Pendigard commited on
Commit
8f82b88
·
verified ·
1 Parent(s): 707bb21

Upload folder using huggingface_hub (part 10)

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/shard000/C++/0000002_gen_menge_grid.cpp +64 -0
  2. pool/shard000/C++/0000009_fp_FieldTOCNum.cpp +214 -0
  3. pool/shard000/C++/0000012_android_cache_database_unittest.cc +115 -0
  4. pool/shard000/C++/0000019_fcitx-formatted-preedit.cpp +73 -0
  5. pool/shard000/C++/0000025_WindowsUpdater.cpp +53 -0
  6. pool/shard000/C++/0000029_P1MeterSerial.cpp +167 -0
  7. pool/shard000/C++/0000030_ReaderBinding.cpp +147 -0
  8. pool/shard000/C++/0000031_testcli.cpp +150 -0
  9. pool/shard000/C++/0000036_main.cpp +106 -0
  10. pool/shard000/C++/0000043_Syntax.cpp +111 -0
  11. pool/shard000/C++/0000053_random_sample.cpp +40 -0
  12. pool/shard000/C++/0000055_Point.cpp +24 -0
  13. pool/shard000/C++/0000060_main.cpp +38 -0
  14. pool/shard000/C++/0000061_CElmPhotocam.cc +184 -0
  15. pool/shard000/C++/0000065_modelprinter.cpp +152 -0
  16. pool/shard000/C++/0000067_main.cpp +112 -0
  17. pool/shard000/C++/0000069_mpmat_test.cpp +68 -0
  18. pool/shard000/C++/0000081_B._Volcanoes.cpp +57 -0
  19. pool/shard000/C++/0000084_main.cpp +42 -0
  20. pool/shard000/C++/0000086_UnbiasedIncomplete.cpp +52 -0
  21. pool/shard000/C++/0000091_updateoriginendpointresponse.cpp +100 -0
  22. pool/shard000/C++/0000092_asset_texture.cpp +139 -0
  23. pool/shard000/C++/0000094_test_201_300.cpp +82 -0
  24. pool/shard000/C++/0000097_strlen_of_shadow.cc +36 -0
  25. pool/shard000/C++/0000112_check_nan.cc +59 -0
  26. pool/shard000/C++/0000122_decoder_engine.cc +117 -0
  27. pool/shard000/C++/0000127_time_conversion_unittest.cc +57 -0
  28. pool/shard000/C++/0000141_potential_file_reader.cpp +283 -0
  29. pool/shard000/C++/0000144_testArrayBuffer.cpp +227 -0
  30. pool/shard000/C++/0000147_ExpressionClassifier.cpp +128 -0
  31. pool/shard000/C++/0000148_random_unittest.cc +27 -0
  32. pool/shard000/C++/0000174_DataFlashFileReader.cpp +63 -0
  33. pool/shard000/C++/0000179_for_each_suffix.cpp +31 -0
  34. pool/shard000/C++/0000187_Event.cpp +59 -0
  35. pool/shard000/C++/0000190_trim_strings.cpp +44 -0
  36. pool/shard000/C++/0000193_common.cpp +30 -0
  37. pool/shard000/C++/0000194_pt554.cpp +107 -0
  38. pool/shard000/C++/0000200_pmic.cpp +284 -0
  39. pool/shard000/C++/0000205_10526279.cpp +132 -0
  40. pool/shard000/C++/0000208_ReadEditDemoDlg.cpp +187 -0
  41. pool/shard000/C++/0000211_SVGFETurbulenceElement.cpp +182 -0
  42. pool/shard000/C++/0000212_mis_fun.cc +110 -0
  43. pool/shard000/C++/0000213_SensorProcessor.cpp +174 -0
  44. pool/shard000/C++/0000216_moc_qaccessibleplugin.cpp +87 -0
  45. pool/shard000/C++/0000219_MonitoredProcess.cpp +137 -0
  46. pool/shard000/C++/0000221_UI.cpp +150 -0
  47. pool/shard000/C++/0000225_MethodOfGettingAValueProfile.cpp +69 -0
  48. pool/shard000/C++/0000238_c_te_bubbletrail.cpp +83 -0
  49. pool/shard000/C++/0000239_2.cc +70 -0
  50. pool/shard000/C++/0000240_tfs_random.cpp +77 -0
pool/shard000/C++/0000002_gen_menge_grid.cpp ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <vector>
2
+
3
+ #include <math.h>
4
+ #include <stdio.h>
5
+ #include <stdbool.h>
6
+
7
+ #define GLM_FORCE_RADIANS
8
+ #include <glm/glm.hpp>
9
+
10
+ enum {
11
+ TOTAL_ITERATIONS = 3
12
+ };
13
+
14
+ bool is_in_sierpinski_carpet(unsigned int i, unsigned int j)
15
+ {
16
+ while (i != 0 && j != 0) {
17
+ if (i % 3 == 1 && j % 3 == 1) {
18
+ return false;
19
+ }
20
+ i /= 3;
21
+ j /= 3;
22
+ }
23
+ return true;
24
+ }
25
+
26
+ bool is_in_menge_sponge(unsigned int i, unsigned int j, unsigned int k)
27
+ {
28
+ if (!is_in_sierpinski_carpet(i, j)) {
29
+ return false;
30
+ }
31
+ if (!is_in_sierpinski_carpet(j, k)) {
32
+ return false;
33
+ }
34
+ if (!is_in_sierpinski_carpet(k, i)) {
35
+ return false;
36
+ }
37
+ return true;
38
+ }
39
+
40
+ int main()
41
+ {
42
+ const int grid_side_len = pow(3, TOTAL_ITERATIONS);
43
+ const int grid_size = (int)pow(grid_side_len, 2);
44
+ int grid[grid_side_len][grid_side_len];
45
+ std::vector<glm::vec3> instance_displacements;
46
+
47
+ for (unsigned int i = 0; i < grid_side_len; i++){
48
+ for (unsigned int j = 0; j < grid_side_len; j++) {
49
+ for (unsigned int k = 0; k < grid_side_len; k++) {
50
+ if (is_in_menge_sponge(i, j, k)) {
51
+ instance_displacements.push_back(
52
+ glm::vec3(i * 2.0f,j * 2.0f,k * -2.0f));
53
+ }
54
+ }
55
+ }
56
+ }
57
+
58
+ fprintf(stdout, "%lu \n", instance_displacements.size());
59
+ fwrite(
60
+ &instance_displacements[0],
61
+ sizeof(instance_displacements[0]),
62
+ instance_displacements.size(),
63
+ stdout);
64
+ }
pool/shard000/C++/0000009_fp_FieldTOCNum.cpp ADDED
@@ -0,0 +1,214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* AbiWord
2
+ * Copyright (C) 1998 AbiSource, Inc.
3
+ * BIDI Copyright (c) 2001,2002 Tomas Frydrych
4
+ * (C) Martin Sevior 2004, , <msevior@physics.unimelb.edu.au>
5
+ *
6
+ * This program is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU General Public License
8
+ * as published by the Free Software Foundation; either version 2
9
+ * of the License, or (at your option) any later version.
10
+ *
11
+ * This program is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program; if not, write to the Free Software
18
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19
+ * 02111-1307, USA.
20
+ */
21
+
22
+
23
+ #include "fp_FieldTOCNum.h"
24
+ #include "fl_BlockLayout.h"
25
+ #include "pt_Types.h"
26
+ #include "pd_Document.h"
27
+ #include "fl_DocLayout.h"
28
+ #include "fp_Line.h"
29
+ #include "ut_debugmsg.h"
30
+ #include "fl_TOCLayout.h"
31
+ #include <string.h>
32
+
33
+ fp_FieldTOCNumRun::fp_FieldTOCNumRun(fl_BlockLayout* pBL,UT_uint32 iOffsetFirst, UT_uint32 iLen) : fp_FieldRun(pBL,iOffsetFirst, iLen)
34
+ {
35
+ UT_ASSERT(pBL);
36
+ _setDirection(pBL->getDominantDirection());
37
+ }
38
+
39
+ bool fp_FieldTOCNumRun::calculateValue(void)
40
+ {
41
+ UT_UCSChar sz_ucs_FieldValue[FPFIELD_MAX_LENGTH + 1];
42
+ //
43
+ // First Find page number.
44
+ //
45
+ PL_StruxDocHandle sdh = getBlock()->getStruxDocHandle();
46
+ PD_Document * pDoc = getBlock()->getDocument();
47
+ PT_DocPosition pos = pDoc->getStruxPosition(sdh)+1;
48
+ FL_DocLayout * pLayout = getBlock()->getDocLayout();
49
+ fl_BlockLayout * pBlockInDoc = pLayout->findBlockAtPosition(pos);
50
+ if(pBlockInDoc == NULL)
51
+ {
52
+ sz_ucs_FieldValue[0] = static_cast<UT_UCSChar>(' ');
53
+ sz_ucs_FieldValue[1] = 0;
54
+ return _setValue(sz_ucs_FieldValue);
55
+ }
56
+ fp_Line * pLine = static_cast<fp_Line *>(pBlockInDoc->getFirstContainer());
57
+ if(pLine == NULL)
58
+ {
59
+ sz_ucs_FieldValue[0] = static_cast<UT_UCSChar>(' ');
60
+ sz_ucs_FieldValue[1] = 0;
61
+ return _setValue(sz_ucs_FieldValue);
62
+ }
63
+ fp_Page * pPage = pLine->getPage();
64
+ UT_sint32 iPage = pLayout->findPage(pPage);
65
+ if( iPage < 0)
66
+ {
67
+ sz_ucs_FieldValue[0] = static_cast<UT_UCSChar>(' ');
68
+ sz_ucs_FieldValue[1] = 0;
69
+ return _setValue(sz_ucs_FieldValue);
70
+ }
71
+ iPage++; // Start from Page 1.
72
+ UT_String sVal("");
73
+ FootnoteType iType = getBlock()->getTOCNumType();
74
+ pLayout->getStringFromFootnoteVal(sVal,iPage,iType);
75
+ const char * psz = sVal.c_str();
76
+ bool bStop = false;
77
+ UT_sint32 i = 0;
78
+ sz_ucs_FieldValue[0] = static_cast<UT_UCSChar>(' ');
79
+ for(i=1; (i<FPFIELD_MAX_LENGTH) && !bStop; i++)
80
+ {
81
+ sz_ucs_FieldValue[i] = static_cast<UT_UCSChar>(*psz);
82
+ if(*psz == 0)
83
+ {
84
+ bStop = true;
85
+ }
86
+ else
87
+ {
88
+ psz++;
89
+ }
90
+ }
91
+ return _setValue(sz_ucs_FieldValue);
92
+ }
93
+
94
+ void fp_FieldTOCNumRun::_draw(dg_DrawArgs* pDA)
95
+ {
96
+ _defaultDraw(pDA);
97
+ }
98
+
99
+ void fp_FieldTOCNumRun::_lookupProperties(const PP_AttrProp * pSpanAP,
100
+ const PP_AttrProp * pBlockAP,
101
+ const PP_AttrProp * pSectionAP,
102
+ GR_Graphics * pG)
103
+ {
104
+ fp_FieldRun::_lookupProperties (pSpanAP, pBlockAP, pSectionAP,pG) ;
105
+ }
106
+
107
+ /////////////////////////////////////////////////////////////////////////////
108
+
109
+
110
+ fp_FieldTOCListLabelRun::fp_FieldTOCListLabelRun(fl_BlockLayout* pBL,UT_uint32 iOffsetFirst, UT_uint32 iLen) : fp_FieldRun(pBL,iOffsetFirst, iLen)
111
+ {
112
+ UT_ASSERT(pBL);
113
+ _setDirection(pBL->getDominantDirection());
114
+ _setLength(0);
115
+ }
116
+
117
+ bool fp_FieldTOCListLabelRun::calculateValue(void)
118
+ {
119
+ UT_UCSChar sz_ucs_FieldValue[FPFIELD_MAX_LENGTH + 1];
120
+ //
121
+ // First get owning TOC.
122
+ //
123
+ UT_ASSERT(getLength() == 0);
124
+ fl_TOCLayout * pTOCL = static_cast<fl_TOCLayout *>(getBlock()->myContainingLayout());
125
+ UT_ASSERT(pTOCL->getContainerType() == FL_CONTAINER_TOC);
126
+ UT_String str = pTOCL->getTOCListLabel(getBlock()).utf8_str();
127
+ if(str.size() == 0)
128
+ {
129
+ sz_ucs_FieldValue[0] = 0;
130
+ return _setValue(sz_ucs_FieldValue);
131
+ }
132
+ UT_sint32 i = 0;
133
+ bool bStop = false;
134
+ for(i=0; (i<FPFIELD_MAX_LENGTH) && !bStop; i++)
135
+ {
136
+ sz_ucs_FieldValue[i] = static_cast<UT_UCSChar>(str[i]);
137
+ if(str[i] == 0)
138
+ {
139
+ bStop = true;
140
+ }
141
+ }
142
+ return _setValue(sz_ucs_FieldValue);
143
+ }
144
+
145
+ void fp_FieldTOCListLabelRun::_draw(dg_DrawArgs* pDA)
146
+ {
147
+ _defaultDraw(pDA);
148
+ }
149
+
150
+ void fp_FieldTOCListLabelRun::_lookupProperties(const PP_AttrProp * pSpanAP,
151
+ const PP_AttrProp * pBlockAP,
152
+ const PP_AttrProp * pSectionAP,
153
+ GR_Graphics * pG)
154
+ {
155
+ fp_FieldRun::_lookupProperties (pSpanAP, pBlockAP, pSectionAP,pG) ;
156
+ _setLength(0);
157
+ }
158
+
159
+ ////////////////////////////////////////////////////////////////////////////
160
+
161
+
162
+ fp_FieldTOCHeadingRun::fp_FieldTOCHeadingRun(fl_BlockLayout* pBL,UT_uint32 iOffsetFirst, UT_uint32 iLen) : fp_FieldRun(pBL,iOffsetFirst, iLen)
163
+ {
164
+ UT_ASSERT(pBL);
165
+ _setDirection(pBL->getDominantDirection());
166
+ _setLength(0);
167
+ }
168
+
169
+ bool fp_FieldTOCHeadingRun::calculateValue(void)
170
+ {
171
+ UT_UCSChar sz_ucs_FieldValue[FPFIELD_MAX_LENGTH + 1];
172
+ //
173
+ // First get owning TOC.
174
+ //
175
+ UT_ASSERT(getLength() == 0);
176
+ fl_TOCLayout * pTOCL = static_cast<fl_TOCLayout *>(getBlock()->myContainingLayout());
177
+ UT_ASSERT(pTOCL->getContainerType() == FL_CONTAINER_TOC);
178
+ UT_UCS4String str = pTOCL->getTOCHeading().ucs4_str();
179
+ if(str.size() == 0)
180
+ {
181
+ sz_ucs_FieldValue[0] = 0;
182
+ return _setValue(sz_ucs_FieldValue);
183
+ }
184
+ UT_sint32 i = 0;
185
+ bool bStop = false;
186
+
187
+ for(i=0; (i<FPFIELD_MAX_LENGTH) && !bStop; i++)
188
+ {
189
+ sz_ucs_FieldValue[i] = static_cast<UT_UCSChar>(str[i]);
190
+ if(str[i] == 0)
191
+ {
192
+ bStop = true;
193
+ }
194
+ }
195
+ return _setValue(sz_ucs_FieldValue);
196
+ }
197
+
198
+ void fp_FieldTOCHeadingRun::_draw(dg_DrawArgs* pDA)
199
+ {
200
+ _defaultDraw(pDA);
201
+ }
202
+
203
+ void fp_FieldTOCHeadingRun::_lookupProperties(const PP_AttrProp * pSpanAP,
204
+ const PP_AttrProp * pBlockAP,
205
+ const PP_AttrProp * pSectionAP,
206
+ GR_Graphics * pG)
207
+ {
208
+ fp_FieldRun::_lookupProperties (pSpanAP, pBlockAP, pSectionAP,pG) ;
209
+ _setLength(0);
210
+ }
211
+
212
+
213
+
214
+
pool/shard000/C++/0000012_android_cache_database_unittest.cc ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 "components/history/core/browser/android/android_cache_database.h"
6
+
7
+ #include "base/files/file_path.h"
8
+ #include "base/files/scoped_temp_dir.h"
9
+ #include "base/strings/utf_string_conversions.h"
10
+ #include "chrome/test/base/testing_profile.h"
11
+ #include "components/history/core/browser/android/android_time.h"
12
+ #include "components/history/core/browser/history_database.h"
13
+ #include "components/history/core/test/test_history_database.h"
14
+ #include "testing/gtest/include/gtest/gtest.h"
15
+
16
+ using base::Time;
17
+ using base::TimeDelta;
18
+
19
+ namespace history {
20
+
21
+ class AndroidCacheDatabaseTest : public testing::Test {
22
+ public:
23
+ AndroidCacheDatabaseTest() {}
24
+ ~AndroidCacheDatabaseTest() override {}
25
+
26
+ protected:
27
+ void SetUp() override {
28
+ // Get a temporary directory for the test DB files.
29
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
30
+ base::FilePath history_db_name_ =
31
+ temp_dir_.path().AppendASCII("history.db");
32
+ android_cache_db_name_ = temp_dir_.path().AppendASCII(
33
+ "TestAndroidCache.db");
34
+ ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_));
35
+ ASSERT_EQ(sql::INIT_OK,
36
+ history_db_.InitAndroidCacheDatabase(android_cache_db_name_));
37
+ }
38
+
39
+ base::ScopedTempDir temp_dir_;
40
+ base::FilePath android_cache_db_name_;
41
+ TestHistoryDatabase history_db_;
42
+ };
43
+
44
+ TEST(AndroidCacheDatabaseAttachTest, AttachDatabaseInTransactionNesting) {
45
+ base::ScopedTempDir temp_dir;
46
+ base::FilePath android_cache_db_name;
47
+ TestHistoryDatabase history_db;
48
+ ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
49
+ base::FilePath history_db_name = temp_dir.path().AppendASCII("history.db");
50
+ android_cache_db_name = temp_dir.path().AppendASCII(
51
+ "TestAndroidCache.db");
52
+ ASSERT_EQ(sql::INIT_OK, history_db.Init(history_db_name));
53
+ // Create nested transactions.
54
+ history_db.BeginTransaction();
55
+ history_db.BeginTransaction();
56
+ history_db.BeginTransaction();
57
+ int transaction_nesting = history_db.transaction_nesting();
58
+ ASSERT_EQ(sql::INIT_OK,
59
+ history_db.InitAndroidCacheDatabase(android_cache_db_name));
60
+ // The count of nested transaction is still same.
61
+ EXPECT_EQ(transaction_nesting, history_db.transaction_nesting());
62
+ }
63
+
64
+ TEST_F(AndroidCacheDatabaseTest, InitAndroidCacheDatabase) {
65
+ // Try to run a sql against the table to verify them exist.
66
+ AndroidCacheDatabase* cache_db =
67
+ static_cast<AndroidCacheDatabase*>(&history_db_);
68
+ EXPECT_TRUE(cache_db->GetDB().Execute(
69
+ "DELETE FROM android_cache_db.bookmark_cache"));
70
+ EXPECT_TRUE(cache_db->GetDB().Execute(
71
+ "DELETE FROM android_cache_db.search_terms"));
72
+ }
73
+
74
+ TEST_F(AndroidCacheDatabaseTest, SearchTermsTable) {
75
+ // Test AddSearchTerm.
76
+ Time search_time1 = Time::Now() - TimeDelta::FromDays(1);
77
+ base::string16 search_term1(base::UTF8ToUTF16("search term 1"));
78
+ SearchTermID id1 = history_db_.AddSearchTerm(search_term1, search_time1);
79
+ ASSERT_TRUE(id1);
80
+ SearchTermRow row1;
81
+ ASSERT_EQ(id1, history_db_.GetSearchTerm(search_term1, &row1));
82
+ EXPECT_EQ(search_term1, row1.term);
83
+ EXPECT_EQ(ToDatabaseTime(search_time1),
84
+ ToDatabaseTime(row1.last_visit_time));
85
+ EXPECT_EQ(id1, row1.id);
86
+
87
+ // Test UpdateSearchTerm.
88
+ SearchTermRow update_row1;
89
+ update_row1.term = (base::UTF8ToUTF16("update search term1"));
90
+ update_row1.last_visit_time = Time::Now();
91
+ ASSERT_TRUE(history_db_.UpdateSearchTerm(id1, update_row1));
92
+ EXPECT_EQ(id1, history_db_.GetSearchTerm(update_row1.term, &row1));
93
+ EXPECT_EQ(update_row1.term, row1.term);
94
+ EXPECT_EQ(ToDatabaseTime(update_row1.last_visit_time),
95
+ ToDatabaseTime(row1.last_visit_time));
96
+ EXPECT_EQ(id1, row1.id);
97
+
98
+ Time search_time2 = Time::Now() - TimeDelta::FromHours(1);
99
+ base::string16 search_term2(base::UTF8ToUTF16("search term 2"));
100
+ SearchTermID id2 = history_db_.AddSearchTerm(search_term2, search_time2);
101
+ ASSERT_TRUE(id2);
102
+ ASSERT_TRUE(history_db_.SetKeywordSearchTermsForURL(1, 1, search_term2));
103
+ ASSERT_TRUE(history_db_.DeleteUnusedSearchTerms());
104
+
105
+ // The search_term1 was removed.
106
+ EXPECT_FALSE(history_db_.GetSearchTerm(update_row1.term, NULL));
107
+ // The search_term2 should still in the table.
108
+ ASSERT_EQ(id2, history_db_.GetSearchTerm(search_term2, &row1));
109
+ EXPECT_EQ(id2, row1.id);
110
+ EXPECT_EQ(ToDatabaseTime(search_time2),
111
+ ToDatabaseTime(row1.last_visit_time));
112
+ EXPECT_EQ(search_term2, row1.term);
113
+ }
114
+
115
+ } // namespace history
pool/shard000/C++/0000019_fcitx-formatted-preedit.cpp ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /***************************************************************************
2
+ * Copyright (C) 2012~2012 by CSSlayer *
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 *
16
+ * Free Software Foundation, Inc., *
17
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
18
+ ***************************************************************************/
19
+
20
+ #include <QDBusMetaType>
21
+
22
+ #include "fcitx-formatted-preedit.h"
23
+
24
+
25
+ void FcitxFormattedPreedit::registerMetaType()
26
+ {
27
+ qRegisterMetaType<FcitxFormattedPreedit>("FcitxFormattedPreedit");
28
+ qDBusRegisterMetaType<FcitxFormattedPreedit>();
29
+ qRegisterMetaType<FcitxFormattedPreeditList>("FcitxFormattedPreeditList");
30
+ qDBusRegisterMetaType<FcitxFormattedPreeditList>();
31
+ }
32
+
33
+ qint32 FcitxFormattedPreedit::format() const
34
+ {
35
+ return m_format;
36
+ }
37
+
38
+ const QString& FcitxFormattedPreedit::string() const
39
+ {
40
+ return m_string;
41
+ }
42
+
43
+ void FcitxFormattedPreedit::setFormat(qint32 format)
44
+ {
45
+ m_format = format;
46
+ }
47
+
48
+ void FcitxFormattedPreedit::setString(const QString& str)
49
+ {
50
+ m_string = str;
51
+ }
52
+
53
+
54
+ QDBusArgument& operator<<(QDBusArgument& argument, const FcitxFormattedPreedit& im)
55
+ {
56
+ argument.beginStructure();
57
+ argument << im.string();
58
+ argument << im.format();
59
+ argument.endStructure();
60
+ return argument;
61
+ }
62
+
63
+ const QDBusArgument& operator>>(const QDBusArgument& argument, FcitxFormattedPreedit& preedit)
64
+ {
65
+ QString str;
66
+ qint32 format;
67
+ argument.beginStructure();
68
+ argument >> str >> format;
69
+ argument.endStructure();
70
+ preedit.setString(str);
71
+ preedit.setFormat(format);
72
+ return argument;
73
+ }
pool/shard000/C++/0000025_WindowsUpdater.cpp ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <MellowPlayer/Infrastructure/Updater/Windows/WindowsUpdater.hpp>
2
+ #include <MellowPlayer/Infrastructure/Updater/Release.hpp>
3
+ #include <QApplication>
4
+ #include <QtCore/QDir>
5
+ #include <QtCore/QProcessEnvironment>
6
+
7
+ using namespace MellowPlayer::Infrastructure;
8
+
9
+ WindowsUpdater::WindowsUpdater(IFileDownloader& fileDownloader) : AbstractPlatformUpdater(fileDownloader)
10
+ {
11
+ }
12
+
13
+ bool WindowsUpdater::canInstall() const
14
+ {
15
+ return asset_.isValid() && asset_.isWindowsInstaller();
16
+ }
17
+
18
+ void WindowsUpdater::doInstall(const QString& assetLocalPath)
19
+ {
20
+ installerPath_ = assetLocalPath;
21
+ // no installation here, we'll start the installer when user clicked on restart
22
+ emit installFinished(QFile::exists(installerPath_));
23
+ }
24
+
25
+ QString WindowsUpdater::assetUrl() const
26
+ {
27
+ return asset_.url();
28
+ }
29
+
30
+ QString WindowsUpdater::assetFileName() const
31
+ {
32
+ return asset_.name();
33
+ }
34
+
35
+ void WindowsUpdater::setRelease(const Release* release)
36
+ {
37
+ AbstractPlatformUpdater::setRelease(release);
38
+
39
+ if (release_ != nullptr) {
40
+ for (auto& asset : release_->assets()) {
41
+ if (asset.isWindowsInstaller()) {
42
+ asset_ = asset;
43
+ break;
44
+ }
45
+ }
46
+ }
47
+ }
48
+
49
+ void WindowsUpdater::restart()
50
+ {
51
+ QProcess::startDetached(installerPath_);
52
+ qApp->quit();
53
+ }
pool/shard000/C++/0000029_P1MeterSerial.cpp ADDED
@@ -0,0 +1,167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include "stdafx.h"
2
+ #include "P1MeterSerial.h"
3
+ #include "../main/Logger.h"
4
+ #include "../main/localtime_r.h"
5
+ #include "../main/Helper.h"
6
+
7
+ //NOTE!!!, this code is partly based on the great work of RHekkers:
8
+ //https://github.com/rhekkers
9
+
10
+ #include <string>
11
+ #include <algorithm>
12
+ #include <iostream>
13
+ #include <boost/bind.hpp>
14
+
15
+ #include <ctime>
16
+
17
+ //
18
+ //Class P1MeterSerial
19
+ //
20
+ P1MeterSerial::P1MeterSerial(const int ID, const std::string& devname, unsigned int baud_rate):
21
+ m_szSerialPort(devname)
22
+ {
23
+ m_HwdID=ID;
24
+ m_iBaudRate=baud_rate;
25
+ m_stoprequested = false;
26
+ }
27
+
28
+ P1MeterSerial::P1MeterSerial(const std::string& devname,
29
+ unsigned int baud_rate,
30
+ boost::asio::serial_port_base::parity opt_parity,
31
+ boost::asio::serial_port_base::character_size opt_csize,
32
+ boost::asio::serial_port_base::flow_control opt_flow,
33
+ boost::asio::serial_port_base::stop_bits opt_stop)
34
+ :AsyncSerial(devname,baud_rate,opt_parity,opt_csize,opt_flow,opt_stop),
35
+ m_iBaudRate(baud_rate)
36
+ {
37
+ m_stoprequested = false;
38
+ }
39
+
40
+ P1MeterSerial::~P1MeterSerial()
41
+ {
42
+ clearReadCallback();
43
+ }
44
+
45
+ //#define DEBUG_FROM_FILE
46
+
47
+ bool P1MeterSerial::StartHardware()
48
+ {
49
+ #ifdef DEBUG_FROM_FILE
50
+ FILE *fIn=fopen("E:\\meter.txt","rb+");
51
+ BYTE buffer[1000];
52
+ int ret=fread((BYTE*)&buffer,1,sizeof(buffer),fIn);
53
+ fclose(fIn);
54
+ ParseData((const BYTE*)&buffer,ret);
55
+ #endif
56
+ m_stoprequested = false;
57
+ m_thread = boost::shared_ptr<boost::thread>(new boost::thread(boost::bind(&P1MeterSerial::Do_Work, this)));
58
+
59
+ //Try to open the Serial Port
60
+ try
61
+ {
62
+ _log.Log(LOG_STATUS,"P1 Smart Meter: Using serial port: %s", m_szSerialPort.c_str());
63
+ if (m_iBaudRate==9600)
64
+ {
65
+ open(
66
+ m_szSerialPort,
67
+ m_iBaudRate,
68
+ boost::asio::serial_port_base::parity(
69
+ boost::asio::serial_port_base::parity::even),
70
+ boost::asio::serial_port_base::character_size(7)
71
+ );
72
+ }
73
+ else
74
+ {
75
+ //DSMRv4
76
+ open(
77
+ m_szSerialPort,
78
+ m_iBaudRate,
79
+ boost::asio::serial_port_base::parity(
80
+ boost::asio::serial_port_base::parity::none),
81
+ boost::asio::serial_port_base::character_size(8)
82
+ );
83
+ }
84
+ }
85
+ catch (boost::exception & e)
86
+ {
87
+ _log.Log(LOG_ERROR,"P1 Smart Meter: Error opening serial port!");
88
+ #ifdef _DEBUG
89
+ _log.Log(LOG_ERROR,"-----------------\n%s\n-----------------",boost::diagnostic_information(e).c_str());
90
+ #endif
91
+ return false;
92
+ }
93
+ catch ( ... )
94
+ {
95
+ _log.Log(LOG_ERROR,"P1 Smart Meter: Error opening serial port!!!");
96
+ return false;
97
+ }
98
+ m_bIsStarted=true;
99
+ m_linecount=0;
100
+ m_exclmarkfound=0;
101
+ setReadCallback(boost::bind(&P1MeterSerial::readCallback, this, _1, _2));
102
+ sOnConnected(this);
103
+ return true;
104
+ }
105
+
106
+ bool P1MeterSerial::StopHardware()
107
+ {
108
+ if (isOpen())
109
+ {
110
+ try {
111
+ clearReadCallback();
112
+ close();
113
+ doClose();
114
+ setErrorStatus(true);
115
+ } catch(...)
116
+ {
117
+ //Don't throw from a Stop command
118
+ }
119
+ }
120
+ m_stoprequested = true;
121
+ if (m_thread)
122
+ {
123
+ m_thread->join();
124
+ // Wait a while. The read thread might be reading. Adding this prevents a pointer error in the async serial class.
125
+ sleep_milliseconds(10);
126
+ }
127
+ m_bIsStarted = false;
128
+ return true;
129
+ }
130
+
131
+
132
+ void P1MeterSerial::readCallback(const char *data, size_t len)
133
+ {
134
+ boost::lock_guard<boost::mutex> l(readQueueMutex);
135
+
136
+ if (!m_bEnableReceive)
137
+ return; //receiving not enabled
138
+
139
+ ParseData((const unsigned char*)data, static_cast<int>(len));
140
+ }
141
+
142
+ bool P1MeterSerial::WriteToHardware(const char *pdata, const unsigned char length)
143
+ {
144
+ return false;
145
+ }
146
+
147
+ void P1MeterSerial::Do_Work()
148
+ {
149
+ int sec_counter = 0;
150
+ int msec_counter = 0;
151
+ while (!m_stoprequested)
152
+ {
153
+ sleep_milliseconds(200);
154
+ if (m_stoprequested)
155
+ break;
156
+ msec_counter++;
157
+ if (msec_counter == 5)
158
+ {
159
+ msec_counter = 0;
160
+
161
+ sec_counter++;
162
+ if (sec_counter % 12 == 0) {
163
+ m_LastHeartbeat=mytime(NULL);
164
+ }
165
+ }
166
+ }
167
+ }
pool/shard000/C++/0000030_ReaderBinding.cpp ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //////////////////////////////////////////////////////////////////////////
2
+ //
3
+ // Copyright (c) 2007-2010, Image Engine Design 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 are
7
+ // met:
8
+ //
9
+ // * Redistributions of source code must retain the above copyright
10
+ // notice, this list of conditions and the following disclaimer.
11
+ //
12
+ // * 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
+ // * Neither the name of Image Engine Design nor the names of any
17
+ // other contributors to this software may be used to endorse or
18
+ // promote products derived from this software without specific prior
19
+ // written permission.
20
+ //
21
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22
+ // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23
+ // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24
+ // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25
+ // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26
+ // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27
+ // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28
+ // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29
+ // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30
+ // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31
+ // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
+ //
33
+ //////////////////////////////////////////////////////////////////////////
34
+
35
+ #include "boost/python.hpp"
36
+
37
+ #include "IECorePython/ReaderBinding.h"
38
+
39
+ #include "IECorePython/OpBinding.h"
40
+ #include "IECorePython/ScopedGILLock.h"
41
+ #include "IECorePython/ScopedGILRelease.h"
42
+
43
+ #include "IECore/FileNameParameter.h"
44
+ #include "IECore/Object.h"
45
+ #include "IECore/Reader.h"
46
+
47
+ using std::string;
48
+ using namespace boost;
49
+ using namespace boost::python;
50
+ using namespace IECore;
51
+ using namespace IECorePython;
52
+
53
+ namespace
54
+ {
55
+
56
+ static list supportedExtensions()
57
+ {
58
+ list result;
59
+ std::vector<std::string> e;
60
+ Reader::supportedExtensions( e );
61
+ for( unsigned int i=0; i<e.size(); i++ )
62
+ {
63
+ result.append( e[i] );
64
+ }
65
+ return result;
66
+ }
67
+
68
+ static list supportedExtensions( TypeId typeId )
69
+ {
70
+ list result;
71
+ std::vector<std::string> e;
72
+ Reader::supportedExtensions( typeId, e );
73
+ for( unsigned int i=0; i<e.size(); i++ )
74
+ {
75
+ result.append( e[i] );
76
+ }
77
+ return result;
78
+ }
79
+
80
+ struct ReaderCreator
81
+ {
82
+
83
+ ReaderCreator( object fn )
84
+ : m_fn( fn )
85
+ {
86
+ }
87
+
88
+ ReaderPtr operator()( const std::string &fileName )
89
+ {
90
+ ScopedGILLock gilLock;
91
+ ReaderPtr result = extract<ReaderPtr>( m_fn( fileName ) );
92
+ return result;
93
+ }
94
+
95
+ private :
96
+
97
+ object m_fn;
98
+
99
+ };
100
+
101
+ struct ReaderCanRead
102
+ {
103
+
104
+ ReaderCanRead( object fn )
105
+ : m_fn( fn )
106
+ {
107
+ }
108
+
109
+ bool operator()( const std::string &fileName )
110
+ {
111
+ ScopedGILLock gilLock;
112
+ bool result = m_fn( fileName );
113
+ return result;
114
+ }
115
+
116
+ private :
117
+
118
+ object m_fn;
119
+
120
+ };
121
+
122
+ static void registerReader( const std::string &extensions, object &canRead, object &creator, TypeId typeId )
123
+ {
124
+ Reader::registerReader( extensions, ReaderCanRead( canRead ), ReaderCreator( creator ), typeId );
125
+ }
126
+
127
+ } // namespace
128
+
129
+ namespace IECorePython
130
+ {
131
+
132
+ void bindReader()
133
+ {
134
+ using boost::python::arg;
135
+
136
+ ReaderClass<Reader, ReaderWrapper<Reader> >()
137
+ .def( init< const std::string &>( ( arg( "description" ) ) ) )
138
+ .def( "create", &Reader::create ).staticmethod( "create" )
139
+ .def( "supportedExtensions", ( list(*)( ) ) &supportedExtensions )
140
+ .def( "supportedExtensions", ( list(*)( IECore::TypeId ) ) &supportedExtensions )
141
+ .staticmethod( "supportedExtensions" )
142
+ .def( "registerReader", &registerReader )
143
+ .staticmethod( "registerReader" )
144
+ ;
145
+ }
146
+
147
+ } // namespace IECorePython
pool/shard000/C++/0000031_testcli.cpp ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2009 Stephen Liu
3
+ * For license terms, see the file COPYING along with this library.
4
+ */
5
+
6
+ #include <signal.h>
7
+ #include <stdio.h>
8
+ #include <stdlib.h>
9
+ #include <assert.h>
10
+ #include <string.h>
11
+ #include <ctype.h>
12
+
13
+ #include "spnetkit/spnksocket.hpp"
14
+ #include "spnetkit/spnklog.hpp"
15
+ #include "spnetkit/spnkgetopt.h"
16
+ #include "spnetkit/spnklist.hpp"
17
+
18
+ #include "sphivedbcli.hpp"
19
+ #include "sphivemsg.hpp"
20
+ #include "sphivejson.hpp"
21
+
22
+ void showUsage( const char * program )
23
+ {
24
+ printf( "\n\n%s [-h host] [-p port] [-t type]\n", program );
25
+ printf( "\t[-i dbfile] [-u user] [-n dbname] [-s sql] [-o] [-v]\n\n" );
26
+
27
+ printf( "\t-h http host\n" );
28
+ printf( "\t-p http port\n" );
29
+ printf( "\t-t rpc type, json/protobuf\n" );
30
+ printf( "\t-i dbfile\n" );
31
+ printf( "\t-u user\n" );
32
+ printf( "\t-n dbname\n" );
33
+ printf( "\t-s sql script\n" );
34
+ printf( "\t-o log socket io\n" );
35
+ printf( "\t-v show this usage\n" );
36
+ printf( "\n\n" );
37
+
38
+ exit( 0 );
39
+ }
40
+
41
+ void printResultSet( SP_HiveResultSet * rs )
42
+ {
43
+ printf( "row.count %d\n", rs->getRowCount() );
44
+
45
+ int column = rs->getColumnCount();
46
+
47
+ for( int i = 0; i < column; i++ ) {
48
+ printf( "\t%s(%s)", rs->getName(i), rs->getType(i) );
49
+ }
50
+
51
+ printf( "\n" );
52
+
53
+ for( int i = 0; i < rs->getRowCount(); i++ ) {
54
+ rs->moveTo( i );
55
+ for( int j = 0; j < column; j++ ) {
56
+ char tmp[ 32 ] = { 0 };
57
+ const char * val = rs->getAsString( j, tmp, sizeof( tmp ) );
58
+
59
+ printf( "\t[%s]", val );
60
+ }
61
+
62
+ printf( "\n" );
63
+ }
64
+ }
65
+
66
+ int main( int argc, char * argv[] )
67
+ {
68
+ SP_NKLog::init4test( "testcli" );
69
+ SP_NKLog::setLogLevel( LOG_DEBUG );
70
+
71
+ char * host = NULL, * port = NULL, * type = NULL;
72
+ char * dbfile = NULL, * user = NULL, * dbname = NULL, * sql = NULL;
73
+
74
+ extern char *optarg ;
75
+ int c ;
76
+
77
+ while( ( c = getopt( argc, argv, "h:p:t:i:u:n:s:ov" ) ) != EOF ) {
78
+ switch ( c ) {
79
+ case 'h' : host = optarg; break;
80
+ case 'p' : port = optarg; break;
81
+ case 't' : type = optarg; break;
82
+ case 'i' : dbfile = optarg; break;
83
+ case 'u' : user = optarg; break;
84
+ case 'n' : dbname = optarg; break;
85
+ case 's' : sql = optarg; break;
86
+ case 'o' : SP_NKSocket::setLogSocketDefault( 1 ); break;
87
+ case 'v' :
88
+ default: showUsage( argv[ 0 ] ); break;
89
+ }
90
+ }
91
+
92
+ if( NULL == host || NULL == host || NULL == dbfile
93
+ || NULL == user || NULL == dbname || NULL == sql ) {
94
+ showUsage( argv[ 0 ] );
95
+ }
96
+
97
+ SP_NKStringList sqlList;
98
+ {
99
+ sql = strdup( sql );
100
+
101
+ for( char * pos = sql; NULL != pos && '\0' != *pos; ) {
102
+ char * next = strchr( pos, ';' );
103
+ if( NULL != next ) *next = '\0';
104
+
105
+ for( ; isspace( *pos ); ) pos++;
106
+
107
+ if( '\0' != *pos ) sqlList.append( pos );
108
+
109
+ pos = next ? next + 1 : NULL;
110
+ }
111
+
112
+ free( sql );
113
+ }
114
+
115
+ int rpcType = SP_HiveDBClientConfig::eJsonRpc;
116
+
117
+ if( NULL != type && 0 == strcasecmp( type, "protobuf" ) ) {
118
+ rpcType = SP_HiveDBClientConfig::eProtoBufRpc;
119
+ }
120
+
121
+ SP_NKTcpSocket socket( host, atoi( port ) );
122
+
123
+ SP_HiveDBProtocol protocol( &socket, 0, rpcType );
124
+
125
+ SP_HiveRespObject * resp = protocol.execute( atoi( dbfile ), user, dbname, &sqlList );
126
+
127
+ if( NULL != resp ) {
128
+ if( 0 == resp->getErrorCode() ) {
129
+ printf( "result.count %d\n", resp->getResultCount() );
130
+
131
+ for( int i = 0; i < resp->getResultCount(); i++ ) {
132
+ SP_HiveResultSet * rs = resp->getResultSet( i );
133
+
134
+ printResultSet( rs );
135
+
136
+ delete rs;
137
+ }
138
+ } else {
139
+ printf( "execute fail, errcode %d, %s\n",
140
+ resp->getErrdataCode(), resp->getErrdataMsg() );
141
+ }
142
+
143
+ delete resp;
144
+ } else {
145
+ printf( "socket error\n" );
146
+ }
147
+
148
+ return 0;
149
+ }
150
+
pool/shard000/C++/0000036_main.cpp ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include "mainwindow.h"
2
+ #if SINGLE_APP
3
+ #include "singleapplication.h"
4
+ #endif
5
+
6
+ #include <QApplication>
7
+ #include <QDir>
8
+ #include <QTranslator>
9
+
10
+ /*! \mainpage QtPass
11
+ *
12
+ * \section intro_sec Introduction
13
+ *
14
+ * QtPass is a multi-platform GUI for pass, the standard unix password manager.
15
+ *
16
+ * https://qtpass.org/
17
+ *
18
+ * \section install_sec Installation
19
+ *
20
+ * \subsection dependencies Dependencies
21
+ *
22
+ * - QtPass requires Qt 5.2 or later.
23
+ * - The Linguist package is required to compile the translations.
24
+ * - For use of the fallback icons the SVG library is required.
25
+ *
26
+ * At runtime the only real dependency is gpg2 but to make the most of it,
27
+ * you'll need git and pass too.
28
+ *
29
+ * \subsection source From source
30
+ *
31
+ * On most *nix systems all you need is:
32
+ *
33
+ * `qmake && make && make install`
34
+ */
35
+
36
+ /**
37
+ * @brief main
38
+ * @param argc
39
+ * @param argv
40
+ * @return
41
+ */
42
+ int main(int argc, char *argv[]) {
43
+ #if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
44
+ QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
45
+ #endif
46
+ QString text = "";
47
+ for (int i = 1; i < argc; ++i) {
48
+ if (i > 1)
49
+ text += " ";
50
+ text += argv[i];
51
+ }
52
+
53
+ if ((text.indexOf("-psn_") == 0) || (text.indexOf("-session") == 0)) {
54
+ text.clear();
55
+ }
56
+
57
+ #if SINGLE_APP
58
+ QString name = qgetenv("USER");
59
+ if (name.isEmpty())
60
+ name = qgetenv("USERNAME");
61
+ SingleApplication app(argc, argv, name + "QtPass");
62
+ if (app.isRunning()) {
63
+ if (text.length() > 0)
64
+ app.sendMessage(text);
65
+ return 0;
66
+ }
67
+ #else
68
+ QApplication app(argc, argv);
69
+ #endif
70
+
71
+ Q_INIT_RESOURCE(resources);
72
+ Q_INIT_RESOURCE(qmake_qmake_qm_files); // qmake names the file
73
+
74
+ QCoreApplication::setOrganizationName("IJHack");
75
+ QCoreApplication::setOrganizationDomain("ijhack.org");
76
+ QCoreApplication::setApplicationName("QtPass");
77
+ QCoreApplication::setApplicationVersion(VERSION);
78
+
79
+ // Setup and load translator for localization
80
+ QTranslator translator;
81
+ QString locale = QLocale::system().name();
82
+ // locale = "nl_NL";
83
+ // locale = "he_IL";
84
+ // locale = "ar_MA";
85
+ translator.load(QString(":localization/localization_%1.qm").arg(locale));
86
+ SingleApplication::installTranslator(&translator);
87
+ SingleApplication::setLayoutDirection(
88
+ QObject::tr("LTR") == "RTL" ? Qt::RightToLeft : Qt::LeftToRight);
89
+ MainWindow w(text);
90
+
91
+ SingleApplication::setActiveWindow(&w);
92
+ SingleApplication::setWindowIcon(QIcon(":artwork/icon.png"));
93
+
94
+ #if SINGLE_APP
95
+ QObject::connect(&app, &SingleApplication::messageAvailable, &w,
96
+ &MainWindow::messageAvailable);
97
+ #endif
98
+
99
+ #if (QT_VERSION >= QT_VERSION_CHECK(5, 7, 0))
100
+ QGuiApplication::setDesktopFileName("qtpass.desktop");
101
+ #endif
102
+
103
+ w.show();
104
+
105
+ return SingleApplication::exec();
106
+ }
pool/shard000/C++/0000043_Syntax.cpp ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //===--- Syntax.cpp - Swift Syntax Implementation -------------------------===//
2
+ //
3
+ // This source file is part of the Swift.org open source project
4
+ //
5
+ // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6
+ // Licensed under Apache License v2.0 with Runtime Library Exception
7
+ //
8
+ // See https://swift.org/LICENSE.txt for license information
9
+ // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10
+ //
11
+ //===----------------------------------------------------------------------===//
12
+
13
+ #include "swift/Syntax/Syntax.h"
14
+ #include "swift/Syntax/SyntaxData.h"
15
+ #include "swift/Syntax/SyntaxVisitor.h"
16
+ #include "swift/Syntax/TokenSyntax.h"
17
+
18
+ using namespace swift;
19
+ using namespace swift::syntax;
20
+
21
+ const RC<RawSyntax> &Syntax::getRaw() const {
22
+ return Data->getRaw();
23
+ }
24
+
25
+ SyntaxKind Syntax::getKind() const {
26
+ return getRaw()->getKind();
27
+ }
28
+
29
+ void Syntax::print(llvm::raw_ostream &OS, SyntaxPrintOptions Opts) const {
30
+ if (auto Raw = getRaw())
31
+ Raw->print(OS, Opts);
32
+ }
33
+
34
+ void Syntax::dump() const {
35
+ getRaw()->dump();
36
+ }
37
+
38
+ void Syntax::dump(llvm::raw_ostream &OS, unsigned Indent) const {
39
+ getRaw()->dump(OS, 0);
40
+ }
41
+
42
+ bool Syntax::isType() const {
43
+ return Data->isType();
44
+ }
45
+
46
+ bool Syntax::isDecl() const {
47
+ return Data->isDecl();
48
+ }
49
+
50
+ bool Syntax::isStmt() const {
51
+ return Data->isStmt();
52
+ }
53
+
54
+ bool Syntax::isExpr() const {
55
+ return Data->isExpr();
56
+ }
57
+
58
+ bool Syntax::isToken() const {
59
+ return getRaw()->isToken();
60
+ }
61
+
62
+ bool Syntax::isPattern() const {
63
+ return Data->isPattern();
64
+ }
65
+
66
+ bool Syntax::isUnknown() const {
67
+ return Data->isUnknown();
68
+ }
69
+
70
+ bool Syntax::isPresent() const {
71
+ return getRaw()->isPresent();
72
+ }
73
+
74
+ bool Syntax::isMissing() const {
75
+ return getRaw()->isMissing();
76
+ }
77
+
78
+ llvm::Optional<Syntax> Syntax::getParent() const {
79
+ auto ParentData = getData().getParent();
80
+ if (!ParentData) return llvm::None;
81
+ return llvm::Optional<Syntax> {
82
+ Syntax { Root, ParentData }
83
+ };
84
+ }
85
+
86
+ Syntax Syntax::getRoot() const {
87
+ return { Root, Root.get() };
88
+ }
89
+
90
+ size_t Syntax::getNumChildren() const {
91
+ return Data->getNumChildren();
92
+ }
93
+
94
+ llvm::Optional<Syntax> Syntax::getChild(const size_t N) const {
95
+ auto ChildData = Data->getChild(N);
96
+ if (!ChildData)
97
+ return llvm::None;
98
+ return Syntax {Root, ChildData.get()};
99
+ }
100
+
101
+ Optional<TokenSyntax> Syntax::getFirstToken() const {
102
+ if (auto tok = getData().getFirstToken())
103
+ return TokenSyntax(Root, tok.get());
104
+ return None;
105
+ }
106
+
107
+ Optional<TokenSyntax> Syntax::getLastToken() const {
108
+ if (auto tok = getData().getLastToken())
109
+ return TokenSyntax(Root, tok.get());
110
+ return None;
111
+ }
pool/shard000/C++/0000053_random_sample.cpp ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <iostream>
2
+ #include <random>
3
+ using namespace std;
4
+
5
+ //given an array of numbers, produce a sample of size K of them.
6
+ //algorithm: swap(array[i++],array[random]) k times -> so that the first k elements are the random sample
7
+
8
+ void swap(int array[],int a,int b){
9
+ if(a!=b){
10
+ array[a]^=array[b];
11
+ array[b]^=array[a];
12
+ array[a]^=array[b];
13
+ }
14
+ }
15
+
16
+ int main(){
17
+
18
+ int numbers[]={1,2,3,4,5,6,7,8,9,10};
19
+ int n=sizeof(numbers)/sizeof(int);
20
+
21
+ random_device rd;
22
+ default_random_engine gen(rd());
23
+
24
+ int sampleSize=4;
25
+
26
+ for(int i=0;i<sampleSize;i++){
27
+ uniform_int_distribution<int> dis(i,n-1);
28
+ swap(numbers,i,dis(gen));
29
+ }
30
+
31
+ //print random sample of size sampleSize
32
+ for(int i=0;i<sampleSize;i++){
33
+ cout<<numbers[i]<<" ";
34
+ }
35
+ cout<<endl;
36
+
37
+
38
+
39
+ return 0;
40
+ }
pool/shard000/C++/0000055_Point.cpp ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include "stdafx.h"
2
+ #include "Point.h"
3
+
4
+ CPoint::CPoint()
5
+ {
6
+ x = y = 0;
7
+ }
8
+
9
+ CPoint::CPoint(DWORD Value)
10
+ {
11
+ x = LOWORD(Value);
12
+ y = HIWORD(Value);
13
+ }
14
+
15
+ CPoint::CPoint(LONG X, LONG Y)
16
+ {
17
+ x = X;
18
+ y = Y;
19
+ }
20
+
21
+ CSize CPoint::operator-(const CPoint& Other) const
22
+ {
23
+ return CSize(Other.x - x, Other.y - y);
24
+ }
pool/shard000/C++/0000060_main.cpp ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include "mainwindow.h"
2
+ #include <QApplication>
3
+ #include <QDesktopWidget>
4
+ #include <QPalette>
5
+
6
+ int main(int argc, char *argv[])
7
+ {
8
+ QApplication a(argc, argv);
9
+ MainWindow w;
10
+
11
+ QDesktopWidget dw;
12
+ int x=dw.width()*0.7;
13
+ int y=dw.height()*0.7;
14
+ //w.setFixedSize(x,y);
15
+ //QRect rect(0, 0, 240, 320);
16
+ //frame->setFrameShape(QFrame::Box);
17
+ //frame->setLineWidth(3);
18
+ //frame->setFrameShadow(QFrame::Plain);
19
+ //frame->setGeometry(rect);
20
+
21
+ //adjustSize();
22
+
23
+ //void createHorizontalGroupBox();
24
+
25
+ //QPalette pal = palette();
26
+ //pal.setColor(QPalette::Background, Qt::black);
27
+ //w.setAutoFillBackground(true);
28
+ //w.setPalette(pal);
29
+
30
+ // QPushButton hello( "Hello world!", 0 );
31
+ // hello.resize( 100, 30 );
32
+ // a.setMainWidget( &hello );
33
+ // hello.show();
34
+
35
+ w.show();
36
+
37
+ return a.exec();
38
+ }
pool/shard000/C++/0000061_CElmPhotocam.cc ADDED
@@ -0,0 +1,184 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include "elm.h"
2
+ #include "CElmPhotocam.h"
3
+
4
+ namespace elm {
5
+
6
+ using namespace v8;
7
+
8
+ GENERATE_PROPERTY_CALLBACKS(CElmPhotocam, file);
9
+ GENERATE_PROPERTY_CALLBACKS(CElmPhotocam, zoom);
10
+ GENERATE_PROPERTY_CALLBACKS(CElmPhotocam, zoom_mode);
11
+ GENERATE_PROPERTY_CALLBACKS(CElmPhotocam, paused);
12
+ GENERATE_PROPERTY_CALLBACKS(CElmPhotocam, gesture_enabled);
13
+ GENERATE_RO_PROPERTY_CALLBACKS(CElmPhotocam, image_size);
14
+ GENERATE_RO_PROPERTY_CALLBACKS(CElmPhotocam, image_region);
15
+ GENERATE_METHOD_CALLBACKS(CElmPhotocam, image_region_show);
16
+ GENERATE_METHOD_CALLBACKS(CElmPhotocam, image_region_bring_in);
17
+
18
+ GENERATE_TEMPLATE_FULL(CElmObject, CElmPhotocam,
19
+ PROPERTY(file),
20
+ PROPERTY(zoom),
21
+ PROPERTY(zoom_mode),
22
+ PROPERTY(paused),
23
+ PROPERTY(gesture_enabled),
24
+ PROPERTY_RO(image_size),
25
+ PROPERTY_RO(image_region),
26
+ METHOD(image_region_show),
27
+ METHOD(image_region_bring_in));
28
+
29
+ CElmPhotocam::CElmPhotocam(Local<Object> _jsObject, CElmObject *parent)
30
+ : CElmObject(_jsObject, elm_photocam_add(elm_object_top_widget_get(parent->GetEvasObject())))
31
+ {
32
+ }
33
+
34
+ void CElmPhotocam::Initialize(Handle<Object> target)
35
+ {
36
+ target->Set(String::NewSymbol("Photocam"), GetTemplate()->GetFunction());
37
+ }
38
+
39
+ void CElmPhotocam::file_set(Handle<Value> val)
40
+ {
41
+ if (!val->IsString())
42
+ return;
43
+
44
+ String::Utf8Value str(val);
45
+ if (!access(*str, R_OK))
46
+ {
47
+ elm_photocam_file_set(eo, *str);
48
+ return;
49
+ }
50
+
51
+ ELM_ERR("warning: can't read image file %s", *str);
52
+ }
53
+
54
+ Handle<Value> CElmPhotocam::file_get(void) const
55
+ {
56
+ const char *file = elm_photocam_file_get(eo);
57
+ return file ? String::New(file) : Null();
58
+ }
59
+
60
+ Handle<Value> CElmPhotocam::zoom_get() const
61
+ {
62
+ return Number::New(elm_photocam_zoom_get(eo));
63
+ }
64
+
65
+ void CElmPhotocam::zoom_set(Handle<Value> value)
66
+ {
67
+ if (value->IsNumber())
68
+ elm_photocam_zoom_set(eo, value->NumberValue());
69
+ }
70
+
71
+ Handle<Value> CElmPhotocam::zoom_mode_get() const
72
+ {
73
+ switch (elm_photocam_zoom_mode_get(eo)) {
74
+ case ELM_PHOTOCAM_ZOOM_MODE_MANUAL:
75
+ return String::NewSymbol("manual");
76
+ case ELM_PHOTOCAM_ZOOM_MODE_AUTO_FIT:
77
+ return String::NewSymbol("auto-fit");
78
+ case ELM_PHOTOCAM_ZOOM_MODE_AUTO_FILL:
79
+ return String::NewSymbol("auto-fill");
80
+ default:
81
+ return String::NewSymbol("auto-fit-in");
82
+ }
83
+ }
84
+
85
+ void CElmPhotocam::zoom_mode_set(Handle<Value> value)
86
+ {
87
+ Elm_Photocam_Zoom_Mode new_mode;
88
+
89
+ if (value->IsNumber())
90
+ new_mode = (Elm_Photocam_Zoom_Mode)value->NumberValue();
91
+ else if (value->IsString())
92
+ {
93
+ String::Utf8Value mode(value->ToString());
94
+ if (!strcmp(*mode, "manual"))
95
+ new_mode = ELM_PHOTOCAM_ZOOM_MODE_MANUAL;
96
+ else if (!strcmp(*mode, "auto-fit"))
97
+ new_mode = ELM_PHOTOCAM_ZOOM_MODE_AUTO_FIT;
98
+ else if (!strcmp(*mode, "auto-fill"))
99
+ new_mode = ELM_PHOTOCAM_ZOOM_MODE_AUTO_FILL;
100
+ else
101
+ new_mode = ELM_PHOTOCAM_ZOOM_MODE_AUTO_FIT_IN;
102
+ }
103
+ else
104
+ new_mode = ELM_PHOTOCAM_ZOOM_MODE_MANUAL;
105
+
106
+ elm_photocam_zoom_mode_set(eo, new_mode);
107
+ }
108
+
109
+ void CElmPhotocam::paused_set(Handle<Value> val)
110
+ {
111
+ elm_photocam_paused_set(eo, val->BooleanValue());
112
+ }
113
+
114
+ Handle<Value> CElmPhotocam::paused_get() const
115
+ {
116
+ return Boolean::New(elm_photocam_paused_get(eo));
117
+ }
118
+
119
+ void CElmPhotocam::gesture_enabled_set(Handle<Value> val)
120
+ {
121
+ elm_photocam_gesture_enabled_set(eo, val->BooleanValue());
122
+ }
123
+
124
+ Handle<Value> CElmPhotocam::gesture_enabled_get() const
125
+ {
126
+ return Boolean::New(elm_photocam_gesture_enabled_get(eo));
127
+ }
128
+
129
+ Handle<Value> CElmPhotocam::image_region_get() const
130
+ {
131
+ HandleScope scope;
132
+
133
+ int x, y, w, h;
134
+ elm_photocam_image_region_get(eo, &x, &y, &w, &h);
135
+
136
+ Local<Object> obj = Object::New();
137
+ obj->Set(String::NewSymbol("x"), Number::New(x));
138
+ obj->Set(String::NewSymbol("y"), Number::New(y));
139
+ obj->Set(String::NewSymbol("width"), Number::New(w));
140
+ obj->Set(String::NewSymbol("height"), Number::New(h));
141
+
142
+ return scope.Close(obj);
143
+ }
144
+
145
+ Handle<Value> CElmPhotocam::image_size_get() const
146
+ {
147
+ HandleScope scope;
148
+
149
+ int w, h;
150
+ elm_photocam_image_size_get(eo, &w, &h);
151
+
152
+ Local<Object> obj = Object::New();
153
+ obj->Set(String::NewSymbol("width"), Number::New(w));
154
+ obj->Set(String::NewSymbol("height"), Number::New(h));
155
+
156
+ return scope.Close(obj);
157
+ }
158
+
159
+ Handle<Value> CElmPhotocam::image_region_show(const Arguments &args)
160
+ {
161
+ for (int i = 0; i < 4; i++)
162
+ if (!args[i]->IsNumber())
163
+ return Undefined();
164
+
165
+ elm_photocam_image_region_show(eo, args[0]->ToInt32()->Value(), args[1]->ToInt32()->Value(),
166
+ args[2]->ToInt32()->Value(), args[3]->ToInt32()->Value());
167
+
168
+ return Undefined();
169
+
170
+ }
171
+
172
+ Handle<Value> CElmPhotocam::image_region_bring_in(const Arguments &args)
173
+ {
174
+ for (int i = 0; i < 4; i++)
175
+ if (!args[i]->IsNumber())
176
+ return Undefined();
177
+
178
+ elm_photocam_image_region_bring_in(eo, args[0]->ToInt32()->Value(), args[1]->ToInt32()->Value(),
179
+ args[2]->ToInt32()->Value(), args[3]->ToInt32()->Value());
180
+
181
+ return Undefined();
182
+ }
183
+
184
+ }
pool/shard000/C++/0000065_modelprinter.cpp ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2013 Canonical Ltd.
3
+ *
4
+ * This program is free software; you can redistribute it and/or modify
5
+ * it under the terms of the GNU Lesser General Public License as published by
6
+ * the Free Software Foundation; version 3.
7
+ *
8
+ * This program is distributed in the hope that it will be useful,
9
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ * GNU Lesser General Public License for more details.
12
+ *
13
+ * You should have received a copy of the GNU Lesser General Public License
14
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15
+ *
16
+ * Authors:
17
+ * Nick Dedekind <nick.dedekind@canonical.com>
18
+ */
19
+
20
+ // self
21
+ #include "modelprinter.h"
22
+
23
+ #include <unitymenumodel.h>
24
+
25
+ // Qt
26
+ #include <QTextStream>
27
+
28
+ ModelPrinter::ModelPrinter(QObject *parent)
29
+ : QObject(parent)
30
+ , m_model(nullptr)
31
+ {
32
+ }
33
+
34
+ void ModelPrinter::setSourceModel(UnityMenuModel * sourceModel)
35
+ {
36
+ if (m_model != nullptr) {
37
+ disconnect(m_model);
38
+ }
39
+ if (m_model != sourceModel) {
40
+ m_model = sourceModel;
41
+ Q_EMIT modelChanged();
42
+ Q_EMIT textChanged();
43
+ }
44
+ if (m_model != nullptr) {
45
+ connect(m_model, &UnityMenuModel::rowsInserted, this, &ModelPrinter::textChanged);
46
+ connect(m_model, &UnityMenuModel::rowsRemoved, this, &ModelPrinter::textChanged);
47
+ connect(m_model, &UnityMenuModel::dataChanged, this, &ModelPrinter::textChanged);
48
+ }
49
+ }
50
+
51
+ UnityMenuModel* ModelPrinter::sourceModel() const
52
+ {
53
+ return m_model;
54
+ }
55
+
56
+ QString ModelPrinter::text()
57
+ {
58
+ return getModelDataString(m_model, 0);
59
+ }
60
+
61
+ QString tabify(int level) { QString str;
62
+ for (int i = 0; i < level; i++) {
63
+ str += QLatin1String(" ");
64
+ }
65
+ return str;
66
+ }
67
+
68
+ QString ModelPrinter::getModelDataString(UnityMenuModel* sourceModel, int level)
69
+ {
70
+ if (!sourceModel)
71
+ return QLatin1String("");
72
+
73
+ QString str;
74
+ QTextStream stream(&str);
75
+
76
+ int rowCount = sourceModel->rowCount();
77
+ for (int row = 0; row < rowCount; row++) {
78
+
79
+ stream << getRowSring(sourceModel, row, level) << endl;
80
+
81
+ UnityMenuModel* childMenuModel = qobject_cast<UnityMenuModel*>(sourceModel->submenu(row));
82
+ if (childMenuModel) {
83
+
84
+ if (!m_children.contains(childMenuModel)) {
85
+ m_children << childMenuModel;
86
+ connect(childMenuModel, &UnityMenuModel::rowsInserted, this, &ModelPrinter::textChanged);
87
+ connect(childMenuModel, &UnityMenuModel::rowsRemoved, this, &ModelPrinter::textChanged);
88
+ connect(childMenuModel, &UnityMenuModel::dataChanged, this, &ModelPrinter::textChanged);
89
+ }
90
+ stream << getModelDataString(childMenuModel, level+1);
91
+ }
92
+ }
93
+ return str;
94
+ }
95
+
96
+ QString ModelPrinter::getRowSring(UnityMenuModel* sourceModel, int row, int depth) const
97
+ {
98
+ QString str;
99
+ QTextStream stream(&str);
100
+
101
+ // Print out this row
102
+ QHash<int, QByteArray> roleNames = sourceModel->roleNames();
103
+ QList<int> roles = roleNames.keys();
104
+ qSort(roles);
105
+
106
+ Q_FOREACH(int role, roles) {
107
+ const QByteArray& roleName = roleNames[role];
108
+ stream << getVariantString(roleName, sourceModel->get(row, roleName), depth);
109
+ }
110
+ return str;
111
+ }
112
+
113
+ QString ModelPrinter::getVariantString(const QVariant& vData) const
114
+ {
115
+ if (vData.type() == QVariant::List) {
116
+ QStringList strList;
117
+ for (const auto& v : vData.toList())
118
+ strList.append(getVariantString(v));
119
+
120
+ return '[' + strList.join(", ") + ']';
121
+ }
122
+
123
+ return vData.toString();
124
+ }
125
+
126
+ QString ModelPrinter::getVariantString(const QString& roleName, const QVariant &vData, int depth) const
127
+ {
128
+ QString str;
129
+ QTextStream stream(&str);
130
+
131
+ if (vData.canConvert(QMetaType::QVariantMap)) {
132
+ QMapIterator<QString, QVariant> iter(vData.toMap());
133
+ while (iter.hasNext()) {
134
+ iter.next();
135
+ stream << tabify(depth);
136
+ stream << roleName
137
+ << "."
138
+ << iter.key()
139
+ << ": "
140
+ << getVariantString(iter.value())
141
+ << endl;
142
+ }
143
+ }
144
+ else {
145
+ stream << tabify(depth);
146
+ stream << roleName
147
+ << ": "
148
+ << getVariantString(vData)
149
+ << endl;
150
+ }
151
+ return str;
152
+ }
pool/shard000/C++/0000067_main.cpp ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright (c) 2012-2013 The Cryptonote 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/program_options.hpp>
6
+
7
+ #include "include_base_utils.h"
8
+ using namespace epee;
9
+
10
+ #include "common/command_line.h"
11
+ #include "transactions_flow_test.h"
12
+
13
+ namespace po = boost::program_options;
14
+
15
+ namespace
16
+ {
17
+ const command_line::arg_descriptor<bool> arg_test_transactions_flow = {"test_transactions_flow", ""};
18
+
19
+ const command_line::arg_descriptor<std::string> arg_working_folder = {"working-folder", "", "."};
20
+ const command_line::arg_descriptor<std::string> arg_source_wallet = {"source-wallet", "", "", true};
21
+ const command_line::arg_descriptor<std::string> arg_dest_wallet = {"dest-wallet", "", "", true};
22
+ const command_line::arg_descriptor<std::string> arg_daemon_addr_a = {"daemon-addr-a", "", "127.0.0.1:8080"};
23
+ const command_line::arg_descriptor<std::string> arg_daemon_addr_b = {"daemon-addr-b", "", "127.0.0.1:8082"};
24
+
25
+ const command_line::arg_descriptor<uint64_t> arg_transfer_amount = {"transfer_amount", "", 60000000000000};
26
+ const command_line::arg_descriptor<size_t> arg_mix_in_factor = {"mix-in-factor", "", 10};
27
+ const command_line::arg_descriptor<size_t> arg_tx_count = {"tx-count", "", 100};
28
+ const command_line::arg_descriptor<size_t> arg_tx_per_second = {"tx-per-second", "", 20};
29
+ const command_line::arg_descriptor<size_t> arg_test_repeat_count = {"test_repeat_count", "", 1};
30
+ }
31
+
32
+ int main(int argc, char* argv[])
33
+ {
34
+ TRY_ENTRY();
35
+ string_tools::set_module_name_and_folder(argv[0]);
36
+
37
+ //set up logging options
38
+ log_space::get_set_log_detalisation_level(true, LOG_LEVEL_3);
39
+ log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL, LOG_LEVEL_2);
40
+ log_space::log_singletone::add_logger(LOGGER_FILE,
41
+ log_space::log_singletone::get_default_log_file().c_str(),
42
+ log_space::log_singletone::get_default_log_folder().c_str());
43
+
44
+ po::options_description desc_options("Allowed options");
45
+ command_line::add_arg(desc_options, command_line::arg_help);
46
+
47
+ command_line::add_arg(desc_options, arg_test_transactions_flow);
48
+
49
+ command_line::add_arg(desc_options, arg_working_folder);
50
+ command_line::add_arg(desc_options, arg_source_wallet);
51
+ command_line::add_arg(desc_options, arg_dest_wallet);
52
+ command_line::add_arg(desc_options, arg_daemon_addr_a);
53
+ command_line::add_arg(desc_options, arg_daemon_addr_b);
54
+
55
+ command_line::add_arg(desc_options, arg_transfer_amount);
56
+ command_line::add_arg(desc_options, arg_mix_in_factor);
57
+ command_line::add_arg(desc_options, arg_tx_count);
58
+ command_line::add_arg(desc_options, arg_tx_per_second);
59
+ command_line::add_arg(desc_options, arg_test_repeat_count);
60
+
61
+ po::variables_map vm;
62
+ bool r = command_line::handle_error_helper(desc_options, [&]()
63
+ {
64
+ po::store(po::parse_command_line(argc, argv, desc_options), vm);
65
+ po::notify(vm);
66
+ return true;
67
+ });
68
+ if (!r)
69
+ return 1;
70
+
71
+ if (command_line::get_arg(vm, command_line::arg_help))
72
+ {
73
+ std::cout << desc_options << std::endl;
74
+ return 0;
75
+ }
76
+
77
+ if (command_line::get_arg(vm, arg_test_transactions_flow))
78
+ {
79
+ std::string working_folder = command_line::get_arg(vm, arg_working_folder);
80
+ std::string path_source_wallet, path_target_wallet;
81
+ if(command_line::has_arg(vm, arg_source_wallet))
82
+ path_source_wallet = command_line::get_arg(vm, arg_source_wallet);
83
+ if(command_line::has_arg(vm, arg_dest_wallet))
84
+ path_target_wallet = command_line::get_arg(vm, arg_dest_wallet);
85
+
86
+ std::string daemon_addr_a = command_line::get_arg(vm, arg_daemon_addr_a);
87
+ std::string daemon_addr_b = command_line::get_arg(vm, arg_daemon_addr_b);
88
+ uint64_t amount_to_transfer = command_line::get_arg(vm, arg_transfer_amount);
89
+ size_t mix_in_factor = command_line::get_arg(vm, arg_mix_in_factor);
90
+ size_t transactions_count = command_line::get_arg(vm, arg_tx_count);
91
+ size_t transactions_per_second = command_line::get_arg(vm, arg_tx_per_second);
92
+ size_t repeat_count = command_line::get_arg(vm, arg_test_repeat_count);
93
+
94
+ for(size_t i = 0; i != repeat_count; i++)
95
+ if(!transactions_flow_test(working_folder, path_source_wallet, path_target_wallet, daemon_addr_a, daemon_addr_b, amount_to_transfer, mix_in_factor, transactions_count, transactions_per_second))
96
+ break;
97
+
98
+ std::string s;
99
+ std::cin >> s;
100
+
101
+ return 1;
102
+ }
103
+ else
104
+ {
105
+ std::cout << desc_options << std::endl;
106
+ return 1;
107
+ }
108
+
109
+ CATCH_ENTRY_L0("main", 1);
110
+
111
+ return 0;
112
+ }
pool/shard000/C++/0000069_mpmat_test.cpp ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include "../../src/SDPSolver.h"
2
+ #include "../../src/Timers.h"
3
+ #include "../../src/parse.h"
4
+
5
+ // FIXME: This should not be a global
6
+ Timers timers;
7
+
8
+ int main() {
9
+
10
+ mp_bitcnt_t precision(512);
11
+ mpf_set_default_prec(precision);
12
+
13
+ Real residue("10e-" + std::to_string(std::floor(precision/(log(10)/log(2)))));
14
+ Real sqrt_residue(sqrt(residue));
15
+
16
+ const size_t Nx(9224), Ny(368);
17
+ Matrix matrix(Nx, Ny), square_gmp(Ny, Ny);
18
+ for (size_t i = 0; i < Nx; ++i)
19
+ for (size_t j = 0; j < Ny; ++j) {
20
+ Real ri(i + 1), rj(j+1);
21
+ matrix.elt(i, j) = ri + rj*rj - sqrt_residue;
22
+ }
23
+
24
+ matrixSquareIntoBlock(matrix, square_gmp, 0, 0);
25
+
26
+ mpmat workspace(1);
27
+ mpf_set_default_prec(mpf_get_default_prec() + 256);
28
+ Matrix square_mpmat(Ny, Ny);
29
+ mpf_set_default_prec(mpf_get_default_prec() - 256);
30
+
31
+ matrixSquareIntoBlockMpmat(workspace, matrix, square_mpmat, 0, 0);
32
+
33
+ bool passed (true);
34
+ std::cout.precision(static_cast<int>(precision * 0.31 + 5));
35
+ for (size_t i = 0; i < Ny; ++i) {
36
+ for (size_t j = 0; j < Ny; ++j) {
37
+ if (abs((square_gmp.elt(i, j) - square_mpmat.elt(i, j)) /
38
+ (square_gmp.elt(i, j) + square_mpmat.elt(i, j))) > residue)
39
+ {
40
+ passed=false;
41
+ std::cout << i << " " << j << "\n\t"
42
+ << "square_gmp: " << square_gmp.elt(i, j) << "\n\t"
43
+ << "square_mpmat: " << square_mpmat.elt(i, j) << "\n\t"
44
+ << "target residue: " << residue << "\n\t"
45
+ << "measured residue: "
46
+ << (square_gmp.elt(i, j) - square_mpmat.elt(i, j)) << "\n";
47
+ }
48
+ }
49
+ }
50
+ if(passed)
51
+ { std::cout << "PASS: sqrt(1-epsilon)^2\n"; }
52
+ else
53
+ { std::cout << "FAIL: sqrt(1-epsilon)^2\n"; }
54
+
55
+ // SDPSolverParameters parameters;
56
+ // parameters.precision = 2048;
57
+ // parameters.resetPrecision();
58
+ // parameters.maxThreads = 1;
59
+ // // parameters.maxThreads=128;
60
+
61
+ // omp_set_num_threads(parameters.maxThreads);
62
+
63
+ // SDPSolver solver(readBootstrapSDP(std::vector<boost::filesystem::path>(
64
+ // // {"../inputs/TTTTtestsmall.xml"})),
65
+ // {"test/mpmat/input.xml"})),
66
+ // parameters);
67
+ // solver.testMultiplication(1, 1, 5);
68
+ }
pool/shard000/C++/0000081_B._Volcanoes.cpp ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include<iostream>
2
+ #include<cstring>
3
+ #define MAX 1000000005//too long
4
+ using namespace std;
5
+ bool visited [MAX][MAX];
6
+ bool planet [MAX][MAX];
7
+ int n;
8
+ bool valid (int i, int j)
9
+ {
10
+ return i>=0 && j>=0 && i<n && j<n && planet[i][j];
11
+ }
12
+ bool dfs(int i, int j)
13
+ {
14
+ if(i==n-1 && j==n-1 ) return true;
15
+ visited [i][j]=true;
16
+ int ni1=i+1;
17
+ int nj1=j;
18
+ int ni2=i;
19
+ int nj2=j+1;
20
+ if(!visited[ni1][nj1] && valid(ni1,nj1) && !visited[ni2][nj2] && valid(ni2,nj2))
21
+ return dfs(ni1,nj1) || dfs(ni2,nj2);
22
+ else if(!visited[ni1][nj1] && valid(ni1,nj1))
23
+ return dfs(ni1,nj2);
24
+ else if(!visited[ni2][nj2] && valid(ni2,nj2))
25
+ return dfs(ni2,nj2);
26
+ else return false;
27
+ }
28
+ int main()
29
+ {
30
+ int m;
31
+ cin>>n>>m;
32
+ memset(visited,false, n+5);
33
+ memset(planet,true,n+5);
34
+ bool flag=true;
35
+ for(int i=0;i<m;i++)
36
+ {
37
+ int x,y;
38
+ cin>>x>>y;
39
+ if(x==n && y==n)
40
+ {
41
+ flag=false;
42
+ break;
43
+ }
44
+ planet [x-1][y-1]=false;
45
+ }
46
+ if(!flag)
47
+ cout<<-1<<endl;
48
+ else
49
+ {
50
+ bool ans=dfs(0,0);
51
+ if(ans)
52
+ cout<<2*n-2<<endl;
53
+ else
54
+ cout<<-1<<endl;
55
+ }
56
+ }
57
+
pool/shard000/C++/0000084_main.cpp ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <iostream>
2
+ #include <cstdio>
3
+
4
+ using namespace std;
5
+
6
+ int N;
7
+ long long map[100001];
8
+ long long solve(int left, int right);
9
+ int main()
10
+ {
11
+ scanf("%d", &N);
12
+ for(int i=0; i<N; i++) scanf("%lld", &map[i]);
13
+ printf("%lld\n", solve(0,N-1));
14
+ return 0;
15
+ }
16
+
17
+ long long solve(int left, int right)
18
+ {
19
+ if(left == right) return map[right]*map[right];
20
+
21
+ int mid = (left+right)/2;
22
+ long long ret = max(solve(left, mid), solve(mid+1, right));
23
+
24
+ int lo = mid;
25
+ int hi = mid+1;
26
+ long long height = min(map[lo],map[hi]);
27
+ long long width = map[lo]+map[hi];
28
+ ret = max(ret, height*width);
29
+ while(left < lo || hi < right) {
30
+ if(hi < right && (left == lo || map[lo-1]<map[hi+1])) {
31
+ ++hi;
32
+ height = min(height, map[hi]);
33
+ width += map[hi];
34
+ } else {
35
+ --lo;
36
+ height = min(height, map[lo]);
37
+ width += map[lo];
38
+ }
39
+ ret = max(ret, height*width);
40
+ }
41
+ return ret;
42
+ }
pool/shard000/C++/0000086_UnbiasedIncomplete.cpp ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Restructuring Shogun's statistical hypothesis testing framework.
3
+ * Copyright (C) 2014 Soumyajit De
4
+ *
5
+ * This program is free software: you can redistribute it and/or modify
6
+ * it under the terms of the GNU General Public License as published by
7
+ * the Free Software Foundation, either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ * GNU General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU General Public License
16
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+
19
+ #include <shogun/lib/SGMatrix.h>
20
+ #include <shogun/lib/GPUMatrix.h>
21
+ #include <shogun/mathematics/eigen3.h>
22
+ #include <flash/statistics/internals/mmd/UnbiasedIncomplete.h>
23
+
24
+ using namespace shogun;
25
+ using namespace internal;
26
+ using namespace mmd;
27
+
28
+ UnbiasedIncomplete::UnbiasedIncomplete(index_t _n) : n(_n)
29
+ {
30
+ }
31
+
32
+ float64_t UnbiasedIncomplete::operator()(SGMatrix<float64_t> km)
33
+ {
34
+ using MatrixXt = const Eigen::MatrixXd;
35
+ using Block = const Eigen::Block<Eigen::Map<MatrixXt>>;
36
+
37
+ Eigen::Map<MatrixXt> map(km.matrix, km.num_rows, km.num_cols);
38
+
39
+ Block& b_x = map.block(0, 0, n, n);
40
+ auto term_1 = b_x.sum() - b_x.diagonal().sum();
41
+
42
+ Block& b_y = map.block(n, n, n, n);
43
+ auto term_2 = b_y.sum() - b_y.diagonal().sum();
44
+
45
+ Block& b_xy = map.block(n, 0, n, n);
46
+ auto term_3 = b_xy.sum() - b_xy.diagonal().sum();
47
+
48
+ auto statistic = term_1/n/(n-1) + term_2/n/(n-1) - 2*term_3/n/n;
49
+
50
+ return statistic;
51
+
52
+ }
pool/shard000/C++/0000091_updateoriginendpointresponse.cpp ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ Copyright 2013-2021 Paul Colby
3
+
4
+ This file is part of QtAws.
5
+
6
+ QtAws is free software: you can redistribute it and/or modify
7
+ it under the terms of the GNU Lesser General Public License as published by
8
+ the Free Software Foundation, either version 3 of the License, or
9
+ (at your option) any later version.
10
+
11
+ QtAws is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU Lesser General Public License for more details.
15
+
16
+ You should have received a copy of the GNU Lesser General Public License
17
+ along with the QtAws. If not, see <http://www.gnu.org/licenses/>.
18
+ */
19
+
20
+ #include "updateoriginendpointresponse.h"
21
+ #include "updateoriginendpointresponse_p.h"
22
+
23
+ #include <QDebug>
24
+ #include <QNetworkReply>
25
+ #include <QXmlStreamReader>
26
+
27
+ namespace QtAws {
28
+ namespace MediaPackage {
29
+
30
+ /*!
31
+ * \class QtAws::MediaPackage::UpdateOriginEndpointResponse
32
+ * \brief The UpdateOriginEndpointResponse class provides an interace for MediaPackage UpdateOriginEndpoint responses.
33
+ *
34
+ * \inmodule QtAwsMediaPackage
35
+ *
36
+ *
37
+ * \sa MediaPackageClient::updateOriginEndpoint
38
+ */
39
+
40
+ /*!
41
+ * Constructs a UpdateOriginEndpointResponse object for \a reply to \a request, with parent \a parent.
42
+ */
43
+ UpdateOriginEndpointResponse::UpdateOriginEndpointResponse(
44
+ const UpdateOriginEndpointRequest &request,
45
+ QNetworkReply * const reply,
46
+ QObject * const parent)
47
+ : MediaPackageResponse(new UpdateOriginEndpointResponsePrivate(this), parent)
48
+ {
49
+ setRequest(new UpdateOriginEndpointRequest(request));
50
+ setReply(reply);
51
+ }
52
+
53
+ /*!
54
+ * \reimp
55
+ */
56
+ const UpdateOriginEndpointRequest * UpdateOriginEndpointResponse::request() const
57
+ {
58
+ Q_D(const UpdateOriginEndpointResponse);
59
+ return static_cast<const UpdateOriginEndpointRequest *>(d->request);
60
+ }
61
+
62
+ /*!
63
+ * \reimp
64
+ * Parses a successful MediaPackage UpdateOriginEndpoint \a response.
65
+ */
66
+ void UpdateOriginEndpointResponse::parseSuccess(QIODevice &response)
67
+ {
68
+ //Q_D(UpdateOriginEndpointResponse);
69
+ QXmlStreamReader xml(&response);
70
+ /// @todo
71
+ }
72
+
73
+ /*!
74
+ * \class QtAws::MediaPackage::UpdateOriginEndpointResponsePrivate
75
+ * \brief The UpdateOriginEndpointResponsePrivate class provides private implementation for UpdateOriginEndpointResponse.
76
+ * \internal
77
+ *
78
+ * \inmodule QtAwsMediaPackage
79
+ */
80
+
81
+ /*!
82
+ * Constructs a UpdateOriginEndpointResponsePrivate object with public implementation \a q.
83
+ */
84
+ UpdateOriginEndpointResponsePrivate::UpdateOriginEndpointResponsePrivate(
85
+ UpdateOriginEndpointResponse * const q) : MediaPackageResponsePrivate(q)
86
+ {
87
+
88
+ }
89
+
90
+ /*!
91
+ * Parses a MediaPackage UpdateOriginEndpoint response element from \a xml.
92
+ */
93
+ void UpdateOriginEndpointResponsePrivate::parseUpdateOriginEndpointResponse(QXmlStreamReader &xml)
94
+ {
95
+ Q_ASSERT(xml.name() == QLatin1String("UpdateOriginEndpointResponse"));
96
+ Q_UNUSED(xml) ///< @todo
97
+ }
98
+
99
+ } // namespace MediaPackage
100
+ } // namespace QtAws
pool/shard000/C++/0000092_asset_texture.cpp ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ The MIT License (MIT)
3
+ Copyright (c) 2016 Alexey Yegorov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21
+ IN THE SOFTWARE.
22
+ */
23
+
24
+ #include "asset_texture.h"
25
+ #include "io/utils/file_guard.h"
26
+ #include <png.h>
27
+ #include <stdlib.h>
28
+ #include <cassert>
29
+ #include <vector>
30
+
31
+ namespace eps {
32
+
33
+ static void read_png_data_callback(png_structp png_ptr,
34
+ png_byte * raw_data,
35
+ png_size_t read_length)
36
+ {
37
+ io::file * stream = static_cast<io::file*>(png_get_io_ptr(png_ptr));
38
+ stream->read(raw_data, 1, read_length);
39
+ }
40
+
41
+ asset_texture::asset_texture()
42
+ : data_(nullptr, ::free)
43
+ {}
44
+
45
+ asset_texture::asset_texture(const std::string & resource)
46
+ : asset(resource)
47
+ , data_(nullptr, ::free)
48
+ {}
49
+
50
+ bool asset_texture::load(utils::link<io::system> fs, const std::string & resource)
51
+ {
52
+ io::file_guard stream(fs, resource);
53
+ if(!stream.valid())
54
+ return false;
55
+
56
+ png_byte header[8];
57
+ if(stream.read(header, 1, 8) != 8)
58
+ return false;
59
+
60
+ if(png_sig_cmp(header, 0, 8) != 0)
61
+ return false;
62
+
63
+ png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
64
+ if(png_ptr == nullptr)
65
+ return false;
66
+
67
+ png_infop info_ptr = png_create_info_struct(png_ptr);
68
+ if(info_ptr == nullptr)
69
+ {
70
+ png_destroy_read_struct(&png_ptr, &info_ptr, nullptr);
71
+ return false;
72
+ }
73
+
74
+ png_set_read_fn(png_ptr, stream.get(), read_png_data_callback);
75
+
76
+ if(setjmp(png_jmpbuf(png_ptr)))
77
+ {
78
+ png_destroy_read_struct(&png_ptr, &info_ptr, nullptr);
79
+ return false;
80
+ }
81
+
82
+ png_uint_32 width, height;
83
+ int bit_depth, color_type;
84
+
85
+ png_set_sig_bytes(png_ptr, 8);
86
+ png_read_info(png_ptr, info_ptr);
87
+ png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
88
+ nullptr, nullptr, nullptr);
89
+
90
+ // convert transparency to full alpha
91
+ if(png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
92
+ png_set_tRNS_to_alpha(png_ptr);
93
+
94
+ // convert grayscale, if needed.
95
+ if(color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
96
+ png_set_expand_gray_1_2_4_to_8(png_ptr);
97
+
98
+ // convert paletted images, if needed.
99
+ if(color_type == PNG_COLOR_TYPE_PALETTE)
100
+ png_set_palette_to_rgb(png_ptr);
101
+
102
+ // add alpha channel, if there is none.
103
+ // rationale: GL_RGBA is faster than GL_RGB on many GPUs
104
+ if(color_type == PNG_COLOR_TYPE_PALETTE || color_type == PNG_COLOR_TYPE_RGB)
105
+ png_set_add_alpha(png_ptr, 0xFF, PNG_FILLER_AFTER);
106
+
107
+ // ensure 8-bit packing
108
+ if(bit_depth < 8)
109
+ png_set_packing(png_ptr);
110
+ else if (bit_depth == 16)
111
+ png_set_scale_16(png_ptr);
112
+
113
+ png_read_update_info(png_ptr, info_ptr);
114
+
115
+ // read the new color type after updates have been made.
116
+ color_type = png_get_color_type(png_ptr, info_ptr);
117
+
118
+ png_size_t row_size = png_get_rowbytes(png_ptr, info_ptr);
119
+ assert(row_size > 0);
120
+
121
+ png_byte * raw_image = static_cast<png_byte*>(malloc(row_size * height));
122
+ assert(raw_image != nullptr);
123
+
124
+ std::vector<png_byte *> row_ptrs(height);
125
+
126
+ for(png_uint_32 i = 0; i < height; ++i)
127
+ row_ptrs[i] = raw_image + i * row_size;
128
+
129
+ png_read_image(png_ptr, &row_ptrs[0]);
130
+ png_destroy_read_struct(&png_ptr, &info_ptr, nullptr);
131
+
132
+ data_ = utils::unique<void, void(*)(void*)>(raw_image, ::free);
133
+ size_.x = width;
134
+ size_.y = height;
135
+
136
+ return true;
137
+ }
138
+
139
+ } /* eps */
pool/shard000/C++/0000094_test_201_300.cpp ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <gtest/gtest.h>
2
+ #include <gmock/gmock.h>
3
+
4
+ #include "linked_list.hpp"
5
+ #include "binary_tree.hpp"
6
+
7
+ #include "234.hpp"
8
+ #include "237.hpp"
9
+ #include "268.hpp"
10
+ #include "283.hpp"
11
+
12
+ using ::testing::UnorderedElementsAre;
13
+ using ::testing::ElementsAre;
14
+
15
+
16
+ TEST(Test234, GeneralTest) {
17
+ using List = LinkedList<int>;
18
+
19
+ List l0;
20
+ EXPECT_TRUE(isPalindromeStack(l0.head()));
21
+ EXPECT_TRUE(isPalindrome(l0.head()));
22
+
23
+ List l1 {1, 2};
24
+ EXPECT_FALSE(isPalindromeStack(l1.head()));
25
+ EXPECT_FALSE(isPalindrome(l1.head()));
26
+ // Test that the linked list has been recovered after reverse.
27
+ EXPECT_THAT(l1.toVector(), ElementsAre(1, 2));
28
+
29
+ List l2 {1, 2, 3, 2, 1};
30
+ EXPECT_TRUE(isPalindromeStack(l2.head()));
31
+ EXPECT_TRUE(isPalindrome(l2.head()));
32
+ EXPECT_THAT(l2.toVector(), ElementsAre(1, 2, 3, 2, 1));
33
+
34
+ List l3 {1, 2, 2, 1};
35
+ EXPECT_TRUE(isPalindromeStack(l3.head()));
36
+ EXPECT_TRUE(isPalindrome(l3.head()));
37
+ EXPECT_THAT(l3.toVector(), ElementsAre(1, 2, 2, 1));
38
+ }
39
+
40
+ TEST(Test237, GeneralTest) {
41
+ using List = LinkedList<int>;
42
+
43
+ List l0 {0, 1, 2};
44
+ deleteNode(l0.nthNode(1));
45
+ EXPECT_THAT(l0.toVector(), ElementsAre(0, 2));
46
+
47
+ List l1 {0, 1, 2};
48
+ deleteNode(l1.nthNode(0));
49
+ EXPECT_THAT(l1.toVector(), ElementsAre(1, 2));
50
+ }
51
+
52
+ TEST(Test268, GeneralTest) {
53
+ std::vector<int> nums0 {3, 0, 1};
54
+ EXPECT_EQ(missingNumber(nums0), 2);
55
+
56
+ std::vector<int> nums1 {1};
57
+ EXPECT_EQ(missingNumber(nums1), 0);
58
+
59
+ std::vector<int> nums2 {9, 6, 4, 2, 3, 5, 7, 0, 1};
60
+ EXPECT_EQ(missingNumber(nums2), 8);
61
+ }
62
+
63
+ TEST(Test283, GeneralTest) {
64
+ std::vector<int> nums0 {0, 1, 0, 3, 12};
65
+ moveZeroes(nums0);
66
+ EXPECT_THAT(nums0, ElementsAre(1, 3, 12, 0, 0));
67
+
68
+ std::vector<int> nums1 {0};
69
+ moveZeroes(nums1);
70
+ EXPECT_THAT(nums1, ElementsAre(0));
71
+
72
+ std::vector<int> nums2 {1, 2};
73
+ moveZeroes(nums2);
74
+ EXPECT_THAT(nums2, ElementsAre(1, 2));
75
+ }
76
+
77
+
78
+ int main(int argc, char **argv) {
79
+ ::testing::InitGoogleTest(&argc, argv);
80
+
81
+ return RUN_ALL_TESTS();
82
+ }
pool/shard000/C++/0000097_strlen_of_shadow.cc ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // RUN: %clangxx_msan -O0 %s -o %t && %run %t
2
+
3
+ // Check that strlen() and similar intercepted functions can be called on shadow
4
+ // memory.
5
+
6
+ #include <assert.h>
7
+ #include <stdint.h>
8
+ #include <stdio.h>
9
+ #include <string.h>
10
+ #include <stdlib.h>
11
+ #include "test.h"
12
+
13
+ const char *mem_to_shadow(const char *p) {
14
+ #if defined(__x86_64__)
15
+ return (char *)((uintptr_t)p ^ 0x500000000000ULL);
16
+ #elif defined (__mips64)
17
+ return (char *)((uintptr_t)p & ~0x4000000000ULL);
18
+ #elif defined(__powerpc64__)
19
+ #define LINEARIZE_MEM(mem) \
20
+ (((uintptr_t)(mem) & ~0x200000000000ULL) ^ 0x100000000000ULL)
21
+ return (char *)(LINEARIZE_MEM(p) + 0x080000000000ULL);
22
+ #elif defined(__aarch64__)
23
+ return (char *)((uintptr_t)p ^ 0x6000000000ULL);
24
+ #endif
25
+ }
26
+
27
+ int main(void) {
28
+ const char *s = "abcdef";
29
+ assert(strlen(s) == 6);
30
+ assert(strlen(mem_to_shadow(s)) == 0);
31
+
32
+ char *t = new char[42];
33
+ t[41] = 0;
34
+ assert(strlen(mem_to_shadow(t)) == 41);
35
+ return 0;
36
+ }
pool/shard000/C++/0000112_check_nan.cc ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // { dg-do run { target c++11 } }
2
+ // { dg-require-c-std "" }
3
+ // { dg-add-options ieee }
4
+ // { dg-options "-D__STDCPP_WANT_MATH_SPEC_FUNCS__" }
5
+
6
+ // Copyright (C) 2016 Free Software Foundation, Inc.
7
+ //
8
+ // This file is part of the GNU ISO C++ Library. This library is free
9
+ // software; you can redistribute it and/or modify it under the
10
+ // terms of the GNU General Public License as published by the
11
+ // Free Software Foundation; either version 3, or (at your option)
12
+ // any later version.
13
+ //
14
+ // This library is distributed in the hope that it will be useful,
15
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ // GNU General Public License for more details.
18
+ //
19
+ // You should have received a copy of the GNU General Public License along
20
+ // with this library; see the file COPYING3. If not see
21
+ // <http://www.gnu.org/licenses/>.
22
+
23
+ // 8.1.2 assoc_legendre
24
+
25
+ #include <cmath>
26
+ #include <testsuite_hooks.h>
27
+
28
+ void
29
+ test01()
30
+ {
31
+ float xf = std::numeric_limits<float>::quiet_NaN();
32
+ double xd = std::numeric_limits<double>::quiet_NaN();
33
+ long double xl = std::numeric_limits<long double>::quiet_NaN();
34
+
35
+ unsigned int l = 2, m = 1;
36
+
37
+ float a = std::assoc_legendre(l, m, xf);
38
+ float b = std::assoc_legendref(l, m, xf);
39
+ double c = std::assoc_legendre(l, m, xd);
40
+ long double d = std::assoc_legendre(l, m, xl);
41
+ long double e = std::assoc_legendrel(l, m, xl);
42
+
43
+ bool test [[gnu::unused]] = true;
44
+ VERIFY(std::isnan(a));
45
+ VERIFY(std::isnan(b));
46
+ VERIFY(std::isnan(c));
47
+ VERIFY(std::isnan(d));
48
+ VERIFY(std::isnan(e));
49
+
50
+ return;
51
+ }
52
+
53
+ int
54
+ main()
55
+ {
56
+ test01();
57
+ return 0;
58
+ }
59
+
pool/shard000/C++/0000122_decoder_engine.cc ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2018 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 "chromeos/services/ime/decoder/decoder_engine.h"
6
+
7
+ #include "base/callback_helpers.h"
8
+ #include "base/files/file_path.h"
9
+ #include "base/files/file_util.h"
10
+ #include "chromeos/services/ime/constants.h"
11
+
12
+ namespace chromeos {
13
+ namespace ime {
14
+
15
+ namespace {
16
+
17
+ // A client delegate passed to the shared library in order for the
18
+ // shared library to send replies back to the engine.
19
+ class ClientDelegate : public ImeClientDelegate {
20
+ public:
21
+ // All replies from the shared library will be sent to both |remote| and
22
+ // |callback|.
23
+ ClientDelegate(const std::string& ime_spec,
24
+ mojo::PendingRemote<mojom::InputChannel> remote)
25
+ : ime_spec_(ime_spec), client_remote_(std::move(remote)) {
26
+ client_remote_.set_disconnect_handler(base::BindOnce(
27
+ &ClientDelegate::OnDisconnected, base::Unretained(this)));
28
+ }
29
+
30
+ ~ClientDelegate() override {}
31
+
32
+ const char* ImeSpec() override { return ime_spec_.c_str(); }
33
+
34
+ void Process(const uint8_t* data, size_t size) override {
35
+ if (client_remote_ && client_remote_.is_bound()) {
36
+ std::vector<uint8_t> msg(data, data + size);
37
+ client_remote_->ProcessMessage(msg, base::DoNothing());
38
+ }
39
+ }
40
+
41
+ void Destroy() override {}
42
+
43
+ private:
44
+ void OnDisconnected() {
45
+ client_remote_.reset();
46
+ LOG(ERROR) << "Client remote is disconnected." << ime_spec_;
47
+ }
48
+
49
+ // The ime specification which is unique in the scope of engine.
50
+ std::string ime_spec_;
51
+
52
+ // The InputChannel remote used to talk to the client.
53
+ mojo::Remote<mojom::InputChannel> client_remote_;
54
+ };
55
+
56
+ } // namespace
57
+
58
+ DecoderEngine::DecoderEngine(ImeCrosPlatform* platform) : platform_(platform) {
59
+ if (!TryLoadDecoder()) {
60
+ LOG(WARNING) << "DecoderEngine INIT INCOMPLETED.";
61
+ }
62
+ }
63
+
64
+ DecoderEngine::~DecoderEngine() {}
65
+
66
+ bool DecoderEngine::TryLoadDecoder() {
67
+ auto* decoder = ImeDecoder::GetInstance();
68
+ if (decoder->GetStatus() == ImeDecoder::Status::kSuccess &&
69
+ decoder->GetEntryPoints().is_ready) {
70
+ decoder_entry_points_ = decoder->GetEntryPoints();
71
+ decoder_entry_points_->init_once(platform_);
72
+ return true;
73
+ }
74
+ return false;
75
+ }
76
+
77
+ bool DecoderEngine::BindRequest(
78
+ const std::string& ime_spec,
79
+ mojo::PendingReceiver<mojom::InputChannel> receiver,
80
+ mojo::PendingRemote<mojom::InputChannel> remote,
81
+ const std::vector<uint8_t>& extra) {
82
+ if (IsImeSupportedByDecoder(ime_spec)) {
83
+ // Activates an IME engine via the shared library. Passing a
84
+ // |ClientDelegate| for engine instance created by the shared library to
85
+ // make safe calls on the client.
86
+ if (decoder_entry_points_->activate_ime(
87
+ ime_spec.c_str(),
88
+ new ClientDelegate(ime_spec, std::move(remote)))) {
89
+ decoder_channel_receivers_.Add(this, std::move(receiver));
90
+ // TODO(https://crbug.com/837156): Registry connection error handler.
91
+ return true;
92
+ }
93
+ return false;
94
+ }
95
+ return false;
96
+ }
97
+
98
+ bool DecoderEngine::IsImeSupportedByDecoder(const std::string& ime_spec) {
99
+ return decoder_entry_points_ &&
100
+ decoder_entry_points_->supports(ime_spec.c_str());
101
+ }
102
+
103
+ void DecoderEngine::ProcessMessage(const std::vector<uint8_t>& message,
104
+ ProcessMessageCallback callback) {
105
+ // TODO(https://crbug.com/837156): Set a default protobuf message.
106
+ std::vector<uint8_t> result;
107
+
108
+ // Handle message via corresponding functions of loaded decoder.
109
+ if (decoder_entry_points_) {
110
+ decoder_entry_points_->process(message.data(), message.size());
111
+ }
112
+
113
+ std::move(callback).Run(result);
114
+ }
115
+
116
+ } // namespace ime
117
+ } // namespace chromeos
pool/shard000/C++/0000127_time_conversion_unittest.cc ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 <math.h>
6
+ #include <stdlib.h>
7
+
8
+ #include "ppapi/shared_impl/time_conversion.h"
9
+ #include "testing/gtest/include/gtest/gtest.h"
10
+
11
+ namespace ppapi {
12
+
13
+ // Slop we'll allow in two Time "internal values" to consider them equal.
14
+ // Double conversion can introduce rounding errors. The internal values are in
15
+ // microseconds, so an error here is very small.
16
+ static const int kTimeInternalValueSlop = 2;
17
+
18
+ // Same as above in double-precision seconds units.
19
+ static const double kTimeSecondsSlop =
20
+ static_cast<double>(kTimeInternalValueSlop) /
21
+ base::Time::kMicrosecondsPerSecond;
22
+
23
+ TEST(TimeConversion, Time) {
24
+ // Should be able to round-trip.
25
+ base::Time now = base::Time::Now();
26
+ base::Time converted = ppapi::PPTimeToTime(TimeToPPTime(now));
27
+ EXPECT_GE(kTimeInternalValueSlop,
28
+ abs(static_cast<int>((converted - now).ToInternalValue())));
29
+
30
+ // Units should be in seconds.
31
+ base::Time one_second_from_now = now + base::TimeDelta::FromSeconds(1);
32
+ double converted_one_second_from_now =
33
+ ppapi::TimeToPPTime(one_second_from_now) - ppapi::TimeToPPTime(now);
34
+ EXPECT_GE(kTimeSecondsSlop, fabs(converted_one_second_from_now - 1));
35
+ }
36
+
37
+ TEST(TimeConversion, EpochTime) {
38
+ // Should be able to round-trip from epoch time.
39
+ base::Time epoch = base::Time::UnixEpoch();
40
+ base::Time converted = ppapi::PPTimeToTime(TimeToPPTime(epoch));
41
+ EXPECT_GE(kTimeInternalValueSlop,
42
+ abs(static_cast<int>((converted - epoch).ToInternalValue())));
43
+
44
+ // Units should be in seconds.
45
+ base::Time one_second_from_epoch = epoch + base::TimeDelta::FromSeconds(1);
46
+ double converted_one_second_from_epoch =
47
+ ppapi::TimeToPPTime(one_second_from_epoch) - ppapi::TimeToPPTime(epoch);
48
+ EXPECT_GE(kTimeSecondsSlop, fabs(converted_one_second_from_epoch - 1));
49
+
50
+ // Epoch time should be equal to a PP_Time of 0.0.
51
+ EXPECT_GE(kTimeSecondsSlop, fabs(ppapi::TimeToPPTime(epoch) - 0.0));
52
+ EXPECT_GE(kTimeInternalValueSlop,
53
+ abs(static_cast<int>(
54
+ (ppapi::PPTimeToTime(0.0) - epoch).ToInternalValue())));
55
+ }
56
+
57
+ } // namespace ppapi
pool/shard000/C++/0000141_potential_file_reader.cpp ADDED
@@ -0,0 +1,283 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* -*- c++ -*- ----------------------------------------------------------
2
+ LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
3
+ https://lammps.sandia.gov/, Sandia National Laboratories
4
+ Steve Plimpton, sjplimp@sandia.gov
5
+
6
+ Copyright (2003) Sandia Corporation. Under the terms of Contract
7
+ DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
8
+ certain rights in this software. This software is distributed under
9
+ the GNU General Public License.
10
+
11
+ See the README file in the top-level LAMMPS directory.
12
+ ------------------------------------------------------------------------- */
13
+
14
+ /* ----------------------------------------------------------------------
15
+ Contributing authors: Richard Berger (Temple U)
16
+ ------------------------------------------------------------------------- */
17
+
18
+ #include "potential_file_reader.h"
19
+
20
+ #include "comm.h"
21
+ #include "error.h"
22
+ #include "text_file_reader.h"
23
+ #include "tokenizer.h"
24
+ #include "update.h"
25
+
26
+ using namespace LAMMPS_NS;
27
+
28
+ /** Class for reading and parsing LAMMPS potential files
29
+ *
30
+ * The value of the class member variable *ignore_comments* controls
31
+ * whether any text following the pound sign (#) should be ignored (true)
32
+ * or not (false). Default: true, i.e. ignore.
33
+ \verbatim embed:rst
34
+
35
+ *See also*
36
+ :cpp:class:`TextFileReader`
37
+
38
+ \endverbatim
39
+ *
40
+ * \param lmp Pointer to LAMMPS instance
41
+ * \param filename Name of file to be read
42
+ * \param potential_name Name of potential style for error messages
43
+ * \param name_suffix Suffix added to potential name in error messages
44
+ * \param auto_convert Bitmask of supported unit conversions
45
+ */
46
+
47
+ PotentialFileReader::PotentialFileReader(LAMMPS *lmp,
48
+ const std::string &filename,
49
+ const std::string &potential_name,
50
+ const std::string &name_suffix,
51
+ const int auto_convert) :
52
+ Pointers(lmp),
53
+ reader(nullptr),
54
+ filename(filename),
55
+ filetype(potential_name + name_suffix),
56
+ unit_convert(auto_convert)
57
+ {
58
+ if (comm->me != 0) {
59
+ error->one(FLERR, "FileReader should only be called by proc 0!");
60
+ }
61
+
62
+ try {
63
+ reader = open_potential(filename);
64
+ if (!reader) {
65
+ error->one(FLERR, "cannot open {} potential file {}: {}",
66
+ potential_name, filename, utils::getsyserror());
67
+ }
68
+ } catch (FileReaderException &e) {
69
+ error->one(FLERR, e.what());
70
+ }
71
+ }
72
+
73
+ /*
74
+ * \param lmp Pointer to LAMMPS instance
75
+ * \param filename Name of file to be read
76
+ * \param potential_name Name of potential style for error messages
77
+ * \param auto_convert Bitmask of supported unit conversions
78
+ */
79
+ PotentialFileReader::PotentialFileReader(LAMMPS *lmp,
80
+ const std::string &filename,
81
+ const std::string &potential_name,
82
+ const int auto_convert) :
83
+ PotentialFileReader(lmp, filename, potential_name, " potential", auto_convert)
84
+ {
85
+ }
86
+
87
+ /** Closes the file */
88
+
89
+ PotentialFileReader::~PotentialFileReader() {
90
+ delete reader;
91
+ }
92
+
93
+ /** Set comment (= text after '#') handling preference for the file to be read
94
+ *
95
+ * \param value Comment text is ignored if true, or not if false */
96
+ void PotentialFileReader::ignore_comments(bool value) {
97
+ reader->ignore_comments = value;
98
+ }
99
+
100
+ /** Read a line but ignore its content */
101
+
102
+ void PotentialFileReader::skip_line() {
103
+ try {
104
+ reader->skip_line();
105
+ } catch (FileReaderException &e) {
106
+ error->one(FLERR, e.what());
107
+ }
108
+ }
109
+
110
+ /** Read the next line(s) until *nparams* words have been read.
111
+ *
112
+ * This reads a line and counts the words in it, if the number
113
+ * is less than the requested number, it will read the next
114
+ * line, as well. Output will be a string with all read lines
115
+ * combined. The purpose is to somewhat replicate the reading
116
+ * behavior of formatted files in Fortran.
117
+ *
118
+ * \param nparams Number of words that must be read. Default: 0
119
+ * \return String with the concatenated text */
120
+
121
+ char *PotentialFileReader::next_line(int nparams) {
122
+ try {
123
+ return reader->next_line(nparams);
124
+ } catch (FileReaderException &e) {
125
+ error->one(FLERR, e.what());
126
+ }
127
+ return nullptr;
128
+ }
129
+
130
+ /** Read lines until *n* doubles have been read and stored in array *list*
131
+ *
132
+ * This reads lines from the file using the next_line() function,
133
+ * and splits them into floating-point numbers using the
134
+ * ValueTokenizer class and stores the number is the provided list.
135
+ *
136
+ * \param list Pointer to array with suitable storage for *n* doubles
137
+ * \param n Number of doubles to be read */
138
+
139
+ void PotentialFileReader::next_dvector(double * list, int n) {
140
+ try {
141
+ return reader->next_dvector(list, n);
142
+ } catch (FileReaderException &e) {
143
+ error->one(FLERR, e.what());
144
+ }
145
+ }
146
+
147
+ /** Read text until *nparams* words are read and passed to a tokenizer object for custom parsing.
148
+ *
149
+ * This reads lines from the file using the next_line() function,
150
+ * and splits them into floating-point numbers using the
151
+ * ValueTokenizer class and stores the number is the provided list.
152
+ *
153
+ * \param nparams Number of words to be read
154
+ * \param separators String with list of separators.
155
+ * \return ValueTokenizer object for read in text */
156
+
157
+ ValueTokenizer PotentialFileReader::next_values(int nparams, const std::string &separators) {
158
+ try {
159
+ return reader->next_values(nparams, separators);
160
+ } catch (FileReaderException &e) {
161
+ error->one(FLERR, e.what());
162
+ }
163
+ return ValueTokenizer("");
164
+ }
165
+
166
+ /** Read next line and convert first word to a double
167
+ *
168
+ * \return Value of first word in line as double */
169
+
170
+ double PotentialFileReader::next_double() {
171
+ try {
172
+ char * line = reader->next_line(1);
173
+ return ValueTokenizer(line).next_double();
174
+ } catch (FileReaderException &e) {
175
+ error->one(FLERR, e.what());
176
+ }
177
+ return 0.0;
178
+ }
179
+
180
+ /** Read next line and convert first word to an int
181
+ *
182
+ * \return Value of first word in line as int */
183
+
184
+ int PotentialFileReader::next_int() {
185
+ try {
186
+ char * line = reader->next_line(1);
187
+ return ValueTokenizer(line).next_int();
188
+ } catch (FileReaderException &e) {
189
+ error->one(FLERR, e.what());
190
+ }
191
+ return 0;
192
+ }
193
+
194
+ /** Read next line and convert first word to a tagint
195
+ *
196
+ * \return Value of first word in line as tagint */
197
+
198
+ tagint PotentialFileReader::next_tagint() {
199
+ try {
200
+ char * line = reader->next_line(1);
201
+ return ValueTokenizer(line).next_tagint();
202
+ } catch (FileReaderException &e) {
203
+ error->one(FLERR, e.what());
204
+ }
205
+ return 0;
206
+ }
207
+
208
+ /** Read next line and convert first word to a bigint
209
+ *
210
+ * \return Value of first word in line as bigint */
211
+
212
+ bigint PotentialFileReader::next_bigint() {
213
+ try {
214
+ char * line = reader->next_line(1);
215
+ return ValueTokenizer(line).next_bigint();
216
+ } catch (FileReaderException &e) {
217
+ error->one(FLERR, e.what());
218
+ }
219
+ return 0;
220
+ }
221
+
222
+ /** Read next line and return first word
223
+ *
224
+ * \return First word of read in line */
225
+
226
+ std::string PotentialFileReader::next_string() {
227
+ try {
228
+ char * line = reader->next_line(1);
229
+ return ValueTokenizer(line).next_string();
230
+ } catch (FileReaderException &e) {
231
+ error->one(FLERR, e.what());
232
+ }
233
+ return "";
234
+ }
235
+
236
+ /** Look up and open the potential file
237
+ *
238
+ \verbatim embed:rst
239
+
240
+ *See also*
241
+ :cpp:func:`utils::open_potential`,
242
+ :cpp:class:`TextFileReader`
243
+
244
+ \endverbatim
245
+ * \param path Path of the potential file to open
246
+ * \return Pointer to TextFileReader object created */
247
+
248
+ TextFileReader *PotentialFileReader::open_potential(const std::string &path) {
249
+ std::string filepath = utils::get_potential_file_path(path);
250
+
251
+ if (!filepath.empty()) {
252
+ std::string unit_style = lmp->update->unit_style;
253
+ std::string date = utils::get_potential_date(filepath, filetype);
254
+ std::string units = utils::get_potential_units(filepath, filetype);
255
+
256
+ if (!date.empty())
257
+ utils::logmesg(lmp,"Reading {} file {} with DATE: {}\n",
258
+ filetype, filename, date);
259
+
260
+ if (units.empty()) {
261
+ unit_convert = utils::NOCONVERT;
262
+ } else {
263
+ if (units == unit_style) {
264
+ unit_convert = utils::NOCONVERT;
265
+ } else {
266
+ if ((units == "metal") && (unit_style == "real") && (unit_convert & utils::METAL2REAL)) {
267
+ unit_convert = utils::METAL2REAL;
268
+ } else if ((units == "real") && (unit_style == "metal") && (unit_convert & utils::REAL2METAL)) {
269
+ unit_convert = utils::REAL2METAL;
270
+ } else {
271
+ lmp->error->one(FLERR, "{} file {} requires {} units "
272
+ "but {} units are in use", filetype,
273
+ filename, units, unit_style);
274
+ }
275
+ }
276
+ }
277
+ if (unit_convert != utils::NOCONVERT)
278
+ lmp->error->warning(FLERR, fmt::format("Converting {} in {} units to {} "
279
+ "units", filetype, units, unit_style));
280
+ return new TextFileReader(filepath, filetype);
281
+ }
282
+ return nullptr;
283
+ }
pool/shard000/C++/0000144_testArrayBuffer.cpp ADDED
@@ -0,0 +1,227 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2
+ * vim: set ts=8 sts=4 et sw=4 tw=99:
3
+ */
4
+
5
+ #include "jsfriendapi.h"
6
+
7
+ #include "jsapi-tests/tests.h"
8
+
9
+ BEGIN_TEST(testArrayBuffer_bug720949_steal)
10
+ {
11
+ static const unsigned NUM_TEST_BUFFERS = 2;
12
+ static const unsigned MAGIC_VALUE_1 = 3;
13
+ static const unsigned MAGIC_VALUE_2 = 17;
14
+
15
+ JS::RootedObject buf_len1(cx), buf_len200(cx);
16
+ JS::RootedObject tarray_len1(cx), tarray_len200(cx);
17
+
18
+ uint32_t sizes[NUM_TEST_BUFFERS] = { sizeof(uint32_t), 200 * sizeof(uint32_t) };
19
+ JS::HandleObject testBuf[NUM_TEST_BUFFERS] = { buf_len1, buf_len200 };
20
+ JS::HandleObject testArray[NUM_TEST_BUFFERS] = { tarray_len1, tarray_len200 };
21
+
22
+ // Single-element ArrayBuffer (uses fixed slots for storage)
23
+ CHECK(buf_len1 = JS_NewArrayBuffer(cx, sizes[0]));
24
+ CHECK(tarray_len1 = JS_NewInt32ArrayWithBuffer(cx, testBuf[0], 0, -1));
25
+
26
+ CHECK(JS_SetElement(cx, testArray[0], 0, MAGIC_VALUE_1));
27
+
28
+ // Many-element ArrayBuffer (uses dynamic storage)
29
+ CHECK(buf_len200 = JS_NewArrayBuffer(cx, 200 * sizeof(uint32_t)));
30
+ CHECK(tarray_len200 = JS_NewInt32ArrayWithBuffer(cx, testBuf[1], 0, -1));
31
+
32
+ for (unsigned i = 0; i < NUM_TEST_BUFFERS; i++) {
33
+ JS::HandleObject obj = testBuf[i];
34
+ JS::HandleObject view = testArray[i];
35
+ uint32_t size = sizes[i];
36
+ JS::RootedValue v(cx);
37
+
38
+ // Byte lengths should all agree
39
+ CHECK(JS_IsArrayBufferObject(obj));
40
+ CHECK_EQUAL(JS_GetArrayBufferByteLength(obj), size);
41
+ CHECK(JS_GetProperty(cx, obj, "byteLength", &v));
42
+ CHECK(v.isInt32(size));
43
+ CHECK(JS_GetProperty(cx, view, "byteLength", &v));
44
+ CHECK(v.isInt32(size));
45
+
46
+ // Modifying the underlying data should update the value returned through the view
47
+ {
48
+ JS::AutoCheckCannotGC nogc;
49
+ bool sharedDummy;
50
+ uint8_t* data = JS_GetArrayBufferData(obj, &sharedDummy, nogc);
51
+ CHECK(data != nullptr);
52
+ *reinterpret_cast<uint32_t*>(data) = MAGIC_VALUE_2;
53
+ }
54
+ CHECK(JS_GetElement(cx, view, 0, &v));
55
+ CHECK(v.isInt32(MAGIC_VALUE_2));
56
+
57
+ // Steal the contents
58
+ void* contents = JS_StealArrayBufferContents(cx, obj);
59
+ CHECK(contents != nullptr);
60
+
61
+ CHECK(JS_IsDetachedArrayBufferObject(obj));
62
+
63
+ // Transfer to a new ArrayBuffer
64
+ JS::RootedObject dst(cx, JS_NewArrayBufferWithContents(cx, size, contents));
65
+ CHECK(JS_IsArrayBufferObject(dst));
66
+ {
67
+ JS::AutoCheckCannotGC nogc;
68
+ bool sharedDummy;
69
+ (void) JS_GetArrayBufferData(obj, &sharedDummy, nogc);
70
+ }
71
+
72
+ JS::RootedObject dstview(cx, JS_NewInt32ArrayWithBuffer(cx, dst, 0, -1));
73
+ CHECK(dstview != nullptr);
74
+
75
+ CHECK_EQUAL(JS_GetArrayBufferByteLength(dst), size);
76
+ {
77
+ JS::AutoCheckCannotGC nogc;
78
+ bool sharedDummy;
79
+ uint8_t* data = JS_GetArrayBufferData(dst, &sharedDummy, nogc);
80
+ CHECK(data != nullptr);
81
+ CHECK_EQUAL(*reinterpret_cast<uint32_t*>(data), MAGIC_VALUE_2);
82
+ }
83
+ CHECK(JS_GetElement(cx, dstview, 0, &v));
84
+ CHECK(v.isInt32(MAGIC_VALUE_2));
85
+ }
86
+
87
+ return true;
88
+ }
89
+ END_TEST(testArrayBuffer_bug720949_steal)
90
+
91
+ // Varying number of views of a buffer, to test the detachment weak pointers
92
+ BEGIN_TEST(testArrayBuffer_bug720949_viewList)
93
+ {
94
+ JS::RootedObject buffer(cx);
95
+
96
+ // No views
97
+ buffer = JS_NewArrayBuffer(cx, 2000);
98
+ buffer = nullptr;
99
+ GC(cx);
100
+
101
+ // One view.
102
+ {
103
+ buffer = JS_NewArrayBuffer(cx, 2000);
104
+ JS::RootedObject view(cx, JS_NewUint8ArrayWithBuffer(cx, buffer, 0, -1));
105
+ void* contents = JS_StealArrayBufferContents(cx, buffer);
106
+ CHECK(contents != nullptr);
107
+ JS_free(nullptr, contents);
108
+ GC(cx);
109
+ CHECK(hasDetachedBuffer(view));
110
+ CHECK(JS_IsDetachedArrayBufferObject(buffer));
111
+ view = nullptr;
112
+ GC(cx);
113
+ buffer = nullptr;
114
+ GC(cx);
115
+ }
116
+
117
+ // Two views
118
+ {
119
+ buffer = JS_NewArrayBuffer(cx, 2000);
120
+
121
+ JS::RootedObject view1(cx, JS_NewUint8ArrayWithBuffer(cx, buffer, 0, -1));
122
+ JS::RootedObject view2(cx, JS_NewUint8ArrayWithBuffer(cx, buffer, 1, 200));
123
+
124
+ // Remove, re-add a view
125
+ view2 = nullptr;
126
+ GC(cx);
127
+ view2 = JS_NewUint8ArrayWithBuffer(cx, buffer, 1, 200);
128
+
129
+ // Detach
130
+ void* contents = JS_StealArrayBufferContents(cx, buffer);
131
+ CHECK(contents != nullptr);
132
+ JS_free(nullptr, contents);
133
+
134
+ CHECK(hasDetachedBuffer(view1));
135
+ CHECK(hasDetachedBuffer(view2));
136
+ CHECK(JS_IsDetachedArrayBufferObject(buffer));
137
+
138
+ view1 = nullptr;
139
+ GC(cx);
140
+ view2 = nullptr;
141
+ GC(cx);
142
+ buffer = nullptr;
143
+ GC(cx);
144
+ }
145
+
146
+ return true;
147
+ }
148
+
149
+ static void GC(JSContext* cx)
150
+ {
151
+ JS_GC(cx);
152
+ JS_GC(cx); // Trigger another to wait for background finalization to end
153
+ }
154
+
155
+ bool hasDetachedBuffer(JS::HandleObject obj) {
156
+ JS::RootedValue v(cx);
157
+ return JS_GetProperty(cx, obj, "byteLength", &v) && v.toInt32() == 0;
158
+ }
159
+
160
+ END_TEST(testArrayBuffer_bug720949_viewList)
161
+
162
+ BEGIN_TEST(testArrayBuffer_externalize)
163
+ {
164
+ if (!testWithSize(cx, 2)) // ArrayBuffer data stored inline in the object.
165
+ return false;
166
+ if (!testWithSize(cx, 2000)) // ArrayBuffer data stored out-of-line in a separate heap allocation.
167
+ return false;
168
+
169
+ return true;
170
+ }
171
+
172
+ bool testWithSize(JSContext* cx, size_t n)
173
+ {
174
+ JS::RootedObject buffer(cx, JS_NewArrayBuffer(cx, n));
175
+ CHECK(buffer != nullptr);
176
+
177
+ JS::RootedObject view(cx, JS_NewUint8ArrayWithBuffer(cx, buffer, 0, -1));
178
+ CHECK(view != nullptr);
179
+
180
+ void* contents = JS_ExternalizeArrayBufferContents(cx, buffer);
181
+ CHECK(contents != nullptr);
182
+ uint32_t actualLength;
183
+ CHECK(hasExpectedLength(cx, view, &actualLength));
184
+ CHECK(actualLength == n);
185
+ CHECK(!JS_IsDetachedArrayBufferObject(buffer));
186
+ CHECK(JS_GetArrayBufferByteLength(buffer) == uint32_t(n));
187
+
188
+ uint8_t* uint8Contents = static_cast<uint8_t*>(contents);
189
+ CHECK(*uint8Contents == 0);
190
+ uint8_t randomByte(rand() % UINT8_MAX);
191
+ *uint8Contents = randomByte;
192
+
193
+ JS::RootedValue v(cx);
194
+ CHECK(JS_GetElement(cx, view, 0, &v));
195
+ CHECK(v.toInt32() == randomByte);
196
+
197
+ view = nullptr;
198
+ GC(cx);
199
+
200
+ CHECK(JS_DetachArrayBuffer(cx, buffer));
201
+ GC(cx);
202
+ CHECK(*uint8Contents == randomByte);
203
+ JS_free(cx, contents);
204
+ GC(cx);
205
+ buffer = nullptr;
206
+ GC(cx);
207
+
208
+ return true;
209
+ }
210
+
211
+ static void GC(JSContext* cx)
212
+ {
213
+ JS_GC(cx);
214
+ JS_GC(cx); // Trigger another to wait for background finalization to end
215
+ }
216
+
217
+ static bool
218
+ hasExpectedLength(JSContext* cx, JS::HandleObject obj, uint32_t* len)
219
+ {
220
+ JS::RootedValue v(cx);
221
+ if (!JS_GetProperty(cx, obj, "byteLength", &v))
222
+ return false;
223
+ *len = v.toInt32();
224
+ return true;
225
+ }
226
+
227
+ END_TEST(testArrayBuffer_externalize)
pool/shard000/C++/0000147_ExpressionClassifier.cpp ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include "ExpressionClassifier.h"
2
+
3
+ using namespace cv;
4
+
5
+
6
+ /*
7
+ sigma describes the classification sharpness. A larger sigma means the
8
+ boundary between different expressions is more blurry. It won't change
9
+ the classification, but will give you probabilities that are smoother.
10
+ */
11
+
12
+ ExpressionClassifier::ExpressionClassifier()
13
+ :sigma(10.0) {
14
+ }
15
+
16
+ void ExpressionClassifier::save(string directory) const {
17
+ ofDirectory dir(directory);
18
+ dir.create(true);
19
+ for(int i = 0; i < size(); i++) {
20
+ string filename = dir.path() + "/" + expressions[i].getDescription() + ".yml";
21
+ cout << "saving to " << filename << endl;
22
+ expressions[i].save(filename);
23
+ }
24
+ }
25
+
26
+ void ExpressionClassifier::load(string directory) {
27
+ ofDirectory dir(directory);
28
+ dir.listDir();
29
+ int n = dir.size();
30
+ expressions.resize(n);
31
+ for(int i = 0; i < n; i++) {
32
+ expressions[i].load(dir.getPath(i));
33
+ }
34
+ }
35
+
36
+ unsigned int ExpressionClassifier::classify(const ofxFaceTracker& tracker) {
37
+ Mat cur;
38
+ tracker.getObjectPointsMat().copyTo(cur);
39
+ norm(cur);
40
+ int n = size();
41
+ probability.resize(n);
42
+ if(n == 0) {
43
+ return 0;
44
+ }
45
+ vector<vector<double> > val(n);
46
+ double sum = 0;
47
+ for(int i = 0; i < n; i++){
48
+ int m = expressions[i].size();
49
+ for(int j = 0; j < m; j++){
50
+ double v = norm(cur, expressions[i].getExample(j));
51
+ double p = exp(-v * v / sigma);
52
+ val[i].push_back(p);
53
+ sum += p;
54
+ }
55
+ }
56
+ for(int i = 0; i < n; i++){
57
+ probability[i] = 0;
58
+ int m = expressions[i].size();
59
+ for(int j = 0; j < m; j++) {
60
+ probability[i] += val[i][j];
61
+ }
62
+ probability[i] /= sum;
63
+ }
64
+ return getPrimaryExpression();
65
+ }
66
+
67
+ unsigned int ExpressionClassifier::getPrimaryExpression() const {
68
+ int maxExpression = 0;
69
+ double maxProbability = 0;
70
+ for(int i = 0; i < probability.size(); i++) {
71
+ double cur = getProbability(i);
72
+ if(cur > maxProbability) {
73
+ maxExpression = i;
74
+ maxProbability = cur;
75
+ }
76
+ }
77
+ return maxExpression;
78
+ }
79
+
80
+ double ExpressionClassifier::getProbability(unsigned int i) const {
81
+ if(i < probability.size()) {
82
+ return probability[i];
83
+ } else {
84
+ return 0;
85
+ }
86
+ }
87
+
88
+ string ExpressionClassifier::getDescription(unsigned int i) const {
89
+ return expressions[i].getDescription();
90
+ }
91
+
92
+ Expression& ExpressionClassifier::getExpression(unsigned int i) {
93
+ return expressions[i];
94
+ }
95
+
96
+ void ExpressionClassifier::setSigma(double sigma) {
97
+ this->sigma = sigma;
98
+ }
99
+
100
+ double ExpressionClassifier::getSigma() const {
101
+ return sigma;
102
+ }
103
+
104
+ unsigned int ExpressionClassifier::size() const {
105
+ return expressions.size();
106
+ }
107
+
108
+ void ExpressionClassifier::addExpression(string description) {
109
+ if(description == "") {
110
+ description = ofToString(expressions.size());
111
+ }
112
+ expressions.push_back(Expression(description));
113
+ }
114
+
115
+ void ExpressionClassifier::addExpression(Expression& expression) {
116
+ expressions.push_back(expression);
117
+ }
118
+
119
+ void ExpressionClassifier::addSample(const ofxFaceTracker& tracker) {
120
+ if(size() == 0) {
121
+ addExpression();
122
+ }
123
+ expressions.back().addSample(tracker.getObjectPointsMat());
124
+ }
125
+
126
+ void ExpressionClassifier::reset() {
127
+ expressions.clear();
128
+ }
pool/shard000/C++/0000148_random_unittest.cc ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 "crypto/random.h"
6
+
7
+ #include "base/strings/string_util.h"
8
+ #include "testing/gtest/include/gtest/gtest.h"
9
+
10
+ // Basic functionality tests. Does NOT test the security of the random data.
11
+
12
+ // Ensures we don't have all trivial data, i.e. that the data is indeed random.
13
+ // Currently, that means the bytes cannot be all the same (e.g. all zeros).
14
+ bool IsTrivial(const std::string& bytes) {
15
+ for (size_t i = 0; i < bytes.size(); i++) {
16
+ if (bytes[i] != bytes[0]) {
17
+ return false;
18
+ }
19
+ }
20
+ return true;
21
+ }
22
+
23
+ TEST(RandBytes, RandBytes) {
24
+ std::string bytes(16, '\0');
25
+ crypto::RandBytes(base::WriteInto(&bytes, bytes.size()), bytes.size());
26
+ EXPECT_TRUE(!IsTrivial(bytes));
27
+ }
pool/shard000/C++/0000174_DataFlashFileReader.cpp ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <DataFlashFileReader.h>
2
+
3
+ #include <fcntl.h>
4
+ #include <string.h>
5
+ #include <sys/types.h>
6
+ #include <stdio.h>
7
+ #include <unistd.h>
8
+
9
+ DataFlashFileReader::DataFlashFileReader() : fd(-1) {}
10
+
11
+ bool DataFlashFileReader::open_log(const char *logfile)
12
+ {
13
+ fd = ::open(logfile, O_RDONLY);
14
+ if (fd == -1) {
15
+ return false;
16
+ }
17
+ return true;
18
+ }
19
+
20
+ bool DataFlashFileReader::update(char type[5])
21
+ {
22
+ uint8_t hdr[3];
23
+ if (::read(fd, hdr, 3) != 3) {
24
+ return false;
25
+ }
26
+ if (hdr[0] != HEAD_BYTE1 || hdr[1] != HEAD_BYTE2) {
27
+ printf("bad log header\n");
28
+ return false;
29
+ }
30
+
31
+ if (hdr[2] == LOG_FORMAT_MSG) {
32
+ struct log_Format f;
33
+ memcpy(&f, hdr, 3);
34
+ if (::read(fd, &f.type, sizeof(f)-3) != sizeof(f)-3) {
35
+ return false;
36
+ }
37
+ memcpy(&formats[f.type], &f, sizeof(formats[f.type]));
38
+ strncpy(type, "FMT", 3);
39
+ type[3] = 0;
40
+
41
+ return handle_log_format_msg(f);
42
+ }
43
+
44
+ const struct log_Format &f = formats[hdr[2]];
45
+ if (f.length == 0) {
46
+ // can't just throw these away as the format specifies the
47
+ // number of bytes in the message
48
+ ::printf("No format defined for type (%d)\n", hdr[2]);
49
+ exit(1);
50
+ }
51
+
52
+ uint8_t msg[f.length];
53
+
54
+ memcpy(msg, hdr, 3);
55
+ if (::read(fd, &msg[3], f.length-3) != f.length-3) {
56
+ return false;
57
+ }
58
+
59
+ strncpy(type, f.name, 4);
60
+ type[4] = 0;
61
+
62
+ return handle_msg(f,msg);
63
+ }
pool/shard000/C++/0000179_for_each_suffix.cpp ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #define _SCL_SECURE_NO_WARNINGS
2
+ #include <nark/fsa/dfa_interface.hpp>
3
+ #include <getopt.h>
4
+ #include <stdio.h>
5
+
6
+ using namespace nark;
7
+
8
+ static void on_suffix(size_t nth, fstring suffix) {
9
+ printf("%06zd\t%.*s\n", nth, suffix.ilen(), suffix.data());
10
+ }
11
+
12
+ int main(int argc, char* argv[]) {
13
+ const char* ifile = NULL; // input dfa file name
14
+ for (int opt=0; (opt = getopt(argc, argv, "i:")) != -1; ) {
15
+ switch (opt) {
16
+ case '?': return 3;
17
+ case 'i': ifile = optarg; break;
18
+ }
19
+ }
20
+ std::auto_ptr<DFA_Interface> dfa;
21
+ if (ifile) dfa.reset(DFA_Interface::load_from(ifile)); // by filename
22
+ else dfa.reset(DFA_Interface::load_from(stdin)); // by FILE*
23
+
24
+ for(int i = optind; i < argc; ++i) {
25
+ const char* exact_prefix = argv[i];
26
+ printf("%s ----------\n", exact_prefix);
27
+ dfa->for_each_suffix(exact_prefix, on_suffix);
28
+ }
29
+ return 0;
30
+ }
31
+
pool/shard000/C++/0000187_Event.cpp ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ Copyright (C) 2005 Matthias Braun <matze@braunis.de>
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
+ */
18
+ #include <config.h>
19
+
20
+ #include "Event.hpp"
21
+
22
+ #include <assert.h>
23
+
24
+ Event::Event(SDL_Event& event)
25
+ : inside(true)
26
+ {
27
+ switch(event.type) {
28
+ case SDL_KEYUP:
29
+ type = KEYUP;
30
+ keysym = event.key.keysym;
31
+ break;
32
+ case SDL_KEYDOWN:
33
+ type = KEYDOWN;
34
+ keysym = event.key.keysym;
35
+ break;
36
+ case SDL_MOUSEMOTION:
37
+ type = MOUSEMOTION;
38
+ mousepos = Vector2(event.motion.x, event.motion.y);
39
+ mousemove = Vector2(event.motion.xrel, event.motion.yrel);
40
+ break;
41
+ case SDL_MOUSEBUTTONUP:
42
+ type = MOUSEBUTTONUP;
43
+ mousepos = Vector2(event.button.x, event.button.y);
44
+ mousebutton = event.button.button;
45
+ break;
46
+ case SDL_MOUSEBUTTONDOWN:
47
+ type = MOUSEBUTTONDOWN;
48
+ mousepos = Vector2(event.button.x, event.button.y);
49
+ mousebutton = event.button.button;
50
+ break;
51
+ default:
52
+ assert(false);
53
+ }
54
+ }
55
+
56
+ Event::Event(float _elapsedTime)
57
+ : type(UPDATE), inside(false), elapsedTime(_elapsedTime)
58
+ {
59
+ }
pool/shard000/C++/0000190_trim_strings.cpp ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <string>
2
+ #include <iostream>
3
+ #include <algorithm>
4
+
5
+ std::string trim_left(const std::string& source) {
6
+ std::string res = source;
7
+ res.erase( res.begin(), std::find_if( res.begin(), res.end(), []( const char c ) { return !std::isspace(c); } ) );
8
+ return res;
9
+ }
10
+
11
+ std::string trim_right(const std::string& source) {
12
+ std::string res = source;
13
+ res.erase( std::find_if( res.rbegin(), res.rend(), []( const char c ) { return !std::isspace(c); } ).base( ), res.end( ) );
14
+ return res;
15
+ }
16
+
17
+ std::string trim( const std::string& source ) {
18
+ return trim_right( trim_left( source ) );
19
+ }
20
+
21
+ std::string& trim_ref( std::string& src ) {
22
+ src.erase( std::find_if( src.rbegin(), src.rend(), []( const int c ) { return !std::isspace(c); } ).base( ), src.end( ) );
23
+ src.erase( src.begin(), std::find_if( src.begin(), src.end(), []( const int c ) { return !std::isspace(c); } ) );
24
+ return src;
25
+ }
26
+
27
+ bool test( const std::string& source, const std::string& result ) {
28
+ return source == trim_left( trim_right( result ) );
29
+ }
30
+
31
+ int main() {
32
+ const std::string const_source = " This is string with spacebars. ";
33
+ std::string source = " This is string with spacebars. ";
34
+
35
+ std::cout << "Source:[" << const_source << "]" << std::endl;
36
+ std::cout << "TrimLeft:[" << trim_left( const_source ) << "]" <<std::endl;
37
+ std::cout << "TrimRight:[" << trim_right( const_source ) << "]" <<std::endl;
38
+ std::cout << "Trim:[" << trim( const_source ) << "]" <<std::endl;
39
+
40
+ std::cout << "Source:[" << source << "]" << std::endl;
41
+ std::cout << "Trim(ref):[" << trim_ref( source ) << "]" <<std::endl;
42
+
43
+ return 0;
44
+ }
pool/shard000/C++/0000193_common.cpp ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include "stdafx.h"
2
+ #include "common.h"
3
+ #include <tlhelp32.h>
4
+ #include <windows.h>
5
+ #include <sstream>
6
+ using std::wstringstream;
7
+
8
+ vector<vector<wstring>> common::proc_snapshot()
9
+ {
10
+ vector<vector<wstring>> ret;
11
+ HANDLE hProcs=0;
12
+ if ( hProcs = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0) )
13
+ {
14
+ PROCESSENTRY32 pe32;
15
+ pe32.dwSize = sizeof( PROCESSENTRY32 );
16
+ BOOL ok = Process32First(hProcs, &pe32);
17
+ while (ok)
18
+ {
19
+ vector<wstring> line;
20
+ wstringstream ss;
21
+ ss<<pe32.th32ProcessID;
22
+ line.push_back(ss.str());
23
+ line.push_back(pe32.szExeFile);
24
+ ret.push_back(line);
25
+ ok = Process32Next(hProcs, &pe32);
26
+ }
27
+ CloseHandle(hProcs);
28
+ }
29
+ return ret;
30
+ };
pool/shard000/C++/0000194_pt554.cpp ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // license:BSD-3-Clause
2
+ // copyright-holders:Fabio Priuli
3
+ /***********************************************************************************************************
4
+
5
+
6
+ NES/Famicom cartridge emulation for Bandai PT-554 PCBs
7
+
8
+
9
+ Here we emulate the following Bandai PT-554 PCB (a CNROM PCB + LPC / PARCOR speech synthesis chip)
10
+
11
+ TODO:
12
+ - emulate the mat controller
13
+
14
+ ***********************************************************************************************************/
15
+
16
+
17
+ #include "emu.h"
18
+ #include "pt554.h"
19
+
20
+
21
+ #ifdef NES_PCB_DEBUG
22
+ #define VERBOSE 1
23
+ #else
24
+ #define VERBOSE 0
25
+ #endif
26
+
27
+ #define LOG_MMC(x) do { if (VERBOSE) logerror x; } while (0)
28
+
29
+
30
+ //-------------------------------------------------
31
+ // constructor
32
+ //-------------------------------------------------
33
+
34
+ const device_type NES_BANDAI_PT554 = &device_creator<nes_bandai_pt554_device>;
35
+
36
+
37
+ nes_bandai_pt554_device::nes_bandai_pt554_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
38
+ : nes_cnrom_device(mconfig, NES_BANDAI_PT554, "NES Cart Bandai PT-554 PCB", tag, owner, clock, "nes_bandai_pt554", __FILE__),
39
+ m_samples(*this, "samples")
40
+ {
41
+ }
42
+
43
+
44
+
45
+ /*-------------------------------------------------
46
+ mapper specific handlers
47
+ -------------------------------------------------*/
48
+
49
+ /*-------------------------------------------------
50
+
51
+ Bandai PT-554 board emulation
52
+
53
+ This is used by Aerobics Studio. It is basically a CNROM board
54
+ with an Mitsubishi M50805 LPC / PARCOR speech synthesis chip
55
+ with internal tables stored in ROM which have not yet been dumped.
56
+
57
+ iNES: mapper 3?
58
+
59
+ -------------------------------------------------*/
60
+
61
+ WRITE8_MEMBER(nes_bandai_pt554_device::write_m)
62
+ {
63
+ LOG_MMC(("Bandai PT-554 Sound write, data: %02x\n", data));
64
+
65
+ if (!BIT(data, 6))
66
+ m_samples->start(data & 0x07, data & 0x07);
67
+ else
68
+ m_samples->stop(data & 0x07);
69
+ }
70
+
71
+ static const char *const pt554_sample_names[] =
72
+ {
73
+ "*ftaerobi",
74
+ "00",
75
+ "01",
76
+ "02",
77
+ "03",
78
+ "04",
79
+ "05",
80
+ "06",
81
+ "07",
82
+ nullptr
83
+ };
84
+
85
+ //-------------------------------------------------
86
+ // MACHINE_DRIVER
87
+ //-------------------------------------------------
88
+
89
+ static MACHINE_CONFIG_FRAGMENT( pt554 )
90
+
91
+ // additional sound hardware
92
+ MCFG_SPEAKER_STANDARD_MONO("addon")
93
+
94
+ MCFG_SOUND_ADD("samples", SAMPLES, 0)
95
+ MCFG_SAMPLES_CHANNELS(8)
96
+ MCFG_SAMPLES_NAMES(pt554_sample_names)
97
+ MCFG_SOUND_ROUTE(ALL_OUTPUTS, "addon", 0.50)
98
+ MACHINE_CONFIG_END
99
+
100
+ //-------------------------------------------------
101
+ // machine_config_additions
102
+ //-------------------------------------------------
103
+
104
+ machine_config_constructor nes_bandai_pt554_device::device_mconfig_additions() const
105
+ {
106
+ return MACHINE_CONFIG_NAME( pt554 );
107
+ }
pool/shard000/C++/0000200_pmic.cpp ADDED
@@ -0,0 +1,284 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ ******************************************************************************
3
+ * @file pmic.cpp
4
+ * @author Mohit Bhoite
5
+ * @version V1.0.0
6
+ * @date 11-August-2015
7
+ * @brief driver for the power managment IC BQ24195
8
+ ******************************************************************************
9
+ Copyright (c) 2013-2015 Particle Industries, Inc. All rights reserved.
10
+
11
+ This library is free software; you can redistribute it and/or
12
+ modify it under the terms of the GNU Lesser General Public
13
+ License as published by the Free Software Foundation, either
14
+ version 3 of the License, or (at your option) any later version.
15
+
16
+ This library is distributed in the hope that it will be useful,
17
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19
+ Lesser General Public License for more details.
20
+
21
+ You should have received a copy of the GNU Lesser General Public
22
+ License along with this library; if not, see <http://www.gnu.org/licenses/>.
23
+ ******************************************************************************
24
+ */
25
+
26
+
27
+ #include "PMIC.h"
28
+
29
+ PMIC::PMIC()
30
+ {
31
+
32
+ }
33
+
34
+
35
+ /*******************************************************************************
36
+ * Function Name :
37
+ * Description :
38
+ * Input :
39
+ * Return :
40
+ *******************************************************************************/
41
+ bool PMIC::begin()
42
+ {
43
+ Wire3.begin();
44
+ return 1;
45
+ }
46
+
47
+
48
+ // Return the version number of the chip
49
+ // Value at reset: 00100011, 0x23
50
+ byte PMIC::getVersion() {
51
+
52
+ byte DATA = 0;
53
+ DATA = readRegister(PMIC_VERSION_REGISTER);
54
+ return DATA;
55
+ }
56
+
57
+ /*
58
+ //-----------------------------------------------------------------------------
59
+ //System Status Register
60
+ //-----------------------------------------------------------------------------
61
+ //NOTE: This is a read-only register
62
+
63
+ REG08
64
+ BIT
65
+ --- VBUS status
66
+ 7: VBUS_STAT[1] | 00: Unknown (no input, or DPDM detection incomplete), 01: USB host
67
+ 6: VBUS_STAT[0] | 10: Adapter port, 11: OTG
68
+ --- Charging status
69
+ 5: CHRG_STAT[1] | 00: Not Charging, 01: Pre-charge (<VBATLOWV)
70
+ 4: CHRG_STAT[0] | 10: Fast Charging, 11: Charge termination done
71
+ 3: DPM_STAT 0: Not DPM
72
+ 1: VINDPM or IINDPM
73
+ 2: PG_STAT 0: Power NO Good :(
74
+ 1: Power Good :)
75
+ 1: THERM_STAT 0: Normal
76
+ 1: In Thermal Regulation (HOT)
77
+ 0: VSYS_STAT 0: Not in VSYSMIN regulation (BAT > VSYSMIN)
78
+ 1: In VSYSMIN regulation (BAT < VSYSMIN)
79
+ */
80
+
81
+ /*******************************************************************************
82
+ * Function Name :
83
+ * Description :
84
+ * Input :
85
+ * Return :
86
+ *******************************************************************************/
87
+ bool PMIC::isPowerGood(void) {
88
+
89
+ byte DATA = 0;
90
+ DATA = readRegister(SYSTEM_STATUS_REGISTER);
91
+ if(DATA & 0b00000100) return 1;
92
+ else return 0;
93
+ }
94
+
95
+ /*******************************************************************************
96
+ * Function Name :
97
+ * Description :
98
+ * Input :
99
+ * Return :
100
+ *******************************************************************************/
101
+ bool PMIC::isHot(void) {
102
+
103
+ byte DATA = 0;
104
+ DATA = readRegister(SYSTEM_STATUS_REGISTER);
105
+ if(DATA & 0b00000010) return 1;
106
+ else return 0;
107
+ }
108
+
109
+ /*******************************************************************************
110
+ * Function Name :
111
+ * Description :
112
+ * Input :
113
+ * Return :
114
+ *******************************************************************************/
115
+ byte PMIC::getSystemStatus() {
116
+
117
+ byte DATA = 0;
118
+ DATA = readRegister(SYSTEM_STATUS_REGISTER);
119
+ return DATA;
120
+ }
121
+
122
+ /*******************************************************************************
123
+ * Function Name :
124
+ * Description :
125
+ * Input :
126
+ * Return :
127
+ *******************************************************************************/
128
+ byte PMIC::getFault() {
129
+
130
+ byte DATA = 0;
131
+ DATA = readRegister(FAULT_REGISTER);
132
+ return DATA;
133
+
134
+ }
135
+
136
+ /*
137
+ //-----------------------------------------------------------------------------
138
+ // Input source control register
139
+ //-----------------------------------------------------------------------------
140
+
141
+ REG00
142
+ BIT
143
+ 7 : 0:Enable Buck regulator 1:disable buck regulator (powered only from a LiPo)
144
+ --- input volatge limit. this is used to determine if USB source is overloaded
145
+ 6 : VINDPM[3] 640mV | offset is 3.88V, Range is 3.88 to 5.08
146
+ 5 : VINDPM[2] 320mV | enabling bits 3 to 6 adds the volatges to 3.88 base value
147
+ 4 : VINDPM[1] 160mV | Default is 4.36 (0110)
148
+ 3 : VINDPM[0] 80mV |
149
+ --- input current limit
150
+ 2 : INLIM[2] 000: 100mA, 001: 150mA, 010: 500mA, | Default: 100mA when OTG pin is LOW and
151
+ 1 : INLIM[1] 011: 900mA, 100: 1.2A, 101: 1.5A | 500mA when OTG pin is HIGH
152
+ 0 : INLIM[0] 110: 2.0A, 111: 3.0A | when charging port detected, 1.5A
153
+
154
+ //-----------------------------------------------------------------------------
155
+ */
156
+
157
+
158
+ /*******************************************************************************
159
+ * Function Name : setInputCurrentLimit
160
+ * Description : Sets the input current limit for the PMIC
161
+ * Input : 100,150,500,900,1200,1500,2000,3000 (mAmp)
162
+ * Return : 0 Error, 1 Success
163
+ *******************************************************************************/
164
+
165
+ bool PMIC::setInputCurrentLimit(uint16_t current) {
166
+
167
+
168
+ byte DATA = readRegister(INPUT_SOURCE_REGISTER);
169
+ byte mask = DATA & 0b11111000;
170
+
171
+ switch (current) {
172
+
173
+ case 100:
174
+ writeRegister(INPUT_SOURCE_REGISTER, (mask | 0b00000000));
175
+ break;
176
+
177
+ case 150:
178
+ writeRegister(INPUT_SOURCE_REGISTER, (mask | 0b00000001));
179
+ break;
180
+
181
+ case 500:
182
+ writeRegister(INPUT_SOURCE_REGISTER, (mask | 0b00000010));
183
+ break;
184
+
185
+ case 900:
186
+ writeRegister(INPUT_SOURCE_REGISTER, (mask | 0b00000011));
187
+ break;
188
+
189
+ case 1200:
190
+ writeRegister(INPUT_SOURCE_REGISTER, (mask | 0b00000100));
191
+ break;
192
+
193
+ case 1500:
194
+ writeRegister(INPUT_SOURCE_REGISTER, (mask | 0b00000101));
195
+ break;
196
+
197
+ case 2000:
198
+ writeRegister(INPUT_SOURCE_REGISTER, (mask | 0b00000110));
199
+ break;
200
+
201
+ case 3000:
202
+ writeRegister(INPUT_SOURCE_REGISTER, (mask | 0b00000111));
203
+ break;
204
+
205
+ default:
206
+ return 0; // return error since the value passed didn't match
207
+ }
208
+
209
+ return 1; // value was written successfully
210
+ }
211
+
212
+ /*******************************************************************************
213
+ * Function Name : readInputSourceRegister
214
+ * Description :
215
+ * Input : NONE
216
+ * Return :
217
+ *******************************************************************************/
218
+
219
+ byte PMIC::readInputSourceRegister(void) {
220
+
221
+
222
+ return readRegister(INPUT_SOURCE_REGISTER);
223
+ }
224
+
225
+ /*******************************************************************************
226
+ * Function Name : enableBuck
227
+ * Description :
228
+ * Input : NONE
229
+ * Return :
230
+ *******************************************************************************/
231
+
232
+ bool PMIC::enableBuck(void) {
233
+
234
+ byte DATA = readRegister(INPUT_SOURCE_REGISTER);
235
+ writeRegister(INPUT_SOURCE_REGISTER, (DATA & 0b01111111));
236
+ return 1;
237
+ }
238
+
239
+ /*******************************************************************************
240
+ * Function Name : disableBuck
241
+ * Description :
242
+ * Input : NONE
243
+ * Return :
244
+ *******************************************************************************/
245
+
246
+ bool PMIC::disableBuck(void) {
247
+
248
+ byte DATA = readRegister(INPUT_SOURCE_REGISTER);
249
+ writeRegister(INPUT_SOURCE_REGISTER, (DATA | 0b10000000));
250
+ return 1;
251
+ }
252
+
253
+ /*******************************************************************************
254
+ * Function Name :
255
+ * Description :
256
+ * Input :
257
+ * Return :
258
+ *******************************************************************************/
259
+ byte PMIC::readRegister(byte startAddress) {
260
+
261
+ byte DATA = 0;
262
+ Wire3.beginTransmission(PMIC_ADDRESS);
263
+ Wire3.write(startAddress);
264
+ Wire3.endTransmission(true);
265
+
266
+ Wire3.requestFrom(PMIC_ADDRESS, 1, true);
267
+ DATA = Wire3.read();
268
+ return DATA;
269
+ }
270
+
271
+
272
+ /*******************************************************************************
273
+ * Function Name :
274
+ * Description :
275
+ * Input :
276
+ * Return :
277
+ *******************************************************************************/
278
+ void PMIC::writeRegister(byte address, byte DATA) {
279
+
280
+ Wire3.beginTransmission(PMIC_ADDRESS);
281
+ Wire3.write(address);
282
+ Wire3.write(DATA);
283
+ Wire3.endTransmission(true);
284
+ }
pool/shard000/C++/0000205_10526279.cpp ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //Language: GNU C++
2
+
3
+
4
+ //
5
+ // main.cpp
6
+ // Practice
7
+ //
8
+ // Created by Neel Shah on 11/27/14.
9
+ // Copyright (c) 2014 Neel Shah. All rights reserved.
10
+ //
11
+
12
+ #include <fstream>
13
+ #include <iostream>
14
+ #include <stdio.h>
15
+ #include <algorithm>
16
+ #include <vector>
17
+ #include <string.h>
18
+ #include <string>
19
+ #include <map>
20
+ #include<stack>
21
+ #include<map>
22
+ #include<queue>
23
+ #include <math.h>
24
+ #include<set>
25
+ #include<stdint.h>
26
+ #include <utility>
27
+ #include <cmath>
28
+ #include <iostream>
29
+ #include <iomanip>
30
+ #define MAXN 100005
31
+ #define MAXLG 17
32
+ #define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
33
+
34
+ using namespace std;
35
+ typedef long long int ll;
36
+ typedef pair<int, int> mp;
37
+ template<class T> void chmin(T &t, const T &f) { if (t > f) t = f; }
38
+ template<class T> void chmax(T &t, const T &f) { if (t < f) t = f; }
39
+
40
+ map<int, int> v[2*MAXN];;
41
+ vector<pair<int, int> > ans;
42
+ int n, m, deg[2*MAXN], eid = 0, self[2*MAXN]={0};
43
+
44
+ int main()
45
+ {
46
+ scanf("%d %d", &n, &m);
47
+ for(int i=0; i<m; ++i)
48
+ {
49
+ int x, y;
50
+ scanf("%d %d", &x, &y);
51
+ x--; y--;
52
+ if(x == y)
53
+ {
54
+ self[x]++;
55
+ continue;
56
+ }
57
+
58
+ deg[x]++; deg[y]++;
59
+ v[x][eid] = y;
60
+ v[y][eid] = x;
61
+ eid++;
62
+ }
63
+
64
+ vector<int> odd;
65
+ for(int i=0; i<n; ++i)
66
+ {
67
+ if(deg[i]%2)
68
+ odd.push_back(i);
69
+ if(odd.size() == 2)
70
+ {
71
+ int x = odd[0];
72
+ int y = odd[1];
73
+
74
+ v[x][eid] = y;
75
+ v[y][eid] = x;
76
+ odd.clear();
77
+ }
78
+ }
79
+
80
+ vector<int> path;
81
+ stack<int> s;
82
+ s.push(0);
83
+
84
+ while(!s.empty())
85
+ {
86
+ int node = s.top();
87
+ if(v[node].size() == 0)
88
+ {
89
+ s.pop();
90
+ path.push_back(node);
91
+ if(self[node] > 0)
92
+ {
93
+ for(int i=0; i<self[node]; ++i)
94
+ path.push_back(node);
95
+ self[node] = 0;
96
+ }
97
+ continue;
98
+ }
99
+
100
+ map<int, int>::iterator it = v[node].begin();
101
+ int id = it->first;
102
+ int next = it->second;
103
+
104
+ map<int, int>::iterator it1 = v[next].find(id);
105
+ v[next].erase(it1);
106
+ map<int, int>::iterator it2 = v[node].find(id);
107
+ v[node].erase(it2);
108
+
109
+ s.push(next);
110
+ }
111
+
112
+ // for(int i=0; i<path.size(); ++i)
113
+ // printf("%d ", path[i]+1);
114
+ // printf("\n");
115
+
116
+ path.erase(path.end()-1);
117
+ for(int i=1; i<path.size(); i+=2)
118
+ {
119
+ ans.push_back(mp(path[i-1], path[i]));
120
+ if(i+1 < path.size())
121
+ ans.push_back(mp(path[i+1], path[i]));
122
+ }
123
+
124
+ ans.push_back(mp(path[0], path[path.size()-1]));
125
+ if(path.size()%2)
126
+ ans.push_back(mp(path[path.size()-1], path[path.size()-1]));
127
+
128
+ printf("%ld\n",ans.size());
129
+ for(int i=0; i<ans.size(); ++i)
130
+ printf("%d %d\n", ans[i].first+1, ans[i].second+1);
131
+ return 0;
132
+ }
pool/shard000/C++/0000208_ReadEditDemoDlg.cpp ADDED
@@ -0,0 +1,187 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // ReadEditDemoDlg.cpp : implementation file
2
+ //
3
+
4
+ #include "stdafx.h"
5
+ #include "ReadEditDemo.h"
6
+ #include "ReadEditDemoDlg.h"
7
+
8
+ #ifdef _DEBUG
9
+ #define new DEBUG_NEW
10
+ #undef THIS_FILE
11
+ static char THIS_FILE[] = __FILE__;
12
+ #endif
13
+
14
+ /////////////////////////////////////////////////////////////////////////////
15
+ // CAboutDlg dialog used for App About
16
+
17
+ class CAboutDlg : public CDialog
18
+ {
19
+ public:
20
+ CAboutDlg();
21
+
22
+ // Dialog Data
23
+ //{{AFX_DATA(CAboutDlg)
24
+ enum { IDD = IDD_ABOUTBOX };
25
+ //}}AFX_DATA
26
+
27
+ // ClassWizard generated virtual function overrides
28
+ //{{AFX_VIRTUAL(CAboutDlg)
29
+ protected:
30
+ virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
31
+ //}}AFX_VIRTUAL
32
+
33
+ // Implementation
34
+ protected:
35
+ //{{AFX_MSG(CAboutDlg)
36
+ //}}AFX_MSG
37
+ DECLARE_MESSAGE_MAP()
38
+ };
39
+
40
+ CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
41
+ {
42
+ //{{AFX_DATA_INIT(CAboutDlg)
43
+ //}}AFX_DATA_INIT
44
+ }
45
+
46
+ void CAboutDlg::DoDataExchange(CDataExchange* pDX)
47
+ {
48
+ CDialog::DoDataExchange(pDX);
49
+ //{{AFX_DATA_MAP(CAboutDlg)
50
+ //}}AFX_DATA_MAP
51
+ }
52
+
53
+ BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
54
+ //{{AFX_MSG_MAP(CAboutDlg)
55
+ // No message handlers
56
+ //}}AFX_MSG_MAP
57
+ END_MESSAGE_MAP()
58
+
59
+ /////////////////////////////////////////////////////////////////////////////
60
+ // CReadEditDemoDlg dialog
61
+
62
+ CReadEditDemoDlg::CReadEditDemoDlg(CWnd* pParent /*=NULL*/)
63
+ : CDialog(CReadEditDemoDlg::IDD, pParent)
64
+ {
65
+ //{{AFX_DATA_INIT(CReadEditDemoDlg)
66
+ // NOTE: the ClassWizard will add member initialization here
67
+ //}}AFX_DATA_INIT
68
+ // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
69
+ m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
70
+ }
71
+
72
+ void CReadEditDemoDlg::DoDataExchange(CDataExchange* pDX)
73
+ {
74
+ CDialog::DoDataExchange(pDX);
75
+ //{{AFX_DATA_MAP(CReadEditDemoDlg)
76
+ DDX_Control(pDX, IDC_READEDIT, m_ctlRead);
77
+ //}}AFX_DATA_MAP
78
+ }
79
+
80
+ BEGIN_MESSAGE_MAP(CReadEditDemoDlg, CDialog)
81
+ //{{AFX_MSG_MAP(CReadEditDemoDlg)
82
+ ON_WM_SYSCOMMAND()
83
+ ON_WM_PAINT()
84
+ ON_WM_QUERYDRAGICON()
85
+ ON_BN_CLICKED(IDC_ADD, OnAdd)
86
+ ON_BN_CLICKED(IDC_CLEAR, OnClear)
87
+ //}}AFX_MSG_MAP
88
+ END_MESSAGE_MAP()
89
+
90
+ /////////////////////////////////////////////////////////////////////////////
91
+ // CReadEditDemoDlg message handlers
92
+
93
+ BOOL CReadEditDemoDlg::OnInitDialog()
94
+ {
95
+ CDialog::OnInitDialog();
96
+
97
+ // Add "About..." menu item to system menu.
98
+
99
+ // IDM_ABOUTBOX must be in the system command range.
100
+ ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
101
+ ASSERT(IDM_ABOUTBOX < 0xF000);
102
+
103
+ CMenu* pSysMenu = GetSystemMenu(FALSE);
104
+ if (pSysMenu != NULL)
105
+ {
106
+ CString strAboutMenu;
107
+ strAboutMenu.LoadString(IDS_ABOUTBOX);
108
+ if (!strAboutMenu.IsEmpty())
109
+ {
110
+ pSysMenu->AppendMenu(MF_SEPARATOR);
111
+ pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
112
+ }
113
+ }
114
+
115
+ // Set the icon for this dialog. The framework does this automatically
116
+ // when the application's main window is not a dialog
117
+ SetIcon(m_hIcon, TRUE); // Set big icon
118
+ SetIcon(m_hIcon, FALSE); // Set small icon
119
+
120
+ // TODO: Add extra initialization here
121
+
122
+ return TRUE; // return TRUE unless you set the focus to a control
123
+ }
124
+
125
+ void CReadEditDemoDlg::OnSysCommand(UINT nID, LPARAM lParam)
126
+ {
127
+ if ((nID & 0xFFF0) == IDM_ABOUTBOX)
128
+ {
129
+ CAboutDlg dlgAbout;
130
+ dlgAbout.DoModal();
131
+ }
132
+ else
133
+ {
134
+ CDialog::OnSysCommand(nID, lParam);
135
+ }
136
+ }
137
+
138
+ // If you add a minimize button to your dialog, you will need the code below
139
+ // to draw the icon. For MFC applications using the document/view model,
140
+ // this is automatically done for you by the framework.
141
+
142
+ void CReadEditDemoDlg::OnPaint()
143
+ {
144
+ if (IsIconic())
145
+ {
146
+ CPaintDC dc(this); // device context for painting
147
+
148
+ SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
149
+
150
+ // Center icon in client rectangle
151
+ int cxIcon = GetSystemMetrics(SM_CXICON);
152
+ int cyIcon = GetSystemMetrics(SM_CYICON);
153
+ CRect rect;
154
+ GetClientRect(&rect);
155
+ int x = (rect.Width() - cxIcon + 1) / 2;
156
+ int y = (rect.Height() - cyIcon + 1) / 2;
157
+
158
+ // Draw the icon
159
+ dc.DrawIcon(x, y, m_hIcon);
160
+ }
161
+ else
162
+ {
163
+ CDialog::OnPaint();
164
+ }
165
+ }
166
+
167
+ // The system calls this to obtain the cursor to display while the user drags
168
+ // the minimized window.
169
+ HCURSOR CReadEditDemoDlg::OnQueryDragIcon()
170
+ {
171
+ return (HCURSOR) m_hIcon;
172
+ }
173
+
174
+ void CReadEditDemoDlg::OnAdd()
175
+ {
176
+ // TODO: Add your control notification handler code here
177
+ CString strText;
178
+ GetDlgItemText (IDC_WRITEEDIT, strText);//»ñÈ¡±à¼­¿ò¿Ø¼þÎı¾
179
+ m_ctlRead.AppendString (strText);//Ìí¼Óµ½Ö»¶Á±à¼­¿ò¿Ø¼þÖÐ
180
+ SetDlgItemText (IDC_WRITEEDIT, "");
181
+ }
182
+
183
+ void CReadEditDemoDlg::OnClear()
184
+ {
185
+ // TODO: Add your control notification handler code here
186
+ SetDlgItemText (IDC_READEDIT, "");
187
+ }
pool/shard000/C++/0000211_SVGFETurbulenceElement.cpp ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3
+ * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org>
4
+ *
5
+ * This library is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU Library General Public
7
+ * License as published by the Free Software Foundation; either
8
+ * version 2 of the License, or (at your option) any later version.
9
+ *
10
+ * This library is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ * Library General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Library General Public License
16
+ * along with this library; see the file COPYING.LIB. If not, write to
17
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
+ * Boston, MA 02110-1301, USA.
19
+ */
20
+
21
+ #include "config.h"
22
+
23
+ #if ENABLE(SVG) && ENABLE(FILTERS)
24
+ #include "SVGFETurbulenceElement.h"
25
+
26
+ #include "Attribute.h"
27
+ #include "SVGElementInstance.h"
28
+ #include "SVGNames.h"
29
+ #include "SVGParserUtilities.h"
30
+
31
+ namespace WebCore {
32
+
33
+ // Animated property definitions
34
+ DEFINE_ANIMATED_NUMBER_MULTIPLE_WRAPPERS(SVGFETurbulenceElement, SVGNames::baseFrequencyAttr, baseFrequencyXIdentifier(), BaseFrequencyX, baseFrequencyX)
35
+ DEFINE_ANIMATED_NUMBER_MULTIPLE_WRAPPERS(SVGFETurbulenceElement, SVGNames::baseFrequencyAttr, baseFrequencyYIdentifier(), BaseFrequencyY, baseFrequencyY)
36
+ DEFINE_ANIMATED_INTEGER(SVGFETurbulenceElement, SVGNames::numOctavesAttr, NumOctaves, numOctaves)
37
+ DEFINE_ANIMATED_NUMBER(SVGFETurbulenceElement, SVGNames::seedAttr, Seed, seed)
38
+ DEFINE_ANIMATED_ENUMERATION(SVGFETurbulenceElement, SVGNames::stitchTilesAttr, StitchTiles, stitchTiles, SVGStitchOptions)
39
+ DEFINE_ANIMATED_ENUMERATION(SVGFETurbulenceElement, SVGNames::typeAttr, Type, type, TurbulenceType)
40
+
41
+ BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGFETurbulenceElement)
42
+ REGISTER_LOCAL_ANIMATED_PROPERTY(baseFrequencyX)
43
+ REGISTER_LOCAL_ANIMATED_PROPERTY(baseFrequencyY)
44
+ REGISTER_LOCAL_ANIMATED_PROPERTY(numOctaves)
45
+ REGISTER_LOCAL_ANIMATED_PROPERTY(seed)
46
+ REGISTER_LOCAL_ANIMATED_PROPERTY(stitchTiles)
47
+ REGISTER_LOCAL_ANIMATED_PROPERTY(type)
48
+ REGISTER_PARENT_ANIMATED_PROPERTIES(SVGFilterPrimitiveStandardAttributes)
49
+ END_REGISTER_ANIMATED_PROPERTIES
50
+
51
+ inline SVGFETurbulenceElement::SVGFETurbulenceElement(const QualifiedName& tagName, Document& document)
52
+ : SVGFilterPrimitiveStandardAttributes(tagName, document)
53
+ , m_numOctaves(1)
54
+ , m_stitchTiles(SVG_STITCHTYPE_NOSTITCH)
55
+ , m_type(FETURBULENCE_TYPE_TURBULENCE)
56
+ {
57
+ ASSERT(hasTagName(SVGNames::feTurbulenceTag));
58
+ registerAnimatedPropertiesForSVGFETurbulenceElement();
59
+ }
60
+
61
+ PassRefPtr<SVGFETurbulenceElement> SVGFETurbulenceElement::create(const QualifiedName& tagName, Document& document)
62
+ {
63
+ return adoptRef(new SVGFETurbulenceElement(tagName, document));
64
+ }
65
+
66
+ const AtomicString& SVGFETurbulenceElement::baseFrequencyXIdentifier()
67
+ {
68
+ DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGBaseFrequencyX", AtomicString::ConstructFromLiteral));
69
+ return s_identifier;
70
+ }
71
+
72
+ const AtomicString& SVGFETurbulenceElement::baseFrequencyYIdentifier()
73
+ {
74
+ DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGBaseFrequencyY", AtomicString::ConstructFromLiteral));
75
+ return s_identifier;
76
+ }
77
+
78
+ bool SVGFETurbulenceElement::isSupportedAttribute(const QualifiedName& attrName)
79
+ {
80
+ DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
81
+ if (supportedAttributes.isEmpty()) {
82
+ supportedAttributes.add(SVGNames::baseFrequencyAttr);
83
+ supportedAttributes.add(SVGNames::numOctavesAttr);
84
+ supportedAttributes.add(SVGNames::seedAttr);
85
+ supportedAttributes.add(SVGNames::stitchTilesAttr);
86
+ supportedAttributes.add(SVGNames::typeAttr);
87
+ }
88
+ return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
89
+ }
90
+
91
+ void SVGFETurbulenceElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
92
+ {
93
+ if (!isSupportedAttribute(name)) {
94
+ SVGFilterPrimitiveStandardAttributes::parseAttribute(name, value);
95
+ return;
96
+ }
97
+
98
+ if (name == SVGNames::typeAttr) {
99
+ TurbulenceType propertyValue = SVGPropertyTraits<TurbulenceType>::fromString(value);
100
+ if (propertyValue > 0)
101
+ setTypeBaseValue(propertyValue);
102
+ return;
103
+ }
104
+
105
+ if (name == SVGNames::stitchTilesAttr) {
106
+ SVGStitchOptions propertyValue = SVGPropertyTraits<SVGStitchOptions>::fromString(value);
107
+ if (propertyValue > 0)
108
+ setStitchTilesBaseValue(propertyValue);
109
+ return;
110
+ }
111
+
112
+ if (name == SVGNames::baseFrequencyAttr) {
113
+ float x, y;
114
+ if (parseNumberOptionalNumber(value, x, y)) {
115
+ setBaseFrequencyXBaseValue(x);
116
+ setBaseFrequencyYBaseValue(y);
117
+ }
118
+ return;
119
+ }
120
+
121
+ if (name == SVGNames::seedAttr) {
122
+ setSeedBaseValue(value.toFloat());
123
+ return;
124
+ }
125
+
126
+ if (name == SVGNames::numOctavesAttr) {
127
+ setNumOctavesBaseValue(value.string().toUIntStrict());
128
+ return;
129
+ }
130
+
131
+ ASSERT_NOT_REACHED();
132
+ }
133
+
134
+ bool SVGFETurbulenceElement::setFilterEffectAttribute(FilterEffect* effect, const QualifiedName& attrName)
135
+ {
136
+ FETurbulence* turbulence = static_cast<FETurbulence*>(effect);
137
+ if (attrName == SVGNames::typeAttr)
138
+ return turbulence->setType(type());
139
+ if (attrName == SVGNames::stitchTilesAttr)
140
+ return turbulence->setStitchTiles(stitchTiles());
141
+ if (attrName == SVGNames::baseFrequencyAttr)
142
+ return (turbulence->setBaseFrequencyX(baseFrequencyX()) || turbulence->setBaseFrequencyY(baseFrequencyY()));
143
+ if (attrName == SVGNames::seedAttr)
144
+ return turbulence->setSeed(seed());
145
+ if (attrName == SVGNames::numOctavesAttr)
146
+ return turbulence->setNumOctaves(numOctaves());
147
+
148
+ ASSERT_NOT_REACHED();
149
+ return false;
150
+ }
151
+
152
+ void SVGFETurbulenceElement::svgAttributeChanged(const QualifiedName& attrName)
153
+ {
154
+ if (!isSupportedAttribute(attrName)) {
155
+ SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName);
156
+ return;
157
+ }
158
+
159
+ SVGElementInstance::InvalidationGuard invalidationGuard(this);
160
+
161
+ if (attrName == SVGNames::baseFrequencyAttr
162
+ || attrName == SVGNames::numOctavesAttr
163
+ || attrName == SVGNames::seedAttr
164
+ || attrName == SVGNames::stitchTilesAttr
165
+ || attrName == SVGNames::typeAttr) {
166
+ primitiveAttributeChanged(attrName);
167
+ return;
168
+ }
169
+
170
+ ASSERT_NOT_REACHED();
171
+ }
172
+
173
+ PassRefPtr<FilterEffect> SVGFETurbulenceElement::build(SVGFilterBuilder*, Filter* filter)
174
+ {
175
+ if (baseFrequencyX() < 0 || baseFrequencyY() < 0)
176
+ return 0;
177
+ return FETurbulence::create(filter, type(), baseFrequencyX(), baseFrequencyY(), numOctaves(), seed(), stitchTiles() == SVG_STITCHTYPE_STITCH);
178
+ }
179
+
180
+ }
181
+
182
+ #endif // ENABLE(SVG)
pool/shard000/C++/0000212_mis_fun.cc ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*!
2
+ * @file mis_fun.cc
3
+ * @brief Thread utility functions.
4
+ *
5
+ * @author Piotr Trojanek <piotr.trojanek@gmail.com>
6
+ *
7
+ * @ingroup LIB
8
+ */
9
+
10
+ #include <pthread.h>
11
+ #include <cstdio>
12
+ #include <unistd.h>
13
+ #include <string>
14
+ #include <errno.h>
15
+ #include <string.h>
16
+
17
+ #include "base/lib/mis_fun.h"
18
+
19
+ #if defined(linux)
20
+ #include <sys/prctl.h>
21
+ #elif defined(__FreeBSD__)
22
+ #include <pthread_np.h>
23
+ #endif
24
+
25
+ namespace mrrocpp {
26
+ namespace lib {
27
+
28
+ //! Set the process scheduler
29
+ void set_process_sched()
30
+ {
31
+ struct sched_param param;
32
+
33
+ int policy_priority_min = sched_get_priority_min(SCHED_FIFO);
34
+ if (policy_priority_min == -1) {
35
+ perror("sched_get_priority_min() ");
36
+ }
37
+
38
+ param.sched_priority = policy_priority_min;
39
+
40
+ if (sched_setscheduler(getpid(), SCHED_FIFO, &param) == -1) {
41
+ perror("sched_setscheduler() ");
42
+ }
43
+ }
44
+
45
+ void set_thread_priority(int sched_priority_l)
46
+ {
47
+ const pthread_t thread = pthread_self();
48
+
49
+ int policy;
50
+ struct sched_param param;
51
+
52
+ if (pthread_getschedparam(thread, &policy, &param)) {
53
+ perror("pthread_getschedparam() ");
54
+ }
55
+
56
+ // check priority range
57
+ int policy_priority_min = sched_get_priority_min(SCHED_FIFO);
58
+ if (policy_priority_min == -1) {
59
+ perror("sched_get_priority_min() ");
60
+ }
61
+
62
+ int policy_priority_max = sched_get_priority_max(SCHED_FIFO);
63
+ if (policy_priority_max == -1) {
64
+ perror("sched_get_priority_max() ");
65
+ }
66
+
67
+ //pthread_setscheduler(thread, SCHED_FIFO, sched_priority_l);
68
+
69
+ if ((sched_priority_l < policy_priority_min) || (sched_priority_l > policy_priority_max)) {
70
+ fprintf(stderr, "requested thread priority (%d) not in <%d:%d> priority range\n", sched_priority_l, policy_priority_min, policy_priority_max);
71
+ } else {
72
+ param.sched_priority = sched_priority_l;
73
+ if (pthread_setschedparam(thread, SCHED_FIFO, &param)) {
74
+ fprintf(stderr, "pthread_setschedparam(%lu, SCHED_FIFO, %d) failed: %s\n", thread, sched_priority_l, strerror(errno));
75
+ //perror("pthread_setschedparam() ");
76
+ }
77
+ }
78
+ }
79
+
80
+ //! set the thread name for debugging
81
+ int set_thread_name(const char * newname)
82
+ {
83
+ #if defined(linux)
84
+ char comm[16];
85
+ snprintf(comm, sizeof(comm), "%s", newname);
86
+ return prctl(PR_SET_NAME, comm, 0l, 0l, 0l);
87
+ #elif defined(__FreeBSD__)
88
+ // FreeBSD defines this call to void
89
+ pthread_set_name_np(pthread_self(), newname);
90
+
91
+ return 0;
92
+ #endif
93
+ return -1;
94
+ }
95
+
96
+ #ifndef TIMESPEC_VALID
97
+ # define TIMESPEC_VALID(__ts) ((__ts)->tv_nsec >= 0 && (__ts)->tv_nsec < 1000000000L)
98
+ #endif
99
+
100
+ void timespec_increment_ns(struct timespec * ts, unsigned long increment)
101
+ {
102
+ ts->tv_nsec += increment;
103
+ while (ts->tv_nsec >= 1000000000) {
104
+ ts->tv_sec += 1;
105
+ ts->tv_nsec -= 1000000000;
106
+ }
107
+ }
108
+
109
+ } // namespace lib
110
+ } // namespace mrrocpp
pool/shard000/C++/0000213_SensorProcessor.cpp ADDED
@@ -0,0 +1,174 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file SensorProcessor.cpp
3
+ * @author George Andrew Brindeiro (georgebrindeiro@lara.unb.br)
4
+ * @date Dec 10, 2013
5
+ *
6
+ * @ingroup ros-nodes
7
+ *
8
+ * @attention Copyright (C) 2013
9
+ * @attention Laboratório de Automação e Robótica (LARA)
10
+ * @attention Universidade de Brasília (UnB)
11
+ */
12
+
13
+ #include <SensorProcessor/SensorProcessor.h>
14
+
15
+ bool print_msgs = false;
16
+ bool display_features = true;
17
+
18
+ ros::Publisher pub_cloud;
19
+ ros::Publisher pub_pose; // TODO: remove this when filter is running
20
+
21
+ int main (int argc, char** argv)
22
+ {
23
+ // Initialize ROS
24
+ ros::init (argc, argv, "hs_sensor_processor");
25
+ ros::NodeHandle nh;
26
+
27
+ // Create ROS subscribers for sensor data
28
+ ros::Subscriber sub_cloud = nh.subscribe ("kinect_cloud", 1, cloud_cb);
29
+
30
+ // Create a ROS publisher for processed sensor data
31
+ pub_cloud = nh.advertise<sensor_msgs::PointCloud2> ("feature_cloud", 1);
32
+
33
+ // Create a CV window for debugging
34
+ if(display_features)
35
+ cv::namedWindow("Display window", CV_WINDOW_AUTOSIZE);
36
+
37
+ // TODO: remove this when filter is running
38
+ ros::Subscriber sub_odom = nh.subscribe ("odometry", 1, odom_cb);
39
+ pub_pose = nh.advertise<geometry_msgs::PoseWithCovarianceStamped> ("estimated_pose", 1);
40
+
41
+ // Spin
42
+ ros::spin ();
43
+ }
44
+
45
+ void cloud_cb(const sensor_msgs::PointCloud2::ConstPtr& cloud_msg)
46
+ {
47
+ // Print cloud message
48
+ if(print_msgs)
49
+ print_cloud_msg(cloud_msg);
50
+
51
+ // Extract RGB image from cloud
52
+ cv::Mat img;
53
+ extract_rgb_image(cloud_msg, img);
54
+
55
+ // Detect keypoints from RGB image
56
+ std::vector<cv::KeyPoint> keypoints;
57
+ extract_keypoints(img, keypoints);
58
+
59
+ // Build feature cloud from keypoints
60
+ sensor_msgs::PointCloud2::Ptr feature_cloud_msg(new sensor_msgs::PointCloud2);
61
+ build_feature_cloud(keypoints, cloud_msg, feature_cloud_msg);
62
+
63
+ // Publish the data
64
+ pub_cloud.publish(feature_cloud_msg);
65
+ }
66
+
67
+ void odom_cb(const nav_msgs::Odometry::ConstPtr& odom_msg)
68
+ {
69
+ // Fake pose estimate from odometry
70
+ geometry_msgs::PoseWithCovarianceStamped::Ptr estimated_pose_msg(new geometry_msgs::PoseWithCovarianceStamped);
71
+ estimated_pose_msg->header = odom_msg->header;
72
+ estimated_pose_msg->pose = odom_msg->pose;
73
+
74
+ pub_pose.publish(estimated_pose_msg);
75
+ }
76
+
77
+ void print_cloud_msg(const sensor_msgs::PointCloud2::ConstPtr& cloud_msg)
78
+ {
79
+ // Parse cloud message
80
+ int seq = cloud_msg->header.seq;
81
+ int time_sec = cloud_msg->header.stamp.sec;
82
+ int time_nsec = cloud_msg->header.stamp.nsec;
83
+ std::string frame_id = cloud_msg->header.frame_id;
84
+ int width = cloud_msg->width;
85
+ int height = cloud_msg->height;
86
+ bool is_bigendian = cloud_msg->is_bigendian;
87
+ int point_step = cloud_msg->point_step;
88
+ int row_step = cloud_msg->row_step;
89
+ bool is_dense = cloud_msg->is_dense;
90
+
91
+ // Print cloud message for debugging
92
+ ROS_INFO("Point cloud\n");
93
+ ROS_INFO("seq: %d", seq);
94
+ ROS_INFO("timestamp: %d.%d", time_sec, time_nsec);
95
+ ROS_INFO("frame_id: %s", frame_id.c_str());
96
+ ROS_INFO("dimensions: %dx%d", width, height);
97
+ ROS_INFO("is_bigendian: %d", is_bigendian);
98
+ ROS_INFO("point_step: %d\n", point_step);
99
+ ROS_INFO("row_step: %d\n", row_step);
100
+ ROS_INFO("is_dense: %d\n", is_dense);
101
+ ROS_INFO("------------------------------------------------------");
102
+ }
103
+
104
+ void extract_rgb_image(const sensor_msgs::PointCloud2::ConstPtr& cloud_msg, cv::Mat& img)
105
+ {
106
+ // Copy the RGB fields of a sensor_msgs::PointCloud2 into a sensor_msgs::Image
107
+ sensor_msgs::Image image_msg;
108
+ pcl::toROSMsg(*cloud_msg, image_msg);
109
+
110
+ // Convert a sensor_msgs::Image to an OpenCV-compatible CvImage, copying the image data.
111
+ cv_bridge::CvImagePtr cv_image_ptr;
112
+ cv_image_ptr = cv_bridge::toCvCopy(image_msg);
113
+
114
+ // Assign cv::Mat portion of CvImage to output
115
+ img = cv_image_ptr->image;
116
+ }
117
+
118
+ void extract_keypoints(cv::Mat& img, std::vector<cv::KeyPoint>& keypoints)
119
+ {
120
+ // Extract SURF keypoints
121
+ int minHessian = 400;
122
+
123
+ cv::SurfFeatureDetector detector(minHessian);
124
+ detector.detect(img, keypoints);
125
+
126
+ // Display detected keypoints
127
+ if(display_features)
128
+ {
129
+ // Print out number of features
130
+ //ROS_INFO("# features: %ld", keypoints.size());
131
+
132
+ // Overlay keypoints on image
133
+ cv::drawKeypoints(img, keypoints, img, cv::Scalar::all(-1), cv::DrawMatchesFlags::DEFAULT);
134
+
135
+ // Show results in display window
136
+ cv::imshow("Display window", img);
137
+ cv::waitKey(10);
138
+ }
139
+ }
140
+
141
+ void build_feature_cloud(const std::vector<cv::KeyPoint>& keypoints, const sensor_msgs::PointCloud2::ConstPtr& cloud_msg, sensor_msgs::PointCloud2::Ptr& feature_cloud_msg)
142
+ {
143
+ // Work with PCL compatible variables
144
+ pcl::PointIndices::Ptr keypoint_indices(new pcl::PointIndices());
145
+ pcl::PCLPointCloud2::Ptr pcl_input(new pcl::PCLPointCloud2);
146
+ pcl::PCLPointCloud2::Ptr pcl_output(new pcl::PCLPointCloud2);
147
+
148
+ // Convert keypoints to PCL format
149
+ for(int i=0; i < keypoints.size(); i++)
150
+ {
151
+ int x = keypoints[i].pt.x;//1-640
152
+ int y = keypoints[i].pt.y;//1-480
153
+
154
+ keypoint_indices->indices.push_back(cloud_msg->width*y+x);
155
+ }
156
+
157
+ // Convert cloud_msg to PCL format
158
+ pcl_conversions::toPCL(*cloud_msg, *pcl_input);
159
+
160
+ // Use ExtractIndices filter to build feature cloud
161
+ pcl::ExtractIndices<pcl::PCLPointCloud2> extract;
162
+
163
+ extract.setInputCloud(pcl_input);
164
+ extract.setIndices(keypoint_indices);
165
+ extract.setNegative(false);
166
+ extract.filter(*pcl_output);
167
+
168
+ // Convert pcl_output to ROS format
169
+ pcl_conversions::fromPCL(*pcl_output, *feature_cloud_msg);
170
+
171
+ // Print out number of features for debugging
172
+ if(display_features)
173
+ ROS_INFO("# feature cloud points: %d", pcl_output->width * pcl_output->height);
174
+ }
pool/shard000/C++/0000216_moc_qaccessibleplugin.cpp ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /****************************************************************************
2
+ ** Meta object code from reading C++ file 'qaccessibleplugin.h'
3
+ **
4
+ ** Created: Mon 26. Nov 09:30:49 2012
5
+ ** by: The Qt Meta Object Compiler version 63 (Qt 4.8.4)
6
+ **
7
+ ** WARNING! All changes made in this file will be lost!
8
+ *****************************************************************************/
9
+
10
+ #include "../../../accessible/qaccessibleplugin.h"
11
+ #if !defined(Q_MOC_OUTPUT_REVISION)
12
+ #error "The header file 'qaccessibleplugin.h' doesn't include <QObject>."
13
+ #elif Q_MOC_OUTPUT_REVISION != 63
14
+ #error "This file was generated using the moc from 4.8.4. It"
15
+ #error "cannot be used with the include files from this version of Qt."
16
+ #error "(The moc has changed too much.)"
17
+ #endif
18
+
19
+ QT_BEGIN_MOC_NAMESPACE
20
+ static const uint qt_meta_data_QAccessiblePlugin[] = {
21
+
22
+ // content:
23
+ 6, // revision
24
+ 0, // classname
25
+ 0, 0, // classinfo
26
+ 0, 0, // methods
27
+ 0, 0, // properties
28
+ 0, 0, // enums/sets
29
+ 0, 0, // constructors
30
+ 0, // flags
31
+ 0, // signalCount
32
+
33
+ 0 // eod
34
+ };
35
+
36
+ static const char qt_meta_stringdata_QAccessiblePlugin[] = {
37
+ "QAccessiblePlugin\0"
38
+ };
39
+
40
+ void QAccessiblePlugin::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
41
+ {
42
+ Q_UNUSED(_o);
43
+ Q_UNUSED(_id);
44
+ Q_UNUSED(_c);
45
+ Q_UNUSED(_a);
46
+ }
47
+
48
+ const QMetaObjectExtraData QAccessiblePlugin::staticMetaObjectExtraData = {
49
+ 0, qt_static_metacall
50
+ };
51
+
52
+ const QMetaObject QAccessiblePlugin::staticMetaObject = {
53
+ { &QObject::staticMetaObject, qt_meta_stringdata_QAccessiblePlugin,
54
+ qt_meta_data_QAccessiblePlugin, &staticMetaObjectExtraData }
55
+ };
56
+
57
+ #ifdef Q_NO_DATA_RELOCATION
58
+ const QMetaObject &QAccessiblePlugin::getStaticMetaObject() { return staticMetaObject; }
59
+ #endif //Q_NO_DATA_RELOCATION
60
+
61
+ const QMetaObject *QAccessiblePlugin::metaObject() const
62
+ {
63
+ return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject;
64
+ }
65
+
66
+ void *QAccessiblePlugin::qt_metacast(const char *_clname)
67
+ {
68
+ if (!_clname) return 0;
69
+ if (!strcmp(_clname, qt_meta_stringdata_QAccessiblePlugin))
70
+ return static_cast<void*>(const_cast< QAccessiblePlugin*>(this));
71
+ if (!strcmp(_clname, "QAccessibleFactoryInterface"))
72
+ return static_cast< QAccessibleFactoryInterface*>(const_cast< QAccessiblePlugin*>(this));
73
+ if (!strcmp(_clname, QAccessibleFactoryInterface_iid))
74
+ return static_cast< QAccessibleFactoryInterface*>(const_cast< QAccessiblePlugin*>(this));
75
+ if (!strcmp(_clname, "com.trolltech.Qt.QFactoryInterface"))
76
+ return static_cast< QFactoryInterface*>(static_cast< QAccessibleFactoryInterface*>(const_cast< QAccessiblePlugin*>(this)));
77
+ return QObject::qt_metacast(_clname);
78
+ }
79
+
80
+ int QAccessiblePlugin::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
81
+ {
82
+ _id = QObject::qt_metacall(_c, _id, _a);
83
+ if (_id < 0)
84
+ return _id;
85
+ return _id;
86
+ }
87
+ QT_END_MOC_NAMESPACE
pool/shard000/C++/0000219_MonitoredProcess.cpp ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
2
+
3
+ #include "CorePrivatePCH.h"
4
+ #include "Misc/MonitoredProcess.h"
5
+
6
+ /* FMonitoredProcess structors
7
+ *****************************************************************************/
8
+
9
+ FMonitoredProcess::FMonitoredProcess( const FString& InURL, const FString& InParams, bool InHidden, bool InCreatePipes )
10
+ : Canceling(false)
11
+ , EndTime(0)
12
+ , Hidden(InHidden)
13
+ , KillTree(false)
14
+ , Params(InParams)
15
+ , ReadPipe(nullptr)
16
+ , ReturnCode(0)
17
+ , StartTime(0)
18
+ , Thread(nullptr)
19
+ , URL(InURL)
20
+ , WritePipe(nullptr)
21
+ , bCreatePipes(InCreatePipes)
22
+ , SleepInterval(0.0f)
23
+ { }
24
+
25
+
26
+ FMonitoredProcess::~FMonitoredProcess()
27
+ {
28
+ if (IsRunning())
29
+ {
30
+ Cancel(true);
31
+ Thread->WaitForCompletion();
32
+ delete Thread;
33
+ }
34
+ }
35
+
36
+
37
+ /* FMonitoredProcess interface
38
+ *****************************************************************************/
39
+
40
+ FTimespan FMonitoredProcess::GetDuration() const
41
+ {
42
+ if (IsRunning())
43
+ {
44
+ return (FDateTime::UtcNow() - StartTime);
45
+ }
46
+
47
+ return (EndTime - StartTime);
48
+ }
49
+
50
+
51
+ bool FMonitoredProcess::Launch()
52
+ {
53
+ if (IsRunning())
54
+ {
55
+ return false;
56
+ }
57
+
58
+ if (bCreatePipes && !FPlatformProcess::CreatePipe(ReadPipe, WritePipe))
59
+ {
60
+ return false;
61
+ }
62
+
63
+ ProcessHandle = FPlatformProcess::CreateProc(*URL, *Params, false, Hidden, Hidden, nullptr, 0, *FPaths::RootDir(), WritePipe);
64
+
65
+ if (!ProcessHandle.IsValid())
66
+ {
67
+ return false;
68
+ }
69
+
70
+ static int32 MonitoredProcessIndex = 0;
71
+ const FString MonitoredProcessName = FString::Printf( TEXT( "FMonitoredProcess %d" ), MonitoredProcessIndex );
72
+ MonitoredProcessIndex++;
73
+
74
+ Thread = FRunnableThread::Create(this, *MonitoredProcessName, 128 * 1024, TPri_AboveNormal);
75
+
76
+ return true;
77
+ }
78
+
79
+
80
+ /* FMonitoredProcess implementation
81
+ *****************************************************************************/
82
+
83
+ void FMonitoredProcess::ProcessOutput( const FString& Output )
84
+ {
85
+ TArray<FString> LogLines;
86
+
87
+ Output.ParseIntoArray(LogLines, TEXT("\n"), false);
88
+
89
+ for (int32 LogIndex = 0; LogIndex < LogLines.Num(); ++LogIndex)
90
+ {
91
+ OutputDelegate.ExecuteIfBound(LogLines[LogIndex]);
92
+ }
93
+ }
94
+
95
+
96
+ /* FRunnable interface
97
+ *****************************************************************************/
98
+
99
+ uint32 FMonitoredProcess::Run()
100
+ {
101
+ // monitor the process
102
+ StartTime = FDateTime::UtcNow();
103
+ {
104
+ do
105
+ {
106
+ FPlatformProcess::Sleep(SleepInterval);
107
+
108
+ ProcessOutput(FPlatformProcess::ReadPipe(ReadPipe));
109
+
110
+ if (Canceling)
111
+ {
112
+ FPlatformProcess::TerminateProc(ProcessHandle, KillTree);
113
+ CanceledDelegate.ExecuteIfBound();
114
+ Thread = nullptr;
115
+
116
+ return 0;
117
+ }
118
+ }
119
+ while (FPlatformProcess::IsProcRunning(ProcessHandle));
120
+ }
121
+ EndTime = FDateTime::UtcNow();
122
+
123
+ // close output pipes
124
+ FPlatformProcess::ClosePipe(ReadPipe, WritePipe);
125
+ ReadPipe = WritePipe = nullptr;
126
+
127
+ // get completion status
128
+ if (!FPlatformProcess::GetProcReturnCode(ProcessHandle, &ReturnCode))
129
+ {
130
+ ReturnCode = -1;
131
+ }
132
+
133
+ CompletedDelegate.ExecuteIfBound(ReturnCode);
134
+ Thread = nullptr;
135
+
136
+ return 0;
137
+ }
pool/shard000/C++/0000221_UI.cpp ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include "UI.h"
2
+ #include "App.h"
3
+
4
+ #include <nana/gui/widgets/label.hpp>
5
+ #include <nana/gui/timer.hpp>
6
+
7
+ using namespace Zephyr;
8
+
9
+ Zephyr::UI::UI(const std::string & windowTitle, App * pApp) : mpApp(pApp), mZoom(0)
10
+ {
11
+ mpForm.reset( new nana::form(nana::rectangle{ 0, 0, mpApp->getWidth(), mpApp->getHeight() }) );
12
+ mpForm->caption(windowTitle);
13
+
14
+ nana::rectangle UIRect = nana::rectangle{ 10, 10, 145, 260 };
15
+
16
+ mpNfm.reset(new nana::nested_form(*mpForm, UIRect, nana::form::appear::bald<>()));
17
+
18
+ // set the HWND from the UI framework to the App
19
+ mpApp->getHwnd() = reinterpret_cast<HWND>(mpForm->native_handle());
20
+
21
+ initialize();
22
+ }
23
+
24
+ Zephyr::UI::~UI()
25
+ {
26
+ }
27
+
28
+ bool Zephyr::UI::initialize()
29
+ {
30
+ // Mouse events
31
+ setupMouseMouseEvent();
32
+ setupMouseClickEvent();
33
+ setupMouseWheelEvent();
34
+
35
+ return true;
36
+ }
37
+
38
+ void Zephyr::UI::show()
39
+ {
40
+ mpNfm->show();
41
+ mpForm->show();
42
+ }
43
+
44
+ std::shared_ptr<nana::form> Zephyr::UI::getForm()
45
+ {
46
+ return mpForm;
47
+ }
48
+
49
+ std::shared_ptr<nana::nested_form> Zephyr::UI::getNestedForm()
50
+ {
51
+ return mpNfm;
52
+ }
53
+
54
+ std::shared_ptr<nana::label> Zephyr::UI::getLabel(const std::string & labelName)
55
+ {
56
+ return std::shared_ptr<nana::label>(dynamic_cast<nana::label*>(mWidgetList[labelName].get()));
57
+ }
58
+
59
+ std::shared_ptr<nana::label> Zephyr::UI::createLabel(std::shared_ptr<nana::nested_form> parent, const std::string & labelName, nana::rectangle & rect)
60
+ {
61
+ std::shared_ptr<nana::label> pLabel(new nana::label(*parent, rect));
62
+ pLabel->caption(labelName);
63
+
64
+ mWidgetList.insert(std::make_pair(labelName, pLabel));
65
+
66
+ return pLabel;
67
+ }
68
+
69
+ void Zephyr::UI::updateCaption(const std::string & widgetName, const std::string caption)
70
+ {
71
+ auto widget = mWidgetList[widgetName];
72
+ widget->caption(caption);
73
+ }
74
+
75
+ std::shared_ptr<nana::button> Zephyr::UI::getButton(const std::string & buttonName)
76
+ {
77
+ return std::shared_ptr<nana::button>(dynamic_cast<nana::button*>(mWidgetList[buttonName].get()));
78
+ }
79
+
80
+ std::shared_ptr<nana::button> Zephyr::UI::createButton(std::shared_ptr<nana::nested_form> parent, const std::string & buttonName, nana::rectangle& rect)
81
+ {
82
+ std::shared_ptr<nana::button> pButton(new nana::button(*parent, rect));
83
+ pButton->caption(buttonName);
84
+
85
+ mWidgetList.insert(std::make_pair(buttonName, pButton));
86
+
87
+ return pButton;
88
+ }
89
+
90
+ std::shared_ptr<nana::slider> Zephyr::UI::getSlider(const std::string & sliderName)
91
+ {
92
+ return std::shared_ptr<nana::slider>(dynamic_cast<nana::slider*>(mWidgetList[sliderName].get()));
93
+ }
94
+
95
+ std::shared_ptr<nana::slider> Zephyr::UI::createSlider(std::shared_ptr<nana::nested_form> parent, const std::string & sliderName, nana::rectangle & rect)
96
+ {
97
+ std::shared_ptr<nana::slider> pSlider(new nana::slider(*parent, rect));
98
+ pSlider->caption(sliderName);
99
+
100
+ mWidgetList.insert(std::make_pair(sliderName, pSlider));
101
+
102
+ return pSlider;
103
+ }
104
+
105
+ void Zephyr::UI::setupMouseMouseEvent()
106
+ {
107
+ mpForm->events().mouse_move([&](const nana::arg_mouse& mouseEvent)
108
+ {
109
+ int deltaX = mouseEvent.pos.x - mMousePosition[0];
110
+ int deltaY = mouseEvent.pos.y - mMousePosition[1];
111
+
112
+ // hold Mid mouse for zoom
113
+ if (mouseEvent.mid_button)
114
+ {
115
+ mpApp->getCamera()->zoom((float)-deltaY);
116
+ }
117
+
118
+ if (mouseEvent.right_button)
119
+ {
120
+ mpApp->getCamera()->rotation((float)deltaX * 0.75f, (float)deltaY * 0.75f);
121
+ }
122
+
123
+ mMousePosition[0] = mouseEvent.pos.x;
124
+ mMousePosition[1] = mouseEvent.pos.y;
125
+ });
126
+ }
127
+
128
+ void Zephyr::UI::setupMouseClickEvent()
129
+ {
130
+ mpForm->events().click([&](const nana::arg_click& clickEvent)
131
+ {
132
+ if (clickEvent.mouse_args->is_left_button())
133
+ {
134
+ auto pickingRay = mpApp->getCamera()->getPickingRay(clickEvent.mouse_args->pos.x, clickEvent.mouse_args->pos.y);
135
+ }
136
+ });
137
+ }
138
+
139
+ void Zephyr::UI::setupMouseWheelEvent()
140
+ {
141
+ // one notch of mouse wheel delta is 120
142
+ const float MOUSE_WHEEL_DELTA = 120.0f;
143
+ mpForm->events().mouse_wheel([&](const nana::arg_wheel& mouseWheelEvent)
144
+ {
145
+ auto distance = (mouseWheelEvent.distance / MOUSE_WHEEL_DELTA) * 10;
146
+ distance = mouseWheelEvent.upwards ? distance : -distance;
147
+
148
+ mpApp->getCamera()->zoom(distance);
149
+ });
150
+ }
pool/shard000/C++/0000225_MethodOfGettingAValueProfile.cpp ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright (C) 2012 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 "MethodOfGettingAValueProfile.h"
28
+
29
+ #if ENABLE(DFG_JIT)
30
+
31
+ #include "CodeBlock.h"
32
+
33
+ namespace JSC {
34
+
35
+ MethodOfGettingAValueProfile MethodOfGettingAValueProfile::fromLazyOperand(
36
+ CodeBlock* codeBlock, const LazyOperandValueProfileKey& key)
37
+ {
38
+ MethodOfGettingAValueProfile result;
39
+ result.m_kind = LazyOperand;
40
+ result.u.lazyOperand.codeBlock = codeBlock;
41
+ result.u.lazyOperand.bytecodeOffset = key.bytecodeOffset();
42
+ result.u.lazyOperand.operand = key.operand();
43
+ return result;
44
+ }
45
+
46
+ EncodedJSValue* MethodOfGettingAValueProfile::getSpecFailBucket(unsigned index) const
47
+ {
48
+ switch (m_kind) {
49
+ case None:
50
+ return 0;
51
+
52
+ case Ready:
53
+ return u.profile->specFailBucket(index);
54
+
55
+ case LazyOperand:
56
+ return u.lazyOperand.codeBlock->lazyOperandValueProfiles().add(
57
+ LazyOperandValueProfileKey(
58
+ u.lazyOperand.bytecodeOffset, u.lazyOperand.operand))->specFailBucket(index);
59
+
60
+ default:
61
+ RELEASE_ASSERT_NOT_REACHED();
62
+ return 0;
63
+ }
64
+ }
65
+
66
+ } // namespace JSC
67
+
68
+ #endif // ENABLE(DFG_JIT)
69
+
pool/shard000/C++/0000238_c_te_bubbletrail.cpp ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //======== (C) Copyright 1999, 2000 Valve, L.L.C. All rights reserved. ========
2
+ //
3
+ // The copyright to the contents herein is the property of Valve, L.L.C.
4
+ // The contents may be used and/or copied only with the written permission of
5
+ // Valve, L.L.C., or in accordance with the terms and conditions stipulated in
6
+ // the agreement/contract under which the contents have been supplied.
7
+ //
8
+ // Purpose:
9
+ //
10
+ // $Workfile: $
11
+ // $Date: $
12
+ // $NoKeywords: $
13
+ //=============================================================================
14
+ #include "cbase.h"
15
+ #include "c_basetempentity.h"
16
+ #include "c_te_legacytempents.h"
17
+
18
+ //-----------------------------------------------------------------------------
19
+ // Purpose: Bubble Trail TE
20
+ //-----------------------------------------------------------------------------
21
+ class C_TEBubbleTrail : public C_BaseTempEntity
22
+ {
23
+ public:
24
+ DECLARE_CLASS( C_TEBubbleTrail, C_BaseTempEntity );
25
+ DECLARE_CLIENTCLASS();
26
+
27
+ C_TEBubbleTrail( void );
28
+ virtual ~C_TEBubbleTrail( void );
29
+
30
+ virtual void PostDataUpdate( DataUpdateType_t updateType );
31
+
32
+ public:
33
+ Vector m_vecMins;
34
+ Vector m_vecMaxs;
35
+ float m_fHeight;
36
+ int m_nModelIndex;
37
+ int m_nCount;
38
+ float m_fSpeed;
39
+ };
40
+
41
+ //-----------------------------------------------------------------------------
42
+ // Purpose:
43
+ //-----------------------------------------------------------------------------
44
+ C_TEBubbleTrail::C_TEBubbleTrail( void )
45
+ {
46
+ m_vecMins.Init();
47
+ m_vecMaxs.Init();
48
+ m_fHeight = 0.0;
49
+ m_nModelIndex = 0;
50
+ m_nCount = 0;
51
+ m_fSpeed = 0;
52
+ }
53
+
54
+ //-----------------------------------------------------------------------------
55
+ // Purpose:
56
+ //-----------------------------------------------------------------------------
57
+ C_TEBubbleTrail::~C_TEBubbleTrail( void )
58
+ {
59
+ }
60
+
61
+ void TE_BubbleTrail( IRecipientFilter& filter, float delay,
62
+ const Vector* mins, const Vector* maxs, float height, int modelindex, int count, float speed )
63
+ {
64
+ tempents->BubbleTrail( *mins, *maxs, height, modelindex, count, speed );
65
+ }
66
+
67
+ //-----------------------------------------------------------------------------
68
+ // Purpose:
69
+ // Input : bool -
70
+ //-----------------------------------------------------------------------------
71
+ void C_TEBubbleTrail::PostDataUpdate( DataUpdateType_t updateType )
72
+ {
73
+ tempents->BubbleTrail( m_vecMins, m_vecMaxs, m_fHeight, m_nModelIndex, m_nCount, m_fSpeed );
74
+ }
75
+
76
+ IMPLEMENT_CLIENTCLASS_EVENT_DT(C_TEBubbleTrail, DT_TEBubbleTrail, CTEBubbleTrail)
77
+ RecvPropVector( RECVINFO(m_vecMins)),
78
+ RecvPropVector( RECVINFO(m_vecMaxs)),
79
+ RecvPropInt( RECVINFO(m_nModelIndex)),
80
+ RecvPropFloat( RECVINFO(m_fHeight )),
81
+ RecvPropInt( RECVINFO(m_nCount)),
82
+ RecvPropFloat( RECVINFO(m_fSpeed )),
83
+ END_RECV_TABLE()
pool/shard000/C++/0000239_2.cc ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Set iterator invalidation tests
2
+
3
+ // Copyright (C) 2003-2013 Free Software Foundation, Inc.
4
+ //
5
+ // This file is part of the GNU ISO C++ Library. This library is free
6
+ // software; you can redistribute it and/or modify it under the
7
+ // terms of the GNU General Public License as published by the
8
+ // Free Software Foundation; either version 3, or (at your option)
9
+ // any later version.
10
+
11
+ // This library is distributed in the hope that it will be useful,
12
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ // GNU General Public License for more details.
15
+
16
+ // You should have received a copy of the GNU General Public License along
17
+ // with this library; see the file COPYING3. If not see
18
+ // <http://www.gnu.org/licenses/>.
19
+
20
+ #include <debug/set>
21
+ #include <iterator>
22
+ #include <testsuite_hooks.h>
23
+
24
+ using __gnu_debug::set;
25
+ using std::advance;
26
+
27
+ // Erase
28
+ void test02()
29
+ {
30
+ bool test __attribute__((unused)) = true;
31
+
32
+ set<int> v;
33
+ for (int i = 0; i < 20; ++i)
34
+ v.insert(i);
35
+
36
+ // Single element erase (middle)
37
+ set<int>::iterator before = v.begin();
38
+ set<int>::iterator at = before;
39
+ advance(at, 3);
40
+ set<int>::iterator after = at;
41
+ ++after;
42
+ v.erase(at);
43
+ VERIFY(before._M_dereferenceable());
44
+ VERIFY(at._M_singular());
45
+ VERIFY(after._M_dereferenceable());
46
+
47
+ // Multiple element erase
48
+ before = v.begin();
49
+ at = before;
50
+ advance(at, 3);
51
+ after = at;
52
+ advance(after, 4);
53
+ v.erase(at, after);
54
+ VERIFY(before._M_dereferenceable());
55
+ VERIFY(at._M_singular());
56
+
57
+ // clear()
58
+ before = v.begin();
59
+ set<int>::iterator finish = v.end();
60
+ VERIFY(before._M_dereferenceable());
61
+ v.clear();
62
+ VERIFY(before._M_singular());
63
+ VERIFY(!finish._M_singular() && !finish._M_dereferenceable());
64
+ }
65
+
66
+ int main()
67
+ {
68
+ test02();
69
+ return 0;
70
+ }
pool/shard000/C++/0000240_tfs_random.cpp ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /******************************************
2
+ * TrafficFS
3
+ * v0.2
4
+ * ----------------------------
5
+ * Traffic Flow Simulator
6
+ *
7
+ * Coded in C++
8
+ * Copyright (c) 2010 by Dr.Kameleon
9
+ *******************************************
10
+ * file : tfs_utils.cpp
11
+ *******************************************/
12
+
13
+ #include "trafficfs.h"
14
+
15
+ Random::Random()
16
+ {
17
+ unsigned seed = time (0);
18
+ srand (seed);
19
+ }
20
+
21
+ string Random::genLicense()
22
+ {
23
+ const char* const plateLetters = "ABEHIKMNOPTXYZ";
24
+ string output = "";
25
+
26
+ for (int i=0; i<3; i++)
27
+ {
28
+ int r = rand()%14;
29
+ output += plateLetters[r];
30
+ }
31
+
32
+ for (int i=0; i<4; i++)
33
+ {
34
+ int r = (rand()%9)+1;
35
+
36
+ stringstream out;
37
+ out << r;
38
+
39
+ output += out.str();
40
+ }
41
+
42
+ return output;
43
+ }
44
+
45
+ string Random::genName()
46
+ {
47
+ const char* const Letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
48
+ string output = "";
49
+
50
+ for (int i=0; i<5; i++)
51
+ {
52
+ int r = rand()%26;
53
+ output += Letters[r];
54
+ }
55
+
56
+ return output;
57
+ }
58
+
59
+ float Random::genSpeed()
60
+ {
61
+ return (rand()%100)+40;
62
+ }
63
+
64
+ directionType Random::genDirection()
65
+ {
66
+ int r = rand()%2;
67
+
68
+ if (r==1)
69
+ return ALPHA;
70
+ else
71
+ return BETA;
72
+ }
73
+
74
+ float Random::genDistance()
75
+ {
76
+ return ((rand()%TFS_MAXDISTANCE)+5)*1000;
77
+ }