Pendigard commited on
Commit
b3787d8
·
verified ·
1 Parent(s): aaf7d06

Upload folder using huggingface_hub (part 83)

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/shard007/C++/0095105_boss_lockmaw.cpp +160 -0
  2. pool/shard007/C++/0095108_awt_Container.cpp +58 -0
  3. pool/shard007/C++/0095114_rssdownloadrulelist.cpp +185 -0
  4. pool/shard007/C++/0095115_main.cpp +68 -0
  5. pool/shard007/C++/0095118_browser_plugin_geolocation_permission_context.cc +94 -0
  6. pool/shard007/C++/0095119_csg_dump.cc +99 -0
  7. pool/shard007/C++/0095120_pair.cpp +141 -0
  8. pool/shard007/C++/0095121_put.cc +91 -0
  9. pool/shard007/C++/0095125_pmt_tests.cpp +126 -0
  10. pool/shard007/C++/0095127_simpledeformation.cpp +94 -0
  11. pool/shard007/C++/0095128_DemoColorImageByScore.cpp +74 -0
  12. pool/shard007/C++/0095129_led.cpp +62 -0
  13. pool/shard007/C++/0095136_websocket_server.cpp +172 -0
  14. pool/shard007/C++/0095139_test_thread_exit.cpp +63 -0
  15. pool/shard007/C++/0095148_ice_transport_adapter_impl.cc +220 -0
  16. pool/shard007/C++/0095151_ipc.cc +212 -0
  17. pool/shard007/C++/0095153_sortstrategy.cpp +90 -0
  18. pool/shard007/C++/0095157_clippingPlane.cpp +101 -0
  19. pool/shard007/C++/0095169_bitcoin.cpp +270 -0
  20. pool/shard007/C++/0095170_rotatecamera.cpp +118 -0
  21. pool/shard007/C++/0095178_hotmetadata.cpp +86 -0
  22. pool/shard007/C++/0095185_test_window_manager.cc +112 -0
  23. pool/shard007/C++/0095186_TcrDistributionManager.cpp +60 -0
  24. pool/shard007/C++/0095191_X3DShadersContext.cpp +230 -0
  25. pool/shard007/C++/0095194_arcball.cpp +132 -0
  26. pool/shard007/C++/0095197_ChunkChecksum.cc +88 -0
  27. pool/shard007/C++/0095209_Particle.cpp +80 -0
  28. pool/shard007/C++/0095217_propagateremotemove.cpp +165 -0
  29. pool/shard007/C++/0095224_TableViewPlugin.cpp +123 -0
  30. pool/shard007/C++/0095225_tmwxPrintout.cpp +89 -0
  31. pool/shard007/C++/0095227_wizardpage.cpp +52 -0
  32. pool/shard007/C++/0095228_string.cpp +111 -0
  33. pool/shard007/C++/0095231_line_following.cpp +206 -0
  34. pool/shard007/C++/0095232_abstractliveedittool.cpp +185 -0
  35. pool/shard007/C++/0095235_Map.cpp +79 -0
  36. pool/shard007/C++/0095236_SysClass.cpp +200 -0
  37. pool/shard007/C++/0095238_background_application_loader.cc +74 -0
  38. pool/shard007/C++/0095240_main.cpp +105 -0
  39. pool/shard007/C++/0095242_extension_uninstall_dialog_view.cc +247 -0
  40. pool/shard007/C++/0095243_memory.cpp +129 -0
  41. pool/shard007/C++/0095244_cmakeeditorfactory.cpp +78 -0
  42. pool/shard007/C++/0095245_bundle.cpp +141 -0
  43. pool/shard007/C++/0095246_AboutScreen.cpp +75 -0
  44. pool/shard007/C++/0095248_recursive_mutex_impl.cc +245 -0
  45. pool/shard007/C++/0095254_cmd_reverse_frames.cpp +67 -0
  46. pool/shard007/C++/0095257_OgreCgProgramManagerDll.cpp +72 -0
  47. pool/shard007/C++/0095259_animation-playlist.cpp +110 -0
  48. pool/shard007/C++/0095261_Http.cpp +176 -0
  49. pool/shard007/C++/0095264_chrome_elf_main.cc +100 -0
  50. pool/shard007/C++/0095271_test_size_handling.cpp +169 -0
pool/shard007/C++/0095105_boss_lockmaw.cpp ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ *
3
+ * Copyright (C) 2011-2012 ArkCORE2 <http://www.arkania.net/>
4
+ * Copyright (C) 2010-2012 Project SkyFire <http://www.projectskyfire.org/>
5
+ *
6
+ *
7
+ * This program is free software; you can redistribute it and/or modify it
8
+ * under the terms of the GNU General Public License as published by the
9
+ * Free Software Foundation; either version 3 of the License, or (at your
10
+ * option) any later version.
11
+ *
12
+ * This program is distributed in the hope that it will be useful, but WITHOUT
13
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15
+ * more details.
16
+ *
17
+ * You should have received a copy of the GNU General Public License along
18
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
19
+ */
20
+
21
+ #include"ScriptPCH.h"
22
+ #include"WorldPacket.h"
23
+ #include"lost_city_of_the_tolvir.h"
24
+ #include"ScriptMgr.h"
25
+ #include"ScriptedCreature.h"
26
+ #include"SpellScript.h"
27
+ #include"SpellAuraEffects.h"
28
+
29
+ enum Spells
30
+ {
31
+ SPELL_DUST_FLAIL = 81642,
32
+ SPELL_SCENT_OF_BLOOD = 81690,
33
+ H_SPELL_SCENT_OF_BLOOD = 89998,
34
+ SPELL_VENOMOUS_RAGE = 81706,
35
+ SPELL_VISCOUS_POISON = 81630,
36
+ H_SPELL_VISCOUS_POISON = 90004,
37
+ };
38
+
39
+ enum Events
40
+ {
41
+ EVENT_DUST_FLAIL = 1,
42
+ EVENT_SCENT_OF_BLOOD = 2,
43
+ EVENT_VENOMOUS_RAGE = 3,
44
+ EVENT_VISCOUS_POISON = 4,
45
+ };
46
+
47
+ enum SummonIds
48
+ {
49
+ NPC_FRENZIED_CROCOLISK = 43658,
50
+ };
51
+
52
+ const Position SummonLocations[4] =
53
+ {
54
+ //Frenzied Crocolisks
55
+ {-11033.29f, -1674.57f, -0.56f, 1.09f},
56
+ {-11029.84f, -1673.09f, -0.37f, 2.33f},
57
+ {-11007.25f, -1666.37f, -0.23f, 2.46f},
58
+ {-11006.83f, -1666.85f, -0.25f, 2.23f},
59
+ };
60
+
61
+ class boss_lockmaw : public CreatureScript
62
+ {
63
+ public:
64
+ boss_lockmaw() : CreatureScript("boss_lockmaw") {}
65
+
66
+ CreatureAI* GetAI(Creature* creature) const
67
+ {
68
+ return new boss_lockmawAI(creature);
69
+ }
70
+ struct boss_lockmawAI : public ScriptedAI
71
+ {
72
+ boss_lockmawAI(Creature* creature) : ScriptedAI(creature), Summons(me)
73
+ {
74
+ instance = creature->GetInstanceScript();
75
+ }
76
+
77
+ InstanceScript* instance;
78
+ EventMap events;
79
+ SummonList Summons;
80
+ bool check_in;
81
+
82
+ void Reset ()
83
+ {
84
+ events.Reset();
85
+ Summons.DespawnAll();
86
+
87
+ if (instance && (instance->GetData(DATA_LOCKMAW_EVENT) != DONE && !check_in))
88
+ instance->SetData(DATA_LOCKMAW_EVENT, NOT_STARTED);
89
+
90
+ check_in = false;
91
+ }
92
+
93
+ void JustDied(Unit* /*Kill*/)
94
+ {
95
+ Summons.DespawnAll();
96
+ if (instance)
97
+ instance->SetData(DATA_LOCKMAW_EVENT, DONE);
98
+ }
99
+
100
+ void EnterCombat(Unit* /*Ent*/)
101
+ {
102
+ if (instance)
103
+ instance->SetData(DATA_LOCKMAW_EVENT, IN_PROGRESS);
104
+
105
+ DoZoneInCombat();
106
+ }
107
+
108
+ void UpdateAI(const uint32 uiDiff)
109
+ {
110
+ if (!UpdateVictim()) /* No target to kill */
111
+ return;
112
+
113
+ events.Update(uiDiff);
114
+
115
+ if (me->HasUnitState(UNIT_STATE_CASTING))
116
+ return;
117
+
118
+ while (uint32 eventId = events.ExecuteEvent())
119
+ {
120
+ switch (eventId)
121
+ {
122
+ case EVENT_DUST_FLAIL:
123
+ DoCast(me->getVictim(), SPELL_DUST_FLAIL);
124
+ events.ScheduleEvent(EVENT_DUST_FLAIL, urand(6000, 10000));
125
+ return;
126
+ case EVENT_VISCOUS_POISON:
127
+ if (Unit* target = SelectTarget(SELECT_TARGET_RANDOM, true))
128
+ DoCast(me->getVictim(), SPELL_VISCOUS_POISON);
129
+ events.ScheduleEvent(EVENT_VISCOUS_POISON, 2000);
130
+ return;
131
+ case EVENT_SCENT_OF_BLOOD:
132
+ if (Unit* target = SelectTarget(SELECT_TARGET_RANDOM, true))
133
+ DoCast(me->getVictim(), SPELL_SCENT_OF_BLOOD);
134
+ for (uint8 i=0; i<4; i++)
135
+ {
136
+ Creature* Crocolisk = me->SummonCreature(NPC_FRENZIED_CROCOLISK, SummonLocations[i], TEMPSUMMON_CORPSE_DESPAWN);
137
+ Crocolisk->AddThreat(me->getVictim(), 0.0f);
138
+ DoZoneInCombat(Crocolisk);
139
+ }
140
+ events.ScheduleEvent(EVENT_SCENT_OF_BLOOD, 6000);
141
+ return;
142
+ case EVENT_VENOMOUS_RAGE:
143
+ if (me->GetHealthPct() < 30)
144
+ DoCast(me, SPELL_VENOMOUS_RAGE);
145
+ events.ScheduleEvent(EVENT_VENOMOUS_RAGE, 1000);
146
+ return;
147
+ default:
148
+ break;
149
+ }
150
+ }
151
+
152
+ DoMeleeAttackIfReady();
153
+ }
154
+ };
155
+ };
156
+
157
+ void AddSC_boss_lockmaw()
158
+ {
159
+ new boss_lockmaw();
160
+ }
pool/shard007/C++/0095108_awt_Container.cpp ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 1998-2008 Sun Microsystems, Inc. All Rights Reserved.
3
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
+ *
5
+ * This code is free software; you can redistribute it and/or modify it
6
+ * under the terms of the GNU General Public License version 2 only, as
7
+ * published by the Free Software Foundation. Sun designates this
8
+ * particular file as subject to the "Classpath" exception as provided
9
+ * by Sun in the LICENSE file that accompanied this code.
10
+ *
11
+ * This code is distributed in the hope that it will be useful, but WITHOUT
12
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
+ * version 2 for more details (a copy is included in the LICENSE file that
15
+ * accompanied this code).
16
+ *
17
+ * You should have received a copy of the GNU General Public License version
18
+ * 2 along with this work; if not, write to the Free Software Foundation,
19
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
+ *
21
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22
+ * CA 95054 USA or visit www.sun.com if you need additional information or
23
+ * have any questions.
24
+ */
25
+
26
+ #include "awt_Container.h"
27
+ #include "awt.h"
28
+
29
+ /************************************************************************
30
+ * AwtContainer fields
31
+ */
32
+
33
+ jfieldID AwtContainer::layoutMgrID;
34
+ jmethodID AwtContainer::findComponentAtMID;
35
+
36
+ /************************************************************************
37
+ * AwtContainer native methods
38
+ */
39
+
40
+ extern "C" {
41
+
42
+ JNIEXPORT void JNICALL
43
+ Java_java_awt_Container_initIDs(JNIEnv *env, jclass cls) {
44
+ TRY;
45
+
46
+ AwtContainer::layoutMgrID =
47
+ env->GetFieldID(cls, "layoutMgr", "Ljava/awt/LayoutManager;");
48
+
49
+ AwtContainer::findComponentAtMID =
50
+ env->GetMethodID(cls, "findComponentAt", "(IIZ)Ljava/awt/Component;");
51
+
52
+ DASSERT(AwtContainer::layoutMgrID != NULL);
53
+ DASSERT(AwtContainer::findComponentAtMID);
54
+
55
+ CATCH_BAD_ALLOC;
56
+ }
57
+
58
+ } /* extern "C" */
pool/shard007/C++/0095114_rssdownloadrulelist.cpp ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Bittorrent Client using Qt and libtorrent.
3
+ * Copyright (C) 2010 Christophe Dumez
4
+ *
5
+ * This program is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU General Public License
7
+ * as published by the Free Software Foundation; either version 2
8
+ * of the License, or (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, write to the Free Software
17
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
+ *
19
+ * In addition, as a special exception, the copyright holders give permission to
20
+ * link this program with the OpenSSL project's "OpenSSL" library (or with
21
+ * modified versions of it that use the same license as the "OpenSSL" library),
22
+ * and distribute the linked executables. You must obey the GNU General Public
23
+ * License in all respects for all of the code used other than "OpenSSL". If you
24
+ * modify file(s), you may extend this exception to your version of the file(s),
25
+ * but you are not obligated to do so. If you do not wish to do so, delete this
26
+ * exception statement from your version.
27
+ *
28
+ * Contact : chris@qbittorrent.org
29
+ */
30
+
31
+ #include <QFile>
32
+ #include <QDataStream>
33
+ #include <QDebug>
34
+
35
+ #include "base/preferences.h"
36
+ #include "base/qinisettings.h"
37
+ #include "rssdownloadrulelist.h"
38
+
39
+ using namespace Rss;
40
+
41
+ DownloadRuleList::DownloadRuleList()
42
+ {
43
+ loadRulesFromStorage();
44
+ }
45
+
46
+ DownloadRulePtr DownloadRuleList::findMatchingRule(const QString &feedUrl, const QString &articleTitle) const
47
+ {
48
+ Q_ASSERT(Preferences::instance()->isRssDownloadingEnabled());
49
+ QStringList ruleNames = m_feedRules.value(feedUrl);
50
+ foreach (const QString &rule_name, ruleNames) {
51
+ DownloadRulePtr rule = m_rules[rule_name];
52
+ if (rule->isEnabled() && rule->matches(articleTitle)) return rule;
53
+ }
54
+ return DownloadRulePtr();
55
+ }
56
+
57
+ void DownloadRuleList::replace(DownloadRuleList *other)
58
+ {
59
+ m_rules.clear();
60
+ m_feedRules.clear();
61
+ foreach (const QString &name, other->ruleNames()) {
62
+ saveRule(other->getRule(name));
63
+ }
64
+ }
65
+
66
+ void DownloadRuleList::saveRulesToStorage()
67
+ {
68
+ QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss");
69
+ qBTRSS.setValue("download_rules", toVariantHash());
70
+ }
71
+
72
+ void DownloadRuleList::loadRulesFromStorage()
73
+ {
74
+ QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss");
75
+ loadRulesFromVariantHash(qBTRSS.value("download_rules").toHash());
76
+ }
77
+
78
+ QVariantHash DownloadRuleList::toVariantHash() const
79
+ {
80
+ QVariantHash ret;
81
+ foreach (const DownloadRulePtr &rule, m_rules.values()) {
82
+ ret.insert(rule->name(), rule->toVariantHash());
83
+ }
84
+ return ret;
85
+ }
86
+
87
+ void DownloadRuleList::loadRulesFromVariantHash(const QVariantHash &h)
88
+ {
89
+ QVariantHash::ConstIterator it = h.begin();
90
+ QVariantHash::ConstIterator itend = h.end();
91
+ for ( ; it != itend; ++it) {
92
+ DownloadRulePtr rule = DownloadRule::fromVariantHash(it.value().toHash());
93
+ if (rule && !rule->name().isEmpty())
94
+ saveRule(rule);
95
+ }
96
+ }
97
+
98
+ void DownloadRuleList::saveRule(const DownloadRulePtr &rule)
99
+ {
100
+ qDebug() << Q_FUNC_INFO << rule->name();
101
+ Q_ASSERT(rule);
102
+ if (m_rules.contains(rule->name())) {
103
+ qDebug("This is an update, removing old rule first");
104
+ removeRule(rule->name());
105
+ }
106
+ m_rules.insert(rule->name(), rule);
107
+ // Update feedRules hashtable
108
+ foreach (const QString &feedUrl, rule->rssFeeds()) {
109
+ m_feedRules[feedUrl].append(rule->name());
110
+ }
111
+ qDebug() << Q_FUNC_INFO << "EXIT";
112
+ }
113
+
114
+ void DownloadRuleList::removeRule(const QString &name)
115
+ {
116
+ qDebug() << Q_FUNC_INFO << name;
117
+ if (!m_rules.contains(name)) return;
118
+ DownloadRulePtr rule = m_rules.take(name);
119
+ // Update feedRules hashtable
120
+ foreach (const QString &feedUrl, rule->rssFeeds()) {
121
+ m_feedRules[feedUrl].removeOne(rule->name());
122
+ }
123
+ }
124
+
125
+ void DownloadRuleList::renameRule(const QString &oldName, const QString &newName)
126
+ {
127
+ if (!m_rules.contains(oldName)) return;
128
+
129
+ DownloadRulePtr rule = m_rules.take(oldName);
130
+ rule->setName(newName);
131
+ m_rules.insert(newName, rule);
132
+ // Update feedRules hashtable
133
+ foreach (const QString &feedUrl, rule->rssFeeds()) {
134
+ m_feedRules[feedUrl].replace(m_feedRules[feedUrl].indexOf(oldName), newName);
135
+ }
136
+ }
137
+
138
+ DownloadRulePtr DownloadRuleList::getRule(const QString &name) const
139
+ {
140
+ return m_rules.value(name);
141
+ }
142
+
143
+ QStringList DownloadRuleList::ruleNames() const
144
+ {
145
+ return m_rules.keys();
146
+ }
147
+
148
+ bool DownloadRuleList::isEmpty() const
149
+ {
150
+ return m_rules.isEmpty();
151
+ }
152
+
153
+ bool DownloadRuleList::serialize(const QString &path)
154
+ {
155
+ QFile f(path);
156
+ if (f.open(QIODevice::WriteOnly)) {
157
+ QDataStream out(&f);
158
+ out.setVersion(QDataStream::Qt_4_5);
159
+ out << toVariantHash();
160
+ f.close();
161
+ return true;
162
+ }
163
+
164
+ return false;
165
+ }
166
+
167
+ bool DownloadRuleList::unserialize(const QString &path)
168
+ {
169
+ QFile f(path);
170
+ if (f.open(QIODevice::ReadOnly)) {
171
+ QDataStream in(&f);
172
+ in.setVersion(QDataStream::Qt_4_5);
173
+ QVariantHash tmp;
174
+ in >> tmp;
175
+ f.close();
176
+ if (tmp.isEmpty())
177
+ return false;
178
+ qDebug("Processing was successful!");
179
+ loadRulesFromVariantHash(tmp);
180
+ return true;
181
+ } else {
182
+ qDebug("Error: could not open file at %s", qPrintable(path));
183
+ return false;
184
+ }
185
+ }
pool/shard007/C++/0095115_main.cpp ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include "almath.h"
2
+ #include "vector"
3
+
4
+ #include <iostream>
5
+
6
+ using namespace almath::network;
7
+
8
+
9
+ void print_table(Table<char, int> t);
10
+
11
+ int main()
12
+ {
13
+
14
+
15
+ std::vector<char> x = { 'a', 'b', 'c', 'd' };
16
+
17
+
18
+
19
+ almath::network::Table<char, int> test(x, x, -1);
20
+
21
+ print_table(test);
22
+
23
+ test.editElement('a', 'a', 1);
24
+
25
+ int newRow[4] = {5, 6, 3, 4};
26
+ int newCol[4] = {5, 2, 3, 1};
27
+
28
+ print_table(test);
29
+
30
+ test.addColumnData('b', newRow);
31
+ test.addRowData('d', newCol);
32
+
33
+ test.addRow('e');
34
+
35
+ int newCol1[5] = {1, 2, 3, 4, 5};
36
+
37
+ test.addColumnData('e', newCol1);
38
+
39
+
40
+ return 0;
41
+ }
42
+
43
+ void print_table(Table<char, int> t)
44
+ {
45
+ const std::vector<char> *rows = t.getRows();
46
+ const std::vector<char> *columns = t.getColumns();
47
+
48
+ for(int i = 0; i < columns->size(); i++)
49
+ {
50
+ std::cout << "\t" << (*columns)[i];
51
+ }
52
+
53
+ std::cout << std::endl;
54
+ for(int i = 0; i < columns->size(); i++)
55
+ {
56
+ std::cout << "\t" << "__";
57
+ }
58
+ std::cout << std::endl;
59
+
60
+ for (int i = 0; i < rows->size(); i++)
61
+ {
62
+ std::cout << (*rows)[i] << "|\t";
63
+ for(int x = 0; x < columns->size(); x++)
64
+ std::cout << t[(*rows)[i]][x] << "\t";
65
+
66
+ std::cout << std::endl;
67
+ }
68
+ }
pool/shard007/C++/0095118_browser_plugin_geolocation_permission_context.cc ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2013 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ #include "content/browser/browser_plugin/browser_plugin_geolocation_permission_context.h"
6
+
7
+ #include "base/bind.h"
8
+ #include "content/browser/browser_plugin/browser_plugin_guest.h"
9
+ #include "content/browser/web_contents/web_contents_impl.h"
10
+ #include "content/public/browser/browser_thread.h"
11
+ #include "content/public/browser/render_process_host.h"
12
+ #include "content/public/browser/render_view_host.h"
13
+
14
+ namespace content {
15
+
16
+ BrowserPluginGeolocationPermissionContext::
17
+ BrowserPluginGeolocationPermissionContext() {
18
+ }
19
+
20
+ BrowserPluginGeolocationPermissionContext::
21
+ ~BrowserPluginGeolocationPermissionContext() {
22
+ }
23
+
24
+ void BrowserPluginGeolocationPermissionContext::RequestGeolocationPermission(
25
+ int render_process_id,
26
+ int render_view_id,
27
+ int bridge_id,
28
+ const GURL& requesting_frame,
29
+ base::Callback<void(bool)> callback) {
30
+ if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
31
+ BrowserThread::PostTask(
32
+ BrowserThread::UI, FROM_HERE,
33
+ base::Bind(
34
+ &BrowserPluginGeolocationPermissionContext::
35
+ RequestGeolocationPermission,
36
+ this,
37
+ render_process_id,
38
+ render_view_id,
39
+ bridge_id,
40
+ requesting_frame,
41
+ callback));
42
+ return;
43
+ }
44
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
45
+
46
+ // Note that callback.Run(true) allows geolocation access, callback.Run(false)
47
+ // denies geolocation access.
48
+ // We need to go to the renderer to ask embedder's js if we are allowed to
49
+ // have geolocation access.
50
+ RenderViewHost* rvh = RenderViewHost::FromID(render_process_id,
51
+ render_view_id);
52
+ if (rvh) {
53
+ DCHECK(rvh->GetProcess()->IsGuest());
54
+ WebContentsImpl* guest_web_contents =
55
+ static_cast<WebContentsImpl*>(rvh->GetDelegate()->GetAsWebContents());
56
+ BrowserPluginGuest* guest = guest_web_contents->GetBrowserPluginGuest();
57
+ guest->AskEmbedderForGeolocationPermission(bridge_id,
58
+ requesting_frame,
59
+ callback);
60
+ }
61
+ }
62
+
63
+ void BrowserPluginGeolocationPermissionContext::
64
+ CancelGeolocationPermissionRequest(int render_process_id,
65
+ int render_view_id,
66
+ int bridge_id,
67
+ const GURL& requesting_frame) {
68
+ if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
69
+ BrowserThread::PostTask(
70
+ BrowserThread::UI, FROM_HERE,
71
+ base::Bind(
72
+ &BrowserPluginGeolocationPermissionContext::
73
+ CancelGeolocationPermissionRequest,
74
+ this,
75
+ render_process_id,
76
+ render_view_id,
77
+ bridge_id,
78
+ requesting_frame));
79
+ return;
80
+ }
81
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
82
+ RenderViewHost* rvh = RenderViewHost::FromID(render_process_id,
83
+ render_view_id);
84
+ if (rvh) {
85
+ DCHECK(rvh->GetProcess()->IsGuest());
86
+ WebContentsImpl* guest_web_contents =
87
+ static_cast<WebContentsImpl*>(rvh->GetDelegate()->GetAsWebContents());
88
+ BrowserPluginGuest* guest = guest_web_contents->GetBrowserPluginGuest();
89
+ if (guest)
90
+ guest->CancelGeolocationRequest(bridge_id);
91
+ }
92
+ }
93
+
94
+ } // namespace content
pool/shard007/C++/0095119_csg_dump.cc ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2009-2021 The VOTCA Development Team (http://www.votca.org)
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ */
17
+
18
+ // Standard includes
19
+ #include <cstdlib>
20
+
21
+ // Local VOTCA includes
22
+ #include "votca/csg/csgapplication.h"
23
+
24
+ using namespace std;
25
+ using namespace votca::csg;
26
+
27
+ class CsgDumpApp : public CsgApplication {
28
+ string ProgramName() override { return "csg_dump"; }
29
+ void HelpText(ostream &out) override {
30
+ out << "Print atoms that are read from topology file to help"
31
+ " debugging atom naming.";
32
+ }
33
+ void Initialize() override {
34
+ CsgApplication::Initialize();
35
+ AddProgramOptions("Specific options")(
36
+ "excl", " display exclusion list instead of molecule list");
37
+ }
38
+
39
+ bool EvaluateTopology(Topology *top, Topology *top_ref) override;
40
+
41
+ bool DoMapping() override { return true; }
42
+ bool DoMappingDefault(void) override { return false; }
43
+ };
44
+
45
+ int main(int argc, char **argv) {
46
+ CsgDumpApp app;
47
+
48
+ return app.Exec(argc, argv);
49
+ }
50
+
51
+ bool CsgDumpApp::EvaluateTopology(Topology *top, Topology *) {
52
+ if (!OptionsMap().count("excl")) {
53
+ cout << "Boundary Condition: ";
54
+ if (top->getBoxType() == BoundaryCondition::typeAuto) {
55
+ cout << "auto";
56
+ } else if (top->getBoxType() == BoundaryCondition::typeTriclinic) {
57
+ cout << "triclinic";
58
+ } else if (top->getBoxType() == BoundaryCondition::typeOrthorhombic) {
59
+ cout << "orthorhombic";
60
+ } else if (top->getBoxType() == BoundaryCondition::typeOpen) {
61
+ cout << "open";
62
+ }
63
+ cout << endl;
64
+ if (top->getBoxType() != BoundaryCondition::typeOpen) {
65
+ cout << " Box matix:";
66
+ Eigen::Matrix3d box = top->getBox();
67
+ for (votca::Index i = 0; i < 3; i++) {
68
+ for (votca::Index j = 0; j < 3; j++) {
69
+ cout << " " << box(i, j);
70
+ }
71
+ cout << endl << " ";
72
+ }
73
+ }
74
+
75
+ cout << "\nList of residues:\n";
76
+ for (votca::Index i = 0; i < top->ResidueCount(); i++) {
77
+ cout << i << " name: " << top->getResidue(i).getName()
78
+ << " id: " << top->getResidue(i).getId() << endl;
79
+ }
80
+
81
+ cout << "\nList of molecules:\n";
82
+ for (const auto &mol : top->Molecules()) {
83
+ cout << "molecule: " << mol.getId() + 1 << " " << mol.getName()
84
+ << " beads: " << mol.BeadCount() << endl;
85
+ for (votca::Index i = 0; i < mol.BeadCount(); ++i) {
86
+ votca::Index resnr = mol.getBead(i)->getResnr();
87
+ cout << mol.getBeadId(i) << " Name " << mol.getBeadName(i) << " Type "
88
+ << mol.getBead(i)->getType() << " Mass "
89
+ << mol.getBead(i)->getMass() << " Resnr " << resnr << " Resname "
90
+ << top->getResidue(resnr).getName() << " Charge "
91
+ << mol.getBead(i)->getQ() << endl;
92
+ }
93
+ }
94
+ } else {
95
+ cout << "\nList of exclusions:\n" << top->getExclusions();
96
+ }
97
+
98
+ return true;
99
+ }
pool/shard007/C++/0095120_pair.cpp ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file
3
+
4
+ This file is part of libzmq, the ZeroMQ core engine in C++.
5
+
6
+ libzmq is free software; you can redistribute it and/or modify it under
7
+ the terms of the GNU Lesser General Public License (LGPL) as published
8
+ by the Free Software Foundation; either version 3 of the License, or
9
+ (at your option) any later version.
10
+
11
+ As a special exception, the Contributors give you permission to link
12
+ this library with independent modules to produce an executable,
13
+ regardless of the license terms of these independent modules, and to
14
+ copy and distribute the resulting executable under terms of your choice,
15
+ provided that you also meet, for each linked independent module, the
16
+ terms and conditions of the license of that module. An independent
17
+ module is a module which is not derived from or based on this library.
18
+ If you modify this library, you must extend this exception to your
19
+ version of the library.
20
+
21
+ libzmq is distributed in the hope that it will be useful, but WITHOUT
22
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
24
+ License for more details.
25
+
26
+ You should have received a copy of the GNU Lesser General Public License
27
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
28
+ */
29
+
30
+ #include "precompiled.hpp"
31
+ #include "macros.hpp"
32
+ #include "pair.hpp"
33
+ #include "err.hpp"
34
+ #include "pipe.hpp"
35
+ #include "msg.hpp"
36
+
37
+ zmq::pair_t::pair_t (class ctx_t *parent_, uint32_t tid_, int sid_) :
38
+ socket_base_t (parent_, tid_, sid_),
39
+ pipe (NULL),
40
+ last_in (NULL)
41
+ {
42
+ options.type = ZMQ_PAIR;
43
+ }
44
+
45
+ zmq::pair_t::~pair_t ()
46
+ {
47
+ zmq_assert (!pipe);
48
+ }
49
+
50
+ void zmq::pair_t::xattach_pipe (pipe_t *pipe_, bool subscribe_to_all_)
51
+ {
52
+ LIBZMQ_UNUSED (subscribe_to_all_);
53
+
54
+ zmq_assert (pipe_ != NULL);
55
+
56
+ // ZMQ_PAIR socket can only be connected to a single peer.
57
+ // The socket rejects any further connection requests.
58
+ if (pipe == NULL)
59
+ pipe = pipe_;
60
+ else
61
+ pipe_->terminate (false);
62
+ }
63
+
64
+ void zmq::pair_t::xpipe_terminated (pipe_t *pipe_)
65
+ {
66
+ if (pipe_ == pipe) {
67
+ if (last_in == pipe) {
68
+ saved_credential.set_deep_copy (last_in->get_credential ());
69
+ last_in = NULL;
70
+ }
71
+ pipe = NULL;
72
+ }
73
+ }
74
+
75
+ void zmq::pair_t::xread_activated (pipe_t *)
76
+ {
77
+ // There's just one pipe. No lists of active and inactive pipes.
78
+ // There's nothing to do here.
79
+ }
80
+
81
+ void zmq::pair_t::xwrite_activated (pipe_t *)
82
+ {
83
+ // There's just one pipe. No lists of active and inactive pipes.
84
+ // There's nothing to do here.
85
+ }
86
+
87
+ int zmq::pair_t::xsend (msg_t *msg_)
88
+ {
89
+ if (!pipe || !pipe->write (msg_)) {
90
+ errno = EAGAIN;
91
+ return -1;
92
+ }
93
+
94
+ if (!(msg_->flags () & msg_t::more))
95
+ pipe->flush ();
96
+
97
+ // Detach the original message from the data buffer.
98
+ int rc = msg_->init ();
99
+ errno_assert (rc == 0);
100
+
101
+ return 0;
102
+ }
103
+
104
+ int zmq::pair_t::xrecv (msg_t *msg_)
105
+ {
106
+ // Deallocate old content of the message.
107
+ int rc = msg_->close ();
108
+ errno_assert (rc == 0);
109
+
110
+ if (!pipe || !pipe->read (msg_)) {
111
+ // Initialise the output parameter to be a 0-byte message.
112
+ rc = msg_->init ();
113
+ errno_assert (rc == 0);
114
+
115
+ errno = EAGAIN;
116
+ return -1;
117
+ }
118
+ last_in = pipe;
119
+ return 0;
120
+ }
121
+
122
+ bool zmq::pair_t::xhas_in ()
123
+ {
124
+ if (!pipe)
125
+ return false;
126
+
127
+ return pipe->check_read ();
128
+ }
129
+
130
+ bool zmq::pair_t::xhas_out ()
131
+ {
132
+ if (!pipe)
133
+ return false;
134
+
135
+ return pipe->check_write ();
136
+ }
137
+
138
+ const zmq::blob_t &zmq::pair_t::get_credential () const
139
+ {
140
+ return last_in ? last_in->get_credential () : saved_credential;
141
+ }
pool/shard007/C++/0095121_put.cc ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2
+ // This source code is licensed under both the GPLv2 (found in the
3
+ // COPYING file in the root directory) and Apache 2.0 License
4
+ // (found in the LICENSE.Apache file in the root directory).
5
+
6
+ #include <memory>
7
+ #include "rocksdb/slice.h"
8
+ #include "rocksdb/merge_operator.h"
9
+ #include "utilities/merge_operators.h"
10
+
11
+ namespace { // anonymous namespace
12
+
13
+ using ROCKSDB_NAMESPACE::Logger;
14
+ using ROCKSDB_NAMESPACE::MergeOperator;
15
+ using ROCKSDB_NAMESPACE::Slice;
16
+
17
+ // A merge operator that mimics Put semantics
18
+ // Since this merge-operator will not be used in production,
19
+ // it is implemented as a non-associative merge operator to illustrate the
20
+ // new interface and for testing purposes. (That is, we inherit from
21
+ // the MergeOperator class rather than the AssociativeMergeOperator
22
+ // which would be simpler in this case).
23
+ //
24
+ // From the client-perspective, semantics are the same.
25
+ class PutOperator : public MergeOperator {
26
+ public:
27
+ bool FullMerge(const Slice& /*key*/, const Slice* /*existing_value*/,
28
+ const std::deque<std::string>& operand_sequence,
29
+ std::string* new_value, Logger* /*logger*/) const override {
30
+ // Put basically only looks at the current/latest value
31
+ assert(!operand_sequence.empty());
32
+ assert(new_value != nullptr);
33
+ new_value->assign(operand_sequence.back());
34
+ return true;
35
+ }
36
+
37
+ bool PartialMerge(const Slice& /*key*/, const Slice& /*left_operand*/,
38
+ const Slice& right_operand, std::string* new_value,
39
+ Logger* /*logger*/) const override {
40
+ new_value->assign(right_operand.data(), right_operand.size());
41
+ return true;
42
+ }
43
+
44
+ using MergeOperator::PartialMergeMulti;
45
+ bool PartialMergeMulti(const Slice& /*key*/,
46
+ const std::deque<Slice>& operand_list,
47
+ std::string* new_value,
48
+ Logger* /*logger*/) const override {
49
+ new_value->assign(operand_list.back().data(), operand_list.back().size());
50
+ return true;
51
+ }
52
+
53
+ static const char* kClassName() { return "PutOperator"; }
54
+ static const char* kNickName() { return "put_v1"; }
55
+ const char* Name() const override { return kClassName(); }
56
+ const char* NickName() const override { return kNickName(); }
57
+ };
58
+
59
+ class PutOperatorV2 : public PutOperator {
60
+ bool FullMerge(const Slice& /*key*/, const Slice* /*existing_value*/,
61
+ const std::deque<std::string>& /*operand_sequence*/,
62
+ std::string* /*new_value*/,
63
+ Logger* /*logger*/) const override {
64
+ assert(false);
65
+ return false;
66
+ }
67
+
68
+ bool FullMergeV2(const MergeOperationInput& merge_in,
69
+ MergeOperationOutput* merge_out) const override {
70
+ // Put basically only looks at the current/latest value
71
+ assert(!merge_in.operand_list.empty());
72
+ merge_out->existing_operand = merge_in.operand_list.back();
73
+ return true;
74
+ }
75
+
76
+ static const char* kNickName() { return "put"; }
77
+ const char* NickName() const override { return kNickName(); }
78
+ };
79
+
80
+ } // end of anonymous namespace
81
+
82
+ namespace ROCKSDB_NAMESPACE {
83
+
84
+ std::shared_ptr<MergeOperator> MergeOperators::CreateDeprecatedPutOperator() {
85
+ return std::make_shared<PutOperator>();
86
+ }
87
+
88
+ std::shared_ptr<MergeOperator> MergeOperators::CreatePutOperator() {
89
+ return std::make_shared<PutOperatorV2>();
90
+ }
91
+ } // namespace ROCKSDB_NAMESPACE
pool/shard007/C++/0095125_pmt_tests.cpp ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright (c) 2012-2016 The Bitcoin Core developers
2
+ // Distributed under the MIT software license, see the accompanying
3
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
+
5
+ #include "consensus/merkle.h"
6
+ #include "merkleblock.h"
7
+ #include "serialize.h"
8
+ #include "streams.h"
9
+ #include "uint256.h"
10
+ #include "arith_uint256.h"
11
+ #include "version.h"
12
+ #include "test/test_bitcoin.h"
13
+
14
+ #include <vector>
15
+
16
+ #include <boost/test/unit_test.hpp>
17
+
18
+ class CPartialMerkleTreeTester : public CPartialMerkleTree
19
+ {
20
+ public:
21
+ // flip one bit in one of the hashes - this should break the authentication
22
+ void Damage() {
23
+ unsigned int n = InsecureRandRange(vHash.size());
24
+ int bit = InsecureRandBits(8);
25
+ *(vHash[n].begin() + (bit>>3)) ^= 1<<(bit&7);
26
+ }
27
+ };
28
+
29
+ BOOST_FIXTURE_TEST_SUITE(pmt_tests, BasicTestingSetup)
30
+
31
+ BOOST_AUTO_TEST_CASE(pmt_test1)
32
+ {
33
+ SeedInsecureRand(false);
34
+ static const unsigned int nTxCounts[] = {1, 4, 7, 17, 56, 100, 127, 256, 312, 513, 1000, 4095};
35
+
36
+ for (int i = 0; i < 12; i++) {
37
+ unsigned int nTx = nTxCounts[i];
38
+
39
+ // build a block with some dummy transactions
40
+ CBlock block;
41
+ for (unsigned int j=0; j<nTx; j++) {
42
+ CMutableTransaction tx;
43
+ tx.nLockTime = j; // actual transaction data doesn't matter; just make the nLockTime's unique
44
+ block.vtx.push_back(MakeTransactionRef(std::move(tx)));
45
+ }
46
+
47
+ // calculate actual merkle root and height
48
+ uint256 merkleRoot1 = BlockMerkleRoot(block);
49
+ std::vector<uint256> vTxid(nTx, uint256());
50
+ for (unsigned int j=0; j<nTx; j++)
51
+ vTxid[j] = block.vtx[j]->GetHash();
52
+ int nHeight = 1, nTx_ = nTx;
53
+ while (nTx_ > 1) {
54
+ nTx_ = (nTx_+1)/2;
55
+ nHeight++;
56
+ }
57
+
58
+ // check with random subsets with inclusion chances 1, 1/2, 1/4, ..., 1/128
59
+ for (int att = 1; att < 15; att++) {
60
+ // build random subset of txid's
61
+ std::vector<bool> vMatch(nTx, false);
62
+ std::vector<uint256> vMatchTxid1;
63
+ for (unsigned int j=0; j<nTx; j++) {
64
+ bool fInclude = InsecureRandBits(att / 2) == 0;
65
+ vMatch[j] = fInclude;
66
+ if (fInclude)
67
+ vMatchTxid1.push_back(vTxid[j]);
68
+ }
69
+
70
+ // build the partial merkle tree
71
+ CPartialMerkleTree pmt1(vTxid, vMatch);
72
+
73
+ // serialize
74
+ CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
75
+ ss << pmt1;
76
+
77
+ // verify CPartialMerkleTree's size guarantees
78
+ unsigned int n = std::min<unsigned int>(nTx, 1 + vMatchTxid1.size()*nHeight);
79
+ BOOST_CHECK(ss.size() <= 10 + (258*n+7)/8);
80
+
81
+ // deserialize into a tester copy
82
+ CPartialMerkleTreeTester pmt2;
83
+ ss >> pmt2;
84
+
85
+ // extract merkle root and matched txids from copy
86
+ std::vector<uint256> vMatchTxid2;
87
+ std::vector<unsigned int> vIndex;
88
+ uint256 merkleRoot2 = pmt2.ExtractMatches(vMatchTxid2, vIndex);
89
+
90
+ // check that it has the same merkle root as the original, and a valid one
91
+ BOOST_CHECK(merkleRoot1 == merkleRoot2);
92
+ BOOST_CHECK(!merkleRoot2.IsNull());
93
+
94
+ // check that it contains the matched transactions (in the same order!)
95
+ BOOST_CHECK(vMatchTxid1 == vMatchTxid2);
96
+
97
+ // check that random bit flips break the authentication
98
+ for (int j=0; j<4; j++) {
99
+ CPartialMerkleTreeTester pmt3(pmt2);
100
+ pmt3.Damage();
101
+ std::vector<uint256> vMatchTxid3;
102
+ uint256 merkleRoot3 = pmt3.ExtractMatches(vMatchTxid3, vIndex);
103
+ BOOST_CHECK(merkleRoot3 != merkleRoot1);
104
+ }
105
+ }
106
+ }
107
+ }
108
+
109
+ BOOST_AUTO_TEST_CASE(pmt_malleability)
110
+ {
111
+ std::vector<uint256> vTxid = {
112
+ ArithToUint256(1), ArithToUint256(2),
113
+ ArithToUint256(3), ArithToUint256(4),
114
+ ArithToUint256(5), ArithToUint256(6),
115
+ ArithToUint256(7), ArithToUint256(8),
116
+ ArithToUint256(9), ArithToUint256(10),
117
+ ArithToUint256(9), ArithToUint256(10),
118
+ };
119
+ std::vector<bool> vMatch = {false, false, false, false, false, false, false, false, false, true, true, false};
120
+
121
+ CPartialMerkleTree tree(vTxid, vMatch);
122
+ std::vector<unsigned int> vIndex;
123
+ BOOST_CHECK(tree.ExtractMatches(vTxid, vIndex).IsNull());
124
+ }
125
+
126
+ BOOST_AUTO_TEST_SUITE_END()
pool/shard007/C++/0095127_simpledeformation.cpp ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Aqsis
2
+ // Copyright (C) 2001, Paul C. Gregory and the other authors and contributors
3
+ // All rights reserved.
4
+ //
5
+ // Redistribution and use in source and binary forms, with or without
6
+ // modification, are permitted provided that the following conditions are met:
7
+ //
8
+ // * Redistributions of source code must retain the above copyright notice,
9
+ // this list of conditions and the following disclaimer.
10
+ // * Redistributions in binary form must reproduce the above copyright notice,
11
+ // this list of conditions and the following disclaimer in the documentation
12
+ // and/or other materials provided with the distribution.
13
+ // * Neither the name of the software's owners nor the names of its
14
+ // contributors may be used to endorse or promote products derived from this
15
+ // software without specific prior written permission.
16
+ //
17
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
+ // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
+ // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
+ // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21
+ // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
+ // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
+ // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
+ // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
+ // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
+ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
+ // POSSIBILITY OF SUCH DAMAGE.
28
+ //
29
+ // (This is the New BSD license)
30
+
31
+ #include "renderer.h"
32
+ #include "surfaces.h"
33
+
34
+ static GeometryPtr createPatch(const float P[12], const float Cs[3],
35
+ const Mat4& trans = Mat4())
36
+ {
37
+ PrimvarStorageBuilder builder;
38
+ builder.add(Primvar::P, P, 12);
39
+ builder.add(PrimvarSpec(PrimvarSpec::Constant, PrimvarSpec::Color, 1, ustring("Cs")),
40
+ Cs, 3);
41
+ IclassStorage storReq(1,4,4,4,4);
42
+ GeometryPtr patch(new Patch(builder.build(storReq)));
43
+ patch->transform(trans);
44
+ return patch;
45
+ }
46
+
47
+ void renderSimpleDeformationScene()
48
+ {
49
+ Options opts;
50
+ opts.xRes = 1024;
51
+ opts.yRes = 1024;
52
+ opts.gridSize = 8;
53
+ opts.clipNear = 0.1;
54
+ opts.superSamp = Imath::V2i(4,4);
55
+ opts.pixelFilter = makeSincFilter(Vec2(3.0,3.0));
56
+ opts.shutterMin = 0;
57
+ opts.shutterMax = 2;
58
+
59
+ Attributes attrs;
60
+ attrs.shadingRate = 1;
61
+ attrs.smoothShading = true;
62
+ attrs.surfaceShader = createShader("default");
63
+
64
+ Mat4 camToScreen = perspectiveProjection(90, opts.clipNear, opts.clipFar);
65
+
66
+ // Output variables.
67
+ VarList outVars;
68
+ outVars.push_back(Stdvar::Ci);
69
+
70
+ Renderer renderer(opts, camToScreen, outVars);
71
+
72
+ {
73
+ float Cs[3] = {1,1,1};
74
+ GeometryKeys keys;
75
+ float P1[12] = {-0.4,-0.4,1, -0.4,-0.3,1, -0.3,-0.4,1, -0.3,-0.3,1};
76
+ keys.push_back(GeometryKey(0, createPatch(P1,Cs)));
77
+ float P2[12] = {-0.1,-0.1,1, -0.1,0.1,1, 0.1,-0.1,1, 0.1,0.1,1};
78
+ keys.push_back(GeometryKey(2, createPatch(P2,Cs)));
79
+ renderer.add(keys, attrs);
80
+ }
81
+
82
+ {
83
+ float Cs[3] = {0.6,0.4,0.4};
84
+ GeometryKeys keys;
85
+ float P1[12] = {1,0,2, 0,1.1,2, 0,-1.1,2, -1,0,2};
86
+ keys.push_back(GeometryKey(0, createPatch(P1,Cs)));
87
+ float P2[12] = {1.5,0,2, 0,0.8,2, 0,-0.8,2, -1.5,0,2};
88
+ keys.push_back(GeometryKey(2, createPatch(P2,Cs)));
89
+ renderer.add(keys, attrs);
90
+ }
91
+
92
+ renderer.render();
93
+ }
94
+
pool/shard007/C++/0095128_DemoColorImageByScore.cpp ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*=========================================================================
2
+ *
3
+ * Copyright David Doria 2011 daviddoria@gmail.com
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0.txt
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *
17
+ *=========================================================================*/
18
+
19
+ // Submodules
20
+ #include <ITKHelpers/ITKHelpers.h>
21
+ #include <Mask/Mask.h>
22
+
23
+ // ITK
24
+ #include "itkImageFileReader.h"
25
+
26
+ // Boost
27
+ #include <boost/bind.hpp>
28
+
29
+ int main(int argc, char *argv[])
30
+ {
31
+ if(argc != 3)
32
+ {
33
+ std::cerr << "Required arguments: image mask" << std::endl;
34
+ return EXIT_FAILURE;
35
+ }
36
+ std::string imageFilename = argv[1];
37
+ std::string maskFilename = argv[2];
38
+ std::cout << "Reading image: " << imageFilename << std::endl;
39
+ std::cout << "Reading mask: " << maskFilename << std::endl;
40
+
41
+ typedef itk::VectorImage<float, 2> FloatVectorImageType;
42
+ typedef itk::ImageFileReader<FloatVectorImageType> ImageReaderType;
43
+ ImageReaderType::Pointer imageReader = ImageReaderType::New();
44
+ imageReader->SetFileName(imageFilename.c_str());
45
+ imageReader->Update();
46
+
47
+ typedef itk::ImageFileReader<Mask> MaskReaderType;
48
+ MaskReaderType::Pointer maskReader = MaskReaderType::New();
49
+ maskReader->SetFileName(maskFilename.c_str());
50
+ maskReader->Update();
51
+
52
+ std::shared_ptr<SelfPatchCompare> patchCompare(new SelfPatchCompare);
53
+ patchCompare->SetNumberOfComponentsPerPixel(imageReader->GetOutput()->GetNumberOfComponentsPerPixel());
54
+ //patchCompare->FunctionsToCompute.push_back(boost::bind(&SelfPatchCompare::SetPatchAverageAbsoluteSourceDifference,patchCompare,_1));
55
+ //patchCompare->FunctionsToCompute.push_back(boost::bind(&SelfPatchCompare::SetPatchColorDifference,patchCompare,_1));
56
+ patchCompare->FunctionsToCompute.push_back(boost::bind(&SelfPatchCompare::SetPatchDepthDifference,patchCompare.get(),_1));
57
+ //patchCompare->SetImage(imageReader->GetOutput());
58
+ //patchCompare->SetMask(maskReader->GetOutput());
59
+
60
+ PatchBasedInpainting inpainting;
61
+ inpainting.SetMask(maskReader->GetOutput());
62
+ inpainting.SetImage(imageReader->GetOutput());
63
+ //inpainting.PatchSortFunction = &SortByDepthDifference;
64
+ //inpainting.SetPatchCompare(patchCompare);
65
+ inpainting.Initialize();
66
+ inpainting.Iterate();
67
+
68
+ CandidatePairs candidatePairs = inpainting.GetPotentialCandidatePairs()[0];
69
+ //patchCompare->SetPairs(&candidatePairs);
70
+ //patchCompare->ComputeAllSourceDifferences();
71
+ WriteImageOfScores(candidatePairs, imageReader->GetOutput()->GetLargestPossibleRegion(), "ScoreImage_TargetPatch.mha");
72
+
73
+ return EXIT_SUCCESS;
74
+ }
pool/shard007/C++/0095129_led.cpp ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * led.cpp - Implementation of LED class which abstracts LED functionality with
3
+ * the naze32
4
+ *
5
+ * Copyright (c) 2016 James Jackson
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in
15
+ * all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ #include "led.h"
27
+ #include "board.h"
28
+
29
+ LED::LED(){}
30
+
31
+ LED::LED(GPIO_TypeDef* port, uint16_t pin) :
32
+ gpio_(port, pin, GPIO_Mode_Out_PP)
33
+ {
34
+ gpio_.write(HIGH);
35
+ }
36
+
37
+ void LED::toggle()
38
+ {
39
+ gpio_.toggle();
40
+ }
41
+
42
+ void LED::turn_on()
43
+ {
44
+ gpio_.write(LOW);
45
+ }
46
+
47
+ void LED::turn_off()
48
+ {
49
+ gpio_.write(HIGH);
50
+ }
51
+
52
+ void LED::blink(uint32_t ms_delay)
53
+ {
54
+ static uint32_t last_time = 0;
55
+ uint32_t now = millis();
56
+
57
+ if(now - last_time > ms_delay)
58
+ {
59
+ toggle();
60
+ last_time = now;
61
+ }
62
+ }
pool/shard007/C++/0095136_websocket_server.cpp ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include "websocket_server.h"
2
+
3
+ #include <QtCore/QDebug>
4
+ #include <QtCore/QFile>
5
+ #include <QtCore/QJsonDocument>
6
+ #include <QtCore/QJsonObject>
7
+ #include <QtCore/QMutexLocker>
8
+ #include <QtNetwork/QSslCertificate>
9
+ #include <QtNetwork/QSslKey>
10
+ #include <QtWebSockets/QWebSocket>
11
+ #include <QtWebSockets/QWebSocketServer>
12
+
13
+ namespace {
14
+ const QString kWebsocketCertPath = WEBSOCKET_CERT_PATH;
15
+
16
+ // Names used for a websocket JSON object.
17
+ const QString kMessageType = "type";
18
+ const QString kPayload = "data";
19
+
20
+ } // namespace
21
+
22
+ WebsocketServer::WebsocketServer(quint16 port)
23
+ : m_websocket_server(new QWebSocketServer("PACC server",
24
+ QWebSocketServer::SecureMode))
25
+ {
26
+ QSslConfiguration sslConfiguration;
27
+ QFile cert_file(kWebsocketCertPath + "/localhost.crt");
28
+ cert_file.open(QIODevice::ReadOnly);
29
+ QSslCertificate certificate(&cert_file, QSsl::Pem);
30
+ cert_file.close();
31
+
32
+ QFile key_file(kWebsocketCertPath + "/localhost.key");
33
+ key_file.open(QIODevice::ReadOnly);
34
+ QSslKey ssl_key(&key_file, QSsl::Rsa, QSsl::Pem);
35
+ key_file.close();
36
+
37
+ if (certificate.isNull() || ssl_key.isNull()) {
38
+ qCritical() << QString("The websocket certificate could not be loaded. "
39
+ "Please verify that localhost.crt and "
40
+ "localhost.key exist in %s and are readable by "
41
+ "the pacc module.")
42
+ .arg(kWebsocketCertPath);
43
+ exit(1);
44
+ }
45
+
46
+ sslConfiguration.setPeerVerifyMode(QSslSocket::VerifyNone);
47
+ sslConfiguration.setLocalCertificate(certificate);
48
+ sslConfiguration.setPrivateKey(ssl_key);
49
+ sslConfiguration.setProtocol(QSsl::TlsV1SslV3);
50
+ m_websocket_server->setSslConfiguration(sslConfiguration);
51
+
52
+ connect(m_websocket_server.data(), &QWebSocketServer::newConnection,
53
+ this, &WebsocketServer::onNewConnection);
54
+ connect(m_websocket_server.data(), &QWebSocketServer::sslErrors,
55
+ [](const QList<QSslError> &) {
56
+ qWarning() << "Ssl errors occurred";
57
+ });
58
+ connect(m_websocket_server.data(), &QWebSocketServer::acceptError,
59
+ [](QAbstractSocket::SocketError socketError) {
60
+ qWarning() << "SocketError: " << QString::number(socketError);
61
+ });
62
+ connect(m_websocket_server.data(), &QWebSocketServer::serverError,
63
+ [](QWebSocketProtocol::CloseCode closeCode) {
64
+ qWarning() << "ServerError: " << QString::number(closeCode);
65
+ });
66
+ connect(m_websocket_server.data(), &QWebSocketServer::peerVerifyError,
67
+ [](const QSslError &error) {
68
+ qWarning() << "PeerVerifyError: " << error.errorString();
69
+ });
70
+
71
+ Q_ASSERT(m_websocket_server->listen(QHostAddress::Any, port) &&
72
+ "Could not start the websocket server");
73
+ }
74
+
75
+ WebsocketServer::~WebsocketServer() {
76
+ }
77
+
78
+ void WebsocketServer::onNewConnection() {
79
+ QWebSocket *socket = m_websocket_server->nextPendingConnection();
80
+
81
+ QMutexLocker l(&m_socket_mutex);
82
+ connect(socket, &QWebSocket::textMessageReceived,
83
+ this, &WebsocketServer::processTextMessage);
84
+ connect(socket, &QWebSocket::disconnected,
85
+ this, &WebsocketServer::socketDisconnected);
86
+ void (QWebSocket::*error)(QAbstractSocket::SocketError) =
87
+ &QWebSocket::error;
88
+ connect(socket, error, [](QAbstractSocket::SocketError error) {
89
+ qWarning() << "onError" << QString::number(error);
90
+ });
91
+
92
+ if (!m_socket.isNull()) {
93
+ qWarning() << "There is already a client connected!";
94
+ }
95
+ m_socket.reset(socket);
96
+
97
+ // Sends all the pending messages.
98
+ while (!m_pending_messages.isEmpty()) {
99
+ const QString &pending_message = m_pending_messages.takeFirst();
100
+ m_socket->sendTextMessage(pending_message);
101
+ }
102
+
103
+ emit clientConnected();
104
+ }
105
+
106
+ void WebsocketServer::sendMessage(const QString &type,
107
+ const QJsonValue &payload) {
108
+ // Assembles the message.
109
+ QJsonObject json_message;
110
+ json_message[kMessageType] = type;
111
+ json_message[kPayload] = payload;
112
+
113
+ QJsonDocument document(json_message);
114
+ QString message = QString::fromUtf8(document.toJson());
115
+
116
+ // Sends the message if there is a socket connected or adds it to the
117
+ // pending queue.
118
+ QMutexLocker l(&m_socket_mutex);
119
+ if (m_socket) {
120
+ m_socket->sendTextMessage(message);
121
+ } else {
122
+ m_pending_messages.append(message);
123
+ }
124
+ }
125
+
126
+ void WebsocketServer::processTextMessage(QString message) {
127
+ QWebSocket *socket = qobject_cast<QWebSocket *>(sender());
128
+
129
+ // Checks if the socket matches.
130
+ if (socket != m_socket.data()) {
131
+ qWarning() << "Message from wrong socket. Ignoring.";
132
+ return;
133
+ }
134
+
135
+ // Parses the message.
136
+ QJsonParseError parse_error;
137
+ QJsonDocument document =
138
+ QJsonDocument::fromJson(message.toUtf8(), &parse_error);
139
+ if (parse_error.error != QJsonParseError::NoError) {
140
+ qWarning() << "Failed to parse the websocket message: "
141
+ << parse_error.errorString();
142
+ return;
143
+ }
144
+ if (!document.isObject()) {
145
+ qWarning() << "Invalid websocket message.";
146
+ return;
147
+ }
148
+
149
+ QJsonObject msg_object = document.object();
150
+ if (!msg_object.contains(kMessageType)) {
151
+ qWarning() << "Invalid websocket message.";
152
+ return;
153
+ }
154
+
155
+ // Reads the message.
156
+ const QString &type = msg_object[kMessageType].toString();
157
+ const QJsonValue &payload = msg_object[kPayload];
158
+
159
+ emit messageReceived(type, payload);
160
+ }
161
+
162
+ void WebsocketServer::socketDisconnected() {
163
+ QWebSocket *socket = qobject_cast<QWebSocket *>(sender());
164
+ QMutexLocker l(&m_socket_mutex);
165
+ if (socket == m_socket.data()) {
166
+ m_socket.take();
167
+ }
168
+ socket->deleteLater();
169
+
170
+ l.unlock();
171
+ emit clientDisconnected();
172
+ }
pool/shard007/C++/0095139_test_thread_exit.cpp ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // (C) Copyright 2009 Anthony Williams
2
+ //
3
+ // Distributed under the Boost Software License, Version 1.0. (See
4
+ // accompanying file LICENSE_1_0.txt or copy at
5
+ // http://www.boost.org/LICENSE_1_0.txt)
6
+
7
+ #include <boost/thread/thread_only.hpp>
8
+ #include <boost/thread/mutex.hpp>
9
+ #include <boost/thread/condition.hpp>
10
+ #include <boost/thread/future.hpp>
11
+ #include <utility>
12
+ #include <memory>
13
+ #include <string>
14
+
15
+ #define BOOST_TEST_MODULE Boost.Threads: thread exit test suite
16
+
17
+ #include <boost/test/unit_test.hpp>
18
+
19
+ boost::thread::id exit_func_thread_id;
20
+
21
+ void exit_func()
22
+ {
23
+ exit_func_thread_id=boost::this_thread::get_id();
24
+ }
25
+
26
+ void tf1()
27
+ {
28
+ boost::this_thread::at_thread_exit(exit_func);
29
+ BOOST_CHECK(exit_func_thread_id!=boost::this_thread::get_id());
30
+ }
31
+
32
+ BOOST_AUTO_TEST_CASE(test_thread_exit_func_runs_when_thread_exits)
33
+ {
34
+ exit_func_thread_id=boost::thread::id();
35
+ boost::thread t(&tf1);
36
+ boost::thread::id const t_id=t.get_id();
37
+ t.join();
38
+ BOOST_CHECK(exit_func_thread_id==t_id);
39
+ }
40
+
41
+ struct fo
42
+ {
43
+ void operator()()
44
+ {
45
+ exit_func_thread_id=boost::this_thread::get_id();
46
+ }
47
+ };
48
+
49
+ void tf2()
50
+ {
51
+ boost::this_thread::at_thread_exit(fo());
52
+ BOOST_CHECK(exit_func_thread_id!=boost::this_thread::get_id());
53
+ }
54
+
55
+
56
+ BOOST_AUTO_TEST_CASE(test_can_use_function_object_for_exit_func)
57
+ {
58
+ exit_func_thread_id=boost::thread::id();
59
+ boost::thread t(tf2);
60
+ boost::thread::id const t_id=t.get_id();
61
+ t.join();
62
+ BOOST_CHECK(exit_func_thread_id==t_id);
63
+ }
pool/shard007/C++/0095148_ice_transport_adapter_impl.cc ADDED
@@ -0,0 +1,220 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 "third_party/blink/renderer/modules/peerconnection/adapters/ice_transport_adapter_impl.h"
6
+
7
+ #include <utility>
8
+
9
+ #include "base/notreached.h"
10
+ #include "third_party/webrtc/api/ice_transport_factory.h"
11
+
12
+ namespace blink {
13
+
14
+ IceTransportAdapterImpl::IceTransportAdapterImpl(
15
+ Delegate* delegate,
16
+ std::unique_ptr<cricket::PortAllocator> port_allocator,
17
+ std::unique_ptr<webrtc::AsyncResolverFactory> async_resolver_factory)
18
+ : delegate_(delegate),
19
+ port_allocator_(std::move(port_allocator)),
20
+ async_resolver_factory_(std::move(async_resolver_factory)) {
21
+ // These settings are copied from PeerConnection:
22
+ // https://codesearch.chromium.org/chromium/src/third_party/webrtc/pc/peerconnection.cc?l=4708&rcl=820ebd0f661696043959b5105b2814e0edd8b694
23
+ port_allocator_->set_step_delay(cricket::kMinimumStepDelay);
24
+ port_allocator_->set_flags(port_allocator_->flags() |
25
+ cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET |
26
+ cricket::PORTALLOCATOR_ENABLE_IPV6 |
27
+ cricket::PORTALLOCATOR_ENABLE_IPV6_ON_WIFI);
28
+ port_allocator_->Initialize();
29
+
30
+ webrtc::IceTransportInit ice_transport_init;
31
+ ice_transport_init.set_port_allocator(port_allocator_.get());
32
+ ice_transport_init.set_async_resolver_factory(async_resolver_factory_.get());
33
+ ice_transport_channel_ =
34
+ webrtc::CreateIceTransport(std::move(ice_transport_init));
35
+ SetupIceTransportChannel();
36
+ // We need to set the ICE role even before Start is called since the Port
37
+ // assumes that the role has been set before receiving incoming connectivity
38
+ // checks. These checks can race with the information signaled for Start.
39
+ ice_transport_channel()->SetIceRole(cricket::ICEROLE_CONTROLLING);
40
+ // The ICE tiebreaker is used to determine which side is controlling/
41
+ // controlled when both sides start in the same role. The number is randomly
42
+ // generated so that each peer can calculate a.tiebreaker <= b.tiebreaker
43
+ // consistently.
44
+ ice_transport_channel()->SetIceTiebreaker(rtc::CreateRandomId64());
45
+ }
46
+
47
+ IceTransportAdapterImpl::IceTransportAdapterImpl(
48
+ Delegate* delegate,
49
+ rtc::scoped_refptr<webrtc::IceTransportInterface> ice_transport)
50
+ : delegate_(delegate), ice_transport_channel_(ice_transport) {
51
+ // The native webrtc peer connection might have been closed in the meantime,
52
+ // clearing the ice transport channel; don't do anything in that case. |this|
53
+ // will eventually be destroyed when the blink layer gets notified by the
54
+ // webrtc layer that the transport has been cleared.
55
+ if (ice_transport_channel())
56
+ SetupIceTransportChannel();
57
+ }
58
+
59
+ IceTransportAdapterImpl::~IceTransportAdapterImpl() = default;
60
+
61
+ static uint32_t GetCandidateFilterForPolicy(IceTransportPolicy policy) {
62
+ switch (policy) {
63
+ case IceTransportPolicy::kRelay:
64
+ return cricket::CF_RELAY;
65
+ case IceTransportPolicy::kAll:
66
+ return cricket::CF_ALL;
67
+ }
68
+ NOTREACHED();
69
+ return 0;
70
+ }
71
+
72
+ void IceTransportAdapterImpl::StartGathering(
73
+ const cricket::IceParameters& local_parameters,
74
+ const cricket::ServerAddresses& stun_servers,
75
+ const WebVector<cricket::RelayServerConfig>& turn_servers,
76
+ IceTransportPolicy policy) {
77
+ if (port_allocator_) {
78
+ port_allocator_->set_candidate_filter(GetCandidateFilterForPolicy(policy));
79
+ port_allocator_->SetConfiguration(
80
+ stun_servers,
81
+ const_cast<WebVector<cricket::RelayServerConfig>&>(turn_servers)
82
+ .ReleaseVector(),
83
+ port_allocator_->candidate_pool_size(),
84
+ port_allocator_->prune_turn_ports());
85
+ }
86
+ if (!ice_transport_channel()) {
87
+ LOG(ERROR) << "StartGathering called, but ICE transport released";
88
+ return;
89
+ }
90
+ ice_transport_channel()->SetIceParameters(local_parameters);
91
+ ice_transport_channel()->MaybeStartGathering();
92
+ DCHECK_EQ(ice_transport_channel()->gathering_state(),
93
+ cricket::kIceGatheringGathering);
94
+ }
95
+
96
+ void IceTransportAdapterImpl::Start(
97
+ const cricket::IceParameters& remote_parameters,
98
+ cricket::IceRole role,
99
+ const Vector<cricket::Candidate>& initial_remote_candidates) {
100
+ if (!ice_transport_channel()) {
101
+ LOG(ERROR) << "Start called, but ICE transport released";
102
+ return;
103
+ }
104
+ ice_transport_channel()->SetRemoteIceParameters(remote_parameters);
105
+ ice_transport_channel()->SetIceRole(role);
106
+ for (const auto& candidate : initial_remote_candidates) {
107
+ ice_transport_channel()->AddRemoteCandidate(candidate);
108
+ }
109
+ }
110
+
111
+ void IceTransportAdapterImpl::HandleRemoteRestart(
112
+ const cricket::IceParameters& new_remote_parameters) {
113
+ if (!ice_transport_channel()) {
114
+ LOG(ERROR) << "HandleRemoteRestart called, but ICE transport released";
115
+ return;
116
+ }
117
+ ice_transport_channel()->RemoveAllRemoteCandidates();
118
+ ice_transport_channel()->SetRemoteIceParameters(new_remote_parameters);
119
+ }
120
+
121
+ void IceTransportAdapterImpl::AddRemoteCandidate(
122
+ const cricket::Candidate& candidate) {
123
+ if (!ice_transport_channel()) {
124
+ LOG(ERROR) << "AddRemoteCandidate called, but ICE transport released";
125
+ return;
126
+ }
127
+ ice_transport_channel()->AddRemoteCandidate(candidate);
128
+ }
129
+
130
+ void IceTransportAdapterImpl::SetupIceTransportChannel() {
131
+ if (!ice_transport_channel()) {
132
+ LOG(ERROR) << "SetupIceTransportChannel called, but ICE transport released";
133
+ return;
134
+ }
135
+ ice_transport_channel()->SignalGatheringState.connect(
136
+ this, &IceTransportAdapterImpl::OnGatheringStateChanged);
137
+ ice_transport_channel()->SignalCandidateGathered.connect(
138
+ this, &IceTransportAdapterImpl::OnCandidateGathered);
139
+ ice_transport_channel()->SignalIceTransportStateChanged.connect(
140
+ this, &IceTransportAdapterImpl::OnStateChanged);
141
+ ice_transport_channel()->SignalNetworkRouteChanged.connect(
142
+ this, &IceTransportAdapterImpl::OnNetworkRouteChanged);
143
+ ice_transport_channel()->SignalRoleConflict.connect(
144
+ this, &IceTransportAdapterImpl::OnRoleConflict);
145
+ }
146
+
147
+ void IceTransportAdapterImpl::OnGatheringStateChanged(
148
+ cricket::IceTransportInternal* transport) {
149
+ DCHECK_EQ(transport, ice_transport_channel());
150
+ delegate_->OnGatheringStateChanged(
151
+ ice_transport_channel()->gathering_state());
152
+ }
153
+
154
+ void IceTransportAdapterImpl::OnCandidateGathered(
155
+ cricket::IceTransportInternal* transport,
156
+ const cricket::Candidate& candidate) {
157
+ DCHECK_EQ(transport, ice_transport_channel());
158
+ delegate_->OnCandidateGathered(candidate);
159
+ }
160
+
161
+ void IceTransportAdapterImpl::OnStateChanged(
162
+ cricket::IceTransportInternal* transport) {
163
+ DCHECK_EQ(transport, ice_transport_channel());
164
+ delegate_->OnStateChanged(ice_transport_channel()->GetIceTransportState());
165
+ }
166
+
167
+ void IceTransportAdapterImpl::OnNetworkRouteChanged(
168
+ absl::optional<rtc::NetworkRoute> new_network_route) {
169
+ if (!ice_transport_channel()) {
170
+ LOG(ERROR) << "OnNetworkRouteChanged called, but ICE transport released";
171
+ return;
172
+ }
173
+ const absl::optional<const cricket::CandidatePair> selected_pair =
174
+ ice_transport_channel()->GetSelectedCandidatePair();
175
+ if (!selected_pair) {
176
+ // The selected connection will only be null if the ICE connection has
177
+ // totally failed, at which point we'll get a StateChanged signal. The
178
+ // client will implicitly clear the selected candidate pair when it receives
179
+ // the failed state change, so we don't need to give an explicit callback
180
+ // here.
181
+ return;
182
+ }
183
+ delegate_->OnSelectedCandidatePairChanged(std::make_pair(
184
+ selected_pair->local_candidate(), selected_pair->remote_candidate()));
185
+ }
186
+
187
+ static const char* IceRoleToString(cricket::IceRole role) {
188
+ switch (role) {
189
+ case cricket::ICEROLE_CONTROLLING:
190
+ return "controlling";
191
+ case cricket::ICEROLE_CONTROLLED:
192
+ return "controlled";
193
+ default:
194
+ return "unknown";
195
+ }
196
+ }
197
+
198
+ static cricket::IceRole IceRoleReversed(cricket::IceRole role) {
199
+ switch (role) {
200
+ case cricket::ICEROLE_CONTROLLING:
201
+ return cricket::ICEROLE_CONTROLLED;
202
+ case cricket::ICEROLE_CONTROLLED:
203
+ return cricket::ICEROLE_CONTROLLING;
204
+ default:
205
+ return cricket::ICEROLE_UNKNOWN;
206
+ }
207
+ }
208
+
209
+ void IceTransportAdapterImpl::OnRoleConflict(
210
+ cricket::IceTransportInternal* transport) {
211
+ DCHECK_EQ(transport, ice_transport_channel());
212
+ // This logic is copied from JsepTransportController.
213
+ cricket::IceRole reversed_role =
214
+ IceRoleReversed(ice_transport_channel()->GetIceRole());
215
+ LOG(INFO) << "Got role conflict; switching to "
216
+ << IceRoleToString(reversed_role) << " role.";
217
+ ice_transport_channel()->SetIceRole(reversed_role);
218
+ }
219
+
220
+ } // namespace blink
pool/shard007/C++/0095151_ipc.cc ADDED
@@ -0,0 +1,212 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * \brief Implementation of the Genode IPC-framework
3
+ * \author Martin Stein
4
+ * \date 2012-02-12
5
+ */
6
+
7
+ /*
8
+ * Copyright (C) 2012-2013 Genode Labs GmbH
9
+ *
10
+ * This file is part of the Genode OS framework, which is distributed
11
+ * under the terms of the GNU General Public License version 2.
12
+ */
13
+
14
+ /* Genode includes */
15
+ #include <base/env.h>
16
+ #include <base/ipc.h>
17
+ #include <base/allocator.h>
18
+ #include <base/thread.h>
19
+ #include <base/native_env.h>
20
+ #include <util/construct_at.h>
21
+ #include <util/retry.h>
22
+
23
+ /* base-hw includes */
24
+ #include <kernel/interface.h>
25
+ #include <kernel/log.h>
26
+
27
+ namespace Hw { extern Genode::Untyped_capability _main_thread_cap; }
28
+
29
+ using namespace Genode;
30
+
31
+ enum
32
+ {
33
+ /* size of the callee-local name of a targeted RPC object */
34
+ RPC_OBJECT_ID_SIZE = sizeof(Native_thread_id),
35
+
36
+ /*
37
+ * The RPC framework marshalls a return value into reply messages to
38
+ * deliver exceptions, wich occured during the RPC call to the caller.
39
+ * This defines the size of this value.
40
+ */
41
+ RPC_RETURN_VALUE_SIZE = sizeof(umword_t),
42
+ };
43
+
44
+
45
+ /*****************************
46
+ ** IPC marshalling support **
47
+ *****************************/
48
+
49
+ void Ipc_ostream::_marshal_capability(Native_capability const &cap) {
50
+ _snd_msg->cap_add(cap); }
51
+
52
+
53
+ void Ipc_istream::_unmarshal_capability(Native_capability &cap) {
54
+ cap = _rcv_msg->cap_get(); }
55
+
56
+
57
+ /*****************
58
+ ** Ipc_ostream **
59
+ *****************/
60
+
61
+ Ipc_ostream::Ipc_ostream(Native_capability dst, Msgbuf_base *snd_msg)
62
+ :
63
+ Ipc_marshaller(&snd_msg->buf[0], snd_msg->size()),
64
+ _snd_msg(snd_msg), _dst(dst)
65
+ {
66
+ _write_offset = align_natural<unsigned>(RPC_OBJECT_ID_SIZE);
67
+ _snd_msg->reset();
68
+ }
69
+
70
+
71
+ /*****************
72
+ ** Ipc_istream **
73
+ *****************/
74
+
75
+ void Ipc_istream::_wait()
76
+ {
77
+ /* FIXME: this shall be not supported */
78
+ Kernel::pause_current_thread();
79
+ }
80
+
81
+
82
+ Ipc_istream::Ipc_istream(Msgbuf_base *rcv_msg)
83
+ :
84
+ Ipc_unmarshaller(&rcv_msg->buf[0], rcv_msg->size()),
85
+ Native_capability(Thread_base::myself() ? Thread_base::myself()->tid().cap
86
+ : Hw::_main_thread_cap),
87
+ _rcv_msg(rcv_msg), _rcv_cs(-1)
88
+ { _read_offset = align_natural<unsigned>(RPC_OBJECT_ID_SIZE); }
89
+
90
+
91
+ Ipc_istream::~Ipc_istream() { }
92
+
93
+
94
+ /****************
95
+ ** Ipc_client **
96
+ ****************/
97
+
98
+ void Ipc_client::_call()
99
+ {
100
+ retry<Genode::Allocator::Out_of_memory>(
101
+ [&] () {
102
+
103
+ /* send request and receive corresponding reply */
104
+ Thread_base::myself()->utcb()->copy_from(*_snd_msg, _write_offset);
105
+
106
+ switch (Kernel::send_request_msg(Ipc_ostream::dst().dst(),
107
+ _rcv_msg->cap_rcv_window())) {
108
+ case -1: throw Blocking_canceled();
109
+ case -2: throw Allocator::Out_of_memory();
110
+ default:
111
+ _rcv_msg->reset();
112
+ _snd_msg->reset();
113
+ Thread_base::myself()->utcb()->copy_to(*_rcv_msg);
114
+
115
+ /* reset unmarshaller */
116
+ _write_offset = _read_offset =
117
+ align_natural<unsigned>(RPC_OBJECT_ID_SIZE);
118
+ }
119
+
120
+ },
121
+ [&] () { upgrade_pd_session_quota(3*4096); });
122
+ }
123
+
124
+
125
+ Ipc_client::Ipc_client(Native_capability const &srv, Msgbuf_base *snd_msg,
126
+ Msgbuf_base *rcv_msg, unsigned short rcv_caps)
127
+ : Ipc_istream(rcv_msg), Ipc_ostream(srv, snd_msg), _result(0) {
128
+ rcv_msg->cap_rcv_window(rcv_caps); }
129
+
130
+
131
+ /****************
132
+ ** Ipc_server **
133
+ ****************/
134
+
135
+ Ipc_server::Ipc_server(Msgbuf_base *snd_msg,
136
+ Msgbuf_base *rcv_msg) :
137
+ Ipc_istream(rcv_msg),
138
+ Ipc_ostream(Native_capability(), snd_msg),
139
+ _reply_needed(false) { }
140
+
141
+
142
+ void Ipc_server::_prepare_next_reply_wait()
143
+ {
144
+ /* now we have a request to reply */
145
+ _reply_needed = true;
146
+
147
+ /* leave space for RPC method return value */
148
+ _write_offset = align_natural<unsigned>(RPC_OBJECT_ID_SIZE +
149
+ RPC_RETURN_VALUE_SIZE);
150
+
151
+ /* reset unmarshaller */
152
+ _read_offset = align_natural<unsigned>(RPC_OBJECT_ID_SIZE);
153
+ }
154
+
155
+
156
+ void Ipc_server::_wait()
157
+ {
158
+ retry<Genode::Allocator::Out_of_memory>(
159
+ [&] () {
160
+
161
+ /* receive request */
162
+ switch (Kernel::await_request_msg(Msgbuf_base::MAX_CAP_ARGS)) {
163
+ case -1: throw Blocking_canceled();
164
+ case -2: throw Allocator::Out_of_memory();
165
+ default:
166
+ _rcv_msg->reset();
167
+ Thread_base::myself()->utcb()->copy_to(*_rcv_msg);
168
+
169
+ /* update server state */
170
+ _prepare_next_reply_wait();
171
+ }
172
+
173
+ },
174
+ [&] () { upgrade_pd_session_quota(3*4096); });
175
+ }
176
+
177
+
178
+ void Ipc_server::_reply()
179
+ {
180
+ Thread_base::myself()->utcb()->copy_from(*_snd_msg, _write_offset);
181
+ _snd_msg->reset();
182
+ Kernel::send_reply_msg(0, false);
183
+ }
184
+
185
+
186
+ void Ipc_server::_reply_wait()
187
+ {
188
+ /* if there is no reply, wait for request */
189
+ if (!_reply_needed) {
190
+ _wait();
191
+ return;
192
+ }
193
+
194
+ retry<Genode::Allocator::Out_of_memory>(
195
+ [&] () {
196
+ /* send reply and receive next request */
197
+ Thread_base::myself()->utcb()->copy_from(*_snd_msg, _write_offset);
198
+ switch (Kernel::send_reply_msg(Msgbuf_base::MAX_CAP_ARGS, true)) {
199
+ case -1: throw Blocking_canceled();
200
+ case -2: throw Allocator::Out_of_memory();
201
+ default:
202
+ _rcv_msg->reset();
203
+ _snd_msg->reset();
204
+ Thread_base::myself()->utcb()->copy_to(*_rcv_msg);
205
+
206
+ /* update server state */
207
+ _prepare_next_reply_wait();
208
+ }
209
+
210
+ },
211
+ [&] () { upgrade_pd_session_quota(3*4096); });
212
+ }
pool/shard007/C++/0095153_sortstrategy.cpp ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * (c) 2015 Raghavendra Nayak, All Rights Reserved.
3
+ * www.openguru.com/
4
+ */
5
+
6
+ #include <iostream>
7
+ #include <string>
8
+
9
+ // This abstract class provides the SortingAlgorithm interface
10
+ class SortingAlgorithms
11
+ {
12
+ public:
13
+ SortingAlgorithms() {}
14
+ virtual ~SortingAlgorithms() {}
15
+
16
+ virtual void sort(const std::string& arrayName) = 0;
17
+ };
18
+
19
+ // Implements the SortingAlgorithm interface via QuickSort
20
+ class QuickSort : public SortingAlgorithms
21
+ {
22
+ public:
23
+ virtual void sort(const std::string& arrayName) {
24
+ std::cout << "Sorting " << arrayName << " using QuickSort." << std::endl;
25
+ }
26
+ };
27
+
28
+ // Implements the SortingAlgorithm interface via MergeSort
29
+ class MergeSort : public SortingAlgorithms
30
+ {
31
+ public:
32
+ virtual void sort(const std::string& arrayName) {
33
+ std::cout << "Sorting " << arrayName << " using MergeSort." << std::endl;
34
+ }
35
+ };
36
+
37
+ // Implements the SortingAlgorithm interface via BubbleSort
38
+ class BubbleSort : public SortingAlgorithms
39
+ {
40
+ public:
41
+ virtual void sort(const std::string& arrayName) {
42
+ std::cout << "Sorting " << arrayName << " using BubbleSort." << std::endl;
43
+ }
44
+ };
45
+
46
+ class Array
47
+ {
48
+ SortingAlgorithms* sortStrategy;
49
+ std::string arrayName;
50
+ public:
51
+ enum SortStrategy
52
+ {
53
+ QUICK, MERGE, BUBBLE
54
+ };
55
+ Array(const std::string& arrayName)
56
+ : sortStrategy(nullptr), arrayName(arrayName) {
57
+ }
58
+ void setStrategy(const int type) {
59
+ switch (type) {
60
+ case QUICK:
61
+ sortStrategy = new QuickSort();
62
+ break;
63
+ case MERGE:
64
+ sortStrategy = new MergeSort();
65
+ break;
66
+ case BUBBLE:
67
+ sortStrategy = new BubbleSort();
68
+ default:
69
+ break;
70
+ }
71
+ }
72
+ void applyStrategy() {
73
+ if (sortStrategy != nullptr) {
74
+ sortStrategy->sort(arrayName);
75
+ }
76
+ }
77
+ };
78
+
79
+ int main(int argc, char **argv)
80
+ {
81
+ Array intArray("integer array");
82
+ int sortStrategy;
83
+ std::cout << "Enter the strategy for sorting: Quick(0) Merge(1) Bubble(2) : ";
84
+ std::cin >> sortStrategy;
85
+
86
+ intArray.setStrategy(sortStrategy);
87
+ intArray.applyStrategy();
88
+
89
+ return 0;
90
+ }
pool/shard007/C++/0095157_clippingPlane.cpp ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /****************************************************************************
2
+
3
+ Copyright (C) 2002-2014 Gilles Debunne. All rights reserved.
4
+
5
+ This file is part of the QGLViewer library version 2.6.1.
6
+
7
+ http://www.libqglviewer.com - contact@libqglviewer.com
8
+
9
+ This file may be used under the terms of the GNU General Public License
10
+ versions 2.0 or 3.0 as published by the Free Software Foundation and
11
+ appearing in the LICENSE file included in the packaging of this file.
12
+ In addition, as a special exception, Gilles Debunne gives you certain
13
+ additional rights, described in the file GPL_EXCEPTION in this package.
14
+
15
+ libQGLViewer uses dual licensing. Commercial/proprietary software must
16
+ purchase a libQGLViewer Commercial License.
17
+
18
+ This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
19
+ WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20
+
21
+ *****************************************************************************/
22
+
23
+ #include "clippingPlane.h"
24
+ #include "QGLViewer/manipulatedFrame.h"
25
+
26
+ using namespace std;
27
+ using namespace qglviewer;
28
+
29
+ // Draws a spiral
30
+ void Viewer::draw()
31
+ {
32
+ const float nbSteps = 200.0;
33
+
34
+ glBegin(GL_QUAD_STRIP);
35
+ for (int i=0; i<nbSteps; ++i)
36
+ {
37
+ const float ratio = i/nbSteps;
38
+ const float angle = 21.0*ratio;
39
+ const float c = cos(angle);
40
+ const float s = sin(angle);
41
+ const float r1 = 1.0 - 0.8f*ratio;
42
+ const float r2 = 0.8f - 0.8f*ratio;
43
+ const float alt = ratio - 0.5f;
44
+ const float nor = 0.5f;
45
+ const float up = sqrt(1.0-nor*nor);
46
+ glColor3f(1.0-ratio, 0.2f , ratio);
47
+ glNormal3f(nor*c, up, nor*s);
48
+ glVertex3f(r1*c, alt, r1*s);
49
+ glVertex3f(r2*c, alt+0.05f, r2*s);
50
+ }
51
+ glEnd();
52
+
53
+
54
+ glPushMatrix();
55
+ glMultMatrixd(manipulatedFrame()->matrix());
56
+ // Since the Clipping Plane equation is multiplied by the current modelView, we can define a
57
+ // constant equation (plane normal along Z and passing by the origin) since we are here in the
58
+ // manipulatedFrame coordinates system (we glMultMatrixd() with the manipulatedFrame matrix()).
59
+ static const GLdouble equation[] = { 0.0, 0.0, 1.0, 0.0 };
60
+ glClipPlane(GL_CLIP_PLANE0, equation);
61
+
62
+ // Draw a plane representation: Its normal...
63
+ glColor3f(0.8f, 0.8f, 0.8f);
64
+ drawArrow(0.4f, 0.015f);
65
+ // ...and a quad (with a slightly shifted z so that it is not clipped).
66
+ glBegin(GL_QUADS);
67
+ glVertex3f(-1.0, -1.0, 0.001f);
68
+ glVertex3f(-1.0, 1.0, 0.001f);
69
+ glVertex3f( 1.0, 1.0, 0.001f);
70
+ glVertex3f( 1.0, -1.0, 0.001f);
71
+ glEnd();
72
+ glPopMatrix();
73
+ }
74
+
75
+ void Viewer::init()
76
+ {
77
+ // Restore previous viewer state.
78
+ restoreStateFromFile();
79
+
80
+ // Opens help window
81
+ help();
82
+
83
+ // The ManipulatedFrame will be used to position the clipping plane
84
+ setManipulatedFrame(new ManipulatedFrame());
85
+
86
+ // Enable plane clipping
87
+ glEnable(GL_CLIP_PLANE0);
88
+ }
89
+
90
+ QString Viewer::helpString() const
91
+ {
92
+ QString text("<h2>C l i p p i n g P l a n e</h2>");
93
+ text += "The standard OpenGL <i>GL_CLIP_PLANE</i> feature is used to add an additionnal clipping ";
94
+ text += "plane in the scene, which position and orientation are set by a <b>ManipulatedFrame</b>.<br><br>";
95
+ text += "Hold the <b>Control</b> key pressed down while using the mouse to modify the plane orientation (left button) ";
96
+ text += "and position (right button) and to interactively see the clipped result.<br><br>";
97
+ text += "Since the plane equation is defined with respect to the current modelView matrix, a constant equation (normal";
98
+ text += "along the Z axis) can be used since we transformed the coordinates system using the <b>matrix()</b> method.";
99
+
100
+ return text;
101
+ }
pool/shard007/C++/0095169_bitcoin.cpp ADDED
@@ -0,0 +1,270 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * W.J. van der Laan 2011-2012
3
+ */
4
+ #include "bitcoingui.h"
5
+ #include "clientmodel.h"
6
+ #include "walletmodel.h"
7
+ #include "optionsmodel.h"
8
+ #include "guiutil.h"
9
+ #include "guiconstants.h"
10
+
11
+ #include "init.h"
12
+ #include "ui_interface.h"
13
+ #include "qtipcserver.h"
14
+
15
+ #include <QApplication>
16
+ #include <QMessageBox>
17
+ #include <QTextCodec>
18
+ #include <QLocale>
19
+ #include <QTranslator>
20
+ #include <QSplashScreen>
21
+ #include <QLibraryInfo>
22
+
23
+ #if defined(BITCOIN_NEED_QT_PLUGINS) && !defined(_BITCOIN_QT_PLUGINS_INCLUDED)
24
+ #define _BITCOIN_QT_PLUGINS_INCLUDED
25
+ #define __INSURE__
26
+ #include <QtPlugin>
27
+ Q_IMPORT_PLUGIN(qcncodecs)
28
+ Q_IMPORT_PLUGIN(qjpcodecs)
29
+ Q_IMPORT_PLUGIN(qtwcodecs)
30
+ Q_IMPORT_PLUGIN(qkrcodecs)
31
+ Q_IMPORT_PLUGIN(qtaccessiblewidgets)
32
+ #endif
33
+
34
+ // Need a global reference for the notifications to find the GUI
35
+ static BitcoinGUI *guiref;
36
+ static QSplashScreen *splashref;
37
+
38
+ static void ThreadSafeMessageBox(const std::string& message, const std::string& caption, int style)
39
+ {
40
+ // Message from network thread
41
+ if(guiref)
42
+ {
43
+ bool modal = (style & CClientUIInterface::MODAL);
44
+ // in case of modal message, use blocking connection to wait for user to click OK
45
+ QMetaObject::invokeMethod(guiref, "error",
46
+ modal ? GUIUtil::blockingGUIThreadConnection() : Qt::QueuedConnection,
47
+ Q_ARG(QString, QString::fromStdString(caption)),
48
+ Q_ARG(QString, QString::fromStdString(message)),
49
+ Q_ARG(bool, modal));
50
+ }
51
+ else
52
+ {
53
+ printf("%s: %s\n", caption.c_str(), message.c_str());
54
+ fprintf(stderr, "%s: %s\n", caption.c_str(), message.c_str());
55
+ }
56
+ }
57
+
58
+ static bool ThreadSafeAskFee(int64 nFeeRequired, const std::string& strCaption)
59
+ {
60
+ if(!guiref)
61
+ return false;
62
+ if(nFeeRequired < MIN_TX_FEE || nFeeRequired <= nTransactionFee || fDaemon)
63
+ return true;
64
+ bool payFee = false;
65
+
66
+ QMetaObject::invokeMethod(guiref, "askFee", GUIUtil::blockingGUIThreadConnection(),
67
+ Q_ARG(qint64, nFeeRequired),
68
+ Q_ARG(bool*, &payFee));
69
+
70
+ return payFee;
71
+ }
72
+
73
+ static void ThreadSafeHandleURI(const std::string& strURI)
74
+ {
75
+ if(!guiref)
76
+ return;
77
+
78
+ QMetaObject::invokeMethod(guiref, "handleURI", GUIUtil::blockingGUIThreadConnection(),
79
+ Q_ARG(QString, QString::fromStdString(strURI)));
80
+ }
81
+
82
+ static void InitMessage(const std::string &message)
83
+ {
84
+ if(splashref)
85
+ {
86
+ splashref->showMessage(QString::fromStdString(message), Qt::AlignBottom|Qt::AlignHCenter, QColor(255,255,200));
87
+ QApplication::instance()->processEvents();
88
+ }
89
+ }
90
+
91
+ static void QueueShutdown()
92
+ {
93
+ QMetaObject::invokeMethod(QCoreApplication::instance(), "quit", Qt::QueuedConnection);
94
+ }
95
+
96
+ /*
97
+ Translate string to current locale using Qt.
98
+ */
99
+ static std::string Translate(const char* psz)
100
+ {
101
+ return QCoreApplication::translate("bitcoin-core", psz).toStdString();
102
+ }
103
+
104
+ /* Handle runaway exceptions. Shows a message box with the problem and quits the program.
105
+ */
106
+ static void handleRunawayException(std::exception *e)
107
+ {
108
+ PrintExceptionContinue(e, "Runaway exception");
109
+ QMessageBox::critical(0, "Runaway exception", BitcoinGUI::tr("A fatal error occurred. EBT can no longer continue safely and will quit.") + QString("\n\n") + QString::fromStdString(strMiscWarning));
110
+ exit(1);
111
+ }
112
+
113
+ #ifndef BITCOIN_QT_TEST
114
+ int main(int argc, char *argv[])
115
+ {
116
+ // Do this early as we don't want to bother initializing if we are just calling IPC
117
+ ipcScanRelay(argc, argv);
118
+
119
+ // Internal string conversion is all UTF-8
120
+ QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
121
+ QTextCodec::setCodecForCStrings(QTextCodec::codecForTr());
122
+
123
+ Q_INIT_RESOURCE(bitcoin);
124
+ QApplication app(argc, argv);
125
+
126
+ // Install global event filter that makes sure that long tooltips can be word-wrapped
127
+ app.installEventFilter(new GUIUtil::ToolTipToRichTextFilter(TOOLTIP_WRAP_THRESHOLD, &app));
128
+
129
+ // Command-line options take precedence:
130
+ ParseParameters(argc, argv);
131
+
132
+ // ... then bitcoin.conf:
133
+ if (!boost::filesystem::is_directory(GetDataDir(false)))
134
+ {
135
+ // This message can not be translated, as translation is not initialized yet
136
+ // (which not yet possible because lang=XX can be overridden in bitcoin.conf in the data directory)
137
+ QMessageBox::critical(0, "EBT",
138
+ QString("Error: Specified data directory \"%1\" does not exist.").arg(QString::fromStdString(mapArgs["-datadir"])));
139
+ return 1;
140
+ }
141
+ ReadConfigFile(mapArgs, mapMultiArgs);
142
+
143
+ // Application identification (must be set before OptionsModel is initialized,
144
+ // as it is used to locate QSettings)
145
+ app.setOrganizationName("EBT");
146
+ app.setOrganizationDomain("EBT.su");
147
+ if(GetBoolArg("-testnet")) // Separate UI settings for testnet
148
+ app.setApplicationName("EBT-Qt-testnet");
149
+ else
150
+ app.setApplicationName("EBT-Qt");
151
+
152
+ // ... then GUI settings:
153
+ OptionsModel optionsModel;
154
+
155
+ // Get desired locale (e.g. "de_DE") from command line or use system locale
156
+ QString lang_territory = QString::fromStdString(GetArg("-lang", QLocale::system().name().toStdString()));
157
+ QString lang = lang_territory;
158
+ // Convert to "de" only by truncating "_DE"
159
+ lang.truncate(lang_territory.lastIndexOf('_'));
160
+
161
+ QTranslator qtTranslatorBase, qtTranslator, translatorBase, translator;
162
+ // Load language files for configured locale:
163
+ // - First load the translator for the base language, without territory
164
+ // - Then load the more specific locale translator
165
+
166
+ // Load e.g. qt_de.qm
167
+ if (qtTranslatorBase.load("qt_" + lang, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
168
+ app.installTranslator(&qtTranslatorBase);
169
+
170
+ // Load e.g. qt_de_DE.qm
171
+ if (qtTranslator.load("qt_" + lang_territory, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
172
+ app.installTranslator(&qtTranslator);
173
+
174
+ // Load e.g. bitcoin_de.qm (shortcut "de" needs to be defined in bitcoin.qrc)
175
+ if (translatorBase.load(lang, ":/translations/"))
176
+ app.installTranslator(&translatorBase);
177
+
178
+ // Load e.g. bitcoin_de_DE.qm (shortcut "de_DE" needs to be defined in bitcoin.qrc)
179
+ if (translator.load(lang_territory, ":/translations/"))
180
+ app.installTranslator(&translator);
181
+
182
+ // Subscribe to global signals from core
183
+ uiInterface.ThreadSafeMessageBox.connect(ThreadSafeMessageBox);
184
+ uiInterface.ThreadSafeAskFee.connect(ThreadSafeAskFee);
185
+ uiInterface.ThreadSafeHandleURI.connect(ThreadSafeHandleURI);
186
+ uiInterface.InitMessage.connect(InitMessage);
187
+ uiInterface.QueueShutdown.connect(QueueShutdown);
188
+ uiInterface.Translate.connect(Translate);
189
+
190
+ // Show help message immediately after parsing command-line options (for "-lang") and setting locale,
191
+ // but before showing splash screen.
192
+ if (mapArgs.count("-?") || mapArgs.count("--help"))
193
+ {
194
+ GUIUtil::HelpMessageBox help;
195
+ help.showOrPrint();
196
+ return 1;
197
+ }
198
+
199
+ QSplashScreen splash(QPixmap(":/images/splash"), 0);
200
+ if (GetBoolArg("-splash", true) && !GetBoolArg("-min"))
201
+ {
202
+ splash.show();
203
+ splash.setAutoFillBackground(true);
204
+ splashref = &splash;
205
+ }
206
+
207
+ app.processEvents();
208
+
209
+ app.setQuitOnLastWindowClosed(false);
210
+
211
+ try
212
+ {
213
+ // Regenerate startup link, to fix links to old versions
214
+ if (GUIUtil::GetStartOnSystemStartup())
215
+ GUIUtil::SetStartOnSystemStartup(true);
216
+
217
+ BitcoinGUI window;
218
+ guiref = &window;
219
+ if(AppInit2())
220
+ {
221
+ {
222
+ // Put this in a block, so that the Model objects are cleaned up before
223
+ // calling Shutdown().
224
+
225
+ optionsModel.Upgrade(); // Must be done after AppInit2
226
+
227
+ if (splashref)
228
+ splash.finish(&window);
229
+
230
+ ClientModel clientModel(&optionsModel);
231
+ WalletModel walletModel(pwalletMain, &optionsModel);
232
+
233
+ window.setClientModel(&clientModel);
234
+ window.setWalletModel(&walletModel);
235
+
236
+ // If -min option passed, start window minimized.
237
+ if(GetBoolArg("-min"))
238
+ {
239
+ window.showMinimized();
240
+ }
241
+ else
242
+ {
243
+ window.show();
244
+ }
245
+
246
+ // Place this here as guiref has to be defined if we don't want to lose URIs
247
+ ipcInit(argc, argv);
248
+
249
+ app.exec();
250
+
251
+ window.hide();
252
+ window.setClientModel(0);
253
+ window.setWalletModel(0);
254
+ guiref = 0;
255
+ }
256
+ // Shutdown the core and its threads, but don't exit Bitcoin-Qt here
257
+ Shutdown(NULL);
258
+ }
259
+ else
260
+ {
261
+ return 1;
262
+ }
263
+ } catch (std::exception& e) {
264
+ handleRunawayException(&e);
265
+ } catch (...) {
266
+ handleRunawayException(NULL);
267
+ }
268
+ return 0;
269
+ }
270
+ #endif // BITCOIN_QT_TEST
pool/shard007/C++/0095170_rotatecamera.cpp ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ #include "global.h"
3
+ #include "rotatecamera.h"
4
+
5
+
6
+ using namespace cv;
7
+
8
+
9
+ cRotateCamera::cRotateCamera()
10
+ {
11
+ SimpleBlobDetector::Params params;
12
+
13
+ // Change thresholds
14
+ params.minThreshold = 1;
15
+ params.maxThreshold = 20;
16
+
17
+ // Filter by Area.
18
+ params.filterByArea = true;
19
+ params.minArea = g_config.m_detectPointMinArea;
20
+ params.maxArea = g_config.m_detectPointMaxArea;
21
+
22
+ // Filter by Circularity
23
+ params.filterByCircularity = true;
24
+ params.minCircularity = 0.1f;
25
+
26
+ // Filter by Convexity
27
+ params.filterByConvexity = true;
28
+ params.minConvexity = 0.87f;
29
+
30
+ // Filter by Inertia
31
+ params.filterByInertia = true;
32
+ params.minInertiaRatio = 0.01f;
33
+
34
+
35
+ m_params = params;
36
+ }
37
+
38
+ cRotateCamera::~cRotateCamera()
39
+ {
40
+
41
+ }
42
+
43
+
44
+ // Ä«¸Þ¶ó ȸÀüÀ» ÀνÄÇÑ´Ù.
45
+ void cRotateCamera::DetectCameraRotate(cCamera &camera0, const vector<cv::Point> &contours, const Mat &skewTransform)
46
+ {
47
+ int thresholdValue = g_config.m_binaryThreshold; // ÀÓ°è°ª(Threshold) ¼³Á¤
48
+ int sensitive = g_config.m_rotateSensitivity;
49
+
50
+ cRectContours origContours(contours);
51
+ cRectContours target = origContours;
52
+ target.ScaleCenter(0.2f);
53
+
54
+
55
+ cvNamedWindow("HUV05-binarization", 0);
56
+ cvResizeWindow("HUV05-binarization", 640, 480);
57
+ cvMoveWindow("HUV05-binarization", -660, 520);
58
+ cvCreateTrackbar("Threshold", "HUV05-binarization", &thresholdValue, 255, NULL);
59
+ cvCreateTrackbar("Sensitivity", "HUV05-binarization", &sensitive, 300, NULL);
60
+
61
+ Mat src(camera0.Resolution().height, camera0.Resolution().width, CV_8UC(3));
62
+ while (1)
63
+ {
64
+ Mat &cam = camera0.ShowCaptureUndistortion(skewTransform, src);
65
+ if (cam.empty())
66
+ continue;
67
+
68
+ Mat grayscaleMat = src.clone();
69
+ cvtColor(src, grayscaleMat, CV_RGB2GRAY); // Ä÷¯¸¦ Èæ¹éÀ¸·Î º¯È¯
70
+
71
+ Mat binaryMat(grayscaleMat.size(), grayscaleMat.type());
72
+ cv::threshold(grayscaleMat, binaryMat, thresholdValue, 255, cv::THRESH_BINARY);
73
+
74
+
75
+ //----------------------------------------------------------------------------------------------
76
+ // À̹ÌÁö¿¡¼­ Æ÷ÀÎÅ͸¦ ã´Â´Ù.
77
+ SimpleBlobDetector detector(m_params);
78
+
79
+ // Detect blobs.
80
+ std::vector<KeyPoint> keypoints;
81
+ detector.detect(binaryMat, keypoints);
82
+
83
+ // Draw detected blobs as red circles.
84
+ // DrawMatchesFlags::DRAW_RICH_KEYPOINTS flag ensures the size of the circle corresponds to the size of blob
85
+ Mat im_with_keypoints;
86
+ drawKeypoints(binaryMat, keypoints, im_with_keypoints, Scalar::all(-1), DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
87
+
88
+ origContours.Draw(im_with_keypoints, Scalar(0, 255, 0), 2);
89
+ target.Draw(im_with_keypoints, Scalar(0, 0, 255), 2);
90
+
91
+ if (!keypoints.empty())
92
+ {
93
+ if (keypoints.size() == 4)
94
+ {
95
+ // 4°³ÀÇ Æ÷ÀÎÆ®¸¦ ¾ÈÁ¤ÀûÀ¸·Î ãÀ¸¸é, À§Ä¡¸¦ ÀúÀåÇϰí, Detect¸¦ Á¾·áÇÑ´Ù.
96
+ cRectContours detectRect(keypoints);
97
+ detectRect.Draw(im_with_keypoints, Scalar(0, 255, 255), 2);
98
+
99
+ // ¿øÁ¡¿¡¼­ ¹þ¾î³­ ±æÀ̸¦ Ãâ·ÂÇÑ´Ù.
100
+ vector<Point> centerLine;
101
+ centerLine.push_back(detectRect.Center());
102
+ centerLine.push_back(origContours.Center());
103
+ DrawLines(im_with_keypoints, centerLine, Scalar(255, 0, 0), 2);
104
+ //
105
+
106
+ Point offset = (origContours.Center() - detectRect.Center()) * (sensitive / 100.f);
107
+ target.Init(origContours.Center() + offset, 10.f);
108
+ }
109
+ }
110
+
111
+ imshow("HUV05-binarization", im_with_keypoints);
112
+
113
+ if (cvWaitKey(10) == VK_ESCAPE)
114
+ break;
115
+ }
116
+
117
+ cvDestroyWindow("HUV05-binarization");
118
+ }
pool/shard007/C++/0095178_hotmetadata.cpp ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //
2
+ // Copyright (c) Microsoft. All rights reserved.
3
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
4
+ //
5
+ //
6
+ // File: HotMetaData.cpp
7
+ //
8
+
9
+ //
10
+ // Class code:MetaData::HotMetaData represents a reader of hot data in MetaData hot stream.
11
+ //
12
+ // ======================================================================================
13
+
14
+ #include "external.h"
15
+
16
+ #include "hotmetadata.h"
17
+ #include "hotdataformat.h"
18
+ #include "hotheapsdirectoryiterator.h"
19
+
20
+ namespace MetaData
21
+ {
22
+
23
+ // --------------------------------------------------------------------------------------
24
+ //
25
+ // Class code:MetaData::HotMetaData represents a reader of hot data in MetaData hot stream.
26
+ //
27
+ __checkReturn
28
+ HRESULT
29
+ HotMetaData::Initialize(
30
+ DataBuffer data)
31
+ {
32
+ m_Data = data;
33
+
34
+ return S_OK;
35
+ } // HotMetaData::Initialize
36
+
37
+ // --------------------------------------------------------------------------------------
38
+ //
39
+ // Returns iterator of stored hot heaps (code:HotHeap).
40
+ //
41
+ __checkReturn
42
+ HRESULT
43
+ HotMetaData::GetHeapsDirectoryIterator(
44
+ HotHeapsDirectoryIterator *pHeapsDirectoryIterator)
45
+ {
46
+ if (m_Data.GetSize() < sizeof(struct HotMetaDataHeader))
47
+ {
48
+ Debug_ReportError("Invalid hot MetaData format - header doesn't fit into the hot data.");
49
+ return METADATA_E_INVALID_FORMAT;
50
+ }
51
+
52
+ struct HotMetaDataHeader *pHeader;
53
+ if (!m_Data.PeekDataAt<struct HotMetaDataHeader>(
54
+ m_Data.GetSize() - sizeof(struct HotMetaDataHeader),
55
+ &pHeader))
56
+ {
57
+ Debug_ReportInternalError("There's a bug, because previous size check succeeded.");
58
+ return METADATA_E_INTERNAL_ERROR;
59
+ }
60
+ // Get rid of the read header
61
+ DataBuffer heapsData = m_Data;
62
+ if (!heapsData.TruncateBySize(sizeof(struct HotMetaDataHeader)))
63
+ {
64
+ Debug_ReportInternalError("There's a bug, because previous size check succeeded.");
65
+ return METADATA_E_INTERNAL_ERROR;
66
+ }
67
+ DataBuffer heapsDirectoryData = heapsData;
68
+ if (!heapsDirectoryData.SkipToExactSize(pHeader->m_nHeapsDirectoryStart_NegativeOffset))
69
+ {
70
+ Debug_ReportError("Invalid hot MetaData format - heaps directory offset reaches in front of hot data.");
71
+ return METADATA_E_INVALID_FORMAT;
72
+ }
73
+ if (!heapsData.TruncateBySize(pHeader->m_nHeapsDirectoryStart_NegativeOffset))
74
+ {
75
+ Debug_ReportInternalError("There's a bug, because previous call to SkipToExactSize succeeded.");
76
+ return METADATA_E_INVALID_FORMAT;
77
+ }
78
+
79
+ pHeapsDirectoryIterator->Initialize(
80
+ heapsDirectoryData,
81
+ heapsData);
82
+
83
+ return S_OK;
84
+ } // HotMetaData::GetHeapsDirectoryIterator
85
+
86
+ }; // namespace MetaData
pool/shard007/C++/0095185_test_window_manager.cc ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2014 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ #include "ui/ozone/platform/test/test_window_manager.h"
6
+
7
+ #include "base/bind.h"
8
+ #include "base/file_util.h"
9
+ #include "base/location.h"
10
+ #include "base/stl_util.h"
11
+ #include "base/threading/worker_pool.h"
12
+ #include "third_party/skia/include/core/SkCanvas.h"
13
+ #include "third_party/skia/include/core/SkSurface.h"
14
+ #include "ui/gfx/codec/png_codec.h"
15
+ #include "ui/gfx/skia_util.h"
16
+ #include "ui/gfx/vsync_provider.h"
17
+ #include "ui/ozone/public/surface_ozone_canvas.h"
18
+
19
+ namespace ui {
20
+
21
+ namespace {
22
+
23
+ void WriteDataToFile(const base::FilePath& location, const SkBitmap& bitmap) {
24
+ DCHECK(!location.empty());
25
+ std::vector<unsigned char> png_data;
26
+ gfx::PNGCodec::FastEncodeBGRASkBitmap(bitmap, true, &png_data);
27
+ base::WriteFile(location,
28
+ reinterpret_cast<const char*>(vector_as_array(&png_data)),
29
+ png_data.size());
30
+ }
31
+
32
+ class FileSurface : public SurfaceOzoneCanvas {
33
+ public:
34
+ FileSurface(const base::FilePath& location) : location_(location) {}
35
+ virtual ~FileSurface() {}
36
+
37
+ // SurfaceOzoneCanvas overrides:
38
+ virtual void ResizeCanvas(const gfx::Size& viewport_size) OVERRIDE {
39
+ surface_ = skia::AdoptRef(SkSurface::NewRaster(SkImageInfo::MakeN32Premul(
40
+ viewport_size.width(), viewport_size.height())));
41
+ }
42
+ virtual skia::RefPtr<SkCanvas> GetCanvas() OVERRIDE {
43
+ return skia::SharePtr(surface_->getCanvas());
44
+ }
45
+ virtual void PresentCanvas(const gfx::Rect& damage) OVERRIDE {
46
+ if (location_.empty())
47
+ return;
48
+ SkBitmap bitmap;
49
+ bitmap.setInfo(surface_->getCanvas()->imageInfo());
50
+
51
+ // TODO(dnicoara) Use SkImage instead to potentially avoid a copy.
52
+ // See crbug.com/361605 for details.
53
+ if (surface_->getCanvas()->readPixels(&bitmap, 0, 0)) {
54
+ base::WorkerPool::PostTask(
55
+ FROM_HERE, base::Bind(&WriteDataToFile, location_, bitmap), true);
56
+ }
57
+ }
58
+ virtual scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider() OVERRIDE {
59
+ return scoped_ptr<gfx::VSyncProvider>();
60
+ }
61
+
62
+ private:
63
+ base::FilePath location_;
64
+ skia::RefPtr<SkSurface> surface_;
65
+ };
66
+
67
+ } // namespace
68
+
69
+ TestWindowManager::TestWindowManager(const base::FilePath& dump_location)
70
+ : location_(dump_location) {
71
+ }
72
+
73
+ TestWindowManager::~TestWindowManager() {
74
+ }
75
+
76
+ void TestWindowManager::Initialize() {
77
+ if (location_.empty())
78
+ return;
79
+ if (!DirectoryExists(location_) && !base::CreateDirectory(location_) &&
80
+ location_ != base::FilePath("/dev/null"))
81
+ PLOG(FATAL) << "unable to create output directory";
82
+ if (!base::PathIsWritable(location_))
83
+ PLOG(FATAL) << "unable to write to output location";
84
+ }
85
+
86
+ int32_t TestWindowManager::AddWindow(TestWindow* window) {
87
+ return windows_.Add(window);
88
+ }
89
+
90
+ void TestWindowManager::RemoveWindow(int32_t window_id, TestWindow* window) {
91
+ DCHECK_EQ(window, windows_.Lookup(window_id));
92
+ windows_.Remove(window_id);
93
+ }
94
+
95
+ base::FilePath TestWindowManager::base_path() const {
96
+ return location_;
97
+ }
98
+
99
+ scoped_ptr<SurfaceOzoneCanvas> TestWindowManager::CreateCanvasForWidget(
100
+ gfx::AcceleratedWidget widget) {
101
+ TestWindow* window = windows_.Lookup(widget);
102
+ DCHECK(window);
103
+ return make_scoped_ptr<SurfaceOzoneCanvas>(new FileSurface(window->path()));
104
+ }
105
+
106
+ bool TestWindowManager::LoadEGLGLES2Bindings(
107
+ AddGLLibraryCallback add_gl_library,
108
+ SetGLGetProcAddressProcCallback set_gl_get_proc_address) {
109
+ return false;
110
+ }
111
+
112
+ } // namespace ui
pool/shard007/C++/0095186_TcrDistributionManager.cpp ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one or more
3
+ * contributor license agreements. See the NOTICE file distributed with
4
+ * this work for additional information regarding copyright ownership.
5
+ * The ASF licenses this file to You under the Apache License, Version 2.0
6
+ * (the "License"); you may not use this file except in compliance with
7
+ * the License. You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ #include <geode/internal/geode_globals.hpp>
18
+ #include "TcrDistributionManager.hpp"
19
+ #include "ThinClientRegion.hpp"
20
+ #include "TcrEndpoint.hpp"
21
+ #include <geode/ExceptionTypes.hpp>
22
+ #include "Utils.hpp"
23
+ using namespace apache::geode::client;
24
+
25
+ TcrDistributionManager::TcrDistributionManager(
26
+ ThinClientRegion* region, TcrConnectionManager& connManager)
27
+ : ThinClientDistributionManager(connManager, region) {
28
+ GF_R_ASSERT(region != nullptr);
29
+ m_clientNotification =
30
+ region->getAttributes().getClientNotificationEnabled();
31
+ }
32
+
33
+ void TcrDistributionManager::getEndpointNames(
34
+ std::unordered_set<std::string>& endpointNames) {
35
+ Utils::parseEndpointNamesString(m_region->getAttributes().getEndpoints(),
36
+ endpointNames);
37
+ }
38
+
39
+ void TcrDistributionManager::destroyAction() {
40
+ if (m_activeEndpoint >= 0) {
41
+ m_region->unregisterKeys();
42
+ }
43
+ }
44
+
45
+ void TcrDistributionManager::postUnregisterAction() {
46
+ if (m_clientNotification) {
47
+ m_region->localInvalidateFailover();
48
+ }
49
+ }
50
+
51
+ bool TcrDistributionManager::preFailoverAction() {
52
+ return !m_region->isDestroyed();
53
+ }
54
+
55
+ bool TcrDistributionManager::postFailoverAction(TcrEndpoint* endpoint) {
56
+ if (m_clientNotification) {
57
+ return (m_region->registerKeys(endpoint) == GF_NOERR);
58
+ }
59
+ return true;
60
+ }
pool/shard007/C++/0095191_X3DShadersContext.cpp ADDED
@@ -0,0 +1,230 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* -*- Mode: C++; coding: utf-8; tab-width: 3; indent-tabs-mode: tab; c-basic-offset: 3 -*-
2
+ *******************************************************************************
3
+ *
4
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
+ *
6
+ * Copyright create3000, Scheffelstraße 31a, Leipzig, Germany 2011.
7
+ *
8
+ * All rights reserved. Holger Seelig <holger.seelig@yahoo.de>.
9
+ *
10
+ * THIS IS UNPUBLISHED SOURCE CODE OF create3000.
11
+ *
12
+ * The copyright notice above does not evidence any actual of intended
13
+ * publication of such source code, and is an unpublished work by create3000.
14
+ * This material contains CONFIDENTIAL INFORMATION that is the property of
15
+ * create3000.
16
+ *
17
+ * No permission is granted to copy, distribute, or create derivative works from
18
+ * the contents of this software, in whole or in part, without the prior written
19
+ * permission of create3000.
20
+ *
21
+ * NON-MILITARY USE ONLY
22
+ *
23
+ * All create3000 software are effectively free software with a non-military use
24
+ * restriction. It is free. Well commented source is provided. You may reuse the
25
+ * source in any way you please with the exception anything that uses it must be
26
+ * marked to indicate is contains 'non-military use only' components.
27
+ *
28
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
29
+ *
30
+ * Copyright 1999, 2016 Holger Seelig <holger.seelig@yahoo.de>.
31
+ *
32
+ * This file is part of the Titania Project.
33
+ *
34
+ * Titania is free software: you can redistribute it and/or modify it under the
35
+ * terms of the GNU General Public License version 3 only, as published by the
36
+ * Free Software Foundation.
37
+ *
38
+ * Titania is distributed in the hope that it will be useful, but WITHOUT ANY
39
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
40
+ * A PARTICULAR PURPOSE. See the GNU General Public License version 3 for more
41
+ * details (a copy is included in the LICENSE file that accompanied this code).
42
+ *
43
+ * You should have received a copy of the GNU General Public License version 3
44
+ * along with Titania. If not, see <http://www.gnu.org/licenses/gpl.html> for a
45
+ * copy of the GPLv3 License.
46
+ *
47
+ * For Silvio, Joy and Adi.
48
+ *
49
+ ******************************************************************************/
50
+
51
+ #include "X3DShadersContext.h"
52
+
53
+ #include "../../Browser/Core/BrowserOptions.h"
54
+ #include "../../Browser/Networking/config.h"
55
+ #include "../../Browser/Shaders/ShaderTest.h"
56
+ #include "../../Browser/X3DBrowser.h"
57
+ #include "../../Components/Networking/LoadSensor.h"
58
+ #include "../../Components/Shaders/ComposedShader.h"
59
+ #include "../../Components/Shaders/ShaderPart.h"
60
+ #include "../../Rendering/OpenGL.h"
61
+
62
+ #include <regex>
63
+
64
+ namespace titania {
65
+ namespace X3D {
66
+
67
+ X3DShadersContext::X3DShadersContext () :
68
+ X3DBaseNode (),
69
+ shaders (true),
70
+ shadingLanguageVersion (),
71
+ maxVertexUniformVectors (0),
72
+ maxFragmentUniformVectors (0),
73
+ maxVertexAttributes (0),
74
+ pointShader (),
75
+ wireframeShader (),
76
+ gouraudShader (),
77
+ phongShader (),
78
+ defaultShader (),
79
+ shadowShader ()
80
+ {
81
+ addChildObjects (shaders,
82
+ pointShader,
83
+ wireframeShader,
84
+ gouraudShader,
85
+ phongShader,
86
+ defaultShader,
87
+ shadowShader);
88
+ }
89
+
90
+ void
91
+ X3DShadersContext::initialize ()
92
+ {
93
+ if (getBrowser () -> getLoadUrlObjects ())
94
+ {
95
+ std::istringstream shadingLanguageVersionStream ((const char*) glGetString (GL_SHADING_LANGUAGE_VERSION));
96
+
97
+ shadingLanguageVersionStream .imbue (std::locale::classic ());
98
+
99
+ shadingLanguageVersionStream >> shadingLanguageVersion;
100
+
101
+ glGetIntegerv (GL_MAX_VERTEX_UNIFORM_VECTORS, &maxVertexUniformVectors);
102
+ glGetIntegerv (GL_MAX_FRAGMENT_UNIFORM_VECTORS, &maxFragmentUniformVectors);
103
+ glGetIntegerv (GL_MAX_VERTEX_ATTRIBS, &maxVertexAttributes);
104
+
105
+ // Shaders
106
+
107
+ if (getBrowser () -> getSharedContext ())
108
+ {
109
+ pointShader = getBrowser () -> getSharedContext () -> getPointShader ();
110
+ wireframeShader = getBrowser () -> getSharedContext () -> getWireframeShader ();
111
+ gouraudShader = getBrowser () -> getSharedContext () -> getGouraudShader ();
112
+ phongShader = getBrowser () -> getSharedContext () -> getPhongShader ();
113
+ shadowShader = getBrowser () -> getSharedContext () -> getShadowShader ();
114
+ }
115
+ else
116
+ {
117
+ pointShader = createShader (getExecutionContext (), "TitaniaPointSet", { get_shader ("Shaders/PointSet.vs") .str () }, { get_shader ("Shaders/PointSet.fs") .str () });
118
+ wireframeShader = createShader (getExecutionContext (), "TitaniaWireframe", { get_shader ("Shaders/Wireframe.vs") .str () }, { get_shader ("Shaders/Wireframe.fs") .str () });
119
+ gouraudShader = createShader (getExecutionContext (), "TitaniaGouraud", { get_shader ("Shaders/Gouraud.vs") .str () }, { get_shader ("Shaders/Gouraud.fs") .str () });
120
+ phongShader = createShader (getExecutionContext (), "TitaniaPhong", { get_shader ("Shaders/Phong.vs") .str () }, { get_shader ("Shaders/Phong.fs") .str () });
121
+ shadowShader = createShader (getExecutionContext (), "TitaniaShadow", { get_shader ("Shaders/Phong.vs") .str () }, { get_shader ("Shaders/Phong.fs") .str () }, true);
122
+
123
+ gouraudShader -> isValid () .addInterest (&X3DShadersContext::set_gouraud_shader_valid, this);
124
+ phongShader -> isValid () .addInterest (&X3DShadersContext::set_phong_shader_valid, this);
125
+ shadowShader -> isValid () .addInterest (&X3DShadersContext::set_shadow_shader_valid, this);
126
+ }
127
+
128
+ // Shading
129
+
130
+ getBrowser () -> getBrowserOptions () -> getShading () .addInterest (&X3DShadersContext::set_shading, this);
131
+
132
+ set_shading ();
133
+ }
134
+ }
135
+
136
+ X3DPtr <ComposedShader>
137
+ X3DShadersContext::createShader (X3DExecutionContext* const executionContext,
138
+ const std::string & name,
139
+ const MFString & vertexUrl,
140
+ const MFString & fragmentUrl,
141
+ const bool shadow)
142
+ {
143
+ const auto vertexPart = MakePtr <ShaderPart> (executionContext);
144
+ const auto fragmentPart = MakePtr <ShaderPart> (executionContext);
145
+ const auto shaderNode = MakePtr <ComposedShader> (executionContext);
146
+
147
+ fragmentPart -> setName (name + "FragmentShaderPart");
148
+ vertexPart -> setName (name + "VertexShaderPart");
149
+ shaderNode -> setName (name + "ComposedShader");
150
+
151
+ vertexPart -> setShadow (shadow);
152
+ fragmentPart -> setShadow (shadow);
153
+
154
+ fragmentPart -> type () = "FRAGMENT";
155
+ vertexPart -> url () = vertexUrl;
156
+ fragmentPart -> url () = fragmentUrl;
157
+
158
+ shaderNode -> setCustom (false);
159
+ shaderNode -> parts () .emplace_back (vertexPart);
160
+ shaderNode -> parts () .emplace_back (fragmentPart);
161
+
162
+ vertexPart -> setup ();
163
+ fragmentPart -> setup ();
164
+ shaderNode -> setup ();
165
+
166
+ return shaderNode;
167
+ }
168
+
169
+ void
170
+ X3DShadersContext::set_gouraud_shader_valid ()
171
+ {
172
+ gouraudShader -> isValid () .removeInterest (&X3DShadersContext::set_gouraud_shader_valid, this);
173
+
174
+ if (gouraudShader -> isValid () and ShaderTest::verify (getBrowser (), gouraudShader))
175
+ return;
176
+
177
+ getBrowser () -> getConsole () -> warn ("*** Warning: All else fails, using fallback VRML shader.\n\n");
178
+
179
+ gouraudShader -> parts () [0] -> setField <MFString> ("url", MFString ({ get_shader ("Shaders/Fallback.vs") .str () }));
180
+ gouraudShader -> parts () [1] -> setField <MFString> ("url", MFString ({ get_shader ("Shaders/Fallback.fs") .str () }));
181
+ }
182
+
183
+ void
184
+ X3DShadersContext::set_phong_shader_valid ()
185
+ {
186
+ phongShader -> isValid () .removeInterest (&X3DShadersContext::set_phong_shader_valid, this);
187
+
188
+ if (phongShader -> isValid () and ShaderTest::verify (getBrowser (), phongShader))
189
+ return;
190
+
191
+ getBrowser () -> getConsole () -> warn ("*** Warning: Phong shading not possible, using Gouraud shading.\n\n");
192
+
193
+ phongShader = gouraudShader;
194
+
195
+ set_shading ();
196
+ }
197
+
198
+ void
199
+ X3DShadersContext::set_shadow_shader_valid ()
200
+ {
201
+ shadowShader -> isValid () .removeInterest (&X3DShadersContext::set_shadow_shader_valid, this);
202
+
203
+ if (shadowShader -> isValid () and ShaderTest::verify (getBrowser (), shadowShader))
204
+ return;
205
+
206
+ getBrowser () -> getConsole () -> warn ("*** Warning: Shadow shading not possible, using Gouraud shading.\n\n");
207
+
208
+ shadowShader = gouraudShader;
209
+ }
210
+
211
+ void
212
+ X3DShadersContext::set_shading ()
213
+ {
214
+ const auto & shading = getBrowser () -> getBrowserOptions () -> getShading ();
215
+
216
+ if (shading == ShadingType::PHONG)
217
+ {
218
+ defaultShader = getPhongShader ();
219
+ }
220
+ else // GOURAUD
221
+ {
222
+ defaultShader = getGouraudShader ();
223
+ }
224
+ }
225
+
226
+ X3DShadersContext::~X3DShadersContext ()
227
+ { }
228
+
229
+ } // X3D
230
+ } // titania
pool/shard007/C++/0095194_arcball.cpp ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include "vixen.h"
2
+ #include "vxutil.h"
3
+ #include "util/vxarcball.h"
4
+
5
+ namespace Vixen {
6
+ VX_IMPLEMENT_CLASSID(ArcBall, Engine, VX_ArcBall);
7
+
8
+ ArcBall::ArcBall() : MouseEngine()
9
+ {
10
+ m_Ball.Set(Vec3(0,0,0), 0);
11
+ m_Rotation.Set(Vec3(0,0,0), 1);
12
+ m_Button = MouseEvent::LEFT;
13
+ GetMessenger()->Observe(this, Event::MOUSE, NULL);
14
+ }
15
+
16
+ Vec3 ArcBall::WhereOnSphere(const Vec2& pos) const
17
+ {
18
+ Vec3 ballMouse;
19
+ float mag;
20
+ Model* mod = (Model*) GetTarget();
21
+
22
+ ballMouse.x = -(pos.x - m_Ball.Center.x) / m_Ball.Radius;
23
+ ballMouse.y = (pos.y - m_Ball.Center.y) / m_Ball.Radius;
24
+ mag = ballMouse.x * ballMouse.x + ballMouse.y * ballMouse.y;
25
+ if (mag > 1)
26
+ {
27
+ float scale = float(1 / sqrt(mag));
28
+ ballMouse.x = ballMouse.x * scale;
29
+ ballMouse.y = ballMouse.y * scale;
30
+ ballMouse.z = 0;
31
+ }
32
+ else
33
+ ballMouse.z = sqrt(1.0f - mag);
34
+ return ballMouse;
35
+ }
36
+
37
+ Quat ArcBall::QuatFromPoints(const Vec3& from, const Vec3& to)
38
+ {
39
+ Quat qu;
40
+ qu.x = from.y * to.z - from.z * to.y;
41
+ qu.y = from.z * to.x - from.x * to.z;
42
+ qu.z = from.x * to.y - from.y * to.x;
43
+ qu.w = from.x * to.x + from.y * to.y + from.z * to.z;
44
+ return qu;
45
+ }
46
+
47
+ void ArcBall::Initialize(const Vec2& pos)
48
+ {
49
+ Model* model = (Model*) GetTarget();
50
+ Scene* scene = GetMainScene();
51
+ Sphere sphere;
52
+
53
+ if (model && model->IsClass(VX_Model))
54
+ {
55
+ if (model->IsClass(VX_Camera))
56
+ {
57
+ Vec3 p;
58
+ scene->GetModels()->GetBound(&sphere, Model::WORLD);
59
+ sphere.Radius = model->GetTranslation().Distance(sphere.Center);
60
+ }
61
+ else
62
+ model->GetBound(&sphere, Model::WORLD);
63
+ m_Ball.Center.Set(sphere.Center.x, sphere.Center.y, sphere.Center.z);
64
+ m_Rotation.Set(model->GetRotation());
65
+ m_Ball.Radius = sphere.Radius;
66
+ }
67
+ else
68
+ {
69
+ float w = scene->GetViewport().Width();
70
+ float h = scene->GetViewport().Height();
71
+ m_Ball.Center.Set(w / 2, h / 2, 0);
72
+ m_Rotation.Set(Vec3(0, 0, 0), 1);
73
+ m_Ball.Radius = (w > h) ? m_Ball.Center.x : m_Ball.Center.y;
74
+ }
75
+ }
76
+
77
+ void ArcBall::OnMouse(const Vec2& pos, uint32 flags)
78
+ {
79
+ SharedObj* target = GetTarget();
80
+ int mouseflags = MouseFlags;
81
+ Vec2 oldpos = MousePos;
82
+
83
+ MouseEngine::OnMouse(pos, flags); // update position and flags
84
+ if (flags != m_Button) // not dragging now?
85
+ return;
86
+ if ((mouseflags & m_Button) == 0) // starting a drag?
87
+ {
88
+ Initialize(pos);
89
+ return;
90
+ }
91
+ Vec3 from = WhereOnSphere(oldpos); // where we were on the sphere last event
92
+ Vec3 to = WhereOnSphere(pos); // where we are on the sphere now
93
+ m_Rotation = QuatFromPoints(from, to); // relative rotation quat
94
+ if (target && target->IsClass(VX_Model))
95
+ {
96
+ Matrix mtx;
97
+ Model* mod = (Model*) target;
98
+ Vec3 t = mod->GetTranslation();
99
+
100
+ if (mod->IsClass(VX_Camera))
101
+ {
102
+ mod->Translate(m_Ball.Center);
103
+ mod->Rotate(m_Rotation);
104
+ mod->Translate(-m_Ball.Center);
105
+ }
106
+ else
107
+ {
108
+ mtx.TranslationMatrix(-m_Ball.Center);
109
+ mtx.Rotate(m_Rotation);
110
+ mtx.SetTranslation(t);
111
+ ((Model*) target)->SetTransform(&mtx);
112
+ }
113
+ }
114
+ if (IsSet(SharedObj::DOEVENTS))
115
+ LogEvent();
116
+ }
117
+
118
+ /*
119
+ * If we should be logging events, log the navigate event here
120
+ */
121
+ void ArcBall::LogEvent()
122
+ {
123
+ NavigateEvent* event = new NavigateEvent;
124
+
125
+ event->Sender = this;
126
+ event->Time = 0;
127
+ event->Flags = NavigateEvent::ROTATION | NavigateEvent::YROTATION | NavigateEvent::XROTATION | NavigateEvent::ZROTATION;
128
+ event->Rot = m_Rotation;
129
+ event->Log();
130
+ }
131
+
132
+ } // end Vixen
pool/shard007/C++/0095197_ChunkChecksum.cc ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* <!-- copyright */
2
+ /*
3
+ * aria2 - The high speed download utility
4
+ *
5
+ * Copyright (C) 2010 Tatsuhiro Tsujikawa
6
+ *
7
+ * This program is free software; you can redistribute it and/or modify
8
+ * it under the terms of the GNU General Public License as published by
9
+ * the Free Software Foundation; either version 2 of the License, or
10
+ * (at your option) any later version.
11
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ * GNU General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU General Public License
18
+ * along with this program; if not, write to the Free Software
19
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
+ *
21
+ * In addition, as a special exception, the copyright holders give
22
+ * permission to link the code of portions of this program with the
23
+ * OpenSSL library under certain conditions as described in each
24
+ * individual source file, and distribute linked combinations
25
+ * including the two.
26
+ * You must obey the GNU General Public License in all respects
27
+ * for all of the code used other than OpenSSL. If you modify
28
+ * file(s) with this exception, you may extend this exception to your
29
+ * version of the file(s), but you are not obligated to do so. If you
30
+ * do not wish to do so, delete this exception statement from your
31
+ * version. If you delete this exception statement from all source
32
+ * files in the program, then also delete it here.
33
+ */
34
+ /* copyright --> */
35
+ #include "ChunkChecksum.h"
36
+ #include "A2STR.h"
37
+
38
+ namespace aria2 {
39
+
40
+ ChunkChecksum::ChunkChecksum():pieceLength_(0) {}
41
+
42
+ ChunkChecksum::ChunkChecksum
43
+ (std::string hashType,
44
+ std::vector<std::string> pieceHashes,
45
+ int32_t pieceLength)
46
+ : hashType_(std::move(hashType)),
47
+ pieceHashes_(std::move(pieceHashes)),
48
+ pieceLength_(pieceLength)
49
+ {}
50
+
51
+ bool ChunkChecksum::validateChunk
52
+ (const std::string& actualDigest,
53
+ size_t index) const
54
+ {
55
+ const std::string& digest = getPieceHash(index);
56
+ return !digest.empty() && actualDigest == digest;
57
+ }
58
+
59
+ int64_t ChunkChecksum::getEstimatedDataLength() const
60
+ {
61
+ return static_cast<int64_t>(pieceLength_)*pieceHashes_.size();
62
+ }
63
+
64
+ size_t ChunkChecksum::countPieceHash() const
65
+ {
66
+ return pieceHashes_.size();
67
+ }
68
+
69
+ const std::string& ChunkChecksum::getPieceHash(size_t index) const
70
+ {
71
+ if(index < pieceHashes_.size()) {
72
+ return pieceHashes_[index];
73
+ } else {
74
+ return A2STR::NIL;
75
+ }
76
+ }
77
+
78
+ void ChunkChecksum::setHashType(std::string hashType)
79
+ {
80
+ hashType_ = std::move(hashType);
81
+ }
82
+
83
+ void ChunkChecksum::setPieceHashes(std::vector<std::string> pieceHashes)
84
+ {
85
+ pieceHashes_ = std::move(pieceHashes);
86
+ }
87
+
88
+ } // namespace aria2
pool/shard007/C++/0095209_Particle.cpp ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Particle.cpp
3
+ */
4
+
5
+ #include "Particle.h"
6
+ #include "map.h"
7
+ #include "Robot.h"
8
+ #include "Point.h"
9
+ #include "config.h"
10
+
11
+ Particle::Particle(Point p_pPoint,double p_dYaw,double p_dBel)
12
+ :_particleLocation(p_pPoint),
13
+ _particleYaw(p_dYaw),
14
+ _particleBelief(p_dBel)
15
+ {
16
+ }
17
+
18
+ void Particle::update(Point p_dDeltaLocation, double p_dDeltaYaw)
19
+ {
20
+ // Update The location according to delta
21
+ _particleLocation.x += p_dDeltaLocation.x;
22
+ _particleLocation.y += p_dDeltaLocation.y;
23
+ _particleYaw += p_dDeltaYaw;
24
+
25
+ // Robot path posterior
26
+ double probOfPath = this->getParticleProbability(p_dDeltaLocation, p_dDeltaYaw);
27
+
28
+ // Calculate new belief according to path, observations and previous belief
29
+ _particleBelief = SAFETY_FACTORY * _particleBelief * probOfPath ;//* ProbOfObs;
30
+
31
+ // Check to see if particle exceeded the maximum probability
32
+ if (_particleBelief > 1)
33
+ {
34
+ _particleBelief = 1;
35
+ }
36
+ }
37
+
38
+ // Calculates the probability that the movement is accurate
39
+ double Particle::getParticleProbability(Point p_pLocation, double p_dDeltaYaw)
40
+ {
41
+ // Distance Traveled
42
+ double distance = sqrt(pow(p_pLocation.x, 2) + pow(p_pLocation.y, 2));
43
+
44
+ // Kept moving forward
45
+ if ((p_dDeltaYaw == 0) && (distance < DISTANCE_LIMIT))
46
+ {
47
+ return 1;
48
+ }
49
+ else if ((distance < DISTANCE_LIMIT) && (p_dDeltaYaw < YAW_LIMIT))
50
+ {
51
+ return 0.8;
52
+ }
53
+ else if (((distance > DISTANCE_LIMIT) && (p_dDeltaYaw < YAW_LIMIT)) ||
54
+ ((distance < DISTANCE_LIMIT) && (p_dDeltaYaw > YAW_LIMIT)))
55
+ {
56
+ return 0.6;
57
+ }
58
+ else
59
+ {
60
+ return 0.2;
61
+ }
62
+ }
63
+
64
+ Particle* Particle::CreateParticle()
65
+ {
66
+ double newX = _particleLocation.x + (rand() % 21) / 100;
67
+ double newY = _particleLocation.y + (rand() % 21) / 100;
68
+ double newYaw = _particleYaw + (rand() % 61 - 30.0) * PI / 180.0;
69
+ return new Particle(Point(newX, newY), newYaw, _particleBelief);//, new Map(*_particleMap));
70
+ }
71
+
72
+
73
+ double Particle::getBelief()
74
+ {
75
+ return this->_particleBelief;
76
+ }
77
+
78
+ Particle::~Particle()
79
+ {
80
+ }
pool/shard007/C++/0095217_propagateremotemove.cpp ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright (C) by Olivier Goffart <ogoffart@owncloud.com>
3
+ *
4
+ * This program is free software; you can redistribute it and/or modify
5
+ * it under the terms of the GNU General Public License as published by
6
+ * the Free Software Foundation; either version 2 of the License, or
7
+ * (at your option) any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful, but
10
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
+ * for more details.
13
+ */
14
+
15
+ #include "propagateremotemove.h"
16
+ #include "owncloudpropagator_p.h"
17
+ #include "account.h"
18
+ #include "syncjournalfilerecord.h"
19
+ #include "filesystem.h"
20
+ #include <QFile>
21
+ #include <QStringList>
22
+
23
+ namespace OCC {
24
+
25
+ MoveJob::MoveJob(AccountPtr account, const QString& path,
26
+ const QString &destination, QObject* parent)
27
+ : AbstractNetworkJob(account, path, parent), _destination(destination)
28
+ { }
29
+
30
+
31
+ void MoveJob::start()
32
+ {
33
+ QNetworkRequest req;
34
+ req.setRawHeader("Destination", QUrl::toPercentEncoding(_destination, "/"));
35
+ setReply(davRequest("MOVE", path(), req));
36
+ setupConnections(reply());
37
+
38
+ if( reply()->error() != QNetworkReply::NoError ) {
39
+ qWarning() << Q_FUNC_INFO << " Network error: " << reply()->errorString();
40
+ }
41
+ AbstractNetworkJob::start();
42
+ }
43
+
44
+
45
+ QString MoveJob::errorString()
46
+ {
47
+ if (_timedout) {
48
+ return tr("Connection timed out");
49
+ } else if (reply()->hasRawHeader("OC-ErrorString")) {
50
+ return reply()->rawHeader("OC-ErrorString");
51
+ } else {
52
+ return reply()->errorString();
53
+ }
54
+ }
55
+
56
+ bool MoveJob::finished()
57
+ {
58
+ emit finishedSignal();
59
+ return true;
60
+ }
61
+
62
+ void PropagateRemoteMove::start()
63
+ {
64
+ if (_propagator->_abortRequested.fetchAndAddRelaxed(0))
65
+ return;
66
+
67
+ qDebug() << Q_FUNC_INFO << _item->_file << _item->_renameTarget;
68
+
69
+ QString targetFile(_propagator->getFilePath(_item->_renameTarget));
70
+
71
+ if (_item->_file == _item->_renameTarget) {
72
+ // The parents has been renamed already so there is nothing more to do.
73
+ finalize();
74
+ return;
75
+ }
76
+ if (_item->_file == QLatin1String("Shared") ) {
77
+ // Before owncloud 7, there was no permissions system. At the time all the shared files were
78
+ // in a directory called "Shared" and were not supposed to be moved, otherwise bad things happens
79
+
80
+ QString versionString = _propagator->account()->serverVersion();
81
+ if (versionString.contains('.') && versionString.split('.')[0].toInt() < 7) {
82
+ QString originalFile(_propagator->getFilePath(QLatin1String("Shared")));
83
+ _propagator->addTouchedFile(originalFile);
84
+ _propagator->addTouchedFile(targetFile);
85
+ QString renameError;
86
+ if( FileSystem::rename(targetFile, originalFile, &renameError) ) {
87
+ done(SyncFileItem::NormalError, tr("This folder must not be renamed. It is renamed back to its original name."));
88
+ } else {
89
+ done(SyncFileItem::NormalError, tr("This folder must not be renamed. Please name it back to Shared."));
90
+ }
91
+ return;
92
+ }
93
+ }
94
+
95
+ _job = new MoveJob(_propagator->account(),
96
+ _propagator->_remoteFolder + _item->_file,
97
+ _propagator->_remoteDir + _item->_renameTarget,
98
+ this);
99
+ connect(_job, SIGNAL(finishedSignal()), this, SLOT(slotMoveJobFinished()));
100
+ _propagator->_activeJobs++;
101
+ _job->start();
102
+
103
+ }
104
+
105
+ void PropagateRemoteMove::abort()
106
+ {
107
+ if (_job && _job->reply())
108
+ _job->reply()->abort();
109
+ }
110
+
111
+ void PropagateRemoteMove::slotMoveJobFinished()
112
+ {
113
+ _propagator->_activeJobs--;
114
+
115
+ Q_ASSERT(_job);
116
+
117
+ qDebug() << Q_FUNC_INFO << _job->reply()->request().url() << "FINISHED WITH STATUS"
118
+ << _job->reply()->error()
119
+ << (_job->reply()->error() == QNetworkReply::NoError ? QLatin1String("") : _job->reply()->errorString());
120
+
121
+ QNetworkReply::NetworkError err = _job->reply()->error();
122
+ _item->_httpErrorCode = _job->reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
123
+
124
+ if (err != QNetworkReply::NoError) {
125
+
126
+ if( checkForProblemsWithShared(_item->_httpErrorCode,
127
+ tr("The file was renamed but is part of a read only share. The original file was restored."))) {
128
+ return;
129
+ }
130
+
131
+ SyncFileItem::Status status = classifyError(err, _item->_httpErrorCode);
132
+ done(status, _job->errorString());
133
+ return;
134
+ }
135
+
136
+ _item->_requestDuration = _job->duration();
137
+ _item->_responseTimeStamp = _job->responseTimestamp();
138
+
139
+ if (_item->_httpErrorCode != 201 ) {
140
+ // Normaly we expect "201 Created"
141
+ // If it is not the case, it might be because of a proxy or gateway intercepting the request, so we must
142
+ // throw an error.
143
+ done(SyncFileItem::NormalError, tr("Wrong HTTP code returned by server. Expected 201, but received \"%1 %2\".")
144
+ .arg(_item->_httpErrorCode).arg(_job->reply()->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString()));
145
+ return;
146
+ }
147
+
148
+ finalize();
149
+
150
+ }
151
+
152
+ void PropagateRemoteMove::finalize()
153
+ {
154
+ _propagator->_journal->deleteFileRecord(_item->_originalFile);
155
+ SyncJournalFileRecord record(*_item, _propagator->getFilePath(_item->_renameTarget));
156
+ record._path = _item->_renameTarget;
157
+
158
+ _propagator->_journal->setFileRecord(record);
159
+ _propagator->_journal->commit("Remote Rename");
160
+ done(SyncFileItem::Success);
161
+ }
162
+
163
+
164
+ }
165
+
pool/shard007/C++/0095224_TableViewPlugin.cpp ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*!
2
+ \file TableViewPlugin.cpp
3
+ \author Dane Gardner <dane.gardner@gmail.com>
4
+
5
+ \section LICENSE
6
+ This file is part of the Parallel Tools GUI Framework (PTGF)
7
+ Copyright (C) 2010-2013 Argo Navis Technologies, LLC
8
+
9
+ This library is free software; you can redistribute it and/or modify it
10
+ under the terms of the GNU Lesser General Public License as published by the
11
+ Free Software Foundation; either version 2.1 of the License, or (at your
12
+ option) any later version.
13
+
14
+ This library is distributed in the hope that it will be useful, but WITHOUT
15
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
17
+ for more details.
18
+
19
+ You should have received a copy of the GNU Lesser General Public License
20
+ along with this library; if not, write to the Free Software Foundation,
21
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22
+ */
23
+
24
+ #include "TableViewPlugin.h"
25
+
26
+ #include <PluginManager/PluginManager.h>
27
+ #include <ViewManager/ViewManager.h>
28
+
29
+ #include "TableView.h"
30
+
31
+ namespace Plugins {
32
+ namespace TableView {
33
+
34
+ /*! \namespace Plugins::TableView
35
+ \brief Contains the TableViewPlugin.
36
+ */
37
+
38
+ /*! \class TableViewPlugin
39
+ \version 0.4.dev
40
+ \brief
41
+
42
+ \par Depends on Plugins:
43
+
44
+ \todo Document this more explicitly.
45
+ */
46
+
47
+ TableViewPlugin::TableViewPlugin(QObject *parent) : QObject(parent)
48
+ {
49
+ m_Name = "TableView";
50
+ m_Version = QString("%1.%2.%3").arg(VER_MAJ).arg(VER_MIN).arg(VER_PAT);
51
+ }
52
+
53
+ TableViewPlugin::~TableViewPlugin()
54
+ {
55
+ }
56
+
57
+ bool TableViewPlugin::initialize(QStringList &args, QString *err)
58
+ {
59
+ Q_UNUSED(args)
60
+ Q_UNUSED(err)
61
+
62
+ try {
63
+
64
+ Core::PluginManager::PluginManager &pluginManager = Core::PluginManager::PluginManager::instance();
65
+ pluginManager.addObject(this); /* Register ourselves as an IViewFactory */
66
+
67
+ } catch(...) {
68
+ return false;
69
+ }
70
+
71
+ return true;
72
+ }
73
+
74
+ void TableViewPlugin::shutdown()
75
+ {
76
+ }
77
+
78
+ QString TableViewPlugin::name()
79
+ {
80
+ return m_Name;
81
+ }
82
+
83
+ QString TableViewPlugin::version()
84
+ {
85
+ return m_Version;
86
+ }
87
+
88
+ QList<Core::PluginManager::Dependency> TableViewPlugin::dependencies()
89
+ {
90
+ return m_Dependencies;
91
+ }
92
+
93
+ QString TableViewPlugin::viewName()
94
+ {
95
+ return "Table View";
96
+ }
97
+
98
+ bool TableViewPlugin::viewHandles(QAbstractItemModel *model)
99
+ {
100
+ Q_UNUSED(model)
101
+
102
+ /* We can handle pretty much anything, so there's no checking needed */
103
+ return true;
104
+ }
105
+
106
+ QAbstractItemView *TableViewPlugin::viewWidget(QAbstractItemModel *model)
107
+ {
108
+ /* Check to see if we should even try to handle this model */
109
+ if(!viewHandles(model)) {
110
+ return NULL;
111
+ }
112
+
113
+ TableView *tableView = new TableView();
114
+ tableView->setModel(model);
115
+ return tableView;
116
+ }
117
+
118
+ } // namespace TableView
119
+ } // namespace Plugins
120
+
121
+ #if QT_VERSION < 0x050000
122
+ Q_EXPORT_PLUGIN(Plugins::TableView::TableViewPlugin)
123
+ #endif
pool/shard007/C++/0095225_tmwxPrintout.cpp ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ File: tmwxPrintout.cpp
3
+ Project: TreeMaker 5.x
4
+ Purpose: Source file for TreeMaker printout class
5
+ Author: Robert J. Lang
6
+ Modified by:
7
+ Created: 2004-06-21
8
+ Copyright: ©2004 Robert J. Lang. All Rights Reserved.
9
+ *******************************************************************************/
10
+
11
+ #include "tmwxPrintout.h"
12
+ #include "tmwxView.h"
13
+ #include "tmwxDesignCanvas.h"
14
+ #include "tmwxFoldedFormFrame.h"
15
+ #include "tmwxStr.h"
16
+ #include "tmModel.h"
17
+
18
+ /**********
19
+ class tmwxPrintout
20
+ **********/
21
+
22
+ /*****
23
+ Constructor
24
+ *****/
25
+ tmwxPrintout::tmwxPrintout(tmwxView* view, const wxString& title)
26
+ : wxDocPrintout(view, title), mDoc(view->GetDoc()), mView(view)
27
+ {
28
+ TMASSERT(mView);
29
+ TMASSERT(mDoc);
30
+ }
31
+
32
+
33
+ /*****
34
+ Called by the framework to obtain information about page range.
35
+ *****/
36
+ void tmwxPrintout::GetPageInfo(int* minPage, int* maxPage, int* selPageFrom,
37
+ int* selPageTo)
38
+ {
39
+ *minPage = 1;
40
+ *maxPage = gFoldedFormFrame->CanPrint() ? 2 : 1;
41
+ *selPageFrom = 1;
42
+ *selPageTo = 1;
43
+ }
44
+
45
+
46
+ /*****
47
+ Return true if the printout can provide the given page.
48
+ *****/
49
+ bool tmwxPrintout::HasPage(int pageNum)
50
+ {
51
+ if (pageNum == 1) return true;
52
+ if (pageNum == 2 && gFoldedFormFrame->CanPrint()) return true;
53
+ return false;
54
+ }
55
+
56
+
57
+ /*****
58
+ Print a single page of the document.
59
+ *****/
60
+ bool tmwxPrintout::OnPrintPage(int page)
61
+ {
62
+ switch(page) {
63
+ case 1: {
64
+ // Draw the canvas image on the DC to create the printed image, letting
65
+ // the canvas know to tweak its presentation for printing and scale it to
66
+ // fit the DC.
67
+ tmwxDesignCanvas* canvas = mView->GetDesignCanvas();
68
+ wxDC* dc = GetDC();
69
+ canvas->SetPrinting(true);
70
+ canvas->OnDraw(*dc);
71
+ canvas->SetPrinting(false);
72
+ return true;
73
+ }
74
+ case 2: {
75
+ // Draw the folded form, if it exists; otherwise return false.
76
+ tmwxFoldedFormFrame* theFrame = gFoldedFormFrame;
77
+ if (theFrame->CanPrint()) {
78
+ wxDC* dc = GetDC();
79
+ theFrame->SetPrinting(true);
80
+ theFrame->OnDraw(*dc);
81
+ theFrame->SetPrinting(false);
82
+ return true;
83
+ }
84
+ return false;
85
+ }
86
+ default:
87
+ return false;
88
+ }
89
+ }
pool/shard007/C++/0095227_wizardpage.cpp ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Cantata
3
+ *
4
+ * Copyright (c) 2011-2014 Craig Drummond <craig.p.drummond@gmail.com>
5
+ *
6
+ * ----
7
+ *
8
+ * This program is free software; you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation; either version 2 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
+ * General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program; see the file COPYING. If not, write to
20
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21
+ * Boston, MA 02110-1301, USA.
22
+ */
23
+
24
+ #include "wizardpage.h"
25
+ #include "support/icon.h"
26
+ #include "support/utils.h"
27
+ #include <QPainter>
28
+ #include <QStyle>
29
+
30
+ void WizardPage::setBackground(const Icon &i)
31
+ {
32
+ int size=fontMetrics().height()*10;
33
+ size=((int)(size/4))*4;
34
+ pix=i.pixmap(size, QIcon::Disabled);
35
+ if (pix.width()<size && pix.height()<size) {
36
+ pix=pix.scaled(QSize(size, size), Qt::KeepAspectRatio, Qt::SmoothTransformation);
37
+ }
38
+ }
39
+
40
+ void WizardPage::paintEvent(QPaintEvent *e)
41
+ {
42
+ int spacing=Utils::layoutSpacing(this);
43
+ spacing*=2;
44
+
45
+ QWizardPage::paintEvent(e);
46
+ QRect r(rect());
47
+ QPainter painter(this);
48
+
49
+ painter.setOpacity(0.2);
50
+ painter.drawPixmap(isRightToLeft() ? r.left() + spacing : r.right() - (pix.width() + spacing),
51
+ r.bottom() - (pix.height() + spacing), pix);
52
+ }
pool/shard007/C++/0095228_string.cpp ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include "string.h"
2
+ //#include "../memory/memory.h"
3
+
4
+ char* itoa(int val, int base){
5
+
6
+ static char buf[32] = {0};
7
+
8
+ int i = 30;
9
+
10
+ for(; val && i ; --i, val /= base)
11
+
12
+ buf[i] = "0123456789abcdef"[val % base];
13
+
14
+ return &buf[i+1];
15
+
16
+ }
17
+
18
+ String::String() {
19
+ this->str = "";
20
+ }
21
+
22
+ String::String(char c) {
23
+
24
+ this->str = (char*)c;
25
+ }
26
+
27
+ String::String(const char* str) {
28
+ this->str = str;
29
+ }
30
+
31
+ String::String(String& s) {
32
+ this->str = s.toCharArray();
33
+ }
34
+
35
+ String::String(bool b) {
36
+ if (b == true) {
37
+ this->str = "true";
38
+ } else if (b == false) {
39
+ this->str = "false";
40
+ } else {
41
+ this->str = "NULL";
42
+ }
43
+ }
44
+
45
+ String::String(int n) {
46
+ this->str = itoa(n, 10);
47
+ }
48
+
49
+ int String::getLength() {
50
+ size_t len = 0;
51
+ while (this->str[len])
52
+ len++;
53
+ return len;
54
+ }
55
+
56
+ bool String::equals(const char* compare) {
57
+ String me(compare);
58
+
59
+
60
+ return (*this == me);
61
+ }
62
+
63
+ bool String::equals(String& s) {
64
+ return (*this == s);
65
+ }
66
+
67
+
68
+ const char* String::toCharArray() {
69
+ return this->str;
70
+ }
71
+
72
+ char String::operator[] (int j)
73
+ {
74
+ if (j > this->getLength()) return 0;
75
+ return this->str[j];
76
+ }
77
+
78
+
79
+ bool String::operator== (String& lhs) {
80
+ if (lhs.getLength() != this->getLength()) return false;
81
+
82
+ unsigned cap = lhs.getLength();
83
+ unsigned int n = 0;
84
+ while ((n < cap) && (lhs.toCharArray()[n] == this->toCharArray()[n])) n++;
85
+ return (n == cap);
86
+ }
87
+
88
+ bool String::operator== (const char* str) {
89
+
90
+ String nigga(str);
91
+ return (*this == nigga);
92
+ }
93
+
94
+ String& String::operator+= (String& c) {
95
+
96
+ String ret;
97
+ int length = this->getLength();
98
+ int length2 = c.getLength();
99
+ int len = length+length2;
100
+ char str[len];
101
+
102
+ for (int j=0; j < length; j++)
103
+ str[j] = this->str[j];
104
+
105
+ for (int i=0; i < c.getLength(); i++)
106
+ str[length+i] = c[i];
107
+
108
+ length = len;
109
+ ret = str;
110
+ return ret;
111
+ }
pool/shard007/C++/0095231_line_following.cpp ADDED
@@ -0,0 +1,206 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include "line_following.hh"
2
+
3
+ //Follow line until junction reached
4
+ void lf_until_junction(void)
5
+ {
6
+ #ifdef __virtual__
7
+ cout << __PRETTY_FUNCTION__ << " was called\n";
8
+ delay(1000);
9
+ return;
10
+ #endif
11
+ char left_speed, right_speed;
12
+ while(1)//!(get_linesensors()==0b111))
13
+ {
14
+ get_linesensors();
15
+ switch(line_sensors[0])
16
+ {
17
+ case 0b000:
18
+ //All sensors off line
19
+ if(line_sensors[1]&0b100){
20
+ //cout << __func__ << ": Detected end of stub";
21
+ //set_motors(0, 0);
22
+ //return;
23
+ }
24
+ cout << __func__ << ": Lost line, calling lf_line_recovery()\n";
25
+ lf_line_recovery(ROT_SPEED);
26
+ break;
27
+
28
+ case 0b111: case 0b011:
29
+ //Both left and right high, must be at a junction
30
+ DEBUG("Junction detected");
31
+ //if((line_sensors[1]==0b111)&(line_sensors[0]==0b111))
32
+ return;
33
+ //delay(100);
34
+ break;
35
+
36
+ case 0b100:
37
+ //Only centre sensor high, everything is happy
38
+ left_speed = right_speed = SPEED;
39
+ break;
40
+ case 0b101: case 0b001:
41
+ //Left on line, right off - Boost right motor
42
+ left_speed=SPEED-CORRECTION;
43
+ right_speed=SPEED;
44
+ break;
45
+ case 0b110: case 0b010:
46
+ //Right on line, left off - Boost left motor
47
+ left_speed=SPEED;
48
+ right_speed=SPEED-CORRECTION;
49
+ break;
50
+ default:
51
+ cout << " lf_until_junction(): get_linesensors() returned something funny: " << line_sensors[0] << endl;
52
+ break;
53
+ }
54
+ set_motors(left_speed, right_speed);
55
+ }
56
+ set_motors(0, 0);
57
+ return;
58
+ }
59
+
60
+ //To be called only at a junction
61
+ void lf_turn(turning turn)
62
+ {
63
+ #ifdef __virtual__
64
+ cout << __PRETTY_FUNCTION__ << " was called with argument ";
65
+ print_turn(turn); cout << endl;
66
+ delay(1000);
67
+ return;
68
+ #endif
69
+
70
+ bool reverse = false;
71
+ unsigned int node = status.current_node;
72
+ directions dir = status.direction;
73
+ if((node==4)&&(dir==WEST))
74
+ reverse = true;
75
+ else if((node==11)&&(dir==SOUTH))
76
+ reverse = true;
77
+ else if((node==10)&&(dir==EAST))
78
+ reverse = true;
79
+ if((turn==FORWARD)|(turn==BACKWARD))
80
+ reverse=false;
81
+
82
+ if(reverse){
83
+ cout << "reverse to turn called\n";
84
+ reverse_to_line(turn);
85
+ return; //don't do another turn
86
+ }
87
+
88
+ switch(turn)
89
+ {
90
+ case LEFT:
91
+ DEBUG("Performing left turn");
92
+ unit_forwards();
93
+ set_motors(128+127, 127);
94
+ delay(800); //wait for the sensors to clear the line
95
+ set_motors(128+20, 20);
96
+ while(!(get_linesensors()&0b100)); //wait for the center sensor to hit the line
97
+ break;
98
+
99
+ case RIGHT:
100
+ DEBUG("Performing right turn");
101
+ unit_forwards();
102
+ set_motors(127, 128+127);
103
+ delay(800); //wait for the sensors to clear the line
104
+ set_motors(20, 128+20);
105
+ while(!(get_linesensors()&0b100)); //wait for the centre sensor to return to the line
106
+ break;
107
+
108
+ case FORWARD:
109
+ DEBUG("Going straight on");
110
+ set_motors(SPEED, SPEED);
111
+ delay(150); //just enough to advance past the junction
112
+ get_linesensors();
113
+ return;
114
+ break;
115
+
116
+ case BACKWARD:
117
+ DEBUG("Performing 180deg turn");
118
+ unit_forwards();
119
+ set_motors(127, 128+127);
120
+ delay(1800); //to find empirically - must go past a 90 deg line if there is one
121
+ set_motors(20, 128+20);
122
+ while(!(get_linesensors()&0b100));
123
+ break;
124
+
125
+ default:
126
+ cout << " lf_turn(): invalid turn asked for\n"; //Panic
127
+ //throw(INVALID_TURN);
128
+
129
+ }
130
+ set_motors(0,0);
131
+ return;
132
+ }
133
+
134
+
135
+ void lf_line_recovery(char rot_speed)
136
+ {
137
+ #ifdef __virtual__
138
+ cout << __PRETTY_FUNCTION__ << " was called with argument " << int(rot_speed) << endl;
139
+ delay(1000);
140
+ return;
141
+ #endif
142
+ //we've lost the line
143
+ //rotate on the spot toward where the line last was
144
+ set_motors(0, 0);
145
+ DEBUG("Attempting to recover line");
146
+ if(line_sensors[1]&0b001) //Left sensor before leaving was high
147
+ set_motors(128+rot_speed, rot_speed);
148
+
149
+ else if(line_sensors[1]&0b010) //Right sensor before leaving was high
150
+ set_motors(rot_speed, 128+rot_speed);
151
+
152
+ else
153
+ {
154
+ cout << " lf_line_recovery(): line_recovery() was called at an odd time\n";
155
+ cout << " lf_line_recovery(): neither right nor left sensor was high last cycle\n";
156
+ cout << " lf_line_recovery(): line_sensors[] are: " << line_sensors[0] << " " << line_sensors[1] << endl;
157
+
158
+ //throw(WRONG_LINE_RECOVERY);
159
+ return;
160
+ }
161
+
162
+ while(!(get_linesensors()&0b100)); //wait for centre line sensor to be high
163
+
164
+ set_motors(0, 0);
165
+ cout << __func__ << ": Success\n";
166
+ return;
167
+ }
168
+
169
+ void unit_forwards(void)
170
+ {
171
+ #ifdef __virtual__
172
+ cout << __PRETTY_FUNCTION__ << "was called\n";
173
+ delay(1000);
174
+ return;
175
+ #endif
176
+ DEBUG("Travelling a unit step forwards");
177
+ set_motors(60, 60);
178
+ delay(1400); //empirically found
179
+ set_motors(0, 0);
180
+ return;
181
+ }
182
+ //called in perform_action, taking a left/right turn to get onto line
183
+ void reverse_to_line(turning turn)
184
+ {
185
+ #ifdef __virtual__
186
+ cout << __PRETTY_FUNCTION__ << "was called with argument ";
187
+ print_turn(turn); cout << endl;
188
+ delay(1000);
189
+ return;
190
+ #endif
191
+ set_motors(128+50, 128+50);
192
+ delay(1000);
193
+ set_conveyor(0);
194
+ if(turn == RIGHT)
195
+ {
196
+ set_motors(60,128+60);
197
+ }
198
+ else
199
+ {
200
+ set_motors(128+60,60);
201
+ }
202
+ delay(1700);
203
+ set_motors(80, 80);
204
+ while(!(get_linesensors()&0b100));
205
+ set_motors(0,0);
206
+ }
pool/shard007/C++/0095232_abstractliveedittool.cpp ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /****************************************************************************
2
+ **
3
+ ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4
+ ** Contact: http://www.qt-project.org/legal
5
+ **
6
+ ** This file is part of Qt Creator.
7
+ **
8
+ ** Commercial License Usage
9
+ ** Licensees holding valid commercial Qt licenses may use this file in
10
+ ** accordance with the commercial license agreement provided with the
11
+ ** Software or, alternatively, in accordance with the terms contained in
12
+ ** a written agreement between you and Digia. For licensing terms and
13
+ ** conditions see http://qt.digia.com/licensing. For further information
14
+ ** use the contact form at http://qt.digia.com/contact-us.
15
+ **
16
+ ** GNU Lesser General Public License Usage
17
+ ** Alternatively, this file may be used under the terms of the GNU Lesser
18
+ ** General Public License version 2.1 as published by the Free Software
19
+ ** Foundation and appearing in the file LICENSE.LGPL included in the
20
+ ** packaging of this file. Please review the following information to
21
+ ** ensure the GNU Lesser General Public License version 2.1 requirements
22
+ ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23
+ **
24
+ ** In addition, as a special exception, Digia gives you certain additional
25
+ ** rights. These rights are described in the Digia Qt LGPL Exception
26
+ ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27
+ **
28
+ ****************************************************************************/
29
+
30
+ #include "abstractliveedittool.h"
31
+ #include "qdeclarativeviewinspector.h"
32
+ #include "../qdeclarativeviewinspector_p.h"
33
+
34
+ #include <QDeclarativeEngine>
35
+
36
+ #include <QDebug>
37
+ #include <QGraphicsItem>
38
+ #include <QDeclarativeItem>
39
+
40
+ namespace QmlJSDebugger {
41
+
42
+ AbstractLiveEditTool::AbstractLiveEditTool(QDeclarativeViewInspector *editorView)
43
+ : QObject(editorView), m_inspector(editorView)
44
+ {
45
+ }
46
+
47
+
48
+ AbstractLiveEditTool::~AbstractLiveEditTool()
49
+ {
50
+ }
51
+
52
+ QDeclarativeViewInspector *AbstractLiveEditTool::inspector() const
53
+ {
54
+ return m_inspector;
55
+ }
56
+
57
+ QDeclarativeView *AbstractLiveEditTool::view() const
58
+ {
59
+ return m_inspector->declarativeView();
60
+ }
61
+
62
+ QGraphicsScene* AbstractLiveEditTool::scene() const
63
+ {
64
+ return view()->scene();
65
+ }
66
+
67
+ void AbstractLiveEditTool::updateSelectedItems()
68
+ {
69
+ selectedItemsChanged(items());
70
+ }
71
+
72
+ QList<QGraphicsItem*> AbstractLiveEditTool::items() const
73
+ {
74
+ return inspector()->selectedItems();
75
+ }
76
+
77
+ bool AbstractLiveEditTool::topItemIsMovable(const QList<QGraphicsItem*> & itemList)
78
+ {
79
+ QGraphicsItem *firstSelectableItem = topMovableGraphicsItem(itemList);
80
+ if (firstSelectableItem == 0)
81
+ return false;
82
+ if (toQDeclarativeItem(firstSelectableItem) != 0)
83
+ return true;
84
+
85
+ return false;
86
+
87
+ }
88
+
89
+ bool AbstractLiveEditTool::topSelectedItemIsMovable(const QList<QGraphicsItem*> &itemList)
90
+ {
91
+ QList<QGraphicsItem*> selectedItems = inspector()->selectedItems();
92
+
93
+ foreach (QGraphicsItem *item, itemList) {
94
+ QDeclarativeItem *declarativeItem = toQDeclarativeItem(item);
95
+ if (declarativeItem
96
+ && selectedItems.contains(declarativeItem)
97
+ /*&& (declarativeItem->qmlItemNode().hasShowContent() || selectNonContentItems)*/)
98
+ return true;
99
+ }
100
+
101
+ return false;
102
+
103
+ }
104
+
105
+ bool AbstractLiveEditTool::topItemIsResizeHandle(const QList<QGraphicsItem*> &/*itemList*/)
106
+ {
107
+ return false;
108
+ }
109
+
110
+ QDeclarativeItem *AbstractLiveEditTool::toQDeclarativeItem(QGraphicsItem *item)
111
+ {
112
+ return qobject_cast<QDeclarativeItem*>(item->toGraphicsObject());
113
+ }
114
+
115
+ QGraphicsItem *AbstractLiveEditTool::topMovableGraphicsItem(const QList<QGraphicsItem*> &itemList)
116
+ {
117
+ foreach (QGraphicsItem *item, itemList) {
118
+ if (item->flags().testFlag(QGraphicsItem::ItemIsMovable))
119
+ return item;
120
+ }
121
+ return 0;
122
+ }
123
+
124
+ QDeclarativeItem *AbstractLiveEditTool::topMovableDeclarativeItem(const QList<QGraphicsItem*>
125
+ &itemList)
126
+ {
127
+ foreach (QGraphicsItem *item, itemList) {
128
+ QDeclarativeItem *declarativeItem = toQDeclarativeItem(item);
129
+ if (declarativeItem /*&& (declarativeItem->qmlItemNode().hasShowContent())*/)
130
+ return declarativeItem;
131
+ }
132
+
133
+ return 0;
134
+ }
135
+
136
+ QList<QGraphicsObject*> AbstractLiveEditTool::toGraphicsObjectList(const QList<QGraphicsItem*>
137
+ &itemList)
138
+ {
139
+ QList<QGraphicsObject*> gfxObjects;
140
+ foreach (QGraphicsItem *item, itemList) {
141
+ QGraphicsObject *obj = item->toGraphicsObject();
142
+ if (obj)
143
+ gfxObjects << obj;
144
+ }
145
+
146
+ return gfxObjects;
147
+ }
148
+
149
+ QString AbstractLiveEditTool::titleForItem(QGraphicsItem *item)
150
+ {
151
+ QString className("QGraphicsItem");
152
+ QString objectStringId;
153
+
154
+ QString constructedName;
155
+
156
+ QGraphicsObject *gfxObject = item->toGraphicsObject();
157
+ if (gfxObject) {
158
+ className = gfxObject->metaObject()->className();
159
+
160
+ className.remove(QRegExp("_QMLTYPE_\\d+"));
161
+ className.remove(QRegExp("_QML_\\d+"));
162
+ if (className.startsWith(QLatin1String("QDeclarative")))
163
+ className = className.remove(QLatin1String("QDeclarative"));
164
+
165
+ QDeclarativeItem *declarativeItem = qobject_cast<QDeclarativeItem*>(gfxObject);
166
+ if (declarativeItem) {
167
+ objectStringId = QDeclarativeViewInspector::idStringForObject(declarativeItem);
168
+ }
169
+
170
+ if (!objectStringId.isEmpty()) {
171
+ constructedName = objectStringId + " (" + className + QLatin1Char(')');
172
+ } else {
173
+ if (!gfxObject->objectName().isEmpty()) {
174
+ constructedName = gfxObject->objectName() + " (" + className + QLatin1Char(')');
175
+ } else {
176
+ constructedName = className;
177
+ }
178
+ }
179
+ }
180
+
181
+ return constructedName;
182
+ }
183
+
184
+
185
+ } // namespace QmlJSDebugger
pool/shard007/C++/0095235_Map.cpp ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <SFML/Graphics/RenderTarget.hpp>
2
+
3
+ #include "graphic/Map.hpp"
4
+
5
+ namespace graphic
6
+ {
7
+
8
+ Map::Map(const algo::Map& map) :
9
+ m_width(map.getWidth()),
10
+ m_height(map.getHeight()),
11
+ m_shapes(new sf::RectangleShape[m_width * m_height])
12
+ {
13
+ this->initRectangles(map);
14
+ this->initCircles(map);
15
+ }
16
+
17
+ Map::~Map()
18
+ {
19
+ delete[] m_shapes;
20
+ }
21
+
22
+
23
+ void
24
+ Map::initRectangles(const algo::Map& map)
25
+ {
26
+ unsigned int x, y;
27
+ sf::RectangleShape model;
28
+
29
+ model.setSize(sf::Vector2f(TILE_SIZE, TILE_SIZE));
30
+ model.setOutlineThickness(TILE_OUTLINE_THICKNESS);
31
+ model.setOutlineColor(TILE_OUTLINE_COLOR);
32
+
33
+ for (x = 0; x < m_width; x++)
34
+ {
35
+ for (y = 0; y < m_height; y++)
36
+ {
37
+ sf::RectangleShape& shape = m_shapes[y * m_width + x];
38
+ shape = model;
39
+ shape.setFillColor(map.at(x, y) == '0' ? WALL_COLOR : PATH_COLOR);
40
+ shape.setPosition(x * TILE_SIZE + TILE_OUTLINE_THICKNESS, y * TILE_SIZE + TILE_OUTLINE_THICKNESS);
41
+ }
42
+ }
43
+ }
44
+
45
+
46
+ void
47
+ Map::initCircles(const algo::Map& map)
48
+ {
49
+ sf::CircleShape model;
50
+
51
+ model.setRadius(POINT_RADIUS);
52
+ model.setOutlineThickness(POINT_OUTLINE_THICKNESS);
53
+ model.setOutlineColor(POINT_OUTLINE_COLOR);
54
+
55
+ m_begin = model;
56
+ m_begin.setFillColor(BEGIN_FILL_COLOR);
57
+ m_begin.move(map.getBegin().x * TILE_SIZE + POINT_SHIFT, map.getBegin().y * TILE_SIZE + POINT_SHIFT);
58
+
59
+ m_end = model;
60
+ m_end.setFillColor(END_FILL_COLOR);
61
+ m_end.move(map.getEnd().x * TILE_SIZE + POINT_SHIFT, map.getEnd().y * TILE_SIZE + POINT_SHIFT);
62
+ }
63
+
64
+
65
+ void
66
+ Map::draw(sf::RenderTarget& target, sf::RenderStates states) const
67
+ {
68
+ unsigned int i;
69
+
70
+ for (i = 0; i < m_width * m_height; i++)
71
+ {
72
+ target.draw(m_shapes[i], states);
73
+ }
74
+
75
+ target.draw(m_begin, states);
76
+ target.draw(m_end, states);
77
+ }
78
+
79
+ }
pool/shard007/C++/0095236_SysClass.cpp ADDED
@@ -0,0 +1,200 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ This file is part of WME Lite.
3
+ http://dead-code.org/redir.php?target=wmelite
4
+
5
+ Copyright (c) 2011 Jan Nedoma
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in
15
+ all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ THE SOFTWARE.
24
+ */
25
+
26
+ #include "persistent.h"
27
+ #include "SysInstance.h"
28
+ #include "SysClass.h"
29
+ #include "SysClassRegistry.h"
30
+ #include "BGame.h"
31
+ #include "BPersistMgr.h"
32
+
33
+ namespace WinterMute {
34
+
35
+ //////////////////////////////////////////////////////////////////////////
36
+ CSysClass::CSysClass(const AnsiString &name, PERSISTBUILD build, PERSISTLOAD load, bool persistent_class) {
37
+ m_Name = name;
38
+
39
+ m_Build = build;
40
+ m_Load = load;
41
+ m_Next = NULL;
42
+ m_SavedID = -1;
43
+ m_Persistent = persistent_class;
44
+ m_NumInst = 0;
45
+
46
+ CSysClassRegistry::GetInstance()->RegisterClass(this);
47
+ }
48
+
49
+
50
+ //////////////////////////////////////////////////////////////////////////
51
+ CSysClass::~CSysClass() {
52
+ CSysClassRegistry::GetInstance()->UnregisterClass(this);
53
+ RemoveAllInstances();
54
+ }
55
+
56
+ //////////////////////////////////////////////////////////////////////////
57
+ bool CSysClass::RemoveAllInstances() {
58
+ Instances::iterator it;
59
+ for (it = m_Instances.begin(); it != m_Instances.end(); ++it) {
60
+ delete(*it);
61
+ }
62
+ m_Instances.clear();
63
+ m_InstanceMap.clear();
64
+
65
+ return true;
66
+ }
67
+
68
+ //////////////////////////////////////////////////////////////////////////
69
+ CSysInstance *CSysClass::AddInstance(void *instance, int id, int savedId) {
70
+ CSysInstance *inst = new CSysInstance(instance, id, this);
71
+ inst->SetSavedID(savedId);
72
+ m_Instances.insert(inst);
73
+
74
+ m_InstanceMap[instance] = inst;
75
+
76
+ CSysClassRegistry::GetInstance()->AddInstanceToTable(inst, instance);
77
+
78
+ return inst;
79
+ }
80
+
81
+
82
+ //////////////////////////////////////////////////////////////////////////
83
+ bool CSysClass::RemoveInstance(void *instance) {
84
+ InstanceMap::iterator mapIt = m_InstanceMap.find(instance);
85
+ if (mapIt == m_InstanceMap.end()) return false;
86
+
87
+ Instances::iterator it = m_Instances.find((*mapIt).second);
88
+ if (it != m_Instances.end()) {
89
+ delete(*it);
90
+ m_Instances.erase(it);
91
+ }
92
+
93
+ m_InstanceMap.erase(mapIt);
94
+
95
+ return false;
96
+ }
97
+
98
+ //////////////////////////////////////////////////////////////////////////
99
+ int CSysClass::GetInstanceID(void *pointer) {
100
+ InstanceMap::iterator mapIt = m_InstanceMap.find(pointer);
101
+ if (mapIt == m_InstanceMap.end()) return -1;
102
+ else return (*mapIt).second->GetID();
103
+ }
104
+
105
+ //////////////////////////////////////////////////////////////////////////
106
+ void *CSysClass::IDToPointer(int savedID) {
107
+ //slow
108
+ Instances::iterator it;
109
+ for (it = m_Instances.begin(); it != m_Instances.end(); ++it) {
110
+ if ((*it)->GetSavedID() == savedID) return (*it)->GetInstance();
111
+ }
112
+ return NULL;
113
+ }
114
+
115
+ //////////////////////////////////////////////////////////////////////////
116
+ int CSysClass::GetNumInstances() {
117
+ return m_Instances.size();
118
+ }
119
+
120
+ //////////////////////////////////////////////////////////////////////////
121
+ void CSysClass::Dump(FILE *stream) {
122
+ fprintf(stream, "%03d %c %-20s instances: %d\n", m_ID, m_Persistent ? 'p' : ' ', m_Name.c_str(), GetNumInstances());
123
+ }
124
+
125
+ //////////////////////////////////////////////////////////////////////////
126
+ void CSysClass::SaveTable(CBGame *Game, CBPersistMgr *PersistMgr) {
127
+ PersistMgr->PutString(m_Name.c_str());
128
+ PersistMgr->PutDWORD(m_ID);
129
+ PersistMgr->PutDWORD(m_Instances.size());
130
+
131
+ Instances::iterator it;
132
+ for (it = m_Instances.begin(); it != m_Instances.end(); ++it) {
133
+ PersistMgr->PutDWORD((*it)->GetID());
134
+ }
135
+ }
136
+
137
+ //////////////////////////////////////////////////////////////////////////
138
+ void CSysClass::LoadTable(CBGame *Game, CBPersistMgr *PersistMgr) {
139
+ m_SavedID = PersistMgr->GetDWORD();
140
+ int numInstances = PersistMgr->GetDWORD();
141
+
142
+ for (int i = 0; i < numInstances; i++) {
143
+ if (m_Persistent) {
144
+ int instId = PersistMgr->GetDWORD();
145
+
146
+ if (i > 0) {
147
+ Game->LOG(0, "Warning: attempting to load multiple instances of persistent class %s (%d)", m_Name.c_str(), numInstances);
148
+ continue;
149
+ }
150
+
151
+ Instances::iterator it = m_Instances.begin();
152
+ if (it != m_Instances.end()) {
153
+ (*it)->SetSavedID(instId);
154
+ CSysClassRegistry::GetInstance()->AddInstanceToTable((*it), (*it)->GetInstance());
155
+ } else Game->LOG(0, "Warning: instance %d of persistent class %s not found", i, m_Name.c_str());
156
+ }
157
+ // normal instances, create empty objects
158
+ else {
159
+ void *emptyObject = m_Build();
160
+ AddInstance(emptyObject, CSysClassRegistry::GetInstance()->GetNextID(), PersistMgr->GetDWORD());
161
+ }
162
+
163
+ }
164
+ }
165
+
166
+ //////////////////////////////////////////////////////////////////////////
167
+ void CSysClass::SaveInstances(CBGame *Game, CBPersistMgr *PersistMgr) {
168
+ Instances::iterator it;
169
+ for (it = m_Instances.begin(); it != m_Instances.end(); ++it) {
170
+ // write instace header
171
+ PersistMgr->PutDWORD(m_ID);
172
+ PersistMgr->PutDWORD((*it)->GetID());
173
+
174
+ m_Load((*it)->GetInstance(), PersistMgr);
175
+ }
176
+ }
177
+
178
+ //////////////////////////////////////////////////////////////////////////
179
+ void CSysClass::LoadInstance(void *instance, CBPersistMgr *PersistMgr) {
180
+ m_Load(instance, PersistMgr);
181
+ }
182
+
183
+
184
+ //////////////////////////////////////////////////////////////////////////
185
+ void CSysClass::ResetSavedIDs() {
186
+ Instances::iterator it;
187
+ for (it = m_Instances.begin(); it != m_Instances.end(); ++it) {
188
+ (*it)->SetSavedID(-1);
189
+ }
190
+ }
191
+
192
+ //////////////////////////////////////////////////////////////////////////
193
+ void CSysClass::InstanceCallback(SYS_INSTANCE_CALLBACK lpCallback, void *lpData) {
194
+ Instances::iterator it;
195
+ for (it = m_Instances.begin(); it != m_Instances.end(); ++it) {
196
+ lpCallback((*it)->GetInstance(), lpData);
197
+ }
198
+ }
199
+
200
+ } // end of namespace WinterMute
pool/shard007/C++/0095238_background_application_loader.cc ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2014 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ #include "mojo/runner/android/background_application_loader.h"
6
+
7
+ #include <utility>
8
+
9
+ #include "base/bind.h"
10
+ #include "base/run_loop.h"
11
+ #include "mojo/shell/application_manager.h"
12
+
13
+ namespace mojo {
14
+ namespace runner {
15
+
16
+ BackgroundApplicationLoader::BackgroundApplicationLoader(
17
+ scoped_ptr<ApplicationLoader> real_loader,
18
+ const std::string& thread_name,
19
+ base::MessageLoop::Type message_loop_type)
20
+ : loader_(std::move(real_loader)),
21
+ message_loop_type_(message_loop_type),
22
+ thread_name_(thread_name),
23
+ message_loop_created_(true, false) {}
24
+
25
+ BackgroundApplicationLoader::~BackgroundApplicationLoader() {
26
+ if (thread_)
27
+ thread_->Join();
28
+ }
29
+
30
+ void BackgroundApplicationLoader::Load(
31
+ const GURL& url,
32
+ InterfaceRequest<Application> application_request) {
33
+ DCHECK(application_request.is_pending());
34
+ if (!thread_) {
35
+ // TODO(tim): It'd be nice if we could just have each Load call
36
+ // result in a new thread like DynamicService{Loader, Runner}. But some
37
+ // loaders are creating multiple ApplicationImpls (NetworkApplicationLoader)
38
+ // sharing a delegate (etc). So we have to keep it single threaded, wait
39
+ // for the thread to initialize, and post to the TaskRunner for subsequent
40
+ // Load calls for now.
41
+ thread_.reset(new base::DelegateSimpleThread(this, thread_name_));
42
+ thread_->Start();
43
+ message_loop_created_.Wait();
44
+ DCHECK(task_runner_.get());
45
+ }
46
+
47
+ task_runner_->PostTask(
48
+ FROM_HERE,
49
+ base::Bind(&BackgroundApplicationLoader::LoadOnBackgroundThread,
50
+ base::Unretained(this), url,
51
+ base::Passed(&application_request)));
52
+ }
53
+
54
+ void BackgroundApplicationLoader::Run() {
55
+ base::MessageLoop message_loop(message_loop_type_);
56
+ base::RunLoop loop;
57
+ task_runner_ = message_loop.task_runner();
58
+ quit_closure_ = loop.QuitClosure();
59
+ message_loop_created_.Signal();
60
+ loop.Run();
61
+
62
+ // Destroy |loader_| on the thread it's actually used on.
63
+ loader_.reset();
64
+ }
65
+
66
+ void BackgroundApplicationLoader::LoadOnBackgroundThread(
67
+ const GURL& url,
68
+ InterfaceRequest<Application> application_request) {
69
+ DCHECK(task_runner_->RunsTasksOnCurrentThread());
70
+ loader_->Load(url, std::move(application_request));
71
+ }
72
+
73
+ } // namespace runner
74
+ } // namespace mojo
pool/shard007/C++/0095240_main.cpp ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <QApplication>
2
+ #include <QFile>
3
+ #include <QDir>
4
+ #include <QJsonDocument>
5
+ #include <QJsonObject>
6
+ #include <QJsonArray>
7
+ #include <QtDebug>
8
+ #include <QMessageBox>
9
+ #include "MainWindow.h"
10
+ #include "Session.h"
11
+ #include "ContactBook.h"
12
+ #include "Device.h"
13
+ #include "ExampleDevice.h"
14
+ #include "DeviceVcfFile.h"
15
+ #include "Exceptions.h"
16
+
17
+
18
+
19
+
20
+
21
+ /** Creates a new session and fills it with example data. */
22
+ std::unique_ptr<Session> makeExampleSession()
23
+ {
24
+ std::unique_ptr<Session> session(new Session);
25
+ session->addDevice(std::unique_ptr<Device>(new ExampleDevice));
26
+
27
+ // Test: add a device based on a VCF file
28
+ QJsonObject cfg;
29
+ cfg["type"] = QString::fromUtf8("VcfFile");
30
+ cfg["fileName"] = QString::fromUtf8("Contacts.vcf");
31
+ session->addDevice(Device::createFromConfig(cfg));
32
+
33
+ return session;
34
+ }
35
+
36
+
37
+
38
+
39
+
40
+ /** Loads the session, either from the current folder ("portable app") or from the user's home.
41
+ If neither contain any reasonable data, creates an empty data file. */
42
+ std::unique_ptr<Session> loadSession()
43
+ {
44
+ // First try loading from the current folder ("portable app"):
45
+ auto session = Session::loadFromFile("ContactBookSanitizer.cbsSession");
46
+ if (session != nullptr)
47
+ {
48
+ return session;
49
+ }
50
+
51
+ // No current folder data, load from user's home:
52
+ auto homePath = QDir::homePath() + "/";
53
+ session = Session::loadFromFile(homePath + "ContactBookSanitizer.cbsSession");
54
+ if (session != nullptr)
55
+ {
56
+ return session;
57
+ }
58
+
59
+ // No data could be read, create a new example session file
60
+ qDebug() << "No session could be loaded. Creating a new session with example data.";
61
+ session = makeExampleSession();
62
+
63
+ // First try writing session to the current folder; if it fails, we're installed, if it succeeds, we're portable
64
+ try
65
+ {
66
+ session->saveToFile("ContactBookSanitizer.cbsSession");
67
+ qDebug() << "Detected a portable installation, session will be stored in current folder.";
68
+ return session;
69
+ }
70
+ catch (const EFileError & exc)
71
+ {
72
+ qDebug()
73
+ << "Failed to write the session file to current folder: " << exc.m_Message
74
+ << "; this usually means we're running in installed mode. Will retry the home path.";
75
+ }
76
+
77
+ // We're installed, save to local home:
78
+ try
79
+ {
80
+ session->saveToFile(homePath + "ContactBookSanitizer.cbsSession");
81
+ qDebug() << "Detected an installed environment, session will be stored in home path: " << homePath;
82
+ return session;
83
+ }
84
+ catch (const EFileError & exc)
85
+ {
86
+ QString msg("Failed to write the session file to both current folder and the home path: %1; session data will be lost after you close the app.");
87
+ msg.arg(exc.m_Message);
88
+ qWarning() << msg;
89
+ QMessageBox::warning(nullptr, QString::fromUtf8("ContactBookSanitizer"), msg);
90
+ }
91
+ return session;
92
+ }
93
+
94
+
95
+
96
+
97
+
98
+ int main(int argc, char *argv[])
99
+ {
100
+ QApplication a(argc, argv);
101
+ MainWindow w(loadSession());
102
+ w.show();
103
+
104
+ return a.exec();
105
+ }
pool/shard007/C++/0095242_extension_uninstall_dialog_view.cc ADDED
@@ -0,0 +1,247 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 "base/basictypes.h"
6
+ #include "base/compiler_specific.h"
7
+ #include "base/string_util.h"
8
+ #include "base/utf_string_conversions.h"
9
+ #include "chrome/browser/extensions/extension_uninstall_dialog.h"
10
+ #include "chrome/browser/profiles/profile.h"
11
+ #include "chrome/browser/ui/browser_list.h"
12
+ #include "chrome/browser/ui/browser_window.h"
13
+ #include "chrome/common/extensions/extension.h"
14
+ #include "grit/generated_resources.h"
15
+ #include "ui/base/l10n/l10n_util.h"
16
+ #include "ui/gfx/compositor/compositor.h"
17
+ #include "ui/gfx/compositor/layer.h"
18
+ #include "ui/views/controls/image_view.h"
19
+ #include "ui/views/controls/label.h"
20
+ #include "ui/views/layout/layout_constants.h"
21
+ #include "ui/views/view.h"
22
+ #include "ui/views/widget/widget.h"
23
+ #include "ui/views/window/dialog_delegate.h"
24
+
25
+ #if defined(USE_ASH)
26
+ #include "ash/shell.h"
27
+ #endif
28
+
29
+ namespace {
30
+
31
+ const int kRightColumnWidth = 210;
32
+ const int kIconSize = 69;
33
+
34
+ class ExtensionUninstallDialogDelegateView;
35
+
36
+ // Returns parent window for extension uninstall dialog.
37
+ // For ash, use app list window if it is visible.
38
+ // For other platforms or when app list is not visible on ash,
39
+ // use browser window of given |profile|.
40
+ // Note this function could return NULL if ash app list is not visible and
41
+ // there is no browser window open for |profile|.
42
+ gfx::NativeWindow GetParent(Profile* profile) {
43
+ #if defined(USE_ASH)
44
+ gfx::NativeWindow app_list = ash::Shell::GetInstance()->GetAppListWindow();
45
+ if (app_list)
46
+ return app_list;
47
+ #endif
48
+
49
+ Browser* browser = BrowserList::GetLastActiveWithProfile(profile);
50
+ if (browser && browser->window())
51
+ return browser->window()->GetNativeHandle();
52
+
53
+ return NULL;
54
+ }
55
+
56
+ // Views implementation of the uninstall dialog.
57
+ class ExtensionUninstallDialogViews : public ExtensionUninstallDialog {
58
+ public:
59
+ ExtensionUninstallDialogViews(Profile* profile,
60
+ ExtensionUninstallDialog::Delegate* delegate);
61
+ virtual ~ExtensionUninstallDialogViews();
62
+
63
+ // Forwards the accept and cancels to the delegate.
64
+ void ExtensionUninstallAccepted();
65
+ void ExtensionUninstallCanceled();
66
+
67
+ ExtensionUninstallDialogDelegateView* view() { return view_; }
68
+
69
+ private:
70
+ void Show() OVERRIDE;
71
+
72
+ ExtensionUninstallDialogDelegateView* view_;
73
+
74
+ DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogViews);
75
+ };
76
+
77
+ // The dialog's view, owned by the views framework.
78
+ class ExtensionUninstallDialogDelegateView : public views::DialogDelegateView {
79
+ public:
80
+ ExtensionUninstallDialogDelegateView(
81
+ ExtensionUninstallDialogViews* dialog_view,
82
+ const Extension* extension,
83
+ SkBitmap* icon);
84
+ virtual ~ExtensionUninstallDialogDelegateView();
85
+
86
+ // Called when the ExtensionUninstallDialog has been destroyed to make sure
87
+ // we invalidate pointers.
88
+ void DialogDestroyed() { dialog_ = NULL; }
89
+
90
+ private:
91
+ // views::DialogDelegate:
92
+ virtual string16 GetDialogButtonLabel(ui::DialogButton button) const OVERRIDE;
93
+ virtual int GetDefaultDialogButton() const OVERRIDE {
94
+ return ui::DIALOG_BUTTON_CANCEL;
95
+ }
96
+ virtual bool Accept() OVERRIDE;
97
+ virtual bool Cancel() OVERRIDE;
98
+
99
+ // views::WidgetDelegate:
100
+ virtual ui::ModalType GetModalType() const OVERRIDE {
101
+ return ui::MODAL_TYPE_WINDOW;
102
+ }
103
+ virtual views::View* GetContentsView() OVERRIDE { return this; }
104
+ virtual string16 GetWindowTitle() const OVERRIDE;
105
+
106
+ // views::View:
107
+ virtual gfx::Size GetPreferredSize() OVERRIDE;
108
+
109
+ virtual void Layout() OVERRIDE;
110
+
111
+ ExtensionUninstallDialogViews* dialog_;
112
+
113
+ views::ImageView* icon_;
114
+ views::Label* heading_;
115
+
116
+ DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogDelegateView);
117
+ };
118
+
119
+ ExtensionUninstallDialogViews::ExtensionUninstallDialogViews(
120
+ Profile* profile, ExtensionUninstallDialog::Delegate* delegate)
121
+ : ExtensionUninstallDialog(profile, delegate),
122
+ view_(NULL) {
123
+ }
124
+
125
+ ExtensionUninstallDialogViews::~ExtensionUninstallDialogViews() {
126
+ // Close the widget (the views framework will delete view_).
127
+ if (view_) {
128
+ view_->DialogDestroyed();
129
+ view_->GetWidget()->CloseNow();
130
+ }
131
+ }
132
+
133
+ void ExtensionUninstallDialogViews::Show() {
134
+ gfx::NativeWindow parent = GetParent(profile_);
135
+ if (!parent) {
136
+ delegate_->ExtensionUninstallCanceled();
137
+ return;
138
+ }
139
+
140
+ view_ = new ExtensionUninstallDialogDelegateView(this, extension_, &icon_);
141
+ views::Widget::CreateWindowWithParent(view_, parent)->Show();
142
+ }
143
+
144
+ void ExtensionUninstallDialogViews::ExtensionUninstallAccepted() {
145
+ // The widget gets destroyed when the dialog is accepted.
146
+ view_ = NULL;
147
+ delegate_->ExtensionUninstallAccepted();
148
+ }
149
+
150
+ void ExtensionUninstallDialogViews::ExtensionUninstallCanceled() {
151
+ // The widget gets destroyed when the dialog is canceled.
152
+ view_ = NULL;
153
+ delegate_->ExtensionUninstallCanceled();
154
+ }
155
+
156
+ ExtensionUninstallDialogDelegateView::ExtensionUninstallDialogDelegateView(
157
+ ExtensionUninstallDialogViews* dialog_view,
158
+ const Extension* extension,
159
+ SkBitmap* icon)
160
+ : dialog_(dialog_view) {
161
+ // Scale down to icon size, but allow smaller icons (don't scale up).
162
+ gfx::Size size(icon->width(), icon->height());
163
+ if (size.width() > kIconSize || size.height() > kIconSize)
164
+ size = gfx::Size(kIconSize, kIconSize);
165
+ icon_ = new views::ImageView();
166
+ icon_->SetImageSize(size);
167
+ icon_->SetImage(*icon);
168
+ AddChildView(icon_);
169
+
170
+ heading_ = new views::Label(
171
+ l10n_util::GetStringFUTF16(IDS_EXTENSION_UNINSTALL_PROMPT_HEADING,
172
+ UTF8ToUTF16(extension->name())));
173
+ heading_->SetMultiLine(true);
174
+ AddChildView(heading_);
175
+ }
176
+
177
+ ExtensionUninstallDialogDelegateView::~ExtensionUninstallDialogDelegateView() {
178
+ }
179
+
180
+ string16 ExtensionUninstallDialogDelegateView::GetDialogButtonLabel(
181
+ ui::DialogButton button) const {
182
+ return l10n_util::GetStringUTF16((button == ui::DIALOG_BUTTON_OK) ?
183
+ IDS_EXTENSION_PROMPT_UNINSTALL_BUTTON : IDS_CANCEL);
184
+ }
185
+
186
+ bool ExtensionUninstallDialogDelegateView::Accept() {
187
+ if (dialog_)
188
+ dialog_->ExtensionUninstallAccepted();
189
+ return true;
190
+ }
191
+
192
+ bool ExtensionUninstallDialogDelegateView::Cancel() {
193
+ if (dialog_)
194
+ dialog_->ExtensionUninstallCanceled();
195
+ return true;
196
+ }
197
+
198
+ string16 ExtensionUninstallDialogDelegateView::GetWindowTitle() const {
199
+ return l10n_util::GetStringUTF16(IDS_EXTENSION_UNINSTALL_PROMPT_TITLE);
200
+ }
201
+
202
+
203
+ gfx::Size ExtensionUninstallDialogDelegateView::GetPreferredSize() {
204
+ int width = kRightColumnWidth;
205
+ width += kIconSize;
206
+ width += views::kPanelHorizMargin * 3;
207
+
208
+ int height = views::kPanelVertMargin * 2;
209
+ height += heading_->GetHeightForWidth(kRightColumnWidth);
210
+
211
+ return gfx::Size(width,
212
+ std::max(height, kIconSize + views::kPanelVertMargin * 2));
213
+ }
214
+
215
+ void ExtensionUninstallDialogDelegateView::Layout() {
216
+ int x = views::kPanelHorizMargin;
217
+ int y = views::kPanelVertMargin;
218
+
219
+ heading_->SizeToFit(kRightColumnWidth);
220
+
221
+ if (heading_->height() <= kIconSize) {
222
+ icon_->SetBounds(x, y, kIconSize, kIconSize);
223
+ x += kIconSize;
224
+ x += views::kPanelHorizMargin;
225
+
226
+ heading_->SetX(x);
227
+ heading_->SetY(y + (kIconSize - heading_->height()) / 2);
228
+ } else {
229
+ icon_->SetBounds(x,
230
+ y + (heading_->height() - kIconSize) / 2,
231
+ kIconSize,
232
+ kIconSize);
233
+ x += kIconSize;
234
+ x += views::kPanelHorizMargin;
235
+
236
+ heading_->SetX(x);
237
+ heading_->SetY(y);
238
+ }
239
+ }
240
+
241
+ } // namespace
242
+
243
+ // static
244
+ ExtensionUninstallDialog* ExtensionUninstallDialog::Create(
245
+ Profile* profile, Delegate* delegate) {
246
+ return new ExtensionUninstallDialogViews(profile, delegate);
247
+ }
pool/shard007/C++/0095243_memory.cpp ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* ----------------------------------------------------------------------
2
+ LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
3
+ http://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
+ #include <cstdio>
15
+ #include <cstdlib>
16
+ #include <cstring>
17
+ #include "memory.h"
18
+ #include "error.h"
19
+
20
+ #if defined(LMP_USER_INTEL) && defined(__INTEL_COMPILER)
21
+ #ifndef LMP_INTEL_NO_TBB
22
+ #define LMP_USE_TBB_ALLOCATOR
23
+ #include "tbb/scalable_allocator.h"
24
+ #else
25
+ #include <malloc.h>
26
+ #endif
27
+ #endif
28
+
29
+ #if defined(LMP_USER_INTEL) && !defined(LAMMPS_MEMALIGN)
30
+ #define LAMMPS_MEMALIGN 64
31
+ #endif
32
+
33
+ using namespace LAMMPS_NS;
34
+
35
+ /* ---------------------------------------------------------------------- */
36
+
37
+ Memory::Memory(LAMMPS *lmp) : Pointers(lmp) {}
38
+
39
+ /* ----------------------------------------------------------------------
40
+ safe malloc
41
+ ------------------------------------------------------------------------- */
42
+
43
+ void *Memory::smalloc(bigint nbytes, const char *name)
44
+ {
45
+ if (nbytes == 0) return NULL;
46
+
47
+ #if defined(LAMMPS_MEMALIGN)
48
+ void *ptr;
49
+
50
+ #if defined(LMP_USE_TBB_ALLOCATOR)
51
+ ptr = scalable_aligned_malloc(nbytes, LAMMPS_MEMALIGN);
52
+ #else
53
+ int retval = posix_memalign(&ptr, LAMMPS_MEMALIGN, nbytes);
54
+ if (retval) ptr = NULL;
55
+ #endif
56
+
57
+ #else
58
+ void *ptr = malloc(nbytes);
59
+ #endif
60
+ if (ptr == NULL) {
61
+ char str[128];
62
+ sprintf(str,"Failed to allocate " BIGINT_FORMAT " bytes for array %s",
63
+ nbytes,name);
64
+ error->one(FLERR,str);
65
+ }
66
+ return ptr;
67
+ }
68
+
69
+ /* ----------------------------------------------------------------------
70
+ safe realloc
71
+ ------------------------------------------------------------------------- */
72
+
73
+ void *Memory::srealloc(void *ptr, bigint nbytes, const char *name)
74
+ {
75
+ if (nbytes == 0) {
76
+ destroy(ptr);
77
+ return NULL;
78
+ }
79
+
80
+ #if defined(LMP_USE_TBB_ALLOCATOR)
81
+ ptr = scalable_aligned_realloc(ptr, nbytes, LAMMPS_MEMALIGN);
82
+ #elif defined(LMP_INTEL_NO_TBB) && defined(LAMMPS_MEMALIGN) && \
83
+ defined(__INTEL_COMPILER)
84
+
85
+ ptr = realloc(ptr, nbytes);
86
+ uintptr_t offset = ((uintptr_t)(const void *)(ptr)) % LAMMPS_MEMALIGN;
87
+ if (offset) {
88
+ void *optr = ptr;
89
+ ptr = smalloc(nbytes, name);
90
+ memcpy(ptr, optr, MIN(nbytes,malloc_usable_size(optr)));
91
+ free(optr);
92
+ }
93
+ #else
94
+ ptr = realloc(ptr,nbytes);
95
+ #endif
96
+ if (ptr == NULL) {
97
+ char str[128];
98
+ sprintf(str,"Failed to reallocate " BIGINT_FORMAT " bytes for array %s",
99
+ nbytes,name);
100
+ error->one(FLERR,str);
101
+ }
102
+ return ptr;
103
+ }
104
+
105
+ /* ----------------------------------------------------------------------
106
+ safe free
107
+ ------------------------------------------------------------------------- */
108
+
109
+ void Memory::sfree(void *ptr)
110
+ {
111
+ if (ptr == NULL) return;
112
+ #if defined(LMP_USE_TBB_ALLOCATOR)
113
+ scalable_aligned_free(ptr);
114
+ #else
115
+ free(ptr);
116
+ #endif
117
+ }
118
+
119
+ /* ----------------------------------------------------------------------
120
+ erroneous usage of templated create/grow functions
121
+ ------------------------------------------------------------------------- */
122
+
123
+ void Memory::fail(const char *name)
124
+ {
125
+ char str[128];
126
+ snprintf(str,128,
127
+ "Cannot create/grow a vector/array of pointers for %s",name);
128
+ error->one(FLERR,str);
129
+ }
pool/shard007/C++/0095244_cmakeeditorfactory.cpp ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**************************************************************************
2
+ **
3
+ ** This file is part of Qt Creator
4
+ **
5
+ ** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
6
+ **
7
+ ** Contact: Nokia Corporation (qt-info@nokia.com)
8
+ **
9
+ ** Commercial Usage
10
+ **
11
+ ** Licensees holding valid Qt Commercial licenses may use this file in
12
+ ** accordance with the Qt Commercial License Agreement provided with the
13
+ ** Software or, alternatively, in accordance with the terms contained in
14
+ ** a written agreement between you and Nokia.
15
+ **
16
+ ** GNU Lesser General Public License Usage
17
+ **
18
+ ** Alternatively, this file may be used under the terms of the GNU Lesser
19
+ ** General Public License version 2.1 as published by the Free Software
20
+ ** Foundation and appearing in the file LICENSE.LGPL included in the
21
+ ** packaging of this file. Please review the following information to
22
+ ** ensure the GNU Lesser General Public License version 2.1 requirements
23
+ ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24
+ **
25
+ ** If you are unsure which license is appropriate for your use, please
26
+ ** contact the sales department at http://qt.nokia.com/contact.
27
+ **
28
+ **************************************************************************/
29
+
30
+ #include "cmakeeditorfactory.h"
31
+ #include "cmakeprojectconstants.h"
32
+ #include "cmakeeditor.h"
33
+
34
+ #include <coreplugin/editormanager/editormanager.h>
35
+ #include <texteditor/texteditorsettings.h>
36
+
37
+ using namespace CMakeProjectManager;
38
+ using namespace CMakeProjectManager::Internal;
39
+
40
+ CMakeEditorFactory::CMakeEditorFactory(CMakeManager *manager, TextEditor::TextEditorActionHandler *handler)
41
+ : m_mimeTypes(QStringList() << QLatin1String(CMakeProjectManager::Constants::CMAKEMIMETYPE)),
42
+ m_manager(manager),
43
+ m_actionHandler(handler)
44
+ {
45
+
46
+ }
47
+
48
+ CMakeEditorFactory::~CMakeEditorFactory()
49
+ {
50
+ }
51
+
52
+ QString CMakeEditorFactory::id() const
53
+ {
54
+ return QLatin1String(CMakeProjectManager::Constants::CMAKE_EDITOR_ID);
55
+ }
56
+
57
+ QString CMakeEditorFactory::displayName() const
58
+ {
59
+ return tr(CMakeProjectManager::Constants::CMAKE_EDITOR_DISPLAY_NAME);
60
+ }
61
+
62
+ Core::IFile *CMakeEditorFactory::open(const QString &fileName)
63
+ {
64
+ Core::IEditor *iface = Core::EditorManager::instance()->openEditor(fileName, id());
65
+ return iface ? iface->file() : 0;
66
+ }
67
+
68
+ Core::IEditor *CMakeEditorFactory::createEditor(QWidget *parent)
69
+ {
70
+ CMakeEditor *rc = new CMakeEditor(parent, this, m_actionHandler);
71
+ TextEditor::TextEditorSettings::instance()->initializeEditor(rc);
72
+ return rc->editableInterface();
73
+ }
74
+
75
+ QStringList CMakeEditorFactory::mimeTypes() const
76
+ {
77
+ return m_mimeTypes;
78
+ }
pool/shard007/C++/0095245_bundle.cpp ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ *** Pointer Bundle
3
+ *** src/model/bundle.cpp
4
+ Copyright T. Youngs 2007-2016
5
+
6
+ This file is part of Aten.
7
+
8
+ Aten is free software: you can redistribute it and/or modify
9
+ it under the terms of the GNU General Public License as published by
10
+ the Free Software Foundation, either version 3 of the License, or
11
+ (at your option) any later version.
12
+
13
+ Aten is distributed in the hope that it will be useful,
14
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ GNU General Public License for more details.
17
+
18
+ You should have received a copy of the GNU General Public License
19
+ along with Aten. If not, see <http://www.gnu.org/licenses/>.
20
+ */
21
+
22
+ #include "model/bundle.h"
23
+ #include "model/model.h"
24
+ #include "math/constants.h"
25
+ #include <stdio.h>
26
+
27
+ ATEN_USING_NAMESPACE
28
+
29
+ // Constructor
30
+ Bundle::Bundle()
31
+ {
32
+ clear();
33
+ }
34
+
35
+ Bundle::Bundle(Forcefield* ptr)
36
+ {
37
+ clear();
38
+ ff = ptr;
39
+ }
40
+
41
+ Bundle::Bundle(Model* ptr)
42
+ {
43
+ clear();
44
+ m = ptr;
45
+ }
46
+
47
+ Bundle::Bundle(Pattern* ptr)
48
+ {
49
+ clear();
50
+ p = ptr;
51
+ }
52
+
53
+ Bundle::Bundle(Atom* ptr)
54
+ {
55
+ clear();
56
+ i = ptr;
57
+ }
58
+
59
+ Bundle::Bundle(Grid* ptr)
60
+ {
61
+ clear();
62
+ g = ptr;
63
+ }
64
+
65
+ Bundle::Bundle(Glyph* ptr)
66
+ {
67
+ clear();
68
+ gl = ptr;
69
+ }
70
+
71
+ // Return reendersource for stored model
72
+ Model* Bundle::rs()
73
+ {
74
+ return (m == NULL ? NULL : m->renderSourceModel());
75
+ }
76
+
77
+ // Clear pointers
78
+ void Bundle::clear()
79
+ {
80
+ m = 0;
81
+ s = 0;
82
+ ff = 0;
83
+ g = 0;
84
+ i = 0;
85
+ p = 0;
86
+ gl = 0;
87
+ }
88
+
89
+ // Check for non-null pointers
90
+ bool Bundle::isNull(int ptrs) const
91
+ {
92
+ if ((ptrs&Bundle::AtomPointer) && (i == 0)) return true;
93
+ if ((ptrs&Bundle::PatternPointer) && (p == 0)) return true;
94
+ if ((ptrs&Bundle::ModelPointer) && (m == 0)) return true;
95
+ if ((ptrs&Bundle::GridPointer) && (g == 0)) return true;
96
+ if ((ptrs&Bundle::SitePointer) && (s == 0)) return true;
97
+ if ((ptrs&Bundle::ForcefieldPointer) && (ff == 0)) return true;
98
+ if ((ptrs&Bundle::GlyphPointer) && (gl == 0)) return true;
99
+ return false;
100
+ }
101
+
102
+ // Notify of non-null pointers
103
+ bool Bundle::notifyNull(int ptrs) const
104
+ {
105
+ if ((ptrs&Bundle::AtomPointer) && (i == 0))
106
+ {
107
+ printf("--> No active atom.\n");
108
+ return true;
109
+ }
110
+ if ((ptrs&Bundle::PatternPointer) && (p == 0))
111
+ {
112
+ printf("--> No active pattern.\n");
113
+ return true;
114
+ }
115
+ if ((ptrs&Bundle::ModelPointer) && (m == 0))
116
+ {
117
+ printf("--> No active model.\n");
118
+ return true;
119
+ }
120
+ if ((ptrs&Bundle::GridPointer) && (g == 0))
121
+ {
122
+ printf("--> No active grid.\n");
123
+ return true;
124
+ }
125
+ if ((ptrs&Bundle::SitePointer) && (s == 0))
126
+ {
127
+ printf("--> No active site.\n");
128
+ return true;
129
+ }
130
+ if ((ptrs&Bundle::ForcefieldPointer) && (ff == 0))
131
+ {
132
+ printf("--> No active forcefield.\n");
133
+ return true;
134
+ }
135
+ if ((ptrs&Bundle::GlyphPointer) && (gl == 0))
136
+ {
137
+ printf("--> No active glyph.\n");
138
+ return true;
139
+ }
140
+ return false;
141
+ }
pool/shard007/C++/0095246_AboutScreen.cpp ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <Arduino.h>
2
+ #include <Adafruit_GFX.h> // Core graphics library
3
+
4
+ #include "AboutScreen.h"
5
+
6
+ AboutScreen::AboutScreen(Adafruit_ILI9341* adafruitTft, ScreenUtils* sUtils, TimeUtils* tUtils, DateTimeCounter* counter) {
7
+ tft = adafruitTft;
8
+ screenUtils = sUtils;
9
+ timeUtils = tUtils;
10
+ dateTimeCounter = counter;
11
+ }
12
+
13
+ void AboutScreen::open(String versionNumber)
14
+ {
15
+ tft->fillScreen(ILI9341_BLACK);
16
+
17
+ screenUtils->drawBatteryStateOfCharge(101);
18
+
19
+ tft->setTextWrap(false);
20
+ tft->setFont(&DroidSansMono8pt7b);
21
+
22
+ tft->setCursor(50, 30);
23
+ tft->setTextColor(ILI9341_GREEN, ILI9341_BLACK);
24
+ tft->println("www.diveino.hu");
25
+
26
+ screenUtils->drawBmpFile((char *)"Touch/logo.bmp", 50, 70);
27
+ screenUtils->drawButtonFrame(40, 60, 160, 160, 10, false);
28
+
29
+ tft->setTextColor(ILI9341_WHITE, ILI9341_BLACK);
30
+ tft->setCursor(10, 310);
31
+ tft->println(versionNumber);
32
+
33
+ dateTimeCounter->init(timeUtils->getCurrentTime());
34
+ }
35
+
36
+ int AboutScreen::handleTouch(Adafruit_FT6206* touchScreen)
37
+ {
38
+ if (touchScreen->touched()) {
39
+ TS_Point touchPoint = touchScreen->getPoint();
40
+
41
+ // flip it around to match the screen.
42
+ touchPoint.x = map(touchPoint.x, 0, 240, 240, 0);
43
+ touchPoint.y = map(touchPoint.y, 0, 320, 320, 0);
44
+
45
+ if (50 < touchPoint.x && touchPoint.x < 50+140 &&
46
+ 70 < touchPoint.y && touchPoint.y < 70+140) {
47
+ drawButtonPress(BUTTON_HOME);
48
+ return GO_HOME;
49
+ }
50
+ delay(100);
51
+ }
52
+
53
+ return NO_ACTION;
54
+ }
55
+
56
+ void AboutScreen::drawButtonPress(int button) {
57
+ switch (button) {
58
+ case BUTTON_HOME:
59
+ screenUtils->drawButtonFrame(40, 60, 160, 160, 10, true);
60
+ break;
61
+ }
62
+
63
+ delay(100);
64
+
65
+ switch (button) {
66
+ case BUTTON_HOME:
67
+ screenUtils->drawButtonFrame(40, 60, 160, 160, 10, false);
68
+ break;
69
+ }
70
+ }
71
+
72
+ void AboutScreen::drawCurrentTime()
73
+ {
74
+ dateTimeCounter->update(timeUtils->getCurrentTime());
75
+ }
pool/shard007/C++/0095248_recursive_mutex_impl.cc ADDED
@@ -0,0 +1,245 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright (c) 2005, Eric Crahen
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished
10
+ * to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in
13
+ * all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY,
21
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
22
+ * IN
23
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ *
25
+ */
26
+
27
+ #include "debug.h"
28
+
29
+ #include "recursive_mutex_impl.h"
30
+ #include "thread_impl.h"
31
+
32
+ #include "zthread/guard.h"
33
+
34
+ #include <assert.h>
35
+ #include <errno.h>
36
+ #include <algorithm>
37
+
38
+ namespace zthread {
39
+
40
+ /**
41
+ * Create a new RecursiveMutexImpl
42
+ *
43
+ * @exception Initialization_Exception thrown if resources could not be
44
+ * properly allocated
45
+ */
46
+ RecursiveMutexImpl::RecursiveMutexImpl() : _owner(0), _count(0) {}
47
+
48
+ /**
49
+ * Destroy this RecursiveMutexImpl and release its resources
50
+ */
51
+ RecursiveMutexImpl::~RecursiveMutexImpl() {
52
+ #ifndef NDEBUG
53
+
54
+ // It is an error to destroy a mutex that has not been released
55
+ if (_owner != 0) {
56
+ ZTDEBUG("** You are destroying a mutex which was never released. **\n");
57
+ assert(0); // Destroyed mutex while in use
58
+ }
59
+
60
+ if (_waiters.size() > 0) {
61
+ ZTDEBUG("** You are destroying a mutex which is blocking %zd threads. **\n",
62
+ _waiters.size());
63
+ assert(0); // Destroyed mutex while in use
64
+ }
65
+
66
+ #endif
67
+ }
68
+
69
+ void RecursiveMutexImpl::Acquire() {
70
+ // Get the monitor for the current thread
71
+ Monitor& m = ThreadImpl::current()->getMonitor();
72
+ Monitor::STATE state;
73
+
74
+ Guard<FastLock> g1(_lock);
75
+
76
+ // If there is an entry count and the current thread is
77
+ // the owner, increment the count and continue.
78
+ if (_owner == &m)
79
+ _count++;
80
+
81
+ else {
82
+ // Acquire the lock if it is free and there are no waiting threads
83
+ if (_owner == 0 && _waiters.empty()) {
84
+ assert(_count == 0);
85
+
86
+ _owner = &m;
87
+ _count++;
88
+
89
+ } else { // Otherwise, wait()
90
+
91
+ _waiters.push_back(&m);
92
+
93
+ m.Acquire();
94
+
95
+ {
96
+ Guard<FastLock, UnlockedScope> g2(g1);
97
+ state = m.wait();
98
+ }
99
+
100
+ m.Release();
101
+
102
+ // Remove from waiter list, regarless of weather release() is called or
103
+ // not. The monitor is sticky, so its possible a state 'stuck' from a
104
+ // previous operation and will leave the wait() w/o release() having
105
+ // been called.
106
+ List::iterator i = std::find(_waiters.begin(), _waiters.end(), &m);
107
+ if (i != _waiters.end()) _waiters.erase(i);
108
+
109
+ // If awoke due to a notify(), take ownership.
110
+ switch (state) {
111
+ case Monitor::SIGNALED:
112
+
113
+ assert(_owner == 0);
114
+ assert(_count == 0);
115
+
116
+ _owner = &m;
117
+ _count++;
118
+
119
+ break;
120
+
121
+ case Monitor::INTERRUPTED:
122
+ throw InterruptedException();
123
+
124
+ default:
125
+ throw SynchronizationException();
126
+ }
127
+ }
128
+ }
129
+ }
130
+
131
+ bool RecursiveMutexImpl::tryAcquire(unsigned long timeout) {
132
+ // Get the monitor for the current thread
133
+ Monitor& m = ThreadImpl::current()->getMonitor();
134
+
135
+ Guard<FastLock> g1(_lock);
136
+
137
+ // If there is an entry count and the current thread is
138
+ // the owner, increment the count and continue.
139
+ if (_owner == &m)
140
+ _count++;
141
+
142
+ else {
143
+ // Acquire the lock if it is free and there are no waiting threads
144
+ if (_owner == 0 && _waiters.empty()) {
145
+ assert(_count == 0);
146
+
147
+ _owner = &m;
148
+ _count++;
149
+
150
+ } else { // Otherwise, wait()
151
+
152
+ _waiters.push_back(&m);
153
+
154
+ Monitor::STATE state = Monitor::TIMEDOUT;
155
+
156
+ // Don't bother waiting if the timeout is 0
157
+ if (timeout) {
158
+ m.Acquire();
159
+
160
+ {
161
+ Guard<FastLock, UnlockedScope> g2(g1);
162
+ state = m.wait(timeout);
163
+ }
164
+
165
+ m.Release();
166
+ }
167
+
168
+ // Remove from waiter list, regarless of weather release() is called or
169
+ // not. The monitor is sticky, so its possible a state 'stuck' from a
170
+ // previous operation and will leave the wait() w/o release() having
171
+ // been called.
172
+ List::iterator i = std::find(_waiters.begin(), _waiters.end(), &m);
173
+ if (i != _waiters.end()) _waiters.erase(i);
174
+
175
+ // If awoke due to a notify(), take ownership.
176
+ switch (state) {
177
+ case Monitor::SIGNALED:
178
+
179
+ assert(_count == 0);
180
+ assert(_owner == 0);
181
+
182
+ _owner = &m;
183
+ _count++;
184
+
185
+ break;
186
+
187
+ case Monitor::INTERRUPTED:
188
+ throw InterruptedException();
189
+
190
+ case Monitor::TIMEDOUT:
191
+ return false;
192
+
193
+ default:
194
+ throw SynchronizationException();
195
+ }
196
+ }
197
+ }
198
+
199
+ return true;
200
+ }
201
+
202
+ void RecursiveMutexImpl::release() {
203
+ // Get the monitor for the current thread
204
+ Monitor& m = ThreadImpl::current()->getMonitor();
205
+
206
+ Guard<FastLock> g1(_lock);
207
+
208
+ // Make sure the operation is valid
209
+ if (!(_owner == &m)) throw InvalidOpException();
210
+
211
+ // Update the count, if it has reached 0, wake another waiter.
212
+ if (--_count == 0) {
213
+ _owner = 0;
214
+
215
+ // Try to find a waiter with a backoff & retry scheme
216
+ for (;;) {
217
+ // Go through the list, attempt to notify() a waiter.
218
+ for (List::iterator i = _waiters.begin(); i != _waiters.end();) {
219
+ // Try the monitor lock, if it cant be locked skip to the next waiter
220
+ Monitor* n = *i;
221
+ if (n->TryAcquire()) {
222
+ // If notify() is not sucessful, it is because the wait() has already
223
+ // been ended (killed/interrupted/notify'd)
224
+ bool woke = n->notify();
225
+ n->Release();
226
+
227
+ // Once notify() succeeds, return
228
+ if (woke) return;
229
+
230
+ } else
231
+ ++i;
232
+ }
233
+
234
+ if (_waiters.empty()) return;
235
+
236
+ { // Backoff and try again
237
+
238
+ Guard<FastLock, UnlockedScope> g2(g1);
239
+ ThreadImpl::yield();
240
+ }
241
+ }
242
+ }
243
+ }
244
+
245
+ } // namespace ZThread
pool/shard007/C++/0095254_cmd_reverse_frames.cpp ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Aseprite
2
+ // Copyright (C) 2001-2015 David Capello
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 version 2 as
6
+ // published by the Free Software Foundation.
7
+
8
+ #ifdef HAVE_CONFIG_H
9
+ #include "config.h"
10
+ #endif
11
+
12
+ #include "app/app.h"
13
+ #include "app/commands/command.h"
14
+ #include "app/context_access.h"
15
+ #include "app/modules/gui.h"
16
+ #include "app/ui/main_window.h"
17
+ #include "app/ui/timeline.h"
18
+ #include "app/document_range_ops.h"
19
+
20
+ namespace app {
21
+
22
+ class ReverseFramesCommand : public Command {
23
+ public:
24
+ ReverseFramesCommand();
25
+ Command* clone() const override { return new ReverseFramesCommand(*this); }
26
+
27
+ protected:
28
+ bool onEnabled(Context* context);
29
+ void onExecute(Context* context);
30
+ };
31
+
32
+ ReverseFramesCommand::ReverseFramesCommand()
33
+ : Command("ReverseFrames",
34
+ "Reverse Frames",
35
+ CmdUIOnlyFlag)
36
+ {
37
+ }
38
+
39
+ bool ReverseFramesCommand::onEnabled(Context* context)
40
+ {
41
+ DocumentRange range = App::instance()->getMainWindow()->getTimeline()->range();
42
+
43
+ return
44
+ context->checkFlags(ContextFlags::ActiveDocumentIsWritable) &&
45
+ range.enabled() &&
46
+ range.frames() >= 2; // We need at least 2 frames to reverse
47
+ }
48
+
49
+ void ReverseFramesCommand::onExecute(Context* context)
50
+ {
51
+ DocumentRange range = App::instance()->getMainWindow()->getTimeline()->range();
52
+ if (!range.enabled())
53
+ return; // Nothing to do
54
+
55
+ Document* doc = context->activeDocument();
56
+
57
+ reverse_frames(doc, range);
58
+
59
+ update_screen_for_document(doc);
60
+ }
61
+
62
+ Command* CommandFactory::createReverseFramesCommand()
63
+ {
64
+ return new ReverseFramesCommand;
65
+ }
66
+
67
+ } // namespace app
pool/shard007/C++/0095257_OgreCgProgramManagerDll.cpp ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ -----------------------------------------------------------------------------
3
+ This source file is part of OGRE
4
+ (Object-oriented Graphics Rendering Engine)
5
+ For the latest info, see http://www.ogre3d.org/
6
+
7
+ Copyright (c) 2000-2012 Torus Knot Software Ltd
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in
17
+ all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
+ THE SOFTWARE.
26
+ -----------------------------------------------------------------------------
27
+ */
28
+
29
+ #include "OgreStableHeaders.h"
30
+ #include "OgreCgPlugin.h"
31
+ #include "OgreCgProgram.h"
32
+ #include "OgreRoot.h"
33
+
34
+ namespace Ogre {
35
+
36
+ CgPlugin* cgPlugin;
37
+ #ifndef OGRE_STATIC_LIB
38
+ //-----------------------------------------------------------------------
39
+ extern "C" void _OgreCgPluginExport dllStartPlugin(void)
40
+ {
41
+ // Create new plugin
42
+ cgPlugin = OGRE_NEW CgPlugin();
43
+
44
+ // Register
45
+ Root::getSingleton().installPlugin(cgPlugin);
46
+
47
+
48
+ }
49
+ extern "C" void _OgreCgPluginExport dllStopPlugin(void)
50
+ {
51
+ Root::getSingleton().uninstallPlugin(cgPlugin);
52
+ OGRE_DELETE cgPlugin;
53
+ }
54
+ #endif
55
+
56
+ void checkForCgError(const String& ogreMethod, const String& errorTextPrefix, CGcontext context)
57
+ {
58
+ CGerror error = cgGetError();
59
+ if (error != CG_NO_ERROR)
60
+ {
61
+ String msg = errorTextPrefix + cgGetErrorString(error);
62
+
63
+ if (error == CG_COMPILER_ERROR)
64
+ {
65
+ // Get listing with full compile errors
66
+ msg = msg + "\n" + cgGetLastListing(context);
67
+ }
68
+ OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, msg, ogreMethod);
69
+ }
70
+ }
71
+
72
+ }
pool/shard007/C++/0095259_animation-playlist.cpp ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ */
17
+
18
+ // CLASS HEADER
19
+ #include <dali/internal/event/animation/animation-playlist.h>
20
+
21
+
22
+ // INTERNAL INCLUDES
23
+ #include <dali/public-api/common/vector-wrapper.h>
24
+ #include <dali/devel-api/common/set-wrapper.h>
25
+ #include <dali/internal/event/animation/animation-impl.h>
26
+
27
+
28
+ namespace Dali
29
+ {
30
+
31
+ namespace Internal
32
+ {
33
+
34
+ AnimationPlaylist* AnimationPlaylist::New()
35
+ {
36
+ return new AnimationPlaylist();
37
+ }
38
+
39
+ AnimationPlaylist::AnimationPlaylist()
40
+ {
41
+ }
42
+
43
+ AnimationPlaylist::~AnimationPlaylist()
44
+ {
45
+ }
46
+
47
+ void AnimationPlaylist::AnimationCreated( Animation& animation )
48
+ {
49
+ mAnimations.PushBack( &animation );
50
+ }
51
+
52
+ void AnimationPlaylist::AnimationDestroyed( Animation& animation )
53
+ {
54
+ Dali::Vector< Animation* >::Iterator iter = std::find( mAnimations.Begin(), mAnimations.End(), &animation );
55
+ DALI_ASSERT_ALWAYS( iter != mAnimations.End() && "Animation not found" );
56
+
57
+ mAnimations.Remove( iter );
58
+ }
59
+
60
+ void AnimationPlaylist::OnPlay( Animation& animation )
61
+ {
62
+ mPlaylist.push_back( Dali::Animation(&animation) );
63
+ }
64
+
65
+ void AnimationPlaylist::OnClear( Animation& animation )
66
+ {
67
+ std::vector< Dali::Animation >::iterator iter = std::find( mPlaylist.begin(), mPlaylist.end(), Dali::Animation(&animation) );
68
+ std::vector< Dali::Animation >::iterator last = mPlaylist.end();
69
+ if( iter != last )
70
+ {
71
+ --last; // move to real last
72
+ std::swap( *iter, *last ); // swap
73
+ mPlaylist.resize( mPlaylist.size() - 1u );
74
+ }
75
+ }
76
+
77
+ void AnimationPlaylist::NotifyCompleted()
78
+ {
79
+ std::vector< Dali::Animation > finishedAnimations;
80
+
81
+ // Since animations can be unreferenced during the signal emissions, iterators into animationPointers may be invalidated.
82
+ // First copy and reference the finished animations, then emit signals
83
+ for ( Dali::Vector< Animation* >::Iterator iter = mAnimations.Begin(); iter != mAnimations.End(); ++iter )
84
+ {
85
+ Animation* animation = *iter;
86
+
87
+ if ( animation->HasFinished() )
88
+ {
89
+ finishedAnimations.push_back( Dali::Animation(animation) );
90
+
91
+ // The animation may be present in mPlaylist - remove if necessary
92
+ // Note that the animation "Finish" signal is emitted after Stop() has been called
93
+ std::vector< Dali::Animation >::iterator iter = std::find( mPlaylist.begin(), mPlaylist.end(), Dali::Animation(animation) );
94
+ DALI_ASSERT_DEBUG(iter != mPlaylist.end());
95
+ mPlaylist.erase( iter );
96
+ }
97
+ }
98
+
99
+ // Now it's safe to emit the signals
100
+ for ( std::vector< Dali::Animation >::iterator iter = finishedAnimations.begin(); iter != finishedAnimations.end(); ++iter )
101
+ {
102
+ Dali::Animation& handle = *iter;
103
+
104
+ GetImplementation(handle).EmitSignalFinish();
105
+ }
106
+ }
107
+
108
+ } // namespace Internal
109
+
110
+ } // namespace Dali
pool/shard007/C++/0095261_Http.cpp ADDED
@@ -0,0 +1,176 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ Copyright_License {
3
+
4
+ XCSoar Glide Computer - http://www.xcsoar.org/
5
+ Copyright (C) 2000-2021 The XCSoar Project
6
+ A detailed list of copyright holders can be found in the file "AUTHORS".
7
+
8
+ This program is free software; you can redistribute it and/or
9
+ modify it under the terms of the GNU General Public License
10
+ as published by the Free Software Foundation; either version 2
11
+ of the License, or (at your option) any later version.
12
+
13
+ This program is distributed in the hope that it will be useful,
14
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ GNU General Public License for more details.
17
+
18
+ You should have received a copy of the GNU General Public License
19
+ along with this program; if not, write to the Free Software
20
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
+ }
22
+ */
23
+
24
+ #include "Http.hpp"
25
+ #include "Assert.hxx"
26
+ #include "Util.hxx"
27
+ #include "Class.hxx"
28
+ #include "Error.hxx"
29
+ #include "net/http/Easy.hxx"
30
+ #include "net/http/Adapter.hxx"
31
+ #include "net/http/Handler.hxx"
32
+
33
+ extern "C" {
34
+ #include <lauxlib.h>
35
+ }
36
+
37
+ #include <map>
38
+ #include <string>
39
+
40
+ class LuaHttpRequest final : CurlResponseHandler {
41
+ CurlEasy easy;
42
+
43
+ CurlResponseHandlerAdapter adapter;
44
+
45
+ int status;
46
+ std::multimap<std::string, std::string> response_headers;
47
+
48
+ std::string response_body;
49
+
50
+ std::exception_ptr error;
51
+
52
+ public:
53
+ explicit LuaHttpRequest(const char *url)
54
+ :easy(url), adapter(*this)
55
+ {
56
+ adapter.Install(easy);
57
+ }
58
+
59
+ private:
60
+ int Perform(lua_State *L);
61
+
62
+ public:
63
+ static int l_new(lua_State *L);
64
+ static int l_perform(lua_State *L);
65
+
66
+ private:
67
+ /* virtual methods from class CurlResponseHandler */
68
+ void OnHeaders(unsigned _status,
69
+ std::multimap<std::string, std::string> &&_headers) override {
70
+ status = _status;
71
+ response_headers = std::move(_headers);
72
+ }
73
+
74
+ void OnData(ConstBuffer<void> data) override {
75
+ // TODO size check
76
+ response_body.append((const char *)data.data, data.size);
77
+ }
78
+
79
+ void OnEnd() override {
80
+ }
81
+
82
+ void OnError(std::exception_ptr e) noexcept override {
83
+ error = std::move(e);
84
+ }
85
+ };
86
+
87
+ static constexpr struct luaL_Reg http_request_funcs[] = {
88
+ {"new", LuaHttpRequest::l_new},
89
+ {nullptr, nullptr}
90
+ };
91
+
92
+ static constexpr struct luaL_Reg http_request_methods[] = {
93
+ {"perform", LuaHttpRequest::l_perform},
94
+ {nullptr, nullptr}
95
+ };
96
+
97
+ static constexpr char lua_http_request_class[] = "http.Request";
98
+ using LuaHttpRequestClass = Lua::Class<LuaHttpRequest, lua_http_request_class>;
99
+
100
+ int
101
+ LuaHttpRequest::l_new(lua_State *L)
102
+ {
103
+ if (lua_gettop(L) != 2)
104
+ return luaL_error(L, "Invalid parameters");
105
+
106
+ if (!lua_isstring(L, 2))
107
+ luaL_argerror(L, 2, "URL expected");
108
+
109
+ LuaHttpRequestClass::New(L, lua_tostring(L, 2));
110
+ return 1;
111
+ }
112
+
113
+ int
114
+ LuaHttpRequest::Perform(lua_State *L)
115
+ {
116
+ using namespace Lua;
117
+
118
+ easy.Perform();
119
+
120
+ // TODO: yield to the main event loop until the request is done
121
+
122
+ if (error)
123
+ Lua::Raise(L, std::move(error));
124
+
125
+ lua_newtable(L);
126
+ SetTable(L, RelativeStackIndex{-1}, "status", status);
127
+
128
+ lua_pushstring(L, "headers");
129
+ lua_newtable(L);
130
+ for (const auto &i : response_headers)
131
+ SetTable(L, RelativeStackIndex{-1}, i.first, i.second);
132
+ lua_settable(L, -3);
133
+
134
+ SetTable(L, RelativeStackIndex{-1}, "body", response_body);
135
+
136
+ return 1;
137
+ }
138
+
139
+ int
140
+ LuaHttpRequest::l_perform(lua_State *L)
141
+ {
142
+ auto &request = LuaHttpRequestClass::Cast(L, 1);
143
+ return request.Perform(L);
144
+ }
145
+
146
+ static void
147
+ CreateHttpRequestMetatable(lua_State *L)
148
+ {
149
+ LuaHttpRequestClass::Register(L);
150
+
151
+ /* metatable.__index = http_request_methods */
152
+ luaL_newlib(L, http_request_methods);
153
+ lua_setfield(L, -2, "__index");
154
+
155
+ /* pop metatable */
156
+ lua_pop(L, 1);
157
+ }
158
+
159
+ void
160
+ Lua::InitHttp(lua_State *L)
161
+ {
162
+ const Lua::ScopeCheckStack check_stack(L);
163
+
164
+ lua_getglobal(L, "xcsoar");
165
+
166
+ /* create the "http" namespace */
167
+ lua_newtable(L);
168
+
169
+ luaL_newlib(L, http_request_funcs); // create 'request'
170
+ lua_setfield(L, -2, "Request"); // http.Request = request
171
+
172
+ lua_setfield(L, -2, "http"); // xcsoar.http = http
173
+ lua_pop(L, 1); // pop global "xcsoar"
174
+
175
+ CreateHttpRequestMetatable(L);
176
+ }
pool/shard007/C++/0095264_chrome_elf_main.cc ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2013 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ #include "chrome/chrome_elf/chrome_elf_main.h"
6
+
7
+ #include <assert.h>
8
+ #include <windows.h>
9
+
10
+ #include "chrome/chrome_elf/chrome_elf_security.h"
11
+ #include "chrome/chrome_elf/crash/crash_helper.h"
12
+ #include "chrome/chrome_elf/third_party_dlls/beacon.h"
13
+ #include "chrome/chrome_elf/third_party_dlls/main.h"
14
+ #include "chrome/install_static/install_details.h"
15
+ #include "chrome/install_static/install_util.h"
16
+ #include "chrome/install_static/product_install_details.h"
17
+ #include "chrome/install_static/user_data_dir.h"
18
+
19
+ // This function is exported from the DLL so that it can be called by WinMain
20
+ // after startup has completed in the browser process. For non-browser processes
21
+ // it will be called inside the DLL loader lock so it should do as little as
22
+ // possible to prevent deadlocks.
23
+ void SignalInitializeCrashReporting() {
24
+ if (!elf_crash::InitializeCrashReporting()) {
25
+ #ifdef _DEBUG
26
+ assert(false);
27
+ #endif // _DEBUG
28
+ }
29
+ }
30
+
31
+ void SignalChromeElf() {
32
+ third_party_dlls::ResetBeacon();
33
+ }
34
+
35
+ bool GetUserDataDirectoryThunk(wchar_t* user_data_dir,
36
+ size_t user_data_dir_length,
37
+ wchar_t* invalid_user_data_dir,
38
+ size_t invalid_user_data_dir_length) {
39
+ std::wstring user_data_dir_str, invalid_user_data_dir_str;
40
+ bool ret = install_static::GetUserDataDirectory(&user_data_dir_str,
41
+ &invalid_user_data_dir_str);
42
+ assert(ret);
43
+ install_static::IgnoreUnused(ret);
44
+ wcsncpy_s(user_data_dir, user_data_dir_length, user_data_dir_str.c_str(),
45
+ _TRUNCATE);
46
+ wcsncpy_s(invalid_user_data_dir, invalid_user_data_dir_length,
47
+ invalid_user_data_dir_str.c_str(), _TRUNCATE);
48
+
49
+ return true;
50
+ }
51
+
52
+ // DllMain
53
+ // -------
54
+ // Warning: The OS loader lock is held during DllMain. Be careful.
55
+ // https://msdn.microsoft.com/en-us/library/windows/desktop/dn633971.aspx
56
+ //
57
+ // - Note: Do not use install_static::GetUserDataDir from inside DllMain.
58
+ // This can result in path expansion that triggers secondary DLL loads,
59
+ // that will blow up with the loader lock held.
60
+ // https://bugs.chromium.org/p/chromium/issues/detail?id=748949#c18
61
+ BOOL APIENTRY DllMain(HMODULE module, DWORD reason, LPVOID reserved) {
62
+ if (reason == DLL_PROCESS_ATTACH) {
63
+ install_static::InitializeProductDetailsForPrimaryModule();
64
+ install_static::InitializeProcessType();
65
+
66
+ if (install_static::IsBrowserProcess()) {
67
+ __try {
68
+ // Disable third party extension points.
69
+ elf_security::EarlyBrowserSecurity();
70
+
71
+ // Initialize the blocking of third-party DLLs if the initialization of
72
+ // the safety beacon succeeds.
73
+ if (third_party_dlls::LeaveSetupBeacon())
74
+ third_party_dlls::Init();
75
+ } __except (elf_crash::GenerateCrashDump(GetExceptionInformation())) {
76
+ }
77
+ } else if (!install_static::IsCrashpadHandlerProcess()) {
78
+ SignalInitializeCrashReporting();
79
+ // CRT on initialization installs an exception filter which calls
80
+ // TerminateProcess. We need to hook CRT's attempt to set an exception.
81
+ elf_crash::DisableSetUnhandledExceptionFilter();
82
+ }
83
+
84
+ } else if (reason == DLL_PROCESS_DETACH) {
85
+ elf_crash::ShutdownCrashReporting();
86
+ }
87
+ return TRUE;
88
+ }
89
+
90
+ void DumpProcessWithoutCrash() {
91
+ elf_crash::DumpWithoutCrashing();
92
+ }
93
+
94
+ void SetMetricsClientId(const char* client_id) {
95
+ elf_crash::SetMetricsClientIdImpl(client_id);
96
+ }
97
+
98
+ bool IsBrowserProcess() {
99
+ return install_static::IsBrowserProcess();
100
+ }
pool/shard007/C++/0095271_test_size_handling.cpp ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ /*==
3
+ **
4
+ ** #### ###### # # # ####
5
+ ** # # # # ## ## # #
6
+ ** # ### # # ## # ###### (C) 2019 Rene Eng
7
+ ** # # # # # # # # LGPL
8
+ ** #### ###### ###### # # # #
9
+ **
10
+ **
11
+ --*/
12
+
13
+
14
+ // module to test header file include
15
+ #include "celma/format/size_handling.hpp"
16
+
17
+
18
+ // OS/C lib includes
19
+ #include <cstring>
20
+
21
+
22
+ // C++ Standard Library includes
23
+ #include <sstream>
24
+
25
+
26
+ // Boost includes
27
+ #define BOOST_TEST_MODULE SizeHandlingTest
28
+ #include <boost/test/unit_test.hpp>
29
+
30
+
31
+ // project includes
32
+ #include "celma/test/check_return.hpp"
33
+
34
+
35
+ namespace {
36
+
37
+
38
+ /// Helper function to test the size formatting with streams and with the
39
+ /// printf()-like function.
40
+ ///
41
+ /// @tparam T The type of the value to format.
42
+ /// @param[in] value
43
+ /// The value to format.
44
+ /// @param[in] exp_result
45
+ /// The expected result of the formatting.
46
+ /// @return
47
+ /// \c false if the result of the formatting does not equal the given
48
+ /// expected result.
49
+ /// @since 1.24.0, 17.04.2019
50
+ template< typename T>
51
+ bool checkFormatSize( const T& value, const std::string exp_result)
52
+ {
53
+
54
+ using celma::format::formatSize;
55
+
56
+ // check with stream
57
+ std::ostringstream oss;
58
+ formatSize( oss, value);
59
+ CHECK_EQUAL_RETURN( exp_result, oss.str());
60
+
61
+ // check with printf format
62
+ char buffer[ 30];
63
+ formatSize( buffer, value);
64
+ CHECK_EQUAL_RETURN( exp_result, buffer);
65
+
66
+ return true;
67
+ } // checkFormatSize
68
+
69
+
70
+ } // namespace
71
+
72
+
73
+
74
+ /// Test if div2unit() returns correct values.
75
+ ///
76
+ /// @since 1.24.0, 17.04.2019
77
+ BOOST_AUTO_TEST_CASE( test_div2unit)
78
+ {
79
+
80
+ using celma::format::div2unit;
81
+
82
+
83
+ double testval = 0.0;
84
+ BOOST_REQUIRE_EQUAL( div2unit( testval), 0);
85
+ BOOST_REQUIRE_EQUAL( testval, 0.0);
86
+
87
+ testval = 1.0;
88
+ BOOST_REQUIRE_EQUAL( div2unit( testval), 0);
89
+ BOOST_REQUIRE_EQUAL( testval, 1.0);
90
+
91
+ testval = 1023.0;
92
+ BOOST_REQUIRE_EQUAL( div2unit( testval), 0);
93
+ BOOST_REQUIRE_EQUAL( testval, 1023.0);
94
+
95
+ testval = 1024.0;
96
+ BOOST_REQUIRE_EQUAL( div2unit( testval), 1);
97
+ BOOST_REQUIRE_EQUAL( testval, 1.0);
98
+
99
+ testval = 1025.0;
100
+ BOOST_REQUIRE_EQUAL( div2unit( testval), 1);
101
+ BOOST_REQUIRE_EQUAL( testval, 1025.0 / 1024.0);
102
+
103
+ testval = 1024.0 * 1024.0 - 1;
104
+ BOOST_REQUIRE_EQUAL( div2unit( testval), 1);
105
+ BOOST_REQUIRE_EQUAL( testval, (1024.0 * 1024.0 - 1) / 1024.0);
106
+
107
+ testval = 1024.0 * 1024.0;
108
+ BOOST_REQUIRE_EQUAL( div2unit( testval), 2);
109
+ BOOST_REQUIRE_EQUAL( testval, 1.0);
110
+
111
+ testval = 1024.0 * 1024.0 + 1;
112
+ BOOST_REQUIRE_EQUAL( div2unit( testval), 2);
113
+ BOOST_REQUIRE_EQUAL( testval, (1024.0 * 1024.0 + 1) / 1024.0 / 1024.0);
114
+
115
+ } // test_div2unit
116
+
117
+
118
+
119
+ /// Test if numDivs2Name return correct values.
120
+ ///
121
+ /// @since 1.24.0, 17.04.2019
122
+ BOOST_AUTO_TEST_CASE( test_numDivs2Name)
123
+ {
124
+
125
+ using celma::format::numDivs2Name;
126
+
127
+
128
+ BOOST_REQUIRE( ::strcmp( numDivs2Name( 0), "bytes") == 0);
129
+ BOOST_REQUIRE( ::strcmp( numDivs2Name( 1), "kbytes") == 0);
130
+ BOOST_REQUIRE( ::strcmp( numDivs2Name( 2), "Mbytes") == 0);
131
+ BOOST_REQUIRE( ::strcmp( numDivs2Name( 3), "Gbytes") == 0);
132
+ BOOST_REQUIRE( ::strcmp( numDivs2Name( 4), "Tbytes") == 0);
133
+ BOOST_REQUIRE( ::strcmp( numDivs2Name( 5), "Pbytes") == 0);
134
+ BOOST_REQUIRE( ::strcmp( numDivs2Name( 6), "Ebytes") == 0);
135
+
136
+ BOOST_REQUIRE( ::strcmp( numDivs2Name( -1), "out of range") == 0);
137
+ BOOST_REQUIRE( ::strcmp( numDivs2Name( 7), "out of range") == 0);
138
+
139
+ } // test_numDivs2Name
140
+
141
+
142
+
143
+ /// Function formatSize() does the whole formatting.
144
+ ///
145
+ /// @since 1.24.0, 17.04.2019
146
+ BOOST_AUTO_TEST_CASE( format_size)
147
+ {
148
+
149
+ BOOST_REQUIRE( checkFormatSize( 1000, "1000.0 bytes"));
150
+ BOOST_REQUIRE( checkFormatSize( 10000, " 9.8 kbytes"));
151
+ BOOST_REQUIRE( checkFormatSize( 100000, " 97.7 kbytes"));
152
+ BOOST_REQUIRE( checkFormatSize( 1000000, " 976.6 kbytes"));
153
+ BOOST_REQUIRE( checkFormatSize( 1024000, "1000.0 kbytes"));
154
+ BOOST_REQUIRE( checkFormatSize( 10000000, " 9.5 Mbytes"));
155
+ BOOST_REQUIRE( checkFormatSize( 100000000, " 95.4 Mbytes"));
156
+ BOOST_REQUIRE( checkFormatSize( 1000000000, " 953.7 Mbytes"));
157
+ BOOST_REQUIRE( checkFormatSize( 1048576000, "1000.0 Mbytes"));
158
+ BOOST_REQUIRE( checkFormatSize( 10000000000L, " 9.3 Gbytes"));
159
+ BOOST_REQUIRE( checkFormatSize( 100000000000L, " 93.1 Gbytes"));
160
+ BOOST_REQUIRE( checkFormatSize( 1000000000000L, " 931.3 Gbytes"));
161
+ BOOST_REQUIRE( checkFormatSize( 1073741824000L, "1000.0 Gbytes"));
162
+ BOOST_REQUIRE( checkFormatSize( 10000000000000L, " 9.1 Tbytes"));
163
+
164
+ } // format_size
165
+
166
+
167
+
168
+ // ===== END OF test_size_handling.cpp =====
169
+