Pendigard commited on
Commit
bd98362
·
verified ·
1 Parent(s): cde9b8e

Upload folder using huggingface_hub (part 23)

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. pool/shard001/C++/0022207_NstBrdCtc65.cpp +117 -0
  2. pool/shard001/C++/0022217_flip.cpp +32 -0
  3. pool/shard001/C++/0022220_FCActor.cpp +165 -0
  4. pool/shard001/C++/0022221_configuration.cc +54 -0
  5. pool/shard001/C++/0022226_TexturesMap.cpp +119 -0
  6. pool/shard001/C++/0022241_brainfuck-jit.cpp +289 -0
  7. pool/shard001/C++/0022242_GetSendStatisticsResult.cpp +68 -0
  8. pool/shard001/C++/0022257_predefinedsetmodel.cpp +63 -0
  9. pool/shard001/C++/0022260_boss_overlord_wyrmthalak.cpp +132 -0
  10. pool/shard001/C++/0022263_labelitem.cpp +121 -0
  11. pool/shard001/C++/0022265_dijkstrea.cpp +60 -0
  12. pool/shard001/C++/0022266_ObserverHandler.cc +29 -0
  13. pool/shard001/C++/0022268_REVector3.cpp +56 -0
  14. pool/shard001/C++/0022270_GetDomainNamesResult.cpp +57 -0
  15. pool/shard001/C++/0022285_spp_struct.cc +57 -0
  16. pool/shard001/C++/0022289_filterSameClassHighBlast.cc +91 -0
  17. pool/shard001/C++/0022295_TcpComm.cpp +242 -0
  18. pool/shard001/C++/0022297_Deonion.cpp +145 -0
  19. pool/shard001/C++/0022300_main.cpp +130 -0
  20. pool/shard001/C++/0022317_debug.cpp +104 -0
  21. pool/shard001/C++/0022320_Update.cpp +141 -0
  22. pool/shard001/C++/0022322_Logger.cpp +43 -0
  23. pool/shard001/C++/0022327_utilities.cpp +310 -0
  24. pool/shard001/C++/0022331_ScrollingCoordinatorBlackBerry.cpp +78 -0
  25. pool/shard001/C++/0022333_model.cpp +132 -0
  26. pool/shard001/C++/0022341_bounding_sphere.cpp +173 -0
  27. pool/shard001/C++/0022343_General.cpp +42 -0
  28. pool/shard001/C++/0022356_local_ntp_browsertest.cc +88 -0
  29. pool/shard001/C++/0022357_ClTransposeKernel.cpp +124 -0
  30. pool/shard001/C++/0022360_AlibavaTimeCutProcessor.cc +163 -0
  31. pool/shard001/C++/0022368_output_custom_factory.cc +69 -0
  32. pool/shard001/C++/0022372_sg_StereoSpatAlgorithm.cpp +152 -0
  33. pool/shard001/C++/0022376_conststr.cpp +43 -0
  34. pool/shard001/C++/0022377_z3dprimitiverenderer.cpp +239 -0
  35. pool/shard001/C++/0022380_TiledTileLayer.cpp +268 -0
  36. pool/shard001/C++/0022382_FailoverRouteTest.cpp +81 -0
  37. pool/shard001/C++/0022383_moc_html5applicationviewer.cpp +88 -0
  38. pool/shard001/C++/0022386_packet_peer.cpp +295 -0
  39. pool/shard001/C++/0022393_marker.cpp +92 -0
  40. pool/shard001/C++/0022399_header_unittest.cc +157 -0
  41. pool/shard001/C++/0022401_Calendar.cpp +141 -0
  42. pool/shard001/C++/0022405_graph.cpp +55 -0
  43. pool/shard001/C++/0022410_main.cpp +201 -0
  44. pool/shard001/C++/0022411_document.cc +66 -0
  45. pool/shard001/C++/0022414_initterm.cpp +82 -0
  46. pool/shard001/C++/0022418_flushAndInsert.cpp +158 -0
  47. pool/shard001/C++/0022425_depthwise_conv.cc +164 -0
  48. pool/shard001/C++/0022426_155.cpp +82 -0
  49. pool/shard001/C++/0022432_DSPJitMisc.cpp +194 -0
  50. pool/shard001/C++/0022436_takeoff.cpp +160 -0
pool/shard001/C++/0022207_NstBrdCtc65.cpp ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ////////////////////////////////////////////////////////////////////////////////////////
2
+ //
3
+ // Nestopia - NES/Famicom emulator written in C++
4
+ //
5
+ // Copyright (C) 2003-2007 Martin Freij
6
+ //
7
+ // This file is part of Nestopia.
8
+ //
9
+ // Nestopia is free software; you can redistribute it and/or modify
10
+ // it under the terms of the GNU General Public License as published by
11
+ // the Free Software Foundation; either version 2 of the License, or
12
+ // (at your option) any later version.
13
+ //
14
+ // Nestopia is distributed in the hope that it will be useful,
15
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ // GNU General Public License for more details.
18
+ //
19
+ // You should have received a copy of the GNU General Public License
20
+ // along with Nestopia; if not, write to the Free Software
21
+ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
+ //
23
+ ////////////////////////////////////////////////////////////////////////////////////////
24
+
25
+ #include "../NstMapper.hpp"
26
+ #include "NstBrdCtc65.hpp"
27
+
28
+ namespace Nes
29
+ {
30
+ namespace Core
31
+ {
32
+ namespace Boards
33
+ {
34
+ #ifdef NST_MSVC_OPTIMIZE
35
+ #pragma optimize("s", on)
36
+ #endif
37
+
38
+ void Ctc65::SubReset(bool)
39
+ {
40
+ for (dword i=0x8000; i <= 0xFFFF; i += 0x2)
41
+ {
42
+ Map( i + 0x0, &Ctc65::Peek_Prg, &Ctc65::Poke_8000 );
43
+ Map( i + 0x1, &Ctc65::Peek_Prg, &Ctc65::Poke_8001 );
44
+ }
45
+
46
+ regs[0] = 0;
47
+ regs[1] = 0;
48
+
49
+ UpdatePrg();
50
+ }
51
+
52
+ void Ctc65::SubSave(State::Saver& state) const
53
+ {
54
+ const byte data[2] = {regs[0],regs[1]};
55
+ state.Begin( AsciiId<'R','E','G'>::V ).Write( data ).End();
56
+ }
57
+
58
+ void Ctc65::SubLoad(State::Loader& state)
59
+ {
60
+ while (const dword chunk = state.Begin())
61
+ {
62
+ if (chunk == AsciiId<'R','E','G'>::V)
63
+ {
64
+ State::Loader::Data<2> data( state );
65
+
66
+ regs[0] = data[0];
67
+ regs[1] = data[1];
68
+
69
+ UpdatePrg();
70
+ }
71
+
72
+ state.End();
73
+ }
74
+ }
75
+
76
+ #ifdef NST_MSVC_OPTIMIZE
77
+ #pragma optimize("", on)
78
+ #endif
79
+
80
+ void Ctc65::UpdatePrg()
81
+ {
82
+ const uint chip = (regs[1] << 5 & 0x20) << (regs[0] >> 7);
83
+ openBus = chip < (regs[0] >> 7);
84
+
85
+ prg.SwapBanks<SIZE_16K,0x0000>
86
+ (
87
+ chip | (regs[0] & 0x1E) | (regs[0] >> 5 & regs[0]),
88
+ chip | (regs[0] & 0x1F) | (~regs[0] >> 5 & 0x01)
89
+ );
90
+ }
91
+
92
+ NES_POKE_D(Ctc65,8000)
93
+ {
94
+ if (regs[0] != data)
95
+ {
96
+ regs[0] = data;
97
+ UpdatePrg();
98
+ ppu.SetMirroring( (data & 0x40) ? Ppu::NMT_VERTICAL : Ppu::NMT_HORIZONTAL );
99
+ }
100
+ }
101
+
102
+ NES_POKE_D(Ctc65,8001)
103
+ {
104
+ if (regs[1] != data)
105
+ {
106
+ regs[1] = data;
107
+ UpdatePrg();
108
+ }
109
+ }
110
+
111
+ NES_PEEK_A(Ctc65,Prg)
112
+ {
113
+ return !openBus ? prg.Peek( address - 0x8000 ) : (address >> 8);
114
+ }
115
+ }
116
+ }
117
+ }
pool/shard001/C++/0022217_flip.cpp ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file flip.cpp
3
+ * @brief mex interface for cv::flip
4
+ * @ingroup core
5
+ * @author Amro
6
+ * @date 2015
7
+ */
8
+ #include "mexopencv.hpp"
9
+ using namespace std;
10
+ using namespace cv;
11
+
12
+ /**
13
+ * Main entry called from Matlab
14
+ * @param nlhs number of left-hand-side arguments
15
+ * @param plhs pointers to mxArrays in the left-hand-side
16
+ * @param nrhs number of right-hand-side arguments
17
+ * @param prhs pointers to mxArrays in the right-hand-side
18
+ */
19
+ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
20
+ {
21
+ // Check the number of arguments
22
+ nargchk(nrhs==2 && nlhs<=1);
23
+
24
+ // Argument vector
25
+ vector<MxArray> rhs(prhs, prhs+nrhs);
26
+
27
+ // Process
28
+ Mat src(rhs[0].toMat()), dst;
29
+ int flipCode = rhs[1].toInt();
30
+ flip(src, dst, flipCode);
31
+ plhs[0] = MxArray(dst);
32
+ }
pool/shard001/C++/0022220_FCActor.cpp ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ Copyright (C) 2011-2012 by Martin Linklater
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in
12
+ all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ THE SOFTWARE.
21
+ */
22
+
23
+ #include "FCActor.h"
24
+
25
+ FCActor::FCActor()
26
+ {
27
+ }
28
+
29
+ FCActor::~FCActor()
30
+ {
31
+ FCPhysics::Instance()->TwoD()->DestroyBody(m_physicsBody);
32
+ }
33
+
34
+ void FCActor::Init( FCXMLNode xml,
35
+ FCXMLNode bodyXML,
36
+ FCXMLNode modelXML,
37
+ FCResourceRef res,
38
+ std::string name,
39
+ FCHandle handle)
40
+ {
41
+ m_createXML = xml;
42
+ m_id = FCXML::StringValueForNodeAttribute(m_createXML, kFCKeyId);
43
+ m_handle = handle;
44
+
45
+ // hardwired to 2D for now 8)
46
+
47
+ if (bodyXML)
48
+ {
49
+ FCPhysics2DBodyDefRef bodyDef = FCPhysics2DBodyDefRef( new FCPhysics2DBodyDef );
50
+
51
+ FCVector2f pos;
52
+ pos.Zero();
53
+
54
+ pos.x += FCXML::FloatValueForNodeAttribute(m_createXML, kFCKeyOffsetX);
55
+ pos.y += FCXML::FloatValueForNodeAttribute(m_createXML, kFCKeyOffsetY);
56
+
57
+ bodyDef->position = pos;
58
+
59
+ bodyDef->angle = FCXML::FloatValueForNodeAttribute(m_createXML, kFCKeyRotation);
60
+
61
+ if( FCXML::BoolValueForNodeAttribute(m_createXML, kFCKeyDynamic) )
62
+ bodyDef->isStatic = false;
63
+ else
64
+ bodyDef->isStatic = true;
65
+
66
+ bodyDef->canSleep = false;
67
+ bodyDef->shapeXML = bodyXML;
68
+
69
+ if (name.size()) {
70
+ m_physicsBody = FCPhysics::Instance()->TwoD()->CreateBody(bodyDef, name, handle);
71
+ }
72
+ else {
73
+ m_physicsBody = FCPhysics::Instance()->TwoD()->CreateBody(bodyDef, "", handle);
74
+ }
75
+ }
76
+
77
+ // now create a model
78
+ if (modelXML)
79
+ {
80
+ m_model = plt_FCModel_Create();
81
+ m_model->InitWithModel(modelXML, res);
82
+ }
83
+ else
84
+ {
85
+ if (bodyXML)
86
+ {
87
+ // physics but no model so build a physics mode
88
+
89
+ m_model = plt_FCModel_Create();
90
+ FCColor4f* pColor = (FCColor4f*)res->UserData();
91
+ if( pColor )
92
+ m_model->InitWithPhysics(bodyXML, *pColor);
93
+ else {
94
+ FCColor4f grey(0.5f, 0.5f, 0.5f, 1.0f );
95
+ m_model->InitWithPhysics(bodyXML, grey);
96
+ }
97
+ }
98
+ }
99
+ }
100
+
101
+ void FCActor::SetPosition(FCVector3f pos)
102
+ {
103
+ m_physicsBody->SetPosition(pos);
104
+ }
105
+
106
+ FCVector3f FCActor::Position() const
107
+ {
108
+ return m_physicsBody->Position();
109
+ }
110
+
111
+ void FCActor::SetLinearVelocity(FCVector3f vel)
112
+ {
113
+ m_physicsBody->SetLinearVelocity(vel);
114
+ }
115
+
116
+ FCVector3f FCActor::LinearVelocity() const
117
+ {
118
+ return m_physicsBody->LinearVelocity();
119
+ }
120
+
121
+ void FCActor::SetDebugModelColor(FCColor4f color)
122
+ {
123
+ m_model->SetDebugMeshColor(color);
124
+ }
125
+
126
+ void FCActor::ApplyImpulseAtWorldPos(FCVector3f impulse, FCVector3f pos)
127
+ {
128
+ m_physicsBody->ApplyImpulseAtWorldPos(impulse, pos);
129
+ }
130
+
131
+ void FCActor::Update(float realTime, float gameTime)
132
+ {
133
+ if( m_physicsBody )
134
+ {
135
+ FCVector3f pos = m_physicsBody->Position();
136
+ float rot = m_physicsBody->Rotation();
137
+
138
+ if( m_model )
139
+ {
140
+ m_model->SetRotation(rot);
141
+ m_model->SetPosition(pos);
142
+ }
143
+ }
144
+ }
145
+
146
+ bool FCActor::NeedsUpdate()
147
+ {
148
+ return false;
149
+ }
150
+
151
+ bool FCActor::NeedsRender()
152
+ {
153
+ return false;
154
+ }
155
+
156
+ bool FCActor::RespondsToTapGesture()
157
+ {
158
+ return false;
159
+ }
160
+
161
+ FCModelRefVec FCActor::RenderGather()
162
+ {
163
+ FCModelRefVec ret;
164
+ return ret;
165
+ }
pool/shard001/C++/0022221_configuration.cc ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file configuration.cc
3
+ * @author Krzysztof Trzepla
4
+ * @copyright (C) 2016 ACK CYFRONET AGH
5
+ * @copyright This software is released under the MIT license cited in
6
+ * 'LICENSE.txt'
7
+ */
8
+
9
+ #include "configuration.h"
10
+
11
+ #include <sstream>
12
+
13
+ namespace one {
14
+ namespace messages {
15
+
16
+ Configuration::Configuration(
17
+ std::unique_ptr<ProtocolServerMessage> serverMessage)
18
+ {
19
+ auto *configurationMsg = serverMessage->mutable_configuration();
20
+
21
+ m_rootUuid = configurationMsg->root_uuid();
22
+
23
+ auto *subscriptions = configurationMsg->mutable_subscriptions();
24
+ std::transform(subscriptions->pointer_begin(), subscriptions->pointer_end(),
25
+ std::back_inserter(m_subscriptions),
26
+ [](auto subscription) { return std::move(*subscription); });
27
+
28
+ auto *disabledSpaces = configurationMsg->mutable_disabled_spaces();
29
+ std::transform(disabledSpaces->pointer_begin(),
30
+ disabledSpaces->pointer_end(), std::back_inserter(m_disabledSpaces),
31
+ [](auto disabled_space) { return std::move(*disabled_space); });
32
+ }
33
+
34
+ const folly::fbstring &Configuration::rootUuid() const { return m_rootUuid; }
35
+
36
+ const std::vector<clproto::Subscription> &Configuration::subscriptions() const
37
+ {
38
+ return m_subscriptions;
39
+ }
40
+
41
+ const std::vector<std::string> &Configuration::disabledSpaces() const
42
+ {
43
+ return m_disabledSpaces;
44
+ }
45
+
46
+ std::string Configuration::toString() const
47
+ {
48
+ std::stringstream stream;
49
+ stream << "type: 'Configuration', root UUID: '" << m_rootUuid << "'";
50
+ return stream.str();
51
+ }
52
+
53
+ } // namespace messages
54
+ } // namespace one
pool/shard001/C++/0022226_TexturesMap.cpp ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3
+ For a list of contributors, see the accompanying CONTRIBUTORS file.
4
+
5
+ This file is part of GtkRadiant.
6
+
7
+ GtkRadiant is free software; you can redistribute it and/or modify
8
+ it under the terms of the GNU General Public License as published by
9
+ the Free Software Foundation; either version 2 of the License, or
10
+ (at your option) any later version.
11
+
12
+ GtkRadiant is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ GNU General Public License for more details.
16
+
17
+ You should have received a copy of the GNU General Public License
18
+ along with GtkRadiant; if not, write to the Free Software
19
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
+ */
21
+
22
+ #include "TexturesMap.h"
23
+ #include "texturelib.h"
24
+
25
+ #include "../image.h" // QERApp_LoadImage
26
+
27
+ TexturesMap::TextureConstructor::TextureConstructor (TexturesMap* cache) :
28
+ m_cache(cache)
29
+ {
30
+ }
31
+
32
+ GLTexture* TexturesMap::TextureConstructor::construct (const TextureKey& key)
33
+ {
34
+ GLTexture* texture = new GLTexture(key.first, key.second);
35
+ if (m_cache->realised()) {
36
+ texture->realise();
37
+ }
38
+ return texture;
39
+ }
40
+
41
+ void TexturesMap::TextureConstructor::destroy (GLTexture* texture)
42
+ {
43
+ if (m_cache->realised()) {
44
+ texture->unrealise();
45
+ }
46
+ delete texture;
47
+ }
48
+
49
+ TexturesMap::TexturesMap () :
50
+ m_qtextures(TextureConstructor(this)), m_observer(0), m_unrealised(1)
51
+ {
52
+ }
53
+
54
+ LoadImageCallback TexturesMap::defaultLoader () const
55
+ {
56
+ return LoadImageCallback(0, QERApp_LoadImage);
57
+ }
58
+
59
+ GLTexture* TexturesMap::capture (const std::string& name)
60
+ {
61
+ return capture(defaultLoader(), name);
62
+ }
63
+
64
+ GLTexture* TexturesMap::capture (const LoadImageCallback& loader, const std::string& name)
65
+ {
66
+ g_debug("textures capture: '%s'\n", name.c_str());
67
+ return m_qtextures.capture(TextureKey(loader, name)).get();
68
+ }
69
+
70
+ void TexturesMap::release (GLTexture* texture)
71
+ {
72
+ g_debug("textures release: '%s'\n", texture->getName().c_str());
73
+ m_qtextures.release(TextureKey(texture->load, texture->getName()));
74
+ }
75
+
76
+ void TexturesMap::attach (TexturesCacheObserver& observer)
77
+ {
78
+ ASSERT_MESSAGE(m_observer == 0, "TexturesMap::attach: cannot attach observer");
79
+ m_observer = &observer;
80
+ }
81
+
82
+ void TexturesMap::detach (TexturesCacheObserver& observer)
83
+ {
84
+ ASSERT_MESSAGE(m_observer == &observer, "TexturesMap::detach: cannot detach observer");
85
+ m_observer = 0;
86
+ }
87
+
88
+ void TexturesMap::realise ()
89
+ {
90
+ if (--m_unrealised == 0) {
91
+ for (TextureCache::iterator i = m_qtextures.begin(); i != m_qtextures.end(); ++i) {
92
+ if (!(*i).value.empty()) {
93
+ (*(*i).value).realise();
94
+ }
95
+ }
96
+ if (m_observer != 0) {
97
+ m_observer->realise();
98
+ }
99
+ }
100
+ }
101
+
102
+ void TexturesMap::unrealise ()
103
+ {
104
+ if (++m_unrealised == 1) {
105
+ if (m_observer != 0) {
106
+ m_observer->unrealise();
107
+ }
108
+ for (TextureCache::iterator i = m_qtextures.begin(); i != m_qtextures.end(); ++i) {
109
+ if (!(*i).value.empty()) {
110
+ (*(*i).value).unrealise();
111
+ }
112
+ }
113
+ }
114
+ }
115
+
116
+ bool TexturesMap::realised ()
117
+ {
118
+ return m_unrealised == 0;
119
+ }
pool/shard001/C++/0022241_brainfuck-jit.cpp ADDED
@@ -0,0 +1,289 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <fstream>
2
+ #include <iostream>
3
+ #include <vector>
4
+
5
+ #include <sys/mman.h>
6
+ #include <cstring>
7
+
8
+ #include "brainfuck.h"
9
+
10
+ // Wraps an mmap()ed area, which starts with read/write permissions,
11
+ // but that can be later turned into read/exec before execution.
12
+ // This is good practice since the pages are never writable AND executable
13
+ // _at the same_time_
14
+ // (See https://eli.thegreenplace.net/2013/11/05/how-to-jit-an-introduction)
15
+ class ExecutableBuffer
16
+ {
17
+ private:
18
+ uint8_t *buf_,
19
+ *ptr_;
20
+ size_t size_;
21
+
22
+ public:
23
+ ExecutableBuffer(size_t size) {
24
+ size_ = size;
25
+ buf_ = (uint8_t*) mmap(
26
+ 0,
27
+ size_,
28
+ PROT_READ | PROT_WRITE,
29
+ MAP_PRIVATE | MAP_ANONYMOUS,
30
+ -1,
31
+ 0
32
+ );
33
+ if (buf_ == MAP_FAILED) {
34
+ perror("mmap");
35
+ exit(1);
36
+ }
37
+ ptr_ = buf_;
38
+ memset(ptr_, 0x00, size);
39
+ }
40
+
41
+ ~ExecutableBuffer() {
42
+ if(munmap(buf_, size_) == -1) {
43
+ perror("munmap");
44
+ exit(1);
45
+ }
46
+ }
47
+
48
+ void make_executable() {
49
+ if (mprotect(buf_, size_, PROT_READ | PROT_EXEC) == -1) {
50
+ perror("mprotect");
51
+ exit(1);
52
+ }
53
+ }
54
+
55
+ uint8_t* get_base () const { return buf_; }
56
+ uint8_t* get_ptr () const { return ptr_; }
57
+ void set_ptr (uint8_t* ptr) { ptr_ = ptr; }
58
+
59
+ void writeb(uint8_t byte) {
60
+ // write a single byte
61
+ (*ptr_++) = byte;
62
+ }
63
+
64
+ void writel(uint32_t value) {
65
+ // write a 4-bytes word, keeping endianness
66
+ writes((uint8_t*)&value, 4);
67
+ }
68
+
69
+ void writes(const uint8_t* bytes, uint32_t size) {
70
+ // write an arbitrary-length series of bytes
71
+ memcpy(ptr_, bytes, size);
72
+ ptr_ += size;
73
+ }
74
+ };
75
+
76
+ class JITProgram
77
+ {
78
+ private:
79
+ ExecutableBuffer &buf_;
80
+
81
+ public:
82
+ JITProgram(ExecutableBuffer &buf)
83
+ : buf_(buf) {}
84
+
85
+ ExecutableBuffer& buffer() {return buf_;}
86
+
87
+ void start() {
88
+ // 0000000000000070 break:
89
+ // 70: cc int3
90
+ // buf_.writeb(0xcc);
91
+ }
92
+
93
+ void finish() {
94
+ // 0000000000000071 finish:
95
+ // 71: c3 retq
96
+ buf_.writeb(0xc3);
97
+ }
98
+
99
+ void run() {
100
+ uint32_t memory[30000];
101
+ memset(memory, 0x00, sizeof(memory));
102
+
103
+ // Set the buffer as executable before attempting to jump
104
+ // into it:
105
+ buf_.make_executable();
106
+
107
+ // Capture the buffer base ptr:
108
+ uint8_t* _base = buf_.get_base();
109
+
110
+ // Inject the address of the working memory in the rdi reg:
111
+ asm("movq %0, %%rdi\n":
112
+ : "r"(&memory)
113
+ : "%rdi");
114
+
115
+ // Cast the base as a func pointer and jump to it:
116
+ ((void (*)()) _base)();
117
+ }
118
+ };
119
+
120
+ class JITCompiler : public ExpressionVisitor
121
+ {
122
+ private:
123
+ JITProgram &program_;
124
+ ExecutableBuffer &buffer_;
125
+
126
+ public:
127
+ JITCompiler(JITProgram &program)
128
+ : program_(program),
129
+ buffer_(program_.buffer()) {}
130
+
131
+ virtual void visit(const Increment& inc) {
132
+ // 0000000000000000 increment:
133
+ // 0: 48 c7 c0 01 00 00 00 movq $1, %rax
134
+ // 7: 01 07 addl %eax, (%rdi)
135
+ buffer_.writes((uint8_t*)"\x48\xc7\xc0", 3);
136
+ buffer_.writel(inc.offset());
137
+ buffer_.writes((uint8_t*)"\x01\x07", 2);
138
+ }
139
+
140
+ virtual void visit(const Decrement& dec) {
141
+ // 0000000000000009 decrement:
142
+ // 9: 48 c7 c0 01 00 00 00 movq $1, %rax
143
+ // 10: 29 07 subl %eax, (%rdi)
144
+ buffer_.writes((uint8_t*)"\x48\xc7\xc0", 3);
145
+ buffer_.writel(dec.offset());
146
+ buffer_.writes((uint8_t*)"\x29\x07", 2);
147
+ }
148
+
149
+ virtual void visit(const Forward& fwd) {
150
+ // 0000000000000012 forward:
151
+ // 12: 48 c7 c0 01 00 00 00 movq $1, %rax
152
+ // 19: 48 01 c7 addq %rax, %rdi
153
+ buffer_.writes((uint8_t*)"\x48\xc7\xc0", 3);
154
+ buffer_.writel(fwd.offset()*4);
155
+ buffer_.writes((uint8_t*)"\x48\x01\xc7", 3);
156
+ }
157
+
158
+ virtual void visit(const Backward& bwd) {
159
+ // 000000000000001c backward:
160
+ // 1c: 48 c7 c0 01 00 00 00 movq $1, %rax
161
+ // 23: 48 29 c7 subq %rax, %rdi
162
+ buffer_.writes((uint8_t*)"\x48\xc7\xc0", 3);
163
+ buffer_.writel(bwd.offset()*4);
164
+ buffer_.writes((uint8_t*)"\x48\x29\xc7", 3);
165
+ }
166
+
167
+ virtual void visit(const Input&) {
168
+ // 0000000000000026 read:
169
+ // 26: 57 pushq %rdi
170
+ // 27: 48 c7 c0 03 00 00 02 movq $33554435, %rax
171
+ // 2e: 48 89 fe movq %rdi, %rsi
172
+ // 31: 48 c7 c7 00 00 00 00 movq $0, %rdi
173
+ // 38: 48 c7 c2 01 00 00 00 movq $1, %rdx
174
+ // 3f: 0f 05 syscall
175
+ // 41: 5f popq %rdi
176
+
177
+ buffer_.writeb(0x57);
178
+ buffer_.writes((uint8_t*)"\x48\xc7\xc0", 3);
179
+ buffer_.writel(0x02000003);
180
+ buffer_.writes((uint8_t*)"\x48\x89\xfe", 3);
181
+ buffer_.writes((uint8_t*)"\x48\xc7\xc7\x00\x00\x00\x00", 7);
182
+ buffer_.writes((uint8_t*)"\x48\xc7\xc2\x01\x00\x00\x00", 7);
183
+ buffer_.writes((uint8_t*)"\x0f\x05", 2);
184
+ buffer_.writeb(0x5f);
185
+ }
186
+
187
+ virtual void visit(const Output&) {
188
+ // 0000000000000042 write:
189
+ // 42: 57 pushq %rdi
190
+ // 43: 48 c7 c0 04 00 00 02 movq $33554436, %rax
191
+ // 4a: 48 89 fe movq %rdi, %rsi
192
+ // 4d: 48 c7 c7 01 00 00 00 movq $1, %rdi
193
+ // 54: 48 c7 c2 01 00 00 00 movq $1, %rdx
194
+ // 5b: 0f 05 syscall
195
+ // 5d: 5f popq %rdi
196
+
197
+ buffer_.writeb(0x57);
198
+ buffer_.writes((uint8_t*)"\x48\xc7\xc0", 3);
199
+ buffer_.writel(0x02000004);
200
+ buffer_.writes((uint8_t*)"\x48\x89\xfe", 3);
201
+ buffer_.writes((uint8_t*)"\x48\xc7\xc7\x01\x00\x00\x00", 7);
202
+ buffer_.writes((uint8_t*)"\x48\xc7\xc2\x01\x00\x00\x00", 7);
203
+ buffer_.writes((uint8_t*)"\x0f\x05", 2);
204
+ buffer_.writeb(0x5f);
205
+ }
206
+
207
+ virtual void visit(const Loop& loop) {
208
+ // 000000000000005e loop_start:
209
+ // 5e: 83 3f 00 cmpl $0, (%rdi)
210
+ // 61: 0f 84 00 00 00 00 je 0
211
+ buffer_.writes((uint8_t*)"\x83\x3f\x00", 3);
212
+ buffer_.writes((uint8_t*)"\x0f\x84", 2);
213
+ buffer_.writel(0); // reserve 4 bytes
214
+
215
+ // Save current position:
216
+ uint8_t *after_loop_start = buffer_.get_ptr();
217
+
218
+ // Recurse into subexpressions:
219
+ for(const auto &child: loop.children()) {
220
+ child->accept(*this);
221
+ }
222
+
223
+ // 0000000000000067 loop_end:
224
+ // 67: 83 3f 00 cmpl $0, (%rdi)
225
+ // 6a: 0f 85 00 00 00 00 jne 0
226
+ buffer_.writes((uint8_t*)"\x83\x3f\x00", 3);
227
+ buffer_.writes((uint8_t*)"\x0f\x85", 2);
228
+ // Calculate how much to jump back (consider the 4 bytes
229
+ // of the operand itself):
230
+ uint32_t jump_back = after_loop_start - buffer_.get_ptr() - 4;
231
+ // Append the distance to the jump:
232
+ buffer_.writel(jump_back);
233
+
234
+ // Now calculate how much to jump forward in case we want
235
+ // to skip the loop, to fill the pending jump:
236
+ uint8_t *after_loop_end = buffer_.get_ptr();
237
+ uint32_t jump_fwd = after_loop_end - after_loop_start;
238
+
239
+ // Go back to the original position (-4), fill the pending
240
+ // jump distance and get back to the the current pos:
241
+ buffer_.set_ptr(after_loop_start - 4);
242
+ buffer_.writel(jump_fwd);
243
+ buffer_.set_ptr(after_loop_end);
244
+ }
245
+
246
+ void compile(const ExpressionVector& expressions) {
247
+ program_.start();
248
+
249
+ for(const auto &expression: expressions) {
250
+ expression->accept(*this);
251
+ }
252
+
253
+ program_.finish();
254
+ }
255
+ };
256
+
257
+ int main(int argc, char *argv[]) {
258
+ std::ifstream ifs(argv[1]);
259
+
260
+ if (!ifs) {
261
+ std::cerr << "Invalid filename!" << std::endl;
262
+ return 1;
263
+ }
264
+
265
+ std::vector<char> program;
266
+
267
+ std::copy(
268
+ (std::istreambuf_iterator<char>(ifs)),
269
+ (std::istreambuf_iterator<char>()),
270
+ std::back_inserter(program)
271
+ );
272
+
273
+ try {
274
+ auto expressions = Parser().parse(program);
275
+
276
+ ExecutableBuffer buffer(1000000);
277
+ JITProgram jit_program(buffer);
278
+ JITCompiler compiler(jit_program);
279
+
280
+ compiler.compile(expressions);
281
+
282
+ jit_program.run();
283
+
284
+ } catch (std::exception& e) {
285
+ std::cerr << "Error: " << e.what() << std::endl;
286
+ }
287
+
288
+ return 0;
289
+ }
pool/shard001/C++/0022242_GetSendStatisticsResult.cpp ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License").
5
+ * You may not use this file except in compliance with the License.
6
+ * A copy of the License is located at
7
+ *
8
+ * http://aws.amazon.com/apache2.0
9
+ *
10
+ * or in the "license" file accompanying this file. This file is distributed
11
+ * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12
+ * express or implied. See the License for the specific language governing
13
+ * permissions and limitations under the License.
14
+ */
15
+ #include <aws/email/model/GetSendStatisticsResult.h>
16
+ #include <aws/core/utils/xml/XmlSerializer.h>
17
+ #include <aws/core/AmazonWebServiceResult.h>
18
+ #include <aws/core/utils/StringUtils.h>
19
+ #include <aws/core/utils/logging/LogMacros.h>
20
+
21
+ #include <utility>
22
+
23
+ using namespace Aws::SES::Model;
24
+ using namespace Aws::Utils::Xml;
25
+ using namespace Aws::Utils::Logging;
26
+ using namespace Aws::Utils;
27
+ using namespace Aws;
28
+
29
+ GetSendStatisticsResult::GetSendStatisticsResult()
30
+ {
31
+ }
32
+
33
+ GetSendStatisticsResult::GetSendStatisticsResult(const AmazonWebServiceResult<XmlDocument>& result)
34
+ {
35
+ *this = result;
36
+ }
37
+
38
+ GetSendStatisticsResult& GetSendStatisticsResult::operator =(const AmazonWebServiceResult<XmlDocument>& result)
39
+ {
40
+ const XmlDocument& xmlDocument = result.GetPayload();
41
+ XmlNode rootNode = xmlDocument.GetRootElement();
42
+ XmlNode resultNode = rootNode;
43
+ if (rootNode.GetName() != "GetSendStatisticsResult")
44
+ {
45
+ resultNode = rootNode.FirstChild("GetSendStatisticsResult");
46
+ }
47
+
48
+ if(!resultNode.IsNull())
49
+ {
50
+ XmlNode sendDataPointsNode = resultNode.FirstChild("SendDataPoints");
51
+ if(!sendDataPointsNode.IsNull())
52
+ {
53
+ XmlNode sendDataPointsMember = sendDataPointsNode.FirstChild("member");
54
+ while(!sendDataPointsMember.IsNull())
55
+ {
56
+ m_sendDataPoints.push_back(sendDataPointsMember);
57
+ sendDataPointsMember = sendDataPointsMember.NextNode("member");
58
+ }
59
+
60
+ }
61
+ }
62
+
63
+ XmlNode responseMetadataNode = rootNode.FirstChild("ResponseMetadata");
64
+ m_responseMetadata = responseMetadataNode;
65
+ AWS_LOGSTREAM_DEBUG("Aws::SES::Model::GetSendStatisticsResult", "x-amzn-request-id: " << m_responseMetadata.GetRequestId() );
66
+
67
+ return *this;
68
+ }
pool/shard001/C++/0022257_predefinedsetmodel.cpp ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+
3
+ Pencil2D - Traditional Animation Software
4
+ Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5
+ Copyright (C) 2012-2020 Matthew Chiawen Chang
6
+
7
+ This program is free software; you can redistribute it and/or
8
+ modify it under the terms of the GNU General Public License
9
+ as published by the Free Software Foundation; version 2 of the License.
10
+
11
+ This program is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU General Public License for more details.
15
+
16
+ */
17
+ // PredefinedSetModel.cpp
18
+ #include "predefinedsetmodel.h"
19
+
20
+ PredefinedSetModel::PredefinedSetModel(QObject *parent, const PredefinedKeySet& mKeySet)
21
+ :QAbstractTableModel(parent), mKeySet(mKeySet)
22
+ {
23
+ }
24
+
25
+ int PredefinedSetModel::rowCount(const QModelIndex & /*parent*/) const
26
+ {
27
+ return mKeySet.size();
28
+ }
29
+
30
+ int PredefinedSetModel::columnCount(const QModelIndex & /*parent*/) const
31
+ {
32
+ return 2;
33
+ }
34
+
35
+ QVariant PredefinedSetModel::headerData(int section, Qt::Orientation orientation, int role) const
36
+ {
37
+ if (role == Qt::DisplayRole)
38
+ {
39
+ if (orientation == Qt::Horizontal) {
40
+ return mKeySet.type(section);
41
+ }
42
+ }
43
+ return QVariant();
44
+ }
45
+
46
+ QVariant PredefinedSetModel::data(const QModelIndex &index, int role) const
47
+ {
48
+ if (role == Qt::DisplayRole)
49
+ {
50
+ const int row = index.row();
51
+ const int column = index.column();
52
+
53
+ if (column == PredefinedKeySet::ColumnType::FILES)
54
+ {
55
+ return mKeySet.filePathAt(row);
56
+ }
57
+ else if (column == PredefinedKeySet::ColumnType::KEYFRAMEPOS)
58
+ {
59
+ return QString::number(mKeySet.keyFrameIndexAt(row));
60
+ }
61
+ }
62
+ return QVariant();
63
+ }
pool/shard001/C++/0022260_boss_overlord_wyrmthalak.cpp ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * This file is part of the OregonCore Project. See AUTHORS file for Copyright information
3
+ *
4
+ * This program is free software; you can redistribute it and/or modify it
5
+ * under the terms of the GNU General Public License as published by the
6
+ * Free Software Foundation; either version 2 of the License, or (at your
7
+ * option) any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful, but WITHOUT
10
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12
+ * more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License along
15
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ /* ScriptData
19
+ SDName: Boss_Overlord_Wyrmthalak
20
+ SD%Complete: 100
21
+ SDComment:
22
+ SDCategory: Blackrock Spire
23
+ EndScriptData */
24
+
25
+ #include "ScriptMgr.h"
26
+ #include "ScriptedCreature.h"
27
+
28
+ #define SPELL_BLASTWAVE 11130
29
+ #define SPELL_SHOUT 23511
30
+ #define SPELL_CLEAVE 20691
31
+ #define SPELL_KNOCKAWAY 20686
32
+
33
+ #define ADD_1X -39.355381f
34
+ #define ADD_1Y -513.456482f
35
+ #define ADD_1Z 88.472046f
36
+ #define ADD_1O 4.679872f
37
+
38
+ #define ADD_2X -49.875881f
39
+ #define ADD_2Y -511.896942f
40
+ #define ADD_2Z 88.195160f
41
+ #define ADD_2O 4.613114f
42
+
43
+ struct boss_overlordwyrmthalakAI : public ScriptedAI
44
+ {
45
+ boss_overlordwyrmthalakAI(Creature* c) : ScriptedAI(c) {}
46
+
47
+ uint32 BlastWave_Timer;
48
+ uint32 Shout_Timer;
49
+ uint32 Cleave_Timer;
50
+ uint32 Knockaway_Timer;
51
+ bool Summoned;
52
+
53
+ void Reset()
54
+ {
55
+ BlastWave_Timer = 20000;
56
+ Shout_Timer = 2000;
57
+ Cleave_Timer = 6000;
58
+ Knockaway_Timer = 12000;
59
+ Summoned = false;
60
+ }
61
+
62
+ void EnterCombat(Unit* /*who*/)
63
+ {
64
+ }
65
+
66
+ void UpdateAI(const uint32 diff)
67
+ {
68
+ //Return since we have no target
69
+ if (!UpdateVictim())
70
+ return;
71
+
72
+ //BlastWave_Timer
73
+ if (BlastWave_Timer <= diff)
74
+ {
75
+ DoCastVictim( SPELL_BLASTWAVE);
76
+ BlastWave_Timer = 20000;
77
+ }
78
+ else BlastWave_Timer -= diff;
79
+
80
+ //Shout_Timer
81
+ if (Shout_Timer <= diff)
82
+ {
83
+ DoCastVictim( SPELL_SHOUT);
84
+ Shout_Timer = 10000;
85
+ }
86
+ else Shout_Timer -= diff;
87
+
88
+ //Cleave_Timer
89
+ if (Cleave_Timer <= diff)
90
+ {
91
+ DoCastVictim( SPELL_CLEAVE);
92
+ Cleave_Timer = 7000;
93
+ }
94
+ else Cleave_Timer -= diff;
95
+
96
+ //Knockaway_Timer
97
+ if (Knockaway_Timer <= diff)
98
+ {
99
+ DoCastVictim( SPELL_KNOCKAWAY);
100
+ Knockaway_Timer = 14000;
101
+ }
102
+ else Knockaway_Timer -= diff;
103
+
104
+ //Summon two Beserks
105
+ if (!Summoned && HealthBelowPct(50))
106
+ {
107
+ Unit* pTarget = SelectTarget(SELECT_TARGET_RANDOM, 0, 100, true);
108
+
109
+ if (Creature* SummonedCreature = me->SummonCreature(9216, ADD_1X, ADD_1Y, ADD_1Z, ADD_1O, TEMPSUMMON_TIMED_DESPAWN, 300000))
110
+ SummonedCreature->AI()->AttackStart(pTarget);
111
+ if (Creature* SummonedCreature = me->SummonCreature(9268, ADD_2X, ADD_2Y, ADD_2Z, ADD_2O, TEMPSUMMON_TIMED_DESPAWN, 300000))
112
+ SummonedCreature->AI()->AttackStart(pTarget);
113
+ Summoned = true;
114
+ }
115
+
116
+ DoMeleeAttackIfReady();
117
+ }
118
+ };
119
+ CreatureAI* GetAI_boss_overlordwyrmthalak(Creature* pCreature)
120
+ {
121
+ return new boss_overlordwyrmthalakAI (pCreature);
122
+ }
123
+
124
+ void AddSC_boss_overlordwyrmthalak()
125
+ {
126
+ Script* newscript;
127
+ newscript = new Script;
128
+ newscript->Name = "boss_overlord_wyrmthalak";
129
+ newscript->GetAI = &GetAI_boss_overlordwyrmthalak;
130
+ newscript->RegisterSelf();
131
+ }
132
+
pool/shard001/C++/0022263_labelitem.cpp ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ This file is part of KDE.
3
+
4
+ This program is free software; you can redistribute it and/or modify
5
+ it under the terms of the GNU General Public License as published by
6
+ the Free Software Foundation; either version 2 of the License, or
7
+ (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License
15
+ along with this program; if not, write to the Free Software
16
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17
+ USA.
18
+ */
19
+
20
+ #include "labelitem.h"
21
+
22
+ #include "polkamodel.h"
23
+
24
+ #include <KLocalizedString>
25
+
26
+ LabelItem::LabelItem( PolkaModel *model, const Polka::ViewLabel &label )
27
+ : QObject( model ), m_model( model ), m_label( label ), m_menuEnabled( true )
28
+ {
29
+ setBrush( QColor( 255,255,230 ) );
30
+
31
+ m_textItem = new QGraphicsTextItem( this );
32
+ setText( label.text() );
33
+
34
+ m_fanMenu = new FanMenu( this );
35
+ m_fanMenu->setZValue( 50 );
36
+ m_fanMenu->hide();
37
+
38
+ FanMenuItem *menuItem = m_fanMenu->addItem( i18n("Remove") );
39
+ connect( menuItem, SIGNAL( clicked() ), SLOT( emitRemoveLabel() ) );
40
+ menuItem = m_fanMenu->addItem( i18n("Rename") );
41
+ connect( menuItem, SIGNAL( clicked() ), SLOT( emitRenameLabel() ) );
42
+ m_fanMenu->setupItems( 80 );
43
+
44
+ setAcceptHoverEvents( true );
45
+
46
+ setFlags( ItemIsMovable );
47
+ }
48
+
49
+ void LabelItem::setLabel( const Polka::ViewLabel &label )
50
+ {
51
+ m_label = label;
52
+ setText( label.text() );
53
+ }
54
+
55
+ Polka::ViewLabel LabelItem::label() const
56
+ {
57
+ return m_label;
58
+ }
59
+
60
+ void LabelItem::setText( const QString &text )
61
+ {
62
+ m_textItem->setPlainText( text );
63
+
64
+ int textWidth = m_textItem->boundingRect().width();
65
+ int textHeight = m_textItem->boundingRect().height();
66
+
67
+ setRect( - textWidth / 2, - textHeight / 2, textWidth, textHeight );
68
+
69
+ m_textItem->setPos( - textWidth / 2, - textHeight / 2 );
70
+ }
71
+
72
+ void LabelItem::setMenuEnabled( bool enabled )
73
+ {
74
+ m_menuEnabled = enabled;
75
+ if ( !m_menuEnabled ) {
76
+ m_fanMenu->hide();
77
+ }
78
+ }
79
+
80
+ void LabelItem::hoverEnterEvent( QGraphicsSceneHoverEvent *event )
81
+ {
82
+ Q_UNUSED( event );
83
+
84
+ if ( m_menuEnabled ) {
85
+ m_fanMenu->show();
86
+ emit menuShown();
87
+ }
88
+ }
89
+
90
+ void LabelItem::hoverLeaveEvent( QGraphicsSceneHoverEvent *event )
91
+ {
92
+ Q_UNUSED( event );
93
+
94
+ m_fanMenu->hide();
95
+ }
96
+
97
+ void LabelItem::mousePressEvent( QGraphicsSceneMouseEvent *event )
98
+ {
99
+ m_movePos = pos();
100
+
101
+ QGraphicsRectItem::mousePressEvent( event );
102
+ }
103
+
104
+ void LabelItem::mouseReleaseEvent( QGraphicsSceneMouseEvent *event )
105
+ {
106
+ if ( pos() != m_movePos ) {
107
+ emit itemMoved( m_label, pos() );
108
+ }
109
+
110
+ QGraphicsRectItem::mouseReleaseEvent( event );
111
+ }
112
+
113
+ void LabelItem::emitRemoveLabel()
114
+ {
115
+ emit removeLabel( this );
116
+ }
117
+
118
+ void LabelItem::emitRenameLabel()
119
+ {
120
+ emit renameLabel( this );
121
+ }
pool/shard001/C++/0022265_dijkstrea.cpp ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <cstdio>
2
+ #include <cstring>
3
+
4
+ #include <algorithm>
5
+ #include <iostream>
6
+ #include <queue>
7
+ #include <vector>
8
+
9
+ using namespace std;
10
+
11
+ const int MAXN = 50100;
12
+ const int INF = (int)(1e9 + 7);
13
+
14
+ int n, m;
15
+ int d[MAXN];
16
+ bool viz[MAXN];
17
+ priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > pq;
18
+ vector<int> G[MAXN], C[MAXN];
19
+
20
+ void dijkstra()
21
+ {
22
+ for (int i = 2; i <= n; ++i)
23
+ d[i] = INF;
24
+ pq.push(make_pair(0, 1));
25
+ while (!pq.empty()) {
26
+ int x = pq.top().second;
27
+ int val = pq.top().first;
28
+ pq.pop();
29
+ viz[x] = true;
30
+ for (size_t i = 0; i < G[x].size(); ++i) {
31
+ if (viz[G[x][i]])
32
+ continue;
33
+ if (C[x][i] + val < d[G[x][i]]) {
34
+ d[G[x][i]] = val + C[x][i];
35
+ pq.push(make_pair(d[G[x][i]], G[x][i]));
36
+ }
37
+ }
38
+ }
39
+ }
40
+
41
+ int main()
42
+ {
43
+ freopen("dijkstra.in", "r", stdin);
44
+ freopen("dijkstra.out", "w", stdout);
45
+
46
+ scanf("%d %d", &n, &m);
47
+ for (int i = 1; i <= m; ++i) {
48
+ int a, b, c;
49
+ scanf("%d %d %d", &a, &b, &c);
50
+ G[a].push_back(b);
51
+ C[a].push_back(c);
52
+ }
53
+ dijkstra();
54
+
55
+ for (int i = 2; i <= n; ++i)
56
+ printf("%d ", d[i] >= INF ? 0 : d[i]);
57
+ printf("\n");
58
+
59
+ return 0;
60
+ }
pool/shard001/C++/0022266_ObserverHandler.cc ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //
2
+ // Created by Eddie Hoyle on 17/09/16.
3
+ //
4
+
5
+ #include "ObserverHandler.hh"
6
+
7
+
8
+ void ObserverHandler::addContext( ObserverContext* context )
9
+ {
10
+ m_contexts.push_back( context );
11
+ if ( m_contexts.size() == 1 )
12
+ {
13
+ setActiveContext( context );
14
+ }
15
+ }
16
+
17
+ void ObserverHandler::setActiveContext( ObserverContext* context )
18
+ {
19
+ if ( std::find( m_contexts.begin(), m_contexts.end(), context ) != m_contexts.end() )
20
+ {
21
+ m_active = context;
22
+ }
23
+ }
24
+
25
+ ObserverContext* ObserverHandler::getActiveContext() const
26
+ {
27
+ return m_active;
28
+ }
29
+
pool/shard001/C++/0022268_REVector3.cpp ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2012 - 2013 Kulykov Oleh
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+
18
+ #include "../../include/recore/REVector3.h"
19
+ #include "../../include/recore/REString.h"
20
+ #include "../../include/recore/private/REStringUtilsPrivate.h"
21
+
22
+
23
+
24
+ REVector3 REVector3::fromString(const char * string)
25
+ {
26
+ if (string)
27
+ {
28
+ REVector3 v;
29
+ if (REStringUtilsPrivate::readArrayF32(string, v.coords, 3, ';') == 3)
30
+ {
31
+ return v;
32
+ }
33
+ }
34
+ return REVector3();
35
+ }
36
+
37
+ REVector3 REVector3::fromString(const REString & string)
38
+ {
39
+ if (string.length() > 0)
40
+ {
41
+ REVector3 v;
42
+ if (REStringUtilsPrivate::readArrayF32(string.UTF8String(), v.coords, 3, ';') == 3)
43
+ {
44
+ return v;
45
+ }
46
+ }
47
+ return REVector3();
48
+ }
49
+
50
+ REString REVector3::toString(const REVector3 & vector3)
51
+ {
52
+ char buff[54];
53
+ const REUInt32 len = REStringUtilsPrivate::writeArrayF32(vector3.coords, buff, 3, ';');
54
+ return REString(buff, len);
55
+ }
56
+
pool/shard001/C++/0022270_GetDomainNamesResult.cpp ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License").
5
+ * You may not use this file except in compliance with the License.
6
+ * A copy of the License is located at
7
+ *
8
+ * http://aws.amazon.com/apache2.0
9
+ *
10
+ * or in the "license" file accompanying this file. This file is distributed
11
+ * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12
+ * express or implied. See the License for the specific language governing
13
+ * permissions and limitations under the License.
14
+ */
15
+ #include <aws/apigateway/model/GetDomainNamesResult.h>
16
+ #include <aws/core/utils/json/JsonSerializer.h>
17
+ #include <aws/core/AmazonWebServiceResult.h>
18
+ #include <aws/core/utils/UnreferencedParam.h>
19
+
20
+ #include <utility>
21
+
22
+ using namespace Aws::APIGateway::Model;
23
+ using namespace Aws::Utils::Json;
24
+ using namespace Aws::Utils;
25
+ using namespace Aws;
26
+
27
+ GetDomainNamesResult::GetDomainNamesResult()
28
+ {
29
+ }
30
+
31
+ GetDomainNamesResult::GetDomainNamesResult(const AmazonWebServiceResult<JsonValue>& result)
32
+ {
33
+ *this = result;
34
+ }
35
+
36
+ GetDomainNamesResult& GetDomainNamesResult::operator =(const AmazonWebServiceResult<JsonValue>& result)
37
+ {
38
+ const JsonValue& jsonValue = result.GetPayload();
39
+ if(jsonValue.ValueExists("position"))
40
+ {
41
+ m_position = jsonValue.GetString("position");
42
+
43
+ }
44
+
45
+ if(jsonValue.ValueExists("items"))
46
+ {
47
+ Array<JsonValue> itemsJsonList = jsonValue.GetArray("items");
48
+ for(unsigned itemsIndex = 0; itemsIndex < itemsJsonList.GetLength(); ++itemsIndex)
49
+ {
50
+ m_items.push_back(itemsJsonList[itemsIndex].AsObject());
51
+ }
52
+ }
53
+
54
+
55
+
56
+ return *this;
57
+ }
pool/shard001/C++/0022285_spp_struct.cc ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /******************************************************************************
2
+ * Copyright 2018 The Apollo Authors. All Rights Reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *****************************************************************************/
16
+ #include "modules/perception/lidar/lib/detector/cnn_segmentation/spp_engine/spp_struct.h"
17
+
18
+ namespace apollo {
19
+ namespace perception {
20
+ namespace lidar {
21
+
22
+ void SppData::MakeReference(size_t width, size_t height, float range) {
23
+ obs_prob_data = category_pt_blob->mutable_cpu_data();
24
+ offset_data = instance_pt_blob->mutable_cpu_data();
25
+ confidence_data = confidence_pt_blob->mutable_cpu_data();
26
+ if (height_pt_blob != nullptr) {
27
+ z_data = height_pt_blob->mutable_cpu_data();
28
+ }
29
+ if (classify_pt_blob != nullptr) {
30
+ class_prob_data = classify_pt_blob->mutable_cpu_data();
31
+ }
32
+ if (heading_pt_blob != nullptr) {
33
+ heading_data = heading_pt_blob->mutable_cpu_data();
34
+ }
35
+
36
+ if (obs_prob_data_ref == nullptr) {
37
+ obs_prob_data_ref = new float*[height];
38
+ }
39
+ for (size_t i = 0; i < height; ++i) {
40
+ obs_prob_data_ref[i] = obs_prob_data + i * width;
41
+ }
42
+
43
+ data_width = width;
44
+ data_height = height;
45
+ data_range = range;
46
+ data_size = width * height;
47
+ }
48
+
49
+ SppData::~SppData() {
50
+ if (obs_prob_data_ref) {
51
+ delete[] obs_prob_data_ref;
52
+ }
53
+ }
54
+
55
+ } // namespace lidar
56
+ } // namespace perception
57
+ } // namespace apollo
pool/shard001/C++/0022289_filterSameClassHighBlast.cc ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Author: Paul B. Horton
3
+ * Organization: Computational Biology Research Center, AIST, Japan
4
+ * Copyright (C) 2004, 2006, Paul B. Horton, All rights reserved.
5
+ * Creation Date: 2004.6.16
6
+ * Last Modified: $Date: 2009/04/25 06:21:47 $
7
+ *
8
+ * Description: filter protein pairs in the WoLF_PSORT dataset.
9
+ * pairs with good (low) e-value scores and
10
+ * the same localization site are printed out.
11
+ *
12
+ *
13
+ */
14
+ #include <iostream>
15
+ #include <fstream>
16
+ #include <limits>
17
+ #include "../Blast8ResultReader.hh"
18
+ #include "utils/perlish/perlish.hh"
19
+ #include "utils/math/StayFiniteLog.hh"
20
+ #include "classifiers/LabeledInstances.hh"
21
+
22
+ namespace cbrc{
23
+ void filterSameClassHighBlast( std::istream& trainStream,
24
+ std::istream& blastResultsStream,
25
+ const double& eValueThreshold ){
26
+ Blast8ResultReader blastResults( blastResultsStream, false );
27
+ LabeledInstances lis( LabeledInstances::text, trainStream );
28
+ std::map<std::string, std::string> nameToClass = lis.getNameToClassMap();
29
+ std::vector<std::string> hitNames;
30
+
31
+ for( size_t i = 0; i < lis.size(); ++i ){
32
+ if( !blastResults.has( lis(i).name() ) ) continue;
33
+
34
+ const std::vector<Blast8Result> hitV = blastResults( lis(i).name() );
35
+
36
+ hitNames.clear();
37
+
38
+ for( size_t j = 0; j < hitV.size(); ++j ){
39
+
40
+ if(( nameToClass[ hitV[j].hitName() ] == nameToClass[ lis(i).name() ] )
41
+ && ( hitV[j].eValue() <= eValueThreshold )
42
+ ){
43
+ if( hitV[j].hitName() != lis(i).name() ) hitNames.push_back( hitV[j].hitName() );
44
+ }
45
+ }
46
+
47
+ if( hitNames.size() > 0 ){
48
+ std::cout << lis(i).name();
49
+ for( size_t i = 0; i < hitNames.size(); ++i ) std::cout << " " << hitNames[i];
50
+ std::cout << std::endl;
51
+ }
52
+ }
53
+ }
54
+ }; // end namescape cbrc
55
+
56
+
57
+ int main( int argc, char** argv ){
58
+ std::string usage( "Usage: " );
59
+ usage += argv[0];
60
+ usage += " WoLFPSORTfile blastResultFile [lg] BlastScoreThreshold";
61
+ if( (argc < 4) || (argc > 5) ){
62
+ std::cout << usage << "\nError: wrong number of arguments\n";
63
+ exit( -1 );
64
+ }
65
+ int curArg = 1;
66
+ std::ifstream trainStream( argv[curArg++] );
67
+ if( !trainStream ){
68
+ std::cout << " could not open file " << argv[curArg-1] << std::endl;
69
+ exit( -1 );
70
+ }
71
+ std::ifstream blastResultsStream( argv[curArg++] );
72
+ if( !blastResultsStream ){
73
+ std::cout << " could not open file " << argv[curArg-1] << std::endl;
74
+ exit( -1 );
75
+ }
76
+ double eValueThreshold;
77
+ if( strcmp( argv[curArg], "lg" ) ){
78
+ eValueThreshold = cbrc::perlish::toDouble( argv[curArg] );
79
+ }else{
80
+ if( argc != 5 ){
81
+ std::cout << usage << "\nError: wrong number of arguments\n";
82
+ exit( -1 );
83
+ }
84
+ eValueThreshold = pow( 2, cbrc::perlish::toDouble( argv[++curArg] ) );
85
+ }
86
+ std::cerr << __FILE__ << ":" << __LINE__ << " eValueThreshold: " << eValueThreshold << std::endl;
87
+ cbrc::filterSameClassHighBlast( trainStream, blastResultsStream,
88
+ eValueThreshold );
89
+ return 1;
90
+ }
91
+
pool/shard001/C++/0022295_TcpComm.cpp ADDED
@@ -0,0 +1,242 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include "TcpComm.h"
2
+
3
+ #ifndef WINCE
4
+ #include <cerrno>
5
+ #include <fcntl.h>
6
+ #endif
7
+
8
+ #ifdef WIN32
9
+
10
+ #ifndef WINCE
11
+ #include <sys/types.h>
12
+ #endif
13
+
14
+ #define ERRNO WSAGetLastError()
15
+ #define RESET_ERRNO WSASetLastError(0)
16
+ #undef EWOULDBLOCK
17
+ #define EWOULDBLOCK WSAEWOULDBLOCK
18
+ #undef EINPROGRESS
19
+ #define EINPROGRESS WSAEINPROGRESS
20
+ #define NON_BLOCK(socket) ioctlsocket(socket, FIONBIO, (u_long*) "NONE")
21
+ #define CLOSE(socket) closesocket(socket)
22
+
23
+ class _WSAFramework
24
+ {
25
+ public:
26
+ _WSAFramework()
27
+ {
28
+ WORD wVersionRequested = MAKEWORD(1, 0);
29
+ WSADATA wsaData;
30
+ WSAStartup(wVersionRequested, &wsaData);
31
+ }
32
+ ~_WSAFramework() {WSACleanup();}
33
+ } _wsaFramework;
34
+
35
+ #else
36
+
37
+ #include <sys/select.h>
38
+ #include <sys/socket.h>
39
+ #include <arpa/inet.h>
40
+ #include <unistd.h>
41
+ #include <sys/ioctl.h>
42
+
43
+ #define ERRNO errno
44
+ #define RESET_ERRNO errno = 0
45
+ #define NON_BLOCK(socket) fcntl(socket,F_SETFL,O_NONBLOCK)
46
+ #define CLOSE(socket) close(socket)
47
+
48
+ #endif
49
+
50
+ TcpComm::TcpComm(const char* ip, int port, int maxPackageSendSize, int maxPackageReceiveSize) :
51
+ createSocket(0),
52
+ transferSocket(0),
53
+ overallBytesSent(0),
54
+ overallBytesReceived(0),
55
+ maxPackageSendSize(maxPackageSendSize),
56
+ maxPackageReceiveSize(maxPackageReceiveSize),
57
+ wasConnected(false)
58
+ {
59
+ address.sin_family = AF_INET;
60
+ address.sin_port = htons(port);
61
+ if(ip) // connect as client?
62
+ address.sin_addr.s_addr = inet_addr(ip);
63
+ else
64
+ {
65
+ createSocket = socket(AF_INET, SOCK_STREAM, 0);
66
+ ASSERT(createSocket > 0);
67
+ int val = 1;
68
+ setsockopt(createSocket, SOL_SOCKET, SO_REUSEADDR, (char*) &val, sizeof(val));
69
+ address.sin_addr.s_addr = INADDR_ANY;
70
+ VERIFY(bind(createSocket, (sockaddr*) &address, sizeof(sockaddr_in)) == 0);
71
+ VERIFY(listen(createSocket, SOMAXCONN) == 0);
72
+ NON_BLOCK(createSocket);
73
+ }
74
+ checkConnection();
75
+ }
76
+
77
+ TcpComm::~TcpComm()
78
+ {
79
+ if(connected())
80
+ closeTransferSocket();
81
+ if(createSocket > 0)
82
+ CLOSE(createSocket);
83
+ }
84
+
85
+ bool TcpComm::checkConnection()
86
+ {
87
+ if(!connected())
88
+ {
89
+ #ifndef WIN32
90
+ unsigned int addrlen = sizeof(sockaddr_in);
91
+ #else
92
+ int addrlen = sizeof(sockaddr_in);
93
+ #endif
94
+
95
+ if(createSocket)
96
+ transferSocket = accept(createSocket, (sockaddr*) &address, &addrlen);
97
+ else if(!wasConnected)
98
+ {
99
+ transferSocket = socket(AF_INET, SOCK_STREAM, 0);
100
+ ASSERT(connected());
101
+ if(connect(transferSocket, (sockaddr*) &address, sizeof(sockaddr_in)) != 0)
102
+ {
103
+ CLOSE(transferSocket);
104
+ transferSocket = 0;
105
+ }
106
+ }
107
+
108
+ if(connected())
109
+ {
110
+ wasConnected = true;
111
+ NON_BLOCK(transferSocket); // switch socket to nonblocking
112
+ #ifdef MACOSX
113
+ int yes = 1;
114
+ VERIFY(!setsockopt(transferSocket, SOL_SOCKET, SO_NOSIGPIPE, &yes, sizeof(yes)));
115
+ #endif
116
+ if(maxPackageSendSize)
117
+ VERIFY(!setsockopt(transferSocket, SOL_SOCKET, SO_SNDBUF, (char*)&maxPackageSendSize, sizeof(maxPackageSendSize)));
118
+ if(maxPackageReceiveSize)
119
+ VERIFY(!setsockopt(transferSocket, SOL_SOCKET, SO_RCVBUF, (char*)&maxPackageReceiveSize, sizeof(maxPackageReceiveSize)));
120
+ return true;
121
+ }
122
+ else
123
+ return false;
124
+ }
125
+ else
126
+ return true;
127
+ }
128
+
129
+ void TcpComm::closeTransferSocket()
130
+ {
131
+ CLOSE(transferSocket);
132
+ transferSocket = 0;
133
+ }
134
+
135
+ bool TcpComm::receive(unsigned char* buffer, int size, bool wait)
136
+ {
137
+ if(!checkConnection())
138
+ return false;
139
+
140
+ if(!wait)
141
+ {
142
+ RESET_ERRNO;
143
+ #ifndef WIN32
144
+ int received = recv(transferSocket, (char*) buffer, size, MSG_PEEK);
145
+ if(received < size)
146
+ {
147
+ if(!received || (received < 0 && ERRNO != EWOULDBLOCK && ERRNO != EINPROGRESS))
148
+ closeTransferSocket();
149
+ return false;
150
+ }
151
+ #else
152
+ char c;
153
+ int received = recv(transferSocket, &c, 1, MSG_PEEK);
154
+ if(!received || (received < 0 && ERRNO != EWOULDBLOCK && ERRNO != EINPROGRESS) ||
155
+ ioctlsocket(transferSocket, FIONREAD, (u_long*) &received) != 0)
156
+ {
157
+ closeTransferSocket();
158
+ return false;
159
+ }
160
+ else if(received == 0)
161
+ return false;
162
+ #endif
163
+ }
164
+
165
+ int received = 0;
166
+ while(received < size)
167
+ {
168
+ RESET_ERRNO;
169
+
170
+ int received2 = recv(transferSocket, (char*) buffer + received,
171
+ size - received, 0);
172
+
173
+ if(!received2 || (received2 < 0 && ERRNO != EWOULDBLOCK && ERRNO != EINPROGRESS)) // error during reading of package
174
+ {
175
+ closeTransferSocket();
176
+ return false;
177
+ }
178
+ else if(ERRNO == EWOULDBLOCK || ERRNO == EINPROGRESS) // wait for the rest
179
+ {
180
+ received2 = 0;
181
+ timeval timeout;
182
+ timeout.tv_sec = 0;
183
+ timeout.tv_usec = 100000;
184
+ fd_set rset;
185
+ FD_ZERO(&rset);
186
+ FD_SET(transferSocket, &rset);
187
+ if(select(transferSocket + 1, &rset, 0, 0, &timeout) == -1)
188
+ {
189
+ closeTransferSocket();
190
+ return false; // error while waiting
191
+ }
192
+ }
193
+ received += received2;
194
+ overallBytesReceived += received2;
195
+ }
196
+ return true; // ok, data received
197
+ }
198
+
199
+ int TcpComm::receiveSys(void* buffer, unsigned int len, int flags)
200
+ {
201
+ return recv(transferSocket, (char*) buffer, len, flags);
202
+ }
203
+
204
+ bool TcpComm::send(const unsigned char* buffer, int size)
205
+ {
206
+ if(!checkConnection())
207
+ return false;
208
+
209
+ RESET_ERRNO;
210
+ int sent = ::send(transferSocket, (const char*) buffer, size, 0);
211
+ if(sent > 0)
212
+ {
213
+ overallBytesSent += sent;
214
+ while(sent < size && (ERRNO == EWOULDBLOCK || ERRNO == EINPROGRESS || ERRNO == 0))
215
+ {
216
+ timeval timeout;
217
+ timeout.tv_sec = 0;
218
+ timeout.tv_usec = 100000;
219
+ fd_set wset;
220
+ FD_ZERO(&wset);
221
+ FD_SET(transferSocket, &wset);
222
+ RESET_ERRNO;
223
+ if(select(transferSocket + 1, 0, &wset, 0, &timeout) == -1)
224
+ break;
225
+ RESET_ERRNO;
226
+ int sent2 = ::send(transferSocket, (const char*) buffer + sent, size - sent, 0);
227
+ if(sent2 >= 0)
228
+ {
229
+ sent += sent2;
230
+ overallBytesSent += sent;
231
+ }
232
+ }
233
+ }
234
+
235
+ if(ERRNO == 0 && sent == size)
236
+ return true;
237
+ else
238
+ {
239
+ closeTransferSocket();
240
+ return false;
241
+ }
242
+ }
pool/shard001/C++/0022297_Deonion.cpp ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Ctrl-Cut - Laser cutter toolchain
3
+ * See LICENSE file
4
+ * Copyright (C) 2011 Amir Hassan <amir@viel-zu.org> and Marius kintel <kintel@kintel.net>
5
+ */
6
+
7
+
8
+ #include "util/Logger.hpp"
9
+ #include "cut/graph/Traverse.hpp"
10
+ #include "cut/geom/SegmentTree.hpp"
11
+ #include "cut/geom/Route.hpp"
12
+ #include "cut/geom/algorithms/Algorithms.hpp"
13
+
14
+ typedef SegmentGraphImpl<boost::setS, boost::setS> UniqueSegmentGraph;
15
+ typedef UniqueSegmentGraph::Vertex Vertex;
16
+ typedef UniqueSegmentGraph::Edge Edge;
17
+ typedef std::map<Point,Vertex>::iterator IndexIter;
18
+
19
+ void walkTheEdge(Route& skins, UniqueSegmentGraph& graph, const Edge lastEdge, const Vertex outV)
20
+ {
21
+ Edge nextEdge;
22
+ Segment lastSegment = graph[lastEdge];
23
+ Point lastPoint = graph[outV];
24
+
25
+ graph.remove_edge(lastEdge);
26
+ float lastSlope;
27
+
28
+ if(lastPoint == lastSegment[0])
29
+ lastSlope = lastSegment.getSlope();
30
+ else if(lastPoint == lastSegment[1])
31
+ lastSlope = lastSegment.getSlope(true);
32
+ else
33
+ assert(false);
34
+
35
+ float minSlopeDiff = (CC_PI * 2);
36
+ float candidateSlope;
37
+ double slopeDiff;
38
+ bool found = false;
39
+
40
+ BOOST_FOREACH(Edge candidate , boost::out_edges(outV, graph)) {
41
+ Segment& segment = graph[candidate];
42
+
43
+ //skip identical segment
44
+ if(segment == lastSegment)
45
+ continue;
46
+
47
+ if(segment[0] != lastPoint)
48
+ candidateSlope = segment.getSlope(true);
49
+ else
50
+ candidateSlope = segment.getSlope();
51
+
52
+ slopeDiff = lastSlope - candidateSlope;
53
+
54
+ if(slopeDiff < 0.01)
55
+ slopeDiff += CC_PI * 2;
56
+
57
+ /*std::cerr << *segment << std::endl;
58
+ std::cerr << candidateSlope << std::endl;*/
59
+
60
+ //save the edge with the least clockwise angle (= least slop_diff)
61
+ if (slopeDiff < minSlopeDiff) {
62
+ minSlopeDiff = slopeDiff;
63
+ nextEdge = candidate;
64
+ found = true;
65
+ }
66
+ }
67
+
68
+ if (found) {
69
+ Segment& seg = graph[nextEdge];
70
+ if(!concat(skins, seg))
71
+ append(skins,seg);
72
+
73
+ //graph.index.erase(seg.first);
74
+ //graph.index.erase(seg.second);
75
+ walkTheEdge(skins, graph, nextEdge, get_opposite(graph, nextEdge, outV));
76
+ }
77
+
78
+ //polyline fully consumed
79
+ }
80
+
81
+ bool find_steapest(Edge& found, const Vertex& v, const UniqueSegmentGraph& g) {
82
+ // Find next clockwise segment
83
+ float steapest = 2 * CC_PI;
84
+ bool f = false;
85
+
86
+ BOOST_FOREACH (const Edge candidate, boost::out_edges(v, g)){
87
+ const Segment& seg = g[candidate];
88
+ float steapness = CC_PI - seg.getSlope();
89
+
90
+ if(steapness < 0)
91
+ steapness += (2 * CC_PI);
92
+
93
+ if (steapness < steapest) {
94
+ steapest = steapness;
95
+ found = candidate;
96
+ f=true;
97
+ }
98
+ }
99
+ return f;
100
+ }
101
+
102
+ void traverse_onion(const Route& src, Route& skins)
103
+ {
104
+ LOG_DEBUG(src.size());
105
+
106
+ UniqueSegmentGraph g;
107
+ for(const SegmentPtr seg : segments(src)) {
108
+ g.addSegment(*seg.get());
109
+ }
110
+
111
+ // points are sorted first by x then by y. therefore the
112
+ // first point in the index must be the most left
113
+ while (!g.index.empty()) {
114
+ Point most_left_point = (*g.index.begin()).first;
115
+ Vertex most_left_vertex = (*g.index.begin()).second;
116
+
117
+ Edge steapest;
118
+
119
+ if(!find_steapest(steapest, most_left_vertex, g)) {
120
+ //dangling vertex
121
+ g.index.erase(g.index.begin());
122
+ continue;
123
+ }
124
+
125
+ const Vertex next_vertex = get_opposite(g,steapest, most_left_vertex);
126
+ const Point& next_point = g[next_vertex];
127
+
128
+ const Segment& steapest_seg = g[steapest];
129
+ if(!concat(skins, steapest_seg))
130
+ append(skins,steapest_seg);
131
+
132
+ // g.index.erase(g.index.begin());
133
+
134
+ if(next_point.y < most_left_point.y || (next_point.y == most_left_point.y && next_point.x > most_left_point.x)) {
135
+ walkTheEdge(skins, g, steapest, next_vertex);
136
+ }
137
+ else {
138
+ walkTheEdge(skins, g, steapest, most_left_vertex);
139
+ }
140
+
141
+ }
142
+
143
+ reverse(skins.begin(), skins.end());
144
+ LOG_DEBUG(skins.size());
145
+ }
pool/shard001/C++/0022300_main.cpp ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*=============================================================================
2
+ Copyright (c) 2001-2011 Joel de Guzman
3
+ Copyright (c) 2001-2011 Hartmut Kaiser
4
+
5
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
6
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7
+ =============================================================================*/
8
+ ///////////////////////////////////////////////////////////////////////////////
9
+ //
10
+ // Not a calculator anymore, right? :-)
11
+ //
12
+ // [ JDG April 10, 2007 ] spirit2
13
+ // [ JDG February 18, 2011 ] Pure attributes. No semantic actions.
14
+ // [ HK June 3, 2011 ] Adding lexer
15
+ //
16
+ ///////////////////////////////////////////////////////////////////////////////
17
+
18
+ #include "config.hpp"
19
+ #include "function.hpp"
20
+ #include "vm.hpp"
21
+ #include "compiler.hpp"
22
+ #include "lexer.hpp"
23
+ #include <boost/lexical_cast.hpp>
24
+ #include <fstream>
25
+
26
+ ///////////////////////////////////////////////////////////////////////////////
27
+ // Main program
28
+ ///////////////////////////////////////////////////////////////////////////////
29
+ int main(int argc, char **argv)
30
+ {
31
+ char const* filename;
32
+ if (argc > 1)
33
+ {
34
+ filename = argv[1];
35
+ }
36
+ else
37
+ {
38
+ std::cerr << "Error: No input file provided." << std::endl;
39
+ return 1;
40
+ }
41
+
42
+ std::ifstream in(filename, std::ios_base::in);
43
+
44
+ if (!in)
45
+ {
46
+ std::cerr << "Error: Could not open input file: "
47
+ << filename << std::endl;
48
+ return 1;
49
+ }
50
+
51
+ std::string source_code; // We will read the contents here.
52
+ in.unsetf(std::ios::skipws); // No white space skipping!
53
+ std::copy(
54
+ std::istream_iterator<char>(in),
55
+ std::istream_iterator<char>(),
56
+ std::back_inserter(source_code));
57
+
58
+ typedef std::string::const_iterator base_iterator_type;
59
+ typedef client::lexer::conjure_tokens<base_iterator_type> lexer_type;
60
+ typedef lexer_type::iterator_type iterator_type;
61
+
62
+ lexer_type lexer; // Our lexer
63
+
64
+ base_iterator_type first = source_code.begin();
65
+ base_iterator_type last = source_code.end();
66
+
67
+ iterator_type iter = lexer.begin(first, last);
68
+ iterator_type end = lexer.end();
69
+
70
+ client::vmachine vm; // Our virtual machine
71
+ client::ast::function_list ast; // Our AST
72
+
73
+ client::error_handler<base_iterator_type, iterator_type>
74
+ error_handler(first, last); // Our error handler
75
+ client::parser::function<iterator_type, lexer_type>
76
+ function(error_handler, lexer); // Our parser
77
+ client::code_gen::compiler
78
+ compiler(error_handler); // Our compiler
79
+
80
+ // note: we don't need a skipper
81
+ bool success = parse(iter, end, +function, ast);
82
+
83
+ std::cout << "-------------------------\n";
84
+
85
+ if (success && iter == end)
86
+ {
87
+ if (compiler(ast))
88
+ {
89
+ boost::shared_ptr<client::code_gen::function>
90
+ p = compiler.find_function("main");
91
+ if (!p)
92
+ return 1;
93
+
94
+ int nargs = argc-2;
95
+ if (p->nargs() != nargs)
96
+ {
97
+ std::cerr << "Error: main function requires " << p->nargs() << " arguments." << std::endl;
98
+ std::cerr << nargs << " supplied." << std::endl;
99
+ return 1;
100
+ }
101
+
102
+ std::cout << "Success\n";
103
+ std::cout << "-------------------------\n";
104
+ std::cout << "Assembler----------------\n\n";
105
+ compiler.print_assembler();
106
+
107
+ // Push the arguments into our stack
108
+ for (int i = 0; i < nargs; ++i)
109
+ vm.get_stack()[i] = boost::lexical_cast<int>(argv[i+2]);
110
+
111
+ // Call the interpreter
112
+ int r = vm.execute(compiler.get_code());
113
+
114
+ std::cout << "-------------------------\n";
115
+ std::cout << "Result: " << r << std::endl;
116
+ std::cout << "-------------------------\n\n";
117
+ }
118
+ else
119
+ {
120
+ std::cout << "Compile failure\n";
121
+ }
122
+ }
123
+ else
124
+ {
125
+ std::cout << "Parse failure\n";
126
+ }
127
+ return 0;
128
+ }
129
+
130
+
pool/shard001/C++/0022317_debug.cpp ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*****************************************************************************
2
+
3
+ This file is part of Modelica C Compiler.
4
+
5
+ Modelica C Compiler is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ Modelica C Compiler is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with Modelica C Compiler. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ ******************************************************************************/
19
+
20
+ #include <debug/debug.h>
21
+
22
+ #include <stdlib.h>
23
+ #include <stdio.h>
24
+ #include <string.h>
25
+ #include <stdarg.h>
26
+
27
+ static const char *enableFlags = NULL; // controls which DEBUG messages are printed
28
+
29
+ void debugInit(const char *flagList) {
30
+ enableFlags = flagList;
31
+ }
32
+
33
+ bool debugIsEnabled(char flag) {
34
+ if (enableFlags != NULL)
35
+ return (strchr(enableFlags, flag) != 0)
36
+ || (strchr(enableFlags, '+') != 0);
37
+ else
38
+ return false;
39
+ }
40
+
41
+ void DEBUG(char flag, const char *format, ...) {
42
+ if (debugIsEnabled(flag)) {
43
+ va_list ap;
44
+ va_start(ap, format);
45
+ vfprintf(stdout, format, ap);
46
+ fflush(stdout);
47
+ va_end(ap);
48
+ }
49
+ }
50
+
51
+ bool isDebugParam(char *param) {
52
+ if (strcmp(param, "c") == 0) {
53
+ return true;
54
+ }
55
+ if (strcmp(param, "a") == 0) {
56
+ return true;
57
+ }
58
+ if (strcmp(param, "s") == 0) {
59
+ return true;
60
+ }
61
+ if (strcmp(param, "g") == 0) {
62
+ return true;
63
+ }
64
+ return false;
65
+ }
66
+
67
+ void ERROR(const char *format, ...) {
68
+ va_list ap;
69
+ va_start(ap, format);
70
+ const char *error_string = "Error: ";
71
+ char *new_format = (char *) malloc(sizeof(char) * strlen(error_string) + (strlen(format)));
72
+ strcpy(new_format, error_string);
73
+ strcat(new_format, format);
74
+ vfprintf(stderr, new_format, ap);
75
+ fprintf(stderr,"\n");
76
+ fflush(stderr);
77
+ va_end(ap);
78
+ exit(EXIT_FAILURE);
79
+ }
80
+
81
+ void ERROR_UNLESS(bool condition, const char *format, ...) {
82
+ if(!condition) {
83
+ va_list ap;
84
+ va_start(ap, format);
85
+ ERROR(format, ap);
86
+ va_end(ap);
87
+ }
88
+ }
89
+
90
+ void WARNING(const char *format, ...) {
91
+ va_list ap;
92
+ va_start(ap, format);
93
+ const char *error_string = "Warning: ";
94
+ char *new_format = (char *) malloc(sizeof(char) * strlen(error_string) + (strlen(format)));
95
+ strcpy(new_format, error_string);
96
+ strcat(new_format, format);
97
+ vfprintf(stderr, new_format, ap);
98
+ fprintf(stderr,"\n");
99
+ fflush(stderr);
100
+ free(new_format);
101
+ va_end(ap);
102
+ }
103
+
104
+
pool/shard001/C++/0022320_Update.cpp ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+
3
+ Copyright (C) 2007 Gregory Smith
4
+ and the "Aleph One" developers.
5
+
6
+ This program is free software; you can redistribute it and/or modify
7
+ it under the terms of the GNU General Public License as published by
8
+ the Free Software Foundation; either version 3 of the License, or
9
+ (at your option) any later version.
10
+
11
+ This program is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU General Public License for more details.
15
+
16
+ This license is contained in the file "COPYING",
17
+ which is included with this source code; it is available online at
18
+ http://www.gnu.org/licenses/gpl.html
19
+
20
+ Checks for updates online
21
+
22
+ */
23
+
24
+ #include "Update.h"
25
+ #include "SDL_net.h"
26
+ #include <boost/tokenizer.hpp>
27
+ #include <string.h>
28
+ #include "alephversion.h"
29
+
30
+ Update *Update::m_instance = 0;
31
+
32
+ Update::Update() : m_status(NoUpdateAvailable), m_thread(0)
33
+ {
34
+ StartUpdateCheck();
35
+ }
36
+
37
+ Update::~Update()
38
+ {
39
+ if (m_thread)
40
+ {
41
+ int status;
42
+ SDL_WaitThread(m_thread, &status);
43
+ m_thread = 0;
44
+ }
45
+ }
46
+
47
+ int Update::update_thread(void *p)
48
+ {
49
+ Update *update = static_cast<Update *>(p);
50
+ return update->Thread();
51
+ }
52
+
53
+ void Update::StartUpdateCheck()
54
+ {
55
+ if (m_status == CheckingForUpdate) return;
56
+ if (m_thread)
57
+ {
58
+ int status;
59
+ SDL_WaitThread(m_thread, &status);
60
+ m_thread = 0;
61
+ }
62
+
63
+ m_status = CheckingForUpdate;
64
+ m_new_date_version.clear();
65
+ m_new_display_version.clear();
66
+
67
+ m_thread = SDL_CreateThread(update_thread, this);
68
+ if (!m_thread)
69
+ {
70
+ m_status = UpdateCheckFailed;
71
+ }
72
+ }
73
+
74
+ int Update::Thread()
75
+ {
76
+ IPaddress ip;
77
+ if (SDLNet_ResolveHost(&ip, A1_UPDATE_HOST, 80) < 0)
78
+ {
79
+ m_status = UpdateCheckFailed;
80
+ return 1;
81
+ }
82
+
83
+ TCPsocket sock = SDLNet_TCP_Open(&ip);
84
+ if (!sock)
85
+ {
86
+ m_status = UpdateCheckFailed;
87
+ return 2;
88
+ }
89
+
90
+ char request[1024];
91
+ sprintf(request, "GET /update_check/%s.php HTTP/1.1\r\nHost: %s\r\nConnection: close\r\n\r\n", A1_UPDATE_PLATFORM, A1_UPDATE_HOST);
92
+
93
+ if (SDLNet_TCP_Send(sock, request, strlen(request)) < strlen(request))
94
+ {
95
+ m_status = UpdateCheckFailed;
96
+ return 3;
97
+ }
98
+
99
+ // ghs: SHOULD but doesn't:
100
+ // handle Location: header
101
+ // handle chunked transfers?
102
+
103
+ const int MAX_REPLY = 8192;
104
+ char reply[MAX_REPLY];
105
+
106
+ int len = SDLNet_TCP_Recv(sock, reply, MAX_REPLY);
107
+ if (len < 0)
108
+ {
109
+ m_status = UpdateCheckFailed;
110
+ return 4;
111
+ }
112
+
113
+ reply[len] = 0;
114
+
115
+ char *line = strtok(reply, "\r\n");
116
+ while (line)
117
+ {
118
+ if (strncmp(line, "A1_DATE_VERSION: ", strlen("A1_DATE_VERSION: ")) == 0)
119
+ {
120
+ m_new_date_version.assign(line + strlen("A1_DATE_VERSION: "));
121
+ }
122
+ else if (strncmp(line, "A1_DISPLAY_VERSION: ", strlen("A1_DISPLAY_VERSION: ")) == 0)
123
+ {
124
+ m_new_display_version.assign(line + strlen("A1_DISPLAY_VERSION: "));
125
+ }
126
+ line = strtok(0, "\r\n");
127
+ }
128
+
129
+ if (m_new_date_version.size())
130
+ {
131
+ m_status = m_new_date_version.compare(A1_DATE_VERSION) > 0 ? UpdateAvailable : NoUpdateAvailable;
132
+ return 0;
133
+ }
134
+ else
135
+ {
136
+ m_status = UpdateCheckFailed;
137
+ return 5;
138
+ }
139
+ }
140
+
141
+
pool/shard001/C++/0022322_Logger.cpp ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include "utils/Logger.h"
2
+
3
+ namespace Logger {
4
+
5
+ const int maxVerbosityLvl = 3;
6
+
7
+ std::ofstream logfile_default;
8
+
9
+ bool isLogToFile = false;
10
+
11
+ /// Global verbosity level for output.
12
+ #ifndef NDEBUG
13
+ // Default to maximum verbosity level when in debug mode
14
+ int gVerbosityLvl = maxVerbosityLvl;
15
+ #else
16
+ int gVerbosityLvl = 0;
17
+ #endif // NDEBUG
18
+
19
+ void setVerbosityLevel (int lvl) {
20
+ if (lvl < 5)
21
+ gVerbosityLvl = lvl;
22
+ }
23
+
24
+ void setLogMethod (bool isFile) {
25
+ isLogToFile = isFile ;
26
+ }
27
+
28
+ void setLogFile (const std::string &file ) {
29
+ print( 0, " Opening ", file, " for logging. " );
30
+ logfile_default.open( file );
31
+ }
32
+
33
+ void closeFile() {
34
+ if ( logfile_default.is_open() )
35
+ logfile_default.close();
36
+
37
+ if ( isLogToFile ) {
38
+ print( 0, "Logging file closed." );
39
+ isLogToFile = false;
40
+ }
41
+ }
42
+
43
+ }
pool/shard001/C++/0022327_utilities.cpp ADDED
@@ -0,0 +1,310 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2011, Google Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #include "common.h"
18
+
19
+ #include <string.h>
20
+ #include <android/bitmap.h>
21
+
22
+ #ifdef __cplusplus
23
+ extern "C" {
24
+ #endif /* __cplusplus */
25
+
26
+ /***************
27
+ * AdaptiveMap *
28
+ ***************/
29
+
30
+ jlong Java_com_googlecode_leptonica_android_AdaptiveMap_nativeBackgroundNormMorph(JNIEnv *env,
31
+ jclass clazz,
32
+ jlong nativePix,
33
+ jint reduction,
34
+ jint size,
35
+ jint bgval) {
36
+ // Normalizes the background of each element in pixa.
37
+
38
+ PIX *pixs = (PIX *) nativePix;
39
+ PIX *pixd = pixBackgroundNormMorph(pixs, NULL, (l_int32) reduction, (l_int32) size,
40
+ (l_int32) bgval);
41
+
42
+ return (jlong) pixd;
43
+ }
44
+
45
+ jlong Java_com_googlecode_leptonica_android_AdaptiveMap_nativePixContrastNorm(JNIEnv *env,
46
+ jclass clazz,
47
+ jlong nativePix,
48
+ jint sizeX,
49
+ jint sizeY,
50
+ jint minDiff,
51
+ jint smoothX,
52
+ jint smoothY) {
53
+
54
+ PIX *pixs = (PIX *) nativePix;
55
+ PIX *pixd = pixContrastNorm(NULL, pixs, (l_int32) sizeX, (l_int32) sizeY,
56
+ (l_int32) minDiff, (l_int32) smoothX, (l_int32) smoothY);
57
+
58
+ return (jlong) pixd;
59
+ }
60
+
61
+ /************
62
+ * Binarize *
63
+ ************/
64
+
65
+ jlong Java_com_googlecode_leptonica_android_Binarize_nativeOtsuAdaptiveThreshold(JNIEnv *env,
66
+ jclass clazz,
67
+ jlong nativePix,
68
+ jint sizeX,
69
+ jint sizeY,
70
+ jint smoothX,
71
+ jint smoothY,
72
+ jfloat scoreFract) {
73
+
74
+ PIX *pixs = (PIX *) nativePix;
75
+ PIX *pixd;
76
+
77
+ if (pixOtsuAdaptiveThreshold(pixs, (l_int32) sizeX, (l_int32) sizeY, (l_int32) smoothX,
78
+ (l_int32) smoothY, (l_float32) scoreFract, NULL, &pixd)) {
79
+ return (jlong) 0;
80
+ }
81
+
82
+ return (jlong) pixd;
83
+ }
84
+
85
+ jlong Java_com_googlecode_leptonica_android_Binarize_nativeSauvolaBinarizeTiled(JNIEnv *env,
86
+ jclass clazz,
87
+ jlong nativePix,
88
+ jint whsize,
89
+ jfloat factor,
90
+ jint nx,
91
+ jint ny) {
92
+
93
+ PIX *pixs = (PIX *) nativePix;
94
+ PIX *pixd;
95
+
96
+ if (pixSauvolaBinarizeTiled(pixs, (l_int32) whsize, (l_float32) factor, (l_int32) nx,
97
+ (l_int32) ny, NULL, &pixd)) {
98
+ return (jlong) 0;
99
+ }
100
+
101
+ return (jlong) pixd;
102
+ }
103
+
104
+ /********
105
+ * Clip *
106
+ ********/
107
+
108
+ jlong Java_com_googlecode_leptonica_android_Clip_nativeClipRectangle(JNIEnv *env, jclass clazz,
109
+ jlong nativePix, jlong nativeBox) {
110
+
111
+ PIX *pixs = (PIX *) nativePix;
112
+ BOX *box = (BOX *) nativeBox;
113
+ PIX *pixd;
114
+ pixd = pixClipRectangle(pixs,box,NULL);
115
+ return (jlong) pixd;
116
+ }
117
+
118
+ /***********
119
+ * Convert *
120
+ ***********/
121
+
122
+ jlong Java_com_googlecode_leptonica_android_Convert_nativeConvertTo8(JNIEnv *env, jclass clazz,
123
+ jlong nativePix) {
124
+ PIX *pixs = (PIX *) nativePix;
125
+ PIX *pixd = pixConvertTo8(pixs, FALSE);
126
+
127
+ return (jlong) pixd;
128
+ }
129
+
130
+ /********
131
+ * Edge *
132
+ ********/
133
+
134
+ jlong Java_com_googlecode_leptonica_android_Edge_nativePixSobelEdgeFilter(JNIEnv *env,
135
+ jclass clazz,
136
+ jlong nativePix,
137
+ jint orientFlag) {
138
+ PIX *pixs = (PIX *) nativePix;
139
+ PIX *pixd = pixSobelEdgeFilter(pixs, (l_int32) orientFlag);
140
+
141
+ return (jlong) pixd;
142
+ }
143
+
144
+ /***********
145
+ * Enhance *
146
+ ***********/
147
+
148
+ jlong Java_com_googlecode_leptonica_android_Enhance_nativeUnsharpMasking(JNIEnv *env, jclass clazz,
149
+ jlong nativePix,
150
+ jint halfwidth,
151
+ jfloat fract) {
152
+ PIX *pixs = (PIX *) nativePix;
153
+ PIX *pixd = pixUnsharpMasking(pixs, (l_int32) halfwidth, (l_float32) fract);
154
+
155
+ return (jlong) pixd;
156
+ }
157
+
158
+ /*************
159
+ * GrayQuant *
160
+ *************/
161
+
162
+ jlong Java_com_googlecode_leptonica_android_GrayQuant_nativePixThresholdToBinary(JNIEnv *env, jclass clazz,
163
+ jlong nativePix, jint thresh) {
164
+ PIX *pixs = (PIX *) nativePix;
165
+ PIX *pixd = pixThresholdToBinary(pixs, (l_int32) thresh);
166
+
167
+ return (jlong) pixd;
168
+ }
169
+
170
+ /**********
171
+ * JpegIO *
172
+ **********/
173
+
174
+ jbyteArray Java_com_googlecode_leptonica_android_JpegIO_nativeCompressToJpeg(JNIEnv *env,
175
+ jclass clazz,
176
+ jlong nativePix,
177
+ jint quality,
178
+ jboolean progressive) {
179
+ PIX *pix = (PIX *) nativePix;
180
+
181
+ l_uint8 *data;
182
+ size_t size;
183
+
184
+ if (pixWriteMemJpeg(&data, &size, pix, (l_int32) quality, progressive == JNI_TRUE ? 1 : 0)) {
185
+ LOGE("Failed to write JPEG data");
186
+
187
+ return NULL;
188
+ }
189
+
190
+ // TODO Can we just use the byte array directly?
191
+ jbyteArray array = env->NewByteArray(size);
192
+ env->SetByteArrayRegion(array, 0, size, (jbyte *) data);
193
+
194
+ free(data);
195
+
196
+ return array;
197
+ }
198
+
199
+ /************
200
+ * MorphApp *
201
+ ************/
202
+
203
+ jlong Java_com_googlecode_leptonica_android_MorphApp_nativePixTophat(JNIEnv *env, jclass clazz,
204
+ jlong nativePix, jint hsize,
205
+ jint vsize, jint type) {
206
+ PIX *pixs = (PIX *) nativePix;
207
+ PIX *pixd = pixTophat(pixs, (l_int32) hsize, (l_int32) vsize, (l_int32) type);
208
+
209
+ return (jlong) pixd;
210
+ }
211
+
212
+ jlong Java_com_googlecode_leptonica_android_MorphApp_nativePixFastTophat(JNIEnv *env, jclass clazz,
213
+ jlong nativePix, jint xsize,
214
+ jint ysize, jint type) {
215
+ PIX *pixs = (PIX *) nativePix;
216
+ PIX *pixd = pixFastTophat(pixs, (l_int32) xsize, (l_int32) ysize, (l_int32) type);
217
+
218
+ return (jlong) pixd;
219
+ }
220
+
221
+ /*********
222
+ * Scale *
223
+ *********/
224
+
225
+ jlong Java_com_googlecode_leptonica_android_Scale_nativeScaleGeneral(JNIEnv *env, jclass clazz,
226
+ jlong nativePix, jfloat scaleX,
227
+ jfloat scaleY, jfloat sharpfract, jint sharpwidth) {
228
+ PIX *pixs = (PIX *) nativePix;
229
+ PIX *pixd = pixScaleGeneral(pixs, (l_float32) scaleX, (l_float32) scaleY,(l_float32) sharpfract, (l_int32) sharpwidth);
230
+ return (jlong) pixd;
231
+ }
232
+
233
+ jlong Java_com_googlecode_leptonica_android_Scale_nativeScale(JNIEnv *env, jclass clazz,
234
+ jlong nativePix, jfloat scaleX,
235
+ jfloat scaleY) {
236
+ PIX *pixs = (PIX *) nativePix;
237
+ PIX *pixd = pixScale(pixs, (l_float32) scaleX, (l_float32) scaleY);
238
+
239
+ return (jlong) pixd;
240
+ }
241
+
242
+ /********
243
+ * Skew *
244
+ ********/
245
+
246
+ jfloat Java_com_googlecode_leptonica_android_Skew_nativeFindSkew(JNIEnv *env, jclass clazz,
247
+ jlong nativePix, jfloat sweepRange,
248
+ jfloat sweepDelta,
249
+ jint sweepReduction,
250
+ jint searchReduction,
251
+ jfloat searchMinDelta) {
252
+ // Corrects the rotation of each element in pixa to 0 degrees.
253
+
254
+ PIX *pixs = (PIX *) nativePix;
255
+
256
+ l_float32 angle, conf;
257
+
258
+ if (!pixFindSkewSweepAndSearch(pixs, &angle, &conf, (l_int32) sweepReduction,
259
+ (l_int32) searchReduction, (l_float32) sweepRange,
260
+ (l_int32) sweepDelta, (l_float32) searchMinDelta)) {
261
+ if (conf <= 0) {
262
+ return (jfloat) 0;
263
+ }
264
+
265
+ return (jfloat) angle;
266
+ }
267
+
268
+ return (jfloat) 0;
269
+ }
270
+
271
+ /**********
272
+ * Rotate *
273
+ **********/
274
+
275
+ jlong Java_com_googlecode_leptonica_android_Rotate_nativeRotate(JNIEnv *env, jclass clazz,
276
+ jlong nativePix, jfloat degrees,
277
+ jboolean quality, jboolean resize) {
278
+ PIX *pixd;
279
+ PIX *pixs = (PIX *) nativePix;
280
+
281
+ l_float32 deg2rad = 3.1415926535 / 180.0;
282
+ l_float32 radians = degrees * deg2rad;
283
+ l_int32 w, h, bpp, type;
284
+
285
+ pixGetDimensions(pixs, &w, &h, &bpp);
286
+
287
+ if (bpp == 1 && quality == JNI_TRUE) {
288
+ pixd = pixRotateBinaryNice(pixs, radians, L_BRING_IN_WHITE);
289
+ } else {
290
+ type = quality == JNI_TRUE ? L_ROTATE_AREA_MAP : L_ROTATE_SAMPLING;
291
+ w = (resize == JNI_TRUE) ? w : 0;
292
+ h = (resize == JNI_TRUE) ? h : 0;
293
+ pixd = pixRotate(pixs, radians, type, L_BRING_IN_WHITE, w, h);
294
+ }
295
+
296
+ return (jlong) pixd;
297
+ }
298
+
299
+ jlong Java_com_googlecode_leptonica_android_Rotate_nativeRotateOrth(JNIEnv *env, jclass clazz,
300
+ jlong nativePix, jint quads) {
301
+
302
+ PIX *pixs = (PIX *) nativePix;
303
+ PIX *pixd;
304
+ pixd = pixRotateOrth(pixs,(int)quads);
305
+ return (jlong) pixd;
306
+ }
307
+
308
+ #ifdef __cplusplus
309
+ }
310
+ #endif /* __cplusplus */
pool/shard001/C++/0022331_ScrollingCoordinatorBlackBerry.cpp ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright (C) 2013 Research In Motion Limited. All rights reserved.
3
+ *
4
+ * Redistribution and use in source and binary forms, with or without
5
+ * modification, are permitted provided that the following conditions
6
+ * are met:
7
+ * 1. Redistributions of source code must retain the above copyright
8
+ * notice, this list of conditions and the following disclaimer.
9
+ * 2. Redistributions in binary form must reproduce the above copyright
10
+ * notice, this list of conditions and the following disclaimer in the
11
+ * documentation and/or other materials provided with the distribution.
12
+ *
13
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
+ * THE POSSIBILITY OF SUCH DAMAGE.
24
+ */
25
+
26
+ #include "config.h"
27
+ #include "ScrollingCoordinatorBlackBerry.h"
28
+
29
+ #include "Frame.h"
30
+ #include "FrameView.h"
31
+ #include "LayerWebKitThread.h"
32
+ #include "Page.h"
33
+ #include "PlatformLayer.h"
34
+ #include "RenderLayerCompositor.h"
35
+ #include "RenderView.h"
36
+
37
+ namespace WebCore {
38
+
39
+ ScrollingCoordinatorBlackBerry::ScrollingCoordinatorBlackBerry(Page* page)
40
+ : ScrollingCoordinator(page)
41
+ {
42
+ }
43
+
44
+ void ScrollingCoordinatorBlackBerry::setLayerIsContainerForFixedPositionLayers(GraphicsLayer* layer, bool isContainer)
45
+ {
46
+ // We don't want to set this for the main frame, the main frame would be treated like a subframe
47
+ // by the LayerRenderer which would result in incorrect positioning.
48
+ if (m_page->mainFrame() && scrollLayerForFrameView(m_page->mainFrame()->view()) == layer)
49
+ isContainer = false;
50
+
51
+ if (layer->platformLayer())
52
+ layer->platformLayer()->setIsContainerForFixedPositionLayers(isContainer);
53
+ }
54
+
55
+ void ScrollingCoordinatorBlackBerry::setLayerIsFixedToContainerLayer(GraphicsLayer* layer, bool isFixed)
56
+ {
57
+ if (layer->platformLayer())
58
+ layer->platformLayer()->setFixedPosition(isFixed);
59
+ }
60
+
61
+ void ScrollingCoordinatorBlackBerry::setLayerFixedToContainerLayerEdge(GraphicsLayer* layer, bool fixedToTop, bool fixedToLeft)
62
+ {
63
+ if (!layer->platformLayer())
64
+ return;
65
+
66
+ layer->platformLayer()->setFixedToTop(fixedToTop);
67
+ layer->platformLayer()->setFixedToLeft(fixedToLeft);
68
+ }
69
+
70
+ void ScrollingCoordinatorBlackBerry::frameViewLayoutUpdated(FrameView* frameView)
71
+ {
72
+ if (GraphicsLayer* scrollLayer = scrollLayerForFrameView(frameView)) {
73
+ scrollLayer->platformLayer()->setFrameContentsSize(frameView->contentsSize());
74
+ scrollLayer->platformLayer()->setFrameVisibleRect(frameView->visibleContentRect());
75
+ }
76
+ }
77
+
78
+ }
pool/shard001/C++/0022333_model.cpp ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include "model.h"
2
+ #include "material.h"
3
+ #include "mesh.h"
4
+
5
+ #include <cfloat>
6
+ #include <iostream>
7
+ #include <set>
8
+
9
+ Model::Model(const Matrix &transform, std::vector<std::unique_ptr<Mesh>> &meshes)
10
+ : m_transform(transform), m_transform_is_dirty(true), m_scale(Vector3d(1, 1, 1))
11
+ {
12
+ for(auto &mesh : meshes) {
13
+ m_meshes.push_back(std::move(mesh));
14
+ }
15
+ }
16
+
17
+ Vector3d Model::min_bound() const
18
+ {
19
+ Vector3d min(DBL_MAX, DBL_MAX, DBL_MAX);
20
+
21
+ for(auto &mesh : m_meshes) {
22
+ for(auto &vertice : mesh->m_vertices) {
23
+ if(vertice.x() < min.x())
24
+ min.x() = vertice.x();
25
+ if(vertice.y() < min.y())
26
+ min.y() = vertice.y();
27
+ if(vertice.z() < min.z())
28
+ min.z() = vertice.z();
29
+ }
30
+ }
31
+
32
+ return min;
33
+ }
34
+ Vector3d Model::max_bound() const
35
+ {
36
+ Vector3d max(-DBL_MAX, -DBL_MAX, -DBL_MAX);
37
+
38
+ for(auto &mesh : m_meshes) {
39
+ for(auto &vertice : mesh->m_vertices) {
40
+ if(vertice.x() > max.x())
41
+ max.x() = vertice.x();
42
+ if(vertice.y() > max.y())
43
+ max.y() = vertice.y();
44
+ if(vertice.z() > max.z())
45
+ max.z() = vertice.z();
46
+ }
47
+ }
48
+
49
+ return max;
50
+ }
51
+
52
+ void Model::set_translation(const Vector3d &translation)
53
+ {
54
+ if(translation != m_translation) {
55
+ m_translation = translation;
56
+ m_transform_is_dirty = true;
57
+ }
58
+ }
59
+
60
+ void Model::set_rotation(const Vector3d &rotation)
61
+ {
62
+ if(rotation != m_rotation) {
63
+ m_rotation = rotation;
64
+ m_transform_is_dirty = true;
65
+ }
66
+ }
67
+
68
+ void Model::set_scale(const Vector3d &scale)
69
+ {
70
+ if(scale != m_scale) {
71
+ m_scale = scale;
72
+ m_transform_is_dirty = true;
73
+ }
74
+ }
75
+
76
+ Vector3d Model::translation() const
77
+ {
78
+ return m_translation;
79
+ }
80
+
81
+ Vector3d Model::rotation() const
82
+ {
83
+ return m_rotation;
84
+ }
85
+
86
+ Vector3d Model::scale() const
87
+ {
88
+ return m_scale;
89
+ }
90
+
91
+ void Model::update_transform(bool force_update)
92
+ {
93
+ if(m_transform_is_dirty || force_update) {
94
+ m_transform_is_dirty = false;
95
+
96
+ Matrix scale_matrix;
97
+ Matrix rotation_x_matrix;
98
+ Matrix rotation_y_matrix;
99
+ Matrix rotation_z_matrix;
100
+ Matrix translation_matrix;
101
+
102
+ Matrix::CreateScale(m_scale.x(), m_scale.y(), m_scale.z(), &scale_matrix);
103
+ Matrix::CreateRotationX(m_rotation.x(), &rotation_x_matrix);
104
+ Matrix::CreateRotationY(m_rotation.y(), &rotation_y_matrix);
105
+ Matrix::CreateRotationZ(m_rotation.z(), &rotation_z_matrix);
106
+ Matrix::CreateTranslation(m_translation, &translation_matrix);
107
+
108
+ Matrix rotation_matrix = rotation_x_matrix * rotation_y_matrix * rotation_z_matrix;
109
+
110
+ m_transform = scale_matrix * rotation_matrix * translation_matrix;
111
+
112
+ for(auto &mesh : m_meshes) {
113
+ mesh->transform_vertices(m_transform, rotation_matrix); // TODO: Hur hanteras skalning med normaler? Är translation det enda som ska ur transformen?
114
+ }
115
+ }
116
+ }
117
+
118
+ void Model::print_memory_usage() const
119
+ {
120
+ size_t size = sizeof(Model);
121
+ std::set<Material*> materials;
122
+ size_t materials_size = 0;
123
+
124
+ for(auto &mesh : m_meshes) {
125
+ size += mesh->memory_size();
126
+ if(materials.insert(mesh->m_material.get()).second) {
127
+ materials_size += mesh->m_material->memory_size();
128
+ }
129
+ }
130
+
131
+ std::cout << "Memory usage: " << size / (1024*1024) << " Mb. Materials: " << materials_size / (1024*1024) << " Mb.\n";
132
+ }
pool/shard001/C++/0022341_bounding_sphere.cpp ADDED
@@ -0,0 +1,173 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright mogemimi. Distributed under the MIT license.
2
+
3
+ #include "pomdog/math/bounding_sphere.h"
4
+ #include "pomdog/basic/conditional_compilation.h"
5
+ #include "pomdog/math/bounding_box.h"
6
+ #include "pomdog/math/containment_type.h"
7
+ #include "pomdog/math/plane.h"
8
+ #include "pomdog/math/ray.h"
9
+ #include "pomdog/utility/assert.h"
10
+
11
+ POMDOG_SUPPRESS_WARNINGS_GENERATED_BY_STD_HEADERS_BEGIN
12
+ #include <cmath>
13
+ POMDOG_SUPPRESS_WARNINGS_GENERATED_BY_STD_HEADERS_END
14
+
15
+ namespace pomdog {
16
+
17
+ BoundingSphere::BoundingSphere(const Vector3& center, float radius)
18
+ : Center(center)
19
+ , Radius(radius)
20
+ {
21
+ POMDOG_ASSERT(radius >= 0);
22
+ }
23
+
24
+ ContainmentType BoundingSphere::Contains(const Vector3& point) const
25
+ {
26
+ auto distanceSquared = math::DistanceSquared(point, Center);
27
+ auto radiusSquared = Radius * Radius;
28
+ if (distanceSquared > radiusSquared) {
29
+ return ContainmentType::Disjoint;
30
+ }
31
+ else if (distanceSquared < radiusSquared) {
32
+ return ContainmentType::Contains;
33
+ }
34
+ return ContainmentType::Intersects;
35
+ }
36
+
37
+ ContainmentType BoundingSphere::Contains(const BoundingBox& box) const
38
+ {
39
+ bool inside = true;
40
+ for (auto& corner : box.GetCorners()) {
41
+ if (this->Contains(corner) == ContainmentType::Disjoint) {
42
+ inside = false;
43
+ break;
44
+ }
45
+ }
46
+ if (inside) {
47
+ return ContainmentType::Contains;
48
+ }
49
+ if (this->Intersects(box)) {
50
+ return ContainmentType::Intersects;
51
+ }
52
+ return ContainmentType::Disjoint;
53
+ }
54
+
55
+ ContainmentType BoundingSphere::Contains(const BoundingSphere& sphere) const
56
+ {
57
+ auto distance = math::Distance(this->Center, sphere.Center);
58
+ if (distance > this->Radius + sphere.Radius) {
59
+ return ContainmentType::Disjoint;
60
+ }
61
+ if (distance + sphere.Radius < this->Radius) {
62
+ return ContainmentType::Contains;
63
+ }
64
+ return ContainmentType::Intersects;
65
+ }
66
+
67
+ bool BoundingSphere::Intersects(const BoundingBox& box) const
68
+ {
69
+ return box.Intersects(*this);
70
+ }
71
+
72
+ bool BoundingSphere::Intersects(const BoundingSphere& sphere) const
73
+ {
74
+ auto distance = math::Distance(this->Center, sphere.Center);
75
+ return distance <= this->Radius + sphere.Radius;
76
+ }
77
+
78
+ PlaneIntersectionType BoundingSphere::Intersects(const Plane& plane) const
79
+ {
80
+ return plane.Intersects(*this);
81
+ }
82
+
83
+ std::optional<float> BoundingSphere::Intersects(const Ray& ray) const
84
+ {
85
+ return ray.Intersects(*this);
86
+ }
87
+
88
+ BoundingSphere
89
+ BoundingSphere::CreateFromPoints(const Vector3* points, std::size_t pointCount) noexcept
90
+ {
91
+ POMDOG_ASSERT(points != nullptr);
92
+ POMDOG_ASSERT(pointCount > 0);
93
+ auto accessor = [&](std::size_t i) -> Vector3 { return points[i]; };
94
+ return CreateFromPoints(std::move(accessor), pointCount);
95
+ }
96
+
97
+ BoundingSphere
98
+ BoundingSphere::CreateFromPoints(std::function<Vector3(std::size_t)> points, std::size_t pointCount) noexcept
99
+ {
100
+ POMDOG_ASSERT(points != nullptr);
101
+ POMDOG_ASSERT(pointCount > 0);
102
+
103
+ // NOTE: Compute bounding sphere using Jack Ritter's algorithm.
104
+ std::size_t maxX = 0;
105
+ std::size_t maxY = 0;
106
+ std::size_t maxZ = 0;
107
+ std::size_t minX = 0;
108
+ std::size_t minY = 0;
109
+ std::size_t minZ = 0;
110
+
111
+ for (std::size_t i = 0; i < pointCount; i++) {
112
+ const auto& p = points(i);
113
+ if (p.X < points(minX).X) {
114
+ minX = i;
115
+ }
116
+ if (p.X > points(maxX).X) {
117
+ maxX = i;
118
+ }
119
+ if (p.Y < points(minY).Y) {
120
+ minY = i;
121
+ }
122
+ if (p.Y > points(maxY).Y) {
123
+ maxY = i;
124
+ }
125
+ if (p.Z < points(minZ).Z) {
126
+ minZ = i;
127
+ }
128
+ if (p.Z > points(maxZ).Z) {
129
+ maxZ = i;
130
+ }
131
+ }
132
+
133
+ const auto distX = math::DistanceSquared(points(maxX), points(minX));
134
+ const auto distY = math::DistanceSquared(points(maxY), points(minY));
135
+ const auto distZ = math::DistanceSquared(points(maxZ), points(minZ));
136
+
137
+ std::size_t max = maxX;
138
+ std::size_t min = minX;
139
+ if (distY > distX && distY > distZ) {
140
+ max = maxY;
141
+ min = minY;
142
+ }
143
+ else if (distZ > distX && distZ > distY) {
144
+ max = maxZ;
145
+ min = minZ;
146
+ }
147
+
148
+ auto center = (points(max) + points(min)) * 0.5f;
149
+ auto radius = math::Distance(points(max), center);
150
+ auto radiusSq = radius * radius;
151
+
152
+ // NOTE: Compute strict bounding sphere.
153
+ for (std::size_t i = 0; i < pointCount; i++) {
154
+ const auto p = points(i);
155
+ const auto diff = p - center;
156
+ const auto distanceSq = math::LengthSquared(diff);
157
+ if (distanceSq > radiusSq) {
158
+ const auto distance = std::sqrt(distanceSq);
159
+ const auto direction = diff / distance;
160
+ const auto g = center - radius * direction;
161
+ center = (g + p) * 0.5f;
162
+ radius = math::Distance(p, center);
163
+ radiusSq = radius * radius;
164
+ }
165
+ }
166
+
167
+ BoundingSphere sphere;
168
+ sphere.Center = center;
169
+ sphere.Radius = radius;
170
+ return sphere;
171
+ }
172
+
173
+ } // namespace pomdog
pool/shard001/C++/0022343_General.cpp ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ /**
3
+ * General Setting
4
+ * -----------------------------------------
5
+ *
6
+ * - Define view
7
+ * - Set/get General Settings
8
+ * - Define device of cue etc
9
+ *
10
+ * @author Victor Algaba
11
+ */
12
+
13
+
14
+
15
+
16
+ #include <QDebug>
17
+ #include "General.h"
18
+ #include "bass.h"
19
+
20
+ General::General(QDialog *parent )
21
+ :QDialog(parent)
22
+ {
23
+ setupUi(this);
24
+ setModal(true);
25
+
26
+ #ifdef Q_OS_WIN32
27
+ setWindowFlags( Qt::Tool);
28
+ #endif
29
+
30
+ //define size of form
31
+ QSize fixedSize(this->width(),this->height());
32
+ setMinimumSize(fixedSize);
33
+ setMaximumSize(fixedSize);
34
+ setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
35
+
36
+ listWidget->setCurrentRow(0);
37
+ // stackedWidget->setCurrentIndex(0);
38
+
39
+
40
+ // connect(BtnSalir,SIGNAL(clicked()),this, SLOT(ClickSalir()));
41
+
42
+ }
pool/shard001/C++/0022356_local_ntp_browsertest.cc ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2013 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ #include "base/prefs/pref_service.h"
6
+ #include "base/strings/utf_string_conversions.h"
7
+ #include "chrome/browser/browser_process.h"
8
+ #include "chrome/browser/search/search.h"
9
+ #include "chrome/browser/ui/search/instant_test_utils.h"
10
+ #include "chrome/browser/ui/tabs/tab_strip_model.h"
11
+ #include "chrome/common/pref_names.h"
12
+ #include "chrome/common/url_constants.h"
13
+ #include "chrome/test/base/in_process_browser_test.h"
14
+ #include "chrome/test/base/ui_test_utils.h"
15
+ #include "content/public/browser/web_contents.h"
16
+ #include "ui/base/resource/resource_bundle.h"
17
+
18
+ class LocalNTPTest : public InProcessBrowserTest,
19
+ public InstantTestBase {
20
+ public:
21
+ LocalNTPTest() {}
22
+
23
+ protected:
24
+ virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
25
+ chrome::EnableInstantExtendedAPIForTesting();
26
+ ASSERT_TRUE(https_test_server().Start());
27
+ GURL instant_url = https_test_server().GetURL(
28
+ "files/local_ntp_browsertest.html?strk=1&");
29
+ InstantTestBase::Init(instant_url);
30
+ }
31
+ };
32
+
33
+ IN_PROC_BROWSER_TEST_F(LocalNTPTest, LocalNTPJavascriptTest) {
34
+ ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
35
+ FocusOmniboxAndWaitForInstantNTPSupport();
36
+
37
+ ui_test_utils::NavigateToURLWithDisposition(
38
+ browser(),
39
+ instant_url(),
40
+ NEW_FOREGROUND_TAB,
41
+ ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB |
42
+ ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
43
+ content::WebContents* active_tab =
44
+ browser()->tab_strip_model()->GetActiveWebContents();
45
+ ASSERT_TRUE(chrome::IsInstantNTP(active_tab));
46
+ bool success = false;
47
+ ASSERT_TRUE(GetBoolFromJS(active_tab, "!!runTests()", &success));
48
+ EXPECT_TRUE(success);
49
+ }
50
+
51
+ // Flaky on Linux Tests bot.
52
+ #if defined(OS_LINUX)
53
+ #define MAYBE_NTPRespectsBrowserLanguageSetting DISABLED_NTPRespectsBrowserLanguageSetting
54
+ #else
55
+ #define MAYBE_NTPRespectsBrowserLanguageSetting NTPRespectsBrowserLanguageSetting
56
+ #endif
57
+ IN_PROC_BROWSER_TEST_F(LocalNTPTest, MAYBE_NTPRespectsBrowserLanguageSetting) {
58
+ // Make sure the default language is not French.
59
+ std::string default_locale = g_browser_process->GetApplicationLocale();
60
+ EXPECT_NE("fr", default_locale);
61
+
62
+ // Switch browser language to French.
63
+ std::string loaded_locale =
64
+ ui::ResourceBundle::GetSharedInstance().ReloadLocaleResources("fr");
65
+ EXPECT_EQ("fr", loaded_locale);
66
+ g_browser_process->SetApplicationLocale(loaded_locale);
67
+ PrefService* prefs = g_browser_process->local_state();
68
+ prefs->SetString(prefs::kApplicationLocale, loaded_locale);
69
+
70
+ // Setup Instant.
71
+ ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
72
+
73
+ // The second argument says to use only the local overlay and NTP.
74
+ instant()->SetInstantEnabled(false, true);
75
+ FocusOmniboxAndWaitForInstantNTPSupport();
76
+
77
+ // Open a new tab.
78
+ ui_test_utils::NavigateToURLWithDisposition(
79
+ browser(),
80
+ GURL(chrome::kChromeUINewTabURL),
81
+ NEW_FOREGROUND_TAB,
82
+ ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
83
+
84
+ // Verify that the NTP is in French.
85
+ content::WebContents* active_tab =
86
+ browser()->tab_strip_model()->GetActiveWebContents();
87
+ EXPECT_EQ(ASCIIToUTF16("Nouvel onglet"), active_tab->GetTitle());
88
+ }
pool/shard001/C++/0022357_ClTransposeKernel.cpp ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright (c) 2017-2021 Arm Limited.
3
+ *
4
+ * SPDX-License-Identifier: MIT
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to
8
+ * deal in the Software without restriction, including without limitation the
9
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10
+ * sell copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+ #include "src/gpu/cl/kernels/ClTransposeKernel.h"
25
+
26
+ #include "arm_compute/core/CL/CLHelpers.h"
27
+ #include "arm_compute/core/CL/CLKernelLibrary.h"
28
+ #include "arm_compute/core/CL/ICLTensor.h"
29
+ #include "arm_compute/core/Helpers.h"
30
+ #include "arm_compute/core/TensorInfo.h"
31
+ #include "arm_compute/core/Utils.h"
32
+ #include "arm_compute/core/Validate.h"
33
+ #include "arm_compute/core/utils/misc/ShapeCalculator.h"
34
+ #include "src/core/CL/CLValidate.h"
35
+ #include "src/core/helpers/AutoConfiguration.h"
36
+ #include "src/core/helpers/WindowHelpers.h"
37
+ #include "support/Cast.h"
38
+ #include "support/StringSupport.h"
39
+
40
+ namespace arm_compute
41
+ {
42
+ namespace opencl
43
+ {
44
+ namespace kernels
45
+ {
46
+ ClTransposeKernel::ClTransposeKernel()
47
+ {
48
+ _type = CLKernelType::ELEMENTWISE;
49
+ }
50
+
51
+ void ClTransposeKernel::configure(const CLCompileContext &compile_context, const ITensorInfo *src, ITensorInfo *dst)
52
+ {
53
+ ARM_COMPUTE_ERROR_ON_NULLPTR(src, dst);
54
+
55
+ // Output auto initialization if not yet initialized
56
+ const TensorShape dst_shape = misc::shape_calculator::compute_transposed_shape(*src);
57
+ auto_init_if_empty(*dst, src->clone()->set_tensor_shape(dst_shape));
58
+
59
+ ARM_COMPUTE_ERROR_THROW_ON(ClTransposeKernel::validate(src, dst));
60
+ auto padding_info = get_padding_info({ src, dst });
61
+
62
+ // Create kernel
63
+ const unsigned int vec_size_x = adjust_vec_size(max_cl_vector_width / src->element_size(), src->dimension(0));
64
+ const int vec_size_x_leftovers = src->dimension(0) % vec_size_x;
65
+ const unsigned int vec_size_y = adjust_vec_size(max_cl_vector_width / src->element_size(), src->dimension(1));
66
+ const int vec_size_y_leftovers = src->dimension(1) % vec_size_y;
67
+
68
+ CLBuildOptions build_opts;
69
+ build_opts.add_option("-DDATA_TYPE_IN_BYTES=" + support::cpp11::to_string(src->element_size()));
70
+ build_opts.add_option("-DVEC_SIZE_X=" + support::cpp11::to_string(vec_size_x));
71
+ build_opts.add_option("-DVEC_SIZE_LEFTOVER_X=" + support::cpp11::to_string(vec_size_x_leftovers));
72
+ build_opts.add_option("-DVEC_SIZE_Y=" + support::cpp11::to_string(vec_size_y));
73
+ build_opts.add_option("-DVEC_SIZE_LEFTOVER_Y=" + support::cpp11::to_string(vec_size_y_leftovers));
74
+
75
+ _kernel = create_kernel(compile_context, "transpose", build_opts.options());
76
+
77
+ // Configure kernel window
78
+ Window win = calculate_max_window(*src, Steps(vec_size_x, vec_size_y));
79
+ ICLKernel::configure_internal(win, cl::NDRange(2, 8));
80
+ ARM_COMPUTE_ERROR_ON(has_padding_changed(padding_info));
81
+ }
82
+
83
+ Status ClTransposeKernel::validate(const ITensorInfo *src, const ITensorInfo *dst)
84
+ {
85
+ ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(src, dst);
86
+ ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(src);
87
+ ARM_COMPUTE_RETURN_ERROR_ON(src->data_type() == DataType::UNKNOWN);
88
+ ARM_COMPUTE_RETURN_ERROR_ON_MSG(src->num_dimensions() > 2, "Transpose up to 2-D src tensor is supported");
89
+
90
+ // Validate configured dst
91
+ if(dst->total_size() != 0)
92
+ {
93
+ const TensorInfo dst_info = src->clone()->set_tensor_shape(misc::shape_calculator::compute_transposed_shape(*src));
94
+ ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(dst, &dst_info);
95
+
96
+ ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_QUANTIZATION_INFO(src, dst);
97
+ ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(src, dst);
98
+ }
99
+
100
+ return Status{};
101
+ }
102
+
103
+ void ClTransposeKernel::run_op(ITensorPack &tensors, const Window &window, cl::CommandQueue &queue)
104
+ {
105
+ ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
106
+ ARM_COMPUTE_ERROR_ON_MISMATCHING_WINDOWS(ICLKernel::window(), window);
107
+
108
+ const auto src = utils::cast::polymorphic_downcast<const ICLTensor *>(tensors.get_const_tensor(TensorType::ACL_SRC));
109
+ auto dst = utils::cast::polymorphic_downcast<ICLTensor *>(tensors.get_tensor(TensorType::ACL_DST));
110
+
111
+ Window slice = window.first_slice_window_2D();
112
+
113
+ do
114
+ {
115
+ unsigned int idx = 0;
116
+ add_2D_tensor_argument(idx, src, slice);
117
+ add_2D_tensor_argument(idx, dst, slice);
118
+ enqueue(queue, *this, slice, lws_hint());
119
+ }
120
+ while(window.slide_window_slice_2D(slice));
121
+ }
122
+ } // namespace kernels
123
+ } // namespace opencl
124
+ } // namespace arm_compute
pool/shard001/C++/0022360_AlibavaTimeCutProcessor.cc ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Created by Eda Yildirim
3
+ * (2014 DESY)
4
+ *
5
+ * email:eda.yildirim@cern.ch
6
+ */
7
+
8
+
9
+ // alibava includes ".h"
10
+ #include "AlibavaTimeCutProcessor.h"
11
+ #include "AlibavaRunHeaderImpl.h"
12
+ #include "AlibavaEventImpl.h"
13
+ #include "ALIBAVA.h"
14
+ #include "AlibavaPedNoiCalIOManager.h"
15
+
16
+
17
+ // marlin includes ".h"
18
+ #include "marlin/Processor.h"
19
+ #include "marlin/Exceptions.h"
20
+ #include "marlin/Global.h"
21
+
22
+ #if defined(USE_AIDA) || defined(MARLIN_USE_AIDA)
23
+ // aida includes <.h>
24
+ #include <marlin/AIDAProcessor.h>
25
+ #include <AIDA/ITree.h>
26
+ #endif
27
+
28
+ // lcio includes <.h>
29
+ #include <lcio.h>
30
+ #include <UTIL/LCTOOLS.h>
31
+ #include <UTIL/LCTime.h>
32
+ #include <IMPL/LCEventImpl.h>
33
+ #include <IMPL/TrackerRawDataImpl.h>
34
+ #include <IMPL/TrackerDataImpl.h>
35
+ #include <IMPL/LCEventImpl.h>
36
+
37
+
38
+ // ROOT includes ".h"
39
+ #include "TH1D.h"
40
+
41
+ // system includes <>
42
+ #include <string>
43
+ #include <iostream>
44
+ #include <stdlib.h>
45
+ #include <memory>
46
+
47
+ using namespace std;
48
+ using namespace lcio;
49
+ using namespace marlin;
50
+ using namespace alibava;
51
+
52
+
53
+ AlibavaTimeCutProcessor::AlibavaTimeCutProcessor () :
54
+ AlibavaBaseProcessor("AlibavaTimeCutProcessor"),
55
+ _timecutmin(0.0),
56
+ _timecutmax(100.0),
57
+ _numberOfMaskedEvents(0),
58
+ _hMaskedEventsNumberName("EventNumberOfMaskedEvents")
59
+ {
60
+
61
+ // modify processor description
62
+ _description =
63
+ "AlibavaTimeCutProcessor masks the events if their TDC time value is not in the range specified by TimeCutMin and TimeCutMax ";
64
+
65
+ registerProcessorParameter ("TimeCutMin",
66
+ "The minimum tdc time that is acceptable to use that Event",
67
+ _timecutmin , float(0.0));
68
+
69
+ registerProcessorParameter ("TimeCutMax",
70
+ "The maximum tdc time that is acceptable to use that Event",
71
+ _timecutmax , float(100.0));
72
+
73
+ }
74
+
75
+
76
+ void AlibavaTimeCutProcessor::init () {
77
+ streamlog_out ( MESSAGE4 ) << "Running init" << endl;
78
+
79
+ // this method is called only once even when the rewind is active
80
+ // usually a good idea to
81
+ printParameters ();
82
+
83
+
84
+ }
85
+ void AlibavaTimeCutProcessor::processRunHeader (LCRunHeader * rdr) {
86
+ streamlog_out ( MESSAGE4 ) << "Running processRunHeader" << endl;
87
+
88
+ // Add processor name to the runheader
89
+ auto_ptr<AlibavaRunHeaderImpl> arunHeader ( new AlibavaRunHeaderImpl(rdr)) ;
90
+ arunHeader->addProcessor(type());
91
+
92
+ _numberOfMaskedEvents = 0;
93
+
94
+ bookHistos();
95
+ }
96
+
97
+ void AlibavaTimeCutProcessor::processEvent (LCEvent * anEvent) {
98
+
99
+ //if ( anEvent->getEventNumber() % 1000 == 0 )
100
+ // streamlog_out ( MESSAGE4 ) << "Looping events "<<anEvent->getEventNumber() << endl;
101
+
102
+ AlibavaEventImpl * alibavaEvent = static_cast<AlibavaEventImpl*> (anEvent);
103
+
104
+ float eventTime = alibavaEvent->getEventTime();
105
+ //filling the TDC distr histo
106
+ TH1D * hTDC = dynamic_cast<TH1D*>(_rootObjectMap["hTDC"]);
107
+ hTDC->Fill(eventTime);
108
+
109
+ streamlog_out(DEBUG0)<<"Event Number: "<< anEvent->getEventNumber()<<" Event time: "<<eventTime<<endl;
110
+ if( eventTime < getTimeCutMin() || eventTime > getTimeCutMax() ){
111
+ streamlog_out(DEBUG0)<< "Event time is not in the specified range."<<endl;
112
+ alibavaEvent->maskEvent();
113
+ streamlog_out(DEBUG0)<<"The event masked!"<<endl;
114
+ _numberOfMaskedEvents++;
115
+ }
116
+ }
117
+
118
+ float AlibavaTimeCutProcessor::getTimeCutMin(){
119
+ return _timecutmin;
120
+ }
121
+ float AlibavaTimeCutProcessor::getTimeCutMax(){
122
+ return _timecutmax;
123
+ }
124
+
125
+ void AlibavaTimeCutProcessor::check (LCEvent * /* evt */ ) {
126
+ // nothing to check here - could be used to fill check plots in reconstruction processor
127
+ }
128
+
129
+
130
+ void AlibavaTimeCutProcessor::end() {
131
+
132
+ streamlog_out ( MESSAGE5 ) << _numberOfMaskedEvents << " event masked using timecut "<<getTimeCutMin()<<" - "<<getTimeCutMax()<< endl;
133
+
134
+ streamlog_out ( MESSAGE4 ) << "Successfully finished" << endl;
135
+
136
+ }
137
+
138
+ void AlibavaTimeCutProcessor::fillHistos(AlibavaEventImpl * anAlibavaEvent){
139
+
140
+ int eventnum = anAlibavaEvent->getEventNumber();
141
+
142
+ if (TH1D * histo = dynamic_cast<TH1D*>(_rootObjectMap[_hMaskedEventsNumberName]))
143
+ histo->Fill(eventnum);
144
+
145
+ }
146
+
147
+
148
+ void AlibavaTimeCutProcessor::bookHistos(){
149
+
150
+ AIDAProcessor::tree(this)->cd(this->name());
151
+
152
+ TH1D * _hMaskedEventsNumber = new TH1D (_hMaskedEventsNumberName.c_str(),"", 2, 0, 1000000);
153
+ _rootObjectMap.insert(make_pair(_hMaskedEventsNumberName, _hMaskedEventsNumber));
154
+ _hMaskedEventsNumber->SetTitle("Event Number of Masked Events; Number of Entries;Event Number");
155
+
156
+ TH1D * hTDC = new TH1D ("hTDC","", 202, -1, 200);
157
+ _rootObjectMap.insert(make_pair("hTDC", hTDC));
158
+ hTDC->SetTitle("TDC distribution amond all events; Time [ns]; Number of events");
159
+
160
+ streamlog_out ( MESSAGE1 ) << "End of Booking histograms. " << endl;
161
+ }
162
+
163
+
pool/shard001/C++/0022368_output_custom_factory.cc ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /** Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 Roland Olbricht et al.
2
+ *
3
+ * This file is part of Overpass_API.
4
+ *
5
+ * Overpass_API is free software: you can redistribute it and/or modify
6
+ * it under the terms of the GNU Affero General Public License as
7
+ * published by the Free Software Foundation, either version 3 of the
8
+ * License, or (at your option) any later version.
9
+ *
10
+ * Overpass_API is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ * GNU General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Affero General Public License
16
+ * along with Overpass_API. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+
19
+ #include "../frontend/output_handler_parser.h"
20
+ #include "output_custom.h"
21
+
22
+
23
+ #ifdef HAVE_CONFIG_H
24
+ #include <config.h>
25
+ #undef VERSION
26
+ #endif
27
+
28
+ #ifdef HAVE_CUSTOM_OUTPUT
29
+
30
+
31
+ class Output_Custom_Generator : public Output_Handler_Parser
32
+ {
33
+ public:
34
+ Output_Custom_Generator() : Output_Handler_Parser("custom") {}
35
+
36
+ Output_Handler* new_output_handler(const std::map< std::string, std::string >& input_params,
37
+ Tokenizer_Wrapper* token, Error_Output* error_output);
38
+
39
+ static Output_Custom_Generator singleton;
40
+ };
41
+
42
+
43
+ Output_Custom_Generator Output_Custom_Generator::singleton;
44
+
45
+
46
+ Output_Handler* Output_Custom_Generator::new_output_handler(const std::map< std::string, std::string >& input_params,
47
+ Tokenizer_Wrapper* token, Error_Output* error_output)
48
+ {
49
+ std::map< std::string, std::string >::const_iterator redirect_it = input_params.find("redirect");
50
+
51
+ std::map< std::string, std::string >::const_iterator url_it = input_params.find("url");
52
+ std::string url = (url_it == input_params.end() ?
53
+ "https://www.openstreetmap.org/browse/{{{type}}}/{{{id}}}" : url_it->second);
54
+
55
+ std::map< std::string, std::string >::const_iterator template_it = input_params.find("template");
56
+ std::string template_name = (template_it == input_params.end() ? "default.wiki" : template_it->second);
57
+ // sanity check for template_name
58
+ if (template_name.find("/") != std::string::npos)
59
+ {
60
+ if (error_output)
61
+ error_output->add_encoding_error("Parameter \"template\" must not contain slashes.");
62
+ template_name = "";
63
+ }
64
+
65
+ return new Output_Custom(redirect_it == input_params.end() || redirect_it->second != "no",
66
+ template_name, url);
67
+ }
68
+
69
+ #endif
pool/shard001/C++/0022372_sg_StereoSpatAlgorithm.cpp ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ This file is part of SpatGRIS.
3
+
4
+ Developers: Samuel Béland, Olivier Bélanger, Nicolas Masson
5
+
6
+ SpatGRIS is free software: you can redistribute it and/or modify
7
+ it under the terms of the GNU General Public License as published by
8
+ the Free Software Foundation, either version 3 of the License, or
9
+ (at your option) any later version.
10
+
11
+ SpatGRIS is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU General Public License for more details.
15
+
16
+ You should have received a copy of the GNU General Public License
17
+ along with SpatGRIS. If not, see <http://www.gnu.org/licenses/>.
18
+ */
19
+
20
+ #include "sg_StereoSpatAlgorithm.hpp"
21
+ #include "sg_DummySpatAlgorithm.hpp"
22
+ #include "sg_StaticMap.hpp"
23
+ #include "sg_StrongArray.hpp"
24
+ #include "sg_TaggedAudioBuffer.hpp"
25
+
26
+ //==============================================================================
27
+ void StereoSpatAlgorithm::updateSpatData(source_index_t const sourceIndex, SourceData const & sourceData) noexcept
28
+ {
29
+ jassert(!isProbablyAudioThread());
30
+
31
+ if (sourceData.directOut) {
32
+ return;
33
+ }
34
+
35
+ // using fast = juce::dsp::FastMathApproximations;
36
+
37
+ auto & queue{ mData[sourceIndex].gainsQueue };
38
+ auto * ticket{ queue.acquire() };
39
+ auto & gains{ ticket->get() };
40
+
41
+ if (sourceData.position) {
42
+ auto const x{ std::clamp(sourceData.position->getCartesian().x, -1.0f, 1.0f)
43
+ * (1.0f - sourceData.azimuthSpan) };
44
+
45
+ auto const fromZeroToPi{ (x + 1.0f) * HALF_PI.get() };
46
+
47
+ auto const leftGain{ std::cos(fromZeroToPi) * 0.5f + 0.5f };
48
+ auto const rightGain{ std::cos(PI.get() - fromZeroToPi) * 0.5f + 0.5f };
49
+
50
+ gains[0] = std::pow(leftGain, 0.5f);
51
+ gains[1] = std::pow(rightGain, 0.5f);
52
+ } else {
53
+ gains[0] = 0.0f;
54
+ gains[1] = 0.0f;
55
+ }
56
+
57
+ queue.setMostRecent(ticket);
58
+ }
59
+
60
+ //==============================================================================
61
+ void StereoSpatAlgorithm::process(AudioConfig const & config,
62
+ SourceAudioBuffer & sourcesBuffer,
63
+ SpeakerAudioBuffer & /*speakersBuffer*/,
64
+ juce::AudioBuffer<float> & stereoBuffer,
65
+ SourcePeaks const & sourcePeaks,
66
+ [[maybe_unused]] SpeakersAudioConfig const * altSpeakerConfig)
67
+ {
68
+ ASSERT_AUDIO_THREAD;
69
+ jassert(!altSpeakerConfig);
70
+ jassert(stereoBuffer.getNumChannels() == 2);
71
+
72
+ auto const & gainInterpolation{ config.spatGainsInterpolation };
73
+ auto const gainFactor{ std::pow(gainInterpolation, 0.1f) * 0.0099f + 0.99f };
74
+
75
+ auto const numSamples{ sourcesBuffer.getNumSamples() };
76
+ for (auto const & source : config.sourcesAudioConfig) {
77
+ if (source.value.isMuted || source.value.directOut || sourcePeaks[source.key] < SMALL_GAIN) {
78
+ continue;
79
+ }
80
+
81
+ auto & data{ mData[source.key] };
82
+
83
+ data.gainsQueue.getMostRecent(data.currentGains);
84
+ if (data.currentGains == nullptr) {
85
+ continue;
86
+ }
87
+ auto const & gains{ data.currentGains->get() };
88
+
89
+ auto & lastGains{ data.lastGains };
90
+ auto const * inputSamples{ sourcesBuffer[source.key].getReadPointer(0) };
91
+
92
+ static constexpr std::array<size_t, 2> SPEAKERS{ 0, 1 };
93
+ auto * const * const buffers{ stereoBuffer.getArrayOfWritePointers() };
94
+
95
+ for (auto const & speaker : SPEAKERS) {
96
+ auto & currentGain{ lastGains[speaker] };
97
+ auto const & targetGain{ gains[speaker] };
98
+ auto * outputSamples{ buffers[speaker] };
99
+ if (gainInterpolation == 0.0f) {
100
+ // linear interpolation over buffer size
101
+ auto const gainSlope = (targetGain - currentGain) / narrow<float>(numSamples);
102
+ if (targetGain < SMALL_GAIN && currentGain < SMALL_GAIN) {
103
+ // this is not going to produce any more sounds!
104
+ continue;
105
+ }
106
+ for (int sampleIndex{}; sampleIndex < numSamples; ++sampleIndex) {
107
+ currentGain += gainSlope;
108
+ outputSamples[sampleIndex] += inputSamples[sampleIndex] * currentGain;
109
+ }
110
+ } else {
111
+ // log interpolation with 1st order filter
112
+ for (int sampleIndex{}; sampleIndex < numSamples; ++sampleIndex) {
113
+ currentGain = targetGain + (currentGain - targetGain) * gainFactor;
114
+ if (currentGain < SMALL_GAIN && targetGain < SMALL_GAIN) {
115
+ // If the gain is near zero and the target gain is also near zero, this means that
116
+ // currentGain will no ever increase over this buffer
117
+ break;
118
+ }
119
+ outputSamples[sampleIndex] += inputSamples[sampleIndex] * currentGain;
120
+ }
121
+ }
122
+ }
123
+ }
124
+
125
+ // Apply gain compensation.
126
+ auto const compensation{ std::pow(10.0f, (narrow<float>(config.sourcesAudioConfig.size()) - 1.0f) * -0.005f) };
127
+ stereoBuffer.applyGain(0, numSamples, compensation);
128
+ }
129
+
130
+ //==============================================================================
131
+ juce::Array<Triplet> StereoSpatAlgorithm::getTriplets() const noexcept
132
+ {
133
+ JUCE_ASSERT_MESSAGE_THREAD;
134
+ jassertfalse;
135
+ return juce::Array<Triplet>{};
136
+ }
137
+
138
+ //==============================================================================
139
+ std::unique_ptr<AbstractSpatAlgorithm> StereoSpatAlgorithm::make(SpeakerSetup const & speakerSetup,
140
+ SourcesData const & sources)
141
+ {
142
+ JUCE_ASSERT_MESSAGE_THREAD;
143
+
144
+ return std::make_unique<StereoSpatAlgorithm>(speakerSetup, sources);
145
+ }
146
+
147
+ //==============================================================================
148
+ StereoSpatAlgorithm::StereoSpatAlgorithm(SpeakerSetup const & speakerSetup, SourcesData const & sources)
149
+ {
150
+ JUCE_ASSERT_MESSAGE_THREAD;
151
+ fixDirectOutsIntoPlace(sources, speakerSetup);
152
+ }
pool/shard001/C++/0022376_conststr.cpp ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* vim:ts=4:sw=4:et:sts=4:
2
+ *
3
+ * Copyright 2016 Thunder422. All rights reserved.
4
+ * Distributed under GNU General Public License Version 3
5
+ * (See accompanying file LICENSE or <http://www.gnu.org/licenses/>)
6
+ */
7
+
8
+ #include "code.h"
9
+ #include "conststr.h"
10
+ #include "executer.h"
11
+ #include "recreator.h"
12
+
13
+
14
+ WordType ConstStrDictionary::add(const std::string &string)
15
+ {
16
+ auto entry = Dictionary::add(string);
17
+ if (!entry.exists) {
18
+ str_values.emplace_back(new std::string(string));
19
+ }
20
+ return entry.operand;
21
+ }
22
+
23
+
24
+ void recreateConstStr(Recreator &recreator)
25
+ {
26
+ auto string = std::string {'"'};
27
+ for (auto c : recreator.getConstStrOperand()) {
28
+ string += c;
29
+ if (c == '"') {
30
+ string += c;
31
+ }
32
+ }
33
+ string += '"';
34
+ recreator.push(string);
35
+ }
36
+
37
+ void executeConstStr(Executer &executer)
38
+ {
39
+ auto operand = executer.getOperand();
40
+ executer.pushConstStr(operand);
41
+ }
42
+
43
+ Code const_str_code {recreateConstStr, executeConstStr};
pool/shard001/C++/0022377_z3dprimitiverenderer.cpp ADDED
@@ -0,0 +1,239 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include "zglew.h"
2
+ #include "z3dprimitiverenderer.h"
3
+
4
+ #include "z3dmesh.h"
5
+ #include "z3dgpuinfo.h"
6
+
7
+ Z3DPrimitiveRenderer::Z3DPrimitiveRenderer(QObject *parent)
8
+ : QObject(parent)
9
+ , m_rendererBase(NULL)
10
+ , m_initialized(false)
11
+ , m_needLighting(false)
12
+ , m_useDisplayList(false)
13
+ , m_respectRendererBaseCoordScale(true)
14
+ , m_hardwareSupportVAO(Z3DGpuInfoInstance.isVAOSupported())
15
+ , m_VAO(0)
16
+ , m_pickingVAO(0)
17
+ , m_privateVAO(0)
18
+ {
19
+ }
20
+
21
+ Z3DPrimitiveRenderer::~Z3DPrimitiveRenderer()
22
+ {
23
+ }
24
+
25
+ void Z3DPrimitiveRenderer::initialize()
26
+ {
27
+ if (m_initialized) {
28
+ LERROR() << getClassName() << "already initialized";
29
+ return;
30
+ }
31
+ if (m_hardwareSupportVAO) {
32
+ glGenVertexArrays(1, &m_VAO);
33
+ glGenVertexArrays(1, &m_pickingVAO);
34
+ glGenVertexArrays(1, &m_privateVAO);
35
+ }
36
+ }
37
+
38
+ void Z3DPrimitiveRenderer::deinitialize()
39
+ {
40
+ if (!m_initialized) {
41
+ LERROR() << getClassName() << "not initialized";
42
+ return;
43
+ }
44
+ if (m_hardwareSupportVAO) {
45
+ glDeleteVertexArrays(1, &m_VAO);
46
+ glDeleteVertexArrays(1, &m_pickingVAO);
47
+ glDeleteVertexArrays(1, &m_privateVAO);
48
+ }
49
+ }
50
+
51
+ void Z3DPrimitiveRenderer::addParameter(ZParameter &para)
52
+ {
53
+ addParameter(&para);
54
+ }
55
+
56
+ void Z3DPrimitiveRenderer::addParameter(ZParameter *para)
57
+ {
58
+ m_parameters.push_back(para);
59
+ }
60
+
61
+ std::vector<ZParameter*> Z3DPrimitiveRenderer::getParameters()
62
+ {
63
+ return m_parameters;
64
+ }
65
+
66
+ QString Z3DPrimitiveRenderer::generateHeader()
67
+ {
68
+ return m_rendererBase->generateHeader();
69
+ }
70
+
71
+ void Z3DPrimitiveRenderer::renderScreenQuad(const Z3DShaderProgram &shader, bool depthAlwaysPass)
72
+ {
73
+ if (!shader.isLinked())
74
+ return;
75
+
76
+ if (depthAlwaysPass)
77
+ glDepthFunc(GL_ALWAYS);
78
+
79
+ if (m_hardwareSupportVAO) {
80
+ glBindVertexArray(m_privateVAO);
81
+ }
82
+
83
+ GLfloat vertices[] = {-1.f, 1.f, 0.f, //top left corner
84
+ -1.f, -1.f, 0.f, //bottom left corner
85
+ 1.f, 1.f, 0.f, //top right corner
86
+ 1.f, -1.f, 0.f}; // bottom right rocner
87
+ GLint attr_vertex = shader.attributeLocation("attr_vertex");
88
+
89
+ GLuint bufObjects[1];
90
+ glGenBuffers(1, bufObjects);
91
+
92
+ glEnableVertexAttribArray(attr_vertex);
93
+ glBindBuffer(GL_ARRAY_BUFFER, bufObjects[0]);
94
+ glBufferData(GL_ARRAY_BUFFER, 3*4*sizeof(GLfloat), vertices, GL_STATIC_DRAW);
95
+ glVertexAttribPointer(attr_vertex, 3, GL_FLOAT, GL_FALSE, 0, 0);
96
+
97
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
98
+
99
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
100
+ glDeleteBuffers(1, bufObjects);
101
+
102
+ glDisableVertexAttribArray(attr_vertex);
103
+
104
+ if (m_hardwareSupportVAO) {
105
+ glBindVertexArray(0);
106
+ }
107
+
108
+ if (depthAlwaysPass)
109
+ glDepthFunc(GL_LESS);
110
+ }
111
+
112
+ void Z3DPrimitiveRenderer::renderTriangleList(const Z3DShaderProgram &shader, const Z3DTriangleList &mesh)
113
+ {
114
+ if (mesh.empty() || !shader.isLinked())
115
+ return;
116
+
117
+ const std::vector<glm::vec3>& vertices = mesh.getVertices();
118
+ const std::vector<float>& textureCoordinates1D = mesh.get1DTextureCoordinates();
119
+ const std::vector<glm::vec2>& textureCoordinates2D = mesh.get2DTextureCoordinates();
120
+ const std::vector<glm::vec3>& textureCoordinates3D = mesh.get3DTextureCoordinates();
121
+ const std::vector<glm::vec3>& normals = mesh.getNormals();
122
+ const std::vector<glm::vec4>& colors = mesh.getColors();
123
+ const std::vector<GLuint>& triangleIndexes = mesh.getIndices();
124
+ GLenum type = mesh.getTriangleListType();
125
+
126
+ if (m_hardwareSupportVAO) {
127
+ glBindVertexArray(m_privateVAO);
128
+ }
129
+
130
+ GLint attr_vertex = shader.attributeLocation("attr_vertex");
131
+ GLint attr_1dTexCoord0 = shader.attributeLocation("attr_1dTexCoord0");
132
+ GLint attr_2dTexCoord0 = shader.attributeLocation("attr_2dTexCoord0");
133
+ GLint attr_3dTexCoord0 = shader.attributeLocation("attr_3dTexCoord0");
134
+ GLint attr_normal = shader.attributeLocation("attr_normal");
135
+ GLint attr_color = shader.attributeLocation("attr_color");
136
+
137
+ GLsizei bufObjectsSize = 1; // vertex
138
+ if (attr_1dTexCoord0 != -1 && !textureCoordinates1D.empty())
139
+ bufObjectsSize++;
140
+ if (attr_2dTexCoord0 != -1 && !textureCoordinates2D.empty())
141
+ bufObjectsSize++;
142
+ if (attr_3dTexCoord0 != -1 && !textureCoordinates3D.empty())
143
+ bufObjectsSize++;
144
+ if (attr_normal != -1 && !normals.empty())
145
+ bufObjectsSize++;
146
+ if (attr_color != -1 && !colors.empty())
147
+ bufObjectsSize++;
148
+ if (!triangleIndexes.empty())
149
+ bufObjectsSize++;
150
+
151
+ GLuint *bufObjects = new GLuint[bufObjectsSize];
152
+ glGenBuffers(bufObjectsSize, bufObjects);
153
+
154
+ int bufIdx = 0;
155
+ glEnableVertexAttribArray(attr_vertex);
156
+ glBindBuffer(GL_ARRAY_BUFFER, bufObjects[bufIdx++]);
157
+ glBufferData(GL_ARRAY_BUFFER, vertices.size()*3*sizeof(GLfloat), &(vertices[0]), GL_STATIC_DRAW);
158
+ glVertexAttribPointer(attr_vertex, 3, GL_FLOAT, GL_FALSE, 0, 0);
159
+
160
+ if (attr_1dTexCoord0 != -1 && !textureCoordinates1D.empty()) {
161
+ glEnableVertexAttribArray(attr_1dTexCoord0);
162
+ glBindBuffer(GL_ARRAY_BUFFER, bufObjects[bufIdx++]);
163
+ glBufferData(GL_ARRAY_BUFFER, textureCoordinates1D.size()*1*sizeof(GLfloat), &(textureCoordinates1D[0]), GL_STATIC_DRAW);
164
+ glVertexAttribPointer(attr_1dTexCoord0, 1, GL_FLOAT, GL_FALSE, 0, 0);
165
+ }
166
+
167
+ if (attr_2dTexCoord0 != -1 && !textureCoordinates2D.empty()) {
168
+ glEnableVertexAttribArray(attr_2dTexCoord0);
169
+ glBindBuffer(GL_ARRAY_BUFFER, bufObjects[bufIdx++]);
170
+ glBufferData(GL_ARRAY_BUFFER, textureCoordinates2D.size()*2*sizeof(GLfloat), &(textureCoordinates2D[0]), GL_STATIC_DRAW);
171
+ glVertexAttribPointer(attr_2dTexCoord0, 2, GL_FLOAT, GL_FALSE, 0, 0);
172
+ }
173
+
174
+ if (attr_3dTexCoord0 != -1 && !textureCoordinates3D.empty()) {
175
+ glEnableVertexAttribArray(attr_3dTexCoord0);
176
+ glBindBuffer(GL_ARRAY_BUFFER, bufObjects[bufIdx++]);
177
+ glBufferData(GL_ARRAY_BUFFER, textureCoordinates3D.size()*3*sizeof(GLfloat), &(textureCoordinates3D[0]), GL_STATIC_DRAW);
178
+ glVertexAttribPointer(attr_3dTexCoord0, 3, GL_FLOAT, GL_FALSE, 0, 0);
179
+ }
180
+
181
+ if (attr_normal != -1 && !normals.empty()) {
182
+ glEnableVertexAttribArray(attr_normal);
183
+ glBindBuffer(GL_ARRAY_BUFFER, bufObjects[bufIdx++]);
184
+ glBufferData(GL_ARRAY_BUFFER, normals.size()*3*sizeof(GLfloat), &(normals[0]), GL_STATIC_DRAW);
185
+ glVertexAttribPointer(attr_normal, 3, GL_FLOAT, GL_FALSE, 0, 0);
186
+ }
187
+
188
+ if (attr_color != -1 && !colors.empty()) {
189
+ glEnableVertexAttribArray(attr_color);
190
+ glBindBuffer(GL_ARRAY_BUFFER, bufObjects[bufIdx++]);
191
+ glBufferData(GL_ARRAY_BUFFER, colors.size()*4*sizeof(GLfloat), &(colors[0]), GL_STATIC_DRAW);
192
+ glVertexAttribPointer(attr_color, 4, GL_FLOAT, GL_FALSE, 0, 0);
193
+ }
194
+
195
+ if (triangleIndexes.empty()) {
196
+ glDrawArrays(type, 0, vertices.size());
197
+ } else {
198
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufObjects[bufIdx++]);
199
+ glBufferData(GL_ELEMENT_ARRAY_BUFFER, triangleIndexes.size()*sizeof(GLuint), &(triangleIndexes[0]), GL_STATIC_DRAW);
200
+ glDrawElements(type, triangleIndexes.size(), GL_UNSIGNED_INT, 0);
201
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
202
+ }
203
+
204
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
205
+ glDeleteBuffers(bufObjectsSize, bufObjects);
206
+ delete bufObjects;
207
+
208
+ glDisableVertexAttribArray(attr_vertex);
209
+ if (attr_1dTexCoord0 != -1 && !textureCoordinates1D.empty())
210
+ glDisableVertexAttribArray(attr_1dTexCoord0);
211
+ if (attr_2dTexCoord0 != -1 && !textureCoordinates2D.empty())
212
+ glDisableVertexAttribArray(attr_2dTexCoord0);
213
+ if (attr_3dTexCoord0 != -1 && !textureCoordinates3D.empty())
214
+ glDisableVertexAttribArray(attr_3dTexCoord0);
215
+ if (attr_normal != -1 && !normals.empty())
216
+ glDisableVertexAttribArray(attr_normal);
217
+ if (attr_color != -1 && !colors.empty())
218
+ glDisableVertexAttribArray(attr_color);
219
+
220
+ if (m_hardwareSupportVAO) {
221
+ glBindVertexArray(0);
222
+ }
223
+ }
224
+
225
+ void Z3DPrimitiveRenderer::invalidateOpenglRenderer()
226
+ {
227
+ if (m_useDisplayList)
228
+ emit openglRendererInvalid();
229
+ }
230
+
231
+ void Z3DPrimitiveRenderer::invalidateOpenglPickingRenderer()
232
+ {
233
+ if (m_useDisplayList)
234
+ emit openglPickingRendererInvalid();
235
+ }
236
+
237
+ void Z3DPrimitiveRenderer::coordScalesChanged()
238
+ {
239
+ }
pool/shard001/C++/0022380_TiledTileLayer.cpp ADDED
@@ -0,0 +1,268 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright (c) 2015 fjz13. All rights reserved.
2
+ // Use of this source code is governed by a MIT-style
3
+ // license that can be found in the LICENSE file.
4
+ #include "MedusaPreCompiled.h"
5
+ #include "TiledTileLayer.h"
6
+ #include "Core/Compress/ZipReader.h"
7
+ #include "Core/Coder/Crypt/Base64Decoder.h"
8
+ #include "Core/Log/Log.h"
9
+ #include "TiledTilesetRef.h"
10
+ #include "TiledMap.h"
11
+ #include "Node/Layer/NormalLayer.h"
12
+ #include "TiledTileset.h"
13
+ #include "Node/NodeFactory.h"
14
+ #include "CoreLib/Common/pugixml/pugixml.hpp"
15
+ #include "TiledMapInstantiateInfo.h"
16
+ #include "Node/Input/InputDispatcher.h"
17
+
18
+ MEDUSA_BEGIN;
19
+ TiledTileLayer::TiledTileLayer()
20
+ {
21
+ }
22
+
23
+ TiledTileLayer::~TiledTileLayer()
24
+ {
25
+ }
26
+
27
+ bool TiledTileLayer::Parse(const pugi::xml_node& node)
28
+ {
29
+ RETURN_FALSE_IF_FALSE(ITiledLayer::Parse(node));
30
+
31
+ pugi::xml_node dataNode = node.child("data");
32
+ StringRef encodingStr = dataNode.attribute("encoding").as_string(nullptr);
33
+ StringRef compressionStr = dataNode.attribute("compression").as_string(nullptr);
34
+ StringRef text = dataNode.child_value();
35
+ uint jump = 0;
36
+ for (; jump < text.Length(); jump++)
37
+ {
38
+ BREAK_IF(StdString::IsAlpha(text[jump]));
39
+ }
40
+
41
+ text = text.SubString(jump); //skip "\n "
42
+
43
+ if (encodingStr == "base64")
44
+ {
45
+ Base64Decoder decoder;
46
+ MemoryData data = decoder.Code(text);
47
+ MemoryData resultData;
48
+ if (compressionStr == "gzip")
49
+ {
50
+ #ifdef MEDUSA_UNZIP
51
+ resultData = ZipReader::DecompressGZIP(data, mSize.Area() * sizeof(uint));
52
+ #endif
53
+
54
+ }
55
+ else if (compressionStr == "zlib")
56
+ {
57
+ #ifdef MEDUSA_ZLIB
58
+ // Use zlib to uncompress the tile layer into the temporary array of tiles.
59
+ uLongf outlen = mSize.Area() * sizeof(uint);
60
+ resultData = MemoryData::Alloc(outlen);
61
+ int err = uncompress(resultData.MutableData(), &outlen, data.Data(), data.Size());
62
+ if (err != 0)
63
+ {
64
+ Log::FormatError("decompression error:{}", err);
65
+ return false;
66
+ }
67
+ #endif
68
+ }
69
+ else if (compressionStr.IsEmpty())
70
+ {
71
+ resultData = data;
72
+ }
73
+ else
74
+ {
75
+ Log::FormatError("Unsupported compression type:{}", compressionStr.c_str());
76
+ return false;
77
+ }
78
+
79
+ const uint* buffer = (const uint*)resultData.Data();
80
+ InitializeTiles();
81
+
82
+ //the decoded data is an array of 32 - bit integers.
83
+ uint tileCount = mSize.Area();
84
+ FOR_EACH_UINT32(i, tileCount)
85
+ {
86
+ uint globalId = buffer[i];
87
+ TiledTileRef& tileRef = MutableTile(i);
88
+
89
+ const TiledTilesetRef* tilesetRef = mMap->FindTilesetContainsGlobalId(globalId);
90
+ tileRef.Initialize(Point2I(i%mSize.Width, AdjustY(i / mSize.Height)), globalId, tilesetRef);
91
+ tileRef.SetLayer(this);
92
+ }
93
+ }
94
+ else if (encodingStr == "csv")
95
+ {
96
+ int index = 0;
97
+ List<uint> outValues;
98
+ StringParser::SplitToValues(text, StringRef(","), outValues);
99
+ for (auto globalId : outValues)
100
+ {
101
+ TiledTileRef& tileRef = MutableTile(index);
102
+ const TiledTilesetRef* tileset = mMap->FindTilesetContainsGlobalId(globalId);
103
+ tileRef.Initialize(Point2I(index%mSize.Width, AdjustY(index / mSize.Height)), globalId, tileset);
104
+ tileRef.SetLayer(this);
105
+ ++index;
106
+ }
107
+
108
+ }
109
+ else if (encodingStr == "xml")
110
+ {
111
+ int index = 0;
112
+ for (auto tileNode : node.children())
113
+ {
114
+ uint globalId = tileNode.attribute("gid").as_uint(0);
115
+ TiledTileRef& tileRef = MutableTile(index);
116
+ const TiledTilesetRef* tileset = mMap->FindTilesetContainsGlobalId(globalId);
117
+ tileRef.Initialize(Point2I(index%mSize.Width, AdjustY(index / mSize.Height)), globalId, tileset);
118
+ tileRef.SetLayer(this);
119
+ ++index;
120
+ }
121
+ }
122
+ else
123
+ {
124
+ Log::FormatError("Unsupported encoding type:{}", encodingStr.c_str());
125
+ return false;
126
+ }
127
+
128
+ AnalyzeTiles();
129
+
130
+ return true;
131
+ }
132
+
133
+ void TiledTileLayer::InitializeTiles()
134
+ {
135
+ mTiles.ForceReserveCount(mSize.Area());
136
+ }
137
+
138
+ void TiledTileLayer::AnalyzeTiles()
139
+ {
140
+ mHasSingleTexture = true;
141
+ TextureAtlasPage* uniqueTexturePage = nullptr;
142
+
143
+ for (const auto& tileRef : mTiles)
144
+ {
145
+ auto* tile = tileRef.Tile();
146
+ CONTINUE_IF_NULL(tile);
147
+ auto* texturePage = tile->Page();
148
+ CONTINUE_IF_NULL(texturePage);
149
+
150
+ if (uniqueTexturePage == nullptr)
151
+ {
152
+ uniqueTexturePage = texturePage;
153
+ }
154
+ else if (uniqueTexturePage != texturePage)
155
+ {
156
+ mHasSingleTexture = false;
157
+ return;
158
+ }
159
+ }
160
+
161
+ }
162
+
163
+ INode* TiledTileLayer::Instantiate(NodeInstantiateInfo* instantiateInfo /*= nullptr*/)const
164
+ {
165
+ TiledMapInstantiateInfo* mapInstantiateInfo = (TiledMapInstantiateInfo*)instantiateInfo;
166
+
167
+ InstantiateMode mode = InstantiateMode::None;
168
+ if (instantiateInfo != nullptr)
169
+ {
170
+ mode = instantiateInfo->Mode;
171
+ }
172
+
173
+ if (mode == InstantiateMode::None)
174
+ {
175
+ mode = mInstantiateMode; //use config rendering mode
176
+ }
177
+
178
+ if (!mHasSingleTexture)
179
+ {
180
+ mode = InstantiateMode::Sprite;
181
+ }
182
+
183
+
184
+ INode* curLayer = nullptr;
185
+ if (instantiateInfo != nullptr)
186
+ {
187
+ curLayer = instantiateInfo->ParentNode;
188
+ }
189
+
190
+ if (curLayer == nullptr)
191
+ {
192
+ StringRef layerClassName = mInstantiateLayer;
193
+ if (layerClassName.IsEmpty())
194
+ {
195
+ layerClassName = NormalLayer::ClassNameStatic();
196
+ }
197
+
198
+ curLayer = NodeFactory::Instance().Create(layerClassName);
199
+ }
200
+
201
+ Point2I offset = Point2I::Zero;
202
+ if (instantiateInfo != nullptr)
203
+ {
204
+ offset = mapInstantiateInfo->Offset;
205
+ }
206
+ switch (mode)
207
+ {
208
+ case InstantiateMode::None:
209
+ case InstantiateMode::Mesh:
210
+ {
211
+ //create quad mesh
212
+ /*for (const auto& tileRef : mTiles)
213
+ {
214
+
215
+ }*/
216
+ }
217
+
218
+ break;
219
+ case InstantiateMode::Sprite:
220
+ for (const auto& tileRef : mTiles)
221
+ {
222
+ INode* node = tileRef.Instantiate(instantiateInfo);
223
+ if (node != nullptr)
224
+ {
225
+ Point2I tilePos = tileRef.Position()+offset;
226
+ curLayer->AddChild(node);
227
+ Point2F pos = mPosition;
228
+ pos.X += tilePos.X*mMap->TileSize().Width;
229
+ pos.Y += tilePos.Y*mMap->TileSize().Height; //from top down
230
+ node->SetPosition(pos);
231
+ }
232
+ }
233
+ break;
234
+ default:
235
+ break;
236
+ }
237
+
238
+ curLayer->SetName(mName);
239
+ curLayer->SetOpacity(mOpacity);
240
+ curLayer->SetState(mRunningState);
241
+ curLayer->SetVisible(mIsVisible);
242
+ curLayer->MutableInput().Enable(mInputEnabled);
243
+
244
+ if (mapInstantiateInfo != nullptr&&mapInstantiateInfo->UpdateSize)
245
+ {
246
+ Size2F newSize = mMap->PixelSize();
247
+ newSize.Width += mapInstantiateInfo->Offset.X*mMap->Width();
248
+ newSize.Height += mapInstantiateInfo->Offset.Y*mMap->Height();
249
+ curLayer->SetSize(newSize);
250
+ curLayer->SetStretch(Stretch::None); //not stretch
251
+ }
252
+
253
+
254
+ #ifdef MEDUSA_SCRIPT
255
+ if (!mScriptFile.IsEmpty())
256
+ {
257
+ curLayer->TryAddScriptFile(mScriptFile);
258
+ }
259
+ #endif
260
+
261
+ return curLayer;
262
+
263
+ }
264
+
265
+
266
+
267
+
268
+ MEDUSA_END;
pool/shard001/C++/0022382_FailoverRouteTest.cpp ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright (c) 2015, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
+ * of patent rights can be found in the PATENTS file in the same directory.
8
+ *
9
+ */
10
+ #include <memory>
11
+ #include <vector>
12
+
13
+ #include <gtest/gtest.h>
14
+
15
+ #include "mcrouter/lib/McReply.h"
16
+ #include "mcrouter/lib/McRequest.h"
17
+ #include "mcrouter/lib/routes/FailoverRoute.h"
18
+ #include "mcrouter/lib/test/RouteHandleTestUtil.h"
19
+
20
+ using namespace facebook::memcache;
21
+
22
+ using std::make_shared;
23
+ using std::vector;
24
+
25
+ TEST(failoverRouteTest, success) {
26
+ vector<std::shared_ptr<TestHandle>> test_handles{
27
+ make_shared<TestHandle>(GetRouteTestData(mc_res_found, "a")),
28
+ make_shared<TestHandle>(GetRouteTestData(mc_res_found, "b")),
29
+ make_shared<TestHandle>(GetRouteTestData(mc_res_found, "c"))
30
+ };
31
+
32
+ TestRouteHandle<FailoverRoute<TestRouteHandleIf>> rh(
33
+ get_route_handles(test_handles));
34
+
35
+ auto reply = rh.route(McRequest("0"), McOperation<mc_op_get>());
36
+ EXPECT_TRUE(toString(reply.value()) == "a");
37
+ }
38
+
39
+ TEST(failoverRouteTest, once) {
40
+ vector<std::shared_ptr<TestHandle>> test_handles{
41
+ make_shared<TestHandle>(GetRouteTestData(mc_res_timeout, "a")),
42
+ make_shared<TestHandle>(GetRouteTestData(mc_res_found, "b")),
43
+ make_shared<TestHandle>(GetRouteTestData(mc_res_found, "c"))
44
+ };
45
+
46
+ TestRouteHandle<FailoverRoute<TestRouteHandleIf>> rh(
47
+ get_route_handles(test_handles));
48
+
49
+ auto reply = rh.route(McRequest("0"), McOperation<mc_op_get>());
50
+ EXPECT_TRUE(toString(reply.value()) == "b");
51
+ }
52
+
53
+ TEST(failoverRouteTest, twice) {
54
+ vector<std::shared_ptr<TestHandle>> test_handles{
55
+ make_shared<TestHandle>(GetRouteTestData(mc_res_timeout, "a")),
56
+ make_shared<TestHandle>(GetRouteTestData(mc_res_timeout, "b")),
57
+ make_shared<TestHandle>(GetRouteTestData(mc_res_found, "c"))
58
+ };
59
+
60
+ TestRouteHandle<FailoverRoute<TestRouteHandleIf>> rh(
61
+ get_route_handles(test_handles));
62
+
63
+ auto reply = rh.route(McRequest("0"), McOperation<mc_op_get>());
64
+ EXPECT_TRUE(toString(reply.value()) == "c");
65
+ }
66
+
67
+ TEST(failoverRouteTest, fail) {
68
+ vector<std::shared_ptr<TestHandle>> test_handles{
69
+ make_shared<TestHandle>(GetRouteTestData(mc_res_timeout, "a")),
70
+ make_shared<TestHandle>(GetRouteTestData(mc_res_timeout, "b")),
71
+ make_shared<TestHandle>(GetRouteTestData(mc_res_timeout, "c"))
72
+ };
73
+
74
+ TestRouteHandle<FailoverRoute<TestRouteHandleIf>> rh(
75
+ get_route_handles(test_handles));
76
+
77
+ auto reply = rh.route(McRequest("0"), McOperation<mc_op_get>());
78
+
79
+ /* Will return the last reply when ran out of targets */
80
+ EXPECT_EQ(toString(reply.value()), "c");
81
+ }
pool/shard001/C++/0022383_moc_html5applicationviewer.cpp ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /****************************************************************************
2
+ ** Meta object code from reading C++ file 'html5applicationviewer.h'
3
+ **
4
+ ** Created by: The Qt Meta Object Compiler version 67 (Qt 5.0.2)
5
+ **
6
+ ** WARNING! All changes made in this file will be lost!
7
+ *****************************************************************************/
8
+
9
+ #include "../untitled/html5applicationviewer/html5applicationviewer.h"
10
+ #include <QtCore/qbytearray.h>
11
+ #include <QtCore/qmetatype.h>
12
+ #if !defined(Q_MOC_OUTPUT_REVISION)
13
+ #error "The header file 'html5applicationviewer.h' doesn't include <QObject>."
14
+ #elif Q_MOC_OUTPUT_REVISION != 67
15
+ #error "This file was generated using the moc from 5.0.2. It"
16
+ #error "cannot be used with the include files from this version of Qt."
17
+ #error "(The moc has changed too much.)"
18
+ #endif
19
+
20
+ QT_BEGIN_MOC_NAMESPACE
21
+ struct qt_meta_stringdata_Html5ApplicationViewer_t {
22
+ QByteArrayData data[1];
23
+ char stringdata[24];
24
+ };
25
+ #define QT_MOC_LITERAL(idx, ofs, len) \
26
+ Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \
27
+ offsetof(qt_meta_stringdata_Html5ApplicationViewer_t, stringdata) + ofs \
28
+ - idx * sizeof(QByteArrayData) \
29
+ )
30
+ static const qt_meta_stringdata_Html5ApplicationViewer_t qt_meta_stringdata_Html5ApplicationViewer = {
31
+ {
32
+ QT_MOC_LITERAL(0, 0, 22)
33
+ },
34
+ "Html5ApplicationViewer\0"
35
+ };
36
+ #undef QT_MOC_LITERAL
37
+
38
+ static const uint qt_meta_data_Html5ApplicationViewer[] = {
39
+
40
+ // content:
41
+ 7, // revision
42
+ 0, // classname
43
+ 0, 0, // classinfo
44
+ 0, 0, // methods
45
+ 0, 0, // properties
46
+ 0, 0, // enums/sets
47
+ 0, 0, // constructors
48
+ 0, // flags
49
+ 0, // signalCount
50
+
51
+ 0 // eod
52
+ };
53
+
54
+ void Html5ApplicationViewer::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
55
+ {
56
+ Q_UNUSED(_o);
57
+ Q_UNUSED(_id);
58
+ Q_UNUSED(_c);
59
+ Q_UNUSED(_a);
60
+ }
61
+
62
+ const QMetaObject Html5ApplicationViewer::staticMetaObject = {
63
+ { &QWidget::staticMetaObject, qt_meta_stringdata_Html5ApplicationViewer.data,
64
+ qt_meta_data_Html5ApplicationViewer, qt_static_metacall, 0, 0}
65
+ };
66
+
67
+
68
+ const QMetaObject *Html5ApplicationViewer::metaObject() const
69
+ {
70
+ return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
71
+ }
72
+
73
+ void *Html5ApplicationViewer::qt_metacast(const char *_clname)
74
+ {
75
+ if (!_clname) return 0;
76
+ if (!strcmp(_clname, qt_meta_stringdata_Html5ApplicationViewer.stringdata))
77
+ return static_cast<void*>(const_cast< Html5ApplicationViewer*>(this));
78
+ return QWidget::qt_metacast(_clname);
79
+ }
80
+
81
+ int Html5ApplicationViewer::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
82
+ {
83
+ _id = QWidget::qt_metacall(_c, _id, _a);
84
+ if (_id < 0)
85
+ return _id;
86
+ return _id;
87
+ }
88
+ QT_END_MOC_NAMESPACE
pool/shard001/C++/0022386_packet_peer.cpp ADDED
@@ -0,0 +1,295 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*************************************************************************/
2
+ /* packet_peer.cpp */
3
+ /*************************************************************************/
4
+ /* This file is part of: */
5
+ /* GODOT ENGINE */
6
+ /* https://godotengine.org */
7
+ /*************************************************************************/
8
+ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
9
+ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
10
+ /* */
11
+ /* Permission is hereby granted, free of charge, to any person obtaining */
12
+ /* a copy of this software and associated documentation files (the */
13
+ /* "Software"), to deal in the Software without restriction, including */
14
+ /* without limitation the rights to use, copy, modify, merge, publish, */
15
+ /* distribute, sublicense, and/or sell copies of the Software, and to */
16
+ /* permit persons to whom the Software is furnished to do so, subject to */
17
+ /* the following conditions: */
18
+ /* */
19
+ /* The above copyright notice and this permission notice shall be */
20
+ /* included in all copies or substantial portions of the Software. */
21
+ /* */
22
+ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
+ /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
+ /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
25
+ /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
+ /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
+ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
+ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
+ /*************************************************************************/
30
+ #include "packet_peer.h"
31
+
32
+ #include "io/marshalls.h"
33
+ #include "project_settings.h"
34
+ /* helpers / binders */
35
+
36
+ PacketPeer::PacketPeer() {
37
+
38
+ allow_object_decoding = false;
39
+ last_get_error = OK;
40
+ }
41
+
42
+ void PacketPeer::set_allow_object_decoding(bool p_enable) {
43
+
44
+ allow_object_decoding = p_enable;
45
+ }
46
+
47
+ bool PacketPeer::is_object_decoding_allowed() const {
48
+
49
+ return allow_object_decoding;
50
+ }
51
+
52
+ Error PacketPeer::get_packet_buffer(PoolVector<uint8_t> &r_buffer) const {
53
+
54
+ const uint8_t *buffer;
55
+ int buffer_size;
56
+ Error err = get_packet(&buffer, buffer_size);
57
+ if (err)
58
+ return err;
59
+
60
+ r_buffer.resize(buffer_size);
61
+ if (buffer_size == 0)
62
+ return OK;
63
+
64
+ PoolVector<uint8_t>::Write w = r_buffer.write();
65
+ for (int i = 0; i < buffer_size; i++)
66
+ w[i] = buffer[i];
67
+
68
+ return OK;
69
+ }
70
+
71
+ Error PacketPeer::put_packet_buffer(const PoolVector<uint8_t> &p_buffer) {
72
+
73
+ int len = p_buffer.size();
74
+ if (len == 0)
75
+ return OK;
76
+
77
+ PoolVector<uint8_t>::Read r = p_buffer.read();
78
+ return put_packet(&r[0], len);
79
+ }
80
+
81
+ Error PacketPeer::get_var(Variant &r_variant) const {
82
+
83
+ const uint8_t *buffer;
84
+ int buffer_size;
85
+ Error err = get_packet(&buffer, buffer_size);
86
+ if (err)
87
+ return err;
88
+
89
+ return decode_variant(r_variant, buffer, buffer_size, NULL, allow_object_decoding);
90
+ }
91
+
92
+ Error PacketPeer::put_var(const Variant &p_packet) {
93
+
94
+ int len;
95
+ Error err = encode_variant(p_packet, NULL, len, !allow_object_decoding); // compute len first
96
+ if (err)
97
+ return err;
98
+
99
+ if (len == 0)
100
+ return OK;
101
+
102
+ uint8_t *buf = (uint8_t *)alloca(len);
103
+ ERR_FAIL_COND_V(!buf, ERR_OUT_OF_MEMORY);
104
+ err = encode_variant(p_packet, buf, len, !allow_object_decoding);
105
+ ERR_FAIL_COND_V(err, err);
106
+
107
+ return put_packet(buf, len);
108
+ }
109
+
110
+ Variant PacketPeer::_bnd_get_var() const {
111
+ Variant var;
112
+ get_var(var);
113
+
114
+ return var;
115
+ };
116
+
117
+ Error PacketPeer::_put_packet(const PoolVector<uint8_t> &p_buffer) {
118
+ return put_packet_buffer(p_buffer);
119
+ }
120
+ PoolVector<uint8_t> PacketPeer::_get_packet() const {
121
+
122
+ PoolVector<uint8_t> raw;
123
+ last_get_error = get_packet_buffer(raw);
124
+ return raw;
125
+ }
126
+
127
+ Error PacketPeer::_get_packet_error() const {
128
+
129
+ return last_get_error;
130
+ }
131
+
132
+ void PacketPeer::_bind_methods() {
133
+
134
+ ClassDB::bind_method(D_METHOD("get_var"), &PacketPeer::_bnd_get_var);
135
+ ClassDB::bind_method(D_METHOD("put_var", "var"), &PacketPeer::put_var);
136
+ ClassDB::bind_method(D_METHOD("get_packet"), &PacketPeer::_get_packet);
137
+ ClassDB::bind_method(D_METHOD("put_packet", "buffer"), &PacketPeer::_put_packet);
138
+ ClassDB::bind_method(D_METHOD("get_packet_error"), &PacketPeer::_get_packet_error);
139
+ ClassDB::bind_method(D_METHOD("get_available_packet_count"), &PacketPeer::get_available_packet_count);
140
+
141
+ ClassDB::bind_method(D_METHOD("set_allow_object_decoding", "enable"), &PacketPeer::set_allow_object_decoding);
142
+ ClassDB::bind_method(D_METHOD("is_object_decoding_allowed"), &PacketPeer::is_object_decoding_allowed);
143
+ };
144
+
145
+ /***************/
146
+
147
+ void PacketPeerStream::_set_stream_peer(REF p_peer) {
148
+
149
+ ERR_FAIL_COND(p_peer.is_null());
150
+ set_stream_peer(p_peer);
151
+ }
152
+
153
+ void PacketPeerStream::_bind_methods() {
154
+
155
+ ClassDB::bind_method(D_METHOD("set_stream_peer", "peer"), &PacketPeerStream::_set_stream_peer);
156
+ ClassDB::bind_method(D_METHOD("set_input_buffer_max_size", "max_size_bytes"), &PacketPeerStream::set_input_buffer_max_size);
157
+ ClassDB::bind_method(D_METHOD("set_output_buffer_max_size", "max_size_bytes"), &PacketPeerStream::set_output_buffer_max_size);
158
+ ClassDB::bind_method(D_METHOD("get_input_buffer_max_size"), &PacketPeerStream::get_input_buffer_max_size);
159
+ ClassDB::bind_method(D_METHOD("get_output_buffer_max_size"), &PacketPeerStream::get_output_buffer_max_size);
160
+ }
161
+
162
+ Error PacketPeerStream::_poll_buffer() const {
163
+
164
+ ERR_FAIL_COND_V(peer.is_null(), ERR_UNCONFIGURED);
165
+
166
+ int read = 0;
167
+ Error err = peer->get_partial_data(&input_buffer[0], ring_buffer.space_left(), read);
168
+ if (err)
169
+ return err;
170
+ if (read == 0)
171
+ return OK;
172
+
173
+ int w = ring_buffer.write(&input_buffer[0], read);
174
+ ERR_FAIL_COND_V(w != read, ERR_BUG);
175
+
176
+ return OK;
177
+ }
178
+
179
+ int PacketPeerStream::get_available_packet_count() const {
180
+
181
+ _poll_buffer();
182
+
183
+ uint32_t remaining = ring_buffer.data_left();
184
+
185
+ int ofs = 0;
186
+ int count = 0;
187
+
188
+ while (remaining >= 4) {
189
+
190
+ uint8_t lbuf[4];
191
+ ring_buffer.copy(lbuf, ofs, 4);
192
+ uint32_t len = decode_uint32(lbuf);
193
+ remaining -= 4;
194
+ ofs += 4;
195
+ if (len > remaining)
196
+ break;
197
+ remaining -= len;
198
+ ofs += len;
199
+ count++;
200
+ }
201
+
202
+ return count;
203
+ }
204
+
205
+ Error PacketPeerStream::get_packet(const uint8_t **r_buffer, int &r_buffer_size) const {
206
+
207
+ ERR_FAIL_COND_V(peer.is_null(), ERR_UNCONFIGURED);
208
+ _poll_buffer();
209
+
210
+ int remaining = ring_buffer.data_left();
211
+ ERR_FAIL_COND_V(remaining < 4, ERR_UNAVAILABLE);
212
+ uint8_t lbuf[4];
213
+ ring_buffer.copy(lbuf, 0, 4);
214
+ remaining -= 4;
215
+ uint32_t len = decode_uint32(lbuf);
216
+ ERR_FAIL_COND_V(remaining < (int)len, ERR_UNAVAILABLE);
217
+
218
+ ring_buffer.read(lbuf, 4); //get rid of first 4 bytes
219
+ ring_buffer.read(&input_buffer[0], len); // read packet
220
+
221
+ *r_buffer = &input_buffer[0];
222
+ r_buffer_size = len;
223
+ return OK;
224
+ }
225
+
226
+ Error PacketPeerStream::put_packet(const uint8_t *p_buffer, int p_buffer_size) {
227
+
228
+ ERR_FAIL_COND_V(peer.is_null(), ERR_UNCONFIGURED);
229
+ Error err = _poll_buffer(); //won't hurt to poll here too
230
+
231
+ if (err)
232
+ return err;
233
+
234
+ if (p_buffer_size == 0)
235
+ return OK;
236
+
237
+ ERR_FAIL_COND_V(p_buffer_size < 0, ERR_INVALID_PARAMETER);
238
+ ERR_FAIL_COND_V(p_buffer_size + 4 > output_buffer.size(), ERR_INVALID_PARAMETER);
239
+
240
+ encode_uint32(p_buffer_size, &output_buffer[0]);
241
+ uint8_t *dst = &output_buffer[4];
242
+ for (int i = 0; i < p_buffer_size; i++)
243
+ dst[i] = p_buffer[i];
244
+
245
+ return peer->put_data(&output_buffer[0], p_buffer_size + 4);
246
+ }
247
+
248
+ int PacketPeerStream::get_max_packet_size() const {
249
+
250
+ return output_buffer.size();
251
+ }
252
+
253
+ void PacketPeerStream::set_stream_peer(const Ref<StreamPeer> &p_peer) {
254
+
255
+ //ERR_FAIL_COND(p_peer.is_null());
256
+
257
+ if (p_peer.ptr() != peer.ptr()) {
258
+ ring_buffer.advance_read(ring_buffer.data_left()); // reset the ring buffer
259
+ };
260
+
261
+ peer = p_peer;
262
+ }
263
+
264
+ void PacketPeerStream::set_input_buffer_max_size(int p_max_size) {
265
+
266
+ //warning may lose packets
267
+ ERR_EXPLAIN("Buffer in use, resizing would cause loss of data");
268
+ ERR_FAIL_COND(ring_buffer.data_left());
269
+ ring_buffer.resize(nearest_shift(p_max_size + 4));
270
+ input_buffer.resize(next_power_of_2(p_max_size + 4));
271
+ }
272
+
273
+ int PacketPeerStream::get_input_buffer_max_size() const {
274
+
275
+ return input_buffer.size() - 4;
276
+ }
277
+
278
+ void PacketPeerStream::set_output_buffer_max_size(int p_max_size) {
279
+
280
+ output_buffer.resize(next_power_of_2(p_max_size + 4));
281
+ }
282
+
283
+ int PacketPeerStream::get_output_buffer_max_size() const {
284
+
285
+ return output_buffer.size() - 4;
286
+ }
287
+
288
+ PacketPeerStream::PacketPeerStream() {
289
+
290
+ int rbsize = GLOBAL_GET("network/limits/packet_peer_stream/max_buffer_po2");
291
+
292
+ ring_buffer.resize(rbsize);
293
+ input_buffer.resize(1 << rbsize);
294
+ output_buffer.resize(1 << rbsize);
295
+ }
pool/shard001/C++/0022393_marker.cpp ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
+ * *
3
+ * Item marker interface program for EW-Database *
4
+ * Copyright (C) 2016 Łukasz "Kuszki" Dróżdż l.drozdz@openmailbox.org *
5
+ * *
6
+ * This program is free software: you can redistribute it and/or modify *
7
+ * it under the terms of the GNU General Public License as published by *
8
+ * the Free Software Foundation, either version 3 of the License, or *
9
+ * (at your option) any later version. *
10
+ * *
11
+ * This program is distributed in the hope that it will be useful, *
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
+ * GNU General Public License for more details. *
15
+ * *
16
+ * You should have received a copy of the GNU General Public License *
17
+ * along with this program. If not, see http://www.gnu.org/licenses/. *
18
+ * *
19
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
20
+
21
+ #include <QCoreApplication>
22
+ #include <QTextStream>
23
+ #include <QTextCodec>
24
+ #include <QUdpSocket>
25
+ #include <QDateTime>
26
+ #include <QSettings>
27
+ #include <QTimer>
28
+ #include <QFile>
29
+ #include <QDir>
30
+
31
+ int main(int argc, char *argv[])
32
+ {
33
+ QCoreApplication a(argc, argv); int i = 0;
34
+ QFile Output; QTextStream Stream(&Output);
35
+ QUdpSocket* Socket = new QUdpSocket(&a);
36
+ QFile File(argv[1]); QByteArray Array;
37
+ QString Database; int Port(0);
38
+
39
+ qsrand(QDateTime::currentMSecsSinceEpoch());
40
+ Stream.setCodec(QTextCodec::codecForLocale());
41
+
42
+ if (File.open(QFile::ReadOnly | QFile::Text)) while (!File.atEnd())
43
+ {
44
+ const QString Line = QString::fromLocal8Bit(File.readLine()); ++i;
45
+
46
+ if (i == 2)
47
+ {
48
+ Output.setFileName(Line.trimmed());
49
+ Output.open(QFile::WriteOnly | QFile::Text);
50
+ }
51
+ else if (i == 3)
52
+ {
53
+ Database = Line.trimmed();
54
+ }
55
+ }
56
+
57
+ if (!Database.isEmpty())
58
+ {
59
+ QSettings Settings("EW-Database");
60
+ Settings.beginGroup("Sockets");
61
+
62
+ for (const auto& K : Settings.childGroups()) if (!Port)
63
+ {
64
+ if (Database.contains(K, Qt::CaseInsensitive))
65
+ {
66
+ Settings.beginGroup(K);
67
+ Port = Settings.value("marker").toInt();
68
+ Settings.endGroup();
69
+ }
70
+ }
71
+
72
+ if (Port) while (!Socket->bind(QHostAddress::LocalHost, qrand() & 0xFFFF));
73
+ }
74
+
75
+ if (Output.isOpen())
76
+ {
77
+ Socket->writeDatagram(QString::number(Socket->localPort()).toUtf8(),
78
+ QHostAddress::LocalHost, Port);
79
+
80
+ Stream << "0 4\nKOD\n**\n";
81
+ }
82
+
83
+ a.connect(Socket, &QUdpSocket::readyRead, [&Socket, &Stream, &Array, &a] (void) -> void
84
+ {
85
+ Array.resize(Socket->pendingDatagramSize());
86
+ Socket->readDatagram(Array.data(), Array.size());
87
+
88
+ Stream << Array; if (Array.endsWith("\n\n")) a.quit();
89
+ });
90
+
91
+ QTimer::singleShot(10000, &a, &QCoreApplication::quit); return a.exec();
92
+ }
pool/shard001/C++/0022399_header_unittest.cc ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2015 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ #include "components/domain_reliability/header.h"
6
+
7
+ #include "base/strings/string_number_conversions.h"
8
+ #include "base/strings/string_split.h"
9
+ #include "base/strings/stringprintf.h"
10
+ #include "components/domain_reliability/config.h"
11
+ #include "testing/gtest/include/gtest/gtest.h"
12
+
13
+ namespace domain_reliability {
14
+ namespace {
15
+
16
+ class DomainReliabilityHeaderTest : public testing::Test {
17
+ protected:
18
+ DomainReliabilityHeaderTest() {}
19
+ ~DomainReliabilityHeaderTest() override {}
20
+
21
+ void Parse(std::string value) {
22
+ parsed_ = DomainReliabilityHeader::Parse(value);
23
+ }
24
+
25
+ const DomainReliabilityHeader* parsed() const { return parsed_.get(); }
26
+
27
+ private:
28
+ scoped_ptr<DomainReliabilityHeader> parsed_;
29
+ };
30
+
31
+ bool CheckReportUris(const char* pipe_separated_expected_report_uris,
32
+ const ScopedVector<GURL>& actual_report_uris) {
33
+ if (!pipe_separated_expected_report_uris)
34
+ return actual_report_uris.empty();
35
+
36
+ std::vector<std::string> expected_report_uri_strings =
37
+ SplitString(pipe_separated_expected_report_uris,
38
+ "|",
39
+ base::KEEP_WHITESPACE,
40
+ base::SPLIT_WANT_ALL);
41
+ if (expected_report_uri_strings.size() != actual_report_uris.size())
42
+ return false;
43
+
44
+ for (size_t i = 0; i < actual_report_uris.size(); ++i) {
45
+ if (actual_report_uris[i]->spec() != expected_report_uri_strings[i])
46
+ return false;
47
+ }
48
+
49
+ return true;
50
+ }
51
+
52
+ TEST_F(DomainReliabilityHeaderTest, SetConfig) {
53
+ static const struct {
54
+ const char* header;
55
+ const char* pipe_separated_report_uris;
56
+ int64_t max_age_in_seconds;
57
+ bool include_subdomains;
58
+ const char* description;
59
+ } test_cases[] = {
60
+ { "report-uri=https://a/; max-age=5",
61
+ "https://a/", 5, false,
62
+ "register" },
63
+ { "report-uri=\"https://a/\"; max-age=5",
64
+ "https://a/", 5, false,
65
+ "register with quoted report-uri" },
66
+ { "report-uri=<https://a/>; max-age=5",
67
+ "https://a/", 5, false,
68
+ "register with bracketed report-uri" },
69
+ { "report-uri=https://a/ https://b/; max-age=5",
70
+ "https://a/|https://b/", 5, false,
71
+ "register with two report-uris" },
72
+ { "report-uri=https://a/; max-age=5; includeSubdomains",
73
+ "https://a/", 5, true,
74
+ "register with includeSubdomains" },
75
+ };
76
+
77
+ for (const auto& test_case : test_cases) {
78
+ std::string assert_prefix = base::StringPrintf(
79
+ "Valid set-config NEL header \"%s\" (%s) incorrectly parsed as ",
80
+ test_case.header,
81
+ test_case.description);
82
+ Parse(test_case.header);
83
+ EXPECT_FALSE(parsed()->IsParseError()) << assert_prefix << "invalid.";
84
+ EXPECT_FALSE(parsed()->IsClearConfig()) << assert_prefix << "clear-config.";
85
+ if (parsed()->IsParseError() || parsed()->IsClearConfig())
86
+ continue;
87
+ EXPECT_TRUE(parsed()->IsSetConfig());
88
+
89
+ std::string assert_message =
90
+ assert_prefix + "\"" + parsed()->ToString() + "\"";
91
+ EXPECT_TRUE(CheckReportUris(test_case.pipe_separated_report_uris,
92
+ parsed()->config().collectors))
93
+ << assert_message;
94
+ EXPECT_EQ(test_case.max_age_in_seconds,
95
+ parsed()->max_age().InSeconds())
96
+ << assert_message;
97
+ EXPECT_EQ(test_case.include_subdomains,
98
+ parsed()->config().include_subdomains)
99
+ << assert_message;
100
+ }
101
+ }
102
+
103
+ TEST_F(DomainReliabilityHeaderTest, ClearConfig) {
104
+ static const struct {
105
+ const char* header;
106
+ const char* description;
107
+ } test_cases[] = {
108
+ { "max-age=0", "unregister" },
109
+ { "report-uri=https://a/; max-age=0", "unregister with report-uri" },
110
+ { "max-age=0; includeSubdomains", "unregister with includeSubdomains" },
111
+ };
112
+
113
+ for (const auto& test_case : test_cases) {
114
+ std::string assert_prefix = base::StringPrintf(
115
+ "Valid clear-config NEL header \"%s\" (%s) incorrectly parsed as ",
116
+ test_case.header,
117
+ test_case.description);
118
+ Parse(test_case.header);
119
+ EXPECT_FALSE(parsed()->IsParseError()) << assert_prefix << "invalid.";
120
+ EXPECT_FALSE(parsed()->IsSetConfig()) << assert_prefix << "set-config.";
121
+ }
122
+ }
123
+
124
+ TEST_F(DomainReliabilityHeaderTest, Error) {
125
+ static const struct {
126
+ const char* header;
127
+ const char* description;
128
+ } test_cases[] = {
129
+ { "", "empty" },
130
+ { "max-age=5", "report-uri missing with non-zero max-age" },
131
+ { "report-uri; max-age=5", "report-uri has no value" },
132
+ { "report-uri=; max-age=5", "report-uri value is empty" },
133
+ { "report-uri=http://a/; max-age=5", "report-uri is insecure" },
134
+ { "report-uri=https://a/ http://b/; max-age=5",
135
+ "one report-uri of two is insecure" },
136
+ { "report-uri=\"https://a/; max-age=5", "report-uri is unbalanced" },
137
+ { "report-uri=https://a/\"; max-age=5", "report-uri is unbalanced" },
138
+ { "report-uri=<https://a/; max-age=5", "report-uri is unbalanced" },
139
+ { "report-uri=https://a/>; max-age=5", "report-uri is unbalanced" },
140
+ { "report-uri=https://a/", "max-age is missing" },
141
+ { "report-uri=https://a/; max-age", "max-age has no value" },
142
+ { "report-uri=https://a/; max-age=", "max-age value is empty" },
143
+ { "report-uri=https://a/; max-age=a", "max-age is entirely non-numeric" },
144
+ { "report-uri=https://a/; max-age=5a", "max-age is partly non-numeric" },
145
+ { "report-uri=https://a/; max-age=5 5", "max-age has multiple values" },
146
+ };
147
+
148
+ for (const auto& test_case : test_cases) {
149
+ Parse(test_case.header);
150
+ EXPECT_TRUE(parsed()->IsParseError())
151
+ << "Invalid NEL header \"" << test_case.header << "\" ("
152
+ << test_case.description << ") incorrectly parsed as valid.";
153
+ }
154
+ }
155
+
156
+ } // namespace
157
+ } // namespace domain_reliability
pool/shard001/C++/0022401_Calendar.cpp ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <string.h>
2
+ #include <sys/time.h>
3
+
4
+ #include <gtk/gtk.h>
5
+
6
+ #include "Calendar.hpp"
7
+ #include "Config.hpp"
8
+
9
+
10
+ void fork_and_run(char* cmdline)
11
+ {
12
+ if (strlen(cmdline)) {
13
+ if (fork() == 0) {
14
+ execl("/bin/sh", "/bin/sh", "-c", cmdline, NULL);
15
+ _exit(0);
16
+ }
17
+ }
18
+ }
19
+
20
+ void monthChangedCb(GtkCalendar *calendar, gpointer cls)
21
+ {
22
+ if (cls) {
23
+ ((Calendar*)cls)->markToday();
24
+ }
25
+ }
26
+ void dayDoubleClickCb(GtkCalendar *calendar, gpointer cls)
27
+ {
28
+ if (cls) {
29
+ ((Calendar*)cls)->runExternalViewer();
30
+ }
31
+ }
32
+
33
+
34
+ Calendar::Calendar()
35
+ {
36
+ widget = gtk_calendar_new();
37
+
38
+ Config* config = Config::getInstance();
39
+ g_object_set(widget,
40
+ "show-heading", true,
41
+ "show-day-names", true,
42
+ "show-details", false,
43
+ "show-week-numbers", config->show_week_numbers,
44
+ NULL);
45
+ if (config->mark_today) {
46
+ // Store today date to be able to mark it after month changes.
47
+ gtk_calendar_get_date((GtkCalendar*)widget,
48
+ &today_year, &today_month, &today_day);
49
+ markToday();
50
+ g_signal_connect(widget, "month-changed",
51
+ GCallback(monthChangedCb), (gpointer)this);
52
+ }
53
+ g_signal_connect(widget, "day-selected-double-click",
54
+ GCallback(dayDoubleClickCb), (gpointer)this);
55
+
56
+ gtk_widget_show(widget);
57
+ }
58
+
59
+ Calendar::~Calendar()
60
+ {
61
+ gtk_widget_destroy(widget);
62
+ }
63
+
64
+ void Calendar::nextYear()
65
+ {
66
+ _change(1, 0);
67
+ }
68
+ void Calendar::prevYear()
69
+ {
70
+ _change(-1, 0);
71
+ }
72
+
73
+ void Calendar::nextMonth()
74
+ {
75
+ _change(0, 1);
76
+ }
77
+ void Calendar::prevMonth()
78
+ {
79
+ _change(0, -1);
80
+ }
81
+
82
+ void Calendar::_change(int year_offset, int month_offset)
83
+ {
84
+ int year, month;
85
+ gtk_calendar_get_date((GtkCalendar*)widget, (guint*)&year, (guint*)&month, NULL);
86
+ month += month_offset;
87
+ if (month > 11) {
88
+ month = 0;
89
+ year_offset++;
90
+ } else if (month < 0) {
91
+ month = 11;
92
+ year_offset--;
93
+ }
94
+ year += year_offset;
95
+ gtk_calendar_select_month((GtkCalendar*)widget, (guint)month, (guint)year);
96
+ }
97
+
98
+ bool Calendar::markToday()
99
+ {
100
+ guint year, month;
101
+ gtk_calendar_get_date((GtkCalendar*)widget, &year, &month, NULL);
102
+ if (year == today_year && month == today_month) {
103
+ gtk_calendar_mark_day((GtkCalendar*)widget, today_day);
104
+ return true;
105
+ } else {
106
+ gtk_calendar_unmark_day((GtkCalendar*)widget, today_day);
107
+ return false;
108
+ }
109
+ }
110
+
111
+ void Calendar::goToday()
112
+ {
113
+ gtk_calendar_select_month((GtkCalendar*)widget, today_month, today_year);
114
+ gtk_calendar_select_day((GtkCalendar*)widget, today_day);
115
+ }
116
+
117
+ bool Calendar::runExternalViewer()
118
+ {
119
+ Config* config = Config::getInstance();
120
+ size_t len = config->external_viewer.length();
121
+ if (len > 0) {
122
+ int year, month, day;
123
+ gtk_calendar_get_date((GtkCalendar*)widget,
124
+ (guint*)&year, (guint*)&month, (guint*)&day);
125
+ struct tm date;
126
+ date.tm_year = year - 1900;
127
+ date.tm_mon = month;
128
+ date.tm_mday = day;
129
+ date.tm_sec = date.tm_min = date.tm_hour = date.tm_wday
130
+ = date.tm_yday = date.tm_isdst = 0;
131
+
132
+ size_t buf_size = len + 64;
133
+ char* cmd = new char[buf_size];
134
+ strftime(cmd, buf_size, config->external_viewer.c_str(), &date);
135
+ fork_and_run(cmd);
136
+ delete[] cmd;
137
+ return true;
138
+ } else {
139
+ return false;
140
+ }
141
+ }
pool/shard001/C++/0022405_graph.cpp ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include "graph.h"
2
+
3
+ Graph::Graph() {
4
+ int i, j;
5
+ for(i = 0; i < 250; ++i)
6
+ for(j = 0; j < 250; ++j)
7
+ matriz[i][j] = ' ';
8
+ }
9
+
10
+ void Graph::addVvertex(char data, int i, int j) {
11
+ matriz[i][j] = data;
12
+ }
13
+
14
+ void Graph::clear() {
15
+ int i, j;
16
+ for(i = 0; i < 250; ++i)
17
+ for(j = 0; j < 250; ++j)
18
+ matriz[i][j] = ' ';
19
+ }
20
+
21
+ char Graph::getValue(int i, int j) {
22
+ return matriz[i][j];
23
+ }
24
+
25
+ void Graph::setValue(char data, int i, int j) {
26
+ matriz[i][j] = data;
27
+ }
28
+
29
+ int Graph::getManhattanHeuristic(int i, int j) {
30
+ return 10*(fabs(xFim - i) + fabs(yFim - j));
31
+ }
32
+
33
+ void Graph::setInit(int i, int j) {
34
+ xInicio = i;
35
+ yInicio = j;
36
+ }
37
+
38
+ void Graph::setEnd(int i, int j) {
39
+ xFim = i;
40
+ yFim = j;
41
+ }
42
+
43
+ int *Graph::getInit() {
44
+ int *pos = new int[2];
45
+ pos[0] = xInicio;
46
+ pos[1] = yInicio;
47
+ return pos;
48
+ }
49
+
50
+ int *Graph::getEnd() {
51
+ int *pos = new int[2];
52
+ pos[0] = xFim;
53
+ pos[1] = yFim;
54
+ return pos;
55
+ }
pool/shard001/C++/0022410_main.cpp ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <sys/types.h>
2
+ #include <math.h>
3
+ #include "fbtext.h"
4
+ #include "fastmath.h"
5
+ #include "gps.h"
6
+ #include "page.h"
7
+ #include "laser.h"
8
+ #include "fbtimer.h"
9
+ #include "clockutil.h"
10
+ #include "celestial.h"
11
+ #include "gpio.h"
12
+ #include "keysin.h"
13
+ #include "uart.h"
14
+ #include "scroller.h"
15
+ #include "string.h"
16
+ #include "flare.h"
17
+ #include "flarelist.h"
18
+ #include "skyplot.h"
19
+ #include "p_config_int.h"
20
+ #include "p_config_long.h"
21
+ #include "p_config_bool.h"
22
+ #include "p_tracker.h"
23
+ #include "p_starfinder.h"
24
+ #include "p_planetfinder.h"
25
+ #include "p_info.h"
26
+ #include "p_debug.h"
27
+ #include "p_calibrate_coarse.h"
28
+ #include "p_calibrate_3star.h"
29
+
30
+ FBTimer fbt;
31
+ CLaser* laser;
32
+ CPage* tracker_page;
33
+ CKeysIn* ki;
34
+ bool stepper_active_holding = false;
35
+ bool debug_flare_imminent = false;
36
+
37
+ #ifdef NO_XPORT
38
+ unsigned short pwm_values[PWM_NUM/2];
39
+ unsigned short gpio_directions[(GPIO_NUM+15)/16];
40
+ unsigned short gpio_values[(GPIO_NUM+15)/16];
41
+ #endif
42
+
43
+
44
+ class DisplayUpdateTimerEvent : public FBTimerEvent {
45
+ public:
46
+ DisplayUpdateTimerEvent() : FBTimerEvent(0, 0, 0, 512) {}
47
+ virtual void Run(FBTimer* timer) {
48
+ long secs = timer->GetTimeSeconds();
49
+ long difftime = secs - event_time_secs;
50
+ if (difftime > 1 || difftime < -1) {
51
+ SetNextScheduledTime(secs + 1, 0);
52
+ }
53
+ UpdateTimeLeftClockDisplay(false);
54
+ }
55
+ } display_updater;
56
+
57
+
58
+ class TurretUpdateTimerEvent : public FBTimerEvent {
59
+ public:
60
+ TurretUpdateTimerEvent() : FBTimerEvent(0, 0, 0, 64) {}
61
+
62
+ virtual void Run(FBTimer* timer) {
63
+ long secs = timer->GetTimeSeconds();
64
+ long difftime = secs - event_time_secs;
65
+ if (difftime > 1 || difftime < -1) {
66
+ SetNextScheduledTime(secs + 1, 0);
67
+ }
68
+ TurretPoll();
69
+ }
70
+
71
+ } turret_updater;
72
+
73
+
74
+ extern "C"
75
+ int main(void)
76
+ {
77
+ txtClear();
78
+
79
+ // Create menus
80
+ txtPrint("Creating menus.\n");
81
+
82
+ main_menu_page = new CMenuPage("Main Menu");
83
+ tracker_page = new CTrackerPage("Flare Tracker");
84
+ CMenuPage* calib_menu_page = new CMenuPage("Calibration");
85
+ CMenuPage* config_menu_page = new CMenuPage("Settings");
86
+ CPage* calib_3star_page = new CCalibrate3StarPage("3-Star Calibration");
87
+
88
+ main_menu_page->AddItem(tracker_page);
89
+ main_menu_page->AddItem(new CStarFinderPage("Star Finder"));
90
+ main_menu_page->AddItem(new CPlanetFinderPage("Planet Finder"));
91
+ main_menu_page->AddItem(calib_menu_page);
92
+ main_menu_page->AddItem(new CInfoPage("Info Page"));
93
+ main_menu_page->AddItem(config_menu_page);
94
+ main_menu_page->AddItem(new CDebugPage("Debug Page"));
95
+
96
+ calib_menu_page->AddItem(new CCalibrateCoarsePage("Coarse Calibration"));
97
+ calib_menu_page->AddItem(calib_3star_page);
98
+
99
+ config_menu_page->AddItem(new CConfigIntPage("Day Clock Brightness", &daytime_clock_pwm, 0, 255));
100
+ config_menu_page->AddItem(new CConfigIntPage("Night Clock Brightness", &nighttime_clock_pwm, 0, 255));
101
+ config_menu_page->AddItem(new CConfigIntPage("Slow Laser Table Speed", &turret_speed_low, 1, 100));
102
+ config_menu_page->AddItem(new CConfigIntPage("Fast Laser Table Speed", &turret_speed_high, 1, 100));
103
+ config_menu_page->AddItem(new CConfigBoolPage("Active Stepper Holding", &stepper_active_holding));
104
+ config_menu_page->AddItem(new CConfigBoolPage("Make Imminent Flare", &debug_flare_imminent));
105
+ config_menu_page->AddItem(new CConfigLongPage("Laser Azimuth Backlash", &turret_azimuth_backlash, 1, 9999));
106
+ config_menu_page->AddItem(new CConfigLongPage("Laser Altitude Backlash", &turret_altitude_backlash, 1, 9999));
107
+
108
+ current_page = tracker_page;
109
+
110
+
111
+ // set first 31 GPIO bits to output
112
+ GPIO_DDR(0) = 0xffff;
113
+ GPIO_DDR(1) = 0x0fff;
114
+ GPIO_DDR(2) = 0x0f00;
115
+ GPIO_DATA(0) = 0x0000;
116
+ GPIO_DATA(1) = 0x0000;
117
+ GPIO_DATA(2) = 0x0000;
118
+ GpioSetDirOutbound(FLARE_ALERT_PIN, true);
119
+ GpioSetDirOutbound(KLAXON_PIN, true);
120
+
121
+ // Clock brightness.
122
+ PWM_DATA(0) = 0x0f00;
123
+
124
+ fm_benchmark();
125
+
126
+ txtPrint("Init GPS Serial link.\n");
127
+ gps_uart.SetBaudRate(4800);
128
+ #ifdef NO_XPORT
129
+ gps_uart.ReadBufStuff("$GPRMC,071458,A,3714.1938,N,12153.8619,W,0.0,241.0,070804,14.9,E,A*36\r\n");
130
+ #endif
131
+
132
+ txtPrint("Init Turret Serial link.\n");
133
+ turret_uart.SetBaudRate(9600);
134
+ millisleep(128);
135
+ turret_uart.WriteString("4!");
136
+ millisleep(512);
137
+ turret_uart.WriteString("0H");
138
+ millisleep(128);
139
+ turret_uart.WriteString("3O");
140
+ millisleep(128);
141
+ turret_uart.WriteString("B32000P");
142
+
143
+ txtPrint("Init Scroller Serial link.\n");
144
+ scroller_uart.SetBaudRate(9600);
145
+ millisleep(128);
146
+ scroller.PageWrite(1, 0, SC_COLOR_LIME, "C.L.I.V.E. v2.0<FI>Celestial<FI>Laser<FI>Identification /<FI>Visualisation<FI>Experiment<FP>");
147
+ sleep(1);
148
+ scroller.Init(1);
149
+ sleep(3);
150
+
151
+ txtPrint("Init keypads.\n");
152
+ ki = new CKeysIn();
153
+
154
+ txtPrint("Init sky object caches.\n");
155
+ InitSkyCaches();
156
+
157
+ txtPrint("Test clock digits.\n");
158
+ scroller.PageWrite(1, 0, SC_COLOR_BRIGHT_GREEN, "Initialize Clock");
159
+ sleep(1);
160
+ TestClockDisplay();
161
+ fbt.ScheduleEvent(&display_updater);
162
+
163
+ txtPrint("Init laser table.\n");
164
+ scroller.PageWrite(1, 0, SC_COLOR_BRIGHT_GREEN, "Initialize Laser");
165
+ fbt.ScheduleEvent(&turret_updater);
166
+ sleep(2);
167
+ laser = new CLaser();
168
+ laser->SetBeamState(BEAM_ON);
169
+
170
+ scroller.PageWrite(1, 0, SC_COLOR_BRIGHT_GREEN, "Initialize GPS");
171
+ sleep(3);
172
+ txtClear();
173
+
174
+ long seconds = 0;
175
+ long lastseconds = 0;
176
+ while (1) {
177
+ GetGpsInfoFromSerial();
178
+ UpdateSkyCaches();
179
+ laser->SetActiveHolding(stepper_active_holding);
180
+ if (debug_flare_imminent) {
181
+ debug_flare_imminent = false;
182
+ delete FlareList[0];
183
+ FlareList[0] = new CFlare(seconds + 135, 0, 45.0, 45.0, 0);
184
+ nextflare = NULL;
185
+ }
186
+ CheckForNextFlare(laser);
187
+ ki->Poll();
188
+ HandleKeys();
189
+ seconds = time();
190
+ if (seconds != lastseconds) {
191
+ if ((seconds & 0x0fff) == 0) { // Every 1h 8m 16s
192
+ UpdateSunRiseSet(seconds, my_latitude, my_longitude);
193
+ }
194
+ UpdateClockBrightness();
195
+ UpdateDisplay();
196
+ lastseconds = seconds;
197
+ }
198
+ }
199
+ }
200
+
201
+
pool/shard001/C++/0022411_document.cc ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* TODO : Manage File problems !
2
+ */
3
+ /*
4
+ ** A program to convert the XML rendered by KWord into LATEX.
5
+ **
6
+ ** Copyright (C) 2000, 2003 Robert JACOLIN
7
+ **
8
+ ** This library is free software; you can redistribute it and/or
9
+ ** modify it under the terms of the GNU Library General Public
10
+ ** License as published by the Free Software Foundation; either
11
+ ** version 2 of the License, or (at your option) any later version.
12
+ **
13
+ ** This library is distributed in the hope that it will be useful,
14
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
+ ** Library General Public License for more details.
17
+ **
18
+ ** To receive a copy of the GNU Library General Public License, write to the
19
+ ** Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20
+ * Boston, MA 02110-1301, USA.
21
+ **
22
+ */
23
+
24
+ #include <kdebug.h>
25
+
26
+ #include "document.h"
27
+
28
+ Document::Document(const KoStore* in, QString fileOut):
29
+ XmlParser(in), _file(fileOut), _in( in )
30
+ {
31
+ //kDebug(30522) << fileIn;
32
+ kDebug(30522) << fileOut;
33
+ _filename = fileOut;
34
+ //setFileHeader(_fileHeader);
35
+ //setRoot(&_document);
36
+ Config::instance()->setEmbeded(false);
37
+ //analyze_config(config);
38
+ }
39
+
40
+ Document::~Document()
41
+ {
42
+
43
+ }
44
+
45
+ void Document::analyze()
46
+ {
47
+ QDomNode node;
48
+ node = init();
49
+ kDebug(30522) <<"ANALYZE A DOC";
50
+ _document.analyze(node);
51
+ kDebug(30522) <<"END ANALYZE";
52
+ }
53
+
54
+ void Document::generate()
55
+ {
56
+ if(_file.open(QIODevice::WriteOnly))
57
+ {
58
+ kDebug(30522) <<"GENERATION";
59
+ _out.setDevice(&_file);
60
+ _document.generate(_out, !isEmbeded());
61
+ //_out << getDocument();
62
+ _file.close();
63
+ }
64
+ else
65
+ kDebug(30522) <<"Can't use the file ...";
66
+ }
pool/shard001/C++/0022414_initterm.cpp ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // initterm.cpp
2
+
3
+ // based on:
4
+ // LIBCTINY - Matt Pietrek 2001
5
+ // MSDN Magazine, January 2001
6
+
7
+ // 08/12/06 (mv)
8
+
9
+ #include <windows.h>
10
+ #include <malloc.h>
11
+ #include "libct.h"
12
+
13
+ #pragma section(".CRT$XCA", read, write)
14
+ #pragma data_seg(".CRT$XCA") // start of ctor section
15
+ _PVFV __xc_a[] = {0};
16
+
17
+ #pragma section(".CRT$XCZ", read, write)
18
+ #pragma data_seg(".CRT$XCZ") // end of ctor section
19
+ _PVFV __xc_z[] = {0};
20
+
21
+ #pragma data_seg()
22
+ #pragma comment(linker, "/merge:.CRT=.rdata")
23
+
24
+ BEGIN_EXTERN_C
25
+
26
+ void _initterm(_PVFV *pfbegin, _PVFV *pfend)
27
+ {
28
+ // walk the table of function pointers from the bottom up, until
29
+ // the end is encountered. Do not skip the first entry. The initial
30
+ // value of pfbegin points to the first valid entry. Do not try to
31
+ // execute what pfend points to. Only entries before pfend are valid.
32
+ while (pfbegin < pfend)
33
+ {
34
+ if (*pfbegin != 0)
35
+ (**pfbegin)();
36
+ ++pfbegin;
37
+ }
38
+ }
39
+
40
+
41
+ static _PVFV *atexitlist = 0;
42
+ static unsigned int max_atexit_entries = 0;
43
+ static unsigned int cur_atexit_entries = 0;
44
+
45
+ void _init_atexit()
46
+ {
47
+ max_atexit_entries = 128;
48
+ atexitlist = (_PVFV*)calloc(max_atexit_entries, sizeof(_PVFV*));
49
+ }
50
+
51
+ int atexit(_PVFV func)
52
+ {
53
+ if (cur_atexit_entries < max_atexit_entries)
54
+ {
55
+ atexitlist[cur_atexit_entries++] = func;
56
+ return 0;
57
+ }
58
+
59
+ return -1;
60
+ }
61
+
62
+ void _doexit()
63
+ {
64
+ if (cur_atexit_entries)
65
+ {
66
+ // Use ptr math to find the end of the array
67
+ _initterm(atexitlist, atexitlist + cur_atexit_entries);
68
+ }
69
+ }
70
+
71
+ void exit(int code)
72
+ {
73
+ _doexit();
74
+ ExitProcess(code);
75
+ }
76
+
77
+ int _purecall()
78
+ {
79
+ ExitProcess((UINT)-1);
80
+ }
81
+
82
+ END_EXTERN_C
pool/shard001/C++/0022418_flushAndInsert.cpp ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*BEGIN_LEGAL
2
+ Intel Open Source License
3
+
4
+ Copyright (c) 2002-2013 Intel Corporation. All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are
8
+ met:
9
+
10
+ Redistributions of source code must retain the above copyright notice,
11
+ this list of conditions and the following disclaimer. Redistributions
12
+ in binary form must reproduce the above copyright notice, this list of
13
+ conditions and the following disclaimer in the documentation and/or
14
+ other materials provided with the distribution. Neither the name of
15
+ the Intel Corporation nor the names of its contributors may be used to
16
+ endorse or promote products derived from this software without
17
+ specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR
23
+ ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+ END_LEGAL */
31
+ //
32
+ // ORIGINAL_AUTHOR: Kim Hazelwood
33
+ //
34
+ // This tool tells you what traces reappear after a code cache
35
+ // flush. It can be used to identify long-lived traces in a program.
36
+ // Note: you must limit the code cache size to trigger flushes
37
+ // Sample usage:
38
+ // pin -xyzzy -limit_code_cache 131072 -t flushAndInsert -- /bin/ls
39
+
40
+ #include "pin.H"
41
+ #include "portability.H"
42
+ #include "utils.H"
43
+ #include <iostream>
44
+ #include <fstream>
45
+ #include <unistd.h>
46
+
47
+ using namespace std;
48
+
49
+ /* ================================================================== */
50
+ /* Global Variables */
51
+ /* ================================================================== */
52
+ int flushes;
53
+ int insertions;
54
+ ofstream TraceFile;
55
+
56
+ /* ===================================================================== */
57
+ /* Commandline Switches */
58
+ /* ===================================================================== */
59
+
60
+ KNOB<BOOL> KnobHelp(KNOB_MODE_WRITEONCE, "pintool",
61
+ "hh", "0", "Print help message (command-line switches)");
62
+ KNOB<string> KnobOutputFile(KNOB_MODE_WRITEONCE, "pintool",
63
+ "o", "flushAndInsert.out", "specify trace file name");
64
+ KNOB<BOOL> KnobPid(KNOB_MODE_WRITEONCE, "pintool",
65
+ "p", "0", "append pid to output");
66
+
67
+ /* ================================================================== */
68
+ /*
69
+ Clear the cache flush count
70
+ */
71
+ VOID InitCounters()
72
+ {
73
+ string logFileName = KnobOutputFile.Value();
74
+ if( KnobPid )
75
+ logFileName += "." + decstr( getpid_portable() );
76
+ TraceFile.open(logFileName.c_str());
77
+
78
+ insertions = 0;
79
+ flushes = 0;
80
+ }
81
+
82
+ /* ================================================================== */
83
+ /*
84
+ Print details of traces as they are inserted
85
+ */
86
+ VOID WatchTraces(TRACE trace, VOID *v)
87
+ {
88
+ insertions++;
89
+ TraceFile << "Code cache insertion #" << insertions;
90
+ TraceFile << "\torig pc=0x" << hex << TRACE_Address(trace);
91
+ TraceFile << "\tcache pc=0x" << hex << TRACE_CodeCacheAddress(trace);
92
+ TraceFile << "\ttrace size (cache)=" << TRACE_CodeCacheSize(trace);
93
+ TraceFile << " (BBL=" << TRACE_NumBbl(trace) << " Ins=" << TRACE_NumIns(trace) << ")" << endl;
94
+ }
95
+ /* ================================================================== */
96
+ /*
97
+ When notified by Pin that the cache is full, perform a flush and
98
+ tell the user about it.
99
+ */
100
+ VOID FlushOnFull(UINT32 trace_size, UINT32 stub_size)
101
+ {
102
+ TraceFile << "Trying to insert trace size " << trace_size << " and exit stub size " << stub_size << "... ";
103
+ flushes++;
104
+ CODECACHE_FlushCache();
105
+ TraceFile << " SWOOSH! (" << flushes << ")" << endl;
106
+ }
107
+
108
+ /* ================================================================== */
109
+ /*
110
+ Print details at the end of the run
111
+ */
112
+ VOID PrintDetailsOnExit(INT32 code, VOID *v)
113
+ {
114
+ int traces = CODECACHE_NumTracesInCache();
115
+ int stubs = CODECACHE_NumExitStubsInCache();
116
+ int compensation = traces - stubs;
117
+ traces = traces - compensation;
118
+
119
+ TraceFile << endl << "------------------------" << endl;
120
+ TraceFile << dec << traces << " traces" << endl;
121
+ TraceFile << stubs << " exit stubs" << endl;
122
+ TraceFile << compensation << " compensations" << endl;
123
+ TraceFile << (traces+stubs+compensation) << " total regions in the code cache" << endl;
124
+ TraceFile << endl << flushes << " flushes!" << endl;
125
+ TraceFile << "#eof" << endl;
126
+ TraceFile.close();
127
+ }
128
+
129
+
130
+ /* ================================================================== */
131
+ /*
132
+ Initialize and begin program execution under the control of Pin
133
+ */
134
+ int main(INT32 argc, CHAR **argv)
135
+ {
136
+ if (PIN_Init(argc, argv) || KnobHelp) return Usage();
137
+
138
+ // Initialize some counters we're using in this tool
139
+ InitCounters();
140
+
141
+ // Register a routine that gets called when the cache is first initialized
142
+ CODECACHE_AddCacheInitFunction(PrintInitInfo, 0);
143
+
144
+ // Register a routine that gets called every time the cache is full
145
+ CODECACHE_AddFullCacheFunction(FlushOnFull, 0);
146
+
147
+ // Register a routine that gets called when a trace is
148
+ // inserted into the codecache
149
+ CODECACHE_AddTraceInsertedFunction(WatchTraces, 0);
150
+
151
+ // Register a routine that gets called when the program ends
152
+ PIN_AddFiniFunction(PrintDetailsOnExit, 0);
153
+
154
+ PIN_StartProgram(); // Never returns
155
+
156
+ return 0;
157
+ }
158
+
pool/shard001/C++/0022425_depthwise_conv.cc ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+ ==============================================================================*/
15
+
16
+ #include "tensorflow/lite/delegates/gpu/gl/kernels/depthwise_conv.h"
17
+
18
+ #include <memory>
19
+ #include <vector>
20
+
21
+ #include "absl/memory/memory.h"
22
+ #include "tensorflow/lite/delegates/gpu/common/convert.h"
23
+ #include "tensorflow/lite/delegates/gpu/common/operations.h"
24
+ #include "tensorflow/lite/delegates/gpu/common/shape.h"
25
+ #include "tensorflow/lite/delegates/gpu/common/status.h"
26
+ #include "tensorflow/lite/delegates/gpu/common/types.h"
27
+ #include "tensorflow/lite/delegates/gpu/common/util.h"
28
+ #include "tensorflow/lite/delegates/gpu/gl/node_shader.h"
29
+ #include "tensorflow/lite/delegates/gpu/gl/variable.h"
30
+ #include "tensorflow/lite/delegates/gpu/gl/workgroups/ideal_workgroup_picker.h"
31
+
32
+ namespace tflite {
33
+ namespace gpu {
34
+ namespace gl {
35
+ namespace {
36
+
37
+ class DepthwiseConvolution : public NodeShader {
38
+ public:
39
+ absl::Status GenerateCode(const GenerationContext& ctx,
40
+ GeneratedCode* generated_code) const final {
41
+ if (ctx.input_shapes.size() != 1) {
42
+ return absl::UnimplementedError(
43
+ "DepthWise Convolution does not support more than 1 runtime tensor");
44
+ }
45
+ const auto& attr =
46
+ absl::any_cast<const DepthwiseConvolution2DAttributes&>(ctx.op_attr);
47
+ auto weights = attr.weights.shape;
48
+ const int offsets_count = weights.h * weights.w;
49
+ const bool offsets_count_too_large = offsets_count > kMaxConstArraySize;
50
+ std::vector<Variable> parameters;
51
+ if (offsets_count_too_large) {
52
+ parameters = {
53
+ {"input_data_0_h", static_cast<int>(ctx.input_shapes[0][1])},
54
+ {"input_data_0_w", static_cast<int>(ctx.input_shapes[0][2])},
55
+ {"padding_w", attr.padding.prepended.w},
56
+ {"padding_h", attr.padding.prepended.h},
57
+ {"dilation_w", attr.dilations.w},
58
+ {"dilation_h", attr.dilations.h},
59
+ {"kernel_w", weights.w},
60
+ {"kernel_h", weights.h},
61
+ {"src_depth", DivideRoundUp(weights.i, 4)},
62
+ {"channel_multiplier", weights.o},
63
+ {"stride", int2(attr.strides.w, attr.strides.h)},
64
+ };
65
+ } else {
66
+ std::vector<int2> offsets;
67
+ for (int h = 0; h < weights.h; ++h) {
68
+ for (int w = 0; w < weights.w; ++w) {
69
+ offsets.emplace_back(w * attr.dilations.w - attr.padding.prepended.w,
70
+ h * attr.dilations.h - attr.padding.prepended.h);
71
+ }
72
+ }
73
+ parameters = {
74
+ {"input_data_0_h", static_cast<int>(ctx.input_shapes[0][1])},
75
+ {"input_data_0_w", static_cast<int>(ctx.input_shapes[0][2])},
76
+ {"offsets_count", offsets_count},
77
+ {"offsets", offsets},
78
+ {"src_depth", DivideRoundUp(weights.i, 4)},
79
+ {"channel_multiplier", weights.o},
80
+ {"stride", int2(attr.strides.w, attr.strides.h)},
81
+ };
82
+ }
83
+ bool non_empty_padding =
84
+ attr.padding.appended.h != 0 || attr.padding.appended.w != 0 ||
85
+ attr.padding.prepended.h != 0 || attr.padding.prepended.w != 0;
86
+
87
+ std::vector<std::pair<std::string, Object>> objects = {
88
+ {"weights", MakeReadonlyObject(ConvertToPIOHW4(attr.weights))}};
89
+
90
+ std::string source;
91
+ if (offsets_count_too_large) {
92
+ source = R"(
93
+ int offsets_count = $kernel_w$ * $kernel_h$;
94
+ int src_layer_offset = (gid.z % $channel_multiplier$) * 4;
95
+ int filter_offset = gid.z * $src_depth$ * offsets_count * 4;
96
+ int i = 0;
97
+ for (int ky = 0; ky < $kernel_h$; ky++) {
98
+ for (int kx = 0; kx < $kernel_w$; kx++, i++) {
99
+ ivec2 coord = gid.xy * $stride$ + ivec2(kx * $dilation_w$ - $padding_w$, ky * $dilation_h$ - $padding_h$);)";
100
+ } else {
101
+ source = R"(
102
+ int offsets_count = $offsets_count$;
103
+ int src_layer_offset = (gid.z % $channel_multiplier$) * 4;
104
+ int filter_offset = gid.z * $src_depth$ * offsets_count * 4;
105
+ for (int i = 0; i < offsets_count; ++i) {
106
+ ivec2 coord = gid.xy * $stride$ + $offsets[i]$;)";
107
+ }
108
+ if (non_empty_padding) {
109
+ source += R"(
110
+ if (coord.x < 0 || coord.y < 0 ||
111
+ coord.x >= $input_data_0_w$ || coord.y >= $input_data_0_h$) {
112
+ continue;
113
+ })";
114
+ }
115
+ source += R"(
116
+ int src_layer = gid.z / $channel_multiplier$;
117
+ vec4 input_ = $input_data_0[coord.x, coord.y, src_layer]$;
118
+ vec4 input_shifted = vec4(
119
+ input_[(src_layer_offset + 0) / $channel_multiplier$],
120
+ input_[(src_layer_offset + 1) / $channel_multiplier$],
121
+ input_[(src_layer_offset + 2) / $channel_multiplier$],
122
+ input_[(src_layer_offset + 3) / $channel_multiplier$]
123
+ );
124
+ int filter_offset = gid.z * offsets_count + i;
125
+ value_0 += input_shifted * $weights[filter_offset]$;
126
+ }
127
+ )";
128
+ if (offsets_count_too_large) {
129
+ source += R"(
130
+ }
131
+ )";
132
+ }
133
+ if (!attr.bias.data.empty()) {
134
+ source += "value_0 += $bias[gid.z]$;\n";
135
+ objects.push_back({"bias", MakeReadonlyObject(attr.bias.data)});
136
+ }
137
+ *generated_code = {
138
+ /*parameters=*/std::move(parameters),
139
+ /*objects=*/std::move(objects),
140
+ /*shared_variables=*/{},
141
+ /*workload=*/uint3(),
142
+ /*workgroup=*/
143
+ GetIdealWorkgroupIfPossible(
144
+ *ctx.gpu_info, OperationType::DEPTHWISE_CONVOLUTION,
145
+ HW(attr.weights.shape.h, attr.weights.shape.w), attr.strides,
146
+ OHWI(attr.weights.shape.o, ctx.input_shapes[0][1],
147
+ ctx.input_shapes[0][2], ctx.input_shapes[0][3])),
148
+ /*source_code=*/std::move(source),
149
+ /*input=*/IOStructure::ONLY_DEFINITIONS,
150
+ /*output=*/IOStructure::AUTO,
151
+ };
152
+ return absl::OkStatus();
153
+ }
154
+ };
155
+
156
+ } // namespace
157
+
158
+ std::unique_ptr<NodeShader> NewDepthwiseConvolutionNodeShader() {
159
+ return absl::make_unique<DepthwiseConvolution>();
160
+ }
161
+
162
+ } // namespace gl
163
+ } // namespace gpu
164
+ } // namespace tflite
pool/shard001/C++/0022426_155.cpp ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ To generate a size n network, we consider the ways to combine a size i
3
+ network with a size j network in both parallel and series with i >= j, i + j =
4
+ n and i, j != n. This way we consider every size n network at least once,
5
+ and for each n we collect the distinct overall capacitances. Notice that
6
+ there is some dynamic programming involved, as the possible overall
7
+ capacitances for smaller network sizes is cached and retrieved when
8
+ determining the possible overall capacitances for the current network size.
9
+
10
+ Also in principle, we can use any fixed capacitance and don't have to stick
11
+ to 60 micro Farads. So we denote our fixed capacitance as 1. This way, when
12
+ we combine fractions, we can ensure that the numerator and denominator
13
+ remains as small as possible.
14
+
15
+ It turns out that with fixed capacitance 1, all related variables can fit
16
+ within unsigned int even while neglecting the GCD step of adding fractions.
17
+ As such, we can totally skip the GCD part of adding fractions and define our
18
+ own struct with a custom < operator that considers a / b < c / d <=> ad < bc
19
+ for use by std::set when checking for order.
20
+ */
21
+
22
+ #include <iostream>
23
+ #include <set>
24
+ #include <vector>
25
+
26
+ struct q_t
27
+ {
28
+ unsigned int n, d;
29
+ q_t(unsigned int const &_n, unsigned int const &_d) : n(_n), d(_d) { }
30
+
31
+ bool operator<(q_t const &rhs) const
32
+ {
33
+ return this->n * rhs.d < this->d * rhs.n;
34
+ }
35
+ };
36
+
37
+ int main()
38
+ {
39
+ std::set<q_t> all_values = {
40
+ { q_t(1, 1) }
41
+ };
42
+
43
+ std::vector<std::set<q_t>> values = {
44
+ { },
45
+ { q_t(1, 1) }
46
+ };
47
+
48
+ for (int n = 2; n <= 18; n++)
49
+ {
50
+ values.emplace_back();
51
+ int i = n - 1;
52
+ int j = 1;
53
+ while (i >= j)
54
+ {
55
+ for (q_t const &a : values[i])
56
+ {
57
+ for (q_t const &b : values[j])
58
+ {
59
+ int v = a.n * b.d + a.d * b.n;
60
+ q_t parallel(v, a.d * b.d);
61
+ q_t series(a.n * b.n, v);
62
+
63
+ if (all_values.find(parallel) == all_values.end())
64
+ {
65
+ values.back().emplace(parallel);
66
+ all_values.emplace(parallel);
67
+ }
68
+
69
+ if (all_values.find(series) == all_values.end())
70
+ {
71
+ values.back().emplace(series);
72
+ all_values.emplace(series);
73
+ }
74
+ }
75
+ }
76
+ i--;
77
+ j++;
78
+ }
79
+ }
80
+
81
+ std::cout << all_values.size();
82
+ }
pool/shard001/C++/0022432_DSPJitMisc.cpp ADDED
@@ -0,0 +1,194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2013 Dolphin Emulator Project
2
+ // Licensed under GPLv2
3
+ // Refer to the license.txt file included.
4
+
5
+ #include "../DSPEmitter.h"
6
+ #include "../DSPIntUtil.h"
7
+
8
+ using namespace Gen;
9
+
10
+ // MRR $D, $S
11
+ // 0001 11dd ddds ssss
12
+ // Move value from register $S to register $D.
13
+ void DSPEmitter::mrr(const UDSPInstruction opc)
14
+ {
15
+ u8 sreg = opc & 0x1f;
16
+ u8 dreg = (opc >> 5) & 0x1f;
17
+
18
+ dsp_op_read_reg(sreg, EDX);
19
+ dsp_op_write_reg(dreg, EDX);
20
+ dsp_conditional_extend_accum(dreg);
21
+ }
22
+
23
+ // LRI $D, #I
24
+ // 0000 0000 100d dddd
25
+ // iiii iiii iiii iiii
26
+ // Load immediate value I to register $D.
27
+ //
28
+ // DSPSpy discovery: This, and possibly other instructions that load a
29
+ // register, has a different behaviour in S40 mode if loaded to AC0.M: The
30
+ // value gets sign extended to the whole accumulator! This does not happen in
31
+ // S16 mode.
32
+ void DSPEmitter::lri(const UDSPInstruction opc)
33
+ {
34
+ u8 reg = opc & DSP_REG_MASK;
35
+ u16 imm = dsp_imem_read(compilePC+1);
36
+ dsp_op_write_reg_imm(reg, imm);
37
+ dsp_conditional_extend_accum_imm(reg, imm);
38
+ }
39
+
40
+ // LRIS $(0x18+D), #I
41
+ // 0000 1ddd iiii iiii
42
+ // Load immediate value I (8-bit sign extended) to accumulator register.
43
+ void DSPEmitter::lris(const UDSPInstruction opc)
44
+ {
45
+ u8 reg = ((opc >> 8) & 0x7) + DSP_REG_AXL0;
46
+ u16 imm = (s8)opc;
47
+ dsp_op_write_reg_imm(reg, imm);
48
+ dsp_conditional_extend_accum_imm(reg, imm);
49
+ }
50
+
51
+ //----
52
+
53
+ // NX
54
+ // 1000 -000 xxxx xxxx
55
+ // No operation, but can be extended with extended opcode.
56
+ // This opcode is supposed to do nothing - it's used if you want to use
57
+ // an opcode extension but not do anything. At least according to duddie.
58
+ void DSPEmitter::nx(const UDSPInstruction opc)
59
+ {
60
+ }
61
+
62
+ //----
63
+
64
+ // DAR $arD
65
+ // 0000 0000 0000 01dd
66
+ // Decrement address register $arD.
67
+ void DSPEmitter::dar(const UDSPInstruction opc)
68
+ {
69
+ // g_dsp.r[opc & 0x3] = dsp_decrement_addr_reg(opc & 0x3);
70
+ decrement_addr_reg(opc & 0x3);
71
+
72
+ }
73
+
74
+ // IAR $arD
75
+ // 0000 0000 0000 10dd
76
+ // Increment address register $arD.
77
+ void DSPEmitter::iar(const UDSPInstruction opc)
78
+ {
79
+ // g_dsp.r[opc & 0x3] = dsp_increment_addr_reg(opc & 0x3);
80
+ increment_addr_reg(opc & 0x3);
81
+ }
82
+
83
+ // SUBARN $arD
84
+ // 0000 0000 0000 11dd
85
+ // Subtract indexing register $ixD from an addressing register $arD.
86
+ // used only in IPL-NTSC ucode
87
+ void DSPEmitter::subarn(const UDSPInstruction opc)
88
+ {
89
+ // u8 dreg = opc & 0x3;
90
+ // g_dsp.r[dreg] = dsp_decrease_addr_reg(dreg, (s16)g_dsp.r[DSP_REG_IX0 + dreg]);
91
+ decrease_addr_reg(opc & 0x3);
92
+ }
93
+
94
+ // ADDARN $arD, $ixS
95
+ // 0000 0000 0001 ssdd
96
+ // Adds indexing register $ixS to an addressing register $arD.
97
+ // It is critical for the Zelda ucode that this one wraps correctly.
98
+ void DSPEmitter::addarn(const UDSPInstruction opc)
99
+ {
100
+ // u8 dreg = opc & 0x3;
101
+ // u8 sreg = (opc >> 2) & 0x3;
102
+ // g_dsp.r[dreg] = dsp_increase_addr_reg(dreg, (s16)g_dsp.r[DSP_REG_IX0 + sreg]);
103
+
104
+ // From looking around it is always called with the matching index register
105
+ increase_addr_reg(opc & 0x3, (opc >> 2) & 0x3);
106
+ }
107
+
108
+ //----
109
+
110
+
111
+ void DSPEmitter::setCompileSR(u16 bit)
112
+ {
113
+
114
+ // g_dsp.r[DSP_REG_SR] |= bit
115
+ OpArg sr_reg;
116
+ gpr.getReg(DSP_REG_SR,sr_reg);
117
+ OR(16, sr_reg, Imm16(bit));
118
+ gpr.putReg(DSP_REG_SR);
119
+
120
+ compileSR |= bit;
121
+ }
122
+
123
+ void DSPEmitter::clrCompileSR(u16 bit)
124
+ {
125
+
126
+ // g_dsp.r[DSP_REG_SR] &= bit
127
+ OpArg sr_reg;
128
+ gpr.getReg(DSP_REG_SR,sr_reg);
129
+ AND(16, sr_reg, Imm16(~bit));
130
+ gpr.putReg(DSP_REG_SR);
131
+
132
+ compileSR &= ~bit;
133
+ }
134
+ // SBCLR #I
135
+ // 0001 0011 aaaa aiii
136
+ // bit of status register $sr. Bit number is calculated by adding 6 to
137
+ // immediate value I.
138
+ void DSPEmitter::sbclr(const UDSPInstruction opc)
139
+ {
140
+ u8 bit = (opc & 0x7) + 6;
141
+
142
+ clrCompileSR(1 << bit);
143
+ }
144
+
145
+ // SBSET #I
146
+ // 0001 0010 aaaa aiii
147
+ // Set bit of status register $sr. Bit number is calculated by adding 6 to
148
+ // immediate value I.
149
+ void DSPEmitter::sbset(const UDSPInstruction opc)
150
+ {
151
+ u8 bit = (opc & 0x7) + 6;
152
+
153
+ setCompileSR(1 << bit);
154
+ }
155
+
156
+ // 1000 1bbb xxxx xxxx, bbb >= 010
157
+ // This is a bunch of flag setters, flipping bits in SR. So far so good,
158
+ // but it's harder to know exactly what effect they have.
159
+ void DSPEmitter::srbith(const UDSPInstruction opc)
160
+ {
161
+ switch ((opc >> 8) & 0xf)
162
+ {
163
+ // M0/M2 change the multiplier mode (it can multiply by 2 for free).
164
+ case 0xa: // M2
165
+ clrCompileSR(SR_MUL_MODIFY);
166
+ break;
167
+ case 0xb: // M0
168
+ setCompileSR(SR_MUL_MODIFY);
169
+ break;
170
+
171
+ // If set, treat multiplicands as unsigned.
172
+ // If clear, treat them as signed.
173
+ case 0xc: // CLR15
174
+ clrCompileSR(SR_MUL_UNSIGNED);
175
+ break;
176
+ case 0xd: // SET15
177
+ setCompileSR(SR_MUL_UNSIGNED);
178
+ break;
179
+
180
+ // Automatic 40-bit sign extension when loading ACx.M.
181
+ // SET40 changes something very important: see the LRI instruction above.
182
+ case 0xe: // SET16 (CLR40)
183
+ clrCompileSR(SR_40_MODE_BIT);
184
+ break;
185
+
186
+ case 0xf: // SET40
187
+ setCompileSR(SR_40_MODE_BIT);
188
+ break;
189
+
190
+ default:
191
+ break;
192
+ }
193
+ }
194
+
pool/shard001/C++/0022436_takeoff.cpp ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /****************************************************************************
2
+ *
3
+ * Copyright (c) 2013-2014 PX4 Development Team. All rights reserved.
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without
6
+ * modification, are permitted provided that the following conditions
7
+ * are met:
8
+ *
9
+ * 1. Redistributions of source code must retain the above copyright
10
+ * notice, this list of conditions and the following disclaimer.
11
+ * 2. Redistributions in binary form must reproduce the above copyright
12
+ * notice, this list of conditions and the following disclaimer in
13
+ * the documentation and/or other materials provided with the
14
+ * distribution.
15
+ * 3. Neither the name PX4 nor the names of its contributors may be
16
+ * used to endorse or promote products derived from this software
17
+ * without specific prior written permission.
18
+ *
19
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
+ * POSSIBILITY OF SUCH DAMAGE.
31
+ *
32
+ ****************************************************************************/
33
+ /**
34
+ * @file takeoff.cpp
35
+ *
36
+ * Helper class to Takeoff
37
+ *
38
+ * @author Lorenz Meier <lorenz@px4.io>
39
+ */
40
+
41
+ #include "takeoff.h"
42
+ #include "navigator.h"
43
+
44
+ Takeoff::Takeoff(Navigator *navigator) :
45
+ MissionBlock(navigator)
46
+ {
47
+ }
48
+
49
+ void
50
+ Takeoff::on_activation()
51
+ {
52
+ set_takeoff_position();
53
+ }
54
+
55
+ void
56
+ Takeoff::on_active()
57
+ {
58
+ struct position_setpoint_triplet_s *rep = _navigator->get_takeoff_triplet();
59
+
60
+ if (rep->current.valid) {
61
+ // reset the position
62
+ set_takeoff_position();
63
+
64
+ } else if (is_mission_item_reached() && !_navigator->get_mission_result()->finished) {
65
+ _navigator->get_mission_result()->finished = true;
66
+ _navigator->set_mission_result_updated();
67
+
68
+ // set loiter item so position controllers stop doing takeoff logic
69
+ set_loiter_item(&_mission_item);
70
+ struct position_setpoint_triplet_s *pos_sp_triplet = _navigator->get_position_setpoint_triplet();
71
+ mission_apply_limitation(_mission_item);
72
+ mission_item_to_position_setpoint(_mission_item, &pos_sp_triplet->current);
73
+ _navigator->set_position_setpoint_triplet_updated();
74
+ }
75
+ }
76
+
77
+ void
78
+ Takeoff::set_takeoff_position()
79
+ {
80
+ struct position_setpoint_triplet_s *rep = _navigator->get_takeoff_triplet();
81
+
82
+ float abs_altitude = 0.0f;
83
+
84
+ float min_abs_altitude;
85
+
86
+ if (_navigator->home_position_valid()) { //only use home position if it is valid
87
+ min_abs_altitude = _navigator->get_global_position()->alt + _navigator->get_takeoff_min_alt();
88
+
89
+ } else { //e.g. flow
90
+ min_abs_altitude = _navigator->get_takeoff_min_alt();
91
+ }
92
+
93
+ // Use altitude if it has been set. If home position is invalid use min_abs_altitude
94
+ if (rep->current.valid && PX4_ISFINITE(rep->current.alt) && _navigator->home_position_valid()) {
95
+ abs_altitude = rep->current.alt;
96
+
97
+ // If the altitude suggestion is lower than home + minimum clearance, raise it and complain.
98
+ if (abs_altitude < min_abs_altitude) {
99
+ if (abs_altitude < min_abs_altitude - 0.1f) { // don't complain if difference is smaller than 10cm
100
+ mavlink_log_critical(_navigator->get_mavlink_log_pub(),
101
+ "Using minimum takeoff altitude: %.2f m", (double)_navigator->get_takeoff_min_alt());
102
+ }
103
+
104
+ abs_altitude = min_abs_altitude;
105
+ }
106
+
107
+ } else {
108
+ // Use home + minimum clearance but only notify.
109
+ abs_altitude = min_abs_altitude;
110
+ mavlink_log_info(_navigator->get_mavlink_log_pub(),
111
+ "Using minimum takeoff altitude: %.2f m", (double)_navigator->get_takeoff_min_alt());
112
+ }
113
+
114
+
115
+ if (abs_altitude < _navigator->get_global_position()->alt) {
116
+ // If the suggestion is lower than our current alt, let's not go down.
117
+ abs_altitude = _navigator->get_global_position()->alt;
118
+ mavlink_log_critical(_navigator->get_mavlink_log_pub(), "Already higher than takeoff altitude");
119
+ }
120
+
121
+ // set current mission item to takeoff
122
+ set_takeoff_item(&_mission_item, abs_altitude);
123
+ _navigator->get_mission_result()->finished = false;
124
+ _navigator->set_mission_result_updated();
125
+ reset_mission_item_reached();
126
+
127
+ // convert mission item to current setpoint
128
+ struct position_setpoint_triplet_s *pos_sp_triplet = _navigator->get_position_setpoint_triplet();
129
+ mission_apply_limitation(_mission_item);
130
+ mission_item_to_position_setpoint(_mission_item, &pos_sp_triplet->current);
131
+
132
+ pos_sp_triplet->previous.valid = false;
133
+ pos_sp_triplet->current.yaw_valid = true;
134
+ pos_sp_triplet->next.valid = false;
135
+
136
+ if (rep->current.valid) {
137
+
138
+ // Go on and check which changes had been requested
139
+ if (PX4_ISFINITE(rep->current.yaw)) {
140
+ pos_sp_triplet->current.yaw = rep->current.yaw;
141
+ }
142
+
143
+ // Set the current latitude and longitude even if they are NAN
144
+ // NANs are handled in FlightTaskAuto.cpp
145
+ pos_sp_triplet->current.lat = rep->current.lat;
146
+ pos_sp_triplet->current.lon = rep->current.lon;
147
+
148
+ // mark this as done
149
+ memset(rep, 0, sizeof(*rep));
150
+ }
151
+
152
+ if (PX4_ISFINITE(pos_sp_triplet->current.lat) && PX4_ISFINITE(pos_sp_triplet->current.lon)) {
153
+ _navigator->set_can_loiter_at_sp(true);
154
+
155
+ } else {
156
+ _navigator->set_can_loiter_at_sp(false);
157
+ }
158
+
159
+ _navigator->set_position_setpoint_triplet_updated();
160
+ }