Pendigard commited on
Commit
cf0f72e
·
verified ·
1 Parent(s): d474875

Upload folder using huggingface_hub (part 123)

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/shard011/C++/0121588_pty_util.cc +58 -0
  2. pool/shard011/C++/0121589_NMR_ModelReaderNode093_Color.cpp +168 -0
  3. pool/shard011/C++/0121590_flowtab.cpp +99 -0
  4. pool/shard011/C++/0121591_MeanSquaredLogError.cpp +45 -0
  5. pool/shard011/C++/0121592_User.cc +95 -0
  6. pool/shard011/C++/0121595_RenderLayerFilterInfo.cpp +136 -0
  7. pool/shard011/C++/0121596_TestAudioAC3toMP2.cpp +159 -0
  8. pool/shard011/C++/0121597_resolve_reduce_attributes.cc +76 -0
  9. pool/shard011/C++/0121599_gsl_distribution.cpp +150 -0
  10. pool/shard011/C++/0121600_timeslice_timeout.cpp +55 -0
  11. pool/shard011/C++/0121602_BLECharacteristic.cpp +147 -0
  12. pool/shard011/C++/0121603_ana2morfsar.cc +241 -0
  13. pool/shard011/C++/0121605_CaiGpsNav.cpp +77 -0
  14. pool/shard011/C++/0121606_PixelShader.cpp +38 -0
  15. pool/shard011/C++/0121610_ClientRequestFactory.cpp +139 -0
  16. pool/shard011/C++/0121611_drawing-group.cpp +167 -0
  17. pool/shard011/C++/0121614_rangeSensor.cpp +121 -0
  18. pool/shard011/C++/0121615_xfa_layout_appadapter.cpp +56 -0
  19. pool/shard011/C++/0121616_TcpConnector.cpp +162 -0
  20. pool/shard011/C++/0121617_PostRAHazardRecognizer.cpp +98 -0
  21. pool/shard011/C++/0121621_KoOasisSettings.cpp +224 -0
  22. pool/shard011/C++/0121623_campaign.cpp +237 -0
  23. pool/shard011/C++/0121624_testParser.cpp +47 -0
  24. pool/shard011/C++/0121626_TrueTypeRasterizer.cpp +202 -0
  25. pool/shard011/C++/0121627_devtools_network_protocol_handler.cc +114 -0
  26. pool/shard011/C++/0121628_GtPolylineF.cpp +193 -0
  27. pool/shard011/C++/0121629_syscall_wrappers_unittest.cc +65 -0
  28. pool/shard011/C++/0121630_token_service_table_unittest.cc +112 -0
  29. pool/shard011/C++/0121632_CWE195_Signed_to_Unsigned_Conversion_Error__fgets_memmove_73b.cpp +73 -0
  30. pool/shard011/C++/0121633_CanvasRenderingContext.cpp +113 -0
  31. pool/shard011/C++/0121635_del_source_formula_Equivalence_Normalize.cpp +188 -0
  32. pool/shard011/C++/0121636_motion_event_web.cc +180 -0
  33. pool/shard011/C++/0121637_SubspaceChat.cpp +264 -0
  34. pool/shard011/C++/0121638_chain.cpp +198 -0
  35. pool/shard011/C++/0121639_zip_reader_ctocpp.cc +220 -0
  36. pool/shard011/C++/0121641_PrimitiveTypeDeclaration.cpp +93 -0
  37. pool/shard011/C++/0121642_MicroBenchmarksQ31.cpp +105 -0
  38. pool/shard011/C++/0121643_FirstPass.cpp +22 -0
  39. pool/shard011/C++/0121645_addatodialog_funcs.cpp +109 -0
  40. pool/shard011/C++/0121646_dlguser.cpp +136 -0
  41. pool/shard011/C++/0121647_renumber_component_wise_01.cc +75 -0
  42. pool/shard011/C++/0121648_help_app_launcher.cc +89 -0
  43. pool/shard011/C++/0121650_FourierTransformationTest.cpp +140 -0
  44. pool/shard011/C++/0121651_ProcessList.cpp +95 -0
  45. pool/shard011/C++/0121653_sensor_comparator_component.cc +66 -0
  46. pool/shard011/C++/0121655_pet_dk.cpp +138 -0
  47. pool/shard011/C++/0121656_glut_win.cpp +138 -0
  48. pool/shard011/C++/0121658_main.cpp +40 -0
  49. pool/shard011/C++/0121660_checkpoints.cpp +87 -0
  50. pool/shard011/C++/0121661_kis_deform_paintop_settings_widget.cpp +80 -0
pool/shard011/C++/0121588_pty_util.cc ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2019 The gVisor Authors.
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
+ #include "test/util/pty_util.h"
16
+
17
+ #include <sys/ioctl.h>
18
+ #include <termios.h>
19
+
20
+ #include "test/util/file_descriptor.h"
21
+ #include "test/util/posix_error.h"
22
+
23
+ namespace gvisor {
24
+ namespace testing {
25
+
26
+ PosixErrorOr<FileDescriptor> OpenReplica(const FileDescriptor& master) {
27
+ return OpenReplica(master, O_NONBLOCK | O_RDWR | O_NOCTTY);
28
+ }
29
+
30
+ PosixErrorOr<FileDescriptor> OpenReplica(const FileDescriptor& master,
31
+ int flags) {
32
+ PosixErrorOr<int> n = ReplicaID(master);
33
+ if (!n.ok()) {
34
+ return PosixErrorOr<FileDescriptor>(n.error());
35
+ }
36
+ return Open(absl::StrCat("/dev/pts/", n.ValueOrDie()), flags);
37
+ }
38
+
39
+ PosixErrorOr<int> ReplicaID(const FileDescriptor& master) {
40
+ // Get pty index.
41
+ int n;
42
+ int ret = ioctl(master.get(), TIOCGPTN, &n);
43
+ if (ret < 0) {
44
+ return PosixError(errno, "ioctl(TIOCGPTN) failed");
45
+ }
46
+
47
+ // Unlock pts.
48
+ int unlock = 0;
49
+ ret = ioctl(master.get(), TIOCSPTLCK, &unlock);
50
+ if (ret < 0) {
51
+ return PosixError(errno, "ioctl(TIOSPTLCK) failed");
52
+ }
53
+
54
+ return n;
55
+ }
56
+
57
+ } // namespace testing
58
+ } // namespace gvisor
pool/shard011/C++/0121589_NMR_ModelReaderNode093_Color.cpp ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*++
2
+
3
+ Copyright (C) 2018 3MF Consortium
4
+
5
+ All rights reserved.
6
+
7
+ Redistribution and use in source and binary forms, with or without modification,
8
+ are permitted provided that the following conditions are met:
9
+
10
+ 1. Redistributions of source code must retain the above copyright notice, this
11
+ list of conditions and the following disclaimer.
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
20
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
+
27
+ Abstract:
28
+ NMR_ModelReaderNode093_Color.cpp implements the Model Reader Color Node Class.
29
+ A color reader model node is a parser for the color node of an XML Model Stream.
30
+
31
+ --*/
32
+
33
+ #include "Model/Reader/v093/NMR_ModelReaderNode093_Color.h"
34
+
35
+ #include "Model/Classes/NMR_ModelConstants.h"
36
+ #include "Common/NMR_Exception.h"
37
+ #include "Common/NMR_Exception_Windows.h"
38
+ #include "Common/NMR_StringUtils.h"
39
+ #include <cmath>
40
+ #include <climits>
41
+
42
+ namespace NMR {
43
+
44
+ CModelReaderNode093_Color::CModelReaderNode093_Color(_In_ PModelWarnings pWarnings)
45
+ : CModelReaderNode(pWarnings)
46
+ {
47
+ m_nResourceID = 0;
48
+ m_nTextureID = 0;
49
+ }
50
+
51
+ void CModelReaderNode093_Color::parseXML(_In_ CXmlReader * pXMLReader)
52
+ {
53
+ // Parse name
54
+ parseName(pXMLReader);
55
+
56
+ // Parse attribute
57
+ parseAttributes(pXMLReader);
58
+
59
+ // Parse Content
60
+ parseContent(pXMLReader);
61
+
62
+ // Parse Color
63
+ parseColor();
64
+ }
65
+
66
+ nfColor CModelReaderNode093_Color::retrieveColor()
67
+ {
68
+ return m_cColor;
69
+ }
70
+
71
+ void CModelReaderNode093_Color::parseColor()
72
+ {
73
+ m_cColor = 0;
74
+
75
+ try {
76
+ if (m_sColorString.length() > 0) {
77
+ nfChar bFirstChar = m_sColorString[0];
78
+ if (bFirstChar == '#') {
79
+ if (fnStringToSRGBColor(m_sColorString.c_str(), m_cColor)) {
80
+ return;
81
+ }
82
+ }
83
+
84
+ if (bFirstChar == 's') {
85
+ std::string sSubStr = m_sColorString.substr(0, 5);
86
+ if (sSubStr == "scRGB") {
87
+ // parse scRGB String
88
+ throw CNMRException(NMR_ERROR_NOTIMPLEMENTED);
89
+ }
90
+ }
91
+
92
+ if (bFirstChar == L't') {
93
+ std::string sSubStr = m_sColorString.substr(0, 4);
94
+ if (sSubStr == "tex(") {
95
+ // parse Texture String
96
+
97
+ if (m_sColorString.length() > 4) {
98
+ std::string sTexID = m_sColorString.substr(4, m_sColorString.length() - sSubStr.length() - 1);
99
+ nfInt32 nValue = fnStringToInt32(sTexID.c_str());
100
+ if ((nValue < 0) || (nValue >= XML_3MF_MAXRESOURCEINDEX))
101
+ throw CNMRException(NMR_ERROR_INVALIDTEXTUREREFERENCE);
102
+
103
+ m_nTextureID = nValue + 1;
104
+ return;
105
+ }
106
+ else {
107
+ throw CNMRException(NMR_ERROR_INVALIDTEXTUREREFERENCE);
108
+ }
109
+ }
110
+ }
111
+
112
+ if (bFirstChar == 'C') {
113
+ std::string sSubStr4 = m_sColorString.substr(0, 4);
114
+ if (sSubStr4 == "CMYK") {
115
+ throw CNMRException(NMR_ERROR_NOTSUPPORTINGLEGACYCMYK);
116
+ }
117
+ }
118
+
119
+ }
120
+
121
+ throw CNMRException(NMR_ERROR_INVALIDVALUEINCOLORSTRING);
122
+ }
123
+ catch (CNMRException & Exception) {
124
+ m_pWarnings->addException(Exception, mrwMissingMandatoryValue);
125
+ }
126
+
127
+ }
128
+
129
+
130
+ ModelResourceID CModelReaderNode093_Color::retrieveID()
131
+ {
132
+ try {
133
+ //if (m_nUniqueResourceID == 0)
134
+ //throw CNMRException(NMR_ERROR_MISSINGMODELCOLORID);
135
+ }
136
+ catch (CNMRException & Exception) {
137
+ m_pWarnings->addException(Exception, mrwMissingMandatoryValue);
138
+ }
139
+
140
+ return m_nResourceID;
141
+ }
142
+
143
+ void CModelReaderNode093_Color::OnAttribute(_In_z_ const nfChar * pAttributeName, _In_z_ const nfChar * pAttributeValue)
144
+ {
145
+ __NMRASSERT(pAttributeName);
146
+ __NMRASSERT(pAttributeValue);
147
+
148
+ if (strcmp(pAttributeName, XML_3MF_ATTRIBUTE_COLOR_VALUE) == 0) {
149
+ m_sColorString = pAttributeValue;
150
+ }
151
+
152
+ if (strcmp(pAttributeName, XML_3MF_ATTRIBUTE_COLOR_ID) == 0) {
153
+ if (m_nResourceID != 0)
154
+ throw CNMRException(NMR_ERROR_DUPLICATECOLORID);
155
+
156
+ // Convert to integer and make a input and range check!
157
+ m_nResourceID = fnStringToUint32(pAttributeValue);
158
+ m_nResourceID++;
159
+ }
160
+
161
+ }
162
+
163
+ ModelResourceID CModelReaderNode093_Color::retrieveTextureID()
164
+ {
165
+ return m_nTextureID;
166
+ }
167
+
168
+ }
pool/shard011/C++/0121590_flowtab.cpp ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*************************************************************************
2
+ * Copyright (c) 2015, Synopsys, Inc. *
3
+ * 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 are *
7
+ * met: *
8
+ * *
9
+ * 1. Redistributions of source code must retain the above copyright *
10
+ * notice, this list of conditions and the following disclaimer. *
11
+ * *
12
+ * 2. Redistributions in binary form must reproduce the above copyright *
13
+ * notice, this list of conditions and the following disclaimer in the *
14
+ * documentation and/or other materials provided with the distribution. *
15
+ * *
16
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
17
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
18
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
19
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT *
20
+ * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
21
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
22
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
23
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
24
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
25
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
26
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
27
+ *************************************************************************/
28
+ // FlowTab.cpp : implementation file
29
+ //
30
+
31
+ #include "stdafx.h"
32
+ #include "discovermdi.h"
33
+ #include "FlowTab.h"
34
+
35
+ #ifdef _DEBUG
36
+ #define new DEBUG_NEW
37
+ #undef THIS_FILE
38
+ static char THIS_FILE[] = __FILE__;
39
+ #endif
40
+
41
+ /////////////////////////////////////////////////////////////////////////////
42
+ // CFlowTab
43
+
44
+ CFlowTab::CFlowTab()
45
+ {
46
+ }
47
+
48
+ CFlowTab::~CFlowTab()
49
+ {
50
+ }
51
+
52
+
53
+ BEGIN_MESSAGE_MAP(CFlowTab, CTabCtrl)
54
+ //{{AFX_MSG_MAP(CFlowTab)
55
+ ON_WM_LBUTTONDOWN()
56
+ //}}AFX_MSG_MAP
57
+ END_MESSAGE_MAP()
58
+
59
+ /////////////////////////////////////////////////////////////////////////////
60
+ // CFlowTab message handlers
61
+
62
+ void CFlowTab::OnLButtonDown(UINT nFlags, CPoint point) {
63
+ int* elements;
64
+ POINT p;
65
+ int item;
66
+ TC_HITTESTINFO test;
67
+
68
+ p.x=point.x;
69
+ p.y=point.y;
70
+ test.pt.x=p.x;
71
+ test.pt.y=p.y;
72
+ test.flags=TCHT_NOWHERE;
73
+ item=HitTest(&test);
74
+ if(item==-1) return;
75
+ SetCurSel(item);
76
+
77
+ // Register or get clipboard format for the task flow node
78
+ UINT formatID=RegisterClipboardFormat("DiscoverTaskFlowNode");
79
+ // Alocate memory for all selected elements indexes.
80
+ // The DragAndDrop Target will receve this array
81
+ HGLOBAL dataID = GlobalAlloc(GMEM_FIXED,3*sizeof(int));
82
+ elements = (int *)::GlobalLock(dataID);
83
+ // Fill an array with the selected elements
84
+ elements[0]=OP_MOVE;
85
+ elements[1]=1;
86
+ elements[2]=item;
87
+ GlobalUnlock(dataID);
88
+ m_DropSource.CacheGlobalData(formatID, dataID);
89
+ m_DropSource.DoDragDrop();
90
+
91
+
92
+ NMHDR info;
93
+ info.hwndFrom=*this;
94
+ info.idFrom=GetWindowLong(*this,GWL_ID);
95
+ info.code=TCN_SELCHANGE;
96
+ SetFocus();
97
+ GetParent()->SendMessage(WM_NOTIFY,(WPARAM)GetWindowLong(*this,GWL_ID),(LPARAM)&info);
98
+ }
99
+
pool/shard011/C++/0121591_MeanSquaredLogError.cpp ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * This program is free software; you can redistribute it and/or modify
3
+ * it under the terms of the GNU General Public License as published by
4
+ * the Free Software Foundation; either version 3 of the License, or
5
+ * (at your option) any later version.
6
+ *
7
+ * Written (W) 2012 Heiko Strathmann
8
+ * Copyright (C) 2012 Berlin Institute of Technology and Max-Planck-Society
9
+ */
10
+
11
+ #include <shogun/evaluation/MeanSquaredLogError.h>
12
+ #include <shogun/labels/Labels.h>
13
+ #include <shogun/labels/RegressionLabels.h>
14
+ #include <shogun/mathematics/Math.h>
15
+
16
+ using namespace shogun;
17
+
18
+ float64_t CMeanSquaredLogError::evaluate(CLabels* predicted, CLabels* ground_truth)
19
+ {
20
+ ASSERT(predicted && ground_truth);
21
+ ASSERT(predicted->get_num_labels()==ground_truth->get_num_labels());
22
+ ASSERT(predicted->get_label_type()==LT_REGRESSION);
23
+ ASSERT(ground_truth->get_label_type()==LT_REGRESSION);
24
+
25
+ int32_t length=predicted->get_num_labels();
26
+ float64_t msle=0.0;
27
+ for (int32_t i=0; i<length; i++)
28
+ {
29
+ float64_t prediction=((CRegressionLabels*) predicted)->get_label(i);
30
+ float64_t truth=((CRegressionLabels*) ground_truth)->get_label(i);
31
+
32
+ if (prediction<=-1.0 || truth<=-1.0)
33
+ {
34
+ SG_WARNING("Negative label[%d] in %s is not allowed, ignoring!\n",
35
+ i, get_name());
36
+ continue;
37
+ }
38
+
39
+ float64_t a=CMath::log(prediction+1);
40
+ float64_t b=CMath::log(truth+1);
41
+ msle+=CMath::sq(a-b);
42
+ }
43
+ msle /= length;
44
+ return CMath::sqrt(msle);
45
+ }
pool/shard011/C++/0121592_User.cc ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
3
+ *
4
+ * Squid software is distributed under GPLv2+ license and includes
5
+ * contributions from numerous individuals and organizations.
6
+ * Please see the COPYING and CONTRIBUTORS files for details.
7
+ */
8
+
9
+ #include "squid.h"
10
+ #include "auth/basic/Config.h"
11
+ #include "auth/basic/User.h"
12
+ #include "auth/CredentialsCache.h"
13
+ #include "Debug.h"
14
+ #include "SquidConfig.h"
15
+ #include "SquidTime.h"
16
+
17
+ Auth::Basic::User::User(Auth::Config *aConfig, const char *aRequestRealm) :
18
+ Auth::User(aConfig, aRequestRealm),
19
+ passwd(NULL),
20
+ queue(NULL),
21
+ currentRequest(NULL)
22
+ {}
23
+
24
+ Auth::Basic::User::~User()
25
+ {
26
+ safe_free(passwd);
27
+ }
28
+
29
+ int32_t
30
+ Auth::Basic::User::ttl() const
31
+ {
32
+ if (credentials() != Auth::Ok && credentials() != Auth::Pending)
33
+ return -1; // TTL is obsolete NOW.
34
+
35
+ int32_t basic_ttl = expiretime - squid_curtime + static_cast<Auth::Basic::Config*>(config)->credentialsTTL;
36
+ int32_t global_ttl = static_cast<int32_t>(expiretime - squid_curtime + ::Config.authenticateTTL);
37
+
38
+ return min(basic_ttl, global_ttl);
39
+ }
40
+
41
+ bool
42
+ Auth::Basic::User::authenticated() const
43
+ {
44
+ if ((credentials() == Auth::Ok) && (expiretime + static_cast<Auth::Basic::Config*>(config)->credentialsTTL > squid_curtime))
45
+ return true;
46
+
47
+ debugs(29, 4, "User not authenticated or credentials need rechecking.");
48
+
49
+ return false;
50
+ }
51
+
52
+ bool
53
+ Auth::Basic::User::valid() const
54
+ {
55
+ if (username() == NULL)
56
+ return false;
57
+ if (passwd == NULL)
58
+ return false;
59
+ return true;
60
+ }
61
+
62
+ void
63
+ Auth::Basic::User::updateCached(Auth::Basic::User *from)
64
+ {
65
+ debugs(29, 9, HERE << "Found user '" << from->username() << "' already in the user cache as '" << this << "'");
66
+
67
+ assert(strcmp(from->username(), username()) == 0);
68
+
69
+ if (strcmp(from->passwd, passwd)) {
70
+ debugs(29, 4, HERE << "new password found. Updating in user master record and resetting auth state to unchecked");
71
+ credentials(Auth::Unchecked);
72
+ xfree(passwd);
73
+ passwd = from->passwd;
74
+ from->passwd = NULL;
75
+ }
76
+
77
+ if (credentials() == Auth::Failed) {
78
+ debugs(29, 4, HERE << "last attempt to authenticate this user failed, resetting auth state to unchecked");
79
+ credentials(Auth::Unchecked);
80
+ }
81
+ }
82
+
83
+ CbcPointer<Auth::CredentialsCache>
84
+ Auth::Basic::User::Cache()
85
+ {
86
+ static CbcPointer<Auth::CredentialsCache> p(new Auth::CredentialsCache("basic", "GC Basic user credentials"));
87
+ return p;
88
+ }
89
+
90
+ void
91
+ Auth::Basic::User::addToNameCache()
92
+ {
93
+ Cache()->insert(userKey(), this);
94
+ }
95
+
pool/shard011/C++/0121595_RenderLayerFilterInfo.cpp ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved.
3
+ * Copyright (C) 2013 Apple Inc. 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
10
+ * copyright notice, this list of conditions and the following
11
+ * disclaimer.
12
+ * 2. Redistributions in binary form must reproduce the above
13
+ * copyright notice, this list of conditions and the following
14
+ * disclaimer in the documentation and/or other materials
15
+ * provided with the distribution.
16
+ *
17
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
18
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
21
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
22
+ * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
26
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27
+ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28
+ * SUCH DAMAGE.
29
+ */
30
+
31
+ #include "config.h"
32
+ #include "RenderLayerFilterInfo.h"
33
+
34
+ #include "CachedSVGDocument.h"
35
+ #include "CachedSVGDocumentReference.h"
36
+ #include "FilterEffectRenderer.h"
37
+ #include "RenderSVGResourceFilter.h"
38
+ #include <wtf/NeverDestroyed.h>
39
+
40
+ namespace WebCore {
41
+
42
+ HashMap<const RenderLayer*, std::unique_ptr<RenderLayer::FilterInfo>>& RenderLayer::FilterInfo::map()
43
+ {
44
+ static NeverDestroyed<HashMap<const RenderLayer*, std::unique_ptr<FilterInfo>>> map;
45
+ return map;
46
+ }
47
+
48
+ RenderLayer::FilterInfo* RenderLayer::FilterInfo::getIfExists(const RenderLayer& layer)
49
+ {
50
+ ASSERT(layer.m_hasFilterInfo == map().contains(&layer));
51
+
52
+ return layer.m_hasFilterInfo ? map().get(&layer) : nullptr;
53
+ }
54
+
55
+ RenderLayer::FilterInfo& RenderLayer::FilterInfo::get(RenderLayer& layer)
56
+ {
57
+ ASSERT(layer.m_hasFilterInfo == map().contains(&layer));
58
+
59
+ auto& info = map().add(&layer, nullptr).iterator->value;
60
+ if (!info) {
61
+ info = std::make_unique<FilterInfo>(layer);
62
+ layer.m_hasFilterInfo = true;
63
+ }
64
+ return *info;
65
+ }
66
+
67
+ void RenderLayer::FilterInfo::remove(RenderLayer& layer)
68
+ {
69
+ ASSERT(layer.m_hasFilterInfo == map().contains(&layer));
70
+ if (!layer.m_hasFilterInfo)
71
+ return;
72
+
73
+ map().remove(&layer);
74
+ layer.m_hasFilterInfo = false;
75
+ }
76
+
77
+ RenderLayer::FilterInfo::FilterInfo(RenderLayer& layer)
78
+ : m_layer(layer)
79
+ {
80
+ }
81
+
82
+ RenderLayer::FilterInfo::~FilterInfo()
83
+ {
84
+ removeReferenceFilterClients();
85
+ }
86
+
87
+ void RenderLayer::FilterInfo::setRenderer(RefPtr<FilterEffectRenderer>&& renderer)
88
+ {
89
+ m_renderer = renderer;
90
+ }
91
+
92
+ void RenderLayer::FilterInfo::notifyFinished(CachedResource&)
93
+ {
94
+ m_layer.filterNeedsRepaint();
95
+ }
96
+
97
+ void RenderLayer::FilterInfo::updateReferenceFilterClients(const FilterOperations& operations)
98
+ {
99
+ removeReferenceFilterClients();
100
+ for (auto& operation : operations.operations()) {
101
+ if (!is<ReferenceFilterOperation>(*operation))
102
+ continue;
103
+ auto& referenceOperation = downcast<ReferenceFilterOperation>(*operation);
104
+ auto* documentReference = referenceOperation.cachedSVGDocumentReference();
105
+ if (auto* cachedSVGDocument = documentReference ? documentReference->document() : nullptr) {
106
+ // Reference is external; wait for notifyFinished().
107
+ cachedSVGDocument->addClient(*this);
108
+ m_externalSVGReferences.append(cachedSVGDocument);
109
+ } else {
110
+ // Reference is internal; add layer as a client so we can trigger filter repaint on SVG attribute change.
111
+ auto* filter = m_layer.renderer().document().getElementById(referenceOperation.fragment());
112
+ if (!filter)
113
+ continue;
114
+ auto* renderer = filter->renderer();
115
+ if (!is<RenderSVGResourceFilter>(renderer))
116
+ continue;
117
+ downcast<RenderSVGResourceFilter>(*renderer).addClientRenderLayer(&m_layer);
118
+ m_internalSVGReferences.append(filter);
119
+ }
120
+ }
121
+ }
122
+
123
+ void RenderLayer::FilterInfo::removeReferenceFilterClients()
124
+ {
125
+ for (auto& resourceHandle : m_externalSVGReferences)
126
+ resourceHandle->removeClient(*this);
127
+ m_externalSVGReferences.clear();
128
+
129
+ for (auto& filter : m_internalSVGReferences) {
130
+ if (auto* renderer = filter->renderer())
131
+ downcast<RenderSVGResourceContainer>(*renderer).removeClientRenderLayer(&m_layer);
132
+ }
133
+ m_internalSVGReferences.clear();
134
+ }
135
+
136
+ } // namespace WebCore
pool/shard011/C++/0121596_TestAudioAC3toMP2.cpp ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * File: TestAudioAC3toMP2.cpp
3
+ * Author: jhoelscher
4
+ *
5
+ * Created on 15. Juni 2009, 18:31
6
+ */
7
+
8
+ #include "org/esb/io/File.h"
9
+ #include "org/esb/av/FormatInputStream.h"
10
+ #include "org/esb/av/PacketInputStream.h"
11
+ #include "org/esb/av/FormatOutputStream.h"
12
+ #include "org/esb/av/PacketOutputStream.h"
13
+ #include "org/esb/av/Packet.h"
14
+ #include "org/esb/av/Encoder.h"
15
+ #include "org/esb/av/Decoder.h"
16
+ #include "org/esb/av/Frame.h"
17
+ #include "org/esb/av/FrameConverter.h"
18
+ #include "org/esb/util/Decimal.h"
19
+
20
+
21
+ #include "org/esb/io/FileInputStream.h"
22
+ #include "org/esb/io/FileOutputStream.h"
23
+ //#include "org/esb/lang/StackDumper.h"
24
+ #include <list>
25
+ using namespace org::esb::io;
26
+ using namespace org::esb::av;
27
+ using namespace org::esb::util;
28
+ using namespace org::esb::lang;
29
+
30
+ class PacketSink : public Sink {
31
+ public:
32
+
33
+ PacketSink() {
34
+ }
35
+
36
+ void write(void * p) {
37
+
38
+ LOGDEBUG("Write Packet to Term Sink");
39
+ Packet* pt = (Packet*) p;
40
+ boost::shared_ptr<Packet> pEnc(new Packet(*pt));
41
+ pkts.push_back(pEnc);
42
+ }
43
+
44
+ std::list<boost::shared_ptr<Packet> > getList() {
45
+ return pkts;
46
+ }
47
+ private:
48
+ std::list<boost::shared_ptr<Packet> > pkts;
49
+
50
+ };
51
+
52
+ int main(int argc, char ** argv) {
53
+ // StackDumper stack(".");
54
+ // int stream_id = 2;
55
+ // File infile("/media/video/ChocolateFactory.ts");
56
+ // File infile("/home/jhoelscher/MediaEncodingCluster/big_buck_bunny_480p_surround-fix.avi");
57
+ std::string src;
58
+
59
+ if (argc == 1) {
60
+ src = MEC_SOURCE_DIR;
61
+ src.append("/test.dvd");
62
+ } else {
63
+ src = argv[1];
64
+ }
65
+ int stream_id = 1;
66
+ if (argc == 3) {
67
+ stream_id = atoi(argv[2]);
68
+ }
69
+
70
+ File infile(src);
71
+ // int stream_id = atoi(argv[2]);
72
+ File outfile("test.mp3");
73
+
74
+ FormatInputStream fis(&infile);
75
+ fis.dumpFormat();
76
+ PacketInputStream pis(&fis);
77
+
78
+ FormatOutputStream fos(&outfile);
79
+ PacketOutputStream pos(&fos);
80
+
81
+ AVCodecContext * c = fis.getFormatContext()->streams[stream_id]->codec;
82
+ Decoder dec(c->codec_id); //CODEC_ID_EAC3
83
+ LOGDEBUG("ChannelLayout:" << fis.getFormatContext()->streams[stream_id]->codec->channel_layout)
84
+ // Decoder dec(c);
85
+
86
+
87
+ dec.setChannels(c->channels);
88
+ // dec.setChannels(2);
89
+ dec.setBitRate(c->bit_rate);
90
+ dec.setSampleRate(c->sample_rate);
91
+ dec.setSampleFormat(c->sample_fmt);
92
+ dec.setTimeBase(c->time_base);
93
+
94
+
95
+ dec.ctx->request_channels = 2;
96
+ // dec.ctx->request_channel_layout = 2;
97
+ dec.open();
98
+
99
+
100
+
101
+ LOGDEBUG(dec.toString());
102
+
103
+ // Encoder enc(CODEC_ID_VORBIS);
104
+ Encoder enc(CODEC_ID_MP3);
105
+ enc.setChannels(2);
106
+ enc.setBitRate(128000);
107
+ enc.setSampleRate(48000);
108
+ enc.setSampleFormat(dec.getSampleFormat());
109
+ AVRational ar;
110
+ ar.num = 1;
111
+ ar.den = enc.getSampleRate();
112
+ enc.setTimeBase(ar);
113
+ // enc.setFlag(CODEC_FLAG_GLOBAL_HEADER);
114
+ // enc.setPixelFormat(PIX_FMT_YUV420P);
115
+ // enc.ctx->bits_per_raw_sample=dec.ctx
116
+ enc.open();
117
+ LOGDEBUG(enc.toString());
118
+ LOGDEBUG("Encoder Frame Size:" << enc.ctx->frame_size);
119
+
120
+
121
+ pos.setEncoder(enc, 0);
122
+ pos.init();
123
+
124
+ FrameConverter conv(&dec, &enc);
125
+ PacketSink sink;
126
+ enc.setSink(&sink);
127
+ // enc.setOutputStream(&pos);
128
+ Packet p;
129
+ for (int a = 0; a < 1000; ) {
130
+
131
+ pis.readPacket(p);
132
+ if (p.getStreamIndex() == stream_id) {
133
+ a++;
134
+ p.setStreamIndex(0);
135
+ p.toString();
136
+ Frame * tmp = dec.decode2(p);
137
+ tmp->toString();
138
+
139
+ // continue;
140
+ if (!tmp->isFinished()) {
141
+ continue;
142
+ }
143
+ Frame * f = new Frame();
144
+ conv.convert(*tmp, *f);
145
+ f->toString();
146
+ // pos.writePacket(p);
147
+ enc.encode(*f);
148
+ delete tmp;
149
+ delete f;
150
+
151
+ }
152
+ }
153
+ list< boost::shared_ptr<Packet> > encoded = sink.getList();
154
+ list< boost::shared_ptr<Packet> >::iterator it = encoded.begin();
155
+ for (; it != encoded.end(); it++) {
156
+ pos.writePacket(*(*it).get());
157
+ }
158
+ Log::close();
159
+ }
pool/shard011/C++/0121597_resolve_reduce_attributes.cc ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2017 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
+ #include <memory>
16
+ #include <string>
17
+ #include <unordered_map>
18
+ #include <vector>
19
+
20
+ #include "tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.h"
21
+ #include "tensorflow/contrib/lite/toco/model.h"
22
+ #include "tensorflow/contrib/lite/toco/tooling_util.h"
23
+ #include "tensorflow/core/platform/logging.h"
24
+
25
+ namespace toco {
26
+
27
+ template <typename T>
28
+ bool ResolveAttributes(Model* model, T* op) {
29
+ if (!op->axis.empty()) {
30
+ // Attributes already resolved
31
+ return false;
32
+ }
33
+ if (op->inputs.size() != 2) return false;
34
+ if (!IsConstantParameterArray(*model, op->inputs[1])) return false;
35
+
36
+ const Array& indices_array = model->GetArray(op->inputs[1]);
37
+ if (!indices_array.has_shape()) return false;
38
+ op->axis = indices_array.GetBuffer<ArrayDataType::kInt32>().data;
39
+ return true;
40
+ }
41
+
42
+ ::tensorflow::Status ResolveReduceAttributes::Run(Model* model,
43
+ std::size_t op_index,
44
+ bool* modified) {
45
+ *modified = false;
46
+ Operator* op = model->operators[op_index].get();
47
+ switch (op->type) {
48
+ case OperatorType::kMean:
49
+ *modified = ResolveAttributes(model, static_cast<MeanOperator*>(op));
50
+ return ::tensorflow::Status::OK();
51
+ case OperatorType::kSum:
52
+ *modified =
53
+ ResolveAttributes(model, static_cast<TensorFlowSumOperator*>(op));
54
+ return ::tensorflow::Status::OK();
55
+ case OperatorType::kReduceProd:
56
+ *modified =
57
+ ResolveAttributes(model, static_cast<TensorFlowProdOperator*>(op));
58
+ return ::tensorflow::Status::OK();
59
+ case OperatorType::kReduceMin:
60
+ *modified =
61
+ ResolveAttributes(model, static_cast<TensorFlowMinOperator*>(op));
62
+ return ::tensorflow::Status::OK();
63
+ case OperatorType::kReduceMax:
64
+ *modified =
65
+ ResolveAttributes(model, static_cast<TensorFlowMaxOperator*>(op));
66
+ return ::tensorflow::Status::OK();
67
+ case OperatorType::kAny:
68
+ *modified =
69
+ ResolveAttributes(model, static_cast<TensorFlowMaxOperator*>(op));
70
+ return ::tensorflow::Status::OK();
71
+ default:
72
+ return ::tensorflow::Status::OK();
73
+ }
74
+ }
75
+
76
+ } // namespace toco
pool/shard011/C++/0121599_gsl_distribution.cpp ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //#include "stdafx.h"
2
+ #include <gsl/gsl_randist.h>
3
+ #include <gsl/gsl_rng.h>
4
+ #include <gsl/gsl_cdf.h>
5
+ #include <gsl/gsl_linalg.h>
6
+ #include <vector>
7
+ #include <iostream>
8
+ #include <cmath>
9
+
10
+
11
+ namespace {
12
+ namespace local {
13
+
14
+ void unit_gaussian_distribution()
15
+ {
16
+ //
17
+ {
18
+ const int N = 1000;
19
+ std::vector<double> data;
20
+ data.reserve(N);
21
+ for (int i = 0; i < N; ++i)
22
+ data.push_back(gsl_ran_ugaussian_pdf(-3.0 + 6.0 * i / N));
23
+ }
24
+
25
+ //
26
+ {
27
+ const double x = 2.0;
28
+
29
+ const double P = gsl_cdf_ugaussian_P(x);
30
+ std::cout << "prob(x < " << x << ") = " << P << std::endl;
31
+
32
+ const double Q = gsl_cdf_ugaussian_Q(x);
33
+ std::cout << "prob(x < " << x << ") = " << Q << std::endl;
34
+
35
+ const double xp = gsl_cdf_ugaussian_Pinv(P);
36
+ std::cout << "Pinv(" << P << ") = " << xp << std::endl;
37
+
38
+ const double xq = gsl_cdf_ugaussian_Qinv(Q);
39
+ std::cout << "Qinv(" << Q << ") = " << xq << std::endl;
40
+ }
41
+ }
42
+
43
+ void gaussian_distribution()
44
+ {
45
+ //
46
+ {
47
+ const double sigma = 2.0;
48
+
49
+ const int N = 1000;
50
+ std::vector<double> data;
51
+ data.reserve(N);
52
+ for (int i = 0; i < N; ++i)
53
+ data.push_back(gsl_ran_gaussian_pdf(-3.0 + 6.0 * i / N, sigma));
54
+ }
55
+
56
+ //
57
+ {
58
+ const double sigma = 2.0;
59
+ const double x = 2.0;
60
+
61
+ const double P = gsl_cdf_gaussian_P(x, sigma);
62
+ std::cout << "prob(x < " << x << ") = " << P << std::endl;
63
+
64
+ const double Q = gsl_cdf_gaussian_Q(x, sigma);
65
+ std::cout << "prob(x < " << x << ") = " << Q << std::endl;
66
+
67
+ const double xp = gsl_cdf_gaussian_Pinv(P, sigma);
68
+ std::cout << "Pinv(" << P << ") = " << xp << std::endl;
69
+
70
+ const double xq = gsl_cdf_gaussian_Qinv(Q, sigma);
71
+ std::cout << "Qinv(" << Q << ") = " << xq << std::endl;
72
+ }
73
+ }
74
+
75
+ void bivariate_gaussian_distribution()
76
+ {
77
+ {
78
+ const double mu_x = -1.0, mu_y = 2.0, sigma_x = 2.0, sigma_y = std::sqrt(3.0), sigma_xy = -2.25, rho = sigma_xy / (sigma_x * sigma_y);
79
+ const double x = 0.5, y = 1.5;
80
+ std::cout << "p([0.5, 1.5] | [-1.0, 2.0], [4.0, -2.25 ; -2.25, 3.0]) = " << gsl_ran_bivariate_gaussian_pdf(x - mu_x, y - mu_y, sigma_x, sigma_y, rho) << std::endl;
81
+ }
82
+
83
+ {
84
+ const double mu_x = 1.0, mu_y = -1.0, sigma_x = std::sqrt(0.9), sigma_y = std::sqrt(0.3), sigma_xy = 0.4, rho = sigma_xy / (sigma_x * sigma_y);
85
+ const double x = 0.5, y = -0.5;
86
+ std::cout << "p([0.5, -0.5] | [1.0, -1.0], [0.9, 0.4 ; 0.4, 0.3]) = " << gsl_ran_bivariate_gaussian_pdf(x - mu_x, y - mu_y, sigma_x, sigma_y, rho) << std::endl;
87
+ }
88
+ }
89
+
90
+ void multivariate_gaussian_distribution()
91
+ {
92
+ {
93
+ gsl_vector *mu = gsl_vector_alloc(2);
94
+ gsl_matrix *covL = gsl_matrix_alloc(2, 2);
95
+ gsl_vector *x = gsl_vector_alloc(2);
96
+ gsl_vector *work = gsl_vector_alloc(2);
97
+
98
+ gsl_vector_set(mu, 0, -1.0); gsl_vector_set(mu, 1, 2.0);
99
+ gsl_matrix_set(covL, 0, 0, 4.0); gsl_matrix_set(covL, 0, 1, -2.25); gsl_matrix_set(covL, 1, 0, -2.25); gsl_matrix_set(covL, 1, 1, 3.0);
100
+ gsl_vector_set(x, 0, 0.5); gsl_vector_set(x, 1, 1.5);
101
+
102
+ gsl_linalg_cholesky_decomp(covL);
103
+
104
+ double pdf = 0.0;
105
+ gsl_ran_multivariate_gaussian_pdf(x, mu, covL, &pdf, work);
106
+ std::cout << "p([0.5, 1.5] | [-1.0, 2.0], [4.0, -2.25 ; -2.25, 3.0]) = " << pdf << std::endl;
107
+
108
+ gsl_vector_free(mu);
109
+ gsl_matrix_free(covL);
110
+ gsl_vector_free(x);
111
+ gsl_vector_free(work);
112
+ }
113
+
114
+ {
115
+ gsl_vector *mu = gsl_vector_alloc(2);
116
+ gsl_matrix *covL = gsl_matrix_alloc(2, 2);
117
+ gsl_vector *x = gsl_vector_alloc(2);
118
+ gsl_vector *work = gsl_vector_alloc(2);
119
+
120
+ gsl_vector_set(mu, 0, 1.0); gsl_vector_set(mu, 1, -1.0);
121
+ gsl_matrix_set(covL, 0, 0, 0.9); gsl_matrix_set(covL, 0, 1, 0.4); gsl_matrix_set(covL, 1, 0, 0.4); gsl_matrix_set(covL, 1, 1, 0.3);
122
+ gsl_vector_set(x, 0, 0.5); gsl_vector_set(x, 1, -0.5);
123
+
124
+ gsl_linalg_cholesky_decomp(covL);
125
+
126
+ double pdf = 0.0;
127
+ gsl_ran_multivariate_gaussian_pdf(x, mu, covL, &pdf, work);
128
+ std::cout << "p([0.5, -0.5] | [1.0, -1.0], [0.9, 0.4 ; 0.4, 0.3]) = " << pdf << std::endl;
129
+
130
+ gsl_vector_free(mu);
131
+ gsl_matrix_free(covL);
132
+ gsl_vector_free(x);
133
+ gsl_vector_free(work);
134
+ }
135
+ }
136
+
137
+ } // namespace local
138
+ } // unnamed namespace
139
+
140
+ namespace my_gsl {
141
+
142
+ void distribution()
143
+ {
144
+ local::unit_gaussian_distribution();
145
+ local::gaussian_distribution();
146
+ local::bivariate_gaussian_distribution();
147
+ local::multivariate_gaussian_distribution();
148
+ }
149
+
150
+ } // namespace my_gsl
pool/shard011/C++/0121600_timeslice_timeout.cpp ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ INTERFACE:
3
+
4
+ #include "timeout.h"
5
+
6
+ class Timeslice_timeout : public Timeout
7
+ {
8
+ };
9
+
10
+ IMPLEMENTATION:
11
+
12
+ #include <cassert>
13
+ #include "globals.h"
14
+ #include "sched_context.h"
15
+ #include "std_macros.h"
16
+
17
+ /* Initialize global valiable timeslice_timeout */
18
+ DEFINE_PER_CPU Per_cpu<Timeout *> timeslice_timeout;
19
+ DEFINE_PER_CPU static Per_cpu<Timeslice_timeout> the_timeslice_timeout(Per_cpu_data::Cpu_num);
20
+
21
+ PUBLIC
22
+ Timeslice_timeout::Timeslice_timeout(Cpu_number cpu)
23
+ {
24
+ timeslice_timeout.cpu(cpu) = this;
25
+ }
26
+
27
+
28
+ /**
29
+ * Timeout expiration callback function
30
+ * @return true to force a reschedule
31
+ */
32
+ PRIVATE
33
+ bool
34
+ Timeslice_timeout::expired()
35
+ {
36
+ Sched_context::Ready_queue &rq = Sched_context::rq.current();
37
+ Sched_context *sched = rq.current_sched();
38
+
39
+ if (sched)
40
+ {
41
+ #if 0
42
+ Context *owner = sched->owner();
43
+
44
+ // Ensure sched is owner's current timeslice
45
+ assert (owner->sched() == sched);
46
+ #endif
47
+ sched->replenish();
48
+ rq.requeue(sched);
49
+ rq.invalidate_sched();
50
+
51
+ // owner->switch_sched(sched);
52
+ }
53
+
54
+ return true; // Force reschedule
55
+ }
pool/shard011/C++/0121602_BLECharacteristic.cpp ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include "Arduino.h"
2
+
3
+ #include "BLEDeviceLimits.h"
4
+
5
+ #include "BLECharacteristic.h"
6
+
7
+ BLECharacteristic::BLECharacteristic(const char* uuid, unsigned char properties, unsigned char valueSize) :
8
+ BLELocalAttribute(uuid, BLETypeCharacteristic),
9
+ _properties(properties),
10
+ _valueSize(min(valueSize, BLE_ATTRIBUTE_MAX_VALUE_LENGTH)),
11
+ _value(NULL),
12
+ _valueLength(0),
13
+ _written(false),
14
+ _subscribed(false),
15
+ _listener(NULL)
16
+ {
17
+ memset(this->_eventHandlers, 0x00, sizeof(this->_eventHandlers));
18
+
19
+ if (valueSize) {
20
+ this->_value = (unsigned char*)malloc(this->_valueSize);
21
+ }
22
+ }
23
+
24
+ BLECharacteristic::BLECharacteristic(const char* uuid, unsigned char properties, const char* value) :
25
+ BLELocalAttribute(uuid, BLETypeCharacteristic),
26
+ _properties(properties),
27
+ _valueSize(min(strlen(value), BLE_ATTRIBUTE_MAX_VALUE_LENGTH)),
28
+ _value(NULL),
29
+ _valueLength(0),
30
+ _written(false),
31
+ _subscribed(false),
32
+ _listener(NULL)
33
+ {
34
+ memset(this->_eventHandlers, 0x00, sizeof(this->_eventHandlers));
35
+
36
+ this->_value = (unsigned char*)malloc(this->_valueSize);
37
+ this->setValue(value);
38
+ }
39
+
40
+ BLECharacteristic::~BLECharacteristic() {
41
+ if (this->_value) {
42
+ free(this->_value);
43
+ }
44
+ }
45
+
46
+ unsigned char BLECharacteristic::properties() const {
47
+ return this->_properties;
48
+ }
49
+
50
+ unsigned char BLECharacteristic::valueSize() const {
51
+ return this->_valueSize;
52
+ }
53
+
54
+ unsigned const char* BLECharacteristic::value() const {
55
+ return this->_value;
56
+ }
57
+
58
+ unsigned char BLECharacteristic::valueLength() const {
59
+ return this->_valueLength;
60
+ }
61
+
62
+ bool BLECharacteristic::fixedLength() const {
63
+ return false;
64
+ }
65
+
66
+ unsigned char BLECharacteristic::operator[] (int offset) const {
67
+ return this->_value[offset];
68
+ }
69
+
70
+ bool BLECharacteristic::setValue(const unsigned char value[], unsigned char length) {
71
+ bool success = true;
72
+
73
+ this->_valueLength = min(length, this->_valueSize);
74
+
75
+ memcpy(this->_value, value, this->_valueLength);
76
+
77
+ if (this->_listener) {
78
+ success = this->_listener->characteristicValueChanged(*this);
79
+ }
80
+
81
+ return success;
82
+ }
83
+
84
+ bool BLECharacteristic::setValue(const char* value) {
85
+ return this->setValue((const unsigned char *)value, strlen(value));
86
+ }
87
+
88
+ bool BLECharacteristic::broadcast() {
89
+ bool success = false;
90
+
91
+ if (this->_listener) {
92
+ success = this-_listener->broadcastCharacteristic(*this);
93
+ }
94
+
95
+ return success;
96
+ }
97
+
98
+ bool BLECharacteristic::written() {
99
+ bool written = this->_written;
100
+
101
+ this->_written = false;
102
+
103
+ return written;
104
+ }
105
+
106
+ void BLECharacteristic::setValue(BLECentral& central, const unsigned char value[], unsigned char length) {
107
+ this->setValue(value, length);
108
+
109
+ this->_written = true;
110
+
111
+ BLECharacteristicEventHandler eventHandler = this->_eventHandlers[BLEWritten];
112
+ if (eventHandler) {
113
+ eventHandler(central, *this);
114
+ }
115
+ }
116
+
117
+ bool BLECharacteristic::subscribed() {
118
+ return this->_subscribed;
119
+ }
120
+
121
+ void BLECharacteristic::setSubscribed(BLECentral& central, bool subscribed) {
122
+ this->_subscribed = subscribed;
123
+
124
+ BLECharacteristicEventHandler eventHandler = this->_eventHandlers[subscribed ? BLESubscribed : BLEUnsubscribed];
125
+
126
+ if (eventHandler) {
127
+ eventHandler(central, *this);
128
+ }
129
+ }
130
+
131
+ bool BLECharacteristic::canNotify() {
132
+ return (this->_listener) ? this->_listener->canNotifyCharacteristic(*this) : false;
133
+ }
134
+
135
+ bool BLECharacteristic::canIndicate() {
136
+ return (this->_listener) ? this->_listener->canIndicateCharacteristic(*this) : false;
137
+ }
138
+
139
+ void BLECharacteristic::setEventHandler(BLECharacteristicEvent event, BLECharacteristicEventHandler eventHandler) {
140
+ if (event < sizeof(this->_eventHandlers)) {
141
+ this->_eventHandlers[event] = eventHandler;
142
+ }
143
+ }
144
+
145
+ void BLECharacteristic::setValueChangeListener(BLECharacteristicValueChangeListener& listener) {
146
+ this->_listener = &listener;
147
+ }
pool/shard011/C++/0121603_ana2morfsar.cc ADDED
@@ -0,0 +1,241 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //////////////////////////////////////////////////////////////////
2
+ //
3
+ // EUSTAGGER LITE
4
+ //
5
+ // Copyright (C) 1996-2013 IXA Taldea
6
+ // EHU-UPV
7
+ //
8
+ // This file is part of EUSTAGGER LITE.
9
+ //
10
+ // EUSTAGGER LITE is free software: you can redistribute it and/or modify
11
+ // it under the terms of the GNU General Public License as published by
12
+ // the Free Software Foundation, either version 3 of the License, or
13
+ // (at your option) any later version.
14
+ //
15
+ // EUSTAGGER LITE is distributed in the hope that it will be useful,
16
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ // GNU General Public License for more details.
19
+ //
20
+ // You should have received a copy of the GNU General Public License
21
+ // along with Foobar. If not, see <http://www.gnu.org/licenses/>.
22
+ //
23
+ // Contact: Ixa Taldea (ixa@ehu.es)
24
+ // 649 Posta kutxa
25
+ // 20080 Donostia (Basque Country)
26
+ //
27
+ //////////////////////////////////////////////////////////////////
28
+
29
+
30
+ /* ***************************************************
31
+ * **************************************************** */
32
+ #include <stdlib.h>
33
+ #include <string.h>
34
+ #include <sstream>
35
+ #include <iostream>
36
+ #include <fstream>
37
+ #include "ana2morfsar.h"
38
+ #include "morfsarFormatu.h"
39
+
40
+
41
+ Ana2Morfsar* yyparseAna2Morfsar;
42
+
43
+ using namespace std;
44
+ /* ******************************************************************* */
45
+ /* ***** METODO PRIBATUAK ******************************************** */
46
+ /* ******************************************************************* */
47
+
48
+ /* ******************************************************************* */
49
+
50
+ void Ana2Morfsar::toMorfsar(){
51
+ extern int ana2morfsarparse(); // LEX-YACC modulua
52
+ extern FILE* ana2morfsarin; // LEX-YACC moduluaren sarrerako FILE*;
53
+ if (fpFitxAna == NULL) {
54
+ cerr << "Errorea Ana2Morfsar::toMorfsar()" << endl;
55
+ exit( EXIT_FAILURE );
56
+ }
57
+ ana2morfsarin=fpFitxAna;
58
+ yyparseAna2Morfsar = this;
59
+ ana2morfsarparse();
60
+ fclose( fpFitxAna );
61
+ }
62
+
63
+ void Ana2Morfsar::toMorfsar(const std::string segString){
64
+ extern void bufferParse(char *buffer, int size);
65
+ char *buffer;
66
+ //ofstream out ("tmp.segp");
67
+ //if (!out) {
68
+ // cerr << "Ezin daiteke tmp.segp fitxategia sortu" << endl;
69
+ //}
70
+ //out << segString << endl;
71
+ if (fpFitxAna != NULL) {
72
+ fpFitxAna = NULL;
73
+ }
74
+ buffer = (char *) malloc(segString.length()+2); /* bukeran \0\0 egotea eskatzen du */
75
+ buffer[0] = '\0';
76
+ strcpy(buffer,segString.c_str());
77
+ buffer[segString.length()+1] = '\0'; // bukaeran \0\0 behar du
78
+ yyparseAna2Morfsar = this;
79
+ bufferParse(buffer,segString.length()+2);
80
+
81
+ }
82
+
83
+
84
+ void Ana2Morfsar::read_data_version() {
85
+ this->dataversion = "4.4.9";
86
+ }
87
+
88
+ /* ******************************************************************* */
89
+ /* ***** METODO PUBLIKOAK ******************************************* */
90
+ /* ******************************************************************* */
91
+
92
+ Ana2Morfsar::Ana2Morfsar(){
93
+ this->tamaina=1;
94
+ this->read_data_version();
95
+ srand(time(0));
96
+ }
97
+ /* ******************************************************************* */
98
+
99
+ Ana2Morfsar::Ana2Morfsar(const string &segp, int tam) {
100
+ this->tamaina=tam;
101
+ this->read_data_version();
102
+ srand(time(0));
103
+ this->setAnaFitx(segp);
104
+ }
105
+
106
+ /* ******************************************************************* */
107
+
108
+ Ana2Morfsar::~Ana2Morfsar(){}
109
+
110
+ /* ******************************************************************* */
111
+
112
+ void Ana2Morfsar::setMorfsarFitx(const string & morfsar) {
113
+ ifstream in (morfsar.c_str());
114
+ if (!in) {
115
+ cerr << "ERROREA" << endl;
116
+ cerr << "\t ana2morfsar::setMorfsarFitx() => Ezin kargatu " << morfsar << " fitxategia." << endl << endl;
117
+ exit(0);
118
+ }
119
+ string sar;
120
+ while(!in.eof()) {
121
+ string line;
122
+ getline(in, line);
123
+
124
+ sar += line + "\n";
125
+ if (line.find("]).") != string::npos) { // lehen != -1
126
+ morfsarForm.addMorfsarSar(sar);
127
+ sar = "";
128
+ }
129
+ }
130
+ in.close();
131
+ }
132
+
133
+ /* ******************************************************************* */
134
+
135
+ void Ana2Morfsar::setAnaFitx(const string &segp) {
136
+ if ( !( this->fpFitxAna = fopen(segp.c_str() , "r" )) ){
137
+ cerr << "Errorea Ana2Morfsar::setAnaFitx --> fopen(" << segp <<")"<<endl;
138
+ exit( EXIT_FAILURE );
139
+ }
140
+ this->toMorfsar();
141
+ }
142
+
143
+ void Ana2Morfsar::setAnaString(const string &segIrteera) {
144
+ this->toMorfsar(segIrteera);
145
+ }
146
+
147
+ /* ******************************************************************* */
148
+
149
+ void Ana2Morfsar::setAnaTam(int tamaina) { this->tamaina = tamaina; }
150
+
151
+
152
+ /* ******************************************************************* */
153
+
154
+ int Ana2Morfsar::getAnaTam() {return this->tamaina; }
155
+
156
+ /* ******************************************************************* */
157
+
158
+ void Ana2Morfsar::add2Gorputza(string type, string value, bool symBal) {
159
+ this->morfsarForm.add2Gorputza(type, value, symBal);
160
+ }
161
+
162
+ /* ******************************************************************* */
163
+
164
+ void Ana2Morfsar::setForma(string forma,const std::string bereiz) {
165
+ this->morfsarForm.setForma(forma,bereiz);
166
+ }
167
+
168
+ /* ******************************************************************* */
169
+
170
+ void Ana2Morfsar::morfemaBerria() {
171
+ this->morfsarForm.morfemaBerria();
172
+ }
173
+
174
+
175
+ /* ******************************************************************* */
176
+
177
+ void Ana2Morfsar::analisiaBukatu() {
178
+ this->morfsarForm.analisiaBukatu();
179
+ }
180
+
181
+
182
+ /* ******************************************************************* */
183
+
184
+ void Ana2Morfsar::begin() { this->morfsarForm.begin(tamaina);}
185
+
186
+ /* ******************************************************************* */
187
+
188
+ bool Ana2Morfsar::ready() { return !this->morfsarForm.end(); }
189
+
190
+ /* ******************************************************************* */
191
+
192
+ void Ana2Morfsar::next() { this->morfsarForm.next(); }
193
+
194
+ /* ******************************************************************* */
195
+
196
+ string Ana2Morfsar::current() {
197
+ string morfsarFitx;
198
+ bool fExist=false;
199
+ do{
200
+ ostringstream tmpFitx;
201
+ tmpFitx << TMP_PATH << rand() << ".tmp.morfsar";
202
+ morfsarFitx=tmpFitx.str();
203
+
204
+ ifstream fIn;
205
+ fIn.open(morfsarFitx.c_str());
206
+ fExist=fIn.is_open();
207
+ fIn.close();
208
+ } while (fExist);
209
+ return this->morfsarForm.current(morfsarFitx);
210
+ }
211
+
212
+ /* ******************************************************************* */
213
+
214
+ string Ana2Morfsar::current(string & tmpFitx) {
215
+ return this->morfsarForm.current(tmpFitx);
216
+ }
217
+
218
+ /* ******************************************************************* */
219
+
220
+ vector<string> Ana2Morfsar::execute(string & amaraunIzen) {
221
+ vector<string> morfsarV;
222
+ int kont=0;
223
+ for (this->begin(); this->ready(); this->next()) {
224
+ kont++;
225
+ string morfsarFitx;
226
+ if (tamaina>0) {
227
+ ostringstream kontOSS;
228
+ kontOSS.fill('0');
229
+ kontOSS.width(6);
230
+ kontOSS << kont;
231
+ morfsarFitx = amaraunIzen + "." + kontOSS.str() + ".morfsar";
232
+ }
233
+ else morfsarFitx= amaraunIzen + ".morfsar";
234
+
235
+ this->current(morfsarFitx);
236
+ morfsarV.push_back(morfsarFitx);
237
+ }
238
+ return morfsarV;
239
+ }
240
+
241
+ /* ******************************************************************* */
pool/shard011/C++/0121605_CaiGpsNav.cpp ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ Copyright_License {
3
+
4
+ XCSoar Glide Computer - http://www.xcsoar.org/
5
+ Copyright (C) 2000-2015 The XCSoar Project
6
+ A detailed list of copyright holders can be found in the file "AUTHORS".
7
+
8
+ This program is free software; you can redistribute it and/or
9
+ modify it under the terms of the GNU General Public License
10
+ as published by the Free Software Foundation; either version 2
11
+ of the License, or (at your option) any later version.
12
+
13
+ This program 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
16
+ GNU General Public License for more details.
17
+
18
+ You should have received a copy of the GNU General Public License
19
+ along with this program; if not, write to the Free Software
20
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
+ }
22
+ */
23
+
24
+ //
25
+
26
+
27
+ // CAUTION!
28
+ // caiGpsNavParseNMEA is called from com port read thread
29
+ // all other functions are called from windows message loop thread
30
+
31
+ #include "Device/Driver/CaiGpsNav.hpp"
32
+ #include "Device/Driver.hpp"
33
+ #include "Device/Port/Port.hpp"
34
+ #include "Operation/Operation.hpp"
35
+
36
+ #include <tchar.h>
37
+
38
+ static constexpr char CtrlC = '\x03';
39
+
40
+ class CaiGpsNavDevice : public AbstractDevice {
41
+ private:
42
+ Port &port;
43
+
44
+ public:
45
+ CaiGpsNavDevice(Port &_port):port(_port) {}
46
+
47
+ public:
48
+ virtual bool EnableNMEA(OperationEnvironment &env) override;
49
+ };
50
+
51
+ bool
52
+ CaiGpsNavDevice::EnableNMEA(OperationEnvironment &env)
53
+ {
54
+ port.Write(CtrlC);
55
+ env.Sleep(200);
56
+ port.Write("NMEA\r");
57
+
58
+ // This is for a slightly different mode, that
59
+ // apparently outputs pressure info too...
60
+ //port.Write("PNP\r\n");
61
+ //port.Write("LOG 0\r\n");
62
+
63
+ return true;
64
+ }
65
+
66
+ static Device *
67
+ CaiGpsNavCreateOnPort(const DeviceConfig &config, Port &com_port)
68
+ {
69
+ return new CaiGpsNavDevice(com_port);
70
+ }
71
+
72
+ const struct DeviceRegister gps_nav_driver = {
73
+ _T("CAI GPS-NAV"),
74
+ _T("Cambridge CAI GPS-NAV"),
75
+ 0,
76
+ CaiGpsNavCreateOnPort,
77
+ };
pool/shard011/C++/0121606_PixelShader.cpp ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /// @file
2
+ /// @author Boris Mikic
3
+ /// @version 3.3
4
+ ///
5
+ /// @section LICENSE
6
+ ///
7
+ /// This program is free software; you can redistribute it and/or modify it under
8
+ /// the terms of the BSD license: http://www.opensource.org/licenses/bsd-license.php
9
+
10
+ #include <hltypes/hresource.h>
11
+ #include <hltypes/hstring.h>
12
+
13
+ #include "PixelShader.h"
14
+
15
+ namespace april
16
+ {
17
+ PixelShader::PixelShader()
18
+ {
19
+ }
20
+
21
+ PixelShader::~PixelShader()
22
+ {
23
+ }
24
+
25
+ bool PixelShader::_loadData(chstr filename, unsigned char** data, long* size)
26
+ {
27
+ if (!hresource::exists(filename))
28
+ {
29
+ return false;
30
+ }
31
+ hresource stream(filename);
32
+ *size = stream.size();
33
+ *data = new unsigned char[*size];
34
+ stream.read_raw(*data, *size);
35
+ return true;
36
+ }
37
+
38
+ }
pool/shard011/C++/0121610_ClientRequestFactory.cpp ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include "include/global.h"
2
+
3
+
4
+ #include "alinous.runtime.engine.debugger/AlinousServerDebugHttpResponse.h"
5
+ #include "alinous.runtime.engine.debugger.client/IClientRequest.h"
6
+ #include "alinous.runtime.engine.debugger/IHttpAccessMethod.h"
7
+ #include "alinous.runtime.engine.debugger/AlinousDebugCommandSender.h"
8
+ #include "alinous.runtime.engine.debugger.client/TerminateServerRequest.h"
9
+ #include "alinous.runtime.engine.debugger.client/StatusThreadRequest.h"
10
+ #include "alinous.runtime.engine.debugger.client/ClearBreakpointsRequest.h"
11
+ #include "alinous.runtime.engine.debugger.client/AddBreakpointsRequest.h"
12
+ #include "alinous.runtime.engine.debugger.client/SetupAllBreakPointsRequest.h"
13
+ #include "alinous.runtime.engine.debugger.client/ResumeRequest.h"
14
+ #include "alinous.runtime.engine.debugger.client/StepOverRequest.h"
15
+ #include "alinous.runtime.engine.debugger.client/StepInRequest.h"
16
+ #include "alinous.runtime.engine.debugger.client/StepReturnRequest.h"
17
+ #include "alinous.runtime.engine.debugger.client/ClientRequestFactory.h"
18
+
19
+ namespace alinous {namespace runtime {namespace engine {namespace debugger {namespace client {
20
+
21
+
22
+
23
+
24
+
25
+ bool ClientRequestFactory::__init_done = __init_static_variables();
26
+ bool ClientRequestFactory::__init_static_variables(){
27
+ Java2CppSystem::getSelf();
28
+ ThreadContext* ctx = ThreadContext::newThreadContext();
29
+ {
30
+ GCNotifier __refobj1(ctx, __FILEW__, __LINE__, L"ClientRequestFactory", L"__init_static_variables");
31
+ }
32
+ ctx->localGC();
33
+ delete ctx;
34
+ return true;
35
+ }
36
+ ClientRequestFactory::ClientRequestFactory(ThreadContext* ctx) throw() : IObject(ctx)
37
+ {
38
+ }
39
+ void ClientRequestFactory::__construct_impl(ThreadContext* ctx) throw()
40
+ {
41
+ }
42
+ ClientRequestFactory::~ClientRequestFactory() throw()
43
+ {
44
+ ThreadContext *ctx = ThreadContext::getCurentContext();
45
+ if(ctx != nullptr){ctx->incGcDenial();}
46
+ __releaseRegerences(false, ctx);
47
+ if(ctx != nullptr){ctx->decGcDenial();}
48
+ }
49
+ void ClientRequestFactory::__releaseRegerences(bool prepare, ThreadContext* ctx) throw()
50
+ {
51
+ if(!prepare){
52
+ return;
53
+ }
54
+ }
55
+ IClientRequest* ClientRequestFactory::createRequest(Map<String,String>* params, ThreadContext* ctx) throw()
56
+ {
57
+ String* command = params->get(AlinousDebugCommandSender::COMMAND, ctx);
58
+ IClientRequest* retRequest = nullptr;
59
+ if(command == nullptr)
60
+ {
61
+ return nullptr;
62
+ }
63
+ else
64
+ {
65
+ if(command->equals(IClientRequest::CMD_TERMINATE, ctx))
66
+ {
67
+ retRequest = (new(ctx) TerminateServerRequest(ctx));
68
+ }
69
+ else
70
+ {
71
+ if(command->equals(IClientRequest::CMD_STATUS_THREAD, ctx))
72
+ {
73
+ retRequest = (new(ctx) StatusThreadRequest(ctx));
74
+ }
75
+ else
76
+ {
77
+ if(command->equals(IClientRequest::CMD_CLEAR_BREAKPOINTS, ctx))
78
+ {
79
+ retRequest = (new(ctx) ClearBreakpointsRequest(ctx));
80
+ }
81
+ else
82
+ {
83
+ if(command->equals(IClientRequest::CMD_ADD_BREAKPOINTS, ctx))
84
+ {
85
+ retRequest = (new(ctx) AddBreakpointsRequest(ctx));
86
+ }
87
+ else
88
+ {
89
+ if(command->equals(IClientRequest::CMD_SETUP_ALL_BREAKPOINTS, ctx))
90
+ {
91
+ retRequest = (new(ctx) SetupAllBreakPointsRequest(ctx));
92
+ }
93
+ else
94
+ {
95
+ if(command->equals(IClientRequest::CMD_RESUME, ctx))
96
+ {
97
+ retRequest = (new(ctx) ResumeRequest(0, ctx));
98
+ }
99
+ else
100
+ {
101
+ if(command->equals(IClientRequest::CMD_STEP_OVER, ctx))
102
+ {
103
+ retRequest = (new(ctx) StepOverRequest(ctx));
104
+ }
105
+ else
106
+ {
107
+ if(command->equals(IClientRequest::CMD_STEP_IN, ctx))
108
+ {
109
+ retRequest = (new(ctx) StepInRequest(ctx));
110
+ }
111
+ else
112
+ {
113
+ if(command->equals(IClientRequest::CMD_STEP_RETURN, ctx))
114
+ {
115
+ retRequest = (new(ctx) StepReturnRequest(ctx));
116
+ }
117
+ }
118
+ }
119
+ }
120
+ }
121
+ }
122
+ }
123
+ }
124
+ }
125
+ }
126
+ if(retRequest != nullptr)
127
+ {
128
+ retRequest->importParams(params, ctx);
129
+ }
130
+ return retRequest;
131
+ }
132
+ IClientRequest* ClientRequestFactory::createDefault(ThreadContext* ctx) throw()
133
+ {
134
+ return (new(ctx) StatusThreadRequest(ctx));
135
+ }
136
+ void ClientRequestFactory::__cleanUp(ThreadContext* ctx){
137
+ }
138
+ }}}}}
139
+
pool/shard011/C++/0121611_drawing-group.cpp ADDED
@@ -0,0 +1,167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file
3
+ * Group belonging to an SVG drawing element.
4
+ *//*
5
+ * Authors:
6
+ * Krzysztof Kosiński <tweenk.pl@gmail.com>
7
+ *
8
+ * Copyright (C) 2011 Authors
9
+ * Released under GNU GPL, read the file 'COPYING' for more information
10
+ */
11
+
12
+ #include "display/cairo-utils.h"
13
+ #include "display/drawing.h"
14
+ #include "display/drawing-context.h"
15
+ #include "display/drawing-item.h"
16
+ #include "display/drawing-group.h"
17
+ #include "style.h"
18
+
19
+ namespace Inkscape {
20
+
21
+ DrawingGroup::DrawingGroup(Drawing &drawing)
22
+ : DrawingItem(drawing)
23
+ , _style(NULL)
24
+ , _child_transform(NULL)
25
+ {}
26
+
27
+ DrawingGroup::~DrawingGroup()
28
+ {
29
+ if (_style)
30
+ sp_style_unref(_style);
31
+ delete _child_transform; // delete NULL; is safe
32
+ }
33
+
34
+ /**
35
+ * Set whether the group returns children from pick calls.
36
+ * Previously this feature was called "transparent groups".
37
+ */
38
+ void
39
+ DrawingGroup::setPickChildren(bool p)
40
+ {
41
+ _pick_children = p;
42
+ }
43
+
44
+ void
45
+ DrawingGroup::setStyle(SPStyle *style)
46
+ {
47
+ _setStyleCommon(_style, style);
48
+ }
49
+
50
+ /**
51
+ * Set additional transform for the group.
52
+ * This is applied after the normal transform and mainly useful for
53
+ * markers, clipping paths, etc.
54
+ */
55
+ void
56
+ DrawingGroup::setChildTransform(Geom::Affine const &new_trans)
57
+ {
58
+ Geom::Affine current;
59
+ if (_child_transform) {
60
+ current = *_child_transform;
61
+ }
62
+
63
+ if (!Geom::are_near(current, new_trans, 1e-18)) {
64
+ // mark the area where the object was for redraw.
65
+ _markForRendering();
66
+ if (new_trans.isIdentity()) {
67
+ delete _child_transform; // delete NULL; is safe
68
+ _child_transform = NULL;
69
+ } else {
70
+ _child_transform = new Geom::Affine(new_trans);
71
+ }
72
+ _markForUpdate(STATE_ALL, true);
73
+ }
74
+ }
75
+
76
+ unsigned
77
+ DrawingGroup::_updateItem(Geom::IntRect const &area, UpdateContext const &ctx, unsigned flags, unsigned reset)
78
+ {
79
+ unsigned beststate = STATE_ALL;
80
+ bool outline = _drawing.outline();
81
+
82
+ UpdateContext child_ctx(ctx);
83
+ if (_child_transform) {
84
+ child_ctx.ctm = *_child_transform * ctx.ctm;
85
+ }
86
+ for (ChildrenList::iterator i = _children.begin(); i != _children.end(); ++i) {
87
+ i->update(area, child_ctx, flags, reset);
88
+ }
89
+ if (beststate & STATE_BBOX) {
90
+ _bbox = Geom::OptIntRect();
91
+ for (ChildrenList::iterator i = _children.begin(); i != _children.end(); ++i) {
92
+ if (i->visible()) {
93
+ _bbox.unionWith(outline ? i->geometricBounds() : i->visualBounds());
94
+ }
95
+ }
96
+ }
97
+ return beststate;
98
+ }
99
+
100
+ unsigned
101
+ DrawingGroup::_renderItem(DrawingContext &dc, Geom::IntRect const &area, unsigned flags, DrawingItem *stop_at)
102
+ {
103
+ if (stop_at == NULL) {
104
+ // normal rendering
105
+ for (ChildrenList::iterator i = _children.begin(); i != _children.end(); ++i) {
106
+ i->render(dc, area, flags, stop_at);
107
+ }
108
+ } else {
109
+ // background rendering
110
+ for (ChildrenList::iterator i = _children.begin(); i != _children.end(); ++i) {
111
+ if (&*i == stop_at) return RENDER_OK; // do not render the stop_at item at all
112
+ if (i->isAncestorOf(stop_at)) {
113
+ // render its ancestors without masks, opacity or filters
114
+ i->render(dc, area, flags | RENDER_FILTER_BACKGROUND, stop_at);
115
+ // stop further rendering
116
+ return RENDER_OK;
117
+ } else {
118
+ i->render(dc, area, flags, stop_at);
119
+ }
120
+ }
121
+ }
122
+ return RENDER_OK;
123
+ }
124
+
125
+ void
126
+ DrawingGroup::_clipItem(DrawingContext &dc, Geom::IntRect const &area)
127
+ {
128
+ for (ChildrenList::iterator i = _children.begin(); i != _children.end(); ++i) {
129
+ i->clip(dc, area);
130
+ }
131
+ }
132
+
133
+ DrawingItem *
134
+ DrawingGroup::_pickItem(Geom::Point const &p, double delta, unsigned flags)
135
+ {
136
+ for (ChildrenList::iterator i = _children.begin(); i != _children.end(); ++i) {
137
+ DrawingItem *picked = i->pick(p, delta, flags);
138
+ if (picked) {
139
+ return _pick_children ? picked : this;
140
+ }
141
+ }
142
+ return NULL;
143
+ }
144
+
145
+ bool
146
+ DrawingGroup::_canClip()
147
+ {
148
+ return true;
149
+ }
150
+
151
+ bool is_drawing_group(DrawingItem *item)
152
+ {
153
+ return dynamic_cast<DrawingGroup *>(item) != NULL;
154
+ }
155
+
156
+ } // end namespace Inkscape
157
+
158
+ /*
159
+ Local Variables:
160
+ mode:c++
161
+ c-file-style:"stroustrup"
162
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
163
+ indent-tabs-mode:nil
164
+ fill-column:99
165
+ End:
166
+ */
167
+ // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
pool/shard011/C++/0121614_rangeSensor.cpp ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2014 - 2015 CyberTech Labs Ltd.
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
+ #include "rangeSensor.h"
16
+
17
+ #include <QtCore/QThread>
18
+
19
+ #include <trikKernel/configurer.h>
20
+ #include <trikKernel/timeVal.h>
21
+ #include <QEventLoop>
22
+ #include <QsLog.h>
23
+
24
+ #include "configurerHelper.h"
25
+ #include "rangeSensorWorker.h"
26
+ #include "moduleLoader.h"
27
+
28
+ using namespace trikControl;
29
+
30
+ RangeSensor::RangeSensor(const QString &port, const trikKernel::Configurer &configurer, ModuleLoader &moduleLoader
31
+ , const trikHal::HardwareAbstractionInterface &hardwareAbstraction)
32
+ : mState("Range Sensor on " + port)
33
+ {
34
+ if (!moduleLoader.load(configurer.attributeByPort(port, "module"))
35
+ || !moduleLoader.load(configurer.attributeByDevice("rangeSensor", "commonModule")))
36
+ {
37
+ QLOG_ERROR() << "Module loading failed";
38
+ mState.fail();
39
+ return;
40
+ }
41
+
42
+ mMinValue = ConfigurerHelper::configureInt(configurer, mState, port, "minValue");
43
+ mMaxValue = ConfigurerHelper::configureInt(configurer, mState, port, "maxValue");
44
+
45
+ mSensorWorker.reset(new RangeSensorWorker(configurer.attributeByPort(port, "eventFile"), mState
46
+ , hardwareAbstraction, mMinValue, mMaxValue, configurer.attributeByPort(port, "filter")));
47
+
48
+ if (!mState.isFailed()) {
49
+ mSensorWorker->moveToThread(&mWorkerThread);
50
+
51
+ connect(mSensorWorker.data(), &RangeSensorWorker::newData, this, &RangeSensor::newData);
52
+
53
+ QLOG_INFO() << "Starting RangeSensor worker thread" << &mWorkerThread;
54
+ QEventLoop l;
55
+ connect(&mWorkerThread, &QThread::started, &l, &QEventLoop::quit);
56
+
57
+ mWorkerThread.setObjectName(mSensorWorker->metaObject()->className());
58
+ mWorkerThread.start();
59
+
60
+ l.exec();
61
+ }
62
+ }
63
+
64
+ RangeSensor::~RangeSensor()
65
+ {
66
+ if (mWorkerThread.isRunning()) {
67
+ mWorkerThread.quit();
68
+ mWorkerThread.wait();
69
+ }
70
+ }
71
+
72
+ RangeSensor::Status RangeSensor::status() const
73
+ {
74
+ return mState.status();
75
+ }
76
+
77
+ void RangeSensor::init()
78
+ {
79
+ if (mState.isFailed()) {
80
+ mState.resetFailure();
81
+ }
82
+
83
+ QMetaObject::invokeMethod(mSensorWorker.data(), &RangeSensorWorker::init);
84
+ }
85
+
86
+ int RangeSensor::read()
87
+ {
88
+ if (!mState.isFailed()) {
89
+ // Read is called synchronously and only takes prepared value from sensor.
90
+ return mSensorWorker->read();
91
+ } else {
92
+ return -1;
93
+ }
94
+ }
95
+
96
+ int RangeSensor::readRawData()
97
+ {
98
+ if (!mState.isFailed()) {
99
+ // Read is called synchronously and only takes prepared value from sensor.
100
+ return mSensorWorker->readRawData();
101
+ } else {
102
+ return -1;
103
+ }
104
+ }
105
+
106
+ void RangeSensor::stop()
107
+ {
108
+ if (!mState.isFailed()) {
109
+ QMetaObject::invokeMethod(mSensorWorker.data(), &RangeSensorWorker::stop);
110
+ }
111
+ }
112
+
113
+ int RangeSensor::minValue() const
114
+ {
115
+ return mMinValue;
116
+ }
117
+
118
+ int RangeSensor::maxValue() const
119
+ {
120
+ return mMaxValue;
121
+ }
pool/shard011/C++/0121615_xfa_layout_appadapter.cpp ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2014 PDFium 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
+ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
+
7
+ #include "xfa/src/foxitlib.h"
8
+ #include "xfa/src/fxfa/src/common/xfa_utils.h"
9
+ #include "xfa/src/fxfa/src/common/xfa_object.h"
10
+ #include "xfa/src/fxfa/src/common/xfa_document.h"
11
+ #include "xfa/src/fxfa/src/common/xfa_parser.h"
12
+ #include "xfa/src/fxfa/src/common/xfa_script.h"
13
+ #include "xfa/src/fxfa/src/common/xfa_docdata.h"
14
+ #include "xfa/src/fxfa/src/common/xfa_doclayout.h"
15
+ #include "xfa/src/fxfa/src/common/xfa_localemgr.h"
16
+ #include "xfa/src/fxfa/src/common/xfa_fm2jsapi.h"
17
+ #include "xfa_document_layout_imp.h"
18
+ #include "xfa_layout_itemlayout.h"
19
+ #include "xfa_layout_pagemgr_new.h"
20
+ #include "xfa_layout_appadapter.h"
21
+ FX_DWORD XFA_GetRelevant(CXFA_Node* pFormItem, FX_DWORD dwParentRelvant) {
22
+ FX_DWORD dwRelevant = XFA_LAYOUTSTATUS_Viewable | XFA_LAYOUTSTATUS_Printable;
23
+ CFX_WideStringC wsRelevant;
24
+ if (pFormItem->TryCData(XFA_ATTRIBUTE_Relevant, wsRelevant)) {
25
+ if (wsRelevant == FX_WSTRC(L"+print") || wsRelevant == FX_WSTRC(L"print")) {
26
+ dwRelevant &= ~XFA_LAYOUTSTATUS_Viewable;
27
+ } else if (wsRelevant == FX_WSTRC(L"-print")) {
28
+ dwRelevant &= ~XFA_LAYOUTSTATUS_Printable;
29
+ }
30
+ }
31
+ if (!(dwParentRelvant & XFA_LAYOUTSTATUS_Viewable) &&
32
+ (dwRelevant != XFA_LAYOUTSTATUS_Viewable)) {
33
+ dwRelevant &= ~XFA_LAYOUTSTATUS_Viewable;
34
+ }
35
+ if (!(dwParentRelvant & XFA_LAYOUTSTATUS_Printable) &&
36
+ (dwRelevant != XFA_LAYOUTSTATUS_Printable)) {
37
+ dwRelevant &= ~XFA_LAYOUTSTATUS_Printable;
38
+ }
39
+ return dwRelevant;
40
+ }
41
+ void XFA_ReleaseLayoutItem(CXFA_LayoutItem* pLayoutItem) {
42
+ CXFA_LayoutItem* pNode = pLayoutItem->m_pFirstChild;
43
+ while (pNode) {
44
+ CXFA_LayoutItem* pNext = pNode->m_pNextSibling;
45
+ pNode->m_pParent = nullptr;
46
+ XFA_ReleaseLayoutItem(pNode);
47
+ pNode = pNext;
48
+ }
49
+ IXFA_Notify* pNotify =
50
+ pLayoutItem->m_pFormNode->GetDocument()->GetParser()->GetNotify();
51
+ if (pLayoutItem->m_pFormNode->GetClassID() == XFA_ELEMENT_PageArea) {
52
+ pNotify->OnPageEvent(static_cast<CXFA_ContainerLayoutItem*>(pLayoutItem),
53
+ XFA_PAGEEVENT_PageRemoved);
54
+ }
55
+ delete pLayoutItem;
56
+ }
pool/shard011/C++/0121616_TcpConnector.cpp ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright (c) 2011-2016 The Cryptonote developers
2
+ // Copyright (c) 2014-2017 XDN-project developers
3
+ // Distributed under the MIT/X11 software license, see the accompanying
4
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
+
6
+ #include "TcpConnector.h"
7
+ #include <cassert>
8
+
9
+ #include <fcntl.h>
10
+ #include <netdb.h>
11
+ #include <sys/errno.h>
12
+ #include <sys/event.h>
13
+ #include <sys/socket.h>
14
+ #include <sys/types.h>
15
+ #include <unistd.h>
16
+
17
+ #include <System/InterruptedException.h>
18
+ #include <System/Ipv4Address.h>
19
+ #include "Dispatcher.h"
20
+ #include "ErrorMessage.h"
21
+ #include "TcpConnection.h"
22
+
23
+ namespace System {
24
+
25
+ namespace {
26
+
27
+ struct ConnectorContext : public OperationContext {
28
+ int connection;
29
+ };
30
+
31
+ }
32
+
33
+ TcpConnector::TcpConnector() : dispatcher(nullptr) {
34
+ }
35
+
36
+ TcpConnector::TcpConnector(Dispatcher& dispatcher) : dispatcher(&dispatcher), context(nullptr) {
37
+ }
38
+
39
+ TcpConnector::TcpConnector(TcpConnector&& other) : dispatcher(other.dispatcher) {
40
+ if (other.dispatcher != nullptr) {
41
+ assert(other.context == nullptr);
42
+ context = nullptr;
43
+ other.dispatcher = nullptr;
44
+ }
45
+ }
46
+
47
+ TcpConnector::~TcpConnector() {
48
+ assert(dispatcher == nullptr || context == nullptr);
49
+ }
50
+
51
+ TcpConnector& TcpConnector::operator=(TcpConnector&& other) {
52
+ dispatcher = other.dispatcher;
53
+ if (other.dispatcher != nullptr) {
54
+ assert(other.context == nullptr);
55
+ context = nullptr;
56
+ other.dispatcher = nullptr;
57
+ }
58
+
59
+ return *this;
60
+ }
61
+
62
+ TcpConnection TcpConnector::connect(const Ipv4Address& address, uint16_t port) {
63
+ assert(dispatcher != nullptr);
64
+ assert(context == nullptr);
65
+ if (dispatcher->interrupted()) {
66
+ throw InterruptedException();
67
+ }
68
+
69
+ std::string message;
70
+ int connection = ::socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
71
+ if (connection == -1) {
72
+ message = "socket failed, " + lastErrorMessage();
73
+ } else {
74
+ sockaddr_in bindAddress;
75
+ bindAddress.sin_family = AF_INET;
76
+ bindAddress.sin_port = 0;
77
+ bindAddress.sin_addr.s_addr = INADDR_ANY;
78
+ if (bind(connection, reinterpret_cast<sockaddr*>(&bindAddress), sizeof bindAddress) != 0) {
79
+ message = "bind failed, " + lastErrorMessage();
80
+ } else {
81
+ int flags = fcntl(connection, F_GETFL, 0);
82
+ if (flags == -1 || fcntl(connection, F_SETFL, flags | O_NONBLOCK) == -1) {
83
+ message = "fcntl failed, " + lastErrorMessage();
84
+ } else {
85
+ sockaddr_in addressData;
86
+ addressData.sin_family = AF_INET;
87
+ addressData.sin_port = htons(port);
88
+ addressData.sin_addr.s_addr = htonl(address.getValue());
89
+ int result = ::connect(connection, reinterpret_cast<sockaddr *>(&addressData), sizeof addressData);
90
+ if (result == -1) {
91
+ if (errno == EINPROGRESS) {
92
+ ConnectorContext connectorContext;
93
+ connectorContext.context = dispatcher->getCurrentContext();
94
+ connectorContext.interrupted = false;
95
+ connectorContext.connection = connection;
96
+
97
+ struct kevent event;
98
+ EV_SET(&event, connection, EVFILT_WRITE, EV_ADD | EV_ENABLE, 0, 0, &connectorContext);
99
+ if (kevent(dispatcher->getKqueue(), &event, 1, NULL, 0, NULL) == -1) {
100
+ message = "kevent failed, " + lastErrorMessage();
101
+ } else {
102
+ context = &connectorContext;
103
+ dispatcher->getCurrentContext()->interruptProcedure = [&] {
104
+ assert(dispatcher != nullptr);
105
+ assert(context != nullptr);
106
+ ConnectorContext* connectorContext = static_cast<ConnectorContext*>(context);
107
+ if (!connectorContext->interrupted) {
108
+ if (close(connectorContext->connection) == -1) {
109
+ throw std::runtime_error("TcpListener::stop, close failed, " + lastErrorMessage());
110
+ }
111
+
112
+ dispatcher->pushContext(connectorContext->context);
113
+ connectorContext->interrupted = true;
114
+ }
115
+ };
116
+
117
+ dispatcher->dispatch();
118
+ dispatcher->getCurrentContext()->interruptProcedure = nullptr;
119
+ assert(dispatcher != nullptr);
120
+ assert(connectorContext.context == dispatcher->getCurrentContext());
121
+ assert(context == &connectorContext);
122
+ context = nullptr;
123
+ connectorContext.context = nullptr;
124
+ if (connectorContext.interrupted) {
125
+ throw InterruptedException();
126
+ }
127
+
128
+ struct kevent event;
129
+ EV_SET(&event, connection, EVFILT_WRITE, EV_ADD | EV_DISABLE, 0, 0, NULL);
130
+
131
+ if (kevent(dispatcher->getKqueue(), &event, 1, NULL, 0, NULL) == -1) {
132
+ message = "kevent failed, " + lastErrorMessage();
133
+ } else {
134
+ int retval = -1;
135
+ socklen_t retValLen = sizeof(retval);
136
+ int s = getsockopt(connection, SOL_SOCKET, SO_ERROR, &retval, &retValLen);
137
+ if (s == -1) {
138
+ message = "getsockopt failed, " + lastErrorMessage();
139
+ } else {
140
+ if (retval != 0) {
141
+ message = "getsockopt failed, " + lastErrorMessage();
142
+ } else {
143
+ return TcpConnection(*dispatcher, connection);
144
+ }
145
+ }
146
+ }
147
+ }
148
+ }
149
+ } else {
150
+ return TcpConnection(*dispatcher, connection);
151
+ }
152
+ }
153
+ }
154
+
155
+ int result = close(connection);
156
+ assert(result != -1);;
157
+ }
158
+
159
+ throw std::runtime_error("TcpConnector::connect, " + message);
160
+ }
161
+
162
+ }
pool/shard011/C++/0121617_PostRAHazardRecognizer.cpp ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //===----- PostRAHazardRecognizer.cpp - hazard recognizer -----------------===//
2
+ //
3
+ // The LLVM Compiler Infrastructure
4
+ //
5
+ // This file is distributed under the University of Illinois Open Source
6
+ // License. See LICENSE.TXT for details.
7
+ //
8
+ //===----------------------------------------------------------------------===//
9
+ //
10
+ /// \file
11
+ /// This runs the hazard recognizer and emits noops when necessary. This
12
+ /// gives targets a way to run the hazard recognizer without running one of
13
+ /// the schedulers. Example use cases for this pass would be:
14
+ ///
15
+ /// - Targets that need the hazard recognizer to be run at -O0.
16
+ /// - Targets that want to guarantee that hazards at the beginning of
17
+ /// scheduling regions are handled correctly. The post-RA scheduler is
18
+ /// a top-down scheduler, but when there are multiple scheduling regions
19
+ /// in a basic block, it visits the regions in bottom-up order. This
20
+ /// makes it impossible for the scheduler to gauranttee it can correctly
21
+ /// handle hazards at the beginning of scheduling regions.
22
+ ///
23
+ /// This pass traverses all the instructions in a program in top-down order.
24
+ /// In contrast to the instruction scheduling passes, this pass never resets
25
+ /// the hazard recognizer to ensure it can correctly handles noop hazards at
26
+ /// the begining of blocks.
27
+ //
28
+ //===----------------------------------------------------------------------===//
29
+
30
+ #include "llvm/ADT/Statistic.h"
31
+ #include "llvm/CodeGen/MachineFunctionPass.h"
32
+ #include "llvm/CodeGen/Passes.h"
33
+ #include "llvm/CodeGen/ScheduleHazardRecognizer.h"
34
+ #include "llvm/Support/Debug.h"
35
+ #include "llvm/Support/ErrorHandling.h"
36
+ #include "llvm/Support/raw_ostream.h"
37
+ #include "llvm/Target/TargetInstrInfo.h"
38
+ #include "llvm/Target/TargetSubtargetInfo.h"
39
+ using namespace llvm;
40
+
41
+ #define DEBUG_TYPE "post-RA-hazard-rec"
42
+
43
+ STATISTIC(NumNoops, "Number of noops inserted");
44
+
45
+ namespace {
46
+ class PostRAHazardRecognizer : public MachineFunctionPass {
47
+
48
+ public:
49
+ static char ID;
50
+ PostRAHazardRecognizer() : MachineFunctionPass(ID) {}
51
+
52
+ void getAnalysisUsage(AnalysisUsage &AU) const override {
53
+ AU.setPreservesCFG();
54
+ MachineFunctionPass::getAnalysisUsage(AU);
55
+ }
56
+
57
+ bool runOnMachineFunction(MachineFunction &Fn) override;
58
+
59
+ };
60
+ char PostRAHazardRecognizer::ID = 0;
61
+
62
+ }
63
+
64
+ char &llvm::PostRAHazardRecognizerID = PostRAHazardRecognizer::ID;
65
+
66
+ INITIALIZE_PASS(PostRAHazardRecognizer, DEBUG_TYPE,
67
+ "Post RA hazard recognizer", false, false)
68
+
69
+ bool PostRAHazardRecognizer::runOnMachineFunction(MachineFunction &Fn) {
70
+ const TargetInstrInfo *TII = Fn.getSubtarget().getInstrInfo();
71
+ std::unique_ptr<ScheduleHazardRecognizer> HazardRec(
72
+ TII->CreateTargetPostRAHazardRecognizer(Fn));
73
+
74
+ // Return if the target has not implemented a hazard recognizer.
75
+ if (!HazardRec.get())
76
+ return false;
77
+
78
+ // Loop over all of the basic blocks
79
+ for (auto &MBB : Fn) {
80
+ // We do not call HazardRec->reset() here to make sure we are handling noop
81
+ // hazards at the start of basic blocks.
82
+ for (MachineInstr &MI : MBB) {
83
+ // If we need to emit noops prior to this instruction, then do so.
84
+ unsigned NumPreNoops = HazardRec->PreEmitNoops(&MI);
85
+ for (unsigned i = 0; i != NumPreNoops; ++i) {
86
+ HazardRec->EmitNoop();
87
+ TII->insertNoop(MBB, MachineBasicBlock::iterator(MI));
88
+ ++NumNoops;
89
+ }
90
+
91
+ HazardRec->EmitInstruction(&MI);
92
+ if (HazardRec->atIssueLimit()) {
93
+ HazardRec->AdvanceCycle();
94
+ }
95
+ }
96
+ }
97
+ return true;
98
+ }
pool/shard011/C++/0121621_KoOasisSettings.cpp ADDED
@@ -0,0 +1,224 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This file is part of the KDE project
2
+ Copyright (C) 2004 Laurent Montel <montel@kde.org>
3
+
4
+ This library is free software; you can redistribute it and/or
5
+ modify it under the terms of the GNU Library General Public
6
+ License as published by the Free Software Foundation; either
7
+ version 2 of the License, or (at your option) any later version.
8
+
9
+ This library 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 GNU
12
+ Library General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Library General Public License
15
+ along with this library; see the file COPYING.LIB. If not, write to
16
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
+ * Boston, MA 02110-1301, USA.
18
+ */
19
+
20
+ #include "KoOasisSettings.h"
21
+ #include "KoXmlNS.h"
22
+ #include <kdebug.h>
23
+
24
+ class KoOasisSettings::Private
25
+ {
26
+ };
27
+
28
+ KoOasisSettings::KoOasisSettings(const KoXmlDocument& doc)
29
+ : m_settingsElement(KoXml::namedItemNS(doc.documentElement(), KoXmlNS::office, "settings")),
30
+ m_configNSURI(KoXmlNS::config)
31
+ , d(0)
32
+ {
33
+ const KoXmlElement contents = doc.documentElement();
34
+ if (m_settingsElement.isNull())
35
+ kDebug(30003) << " document doesn't have tag 'office:settings'";
36
+ }
37
+
38
+ KoOasisSettings::KoOasisSettings(const KoXmlDocument& doc, const char* officeNSURI, const char* configNSURI)
39
+ : m_settingsElement(KoXml::namedItemNS(doc.documentElement(), officeNSURI, "settings")),
40
+ m_configNSURI(configNSURI)
41
+ , d(0)
42
+ {
43
+ const KoXmlElement contents = doc.documentElement();
44
+ if (m_settingsElement.isNull())
45
+ kDebug(30003) << " document doesn't have tag 'office:settings'";
46
+ }
47
+
48
+ KoOasisSettings::~KoOasisSettings()
49
+ {
50
+ delete d;
51
+ }
52
+
53
+ KoOasisSettings::Items KoOasisSettings::itemSet(const QString& itemSetName) const
54
+ {
55
+ KoXmlElement e;
56
+ forEachElement(e, m_settingsElement) {
57
+ if (e.localName() == "config-item-set" &&
58
+ e.namespaceURI() == m_configNSURI &&
59
+ e.attributeNS(m_configNSURI, "name", QString()) == itemSetName) {
60
+ return Items(e, this);
61
+ }
62
+ }
63
+
64
+ return Items(KoXmlElement(), this);
65
+ }
66
+
67
+ KoOasisSettings::IndexedMap KoOasisSettings::Items::indexedMap(const QString& itemMapName) const
68
+ {
69
+ KoXmlElement configItem;
70
+ forEachElement(configItem, m_element) {
71
+ if (configItem.localName() == "config-item-map-indexed" &&
72
+ configItem.namespaceURI() == m_settings->m_configNSURI &&
73
+ configItem.attributeNS(m_settings->m_configNSURI, "name", QString()) == itemMapName) {
74
+ return IndexedMap(configItem, m_settings);
75
+ }
76
+ }
77
+ return IndexedMap(KoXmlElement(), m_settings);
78
+ }
79
+
80
+ KoOasisSettings::NamedMap KoOasisSettings::Items::namedMap(const QString& itemMapName) const
81
+ {
82
+ KoXmlElement configItem;
83
+ forEachElement(configItem, m_element) {
84
+ if (configItem.localName() == "config-item-map-named" &&
85
+ configItem.namespaceURI() == m_settings->m_configNSURI &&
86
+ configItem.attributeNS(m_settings->m_configNSURI, "name", QString()) == itemMapName) {
87
+ return NamedMap(configItem, m_settings);
88
+ }
89
+ }
90
+ return NamedMap(KoXmlElement(), m_settings);
91
+ }
92
+
93
+ KoOasisSettings::Items KoOasisSettings::IndexedMap::entry(int entryIndex) const
94
+ {
95
+ int i = 0;
96
+ KoXmlElement entry;
97
+ forEachElement(entry, m_element) {
98
+ if (entry.localName() == "config-item-map-entry" &&
99
+ entry.namespaceURI() == m_settings->m_configNSURI) {
100
+ if (i == entryIndex)
101
+ return Items(entry, m_settings);
102
+ else
103
+ ++i;
104
+ }
105
+ }
106
+ return Items(KoXmlElement(), m_settings);
107
+ }
108
+
109
+ KoOasisSettings::Items KoOasisSettings::NamedMap::entry(const QString& entryName) const
110
+ {
111
+ KoXmlElement entry;
112
+ forEachElement(entry, m_element) {
113
+ if (entry.localName() == "config-item-map-entry" &&
114
+ entry.namespaceURI() == m_settings->m_configNSURI &&
115
+ entry.attributeNS(m_settings->m_configNSURI, "name", QString()) == entryName) {
116
+ return Items(entry, m_settings);
117
+ }
118
+ }
119
+ return Items(KoXmlElement(), m_settings);
120
+ }
121
+
122
+ // helper method
123
+ QString KoOasisSettings::Items::findConfigItem(const KoXmlElement& element,
124
+ const QString& item, bool* ok) const
125
+ {
126
+ KoXmlElement it;
127
+ forEachElement(it, element) {
128
+ if (it.localName() == "config-item" &&
129
+ it.namespaceURI() == m_settings->m_configNSURI &&
130
+ it.attributeNS(m_settings->m_configNSURI, "name", QString()) == item) {
131
+ *ok = true;
132
+ return it.text();
133
+ }
134
+ }
135
+ *ok = false;
136
+ return QString();
137
+ }
138
+
139
+
140
+ QString KoOasisSettings::Items::findConfigItem(const QString& item, bool* ok) const
141
+ {
142
+ return findConfigItem(m_element, item, ok);
143
+ }
144
+
145
+ #if 0 // does anyone need this one? passing a default value does the job, too
146
+ bool KoOasisSettings::Items::hasConfigItem(const QString& configName) const
147
+ {
148
+ bool ok;
149
+ (void)findConfigItem(configName, &ok);
150
+ return ok;
151
+ }
152
+ #endif
153
+
154
+ QString KoOasisSettings::Items::parseConfigItemString(const QString& configName, const QString& defValue) const
155
+ {
156
+ bool ok;
157
+ const QString str = findConfigItem(configName, &ok);
158
+ return ok ? str : defValue;
159
+ }
160
+
161
+ int KoOasisSettings::Items::parseConfigItemInt(const QString& configName, int defValue) const
162
+ {
163
+ bool ok;
164
+ const QString str = findConfigItem(configName, &ok);
165
+ int value;
166
+ if (ok) {
167
+ value = str.toInt(&ok);
168
+ if (ok)
169
+ return value;
170
+ }
171
+ return defValue;
172
+ }
173
+
174
+ qreal KoOasisSettings::Items::parseConfigItemDouble(const QString& configName, qreal defValue) const
175
+ {
176
+ bool ok;
177
+ const QString str = findConfigItem(configName, &ok);
178
+ qreal value;
179
+ if (ok) {
180
+ value = str.toDouble(&ok);
181
+ if (ok)
182
+ return value;
183
+ }
184
+ return defValue;
185
+ }
186
+
187
+ bool KoOasisSettings::Items::parseConfigItemBool(const QString& configName, bool defValue) const
188
+ {
189
+ bool ok;
190
+ const QString str = findConfigItem(configName, &ok);
191
+ if (! ok)
192
+ return defValue;
193
+ if (str == "true")
194
+ return true;
195
+ else if (str == "false")
196
+ return false;
197
+ return defValue;
198
+ }
199
+
200
+ short KoOasisSettings::Items::parseConfigItemShort(const QString& configName, short defValue) const
201
+ {
202
+ bool ok;
203
+ const QString str = findConfigItem(configName, &ok);
204
+ short value;
205
+ if (ok) {
206
+ value = str.toShort(&ok);
207
+ if (ok)
208
+ return value;
209
+ }
210
+ return defValue;
211
+ }
212
+
213
+ long KoOasisSettings::Items::parseConfigItemLong(const QString& configName, long defValue) const
214
+ {
215
+ bool ok;
216
+ const QString str = findConfigItem(configName, &ok);
217
+ long value;
218
+ if (ok) {
219
+ value = str.toLong(&ok);
220
+ if (ok)
221
+ return value;
222
+ }
223
+ return defValue;
224
+ }
pool/shard011/C++/0121623_campaign.cpp ADDED
@@ -0,0 +1,237 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* xoreos - A reimplementation of BioWare's Aurora engine
2
+ *
3
+ * xoreos is the legal property of its developers, whose names
4
+ * can be found in the AUTHORS file distributed with this source
5
+ * distribution.
6
+ *
7
+ * xoreos 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; either version 3
10
+ * of the License, or (at your option) any later version.
11
+ *
12
+ * xoreos 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 xoreos. If not, see <http://www.gnu.org/licenses/>.
19
+ */
20
+
21
+ /** @file
22
+ * The context holding a Witcher campaign.
23
+ */
24
+
25
+ #include "src/common/util.h"
26
+ #include "src/common/error.h"
27
+ #include "src/common/readfile.h"
28
+ #include "src/common/filepath.h"
29
+ #include "src/common/filelist.h"
30
+ #include "src/common/configman.h"
31
+
32
+ #include "src/aurora/gff3file.h"
33
+
34
+ #include "src/engines/witcher/campaign.h"
35
+ #include "src/engines/witcher/console.h"
36
+
37
+ namespace Engines {
38
+
39
+ namespace Witcher {
40
+
41
+ void CampaignDescription::clear() {
42
+ tag.clear();
43
+
44
+ name.clear();
45
+ description.clear();
46
+
47
+ file.clear();
48
+ directory.clear();
49
+ }
50
+
51
+
52
+ Campaign::Campaign(::Engines::Console &console) : _running(false),
53
+ _module(console, this), _newCampaign(0) {
54
+
55
+ findCampaigns();
56
+ }
57
+
58
+ Campaign::~Campaign() {
59
+ clear();
60
+ }
61
+
62
+ const std::list<CampaignDescription> &Campaign::getCampaigns() const {
63
+ return _campaigns;
64
+ }
65
+
66
+ void Campaign::findCampaigns() {
67
+ Common::UString moduleDir = ConfigMan.getString("WITCHER_moduleDir");
68
+ if (moduleDir.empty())
69
+ return;
70
+
71
+ Common::FileList modules;
72
+ if (!modules.addDirectory(moduleDir, -1))
73
+ return;
74
+
75
+ Common::FileList mmdFiles;
76
+ if (!modules.getSubListGlob(".*\\.mmd", true, mmdFiles))
77
+ return;
78
+
79
+ for (Common::FileList::const_iterator c = mmdFiles.begin(); c != mmdFiles.end(); ++c) {
80
+ CampaignDescription desc;
81
+
82
+ desc.directory = Common::FilePath::relativize(moduleDir, Common::FilePath::getDirectory(*c));
83
+ if (!readCampaign(*c, desc))
84
+ continue;
85
+
86
+ _campaigns.push_back(desc);
87
+ }
88
+ }
89
+
90
+ bool Campaign::readCampaign(const Common::UString &mmdFile, CampaignDescription &desc) {
91
+ Common::ReadFile *file = new Common::ReadFile;
92
+ if (!file->open(mmdFile)) {
93
+ delete file;
94
+ return false;
95
+ }
96
+
97
+ Aurora::GFF3File *gff = 0;
98
+ try {
99
+ gff = new Aurora::GFF3File(file, MKTAG('M', 'M', 'D', ' '));
100
+ } catch (...) {
101
+ return false;
102
+ }
103
+
104
+ gff->getTopLevel().getLocString("Meta_Name", desc.name);
105
+ gff->getTopLevel().getLocString("Meta_Desc", desc.description);
106
+
107
+ delete gff;
108
+
109
+ desc.file = mmdFile;
110
+ desc.tag = Common::FilePath::getStem(mmdFile).toLower();
111
+
112
+ return true;
113
+ }
114
+
115
+ void Campaign::clear() {
116
+ _module.clear();
117
+
118
+ _currentCampaign.clear();
119
+
120
+ _modules.clear();
121
+ _startModule.clear();
122
+
123
+ _newCampaign = 0;
124
+ }
125
+
126
+ void Campaign::load(const CampaignDescription &desc) {
127
+ if (isRunning()) {
128
+ // We are currently running a campaign. Schedule a safe change instead
129
+
130
+ changeCampaign(desc);
131
+ return;
132
+ }
133
+
134
+ // We are not currently running a campaign. Directly load the new campaign
135
+ loadCampaign(desc);
136
+ }
137
+
138
+ void Campaign::loadCampaignFile(const CampaignDescription &desc) {
139
+ Common::ReadFile *file = 0;
140
+ Aurora::GFF3File *gff = 0;
141
+ try {
142
+
143
+ try {
144
+ if (desc.file.empty())
145
+ throw Common::Exception("Campaign file is empty");
146
+
147
+ file = new Common::ReadFile(desc.file);
148
+ gff = new Aurora::GFF3File(file, MKTAG('M', 'M', 'D', ' '));
149
+ } catch (Common::Exception &UNUSED(e)) {
150
+ delete file;
151
+ throw;
152
+ }
153
+
154
+ _startModule = gff->getTopLevel().getString("StartingMod");
155
+
156
+ const Aurora::GFF3List &modules = gff->getTopLevel().getList("Meta_Mod_list");
157
+ for (Aurora::GFF3List::const_iterator m = modules.begin(); m != modules.end(); ++m)
158
+ _modules.push_back((*m)->getString("Mod_Name"));
159
+
160
+ if (_startModule.empty())
161
+ throw Common::Exception("No starting module");
162
+
163
+ } catch (Common::Exception &e) {
164
+ delete gff;
165
+
166
+ e.add("Failed to load campaign \"%s\" (\"%s\")", desc.tag.c_str(), desc.name.getString().c_str());
167
+ throw;
168
+ }
169
+
170
+ delete gff;
171
+ }
172
+
173
+ void Campaign::loadCampaign(const CampaignDescription &desc) {
174
+ clear();
175
+ loadCampaignFile(desc);
176
+
177
+ _currentCampaign = desc;
178
+
179
+ try {
180
+ _module.load(_currentCampaign.directory + "/" + _startModule + ".mod");
181
+ } catch (Common::Exception &e) {
182
+ clear();
183
+
184
+ e.add("Failed to load campaign's starting module");
185
+ throw;
186
+ }
187
+ }
188
+
189
+ void Campaign::run() {
190
+ _running = true;
191
+
192
+ try {
193
+ _module.run();
194
+ } catch (...) {
195
+ _running = false;
196
+ throw;
197
+ }
198
+
199
+ _running = false;
200
+ }
201
+
202
+ bool Campaign::isRunning() const {
203
+ return _running;
204
+ }
205
+
206
+ void Campaign::changeCampaign(const CampaignDescription &desc) {
207
+ _newCampaign = &desc;
208
+ }
209
+
210
+ void Campaign::replaceCampaign() {
211
+ if (!_newCampaign)
212
+ return;
213
+
214
+ const CampaignDescription *campaign = _newCampaign;
215
+
216
+ loadCampaign(*campaign);
217
+ }
218
+
219
+ const Aurora::LocString&Campaign::getName() const {
220
+ return _currentCampaign.name;
221
+ }
222
+
223
+ const Aurora::LocString &Campaign::getDescription() const {
224
+ return _currentCampaign.description;
225
+ }
226
+
227
+ void Campaign::refreshLocalized() {
228
+ _module.refreshLocalized();
229
+ }
230
+
231
+ Module *Campaign::getModule() {
232
+ return &_module;
233
+ }
234
+
235
+ } // End of namespace Witcher
236
+
237
+ } // End of namespace Engines
pool/shard011/C++/0121624_testParser.cpp ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //============================================================================//
2
+ // An example to test the performance of reconstruction methods //
3
+ // //
4
+ // Chao Peng //
5
+ // 11/12/2016 //
6
+ //============================================================================//
7
+
8
+ #include "PRadBenchMark.h"
9
+ #include "ConfigParser.h"
10
+ #include <iostream>
11
+ #include <iomanip>
12
+ #include <string>
13
+ #include <vector>
14
+
15
+ using namespace std;
16
+
17
+ int main(int argc, char *argv[])
18
+ {
19
+ if(argc < 2) {
20
+ cout << "usage: " << argv[0] << " <file>" << endl;
21
+ return -1;
22
+ }
23
+
24
+ PRadBenchMark timer;
25
+
26
+ ConfigParser parser;
27
+ int count = 100;
28
+
29
+ for(int i = 1; i <= count; ++i)
30
+ {
31
+ parser.OpenFile(argv[1]);
32
+ while(parser.ParseLine()) {;}
33
+
34
+ cout <<"------[ " << i << " ]---"
35
+ << "---[ " << timer.GetElapsedTimeStr() << " ]---"
36
+ << "---[ " << timer.GetElapsedTime()/(double)i << " ms/time ]------"
37
+ << "\r" << flush;
38
+ }
39
+
40
+ cout <<"------[ ev " << count << " ]---"
41
+ << "---[ " << timer.GetElapsedTimeStr() << " ]---"
42
+ << "---[ " << timer.GetElapsedTime()/(double)count << " ms/time ]------"
43
+ << endl;
44
+ cout << "Finished." << endl;
45
+
46
+ return 0;
47
+ }
pool/shard011/C++/0121626_TrueTypeRasterizer.cpp ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Copyright (c) 2006-2016 LOVE Development Team
3
+ *
4
+ * This software is provided 'as-is', without any express or implied
5
+ * warranty. In no event will the authors be held liable for any damages
6
+ * arising from the use of this software.
7
+ *
8
+ * Permission is granted to anyone to use this software for any purpose,
9
+ * including commercial applications, and to alter it and redistribute it
10
+ * freely, subject to the following restrictions:
11
+ *
12
+ * 1. The origin of this software must not be misrepresented; you must not
13
+ * claim that you wrote the original software. If you use this software
14
+ * in a product, an acknowledgment in the product documentation would be
15
+ * appreciated but is not required.
16
+ * 2. Altered source versions must be plainly marked as such, and must not be
17
+ * misrepresented as being the original software.
18
+ * 3. This notice may not be removed or altered from any source distribution.
19
+ **/
20
+
21
+ // LOVE
22
+ #include "TrueTypeRasterizer.h"
23
+
24
+ #include "common/Exception.h"
25
+
26
+ namespace love
27
+ {
28
+ namespace font
29
+ {
30
+ namespace freetype
31
+ {
32
+
33
+ TrueTypeRasterizer::TrueTypeRasterizer(FT_Library library, love::Data *data, int size, Hinting hinting)
34
+ : data(data)
35
+ , hinting(hinting)
36
+ {
37
+ if (size <= 0)
38
+ throw love::Exception("Invalid TrueType font size: %d", size);
39
+
40
+ FT_Error err = FT_Err_Ok;
41
+ err = FT_New_Memory_Face(library,
42
+ (const FT_Byte *)data->getData(), /* first byte in memory */
43
+ data->getSize(), /* size in bytes */
44
+ 0, /* face_index */
45
+ &face);
46
+
47
+ if (err != FT_Err_Ok)
48
+ throw love::Exception("TrueType Font loading error: FT_New_Face failed: 0x%x (problem with font file?)", err);
49
+
50
+ err = FT_Set_Pixel_Sizes(face, size, size);
51
+
52
+ if (err != FT_Err_Ok)
53
+ throw love::Exception("TrueType Font loading error: FT_Set_Pixel_Sizes failed: 0x%x (invalid size?)", err);
54
+
55
+ // Set global metrics
56
+ FT_Size_Metrics s = face->size->metrics;
57
+ metrics.advance = (int) (s.max_advance >> 6);
58
+ metrics.ascent = (int) (s.ascender >> 6);
59
+ metrics.descent = (int) (s.descender >> 6);
60
+ metrics.height = (int) (s.height >> 6);
61
+ }
62
+
63
+ TrueTypeRasterizer::~TrueTypeRasterizer()
64
+ {
65
+ FT_Done_Face(face);
66
+ }
67
+
68
+ int TrueTypeRasterizer::getLineHeight() const
69
+ {
70
+ return (int)(getHeight() * 1.25);
71
+ }
72
+
73
+ GlyphData *TrueTypeRasterizer::getGlyphData(uint32 glyph) const
74
+ {
75
+ love::font::GlyphMetrics glyphMetrics = {};
76
+ FT_Glyph ftglyph;
77
+
78
+ FT_Error err = FT_Err_Ok;
79
+ FT_ULong loadoption = hintingToLoadOption(hinting);
80
+
81
+ // Initialize
82
+ err = FT_Load_Glyph(face, FT_Get_Char_Index(face, glyph), FT_LOAD_DEFAULT | loadoption);
83
+
84
+ if (err != FT_Err_Ok)
85
+ throw love::Exception("TrueType Font glyph error: FT_Load_Glyph failed (0x%x)", err);
86
+
87
+ err = FT_Get_Glyph(face->glyph, &ftglyph);
88
+
89
+ if (err != FT_Err_Ok)
90
+ throw love::Exception("TrueType Font glyph error: FT_Get_Glyph failed (0x%x)", err);
91
+
92
+ FT_Render_Mode rendermode = FT_RENDER_MODE_NORMAL;
93
+ if (hinting == HINTING_MONO)
94
+ rendermode = FT_RENDER_MODE_MONO;
95
+
96
+ err = FT_Glyph_To_Bitmap(&ftglyph, rendermode, 0, 1);
97
+
98
+ if (err != FT_Err_Ok)
99
+ throw love::Exception("TrueType Font glyph error: FT_Glyph_To_Bitmap failed (0x%x)", err);
100
+
101
+ FT_BitmapGlyph bitmap_glyph = (FT_BitmapGlyph) ftglyph;
102
+ FT_Bitmap &bitmap = bitmap_glyph->bitmap; //just to make things easier
103
+
104
+ // Get metrics
105
+ glyphMetrics.bearingX = bitmap_glyph->left;
106
+ glyphMetrics.bearingY = bitmap_glyph->top;
107
+ glyphMetrics.height = bitmap.rows;
108
+ glyphMetrics.width = bitmap.width;
109
+ glyphMetrics.advance = (int) (ftglyph->advance.x >> 16);
110
+
111
+ GlyphData *glyphData = new GlyphData(glyph, glyphMetrics, GlyphData::FORMAT_LUMINANCE_ALPHA);
112
+
113
+ const uint8 *pixels = bitmap.buffer;
114
+ uint8 *dest = (uint8 *) glyphData->getData();
115
+
116
+ // We treat the luminance of the FreeType bitmap as alpha in the GlyphData.
117
+ if (bitmap.pixel_mode == FT_PIXEL_MODE_MONO)
118
+ {
119
+ for (int y = 0; y < (int) bitmap.rows; y++)
120
+ {
121
+ for (int x = 0; x < (int) bitmap.width; x++)
122
+ {
123
+ // Extract the 1-bit value and convert it to uint8.
124
+ uint8 v = ((pixels[x / 8]) & (1 << (7 - (x % 8)))) ? 255 : 0;
125
+ dest[2 * (y * bitmap.width + x) + 0] = 255;
126
+ dest[2 * (y * bitmap.width + x) + 1] = v;
127
+ }
128
+
129
+ pixels += bitmap.pitch;
130
+ }
131
+ }
132
+ else if (bitmap.pixel_mode == FT_PIXEL_MODE_GRAY)
133
+ {
134
+ for (int y = 0; y < (int) bitmap.rows; y++)
135
+ {
136
+ for (int x = 0; x < (int) bitmap.width; x++)
137
+ {
138
+ dest[2 * (y * bitmap.width + x) + 0] = 255;
139
+ dest[2 * (y * bitmap.width + x) + 1] = pixels[x];
140
+ }
141
+
142
+ pixels += bitmap.pitch;
143
+ }
144
+ }
145
+ else
146
+ {
147
+ delete glyphData;
148
+ FT_Done_Glyph(ftglyph);
149
+ throw love::Exception("Unknown TrueType glyph pixel mode.");
150
+ }
151
+
152
+ // Having copied the data over, we can destroy the glyph.
153
+ FT_Done_Glyph(ftglyph);
154
+
155
+ return glyphData;
156
+ }
157
+
158
+ int TrueTypeRasterizer::getGlyphCount() const
159
+ {
160
+ return (int) face->num_glyphs;
161
+ }
162
+
163
+ bool TrueTypeRasterizer::hasGlyph(uint32 glyph) const
164
+ {
165
+ return FT_Get_Char_Index(face, glyph) != 0;
166
+ }
167
+
168
+ float TrueTypeRasterizer::getKerning(uint32 leftglyph, uint32 rightglyph) const
169
+ {
170
+ FT_Vector kerning = {};
171
+ FT_Get_Kerning(face, leftglyph, rightglyph, FT_KERNING_DEFAULT, &kerning);
172
+ return float(kerning.x >> 6);
173
+ }
174
+
175
+ bool TrueTypeRasterizer::accepts(FT_Library library, love::Data *data)
176
+ {
177
+ const FT_Byte *fbase = (const FT_Byte *) data->getData();
178
+ FT_Long fsize = (FT_Long) data->getSize();
179
+
180
+ // Pasing in -1 for the face index lets us test if the data is valid.
181
+ return FT_New_Memory_Face(library, fbase, fsize, -1, nullptr) == 0;
182
+ }
183
+
184
+ FT_ULong TrueTypeRasterizer::hintingToLoadOption(Hinting hint)
185
+ {
186
+ switch (hint)
187
+ {
188
+ case HINTING_NORMAL:
189
+ default:
190
+ return FT_LOAD_TARGET_NORMAL;
191
+ case HINTING_LIGHT:
192
+ return FT_LOAD_TARGET_LIGHT;
193
+ case HINTING_MONO:
194
+ return FT_LOAD_TARGET_MONO;
195
+ case HINTING_NONE:
196
+ return FT_LOAD_NO_HINTING;
197
+ }
198
+ }
199
+
200
+ } // freetype
201
+ } // font
202
+ } // love
pool/shard011/C++/0121627_devtools_network_protocol_handler.cc ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2014 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 "chrome/browser/devtools/devtools_network_protocol_handler.h"
6
+
7
+ #include "base/values.h"
8
+ #include "chrome/browser/devtools/devtools_network_conditions.h"
9
+ #include "chrome/browser/devtools/devtools_network_controller_handle.h"
10
+ #include "chrome/browser/devtools/devtools_protocol_constants.h"
11
+ #include "chrome/browser/profiles/profile.h"
12
+ #include "content/public/browser/devtools_agent_host.h"
13
+ #include "content/public/browser/web_contents.h"
14
+
15
+ DevToolsNetworkProtocolHandler::DevToolsNetworkProtocolHandler() {
16
+ }
17
+
18
+ DevToolsNetworkProtocolHandler::~DevToolsNetworkProtocolHandler() {
19
+ }
20
+
21
+ base::DictionaryValue* DevToolsNetworkProtocolHandler::HandleCommand(
22
+ content::DevToolsAgentHost* agent_host,
23
+ base::DictionaryValue* command_dict) {
24
+ int id = 0;
25
+ std::string method;
26
+ base::DictionaryValue* params = nullptr;
27
+ if (!DevToolsProtocol::ParseCommand(command_dict, &id, &method, &params))
28
+ return nullptr;
29
+
30
+ namespace network = ::chrome::devtools::Network;
31
+
32
+ if (method == network::emulateNetworkConditions::kName)
33
+ return EmulateNetworkConditions(agent_host, id, params).release();
34
+
35
+ if (method == network::canEmulateNetworkConditions::kName)
36
+ return CanEmulateNetworkConditions(agent_host, id, params).release();
37
+
38
+ return nullptr;
39
+ }
40
+
41
+ scoped_ptr<base::DictionaryValue>
42
+ DevToolsNetworkProtocolHandler::CanEmulateNetworkConditions(
43
+ content::DevToolsAgentHost* agent_host,
44
+ int command_id,
45
+ base::DictionaryValue* params) {
46
+ scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue());
47
+ result->SetBoolean(chrome::devtools::kResult, true);
48
+ return DevToolsProtocol::CreateSuccessResponse(command_id, result.Pass());
49
+ }
50
+
51
+ scoped_ptr<base::DictionaryValue>
52
+ DevToolsNetworkProtocolHandler::EmulateNetworkConditions(
53
+ content::DevToolsAgentHost* agent_host,
54
+ int command_id,
55
+ base::DictionaryValue* params) {
56
+ namespace names = ::chrome::devtools::Network::emulateNetworkConditions;
57
+
58
+ bool offline = false;
59
+ if (!params || !params->GetBoolean(names::kParamOffline, &offline)) {
60
+ return DevToolsProtocol::CreateInvalidParamsResponse(
61
+ command_id, names::kParamOffline);
62
+ }
63
+ double latency = 0.0;
64
+ if (!params->GetDouble(names::kParamLatency, &latency)) {
65
+ return DevToolsProtocol::CreateInvalidParamsResponse(
66
+ command_id, names::kParamLatency);
67
+ }
68
+ if (latency < 0.0)
69
+ latency = 0.0;
70
+
71
+ double download_throughput = 0.0;
72
+ if (!params->GetDouble(names::kParamDownloadThroughput,
73
+ &download_throughput)) {
74
+ return DevToolsProtocol::CreateInvalidParamsResponse(
75
+ command_id, names::kParamDownloadThroughput);
76
+ }
77
+ if (download_throughput < 0.0)
78
+ download_throughput = 0.0;
79
+
80
+ double upload_throughput = 0.0;
81
+ if (!params->GetDouble(names::kParamUploadThroughput, &upload_throughput)) {
82
+ return DevToolsProtocol::CreateInvalidParamsResponse(
83
+ command_id, names::kParamUploadThroughput);
84
+ }
85
+ if (upload_throughput < 0.0)
86
+ upload_throughput = 0.0;
87
+
88
+ scoped_ptr<DevToolsNetworkConditions> conditions(
89
+ new DevToolsNetworkConditions(
90
+ offline, latency, download_throughput, upload_throughput));
91
+
92
+ UpdateNetworkState(agent_host, conditions.Pass());
93
+ return scoped_ptr<base::DictionaryValue>();
94
+ }
95
+
96
+ void DevToolsNetworkProtocolHandler::UpdateNetworkState(
97
+ content::DevToolsAgentHost* agent_host,
98
+ scoped_ptr<DevToolsNetworkConditions> conditions) {
99
+ Profile* profile = Profile::FromBrowserContext(
100
+ agent_host->GetBrowserContext());
101
+ if (!profile)
102
+ return;
103
+ profile->GetDevToolsNetworkControllerHandle()->SetNetworkState(
104
+ agent_host->GetId(), conditions.Pass());
105
+ }
106
+
107
+ void DevToolsNetworkProtocolHandler::DevToolsAgentStateChanged(
108
+ content::DevToolsAgentHost* agent_host,
109
+ bool attached) {
110
+ scoped_ptr<DevToolsNetworkConditions> conditions;
111
+ if (attached)
112
+ conditions.reset(new DevToolsNetworkConditions());
113
+ UpdateNetworkState(agent_host, conditions.Pass());
114
+ }
pool/shard011/C++/0121628_GtPolylineF.cpp ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ ** This file is part of the TridentCAD
3
+ ** This software was merged and developed by:
4
+ **
5
+ ** Anthony Daniels
6
+ **
7
+ ** TridentCAD is free software: you can redistribute it and/or modify
8
+ ** it under the terms of the GNU Lesser General Public License as published by
9
+ ** the Free Software Foundation, either version 3 of the License, or
10
+ ** (at your option) any later version.
11
+ **
12
+ ** The United States of America Department of Defense has unlimited
13
+ ** usage, redistribution, and modification rights to TridentCAD.
14
+ **
15
+ ** TridentCAD is distributed in the hope that it will be useful,
16
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ ** GNU Lesser General Public License for more details.
19
+ **
20
+ ** You should have received a copy of the GNU Lesser General Public License
21
+ ** along with TridentCAD. If not, see <http://www.gnu.org/licenses/>.
22
+ */
23
+ #pragma once
24
+ #pragma warning(push)
25
+ #pragma warning (disable : 4005 ) /* macro redefinition */
26
+ #define HTL_DLLEXPORT
27
+ #pragma warning(pop)
28
+
29
+ #include ".\GtPolylineF.h"
30
+ #include <modHtlArchive.h>
31
+
32
+ namespace GT
33
+ {
34
+
35
+ namespace GtCore
36
+ {
37
+ GtPolylineF::GtPolylineF(void)
38
+ : HtlBase()
39
+ {
40
+ //HtlBase Initialization
41
+ m_strType = "GtPolylineF";
42
+ //GtPolylineF Initialization////////////////////
43
+ m_objNullPoint.Zero();
44
+ return;
45
+ };
46
+
47
+
48
+ GtPolylineF::GtPolylineF(GtPolylineF& rhs)
49
+ : HtlBase(rhs)
50
+ {
51
+ //HtlBase Initialization
52
+ m_strType = "GtPolylineF";
53
+ //GtPolylineF Initialization////////////////////
54
+ size_t i, intNumPts;
55
+ m_arrObjPoints.clear();
56
+ intNumPts = rhs.Size();
57
+ for(i = 0; i < intNumPts; i++)
58
+ {
59
+ this->m_arrObjPoints.push_back(rhs.m_arrObjPoints.at(i));
60
+ };
61
+ return;
62
+ };
63
+
64
+ GtPolylineF & GtPolylineF::operator = (GtPolylineF & rhs)
65
+ {
66
+ if(this == &rhs)
67
+ return *this;
68
+
69
+ HtlBase::operator=(rhs);
70
+
71
+ //ORSSerializable Initialization
72
+ m_strType = "GtPolylineF";
73
+ //GtPolylineF Initialization////////////////////
74
+ size_t i, intNumPts;
75
+ m_arrObjPoints.clear();
76
+ intNumPts = rhs.Size();
77
+ for(i = 0; i < intNumPts; i++)
78
+ {
79
+ this->m_arrObjPoints.push_back(rhs.m_arrObjPoints.at(i));
80
+ };
81
+ return *this;
82
+ };
83
+
84
+ GtPolylineF::~GtPolylineF(void)
85
+ {
86
+ return;
87
+ };
88
+
89
+
90
+ bool GtPolylineF::operator == (GtPolylineF & rhs)
91
+ {
92
+ size_t i, intLHSNumPoints, intRHSNumPoints;
93
+ intLHSNumPoints = m_arrObjPoints.size();
94
+ intRHSNumPoints = rhs.m_arrObjPoints.size();
95
+ if(intLHSNumPoints != intRHSNumPoints){return false;};
96
+ //if number of points same must compare all of them
97
+ for(i = 0; i < intLHSNumPoints; i++)
98
+ {
99
+ if(m_arrObjPoints.at(i) != rhs.m_arrObjPoints.at(i)){return false;};
100
+ }
101
+ //made it this far without finding a difference, must be the same
102
+ return true;
103
+ };
104
+
105
+ bool GtPolylineF::operator != (GtPolylineF & rhs)
106
+ {
107
+ size_t i, intLHSNumPoints, intRHSNumPoints;
108
+ intLHSNumPoints = m_arrObjPoints.size();
109
+ intRHSNumPoints = rhs.m_arrObjPoints.size();
110
+ if(intLHSNumPoints != intRHSNumPoints){return true;};
111
+ //if number of points same must compare all of them
112
+ for(i = 0; i < intLHSNumPoints; i++)
113
+ {
114
+ if(m_arrObjPoints.at(i) != rhs.m_arrObjPoints.at(i)){return true;};
115
+ }
116
+ //made it this far without finding a difference, must be the same
117
+ return false;
118
+ };
119
+
120
+ void GtPolylineF::Clear(void)
121
+ {
122
+ m_arrObjPoints.clear();
123
+ };
124
+ size_t GtPolylineF::Size(void)
125
+ {
126
+ return m_arrObjPoints.size();
127
+ };
128
+ GtPoint3DF & GtPolylineF::At(size_t intIndex)
129
+ {
130
+ size_t intNumPoints;
131
+ intNumPoints = m_arrObjPoints.size();
132
+ if((intIndex >= 0) && (intIndex < intNumPoints))
133
+ {
134
+ return m_arrObjPoints.at(intIndex);
135
+ }else{
136
+ return m_objNullPoint;
137
+ };
138
+ };
139
+ void GtPolylineF::PushBack(GtPoint3DF & objNewPoint)
140
+ {
141
+ m_arrObjPoints.push_back(objNewPoint);
142
+ return;
143
+ };
144
+ void GtPolylineF::Round(int intNumDecimals)
145
+ {
146
+ size_t i, intNumPoints;
147
+ intNumPoints = m_arrObjPoints.size();
148
+ if(intNumPoints <= 0){return;};
149
+ for(i = 0; i < intNumPoints; i++)
150
+ {
151
+ m_arrObjPoints.at(i).Round(intNumDecimals);
152
+ };
153
+ };
154
+
155
+ //Virtual Inheritance Serialization Engines
156
+ //SERIALIZATION ACCESSOR MACRO///////////////////////////////////////
157
+ int GtPolylineF::Save(HTL::HtlElement * ptrCurrNode, std::string strMemVarName, bool blnWithSubObjects)
158
+ {
159
+
160
+ int intReturn = 0;
161
+ //SAFETY CHECK //put at top of all Serialize Methods
162
+ if(!ptrCurrNode){return 0;};
163
+ //CALL PARENT CLASS Serialize()
164
+ /*...*/
165
+ HtlBase::Save(ptrCurrNode, strMemVarName, blnWithSubObjects);
166
+ //Standard Member Variables
167
+ intReturn &= SetHtlMemVar< StlVector<GtPoint3DF, HTL_BASE> ,STL_CONTAINER>(ptrCurrNode,"m_arrObjPoints",m_arrObjPoints,true);
168
+
169
+
170
+ return intReturn;
171
+
172
+
173
+ };
174
+
175
+ int GtPolylineF::Load(HTL::HtlElement * ptrCurrNode, std::string strMemVarName)
176
+ {
177
+
178
+ int intReturn = 0;
179
+ //SAFETY CHECK //put at top of all Serialize Methods
180
+ if(!ptrCurrNode){return 0;};
181
+ //CALL PARENT CLASS Serialize()
182
+ /*...*/
183
+ HtlBase::Load(ptrCurrNode,strMemVarName);
184
+ //Standard Member Variables
185
+ //Standard Member Variables
186
+ intReturn &= GetHtlMemVar< StlVector<GtPoint3DF, HTL_BASE> ,STL_CONTAINER>(ptrCurrNode,"m_arrObjPoints",m_arrObjPoints);
187
+ return intReturn;
188
+
189
+ };
190
+
191
+ };//end namespace GtCore
192
+
193
+ };//end namespace GT
pool/shard011/C++/0121629_syscall_wrappers_unittest.cc ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2014 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 "sandbox/linux/services/syscall_wrappers.h"
6
+
7
+ #include <sys/syscall.h>
8
+ #include <sys/types.h>
9
+ #include <sys/wait.h>
10
+ #include <unistd.h>
11
+
12
+ #include "base/logging.h"
13
+ #include "base/posix/eintr_wrapper.h"
14
+ #include "base/third_party/valgrind/valgrind.h"
15
+ #include "build/build_config.h"
16
+ #include "sandbox/linux/tests/test_utils.h"
17
+ #include "sandbox/linux/tests/unit_tests.h"
18
+ #include "testing/gtest/include/gtest/gtest.h"
19
+
20
+ namespace sandbox {
21
+
22
+ namespace {
23
+
24
+ TEST(SyscallWrappers, BasicSyscalls) {
25
+ EXPECT_EQ(getpid(), sys_getpid());
26
+ }
27
+
28
+ TEST(SyscallWrappers, CloneBasic) {
29
+ pid_t child = sys_clone(SIGCHLD);
30
+ TestUtils::HandlePostForkReturn(child);
31
+ EXPECT_LT(0, child);
32
+ }
33
+
34
+ TEST(SyscallWrappers, CloneParentSettid) {
35
+ pid_t ptid = 0;
36
+ pid_t child = sys_clone(CLONE_PARENT_SETTID | SIGCHLD, nullptr, &ptid,
37
+ nullptr, nullptr);
38
+ TestUtils::HandlePostForkReturn(child);
39
+ EXPECT_LT(0, child);
40
+ EXPECT_EQ(child, ptid);
41
+ }
42
+
43
+ TEST(SyscallWrappers, CloneChildSettid) {
44
+ pid_t ctid = 0;
45
+ pid_t pid =
46
+ sys_clone(CLONE_CHILD_SETTID | SIGCHLD, nullptr, nullptr, &ctid, nullptr);
47
+
48
+ const int kSuccessExit = 0;
49
+ if (0 == pid) {
50
+ // In child.
51
+ if (sys_getpid() == ctid)
52
+ _exit(kSuccessExit);
53
+ _exit(1);
54
+ }
55
+
56
+ ASSERT_NE(-1, pid);
57
+ int status = 0;
58
+ ASSERT_EQ(pid, HANDLE_EINTR(waitpid(pid, &status, 0)));
59
+ ASSERT_TRUE(WIFEXITED(status));
60
+ EXPECT_EQ(kSuccessExit, WEXITSTATUS(status));
61
+ }
62
+
63
+ } // namespace
64
+
65
+ } // namespace sandbox
pool/shard011/C++/0121630_token_service_table_unittest.cc ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2014 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/files/scoped_temp_dir.h"
6
+ #include "base/macros.h"
7
+ #include "base/strings/string_number_conversions.h"
8
+ #include "base/time/time.h"
9
+ #include "build/build_config.h"
10
+ #include "components/os_crypt/os_crypt_mocker.h"
11
+ #include "components/signin/core/browser/webdata/token_service_table.h"
12
+ #include "components/webdata/common/web_database.h"
13
+ #include "testing/gtest/include/gtest/gtest.h"
14
+
15
+ using base::Time;
16
+
17
+ class TokenServiceTableTest : public testing::Test {
18
+ public:
19
+ TokenServiceTableTest() {}
20
+ ~TokenServiceTableTest() override {}
21
+
22
+ protected:
23
+ void SetUp() override {
24
+ OSCryptMocker::SetUpWithSingleton();
25
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
26
+ file_ = temp_dir_.GetPath().AppendASCII("TestWebDatabase");
27
+
28
+ table_.reset(new TokenServiceTable);
29
+ db_.reset(new WebDatabase);
30
+ db_->AddTable(table_.get());
31
+ ASSERT_EQ(sql::INIT_OK, db_->Init(file_));
32
+ }
33
+
34
+ void TearDown() override { OSCryptMocker::TearDown(); }
35
+
36
+ base::FilePath file_;
37
+ base::ScopedTempDir temp_dir_;
38
+ std::unique_ptr<TokenServiceTable> table_;
39
+ std::unique_ptr<WebDatabase> db_;
40
+
41
+ private:
42
+ DISALLOW_COPY_AND_ASSIGN(TokenServiceTableTest);
43
+ };
44
+
45
+ TEST_F(TokenServiceTableTest, TokenServiceGetAllRemoveAll) {
46
+ std::map<std::string, std::string> out_map;
47
+ std::string service;
48
+ std::string service2;
49
+ service = "testservice";
50
+ service2 = "othertestservice";
51
+
52
+ EXPECT_TRUE(table_->GetAllTokens(&out_map));
53
+ EXPECT_TRUE(out_map.empty());
54
+
55
+ // Check that get all tokens works
56
+ EXPECT_TRUE(table_->SetTokenForService(service, "pepperoni"));
57
+ EXPECT_TRUE(table_->SetTokenForService(service2, "steak"));
58
+ EXPECT_TRUE(table_->GetAllTokens(&out_map));
59
+ EXPECT_EQ("pepperoni", out_map.find(service)->second);
60
+ EXPECT_EQ("steak", out_map.find(service2)->second);
61
+ out_map.clear();
62
+
63
+ // Purge
64
+ EXPECT_TRUE(table_->RemoveAllTokens());
65
+ EXPECT_TRUE(table_->GetAllTokens(&out_map));
66
+ EXPECT_TRUE(out_map.empty());
67
+
68
+ // Check that you can still add it back in
69
+ EXPECT_TRUE(table_->SetTokenForService(service, "cheese"));
70
+ EXPECT_TRUE(table_->GetAllTokens(&out_map));
71
+ EXPECT_EQ("cheese", out_map.find(service)->second);
72
+ }
73
+
74
+ TEST_F(TokenServiceTableTest, TokenServiceGetSet) {
75
+ std::map<std::string, std::string> out_map;
76
+ std::string service;
77
+ service = "testservice";
78
+
79
+ EXPECT_TRUE(table_->GetAllTokens(&out_map));
80
+ EXPECT_TRUE(out_map.empty());
81
+
82
+ EXPECT_TRUE(table_->SetTokenForService(service, "pepperoni"));
83
+ EXPECT_TRUE(table_->GetAllTokens(&out_map));
84
+ EXPECT_EQ("pepperoni", out_map.find(service)->second);
85
+ out_map.clear();
86
+
87
+ // try blanking it - won't remove it from the db though!
88
+ EXPECT_TRUE(table_->SetTokenForService(service, std::string()));
89
+ EXPECT_TRUE(table_->GetAllTokens(&out_map));
90
+ EXPECT_EQ("", out_map.find(service)->second);
91
+ out_map.clear();
92
+
93
+ // try mutating it
94
+ EXPECT_TRUE(table_->SetTokenForService(service, "ham"));
95
+ EXPECT_TRUE(table_->GetAllTokens(&out_map));
96
+ EXPECT_EQ("ham", out_map.find(service)->second);
97
+ }
98
+
99
+ TEST_F(TokenServiceTableTest, TokenServiceRemove) {
100
+ std::map<std::string, std::string> out_map;
101
+ std::string service;
102
+ std::string service2;
103
+ service = "testservice";
104
+ service2 = "othertestservice";
105
+
106
+ EXPECT_TRUE(table_->SetTokenForService(service, "pepperoni"));
107
+ EXPECT_TRUE(table_->SetTokenForService(service2, "steak"));
108
+ EXPECT_TRUE(table_->RemoveTokenForService(service));
109
+ EXPECT_TRUE(table_->GetAllTokens(&out_map));
110
+ EXPECT_EQ(0u, out_map.count(service));
111
+ EXPECT_EQ("steak", out_map.find(service2)->second);
112
+ }
pool/shard011/C++/0121632_CWE195_Signed_to_Unsigned_Conversion_Error__fgets_memmove_73b.cpp ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* TEMPLATE GENERATED TESTCASE FILE
2
+ Filename: CWE195_Signed_to_Unsigned_Conversion_Error__fgets_memmove_73b.cpp
3
+ Label Definition File: CWE195_Signed_to_Unsigned_Conversion_Error.label.xml
4
+ Template File: sources-sink-73b.tmpl.cpp
5
+ */
6
+ /*
7
+ * @description
8
+ * CWE: 195 Signed to Unsigned Conversion Error
9
+ * BadSource: fgets Read data from the console using fgets()
10
+ * GoodSource: Positive integer
11
+ * Sinks: memmove
12
+ * BadSink : Copy strings using memmove() with the length of data
13
+ * Flow Variant: 73 Data flow: data passed in a list from one function to another in different source files
14
+ *
15
+ * */
16
+
17
+ #include "std_testcase.h"
18
+ #include <list>
19
+
20
+ using namespace std;
21
+
22
+ namespace CWE195_Signed_to_Unsigned_Conversion_Error__fgets_memmove_73
23
+ {
24
+
25
+ #ifndef OMITBAD
26
+
27
+ void badSink(list<int> dataList)
28
+ {
29
+ /* copy data out of dataList */
30
+ int data = dataList.back();
31
+ {
32
+ char source[100];
33
+ char dest[100] = "";
34
+ memset(source, 'A', 100-1);
35
+ source[100-1] = '\0';
36
+ if (data < 100)
37
+ {
38
+ /* POTENTIAL FLAW: data is interpreted as an unsigned int - if its value is negative,
39
+ * the sign conversion could result in a very large number */
40
+ memmove(dest, source, data);
41
+ dest[data] = '\0'; /* NULL terminate */
42
+ }
43
+ printLine(dest);
44
+ }
45
+ }
46
+
47
+ #endif /* OMITBAD */
48
+
49
+ #ifndef OMITGOOD
50
+
51
+ /* goodG2B uses the GoodSource with the BadSink */
52
+ void goodG2BSink(list<int> dataList)
53
+ {
54
+ int data = dataList.back();
55
+ {
56
+ char source[100];
57
+ char dest[100] = "";
58
+ memset(source, 'A', 100-1);
59
+ source[100-1] = '\0';
60
+ if (data < 100)
61
+ {
62
+ /* POTENTIAL FLAW: data is interpreted as an unsigned int - if its value is negative,
63
+ * the sign conversion could result in a very large number */
64
+ memmove(dest, source, data);
65
+ dest[data] = '\0'; /* NULL terminate */
66
+ }
67
+ printLine(dest);
68
+ }
69
+ }
70
+
71
+ #endif /* OMITGOOD */
72
+
73
+ } /* close namespace */
pool/shard011/C++/0121633_CanvasRenderingContext.cpp ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright (C) 2009 Apple Inc. 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. ``AS IS'' AND ANY
14
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
+ */
25
+
26
+ #include "config.h"
27
+ #include "CanvasRenderingContext.h"
28
+
29
+ #include "CachedImage.h"
30
+ #include "CanvasPattern.h"
31
+ #include "HTMLImageElement.h"
32
+ #include "HTMLVideoElement.h"
33
+ #include "Image.h"
34
+ #include "URL.h"
35
+ #include "SecurityOrigin.h"
36
+
37
+ namespace WebCore {
38
+
39
+ CanvasRenderingContext::CanvasRenderingContext(HTMLCanvasElement* canvas)
40
+ : m_canvas(canvas)
41
+ {
42
+ }
43
+
44
+ bool CanvasRenderingContext::wouldTaintOrigin(const CanvasPattern* pattern)
45
+ {
46
+ if (canvas()->originClean() && pattern && !pattern->originClean())
47
+ return true;
48
+ return false;
49
+ }
50
+
51
+ bool CanvasRenderingContext::wouldTaintOrigin(const HTMLCanvasElement* sourceCanvas)
52
+ {
53
+ if (canvas()->originClean() && sourceCanvas && !sourceCanvas->originClean())
54
+ return true;
55
+ return false;
56
+ }
57
+
58
+ bool CanvasRenderingContext::wouldTaintOrigin(const HTMLImageElement* image)
59
+ {
60
+ if (!image || !canvas()->originClean())
61
+ return false;
62
+
63
+ CachedImage* cachedImage = image->cachedImage();
64
+ if (!cachedImage->image()->hasSingleSecurityOrigin())
65
+ return true;
66
+
67
+ return wouldTaintOrigin(cachedImage->response().url()) && !cachedImage->passesAccessControlCheck(canvas()->securityOrigin());
68
+ }
69
+
70
+ bool CanvasRenderingContext::wouldTaintOrigin(const HTMLVideoElement* video)
71
+ {
72
+ #if ENABLE(VIDEO)
73
+ // FIXME: This check is likely wrong when a redirect is involved. We need
74
+ // to test the finalURL. Please be careful when fixing this issue not to
75
+ // make currentSrc be the final URL because then the
76
+ // HTMLMediaElement.currentSrc DOM API would leak redirect destinations!
77
+ if (!video || !canvas()->originClean())
78
+ return false;
79
+
80
+ if (!video->hasSingleSecurityOrigin())
81
+ return true;
82
+
83
+ if (!(video->player() && video->player()->didPassCORSAccessCheck()) && wouldTaintOrigin(video->currentSrc()))
84
+ return true;
85
+
86
+ #else
87
+ UNUSED_PARAM(video);
88
+ #endif
89
+
90
+ return false;
91
+ }
92
+
93
+ bool CanvasRenderingContext::wouldTaintOrigin(const URL& url)
94
+ {
95
+ if (!canvas()->originClean())
96
+ return false;
97
+
98
+ if (canvas()->securityOrigin()->taintsCanvas(url))
99
+ return true;
100
+
101
+ if (url.protocolIsData())
102
+ return false;
103
+
104
+ return false;
105
+ }
106
+
107
+ void CanvasRenderingContext::checkOrigin(const URL& url)
108
+ {
109
+ if (wouldTaintOrigin(url))
110
+ canvas()->setOriginTainted();
111
+ }
112
+
113
+ } // namespace WebCore
pool/shard011/C++/0121635_del_source_formula_Equivalence_Normalize.cpp ADDED
@@ -0,0 +1,188 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*****************************************************************************/
2
+ /* Project name: del - mathematics development language */
3
+ /* File Name: del_source_formula_Equivalence_Normalize.cpp */
4
+ /* Description: normalization subset formula routines */
5
+ /* Copyright: (c) 2006-2009 Dmitri Vlasov */
6
+ /* Author: Dmitri Yurievich Vlasov, Novosibirsk, Russia */
7
+ /* Email: vlasov at academ.org */
8
+ /* URL: http://mathdevlanguage.sourceforge.net */
9
+ /* Modified by: */
10
+ /* License: GNU General Public License Version 3 */
11
+ /*****************************************************************************/
12
+
13
+ #pragma once
14
+
15
+ #include "del/lexer/del_lexer.hpp"
16
+ #include "del/source/del_source.hpp"
17
+
18
+ namespace del {
19
+ namespace source {
20
+ namespace formula {
21
+
22
+ /****************************
23
+ * Private members
24
+ ****************************/
25
+
26
+ using manipulator :: endLine;
27
+ using manipulator :: space;
28
+ using manipulator :: tab;
29
+
30
+ // normalization routines
31
+ void
32
+ Equivalence :: transformIntersection (del :: Theory* theory) const
33
+ {
34
+ for (value :: Integer i = 0; i < term_2_->getSize(); ++ i) {
35
+ const del :: Term* const
36
+ conjTerm = Formula :: term_2_->getSubterm (i);
37
+ const del :: Formula* const formula = new Equivalence
38
+ (
39
+ location_,
40
+ Formula :: term_1_->clone(),
41
+ conjTerm->clone(),
42
+ image_,
43
+ COMPLEX_KIND,
44
+ isRoot_
45
+ );
46
+ theory->addFormula (formula);
47
+ }
48
+ Del :: statistics().data()->incConjunctionRight();
49
+ }
50
+ void
51
+ Equivalence :: transformComplexExists (del :: Theory* theory, const del :: Term* complexExists) const
52
+ {
53
+ const value :: Variable
54
+ var = Table :: variables()->fresh ("X");
55
+ const del :: Term* const
56
+ term_1_1 = new term :: Variable (location_, var, complexExists->getSubterm());
57
+
58
+ const del :: Term* const
59
+ term_1_2 = complexExists->getSubterm()->clone();
60
+ const del :: Term* const
61
+ term_2_1 = new term :: Variable (location_, var, complexExists->getSubterm());
62
+ const del :: Term* const
63
+ term_2_2 = complexExists->getSubterm()->clone();
64
+
65
+ const del :: Formula* const first = new formula :: Equivalence
66
+ (
67
+ location_,
68
+ term_1_1,
69
+ term_1_2,
70
+ image_
71
+ );
72
+ const del :: Formula* const second = new formula :: Equivalence
73
+ (
74
+ location_,
75
+ term_2_2,
76
+ term_2_1,
77
+ image_
78
+ );
79
+ theory->addFormula (clone());
80
+ theory->replace (complexExists->getSubterm(), term_1_1);
81
+ theory->addFormula (first);
82
+ theory->addFormula (second);
83
+ }
84
+ void
85
+ Equivalence :: transformRightExists
86
+ (
87
+ del :: Theory* theory,
88
+ del :: Term*& term
89
+ ) const
90
+ {
91
+ /* If A1 ⊓ ··· ⊓ An ⊓ ∃r1.B1 ⊓ ··· ∃rm.Bm ⊑ ∃r.B in T, remove it,
92
+ * remove it, take a new concept names Z1...Zm and add
93
+ * A1 ⊓ ··· ⊓ An ⊓ Z1 ⊓ ... ⊓ Zm ⊑ X, ∃r1 .B1 ≡ Z1 ... ∃rm .Bm ≡ Zm
94
+ * and X ≡ ∃r.B to T */
95
+
96
+ const value :: Variable
97
+ var = Table :: variables()->fresh ("Y");
98
+ const del :: Term* const
99
+ varTerm = new term :: Variable (location_, var, term);
100
+
101
+
102
+ const del :: Formula* const first = new formula :: Identity
103
+ (
104
+ location_,
105
+ term,
106
+ varTerm,
107
+ image_
108
+ );
109
+ term = varTerm->clone();
110
+ const del :: Formula* const
111
+ second = clone();
112
+ theory->addFormula (first);
113
+ theory->addFormula (second);
114
+ }
115
+ void
116
+ Equivalence :: transformExisisVector (del :: Theory* theory, del :: Term* term) const
117
+ {
118
+ if (!term->isIntersection()) {
119
+ return;
120
+ }
121
+ term :: Intersect*
122
+ existsIntersection = dynamic_cast<term :: Intersect*>(term);
123
+ term :: Intersect*
124
+ intersection = dynamic_cast<term :: Intersect*>(const_cast<del :: Term*>(term_1_));
125
+
126
+ for (value :: Integer i = 0; i < existsIntersection->getSize(); ++ i) {
127
+ const value :: Variable
128
+ var = Table :: variables()->fresh ("U");
129
+ const del :: Term* const
130
+ subterm = existsIntersection->getSubterm (i);
131
+ const del :: Term* const
132
+ varTerm = new term :: Variable (location_, var, subterm);
133
+
134
+ intersection->addTerm (varTerm);
135
+
136
+ const del :: Formula* const first = new formula :: Identity
137
+ (
138
+ location_,
139
+ subterm->clone(),
140
+ varTerm->clone(),
141
+ image_
142
+ );
143
+ theory->addFormula (first);
144
+ }
145
+ existsIntersection->commitSuicide();
146
+ }
147
+ void
148
+ Equivalence :: transformSingleExists (del :: Theory* theory) const
149
+ {
150
+ /* If ∃r1.B1 ⊑ ∃r2.B2 in T , remove it,
151
+ * take a new concept name X and add ∃r1.B1 ⊑ X
152
+ * and X ⊑ ∃r2.B2 to T */
153
+ if (!term_1_->isExists() || !term_2_->isExists()) {
154
+ return;
155
+ }
156
+ const value :: Variable
157
+ var = Table :: variables()->fresh ("W");
158
+ const del :: Term* const
159
+ term_1_1 = term_1_->clone();
160
+ const del :: Term* const
161
+ term_1_2 = new term :: Variable (location_, var, term_1_1);
162
+ const del :: Term* const
163
+ term_2_1 = new term :: Variable (location_, var);
164
+ const del :: Term* const
165
+ term_2_2 = term_2_->clone();
166
+
167
+ const del :: Formula* const first = new formula :: Identity
168
+ (
169
+ location_,
170
+ term_1_1,
171
+ term_1_2,
172
+ image_
173
+ );
174
+ const del :: Formula* const second = new formula :: Equivalence
175
+ (
176
+ location_,
177
+ term_2_1,
178
+ term_2_2,
179
+ image_
180
+ );
181
+ theory->addFormula (first);
182
+ theory->addFormula (second);
183
+ }
184
+ }
185
+ }
186
+ }
187
+
188
+
pool/shard011/C++/0121636_motion_event_web.cc ADDED
@@ -0,0 +1,180 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2014 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
+ // MSVC++ requires this to be set before any other includes to get M_PI.
6
+ #define _USE_MATH_DEFINES
7
+
8
+ #include "content/browser/renderer_host/input/motion_event_web.h"
9
+
10
+ #include <cmath>
11
+
12
+ #include "base/logging.h"
13
+ #include "content/browser/renderer_host/input/web_input_event_util.h"
14
+ #include "content/common/input/web_touch_event_traits.h"
15
+
16
+ using blink::WebInputEvent;
17
+ using blink::WebTouchEvent;
18
+ using blink::WebTouchPoint;
19
+
20
+ namespace content {
21
+ namespace {
22
+
23
+ ui::MotionEvent::Action GetActionFrom(const WebTouchEvent& event) {
24
+ DCHECK(event.touchesLength);
25
+ switch (event.type) {
26
+ case WebInputEvent::TouchStart:
27
+ if (WebTouchEventTraits::AllTouchPointsHaveState(
28
+ event, WebTouchPoint::StatePressed))
29
+ return ui::MotionEvent::ACTION_DOWN;
30
+ else
31
+ return ui::MotionEvent::ACTION_POINTER_DOWN;
32
+ case WebInputEvent::TouchEnd:
33
+ if (WebTouchEventTraits::AllTouchPointsHaveState(
34
+ event, WebTouchPoint::StateReleased))
35
+ return ui::MotionEvent::ACTION_UP;
36
+ else
37
+ return ui::MotionEvent::ACTION_POINTER_UP;
38
+ case WebInputEvent::TouchCancel:
39
+ DCHECK(WebTouchEventTraits::AllTouchPointsHaveState(
40
+ event, WebTouchPoint::StateCancelled));
41
+ return ui::MotionEvent::ACTION_CANCEL;
42
+ case WebInputEvent::TouchMove:
43
+ return ui::MotionEvent::ACTION_MOVE;
44
+ default:
45
+ break;
46
+ };
47
+ NOTREACHED()
48
+ << "Unable to derive a valid MotionEvent::Action from the WebTouchEvent.";
49
+ return ui::MotionEvent::ACTION_CANCEL;
50
+ }
51
+
52
+ int GetActionIndexFrom(const WebTouchEvent& event) {
53
+ for (size_t i = 0; i < event.touchesLength; ++i) {
54
+ if (event.touches[i].state != WebTouchPoint::StateUndefined &&
55
+ event.touches[i].state != WebTouchPoint::StateStationary)
56
+ return i;
57
+ }
58
+ return -1;
59
+ }
60
+
61
+ } // namespace
62
+
63
+ MotionEventWeb::MotionEventWeb(const WebTouchEvent& event)
64
+ : event_(event),
65
+ cached_action_(GetActionFrom(event)),
66
+ cached_action_index_(GetActionIndexFrom(event)) {
67
+ DCHECK_GT(GetPointerCount(), 0U);
68
+ }
69
+
70
+ MotionEventWeb::~MotionEventWeb() {}
71
+
72
+ int MotionEventWeb::GetId() const {
73
+ return 0;
74
+ }
75
+
76
+ MotionEventWeb::Action MotionEventWeb::GetAction() const {
77
+ return cached_action_;
78
+ }
79
+
80
+ int MotionEventWeb::GetActionIndex() const { return cached_action_index_; }
81
+
82
+ size_t MotionEventWeb::GetPointerCount() const { return event_.touchesLength; }
83
+
84
+ int MotionEventWeb::GetPointerId(size_t pointer_index) const {
85
+ DCHECK_LT(pointer_index, GetPointerCount());
86
+ return event_.touches[pointer_index].id;
87
+ }
88
+
89
+ float MotionEventWeb::GetX(size_t pointer_index) const {
90
+ DCHECK_LT(pointer_index, GetPointerCount());
91
+ return event_.touches[pointer_index].position.x;
92
+ }
93
+
94
+ float MotionEventWeb::GetY(size_t pointer_index) const {
95
+ DCHECK_LT(pointer_index, GetPointerCount());
96
+ return event_.touches[pointer_index].position.y;
97
+ }
98
+
99
+ float MotionEventWeb::GetRawX(size_t pointer_index) const {
100
+ DCHECK_LT(pointer_index, GetPointerCount());
101
+ return event_.touches[pointer_index].screenPosition.x;
102
+ }
103
+
104
+ float MotionEventWeb::GetRawY(size_t pointer_index) const {
105
+ DCHECK_LT(pointer_index, GetPointerCount());
106
+ return event_.touches[pointer_index].screenPosition.y;
107
+ }
108
+
109
+ float MotionEventWeb::GetTouchMajor(size_t pointer_index) const {
110
+ DCHECK_LT(pointer_index, GetPointerCount());
111
+ return 2.f * std::max(event_.touches[pointer_index].radiusX,
112
+ event_.touches[pointer_index].radiusY);
113
+ }
114
+
115
+ float MotionEventWeb::GetTouchMinor(size_t pointer_index) const {
116
+ DCHECK_LT(pointer_index, GetPointerCount());
117
+ return 2.f * std::min(event_.touches[pointer_index].radiusX,
118
+ event_.touches[pointer_index].radiusY);
119
+ }
120
+
121
+ float MotionEventWeb::GetOrientation(size_t pointer_index) const {
122
+ DCHECK_LT(pointer_index, GetPointerCount());
123
+
124
+ float rotation_angle_rad = event_.touches[pointer_index].rotationAngle
125
+ * M_PI / 180.f;
126
+ DCHECK(0 <= rotation_angle_rad && rotation_angle_rad <= M_PI_2)
127
+ << "Unexpected touch rotation angle";
128
+
129
+ if (event_.touches[pointer_index].radiusX
130
+ > event_.touches[pointer_index].radiusY) {
131
+ // The case radiusX == radiusY is omitted from here on purpose: for circles,
132
+ // we want to pass the angle (which could be any value in such cases but
133
+ // always seem to be set to zero) unchanged.
134
+ rotation_angle_rad -= (float) M_PI_2;
135
+ }
136
+
137
+ return rotation_angle_rad;
138
+ }
139
+
140
+ float MotionEventWeb::GetPressure(size_t pointer_index) const {
141
+ return 0.f;
142
+ }
143
+
144
+ base::TimeTicks MotionEventWeb::GetEventTime() const {
145
+ return base::TimeTicks() +
146
+ base::TimeDelta::FromMicroseconds(event_.timeStampSeconds *
147
+ base::Time::kMicrosecondsPerSecond);
148
+ }
149
+
150
+ ui::MotionEvent::ToolType MotionEventWeb::GetToolType(
151
+ size_t pointer_index) const {
152
+ // TODO(jdduke): Plumb tool type from the platform event, crbug.com/404128.
153
+ DCHECK_LT(pointer_index, GetPointerCount());
154
+ return TOOL_TYPE_UNKNOWN;
155
+ }
156
+
157
+ int MotionEventWeb::GetButtonState() const {
158
+ NOTIMPLEMENTED();
159
+ return 0;
160
+ }
161
+
162
+ int MotionEventWeb::GetFlags() const {
163
+ return WebEventModifiersToEventFlags(event_.modifiers);
164
+ }
165
+
166
+ scoped_ptr<ui::MotionEvent> MotionEventWeb::Clone() const {
167
+ return scoped_ptr<MotionEvent>(new MotionEventWeb(event_));
168
+ }
169
+
170
+ scoped_ptr<ui::MotionEvent> MotionEventWeb::Cancel() const {
171
+ WebTouchEvent cancel_event(event_);
172
+ WebTouchEventTraits::ResetTypeAndTouchStates(
173
+ blink::WebInputEvent::TouchCancel,
174
+ // TODO(rbyers): Shouldn't we use a fresh timestamp?
175
+ event_.timeStampSeconds,
176
+ &cancel_event);
177
+ return scoped_ptr<MotionEvent>(new MotionEventWeb(cancel_event));
178
+ }
179
+
180
+ } // namespace content
pool/shard011/C++/0121637_SubspaceChat.cpp ADDED
@@ -0,0 +1,264 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include "SubspaceChat.h"
2
+
3
+ #include <iostream>
4
+
5
+ #include "AsciiUtil.h"
6
+ #include "SubspaceSettings.h"
7
+
8
+ #include "SubspacePlayer.h"
9
+
10
+ const string SubspaceChat::defaultHeaderSeparator_ = "> ";
11
+ const string SubspaceChat::defaultName_ = "<unknown>";
12
+
13
+ SubspaceChat::SubspaceChat() :
14
+ headerWidth_(defaultHeaderWidth_),
15
+ headerSeparator_(defaultHeaderSeparator_),
16
+ lineWidth_(defaultLineWidth_)
17
+ //players_(0)
18
+ {
19
+ //headerSeparator_ = "> ";
20
+ }
21
+
22
+ SubspaceChat::~SubspaceChat()
23
+ {
24
+ }
25
+
26
+ Uint SubspaceChat::countLines() const
27
+ {
28
+ Uint lines = 0, msgLines = 0;
29
+
30
+ MessageList::const_iterator i;
31
+ for(i = messages_.begin(); i != messages_.end(); ++i)
32
+ {
33
+ msgLines = countMessageLines(*i);
34
+ lines += msgLines;
35
+ }
36
+
37
+ return lines;
38
+ }
39
+
40
+ double SubspaceChat::getDisplayHeight() const
41
+ {
42
+ Uint lines = min(linesDisplayed_, countLines());
43
+
44
+ return (double)lines * font_.getFontHeight();
45
+ }
46
+
47
+ const TextureFont& SubspaceChat::getFont() const
48
+ {
49
+ return font_;
50
+ }
51
+
52
+ Uint SubspaceChat::getHeaderWidth() const
53
+ {
54
+ return headerWidth_;
55
+ }
56
+
57
+ Uint SubspaceChat::getLinesDisplayed() const
58
+ {
59
+ return linesDisplayed_;
60
+ }
61
+
62
+ Uint SubspaceChat::getLineWidth() const
63
+ {
64
+ return lineWidth_;
65
+ }
66
+
67
+ Uint SubspaceChat::size() const
68
+ {
69
+ return (Uint)messages_.size();
70
+ }
71
+
72
+
73
+ void SubspaceChat::setFont(const TextureFont& font)
74
+ {
75
+ font_ = font;
76
+ }
77
+
78
+ void SubspaceChat::setHeaderWidth(Uint width)
79
+ {
80
+ Uint w = min(width, lineWidth_ - headerSeparator_.size() - 1 - 1);
81
+ headerWidth_ = w;
82
+ }
83
+
84
+ void SubspaceChat::setLineWidth(Uint width)
85
+ {
86
+ lineWidth_ = width;
87
+ }
88
+
89
+ void SubspaceChat::setLinesDisplayed(Uint lines)
90
+ {
91
+ linesDisplayed_ = lines;
92
+ if(countLines() < linesDisplayed_)
93
+ {
94
+ linesDisplayOffset_ = 0;
95
+ }
96
+ }
97
+
98
+ void SubspaceChat::setLineOffset(Uint offset)
99
+ {
100
+ linesDisplayOffset_ = offset;
101
+ }
102
+
103
+ /*void SubspaceChat::setPlayers(const SubspacePlayerMap* map)
104
+ {
105
+ players_ = map;
106
+ }*/
107
+
108
+ void SubspaceChat::addMessage(const ChatMessage& m)
109
+ {
110
+ Uint size = countLines();
111
+ Uint newLines = countMessageLines(m);
112
+ if(size + newLines > linesDisplayed_) // if at the end of the buffer
113
+ linesDisplayOffset_ = size+newLines - linesDisplayed_; // scroll down
114
+
115
+ messages_.push_back(m);
116
+ }
117
+
118
+
119
+ void SubspaceChat::clear()
120
+ {
121
+ messages_.clear();
122
+ }
123
+
124
+ /*void SubspaceChat::doChat(Uint16 playerID, const string& message, Uint8 chatType, Uint8 soundByte)
125
+ {
126
+ string name = defaultName_;
127
+ SubspacePlayerMap::const_iterator i;
128
+ if(players_)
129
+ {
130
+ i = players_->find(playerID);
131
+ if(i != players_->end())
132
+ name = ((*i).second)->getName();
133
+ }
134
+
135
+ addMessage(ChatMessage(name, message, (ChatType)chatType, soundByte));
136
+ }*/
137
+
138
+ /*void SubspaceChat::doChatOutbound(Uint16 playerID, const string& message, Uint8 chatType, Uint8 soundByte)
139
+ {
140
+ doChat(playerID, message, chatType, soundByte);
141
+
142
+ SubspaceChatCommands::Chat cmd;
143
+ cmd.playerID = playerID;
144
+ cmd.message = message;
145
+ cmd.type = (ChatType)chatType;
146
+ cmd.soundByte = soundByte;
147
+
148
+ this->CommandGenerator<SubspaceChatCommandReceiver>::invokeCommand(&cmd);
149
+ }*/
150
+
151
+ void SubspaceChat::writeMessage(const string& sender, const string& text, ChatType chatType)
152
+ {
153
+ this->messages_.push_back(ChatMessage(sender, text, chatType));
154
+ }
155
+
156
+ void SubspaceChat::draw() const
157
+ {
158
+ Uint line = 0;
159
+ Uint msgLines = 0;
160
+ Uint msgNum = 0, msgLineOffset = 0;
161
+
162
+ if(messages_.size() == 0)
163
+ return;
164
+
165
+ findLine(linesDisplayOffset_, msgNum, msgLineOffset);
166
+
167
+ // display offset message
168
+ /*for(msgNum; line < linesDisplayed_ && msgNum < messages_.size(); ++msgNum)
169
+ {
170
+ msgLines = drawMessage(messages_[msgNum], msgLineOffset, linesDisplayed_);
171
+ glTranslated(0, -(double)font_.getFontHeight() * msgLines, 0);
172
+ line += msgLines;
173
+ }*/
174
+
175
+ // display offset message
176
+ msgLines = drawMessage(messages_[msgNum], msgLineOffset, linesDisplayed_);
177
+ //glTranslated(0, -(double)font_.getFontHeight() * msgLines, 0);
178
+ line += msgLines;
179
+ ++msgNum;
180
+
181
+ // display other messages
182
+ for(msgNum; line < linesDisplayed_ && msgNum < messages_.size(); ++msgNum)
183
+ {
184
+ msgLines = drawMessage(messages_[msgNum], 0, linesDisplayed_ - line);
185
+ //glTranslated(0, font_.getHeight() * msgLines, 0);
186
+ line += msgLines;
187
+ }
188
+ }
189
+
190
+ void SubspaceChat::update(double time)
191
+ {
192
+ }
193
+
194
+ Uint SubspaceChat::countMessageLines(const ChatMessage& msg) const
195
+ {
196
+ /*
197
+ <----------lineWidth-------->
198
+ Header Message
199
+ |-------|-------------------|
200
+ */
201
+
202
+ Uint messageWidth = lineWidth_ - headerWidth_;
203
+ return AsciiUtil::countWrapLines(msg.text, messageWidth);
204
+ }
205
+
206
+ void SubspaceChat::findLine(Uint lineNum, Uint& msgNum, Uint& msgLineOffset) const
207
+ {
208
+ Uint msgLines = 0;
209
+ Uint line = 0;
210
+
211
+ msgNum = 0;
212
+
213
+ msgLines = countMessageLines(messages_[msgNum]);
214
+ while(line + msgLines <= lineNum)
215
+ {
216
+ ++msgNum;
217
+ line += msgLines;
218
+ msgLines = countMessageLines(messages_[msgNum]);
219
+ }
220
+
221
+ //msgLineOffset = line+(msgLines-1) - lineNum;
222
+ msgLineOffset = lineNum - line;
223
+ }
224
+
225
+
226
+ Uint SubspaceChat::drawMessage(const ChatMessage& msg, Uint lineOffset, Uint maxMsgLines) const
227
+ {
228
+ assert(headerWidth_ >= headerSeparator_.size());
229
+
230
+ Uint senderWidth = headerWidth_ - headerSeparator_.size();
231
+ Uint messageWidth = lineWidth_ - headerWidth_;
232
+ vector<string> msgText = AsciiUtil::wordWrap(msg.text, messageWidth);
233
+ string headerString;
234
+ Uint linesDisplayed = 0;
235
+
236
+ if(msg.sender.size() == 0)
237
+ headerString = "";
238
+ else if(msg.sender.size() > senderWidth)
239
+ {
240
+ headerString = msg.sender.substr(0, senderWidth);
241
+ headerString += headerSeparator_;
242
+ }
243
+ else
244
+ {
245
+ headerString = AsciiUtil::fixedWidthString(msg.sender, senderWidth, AsciiUtil::rightJustified);
246
+ headerString += headerSeparator_;
247
+ }
248
+
249
+ vector<string>::iterator i;
250
+ for(i = msgText.begin() + lineOffset; i != msgText.end() && linesDisplayed < maxMsgLines; ++i)
251
+ {
252
+ glTranslated(0, -(double)font_.getFontHeight(), 0);
253
+
254
+ font_.displayString(headerString.c_str(), msg.getNameColor());
255
+ glTranslated(headerString.length() * font_.getFontWidth(), 0, 0);
256
+
257
+ font_.displayString((*i).c_str(), msg.getTextColor());
258
+ glTranslated(-(double)(headerString.length() * font_.getFontWidth()), 0, 0);
259
+
260
+ ++linesDisplayed;
261
+ }
262
+
263
+ return linesDisplayed;
264
+ }
pool/shard011/C++/0121638_chain.cpp ADDED
@@ -0,0 +1,198 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright (c) 2009-2010 Satoshi Nakamoto
2
+ // Copyright (c) 2009-2017 The Bitcoin Core developers
3
+ // Distributed under the MIT software license, see the accompanying
4
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
+
6
+ #include <chain.h>
7
+
8
+ #include "validation.h"
9
+
10
+ /* Moved here from the header, because we need auxpow and the logic
11
+ becomes more involved. */
12
+ CBlockHeader CBlockIndex::GetBlockHeader(const Consensus::Params& consensusParams) const
13
+ {
14
+ CBlockHeader block;
15
+
16
+ block.nVersion = nVersion;
17
+
18
+ /* The CBlockIndex object's block header is missing the auxpow.
19
+ So if this is an auxpow block, read it from disk instead. We only
20
+ have to read the actual *header*, not the full block. */
21
+ if (block.IsAuxpow())
22
+ {
23
+ ReadBlockHeaderFromDisk(block, this, consensusParams);
24
+ return block;
25
+ }
26
+
27
+ if (pprev)
28
+ block.hashPrevBlock = pprev->GetBlockHash();
29
+ block.hashMerkleRoot = hashMerkleRoot;
30
+ block.nTime = nTime;
31
+ block.nBits = nBits;
32
+ block.nNonce = nNonce;
33
+ return block;
34
+ }
35
+
36
+ /**
37
+ * CChain implementation
38
+ */
39
+ void CChain::SetTip(CBlockIndex *pindex) {
40
+ if (pindex == nullptr) {
41
+ vChain.clear();
42
+ return;
43
+ }
44
+ vChain.resize(pindex->nHeight + 1);
45
+ while (pindex && vChain[pindex->nHeight] != pindex) {
46
+ vChain[pindex->nHeight] = pindex;
47
+ pindex = pindex->pprev;
48
+ }
49
+ }
50
+
51
+ CBlockLocator CChain::GetLocator(const CBlockIndex *pindex) const {
52
+ int nStep = 1;
53
+ std::vector<uint256> vHave;
54
+ vHave.reserve(32);
55
+
56
+ if (!pindex)
57
+ pindex = Tip();
58
+ while (pindex) {
59
+ vHave.push_back(pindex->GetBlockHash());
60
+ // Stop when we have added the genesis block.
61
+ if (pindex->nHeight == 0)
62
+ break;
63
+ // Exponentially larger steps back, plus the genesis block.
64
+ int nHeight = std::max(pindex->nHeight - nStep, 0);
65
+ if (Contains(pindex)) {
66
+ // Use O(1) CChain index if possible.
67
+ pindex = (*this)[nHeight];
68
+ } else {
69
+ // Otherwise, use O(log n) skiplist.
70
+ pindex = pindex->GetAncestor(nHeight);
71
+ }
72
+ if (vHave.size() > 10)
73
+ nStep *= 2;
74
+ }
75
+
76
+ return CBlockLocator(vHave);
77
+ }
78
+
79
+ const CBlockIndex *CChain::FindFork(const CBlockIndex *pindex) const {
80
+ if (pindex == nullptr) {
81
+ return nullptr;
82
+ }
83
+ if (pindex->nHeight > Height())
84
+ pindex = pindex->GetAncestor(Height());
85
+ while (pindex && !Contains(pindex))
86
+ pindex = pindex->pprev;
87
+ return pindex;
88
+ }
89
+
90
+ CBlockIndex* CChain::FindEarliestAtLeast(int64_t nTime) const
91
+ {
92
+ std::vector<CBlockIndex*>::const_iterator lower = std::lower_bound(vChain.begin(), vChain.end(), nTime,
93
+ [](CBlockIndex* pBlock, const int64_t& time) -> bool { return pBlock->GetBlockTimeMax() < time; });
94
+ return (lower == vChain.end() ? nullptr : *lower);
95
+ }
96
+
97
+ /** Turn the lowest '1' bit in the binary representation of a number into a '0'. */
98
+ int static inline InvertLowestOne(int n) { return n & (n - 1); }
99
+
100
+ /** Compute what height to jump back to with the CBlockIndex::pskip pointer. */
101
+ int static inline GetSkipHeight(int height) {
102
+ if (height < 2)
103
+ return 0;
104
+
105
+ // Determine which height to jump back to. Any number strictly lower than height is acceptable,
106
+ // but the following expression seems to perform well in simulations (max 110 steps to go back
107
+ // up to 2**18 blocks).
108
+ return (height & 1) ? InvertLowestOne(InvertLowestOne(height - 1)) + 1 : InvertLowestOne(height);
109
+ }
110
+
111
+ const CBlockIndex* CBlockIndex::GetAncestor(int height) const
112
+ {
113
+ if (height > nHeight || height < 0) {
114
+ return nullptr;
115
+ }
116
+
117
+ const CBlockIndex* pindexWalk = this;
118
+ int heightWalk = nHeight;
119
+ while (heightWalk > height) {
120
+ int heightSkip = GetSkipHeight(heightWalk);
121
+ int heightSkipPrev = GetSkipHeight(heightWalk - 1);
122
+ if (pindexWalk->pskip != nullptr &&
123
+ (heightSkip == height ||
124
+ (heightSkip > height && !(heightSkipPrev < heightSkip - 2 &&
125
+ heightSkipPrev >= height)))) {
126
+ // Only follow pskip if pprev->pskip isn't better than pskip->pprev.
127
+ pindexWalk = pindexWalk->pskip;
128
+ heightWalk = heightSkip;
129
+ } else {
130
+ assert(pindexWalk->pprev);
131
+ pindexWalk = pindexWalk->pprev;
132
+ heightWalk--;
133
+ }
134
+ }
135
+ return pindexWalk;
136
+ }
137
+
138
+ CBlockIndex* CBlockIndex::GetAncestor(int height)
139
+ {
140
+ return const_cast<CBlockIndex*>(static_cast<const CBlockIndex*>(this)->GetAncestor(height));
141
+ }
142
+
143
+ void CBlockIndex::BuildSkip()
144
+ {
145
+ if (pprev)
146
+ pskip = pprev->GetAncestor(GetSkipHeight(nHeight));
147
+ }
148
+
149
+ arith_uint256 GetBlockProof(const CBlockIndex& block)
150
+ {
151
+ arith_uint256 bnTarget;
152
+ bool fNegative;
153
+ bool fOverflow;
154
+ bnTarget.SetCompact(block.nBits, &fNegative, &fOverflow);
155
+ if (fNegative || fOverflow || bnTarget == 0)
156
+ return 0;
157
+ // We need to compute 2**256 / (bnTarget+1), but we can't represent 2**256
158
+ // as it's too large for an arith_uint256. However, as 2**256 is at least as large
159
+ // as bnTarget+1, it is equal to ((2**256 - bnTarget - 1) / (bnTarget+1)) + 1,
160
+ // or ~bnTarget / (bnTarget+1) + 1.
161
+ return (~bnTarget / (bnTarget + 1)) + 1;
162
+ }
163
+
164
+ int64_t GetBlockProofEquivalentTime(const CBlockIndex& to, const CBlockIndex& from, const CBlockIndex& tip, const Consensus::Params& params)
165
+ {
166
+ arith_uint256 r;
167
+ int sign = 1;
168
+ if (to.nChainWork > from.nChainWork) {
169
+ r = to.nChainWork - from.nChainWork;
170
+ } else {
171
+ r = from.nChainWork - to.nChainWork;
172
+ sign = -1;
173
+ }
174
+ r = r * arith_uint256(params.nPowTargetSpacing) / GetBlockProof(tip);
175
+ if (r.bits() > 63) {
176
+ return sign * std::numeric_limits<int64_t>::max();
177
+ }
178
+ return sign * r.GetLow64();
179
+ }
180
+
181
+ /** Find the last common ancestor two blocks have.
182
+ * Both pa and pb must be non-nullptr. */
183
+ const CBlockIndex* LastCommonAncestor(const CBlockIndex* pa, const CBlockIndex* pb) {
184
+ if (pa->nHeight > pb->nHeight) {
185
+ pa = pa->GetAncestor(pb->nHeight);
186
+ } else if (pb->nHeight > pa->nHeight) {
187
+ pb = pb->GetAncestor(pa->nHeight);
188
+ }
189
+
190
+ while (pa != pb && pa && pb) {
191
+ pa = pa->pprev;
192
+ pb = pb->pprev;
193
+ }
194
+
195
+ // Eventually all chain branches meet at the genesis block.
196
+ assert(pa == pb);
197
+ return pa;
198
+ }
pool/shard011/C++/0121639_zip_reader_ctocpp.cc ADDED
@@ -0,0 +1,220 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright (c) 2014 The Chromium Embedded Framework Authors. All rights
2
+ // reserved. Use of this source code is governed by a BSD-style license that
3
+ // can be found in the LICENSE file.
4
+ //
5
+ // ---------------------------------------------------------------------------
6
+ //
7
+ // This file was generated by the CEF translator tool. If making changes by
8
+ // hand only do so within the body of existing method and function
9
+ // implementations. See the translator.README.txt file in the tools directory
10
+ // for more information.
11
+ //
12
+
13
+ #include "libcef_dll/ctocpp/stream_reader_ctocpp.h"
14
+ #include "libcef_dll/ctocpp/zip_reader_ctocpp.h"
15
+
16
+
17
+ // STATIC METHODS - Body may be edited by hand.
18
+
19
+ CefRefPtr<CefZipReader> CefZipReader::Create(
20
+ CefRefPtr<CefStreamReader> stream) {
21
+ // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
22
+
23
+ // Verify param: stream; type: refptr_same
24
+ DCHECK(stream.get());
25
+ if (!stream.get())
26
+ return NULL;
27
+
28
+ // Execute
29
+ cef_zip_reader_t* _retval = cef_zip_reader_create(
30
+ CefStreamReaderCToCpp::Unwrap(stream));
31
+
32
+ // Return type: refptr_same
33
+ return CefZipReaderCToCpp::Wrap(_retval);
34
+ }
35
+
36
+
37
+ // VIRTUAL METHODS - Body may be edited by hand.
38
+
39
+ bool CefZipReaderCToCpp::MoveToFirstFile() {
40
+ if (CEF_MEMBER_MISSING(struct_, move_to_first_file))
41
+ return false;
42
+
43
+ // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
44
+
45
+ // Execute
46
+ int _retval = struct_->move_to_first_file(struct_);
47
+
48
+ // Return type: bool
49
+ return _retval?true:false;
50
+ }
51
+
52
+ bool CefZipReaderCToCpp::MoveToNextFile() {
53
+ if (CEF_MEMBER_MISSING(struct_, move_to_next_file))
54
+ return false;
55
+
56
+ // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
57
+
58
+ // Execute
59
+ int _retval = struct_->move_to_next_file(struct_);
60
+
61
+ // Return type: bool
62
+ return _retval?true:false;
63
+ }
64
+
65
+ bool CefZipReaderCToCpp::MoveToFile(const CefString& fileName,
66
+ bool caseSensitive) {
67
+ if (CEF_MEMBER_MISSING(struct_, move_to_file))
68
+ return false;
69
+
70
+ // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
71
+
72
+ // Verify param: fileName; type: string_byref_const
73
+ DCHECK(!fileName.empty());
74
+ if (fileName.empty())
75
+ return false;
76
+
77
+ // Execute
78
+ int _retval = struct_->move_to_file(struct_,
79
+ fileName.GetStruct(),
80
+ caseSensitive);
81
+
82
+ // Return type: bool
83
+ return _retval?true:false;
84
+ }
85
+
86
+ bool CefZipReaderCToCpp::Close() {
87
+ if (CEF_MEMBER_MISSING(struct_, close))
88
+ return false;
89
+
90
+ // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
91
+
92
+ // Execute
93
+ int _retval = struct_->close(struct_);
94
+
95
+ // Return type: bool
96
+ return _retval?true:false;
97
+ }
98
+
99
+ CefString CefZipReaderCToCpp::GetFileName() {
100
+ if (CEF_MEMBER_MISSING(struct_, get_file_name))
101
+ return CefString();
102
+
103
+ // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
104
+
105
+ // Execute
106
+ cef_string_userfree_t _retval = struct_->get_file_name(struct_);
107
+
108
+ // Return type: string
109
+ CefString _retvalStr;
110
+ _retvalStr.AttachToUserFree(_retval);
111
+ return _retvalStr;
112
+ }
113
+
114
+ int64 CefZipReaderCToCpp::GetFileSize() {
115
+ if (CEF_MEMBER_MISSING(struct_, get_file_size))
116
+ return 0;
117
+
118
+ // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
119
+
120
+ // Execute
121
+ int64 _retval = struct_->get_file_size(struct_);
122
+
123
+ // Return type: simple
124
+ return _retval;
125
+ }
126
+
127
+ time_t CefZipReaderCToCpp::GetFileLastModified() {
128
+ if (CEF_MEMBER_MISSING(struct_, get_file_last_modified))
129
+ return 0;
130
+
131
+ // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
132
+
133
+ // Execute
134
+ time_t _retval = struct_->get_file_last_modified(struct_);
135
+
136
+ // Return type: simple
137
+ return _retval;
138
+ }
139
+
140
+ bool CefZipReaderCToCpp::OpenFile(const CefString& password) {
141
+ if (CEF_MEMBER_MISSING(struct_, open_file))
142
+ return false;
143
+
144
+ // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
145
+
146
+ // Unverified params: password
147
+
148
+ // Execute
149
+ int _retval = struct_->open_file(struct_,
150
+ password.GetStruct());
151
+
152
+ // Return type: bool
153
+ return _retval?true:false;
154
+ }
155
+
156
+ bool CefZipReaderCToCpp::CloseFile() {
157
+ if (CEF_MEMBER_MISSING(struct_, close_file))
158
+ return false;
159
+
160
+ // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
161
+
162
+ // Execute
163
+ int _retval = struct_->close_file(struct_);
164
+
165
+ // Return type: bool
166
+ return _retval?true:false;
167
+ }
168
+
169
+ int CefZipReaderCToCpp::ReadFile(void* buffer, size_t bufferSize) {
170
+ if (CEF_MEMBER_MISSING(struct_, read_file))
171
+ return 0;
172
+
173
+ // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
174
+
175
+ // Verify param: buffer; type: simple_byaddr
176
+ DCHECK(buffer);
177
+ if (!buffer)
178
+ return 0;
179
+
180
+ // Execute
181
+ int _retval = struct_->read_file(struct_,
182
+ buffer,
183
+ bufferSize);
184
+
185
+ // Return type: simple
186
+ return _retval;
187
+ }
188
+
189
+ int64 CefZipReaderCToCpp::Tell() {
190
+ if (CEF_MEMBER_MISSING(struct_, tell))
191
+ return 0;
192
+
193
+ // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
194
+
195
+ // Execute
196
+ int64 _retval = struct_->tell(struct_);
197
+
198
+ // Return type: simple
199
+ return _retval;
200
+ }
201
+
202
+ bool CefZipReaderCToCpp::Eof() {
203
+ if (CEF_MEMBER_MISSING(struct_, eof))
204
+ return false;
205
+
206
+ // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
207
+
208
+ // Execute
209
+ int _retval = struct_->eof(struct_);
210
+
211
+ // Return type: bool
212
+ return _retval?true:false;
213
+ }
214
+
215
+
216
+ #ifndef NDEBUG
217
+ template<> long CefCToCpp<CefZipReaderCToCpp, CefZipReader,
218
+ cef_zip_reader_t>::DebugObjCt = 0;
219
+ #endif
220
+
pool/shard011/C++/0121641_PrimitiveTypeDeclaration.cpp ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <pddl/detail/parsing/PrimitiveTypeDeclaration.h>
2
+
3
+ #include <pddl/Exception.h>
4
+ #include <pddl/detail/ASTCopy.h>
5
+ #include <pddl/detail/parsing/PrimitiveType.h>
6
+
7
+ namespace pddl
8
+ {
9
+ namespace detail
10
+ {
11
+
12
+ ////////////////////////////////////////////////////////////////////////////////////////////////////
13
+ //
14
+ // PrimitiveTypeDeclaration
15
+ //
16
+ ////////////////////////////////////////////////////////////////////////////////////////////////////
17
+
18
+ std::experimental::optional<ast::PrimitiveTypeDeclarationPointer *> findPrimitiveTypeDeclaration(ast::Domain &domain, const std::string &typeName)
19
+ {
20
+ auto &types = domain.types;
21
+
22
+ const auto matchingPrimitiveType = std::find_if(types.begin(), types.end(),
23
+ [&](const auto &primitiveType)
24
+ {
25
+ return primitiveType->name == typeName;
26
+ });
27
+
28
+ if (matchingPrimitiveType != types.end())
29
+ return &*matchingPrimitiveType;
30
+
31
+ return std::experimental::nullopt;
32
+ }
33
+
34
+ ////////////////////////////////////////////////////////////////////////////////////////////////////
35
+
36
+ ast::PrimitiveTypeDeclarationPointer &parseAndAddUntypedPrimitiveTypeDeclaration(Context &context, ast::Domain &domain, std::vector<bool> &flaggedTypes)
37
+ {
38
+ auto &tokenizer = context.tokenizer;
39
+ auto typeName = tokenizer.getIdentifier();
40
+
41
+ auto &types = domain.types;
42
+
43
+ auto matchingPrimitiveTypeDeclaration = findPrimitiveTypeDeclaration(domain, typeName);
44
+
45
+ if (matchingPrimitiveTypeDeclaration)
46
+ return *matchingPrimitiveTypeDeclaration.value();
47
+
48
+ types.emplace_back(std::make_unique<ast::PrimitiveTypeDeclaration>(std::move(typeName)));
49
+ flaggedTypes.emplace_back(false);
50
+
51
+ return types.back();
52
+ }
53
+
54
+ ////////////////////////////////////////////////////////////////////////////////////////////////////
55
+
56
+ void parseAndAddPrimitiveTypeDeclarations(Context &context, ast::Domain &domain)
57
+ {
58
+ auto &tokenizer = context.tokenizer;
59
+ tokenizer.skipWhiteSpace();
60
+
61
+ auto &types = domain.types;
62
+ assert(types.empty());
63
+
64
+ std::vector<bool> flaggedTypes;
65
+
66
+ while (tokenizer.currentCharacter() != ')')
67
+ {
68
+ auto &childType = parseAndAddUntypedPrimitiveTypeDeclaration(context, domain, flaggedTypes);
69
+ flaggedTypes[&childType - &types.front()] = true;
70
+
71
+ tokenizer.skipWhiteSpace();
72
+
73
+ if (!tokenizer.testAndSkip<char>('-'))
74
+ continue;
75
+
76
+ // Skip parent type information for now
77
+ auto &parentType = parseAndAddUntypedPrimitiveTypeDeclaration(context, domain, flaggedTypes);
78
+
79
+ for (size_t i = 0; i < flaggedTypes.size(); i++)
80
+ if (flaggedTypes[i])
81
+ {
82
+ flaggedTypes[i] = false;
83
+ types[i]->parentTypes.emplace_back(std::make_unique<ast::PrimitiveType>(parentType.get()));
84
+ }
85
+
86
+ tokenizer.skipWhiteSpace();
87
+ }
88
+ }
89
+
90
+ ////////////////////////////////////////////////////////////////////////////////////////////////////
91
+
92
+ }
93
+ }
pool/shard011/C++/0121642_MicroBenchmarksQ31.cpp ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include "MicroBenchmarksQ31.h"
2
+ #include "Error.h"
3
+
4
+ static void add_while_q31(
5
+ const q31_t * pSrcA,
6
+ const q31_t * pSrcB,
7
+ q31_t * pDst,
8
+ uint32_t blockSize)
9
+ {
10
+ uint32_t blkCnt;
11
+
12
+ blkCnt = blockSize;
13
+
14
+ while (blkCnt > 0U)
15
+ {
16
+ /* C = A + B */
17
+
18
+ /* Add and store result in destination buffer. */
19
+ *pDst++ = (*pSrcA++) + (*pSrcB++);
20
+
21
+ /* Decrement loop counter */
22
+ blkCnt--;
23
+ }
24
+ }
25
+
26
+ static void add_for_q31(
27
+ const q31_t * pSrcA,
28
+ const q31_t * pSrcB,
29
+ q31_t * pDst,
30
+ uint32_t blockSize)
31
+ {
32
+ uint32_t blkCnt;
33
+ int32_t i;
34
+
35
+ blkCnt = blockSize;
36
+
37
+ for(i=0; i<blkCnt; i++)
38
+ {
39
+ /* C = A + B */
40
+
41
+ /* Add and store result in destination buffer. */
42
+ *pDst++ = (*pSrcA++) + (*pSrcB++);
43
+
44
+ }
45
+ }
46
+
47
+ static void add_array_q31(
48
+ const q31_t * pSrcA,
49
+ const q31_t * pSrcB,
50
+ q31_t * pDst,
51
+ uint32_t blockSize)
52
+ {
53
+ uint32_t blkCnt;
54
+ int32_t i;
55
+
56
+ blkCnt = blockSize;
57
+
58
+ for(i=0; i<blkCnt; i++)
59
+ {
60
+ /* C = A + B */
61
+
62
+ /* Add and store result in destination buffer. */
63
+ pDst[i] = pSrcA[i] + pSrcB[i];
64
+
65
+ }
66
+ }
67
+
68
+ void MicroBenchmarksQ31::test_while_q31()
69
+ {
70
+ add_while_q31(this->inp1,this->inp2,this->outp,this->nbSamples);
71
+ }
72
+
73
+ void MicroBenchmarksQ31::test_for_q31()
74
+ {
75
+ add_for_q31(this->inp1,this->inp2,this->outp,this->nbSamples);
76
+ }
77
+
78
+ void MicroBenchmarksQ31::test_array_q31()
79
+ {
80
+ add_array_q31(this->inp1,this->inp2,this->outp,this->nbSamples);
81
+ }
82
+
83
+
84
+ void MicroBenchmarksQ31::setUp(Testing::testID_t id,std::vector<Testing::param_t>& params,Client::PatternMgr *mgr)
85
+ {
86
+
87
+
88
+ std::vector<Testing::param_t>::iterator it = params.begin();
89
+ this->nbSamples = *it;
90
+
91
+ input1.reload(MicroBenchmarksQ31::INPUT1_Q31_ID,mgr,this->nbSamples);
92
+ input2.reload(MicroBenchmarksQ31::INPUT2_Q31_ID,mgr,this->nbSamples);
93
+
94
+
95
+ output.create(this->nbSamples,MicroBenchmarksQ31::OUT_SAMPLES_Q31_ID,mgr);
96
+
97
+ this->inp1=input1.ptr();
98
+ this->inp2=input2.ptr();
99
+ this->outp=output.ptr();
100
+
101
+ }
102
+
103
+ void MicroBenchmarksQ31::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
104
+ {
105
+ }
pool/shard011/C++/0121643_FirstPass.cpp ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include "llvm/Pass.h"
2
+ #include "llvm/IR/Function.h"
3
+ #include "llvm/Support/raw_ostream.h"
4
+
5
+ using namespace llvm;
6
+
7
+ namespace {
8
+ struct FirstPass : public FunctionPass {
9
+ static char ID;
10
+ FirstPass() : FunctionPass(ID) {}
11
+
12
+ bool runOnFunction(Function &F) override {
13
+ errs() << "Function recognized: ";
14
+ errs().write_escaped(F.getName());
15
+ errs() << '\n';
16
+ return false;
17
+ }
18
+ };
19
+ }
20
+
21
+ char FirstPass::ID = 0;
22
+ static RegisterPass<FirstPass> X("FirstPass", "Function printer pass", false, false);
pool/shard011/C++/0121645_addatodialog_funcs.cpp ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include "addatodialog.h"
2
+ #include "epsrproject.h"
3
+
4
+ #include <QPushButton>
5
+
6
+ AddAtoDialog::AddAtoDialog(MainWindow *parent) : QDialog(parent)
7
+ {
8
+ ui.setupUi(this);
9
+
10
+ mainWindow_ = parent;
11
+
12
+ ui.atoComboBox->clear();
13
+ ui.atoTable->clearContents();
14
+
15
+ QStringList atoFileList = mainWindow_->listAtoFiles();
16
+ QString boxAtoFileName = mainWindow_->atoFileName();
17
+
18
+ for (int i = 0; i < atoFileList.count(); i++)
19
+ {
20
+ ui.atoComboBox->addItem(atoFileList.at(i));
21
+ ui.atoList->addItem(atoFileList.at(i));
22
+ }
23
+ if (!boxAtoFileName.isEmpty())
24
+ {
25
+ ui.atoComboBox->addItem(boxAtoFileName);
26
+ }
27
+
28
+ ui.atoTable->setSelectionBehavior(QAbstractItemView::SelectRows);
29
+ ui.atoTable->setSelectionMode(QAbstractItemView::SingleSelection);
30
+
31
+ connect(ui.okButton, SIGNAL(clicked()), this, SLOT(checkEntries()));
32
+ connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
33
+ }
34
+
35
+ void AddAtoDialog::on_okButton_clicked(bool checked)
36
+ {
37
+
38
+ }
39
+
40
+ void AddAtoDialog::on_cancelButton_clicked(bool checked)
41
+ {
42
+
43
+ }
44
+
45
+ void AddAtoDialog::checkEntries()
46
+ {
47
+ QList<QTableWidgetItem*> twi = ui.atoTable->findItems("0", Qt::MatchExactly);
48
+ if (ui.atoTable->rowCount() < 1 || twi.isEmpty() == false)
49
+ {
50
+ QMessageBox::warning(this, tr("No .ato files to add"),
51
+ tr("Add ato files to the right hand table and input the number of these molecules to add."));
52
+ }
53
+ else
54
+ {
55
+ accept();
56
+ }
57
+ }
58
+
59
+ void AddAtoDialog::on_addAtoButton_clicked(bool checked)
60
+ {
61
+ if (ui.atoList->currentRow() == -1)
62
+ {
63
+ return;
64
+ }
65
+
66
+ QString atoFileName = ui.atoList->currentItem()->text();
67
+ int lastAtoFile = ui.atoTable->rowCount();
68
+ ui.atoTable->setRowCount(lastAtoFile+1);
69
+ QTableWidgetItem *item = new QTableWidgetItem(atoFileName);
70
+ item->setFlags(item->flags() & ~Qt::ItemIsEditable);
71
+ ui.atoTable->setItem(lastAtoFile,0, item);
72
+ ui.atoTable->setItem(lastAtoFile,1, new QTableWidgetItem("0"));
73
+ }
74
+
75
+ void AddAtoDialog::on_removeAtoButton_clicked(bool checked)
76
+ {
77
+ if (ui.atoTable->rowCount() != 0)
78
+ {
79
+ int row = ui.atoTable->currentRow();
80
+ ui.atoTable->removeRow(row);
81
+ }
82
+ }
83
+
84
+ QString AddAtoDialog::getContainer()
85
+ {
86
+ return ui.atoComboBox->currentText();
87
+ }
88
+
89
+ QStringList AddAtoDialog::getAtoFiles()
90
+ {
91
+ QStringList selectedAtoFiles;
92
+
93
+ for (int i = 0; i < ui.atoTable->rowCount(); i++)
94
+ {
95
+ selectedAtoFiles.append(ui.atoTable->item(i,0)->text());
96
+ }
97
+ return selectedAtoFiles;
98
+ }
99
+
100
+ QStringList AddAtoDialog::getNumberMols()
101
+ {
102
+ QStringList numberMols;
103
+
104
+ for (int i = 0; i < ui.atoTable->rowCount(); i++)
105
+ {
106
+ numberMols.append(ui.atoTable->item(i,1)->text());
107
+ }
108
+ return numberMols;
109
+ }
pool/shard011/C++/0121646_dlguser.cpp ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------------------
2
+ // Name: DlgUser.cpp
3
+ // Purpose: Dialog mit Variable Gestaltung durch DlgUser.wxr
4
+ // Author: Mark Johnson
5
+ // Modified by: 19991105.mj10777
6
+ // Created: 19991105
7
+ // Copyright: (c) Mark Johnson
8
+ // Licence: wxWindows license
9
+ // RCS-ID: $Id: dlguser.cpp 44499 2007-02-13 23:22:24Z VZ $
10
+ //----------------------------------------------------------------------------------------
11
+
12
+ // For compilers that support precompilation, includes "wx/wx.h".
13
+ #include "wx/wxprec.h"
14
+ //----------------------------------------------------------------------------------------
15
+ #ifdef __BORLANDC__
16
+ #pragma hdrstop
17
+ #endif
18
+ //----------------------------------------------------------------------------------------
19
+ #ifndef WX_PRECOMP
20
+ #include "wx/wx.h"
21
+ #endif
22
+
23
+
24
+ //----------------------------------------------------------------------------------------
25
+ //-- all #includes that every .cpp needs ----19990807.mj10777 ----------------
26
+ //----------------------------------------------------------------------------------------
27
+ #include "std.h"
28
+
29
+ //----------------------------------------------------------------------------------------
30
+ DlgUser::DlgUser(wxWindow *parent, MainDoc *p_Doc, const wxString& title) :
31
+ wxDialog(parent, ID_DIALOG_DSN, title)
32
+ {
33
+ int chSize; // Height of Font * 1.4 = Height of wxTextCtrl
34
+
35
+ float ratio = (float)1.4;
36
+ #ifdef __WXMOTIF__
37
+ ratio = (float)2.1;
38
+ #endif
39
+
40
+ SetBackgroundColour(_T("wheat"));
41
+ pDoc = p_Doc;
42
+ wxLayoutConstraints* layout;
43
+ SetAutoLayout(true);
44
+
45
+ m_Label1 = new wxStaticText(this, wxID_ANY, _("User ID:"));
46
+ m_Label1->SetFont(* pDoc->ft_Doc);
47
+ layout = new wxLayoutConstraints;
48
+ layout->left.SameAs(this, wxLeft, 10);
49
+ layout->top.SameAs(this, wxTop, 10);
50
+ layout->height.AsIs();
51
+ layout->width.Absolute(75);
52
+ m_Label1->SetConstraints(layout);
53
+
54
+ int w;
55
+ m_Label1->GetSize(&w, &chSize);
56
+
57
+ m_UserName = new wxTextCtrl(this, wxID_ANY, wxEmptyString);
58
+ m_UserName->SetFont(* pDoc->ft_Doc);
59
+ chSize = (int) (m_UserName->GetCharHeight()*ratio);
60
+
61
+ layout = new wxLayoutConstraints;
62
+ layout->left.SameAs(m_Label1, wxRight, 10);
63
+ layout->centreY.SameAs(m_Label1,wxCentreY);
64
+ layout->width.Absolute(200);
65
+ layout->height.Absolute(chSize);
66
+ // layout->height.AsIs();
67
+ m_UserName->SetConstraints(layout);
68
+
69
+
70
+ m_Label2 = new wxStaticText(this, wxID_ANY, _("Password:"));
71
+ m_Label2->SetFont(* pDoc->ft_Doc);
72
+ layout = new wxLayoutConstraints;
73
+ layout->left.SameAs(m_Label1, wxLeft);
74
+ layout->top.SameAs(m_Label1, wxBottom, 10);
75
+ layout->height.AsIs();
76
+ layout->width.SameAs(m_Label1, wxWidth);
77
+ m_Label2->SetConstraints(layout);
78
+
79
+ m_Password = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PASSWORD);
80
+ m_Password->SetFont(* pDoc->ft_Doc);
81
+ layout = new wxLayoutConstraints;
82
+ layout->left.SameAs(m_UserName, wxLeft);
83
+ layout->width.SameAs(m_UserName, wxWidth);
84
+ layout->centreY.SameAs(m_Label2,wxCentreY);
85
+ layout->height.Absolute(chSize);
86
+ //layout->height.AsIs();
87
+ m_Password->SetConstraints(layout);
88
+
89
+ m_OK = new wxButton(this, wxID_OK);
90
+ m_OK->SetFont(* pDoc->ft_Doc);
91
+ layout = new wxLayoutConstraints;
92
+ layout->left.SameAs(this, wxLeft, 10);
93
+ layout->top.SameAs(m_Label2, wxBottom,10);
94
+ layout->height.AsIs();
95
+ layout->width.Absolute(75);
96
+ m_OK->SetConstraints(layout);
97
+
98
+ m_Cancel = new wxButton(this, wxID_CANCEL);
99
+ m_Cancel->SetFont(* pDoc->ft_Doc);
100
+ layout = new wxLayoutConstraints;
101
+ layout->left.SameAs(m_OK, wxRight, 10);
102
+ layout->top.SameAs(m_OK, wxTop);
103
+ layout->height.AsIs();
104
+ layout->width.SameAs(m_OK, wxWidth);
105
+ m_Cancel->SetConstraints(layout);
106
+
107
+ m_OK->SetDefault();
108
+ m_UserName->SetFocus();
109
+
110
+ s_User = wxEmptyString;
111
+ s_Password = wxEmptyString;
112
+ Layout();
113
+ }
114
+
115
+ //----------------------------------------------------------------------------------------
116
+ void DlgUser::OnInit()
117
+ {
118
+ wxString Temp; Temp.Printf(_T(">>> %s <<<"),s_DSN.c_str());
119
+ SetTitle(Temp);
120
+ m_UserName->SetLabel(s_User);
121
+ m_Password->SetLabel(s_Password);
122
+ }
123
+
124
+ //----------------------------------------------------------------------------------------
125
+ BEGIN_EVENT_TABLE(DlgUser, wxDialog)
126
+ EVT_BUTTON(wxID_OK, DlgUser::OnOk)
127
+ END_EVENT_TABLE()
128
+
129
+ //----------------------------------------------------------------------------------------
130
+ void DlgUser::OnOk(wxCommandEvent& WXUNUSED(event) )
131
+ {
132
+ s_User = m_UserName->GetValue();
133
+ s_Password = m_Password->GetValue();
134
+ EndModal(wxID_OK);
135
+ }
136
+
pool/shard011/C++/0121647_renumber_component_wise_01.cc ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // ---------------------------------------------------------------------
2
+ //
3
+ // Copyright (C) 2005 - 2017 by the deal.II authors
4
+ //
5
+ // This file is part of the deal.II library.
6
+ //
7
+ // The deal.II library is free software; you can use it, redistribute
8
+ // it, and/or modify it under the terms of the GNU Lesser General
9
+ // Public License as published by the Free Software Foundation; either
10
+ // version 2.1 of the License, or (at your option) any later version.
11
+ // The full text of the license can be found in the file LICENSE at
12
+ // the top level of the deal.II distribution.
13
+ //
14
+ // ---------------------------------------------------------------------
15
+
16
+
17
+
18
+ // test DoFRenumbering::component_wise for codim=1
19
+
20
+ #include "../tests.h"
21
+ #include <deal.II/base/function_lib.h>
22
+ #include <deal.II/grid/tria.h>
23
+ #include <deal.II/grid/grid_in.h>
24
+ #include <deal.II/dofs/dof_handler.h>
25
+ #include <deal.II/dofs/dof_accessor.h>
26
+ #include <deal.II/fe/fe_q.h>
27
+ #include <deal.II/fe/fe_system.h>
28
+ #include <deal.II/dofs/dof_renumbering.h>
29
+
30
+ #include <string>
31
+
32
+ std::ofstream logfile("output");
33
+
34
+ template <int dim, int spacedim>
35
+ void test(std::string filename)
36
+ {
37
+ Triangulation<dim, spacedim> tria;
38
+ GridIn<dim, spacedim> gi;
39
+ gi.attach_triangulation (tria);
40
+ std::ifstream in (filename.c_str());
41
+ gi.read_ucd (in);
42
+
43
+ deallog << tria.n_active_cells() << " active cells" << std::endl;
44
+
45
+ FESystem<dim,spacedim> fe(FE_Q<dim,spacedim> (2), spacedim);
46
+ DoFHandler<dim,spacedim> dof_handler (tria);
47
+ dof_handler.distribute_dofs (fe);
48
+
49
+ deallog << dof_handler.n_dofs() << " degrees of freedom" << std::endl;
50
+ DoFRenumbering::component_wise (dof_handler);
51
+
52
+ for (typename DoFHandler<dim,spacedim>::active_cell_iterator
53
+ cell = dof_handler.begin_active(); cell!=dof_handler.end(); ++cell)
54
+ {
55
+ std::vector<types::global_dof_index> x (cell->get_fe().dofs_per_cell);
56
+ cell->get_dof_indices (x);
57
+
58
+ deallog << cell << std::endl;
59
+ for (unsigned int i=0; i<x.size(); ++i)
60
+ deallog << " " << x[i] << std::endl;
61
+ }
62
+ }
63
+
64
+
65
+
66
+ int main ()
67
+ {
68
+ deallog.attach(logfile);
69
+
70
+ test<2,3>(SOURCE_DIR "/grids/square.inp");
71
+ test<2,3>(SOURCE_DIR "/grids/sphere_1.inp");
72
+
73
+ return 0;
74
+ }
75
+
pool/shard011/C++/0121648_help_app_launcher.cc ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright (c) 2012 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 "chrome/browser/chromeos/login/help_app_launcher.h"
6
+
7
+ #include <string>
8
+
9
+ #include "base/strings/stringprintf.h"
10
+ #include "base/strings/utf_string_conversions.h"
11
+ #include "chrome/browser/chromeos/login/ui/login_web_dialog.h"
12
+ #include "chrome/browser/chromeos/profiles/profile_helper.h"
13
+ #include "chrome/browser/profiles/profile.h"
14
+ #include "chrome/grit/generated_resources.h"
15
+ #include "chrome/grit/locale_settings.h"
16
+ #include "content/public/browser/browser_thread.h"
17
+ #include "extensions/browser/extension_registry.h"
18
+ #include "ui/base/l10n/l10n_util.h"
19
+ #include "ui/gfx/geometry/rect.h"
20
+ #include "ui/gfx/geometry/size.h"
21
+ #include "url/gurl.h"
22
+
23
+ using content::BrowserThread;
24
+ using extensions::ExtensionRegistry;
25
+
26
+ namespace {
27
+
28
+ // Official HelpApp extension id.
29
+ const char kExtensionId[] = "honijodknafkokifofgiaalefdiedpko";
30
+
31
+ const char kHelpAppFormat[] = "chrome-extension://%s/oobe.html?id=%d";
32
+
33
+ const char* g_extension_id_for_test = nullptr;
34
+
35
+ } // namespace
36
+
37
+ namespace chromeos {
38
+
39
+ ///////////////////////////////////////////////////////////////////////////////
40
+ // HelpApp, public:
41
+
42
+ HelpAppLauncher::HelpAppLauncher(gfx::NativeWindow parent_window)
43
+ : parent_window_(parent_window) {}
44
+
45
+ void HelpAppLauncher::ShowHelpTopic(HelpTopic help_topic_id) {
46
+ Profile* profile = ProfileHelper::GetSigninProfile();
47
+ ExtensionRegistry* registry = ExtensionRegistry::Get(profile);
48
+
49
+ DCHECK(registry);
50
+ if (!registry)
51
+ return;
52
+
53
+ const char* extension_id = kExtensionId;
54
+ if (g_extension_id_for_test && *g_extension_id_for_test != '\0') {
55
+ extension_id = g_extension_id_for_test;
56
+ }
57
+
58
+ GURL url(base::StringPrintf(kHelpAppFormat, extension_id,
59
+ static_cast<int>(help_topic_id)));
60
+ // HelpApp component extension presents only in official builds so we can
61
+ // show help only when the extensions is installed.
62
+ if (registry->enabled_extensions().GetByID(url.host()))
63
+ ShowHelpTopicDialog(profile, GURL(url));
64
+ }
65
+
66
+ // static
67
+ void HelpAppLauncher::SetExtensionIdForTest(const char* extension_id) {
68
+ g_extension_id_for_test = extension_id;
69
+ }
70
+
71
+ ///////////////////////////////////////////////////////////////////////////////
72
+ // HelpApp, protected:
73
+
74
+ HelpAppLauncher::~HelpAppLauncher() {}
75
+
76
+ ///////////////////////////////////////////////////////////////////////////////
77
+ // HelpApp, private:
78
+
79
+ void HelpAppLauncher::ShowHelpTopicDialog(Profile* profile,
80
+ const GURL& topic_url) {
81
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
82
+ LoginWebDialog* dialog = new LoginWebDialog(
83
+ profile, NULL, parent_window_,
84
+ l10n_util::GetStringUTF16(IDS_LOGIN_OOBE_HELP_DIALOG_TITLE), topic_url);
85
+ dialog->Show();
86
+ // The dialog object will be deleted on dialog close.
87
+ }
88
+
89
+ } // namespace chromeos
pool/shard011/C++/0121650_FourierTransformationTest.cpp ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // ************************************************************************** //
2
+ //
3
+ // BornAgain: simulate and fit scattering at grazing incidence
4
+ //
5
+ //! @file Tests/Functional/Core/CoreSpecial/FourierTransformationTest.cpp
6
+ //! @brief Implements FourierTransformationTest class.
7
+ //!
8
+ //! @homepage http://www.bornagainproject.org
9
+ //! @license GNU General Public License v3 or higher (see COPYING)
10
+ //! @copyright Forschungszentrum Jülich GmbH 2018
11
+ //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12
+ //
13
+ // ************************************************************************** //
14
+
15
+ #include "FourierTransformationTest.h"
16
+ #include "FileSystemUtils.h"
17
+ #include "IntensityDataFunctions.h"
18
+ #include "IntensityDataIOFactory.h"
19
+ #include "OutputData.h"
20
+ #include "TestUtils.h"
21
+ #include "BATesting.h"
22
+ #include <iostream>
23
+ #include <memory>
24
+ #include <vector>
25
+
26
+ namespace
27
+ {
28
+
29
+ const double threshold = 1e-10;
30
+
31
+ //! Returns file names to test fft.
32
+ std::vector<std::string> inputImages() {
33
+ return {"CylindersAndPrisms.int.gz", "RectDetectorGeneric.int.gz"};
34
+ }
35
+
36
+ //! Returns location of images to test fft.
37
+ std::string inputImageDir();
38
+
39
+ //! Returns file names with paths to test fft.
40
+ std::vector<std::string> inputImageNames();
41
+
42
+ //! Returns name of directory with fft images for reference.
43
+ std::string fftReferenceDir();
44
+
45
+ //! Returns name of fft image based on given image name.
46
+ std::string fftReferenceImage(const std::string& input_image);
47
+
48
+ //! Returns name of directory for output fft images.
49
+ std::string outputDir();
50
+
51
+ }
52
+
53
+ bool FourierTransformationTest::runTest()
54
+ {
55
+ bool success(true);
56
+
57
+ for (auto inputImage : inputImageNames())
58
+ success &= test_fft(inputImage, fftReferenceImage(inputImage));
59
+
60
+ return success;
61
+ }
62
+
63
+ bool FourierTransformationTest::test_fft(const std::string& input_image_name,
64
+ const std::string& reference_fft_name)
65
+ {
66
+ std::cout << "\nFourierTransformationTest::test_fft()"
67
+ << "\n";
68
+ std::cout << "Input image: " << input_image_name << "\n";
69
+ std::cout << "Reference fft: " << reference_fft_name << "\n";
70
+
71
+ // loading input image
72
+ std::unique_ptr<OutputData<double>> input_image;
73
+ try {
74
+ input_image.reset(IntensityDataIOFactory::readOutputData(input_image_name));
75
+ } catch (const std::exception&) {
76
+ std::cout << "Error: no input image.\n";
77
+ return false;
78
+ }
79
+
80
+ // making fourier transformation
81
+ std::unique_ptr<OutputData<double>> fft =
82
+ IntensityDataFunctions::createFFT(*input_image.get());
83
+
84
+ // loading reference fft
85
+ std::unique_ptr<OutputData<double>> reference_fft;
86
+ try {
87
+ reference_fft.reset(IntensityDataIOFactory::readOutputData(reference_fft_name));
88
+ } catch (const std::exception&) {
89
+ std::cout << "Error: no reference fft image. Creating new one.\n";
90
+ }
91
+
92
+ // comparing new fft against reference fft, if exist
93
+ bool success(false);
94
+ if (reference_fft)
95
+ success = TestUtils::isTheSame(*fft, *reference_fft, threshold) ? true : false;
96
+
97
+ if (!success) {
98
+ FileSystemUtils::createDirectory(outputDir());
99
+ std::string out_fname = FileSystemUtils::jointPath(
100
+ outputDir(), FileSystemUtils::filename(reference_fft_name));
101
+ IntensityDataIOFactory::writeOutputData(*fft, out_fname);
102
+ std::cout << "New fft image stored in " << out_fname << "\n";
103
+ }
104
+
105
+ return success;
106
+ }
107
+
108
+ namespace
109
+ {
110
+ std::string inputImageDir()
111
+ {
112
+ return std::string(BATesting::CoreReferenceDir());
113
+ }
114
+
115
+ std::vector<std::string> inputImageNames()
116
+ {
117
+ std::vector<std::string> result;
118
+ for (auto name : inputImages())
119
+ result.push_back(FileSystemUtils::jointPath(inputImageDir(), name));
120
+
121
+ return result;
122
+ }
123
+
124
+ std::string fftReferenceDir()
125
+ {
126
+ return BATesting::CoreReferenceDir();
127
+ }
128
+
129
+ std::string fftReferenceImage(const std::string& input_image)
130
+ {
131
+ auto filename = FileSystemUtils::filename(input_image);
132
+ return FileSystemUtils::jointPath(fftReferenceDir(), "FourierTransformation_" + filename);
133
+ }
134
+
135
+ std::string outputDir()
136
+ {
137
+ return std::string(BATesting::CoreOutputDir());
138
+ }
139
+
140
+ }
pool/shard011/C++/0121651_ProcessList.cpp ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright (c) 2020 The Orbit 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 "ProcessService/ProcessList.h"
6
+
7
+ #include <absl/container/flat_hash_map.h>
8
+ #include <absl/strings/numbers.h>
9
+ #include <stdint.h>
10
+
11
+ #include <filesystem>
12
+ #include <string>
13
+
14
+ #include "OrbitBase/Logging.h"
15
+ #include "OrbitBase/Result.h"
16
+ #include "OrbitBase/ThreadUtils.h"
17
+ #include "ProcessServiceUtils.h"
18
+
19
+ namespace orbit_process_service_internal {
20
+
21
+ ErrorMessageOr<void> ProcessList::Refresh() {
22
+ absl::flat_hash_map<pid_t, Process> updated_processes{};
23
+
24
+ // TODO(b/161423785): This for loop should be refactored. For example, when
25
+ // parts are in a separate function, OUTCOME_TRY could be used to simplify
26
+ // error handling.
27
+ std::error_code error;
28
+ auto directory_iterator = std::filesystem::directory_iterator("/proc", error);
29
+ if (error) {
30
+ return ErrorMessage(absl::StrFormat("Unable to iterate /proc directory: %s", error.message()));
31
+ }
32
+
33
+ for (auto it = begin(directory_iterator); it != end(directory_iterator); it.increment(error)) {
34
+ if (error) {
35
+ return ErrorMessage(
36
+ absl::StrFormat("Unable to iterate /proc directory: %s", error.message()));
37
+ }
38
+
39
+ bool is_directory = it->is_directory(error);
40
+ if (error) {
41
+ ORBIT_ERROR("Unable to stat \"%s\" directory entry: %s", it->path(), error.message());
42
+ continue;
43
+ }
44
+
45
+ if (!is_directory) continue;
46
+
47
+ const std::filesystem::path& path = it->path();
48
+ std::string folder_name = path.filename().string();
49
+
50
+ uint32_t pid;
51
+ if (!absl::SimpleAtoi(folder_name, &pid)) continue;
52
+
53
+ const auto iter = processes_.find(pid);
54
+
55
+ if (iter != processes_.end()) {
56
+ auto process = processes_.extract(iter);
57
+
58
+ const auto total_cpu_time = orbit_process_service::GetCumulativeTotalCpuTime();
59
+ const auto cpu_time = orbit_process_service::GetCumulativeCpuTimeFromProcess(process.key());
60
+ if (cpu_time && total_cpu_time) {
61
+ process.mapped().UpdateCpuUsage(cpu_time.value(), total_cpu_time.value());
62
+ } else {
63
+ // We don't fail in this case. This could be a permission problem which might occur when not
64
+ // running as root.
65
+ ORBIT_ERROR("Could not update the CPU usage of process %d", process.key());
66
+ }
67
+
68
+ updated_processes.insert(std::move(process));
69
+ continue;
70
+ }
71
+
72
+ auto process_or_error = Process::FromPid(pid);
73
+
74
+ if (process_or_error.has_error()) {
75
+ // We don't fail in this case. This could be a permission problem which is restricted to a
76
+ // small amount of processes.
77
+ ORBIT_ERROR("Could not create process list entry for pid %u: %s", pid,
78
+ process_or_error.error().message());
79
+ continue;
80
+ }
81
+
82
+ updated_processes.emplace(pid, std::move(process_or_error.value()));
83
+ }
84
+
85
+ processes_ = std::move(updated_processes);
86
+
87
+ if (processes_.empty()) {
88
+ return ErrorMessage{
89
+ "Could not determine a single process from the proc-filesystem. Something seems to wrong."};
90
+ }
91
+
92
+ return outcome::success();
93
+ }
94
+
95
+ } // namespace orbit_process_service_internal
pool/shard011/C++/0121653_sensor_comparator_component.cc ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <algorithm>
2
+ #include <string.h>
3
+ #include "../memory.h"
4
+ #include "sensor_comparator_component.h"
5
+
6
+ /* THIS FILE IS AUTOGENERATED BY gen/gen_component_impl.py; DO NOT HAND-MODIFY */
7
+
8
+ void
9
+ sensor_comparator_component_manager::create_component_instance_data(unsigned count) {
10
+ if (count <= buffer.allocated)
11
+ return;
12
+
13
+ component_buffer new_buffer;
14
+ instance_data new_pool;
15
+
16
+ size_t size = sizeof(c_entity) * count;
17
+ size = sizeof(float) * count + align_size<float>(size);
18
+ size = sizeof(float) * count + align_size<float>(size);
19
+ size += 16; // for worst-case misalignment of initial ptr
20
+
21
+ new_buffer.buffer = malloc(size);
22
+ new_buffer.num = buffer.num;
23
+ new_buffer.allocated = count;
24
+ memset(new_buffer.buffer, 0, size);
25
+
26
+ new_pool.entity = align_ptr((c_entity *)new_buffer.buffer);
27
+ new_pool.compare_result = align_ptr((float *)(new_pool.entity + count));
28
+ new_pool.compare_epsilon = align_ptr((float *)(new_pool.compare_result + count));
29
+
30
+ memcpy(new_pool.entity, instance_pool.entity, buffer.num * sizeof(c_entity));
31
+ memcpy(new_pool.compare_result, instance_pool.compare_result, buffer.num * sizeof(float));
32
+ memcpy(new_pool.compare_epsilon, instance_pool.compare_epsilon, buffer.num * sizeof(float));
33
+
34
+ free(buffer.buffer);
35
+ buffer = new_buffer;
36
+
37
+ instance_pool = new_pool;
38
+ }
39
+
40
+ void
41
+ sensor_comparator_component_manager::destroy_instance(instance i) {
42
+ auto last_index = buffer.num - 1;
43
+ auto last_entity = instance_pool.entity[last_index];
44
+ auto current_entity = instance_pool.entity[i.index];
45
+
46
+ instance_pool.entity[i.index] = instance_pool.entity[last_index];
47
+ instance_pool.compare_result[i.index] = instance_pool.compare_result[last_index];
48
+ instance_pool.compare_epsilon[i.index] = instance_pool.compare_epsilon[last_index];
49
+
50
+ entity_instance_map[last_entity] = i.index;
51
+ entity_instance_map.erase(current_entity);
52
+
53
+ --buffer.num;
54
+ }
55
+
56
+ void
57
+ sensor_comparator_component_manager::entity(c_entity e) {
58
+ if (buffer.num >= buffer.allocated) {
59
+ printf("Increasing size of sensor_comparator buffer. Please adjust\n");
60
+ create_component_instance_data(std::max(1u, buffer.allocated) * 2);
61
+ }
62
+
63
+ auto inst = lookup(e);
64
+
65
+ instance_pool.entity[inst.index] = e;
66
+ }
pool/shard011/C++/0121655_pet_dk.cpp ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
3
+ * Copyright (C) 2011-2015 ArkCORE <http://www.arkania.net/>
4
+ *
5
+ * This program is free software; you can redistribute it and/or modify it
6
+ * under the terms of the GNU General Public License as published by the
7
+ * Free Software Foundation; either version 2 of the License, or (at your
8
+ * option) any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful, but WITHOUT
11
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13
+ * more details.
14
+ *
15
+ * You should have received a copy of the GNU General Public License along
16
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+
19
+ /*
20
+ * Ordered alphabetically using scriptname.
21
+ * Scriptnames of files in this file should be prefixed with "npc_pet_dk_".
22
+ */
23
+
24
+ #include "ScriptMgr.h"
25
+ #include "ScriptedCreature.h"
26
+ #include "CombatAI.h"
27
+ #include "Cell.h"
28
+ #include "CellImpl.h"
29
+ #include "GridNotifiers.h"
30
+ #include "GridNotifiersImpl.h"
31
+
32
+ enum DeathKnightSpells
33
+ {
34
+ SPELL_DK_SUMMON_GARGOYLE_1 = 49206,
35
+ SPELL_DK_SUMMON_GARGOYLE_2 = 50514,
36
+ SPELL_DK_DISMISS_GARGOYLE = 50515,
37
+ SPELL_DK_SANCTUARY = 54661
38
+ };
39
+
40
+ class npc_pet_dk_ebon_gargoyle : public CreatureScript
41
+ {
42
+ public:
43
+ npc_pet_dk_ebon_gargoyle() : CreatureScript("npc_pet_dk_ebon_gargoyle") { }
44
+
45
+ struct npc_pet_dk_ebon_gargoyleAI : CasterAI
46
+ {
47
+ npc_pet_dk_ebon_gargoyleAI(Creature* creature) : CasterAI(creature) { }
48
+
49
+ void InitializeAI() override
50
+ {
51
+ // Not needed to be despawned now
52
+ _despawnTimer = 0;
53
+
54
+ CasterAI::InitializeAI();
55
+ uint64 ownerGuid = me->GetOwnerGUID();
56
+ if (!ownerGuid)
57
+ return;
58
+
59
+ // Find victim of Summon Gargoyle spell
60
+ std::list<Unit*> targets;
61
+ Trinity::AnyUnfriendlyUnitInObjectRangeCheck u_check(me, me, 30.0f);
62
+ Trinity::UnitListSearcher<Trinity::AnyUnfriendlyUnitInObjectRangeCheck> searcher(me, targets, u_check);
63
+ me->VisitNearbyObject(30.0f, searcher);
64
+ for (std::list<Unit*>::const_iterator iter = targets.begin(); iter != targets.end(); ++iter)
65
+ if ((*iter)->GetAura(SPELL_DK_SUMMON_GARGOYLE_1, ownerGuid))
66
+ {
67
+ me->Attack((*iter), false);
68
+ break;
69
+ }
70
+ }
71
+
72
+ void JustDied(Unit* /*killer*/) override
73
+ {
74
+ // Stop Feeding Gargoyle when it dies
75
+ if (Unit* owner = me->GetOwner())
76
+ owner->RemoveAurasDueToSpell(SPELL_DK_SUMMON_GARGOYLE_2);
77
+ }
78
+
79
+ // Fly away when dismissed
80
+ void SpellHit(Unit* source, SpellInfo const* spell) override
81
+ {
82
+ if (spell->Id != SPELL_DK_DISMISS_GARGOYLE || !me->IsAlive())
83
+ return;
84
+
85
+ Unit* owner = me->GetOwner();
86
+ if (!owner || owner != source)
87
+ return;
88
+
89
+ // Stop Fighting
90
+ me->ApplyModFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE, true);
91
+
92
+ // Sanctuary
93
+ me->CastSpell(me, SPELL_DK_SANCTUARY, true);
94
+ me->SetReactState(REACT_PASSIVE);
95
+
96
+ //! HACK: Creature's can't have MOVEMENTFLAG_FLYING
97
+ // Fly Away
98
+ me->SetCanFly(true);
99
+ me->SetSpeed(MOVE_FLIGHT, 0.75f, true);
100
+ me->SetSpeed(MOVE_RUN, 0.75f, true);
101
+ float x = me->GetPositionX() + 20 * std::cos(me->GetOrientation());
102
+ float y = me->GetPositionY() + 20 * std::sin(me->GetOrientation());
103
+ float z = me->GetPositionZ() + 40;
104
+ me->GetMotionMaster()->Clear(false);
105
+ me->GetMotionMaster()->MovePoint(0, x, y, z);
106
+
107
+ // Despawn as soon as possible
108
+ _despawnTimer = 4 * IN_MILLISECONDS;
109
+ }
110
+
111
+ void UpdateAI(uint32 diff) override
112
+ {
113
+ if (_despawnTimer > 0)
114
+ {
115
+ if (_despawnTimer > diff)
116
+ _despawnTimer -= diff;
117
+ else
118
+ me->DespawnOrUnsummon();
119
+ return;
120
+ }
121
+
122
+ CasterAI::UpdateAI(diff);
123
+ }
124
+
125
+ private:
126
+ uint32 _despawnTimer;
127
+ };
128
+
129
+ CreatureAI* GetAI(Creature* creature) const override
130
+ {
131
+ return new npc_pet_dk_ebon_gargoyleAI(creature);
132
+ }
133
+ };
134
+
135
+ void AddSC_deathknight_pet_scripts()
136
+ {
137
+ new npc_pet_dk_ebon_gargoyle();
138
+ }
pool/shard011/C++/0121656_glut_win.cpp ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright (c) 2012, Frederic Dubouchet
3
+ * 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 are met:
7
+ * * Redistributions of source code must retain the above copyright
8
+ * notice, this list of conditions and the following disclaimer.
9
+ * * 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
+ * * Neither the name of the CERN nor the
13
+ * names of its contributors may be used to endorse or promote products
14
+ * derived from this software without specific prior written permission.
15
+ *
16
+ * THIS SOFTWARE IS PROVIDED BY Frederic Dubouchet ``AS IS'' AND ANY
17
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ * DISCLAIMED. IN NO EVENT SHALL Frederic DUBOUCHEDT BE LIABLE FOR ANY
20
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
+ */
27
+
28
+ #include <stdlib.h>
29
+ #include <stdexcept>
30
+ #include <string>
31
+ #ifdef __linux__
32
+ #include <GL/glut.h>
33
+ #endif
34
+ #ifdef __APPLE__
35
+ #include <glut/glut.h>
36
+ #endif
37
+
38
+ #include "glut_win.hpp"
39
+
40
+ static void init() {
41
+ glut_win::instance()->pwin_->init();
42
+ }
43
+
44
+ static void finish() {
45
+ glut_win::instance()->pwin_->finish();
46
+ }
47
+
48
+ static void display() {
49
+ static bool s_first = true;
50
+ if (s_first) {
51
+ s_first = false;
52
+ init();
53
+ } else {
54
+ glut_win::instance()->pwin_->display();
55
+ }
56
+ glutSwapBuffers();
57
+ }
58
+
59
+ static void keyboard(unsigned char key, int x, int y) {
60
+ switch(key) {
61
+ case 27 :
62
+ finish();
63
+ exit(0);
64
+ break;
65
+ }
66
+ glut_win::instance()->pwin_->keyboard(key, x, y);
67
+ }
68
+
69
+ static void reshape(int w, int h) {
70
+ glut_win::instance()->pwin_->reshape(w, h);
71
+ }
72
+
73
+ static void idle() {
74
+ glut_win::instance()->pwin_->idle();
75
+ glutPostRedisplay();
76
+ }
77
+
78
+ static void mouse_move(int x, int y) {
79
+ glut_win::instance()->pwin_->mouse_move(x, y);
80
+ }
81
+
82
+ static void mouse_event(int button, int state, int x, int y) {
83
+ glut_win::instance()->pwin_->mouse_event(button, state, x, y);
84
+ }
85
+
86
+ glut_win* glut_win::instance_ = NULL;
87
+
88
+ glut_win* glut_win::instance(
89
+ const std::string& name,
90
+ const std::pair<unsigned int, unsigned int>& range,
91
+ i_win* windesc,
92
+ bool fullscreen)
93
+ throw(std::exception)
94
+ {
95
+ if (!instance_)
96
+ instance_ = new glut_win(name, range, windesc, fullscreen);
97
+ return instance_;
98
+ }
99
+
100
+ glut_win* glut_win::instance() throw(std::exception) {
101
+ if (instance_) return instance_;
102
+ else throw std::runtime_error(std::string("glut_win was not initialized!"));
103
+ }
104
+
105
+ glut_win::glut_win(
106
+ const std::string& name,
107
+ const std::pair<unsigned int, unsigned int>& range,
108
+ i_win* windesc,
109
+ bool fullscreen)
110
+ throw(std::exception) :
111
+ fullscreen_(fullscreen),
112
+ pwin_(windesc)
113
+ {
114
+ if (!pwin_) throw std::runtime_error(std::string("Window class == NULL"));
115
+ int ac = 0;
116
+ glutInit(&ac, NULL);
117
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
118
+ if (!fullscreen_)
119
+ glutInitWindowSize(range.first, range.second);
120
+ glutCreateWindow(name.c_str());
121
+ if (fullscreen_)
122
+ glutFullScreen();
123
+ }
124
+
125
+ glut_win::~glut_win() { }
126
+
127
+ void glut_win::run()
128
+ throw(std::exception)
129
+ {
130
+ glutDisplayFunc(display);
131
+ glutKeyboardFunc(keyboard);
132
+ glutReshapeFunc(reshape);
133
+ glutMotionFunc(mouse_move);
134
+ glutMouseFunc(mouse_event);
135
+ glutIdleFunc(idle);
136
+ glutMainLoop();
137
+ }
138
+
pool/shard011/C++/0121658_main.cpp ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* ************************************************************************** */
2
+ /* */
3
+ /* ::: :::::::: */
4
+ /* main.cpp :+: :+: :+: */
5
+ /* +:+ +:+ +:+ */
6
+ /* By: ncharret <marvin@42.fr> +#+ +:+ +#+ */
7
+ /* +#+#+#+#+#+ +#+ */
8
+ /* Created: 2015/06/16 17:15:24 by ncharret #+# #+# */
9
+ /* Updated: 2015/06/16 17:29:35 by ncharret ### ########.fr */
10
+ /* */
11
+ /* ************************************************************************** */
12
+
13
+ #include "ZombieEvent.hpp"
14
+ #include "Zombie.hpp"
15
+
16
+ void pitiZomb() {
17
+
18
+ Zombie piti("petit", "Pony");
19
+ piti.announce();
20
+ piti.announce();
21
+ }
22
+
23
+ int main()
24
+ {
25
+ ZombieEvent factory;
26
+ factory.setZombieType("rebelz");
27
+ for (int i = 0; i < 3; i++) {
28
+
29
+ Zombie *zomb = factory.randomChump();
30
+ delete zomb;
31
+ }
32
+ factory.setZombieType("pasrebelz");
33
+ for (int i = 0; i < 3; i++) {
34
+
35
+ Zombie *zomb = factory.randomChump();
36
+ delete zomb;
37
+ }
38
+ pitiZomb();
39
+ return (0);
40
+ }
pool/shard011/C++/0121660_checkpoints.cpp ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright (c) 2009-2012 The Bitcoin developers
2
+ // Distributed under the MIT/X11 software license, see the accompanying
3
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
+
5
+ #include <boost/assign/list_of.hpp> // for 'map_list_of()'
6
+ #include <boost/foreach.hpp>
7
+
8
+ #include "checkpoints.h"
9
+
10
+ #include "txdb.h"
11
+ #include "main.h"
12
+ #include "uint256.h"
13
+
14
+
15
+ static const int nCheckpointSpan = 500;
16
+
17
+ namespace Checkpoints
18
+ {
19
+ typedef std::map<int, uint256> MapCheckpoints;
20
+
21
+ //
22
+ // What makes a good checkpoint block?
23
+ // + Is surrounded by blocks with reasonable timestamps
24
+ // (no blocks before with a timestamp after, none after with
25
+ // timestamp before)
26
+ // + Contains no strange transactions
27
+ //
28
+ static MapCheckpoints mapCheckpoints =
29
+ boost::assign::map_list_of
30
+ ( 0, uint256("0x00000068ea1bda5d79b59679d475024f8bc3344a5571a2c00bed231c7495fae6") ) // genesis
31
+ ;
32
+
33
+ // TestNet has no checkpoints
34
+ static MapCheckpoints mapCheckpointsTestnet;
35
+
36
+ bool CheckHardened(int nHeight, const uint256& hash)
37
+ {
38
+ MapCheckpoints& checkpoints = (TestNet() ? mapCheckpointsTestnet : mapCheckpoints);
39
+
40
+ MapCheckpoints::const_iterator i = checkpoints.find(nHeight);
41
+ if (i == checkpoints.end()) return true;
42
+ return hash == i->second;
43
+ }
44
+
45
+ int GetTotalBlocksEstimate()
46
+ {
47
+ MapCheckpoints& checkpoints = (TestNet() ? mapCheckpointsTestnet : mapCheckpoints);
48
+
49
+ if (checkpoints.empty())
50
+ return 0;
51
+ return checkpoints.rbegin()->first;
52
+ }
53
+
54
+ CBlockIndex* GetLastCheckpoint(const std::map<uint256, CBlockIndex*>& mapBlockIndex)
55
+ {
56
+ MapCheckpoints& checkpoints = (TestNet() ? mapCheckpointsTestnet : mapCheckpoints);
57
+
58
+ BOOST_REVERSE_FOREACH(const MapCheckpoints::value_type& i, checkpoints)
59
+ {
60
+ const uint256& hash = i.second;
61
+ std::map<uint256, CBlockIndex*>::const_iterator t = mapBlockIndex.find(hash);
62
+ if (t != mapBlockIndex.end())
63
+ return t->second;
64
+ }
65
+ return NULL;
66
+ }
67
+
68
+ // Automatically select a suitable sync-checkpoint
69
+ const CBlockIndex* AutoSelectSyncCheckpoint()
70
+ {
71
+ const CBlockIndex *pindex = pindexBest;
72
+ // Search backward for a block within max span and maturity window
73
+ while (pindex->pprev && pindex->nHeight + nCheckpointSpan > pindexBest->nHeight)
74
+ pindex = pindex->pprev;
75
+ return pindex;
76
+ }
77
+
78
+ // Check against synchronized checkpoint
79
+ bool CheckSync(int nHeight)
80
+ {
81
+ const CBlockIndex* pindexSync = AutoSelectSyncCheckpoint();
82
+
83
+ if (nHeight <= pindexSync->nHeight)
84
+ return false;
85
+ return true;
86
+ }
87
+ }
pool/shard011/C++/0121661_kis_deform_paintop_settings_widget.cpp ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright (c) 2008,2009,2010 Lukáš Tvrdý <lukast.dev@gmail.com>
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, USA.
17
+ */
18
+ #include "kis_deform_paintop_settings.h"
19
+ #include "kis_deform_paintop_settings_widget.h"
20
+ #include "kis_deform_option.h"
21
+
22
+ #include <kis_paintop_options_widget.h>
23
+ #include <kis_brush_size_option.h>
24
+
25
+ #include <kis_pressure_rotation_option.h>
26
+ #include <kis_pressure_opacity_option.h>
27
+ #include <kis_pressure_size_option.h>
28
+ #include <kis_curve_option_widget.h>
29
+ #include <kis_airbrush_option.h>
30
+ #include <kis_compositeop_option.h>
31
+
32
+ KisDeformPaintOpSettingsWidget::KisDeformPaintOpSettingsWidget(QWidget* parent)
33
+ : KisPaintOpOptionsWidget(parent)
34
+ {
35
+ m_deformOption = new KisDeformOption();
36
+ m_brushSizeOption = new KisBrushSizeOption();
37
+ m_brushSizeOption->setDiameter(200);
38
+
39
+ addPaintOpOption(m_brushSizeOption);
40
+ addPaintOpOption(m_deformOption);
41
+ addPaintOpOption(new KisCompositeOpOption(true));
42
+ addPaintOpOption(new KisCurveOptionWidget(new KisPressureOpacityOption()));
43
+ addPaintOpOption(new KisCurveOptionWidget(new KisPressureSizeOption()));
44
+ addPaintOpOption(new KisCurveOptionWidget(new KisPressureRotationOption()));
45
+ addPaintOpOption(new KisAirbrushOption());
46
+ }
47
+
48
+ KisDeformPaintOpSettingsWidget::~ KisDeformPaintOpSettingsWidget()
49
+ {
50
+ }
51
+
52
+
53
+ void KisDeformPaintOpSettingsWidget::changePaintOpSize(qreal x, qreal y)
54
+ {
55
+ // if the movement is more left<->right then up<->down
56
+ if (qAbs(x) > qAbs(y)) {
57
+ m_brushSizeOption->setDiameter(m_brushSizeOption->diameter() + qRound(x));
58
+ }
59
+ else { // vice-versa
60
+ // we can do something different, e.g. change deform mode or ...
61
+ }
62
+ }
63
+
64
+
65
+ QSizeF KisDeformPaintOpSettingsWidget::paintOpSize() const
66
+ {
67
+ qreal height = m_brushSizeOption->diameter() * m_brushSizeOption->brushAspect();
68
+ return QSizeF(m_brushSizeOption->diameter(), height);
69
+ }
70
+
71
+
72
+ KisPropertiesConfiguration* KisDeformPaintOpSettingsWidget::configuration() const
73
+ {
74
+ KisDeformPaintOpSettings* config = new KisDeformPaintOpSettings();
75
+ config->setOptionsWidget(const_cast<KisDeformPaintOpSettingsWidget*>(this));
76
+ config->setProperty("paintop", "deformBrush");
77
+ writeConfiguration(config);
78
+ return config;
79
+ }
80
+