Upload folder using huggingface_hub (part 90)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- pool/shard008/C++/0096461_testtime_wstream.cpp +89 -0
- pool/shard008/C++/0096465_ObsEdge.cc +181 -0
- pool/shard008/C++/0096469_protocol_packet_test.cc +268 -0
- pool/shard008/C++/0096471_arrays-maxsum.cpp +58 -0
- pool/shard008/C++/0096472_command.cpp +174 -0
- pool/shard008/C++/0096473_FontHostStreamTest.cpp +116 -0
- pool/shard008/C++/0096474_QuotaVirtualMachine.cc +141 -0
- pool/shard008/C++/0096475_qgscurvev2.cpp +103 -0
- pool/shard008/C++/0096476_generate.cpp +96 -0
- pool/shard008/C++/0096477_matcher.cc +41 -0
- pool/shard008/C++/0096480_match_test.cc +66 -0
- pool/shard008/C++/0096483_HardwareCAN.cpp +122 -0
- pool/shard008/C++/0096489_BenchGfxCommmands.cpp +30 -0
- pool/shard008/C++/0096504_math_test.cc +210 -0
- pool/shard008/C++/0096507_dicomimagelabel.cpp +69 -0
- pool/shard008/C++/0096510_GLTextureRectangle.cpp +112 -0
- pool/shard008/C++/0096511_mesh2d.cpp +189 -0
- pool/shard008/C++/0096512_CWE590_Free_Memory_Not_on_Heap__delete_array_int_static_67b.cpp +54 -0
- pool/shard008/C++/0096515_TestReverse.cpp +37 -0
- pool/shard008/C++/0096517_ST_NUCLEO-F042K6-spis.cpp +105 -0
- pool/shard008/C++/0096519_tcpMessageClient.cpp +181 -0
- pool/shard008/C++/0096521_basic_sspi_auth.cc +182 -0
- pool/shard008/C++/0096533_kate.cpp +81 -0
- pool/shard008/C++/0096536_pepper_broker.cc +259 -0
- pool/shard008/C++/0096537_tictactoe.cpp +176 -0
- pool/shard008/C++/0096542_Sch.cpp +115 -0
- pool/shard008/C++/0096543_ContainerTraitsTest.cpp +51 -0
- pool/shard008/C++/0096547_obstacle-shadowing-propagation-loss-model.cc +124 -0
- pool/shard008/C++/0096548_animgoals_stackentry.cpp +122 -0
- pool/shard008/C++/0096549_qgsfieldformatter.cpp +91 -0
- pool/shard008/C++/0096551_nofCarpenter.cpp +69 -0
- pool/shard008/C++/0096563_fingerprint_calculator.cpp +67 -0
- pool/shard008/C++/0096564_desktop_native_cursor_manager.cc +96 -0
- pool/shard008/C++/0096566_HashMap_Test.cpp +94 -0
- pool/shard008/C++/0096567_media_stream_device_permission_context_unittest.cc +138 -0
- pool/shard008/C++/0096568_UrlFilter.cpp +72 -0
- pool/shard008/C++/0096569_ImportDeviceDialog.cpp +82 -0
- pool/shard008/C++/0096571_chown.cpp +219 -0
- pool/shard008/C++/0096575_firstrun.cpp +115 -0
- pool/shard008/C++/0096577_catv_randomizer_bb_impl.cc +96 -0
- pool/shard008/C++/0096578_AP_Follow.cpp +392 -0
- pool/shard008/C++/0096579_GameFieldText.cpp +190 -0
- pool/shard008/C++/0096580_opimport.cpp +239 -0
- pool/shard008/C++/0096581_OrderAmount.cpp +116 -0
- pool/shard008/C++/0096582_test.cpp +133 -0
- pool/shard008/C++/0096584_csvr.cpp +100 -0
- pool/shard008/C++/0096586_storage_monitor.cc +185 -0
- pool/shard008/C++/0096587_point_set_read_xyz.cpp +47 -0
- pool/shard008/C++/0096589_utils.cpp +31 -0
- pool/shard008/C++/0096590_configsettingslog.cpp +153 -0
pool/shard008/C++/0096461_testtime_wstream.cpp
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Copyright (c) 2003-2004 CrystalClear Software, Inc.
|
| 2 |
+
* Use, modification and distribution is subject to the
|
| 3 |
+
* Boost Software License, Version 1.0. (See accompanying
|
| 4 |
+
* file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
|
| 5 |
+
* Author: Bart Garst
|
| 6 |
+
* $Date: 2008-11-26 22:07:14 +0100 (Wed, 26 Nov 2008) $
|
| 7 |
+
*/
|
| 8 |
+
#include <iostream>
|
| 9 |
+
#include <sstream>
|
| 10 |
+
#include <boost/date_time/gregorian/gregorian.hpp>
|
| 11 |
+
#include <boost/date_time/posix_time/posix_time.hpp>
|
| 12 |
+
#include "../testfrmwk.hpp"
|
| 13 |
+
#include <boost/lexical_cast.hpp>
|
| 14 |
+
|
| 15 |
+
using namespace boost::gregorian;
|
| 16 |
+
using namespace boost::posix_time;
|
| 17 |
+
using boost::lexical_cast;
|
| 18 |
+
|
| 19 |
+
int main(){
|
| 20 |
+
#if defined(BOOST_NO_STD_WSTRING) || \
|
| 21 |
+
defined(BOOST_DATE_TIME_INCLUDE_LIMITED_HEADERS)
|
| 22 |
+
check("No wstring/wstream support for this compiler", false);
|
| 23 |
+
#else
|
| 24 |
+
|
| 25 |
+
std::wstring res, ws;
|
| 26 |
+
std::wstringstream wss;
|
| 27 |
+
/* time_period was used because all the time-type objects
|
| 28 |
+
* that have operator<< can be easily accessed from it.
|
| 29 |
+
* Tose are: ptime, time_duration, time_period */
|
| 30 |
+
date d1(2003,Jan,20), d2(2003,May,10);
|
| 31 |
+
time_period tp(ptime(d1,hours(1)), ptime(d2,hours(15)));
|
| 32 |
+
|
| 33 |
+
// ptime
|
| 34 |
+
wss << tp.begin();
|
| 35 |
+
res = L"2003-Jan-20 01:00:00";
|
| 36 |
+
check("ptime op<<", res == wss.str());
|
| 37 |
+
wss.str(L"");
|
| 38 |
+
ws = to_simple_wstring(tp.begin());
|
| 39 |
+
check("ptime to_simple_wstring", res == ws);
|
| 40 |
+
res = L"20030120T010000";
|
| 41 |
+
ws = to_iso_wstring(tp.begin());
|
| 42 |
+
check("ptime to_iso_wstring", res == ws);
|
| 43 |
+
res = L"2003-01-20T01:00:00";
|
| 44 |
+
ws = to_iso_extended_wstring(tp.begin());
|
| 45 |
+
check("ptime to_iso_extended_wstring", res == ws);
|
| 46 |
+
|
| 47 |
+
// time_duration
|
| 48 |
+
wss << tp.length();
|
| 49 |
+
res = L"2654:00:00";
|
| 50 |
+
check("time_duration", res == wss.str());
|
| 51 |
+
wss.str(L"");
|
| 52 |
+
ws = to_simple_wstring(tp.length());
|
| 53 |
+
check("time_duration to_simple_wstring", res == ws);
|
| 54 |
+
res = L"26540000";
|
| 55 |
+
ws = to_iso_wstring(tp.length());
|
| 56 |
+
check("time_duration to_iso_wstring", res == ws);
|
| 57 |
+
|
| 58 |
+
// time_period
|
| 59 |
+
wss << tp;
|
| 60 |
+
#ifdef BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG
|
| 61 |
+
res = L"[2003-Jan-20 01:00:00/2003-May-10 14:59:59.999999999]";
|
| 62 |
+
#else
|
| 63 |
+
res = L"[2003-Jan-20 01:00:00/2003-May-10 14:59:59.999999]";
|
| 64 |
+
#endif
|
| 65 |
+
check("time_period", res == wss.str());
|
| 66 |
+
wss.str(L"");
|
| 67 |
+
ws = to_simple_wstring(tp);
|
| 68 |
+
check("time_period to_simple_wstring", res == ws);
|
| 69 |
+
|
| 70 |
+
// special values
|
| 71 |
+
time_duration sv_td(neg_infin);
|
| 72 |
+
date sv_d(pos_infin);
|
| 73 |
+
ptime sv_tp(sv_d,hours(1));
|
| 74 |
+
res = L"+infinity";
|
| 75 |
+
wss << sv_tp;
|
| 76 |
+
check("ptime op<< special value", res == wss.str());
|
| 77 |
+
wss.str(L"");
|
| 78 |
+
ws = to_simple_wstring(sv_tp);
|
| 79 |
+
check("ptime to_simple_wstring special value", res == ws);
|
| 80 |
+
res = L"-infinity";
|
| 81 |
+
wss << sv_td;
|
| 82 |
+
check("time_duration op<< special value", res == wss.str());
|
| 83 |
+
wss.str(L"");
|
| 84 |
+
ws = to_simple_wstring(sv_td);
|
| 85 |
+
check("time_duration to_simple_wstring special value", res == ws);
|
| 86 |
+
|
| 87 |
+
#endif
|
| 88 |
+
return printTestStats();
|
| 89 |
+
}
|
pool/shard008/C++/0096465_ObsEdge.cc
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <cassert>
|
| 2 |
+
#include "ObsEdge.h"
|
| 3 |
+
#include "Belief.h"
|
| 4 |
+
#include "BeliefNode.h"
|
| 5 |
+
#include "Bounds.h"
|
| 6 |
+
#include "RandSource.h"
|
| 7 |
+
#include "Simulator.h"
|
| 8 |
+
using namespace std;
|
| 9 |
+
|
| 10 |
+
Simulator* ObsEdge::simulator;
|
| 11 |
+
|
| 12 |
+
void ObsEdge::initStatic(Simulator* simulator)
|
| 13 |
+
{
|
| 14 |
+
ObsEdge::simulator = simulator;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
void ObsEdge::clearParticles()
|
| 18 |
+
{
|
| 19 |
+
cachedParticles->particles.clear();
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
inline void ObsEdge::addNode(PolicyGraph::Node* node) {
|
| 23 |
+
nodes.push_back(node);
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
void ObsEdge::backup()
|
| 27 |
+
{
|
| 28 |
+
if (bounds->model.getObsType(obs) == TermObs){
|
| 29 |
+
bestPolicyNode = bounds->policyGraph.getInitPolicy(0);
|
| 30 |
+
lower = upper = cachedParticles->currSum;
|
| 31 |
+
// update lastUpdated to prevent count from being increased in
|
| 32 |
+
// addParticle() and fails the assert()
|
| 33 |
+
lastUpdated = 0;
|
| 34 |
+
} else {
|
| 35 |
+
if (lastUpdated == Never) {
|
| 36 |
+
findBestInitPolicy();
|
| 37 |
+
findInitUpper();
|
| 38 |
+
lastUpdated = 0;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
if (bounds->model.getObsType(obs) != LoopObs) {
|
| 42 |
+
// LoopObs can only have init policies as child
|
| 43 |
+
if (nextBelief != NULL)
|
| 44 |
+
backupFromNextBelief();
|
| 45 |
+
|
| 46 |
+
addPolicyNodes();
|
| 47 |
+
backupFromPolicyGraph();
|
| 48 |
+
} else {
|
| 49 |
+
// LoopObs
|
| 50 |
+
lower = upper = bestPolicyVal;
|
| 51 |
+
}
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
void ObsEdge::findBestInitPolicy()
|
| 56 |
+
{
|
| 57 |
+
bestPolicyVal = NegInf;
|
| 58 |
+
|
| 59 |
+
for (long i = 0; i < bounds->model.getNumInitPolicies(); i++) {
|
| 60 |
+
double currPolicyVal = cachedParticles->currSum;
|
| 61 |
+
for (long k = 0; k < count; ++k) {
|
| 62 |
+
double sumDiscounted;
|
| 63 |
+
Particle& particle = cachedParticles->particles[k];
|
| 64 |
+
RandStream randStream;
|
| 65 |
+
randStream.initseed(bounds->randSource.getStream(k).get());
|
| 66 |
+
simulator->runSingle(bounds->maxSimulLength, &sumDiscounted, particle.state, *bounds->policyGraph.getInitPolicy(i), &randStream);
|
| 67 |
+
double currValue = power(bounds->model.getDiscount(), particle.pathLength) * sumDiscounted;
|
| 68 |
+
currPolicyVal += currValue;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
if (currPolicyVal > bestPolicyVal) {
|
| 72 |
+
bestPolicyVal = currPolicyVal;
|
| 73 |
+
bestPolicyNode = bounds->policyGraph.getInitPolicy(i);
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
lower = bestPolicyVal;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
void ObsEdge::backupFromPolicyGraph()
|
| 80 |
+
{
|
| 81 |
+
assert(count == int(cachedParticles->particles.size()));
|
| 82 |
+
for (vector<PolicyGraph::Node*>::iterator it = nodes.begin();
|
| 83 |
+
it != nodes.end(); ++it) {
|
| 84 |
+
double sumPolicyValue = cachedParticles->currSum;
|
| 85 |
+
|
| 86 |
+
#pragma omp parallel for reduction(+:sumPolicyValue)
|
| 87 |
+
for (long k = 0; k < count; k++) {
|
| 88 |
+
double sumDiscounted;
|
| 89 |
+
Particle& particle = cachedParticles->particles[k];
|
| 90 |
+
RandStream randStream;
|
| 91 |
+
randStream.initseed(bounds->randSource.getStream(k).get());
|
| 92 |
+
|
| 93 |
+
simulator->runSingle(bounds->maxSimulLength, &sumDiscounted, particle.state, *(*it), &randStream);
|
| 94 |
+
double currValue = power(bounds->model.getDiscount(), particle.pathLength) * sumDiscounted;
|
| 95 |
+
|
| 96 |
+
sumPolicyValue += currValue;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
if (sumPolicyValue > bestPolicyVal) {
|
| 100 |
+
bestPolicyVal = sumPolicyValue;
|
| 101 |
+
bestPolicyNode = *it;
|
| 102 |
+
lower = sumPolicyValue;
|
| 103 |
+
}
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
nodes.clear();
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
void ObsEdge::backupFromNextBelief()
|
| 110 |
+
{
|
| 111 |
+
assert(nextBelief != NULL);
|
| 112 |
+
|
| 113 |
+
double nextLower = nextBelief->beliefNode->lBound * count
|
| 114 |
+
+ cachedParticles->currSum;
|
| 115 |
+
double nextUpper = nextBelief->beliefNode->uBound * count
|
| 116 |
+
+ cachedParticles->currSum;
|
| 117 |
+
|
| 118 |
+
if (nextLower > lower) {
|
| 119 |
+
lower = nextLower;
|
| 120 |
+
bestPolicyVal = nextLower;
|
| 121 |
+
bestPolicyNode = nextBelief->beliefNode->bestPolicyNode;
|
| 122 |
+
}
|
| 123 |
+
//lastUpdated = (nextBelief->beliefNode->lastUpdated > lastUpdated) ? nextBelief->beliefNode->lastUpdated : lastUpdated;
|
| 124 |
+
|
| 125 |
+
if (nextUpper < upper)
|
| 126 |
+
upper = nextUpper;
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
void ObsEdge::addPolicyNodes()
|
| 130 |
+
{
|
| 131 |
+
if (lastUpdated == Never) {
|
| 132 |
+
PolicyGraph& policyGraph = bounds->policyGraph;
|
| 133 |
+
for (long j=0; j < bounds->model.getNumInitPolicies(); j++){
|
| 134 |
+
PolicyGraph::Node* node = policyGraph.getInitPolicy(j);
|
| 135 |
+
addNode(node);
|
| 136 |
+
}
|
| 137 |
+
lastUpdated = 0;
|
| 138 |
+
} else {
|
| 139 |
+
PolicyGraph& policyGraph = bounds->policyGraph;
|
| 140 |
+
Model& model = bounds->model;
|
| 141 |
+
long obsGrp = model.getObsGrpFromObs(obs);
|
| 142 |
+
long end = policyGraph.getSize(obsGrp);
|
| 143 |
+
long start = lastUpdated;
|
| 144 |
+
|
| 145 |
+
for (long j=start; j < end; j++) {
|
| 146 |
+
PolicyGraph::Node* node = policyGraph.getPolicy(obsGrp, j);
|
| 147 |
+
addNode(node);
|
| 148 |
+
}
|
| 149 |
+
lastUpdated = end;
|
| 150 |
+
}
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
void ObsEdge::addParticle(const State& state, long pathLength, double immediateReward)
|
| 154 |
+
{
|
| 155 |
+
if (cachedParticles == NULL) {
|
| 156 |
+
cachedParticles = new ParticleStore();
|
| 157 |
+
}
|
| 158 |
+
// weight = 1
|
| 159 |
+
cachedParticles->particles.push_back(Particle(state, pathLength, 1));
|
| 160 |
+
|
| 161 |
+
if (lastUpdated == Never) {
|
| 162 |
+
++count;
|
| 163 |
+
assert(count == int(cachedParticles->particles.size()));
|
| 164 |
+
cachedParticles->currSum += immediateReward;
|
| 165 |
+
}
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
double ObsEdge::findInitUpper()
|
| 169 |
+
{
|
| 170 |
+
double sumDiscounted = 0;
|
| 171 |
+
Model& model = bounds->model;
|
| 172 |
+
|
| 173 |
+
for (long k=0; k < count; k++) {
|
| 174 |
+
Particle& particle = cachedParticles->particles[k];
|
| 175 |
+
double currValue = power(model.getDiscount(), particle.pathLength) * model.upperBound(particle.state);
|
| 176 |
+
sumDiscounted += currValue;
|
| 177 |
+
}
|
| 178 |
+
upper = cachedParticles->currSum + sumDiscounted;
|
| 179 |
+
|
| 180 |
+
return upper;
|
| 181 |
+
}
|
pool/shard008/C++/0096469_protocol_packet_test.cc
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2016, Ford Motor Company
|
| 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, this
|
| 9 |
+
* list of conditions and the following disclaimer.
|
| 10 |
+
*
|
| 11 |
+
* Redistributions in binary form must reproduce the above copyright notice,
|
| 12 |
+
* this list of conditions and the following
|
| 13 |
+
* disclaimer in the documentation and/or other materials provided with the
|
| 14 |
+
* distribution.
|
| 15 |
+
*
|
| 16 |
+
* Neither the name of the Ford Motor Company nor the names of its contributors
|
| 17 |
+
* may be used to endorse or promote products derived from this software
|
| 18 |
+
* without specific prior written permission.
|
| 19 |
+
*
|
| 20 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 21 |
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 22 |
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 23 |
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
| 24 |
+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
| 25 |
+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
| 26 |
+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
| 27 |
+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
| 28 |
+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
| 29 |
+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
| 30 |
+
* POSSIBILITY OF SUCH DAMAGE.
|
| 31 |
+
*/
|
| 32 |
+
|
| 33 |
+
#include "gtest/gtest.h"
|
| 34 |
+
#include <vector>
|
| 35 |
+
|
| 36 |
+
#include "utils/macro.h"
|
| 37 |
+
#include "protocol_handler/protocol_packet.h"
|
| 38 |
+
#include "protocol/common.h"
|
| 39 |
+
|
| 40 |
+
namespace test {
|
| 41 |
+
namespace components {
|
| 42 |
+
namespace protocol_handler_test {
|
| 43 |
+
|
| 44 |
+
using protocol_handler::RawMessagePtr;
|
| 45 |
+
using protocol_handler::ProtocolPacket;
|
| 46 |
+
using protocol_handler::ConnectionID;
|
| 47 |
+
using protocol_handler::FRAME_TYPE_MAX_VALUE;
|
| 48 |
+
using protocol_handler::FRAME_DATA_FIRST;
|
| 49 |
+
using protocol_handler::FRAME_TYPE_FIRST;
|
| 50 |
+
using protocol_handler::PROTOCOL_VERSION_1;
|
| 51 |
+
using protocol_handler::PROTOCOL_VERSION_3;
|
| 52 |
+
using protocol_handler::PROTECTION_OFF;
|
| 53 |
+
using protocol_handler::RESULT_CODE;
|
| 54 |
+
using protocol_handler::RESULT_OK;
|
| 55 |
+
using protocol_handler::RESULT_FAIL;
|
| 56 |
+
using protocol_handler::FRAME_TYPE_CONTROL;
|
| 57 |
+
using protocol_handler::kControl;
|
| 58 |
+
using protocol_handler::kRpc;
|
| 59 |
+
using protocol_handler::kAudio;
|
| 60 |
+
using protocol_handler::kMobileNav;
|
| 61 |
+
using protocol_handler::kBulk;
|
| 62 |
+
using protocol_handler::kInvalidServiceType;
|
| 63 |
+
using protocol_handler::FRAME_DATA_HEART_BEAT;
|
| 64 |
+
using protocol_handler::FRAME_DATA_START_SERVICE_ACK;
|
| 65 |
+
using protocol_handler::FRAME_DATA_LAST_CONSECUTIVE;
|
| 66 |
+
using protocol_handler::PROTOCOL_HEADER_V1_SIZE;
|
| 67 |
+
using protocol_handler::PROTOCOL_HEADER_V2_SIZE;
|
| 68 |
+
using protocol_handler::PROTOCOL_VERSION_MAX;
|
| 69 |
+
|
| 70 |
+
class ProtocolPacketTest : public ::testing::Test {
|
| 71 |
+
protected:
|
| 72 |
+
void SetUp() OVERRIDE {
|
| 73 |
+
some_message_id_ = 0xABCDEF0;
|
| 74 |
+
some_session_id_ = 0xFEDCBA0;
|
| 75 |
+
some_connection_id_ = 10;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
RawMessagePtr GetRawMessage(uint8_t version,
|
| 79 |
+
uint8_t frame_type,
|
| 80 |
+
uint8_t service_type) {
|
| 81 |
+
ProtocolPacket prot_packet(some_connection_id_,
|
| 82 |
+
version,
|
| 83 |
+
PROTECTION_OFF,
|
| 84 |
+
frame_type,
|
| 85 |
+
service_type,
|
| 86 |
+
FRAME_DATA_HEART_BEAT,
|
| 87 |
+
some_session_id_,
|
| 88 |
+
0u,
|
| 89 |
+
some_message_id_);
|
| 90 |
+
EXPECT_EQ(frame_type, prot_packet.frame_type());
|
| 91 |
+
return prot_packet.serializePacket();
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
const uint8_t zero_test_data_element_ = 0x0u;
|
| 95 |
+
uint32_t some_message_id_;
|
| 96 |
+
uint32_t some_session_id_;
|
| 97 |
+
ConnectionID some_connection_id_;
|
| 98 |
+
};
|
| 99 |
+
|
| 100 |
+
TEST_F(ProtocolPacketTest, SerializePacketWithDiffVersions) {
|
| 101 |
+
uint8_t version = PROTOCOL_VERSION_1;
|
| 102 |
+
for (; version <= PROTOCOL_VERSION_MAX; ++version) {
|
| 103 |
+
RawMessagePtr res = GetRawMessage(version, FRAME_TYPE_CONTROL, kControl);
|
| 104 |
+
EXPECT_EQ(version, res->protocol_version());
|
| 105 |
+
EXPECT_EQ(kControl, res->service_type());
|
| 106 |
+
EXPECT_EQ(some_connection_id_, res->connection_key());
|
| 107 |
+
if (res->protocol_version() == PROTOCOL_VERSION_1) {
|
| 108 |
+
EXPECT_EQ(PROTOCOL_HEADER_V1_SIZE, res->data_size());
|
| 109 |
+
} else {
|
| 110 |
+
EXPECT_EQ(PROTOCOL_HEADER_V2_SIZE, res->data_size());
|
| 111 |
+
}
|
| 112 |
+
}
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
// ServiceType should be equal 0x0 (Control), 0x07 (RPC), 0x0A (PCM), 0x0B
|
| 116 |
+
// (Video), 0x0F (Bulk)
|
| 117 |
+
TEST_F(ProtocolPacketTest, SerializePacketWithDiffServiceType) {
|
| 118 |
+
std::vector<uint8_t> serv_types;
|
| 119 |
+
serv_types.push_back(kControl);
|
| 120 |
+
serv_types.push_back(kRpc);
|
| 121 |
+
serv_types.push_back(kAudio);
|
| 122 |
+
serv_types.push_back(kMobileNav);
|
| 123 |
+
serv_types.push_back(kBulk);
|
| 124 |
+
|
| 125 |
+
for (size_t i = 0; i < serv_types.size(); ++i) {
|
| 126 |
+
RawMessagePtr res =
|
| 127 |
+
GetRawMessage(PROTOCOL_VERSION_3, FRAME_TYPE_CONTROL, serv_types[i]);
|
| 128 |
+
EXPECT_EQ(PROTOCOL_VERSION_3,
|
| 129 |
+
static_cast< ::protocol_handler::MajorProtocolVersion>(
|
| 130 |
+
res->protocol_version()));
|
| 131 |
+
EXPECT_EQ(serv_types[i], res->service_type());
|
| 132 |
+
EXPECT_EQ(PROTOCOL_HEADER_V2_SIZE, res->data_size());
|
| 133 |
+
}
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
TEST_F(ProtocolPacketTest, SerializePacketWithWrongServiceType) {
|
| 137 |
+
std::vector<uint8_t> serv_types;
|
| 138 |
+
for (uint8_t service_type = kControl + 1; service_type < kRpc;
|
| 139 |
+
++service_type) {
|
| 140 |
+
serv_types.push_back(service_type);
|
| 141 |
+
}
|
| 142 |
+
serv_types.push_back(0x08);
|
| 143 |
+
serv_types.push_back(0x09);
|
| 144 |
+
serv_types.push_back(0x0C);
|
| 145 |
+
serv_types.push_back(0x0D);
|
| 146 |
+
serv_types.push_back(0x0E);
|
| 147 |
+
|
| 148 |
+
for (size_t i = 0; i < serv_types.size(); ++i) {
|
| 149 |
+
RawMessagePtr res =
|
| 150 |
+
GetRawMessage(PROTOCOL_VERSION_3, FRAME_TYPE_CONTROL, serv_types[i]);
|
| 151 |
+
EXPECT_EQ(PROTOCOL_VERSION_3,
|
| 152 |
+
static_cast< ::protocol_handler::MajorProtocolVersion>(
|
| 153 |
+
res->protocol_version()));
|
| 154 |
+
EXPECT_EQ(kInvalidServiceType, res->service_type());
|
| 155 |
+
}
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
TEST_F(ProtocolPacketTest, SetPacketWithDiffFrameType) {
|
| 159 |
+
uint8_t frame_type;
|
| 160 |
+
for (frame_type = FRAME_TYPE_CONTROL + 1; frame_type <= FRAME_TYPE_MAX_VALUE;
|
| 161 |
+
++frame_type) {
|
| 162 |
+
RawMessagePtr res = GetRawMessage(PROTOCOL_VERSION_3, frame_type, kControl);
|
| 163 |
+
EXPECT_EQ(PROTOCOL_VERSION_3,
|
| 164 |
+
static_cast< ::protocol_handler::MajorProtocolVersion>(
|
| 165 |
+
res->protocol_version()));
|
| 166 |
+
EXPECT_EQ(kControl, res->service_type());
|
| 167 |
+
}
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
TEST_F(ProtocolPacketTest, AppendDataToEmptyPacket) {
|
| 171 |
+
// Set version, serviceType, frameData, sessionId
|
| 172 |
+
const uint8_t session_id = 1u;
|
| 173 |
+
uint8_t some_data[] = {
|
| 174 |
+
zero_test_data_element_, kRpc, FRAME_DATA_START_SERVICE_ACK, session_id};
|
| 175 |
+
ProtocolPacket protocol_packet;
|
| 176 |
+
RESULT_CODE res = protocol_packet.appendData(some_data, sizeof(some_data));
|
| 177 |
+
EXPECT_EQ(RESULT_FAIL, res);
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
TEST_F(ProtocolPacketTest, SetTotalDataBytes) {
|
| 181 |
+
const uint8_t new_data_size = 10u;
|
| 182 |
+
ProtocolPacket protocol_packet;
|
| 183 |
+
protocol_packet.set_total_data_bytes(new_data_size);
|
| 184 |
+
EXPECT_EQ(new_data_size, protocol_packet.total_data_bytes());
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
TEST_F(ProtocolPacketTest, AppendDataToPacketWithNonZeroSize) {
|
| 188 |
+
// Set version, serviceType, frameData, sessionId
|
| 189 |
+
const uint8_t session_id = 1u;
|
| 190 |
+
uint8_t some_data[] = {
|
| 191 |
+
zero_test_data_element_, kRpc, FRAME_DATA_LAST_CONSECUTIVE, session_id};
|
| 192 |
+
ProtocolPacket protocol_packet;
|
| 193 |
+
protocol_packet.set_total_data_bytes(sizeof(some_data) + 1);
|
| 194 |
+
RESULT_CODE res = protocol_packet.appendData(some_data, sizeof(some_data));
|
| 195 |
+
EXPECT_EQ(RESULT_OK, res);
|
| 196 |
+
EXPECT_EQ(zero_test_data_element_, protocol_packet.data()[0]);
|
| 197 |
+
EXPECT_EQ(kRpc, protocol_packet.data()[1]);
|
| 198 |
+
EXPECT_EQ(FRAME_DATA_LAST_CONSECUTIVE, protocol_packet.data()[2]);
|
| 199 |
+
EXPECT_EQ(session_id, protocol_packet.data()[3]);
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
TEST_F(ProtocolPacketTest, SetData) {
|
| 203 |
+
const uint8_t session_id = 1u;
|
| 204 |
+
uint8_t some_data[] = {
|
| 205 |
+
zero_test_data_element_, kRpc, FRAME_DATA_HEART_BEAT, session_id};
|
| 206 |
+
ProtocolPacket protocol_packet;
|
| 207 |
+
protocol_packet.set_data(some_data, sizeof(some_data));
|
| 208 |
+
EXPECT_EQ(zero_test_data_element_, protocol_packet.data()[0]);
|
| 209 |
+
EXPECT_EQ(kRpc, protocol_packet.data()[1]);
|
| 210 |
+
EXPECT_EQ(FRAME_DATA_HEART_BEAT, protocol_packet.data()[2]);
|
| 211 |
+
EXPECT_EQ(session_id, protocol_packet.data()[3]);
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
TEST_F(ProtocolPacketTest, DeserializeZeroPacket) {
|
| 215 |
+
uint8_t message[] = {};
|
| 216 |
+
ProtocolPacket protocol_packet;
|
| 217 |
+
RESULT_CODE res = protocol_packet.deserializePacket(message, 0);
|
| 218 |
+
EXPECT_EQ(RESULT_OK, res);
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
TEST_F(ProtocolPacketTest, DeserializeNonZeroPacket) {
|
| 222 |
+
// Set header, serviceType, frameData, sessionId
|
| 223 |
+
const uint8_t session_id = 1u;
|
| 224 |
+
const uint8_t version_frame_type = 0x21;
|
| 225 |
+
uint8_t some_message[] = {
|
| 226 |
+
version_frame_type, kRpc, FRAME_DATA_START_SERVICE_ACK, session_id};
|
| 227 |
+
ProtocolPacket protocol_packet;
|
| 228 |
+
RESULT_CODE res =
|
| 229 |
+
protocol_packet.deserializePacket(some_message, PROTOCOL_HEADER_V2_SIZE);
|
| 230 |
+
EXPECT_EQ(RESULT_OK, res);
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
TEST_F(ProtocolPacketTest, DeserializePacket_FrameTypeFirst_ResultOK) {
|
| 234 |
+
// Arrange
|
| 235 |
+
const uint8_t session_id = 1u;
|
| 236 |
+
const uint8_t data_size = 1u;
|
| 237 |
+
const uint8_t version_frame_type = 0x22;
|
| 238 |
+
// Set protol version - 2 and frame type - first
|
| 239 |
+
uint8_t message[] = {version_frame_type,
|
| 240 |
+
kRpc,
|
| 241 |
+
FRAME_DATA_FIRST,
|
| 242 |
+
session_id,
|
| 243 |
+
zero_test_data_element_,
|
| 244 |
+
zero_test_data_element_,
|
| 245 |
+
zero_test_data_element_,
|
| 246 |
+
zero_test_data_element_,
|
| 247 |
+
zero_test_data_element_,
|
| 248 |
+
zero_test_data_element_,
|
| 249 |
+
zero_test_data_element_,
|
| 250 |
+
zero_test_data_element_,
|
| 251 |
+
zero_test_data_element_,
|
| 252 |
+
zero_test_data_element_,
|
| 253 |
+
zero_test_data_element_,
|
| 254 |
+
data_size,
|
| 255 |
+
zero_test_data_element_};
|
| 256 |
+
ProtocolPacket protocol_packet;
|
| 257 |
+
// Act
|
| 258 |
+
RESULT_CODE res =
|
| 259 |
+
protocol_packet.deserializePacket(message, PROTOCOL_HEADER_V2_SIZE);
|
| 260 |
+
uint8_t frame_type = protocol_packet.frame_type();
|
| 261 |
+
// Assert
|
| 262 |
+
EXPECT_EQ(FRAME_TYPE_FIRST, frame_type);
|
| 263 |
+
EXPECT_EQ(RESULT_OK, res);
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
} // namespace protocol_handler_test
|
| 267 |
+
} // namespace components
|
| 268 |
+
} // namespace test
|
pool/shard008/C++/0096471_arrays-maxsum.cpp
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// http://www.interviewbit.com/courses/programming/topics/arrays/problems/maxsum/
|
| 2 |
+
|
| 3 |
+
// Kadane's Algorithm: https://en.wikipedia.org/wiki/Maximum_subarray_problem
|
| 4 |
+
|
| 5 |
+
// Q: how big are expected values? Ok to use int?
|
| 6 |
+
|
| 7 |
+
#include <iostream>
|
| 8 |
+
#include <limits>
|
| 9 |
+
#include <vector>
|
| 10 |
+
|
| 11 |
+
using std::cin;
|
| 12 |
+
using std::cout;
|
| 13 |
+
|
| 14 |
+
int maxSubArray(const std::vector<int> &A) {
|
| 15 |
+
|
| 16 |
+
if (A.size() <= 0) {
|
| 17 |
+
return 0;
|
| 18 |
+
}
|
| 19 |
+
int max_ending_here = 0;
|
| 20 |
+
int max_so_far = 0;
|
| 21 |
+
int max_value = std::numeric_limits<int>::min(); //store max value in case all elements in array are negative
|
| 22 |
+
|
| 23 |
+
for (int i = 0; i < A.size(); ++i) {
|
| 24 |
+
max_ending_here = max_ending_here + A[i];
|
| 25 |
+
|
| 26 |
+
if (max_ending_here < 0) {
|
| 27 |
+
max_ending_here = 0;
|
| 28 |
+
} else if (max_so_far < max_ending_here) {
|
| 29 |
+
max_so_far = max_ending_here;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
if (A[i] > max_value) {
|
| 33 |
+
max_value = A[i];
|
| 34 |
+
}
|
| 35 |
+
}
|
| 36 |
+
if (max_value < 0) { //all values in array were negative - return the least negative value
|
| 37 |
+
return max_value;
|
| 38 |
+
} else {
|
| 39 |
+
return max_so_far;
|
| 40 |
+
}
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
int main() {
|
| 45 |
+
std::vector<int> a;
|
| 46 |
+
int input;
|
| 47 |
+
|
| 48 |
+
while (1) {
|
| 49 |
+
cout << "Enter values 1 at a time into vector. Enter 0 when you are finished.\n";
|
| 50 |
+
cin >> input;
|
| 51 |
+
|
| 52 |
+
while (input != 0) {
|
| 53 |
+
a.push_back(input);
|
| 54 |
+
cin >> input;
|
| 55 |
+
}
|
| 56 |
+
cout << "\nMax subarray sum: " << maxSubArray(a) << "\n";
|
| 57 |
+
}
|
| 58 |
+
}
|
pool/shard008/C++/0096472_command.cpp
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Own header
|
| 2 |
+
#include "command.h"
|
| 3 |
+
|
| 4 |
+
// Project headers
|
| 5 |
+
#include "mutex.h"
|
| 6 |
+
#include "string_utils.h"
|
| 7 |
+
#include "gui/gui_base.h"
|
| 8 |
+
// #include "widgets/command_view.h"
|
| 9 |
+
|
| 10 |
+
// Standard headers
|
| 11 |
+
#include <stdlib.h>
|
| 12 |
+
#include <string.h>
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
CommandSender g_commandSender;
|
| 16 |
+
char COMMAND_RETURN_NOTHING[] = "nothing";
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
char *CreateIntToSend(int val)
|
| 20 |
+
{
|
| 21 |
+
// Max num chars needed to represent an int is:
|
| 22 |
+
// 10 digits + 1 sign + 1 null terminator = 12
|
| 23 |
+
char *rv = new char[12];
|
| 24 |
+
itoa(val, rv, 10);
|
| 25 |
+
return rv;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
// ****************************************************************************
|
| 30 |
+
// Class CommandReceiver
|
| 31 |
+
// ****************************************************************************
|
| 32 |
+
|
| 33 |
+
CommandReceiver::CommandReceiver(char const *name)
|
| 34 |
+
{
|
| 35 |
+
m_receiverName = StringDuplicate(name);
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
CommandReceiver::~CommandReceiver()
|
| 40 |
+
{
|
| 41 |
+
delete[] m_receiverName;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
bool CommandReceiver::GetArgumentBool(char const *arguments, char const *argName, bool defaultVal)
|
| 46 |
+
{
|
| 47 |
+
bool val = defaultVal;
|
| 48 |
+
if (arguments)
|
| 49 |
+
{
|
| 50 |
+
char const *match = strstr(arguments, argName);
|
| 51 |
+
if (match)
|
| 52 |
+
{
|
| 53 |
+
match += strlen(argName);
|
| 54 |
+
if (*match == '=')
|
| 55 |
+
{
|
| 56 |
+
match++;
|
| 57 |
+
if (stricmp(match, "true") == 0)
|
| 58 |
+
{
|
| 59 |
+
val = true;
|
| 60 |
+
}
|
| 61 |
+
else
|
| 62 |
+
{
|
| 63 |
+
val = false;
|
| 64 |
+
}
|
| 65 |
+
}
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
return val;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
int CommandReceiver::GetArgumentInt(char const *arguments, char const *argName, int defaultVal)
|
| 74 |
+
{
|
| 75 |
+
int val = defaultVal;
|
| 76 |
+
if (arguments)
|
| 77 |
+
{
|
| 78 |
+
char const *match = strstr(arguments, argName);
|
| 79 |
+
if (match)
|
| 80 |
+
{
|
| 81 |
+
match += strlen(argName);
|
| 82 |
+
if (*match == '=')
|
| 83 |
+
{
|
| 84 |
+
match++;
|
| 85 |
+
val = atoi(match);
|
| 86 |
+
}
|
| 87 |
+
}
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
return val;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
// ****************************************************************************
|
| 96 |
+
// Class CommandSender
|
| 97 |
+
// ****************************************************************************
|
| 98 |
+
|
| 99 |
+
CommandSender::CommandSender()
|
| 100 |
+
{
|
| 101 |
+
m_deferredCommandsMutex = new Mutex;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
void CommandSender::RegisterReceiver(CommandReceiver *receiver)
|
| 106 |
+
{
|
| 107 |
+
DebugAssert(receiver->m_receiverName);
|
| 108 |
+
DebugAssert(strlen(receiver->m_receiverName) > 2);
|
| 109 |
+
|
| 110 |
+
// Make sure the specified CommandReceiver isn't already registered
|
| 111 |
+
for (int i = 0; i < m_receivers.Size(); ++i)
|
| 112 |
+
{
|
| 113 |
+
CommandReceiver *r = m_receivers[i];
|
| 114 |
+
if (stricmp(receiver->m_receiverName, r->m_receiverName) == 0)
|
| 115 |
+
{
|
| 116 |
+
DebugAssert(0);
|
| 117 |
+
}
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
m_receivers.PutData(receiver);
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
char *CommandSender::SendCommand(char const *from, char const *target, char const *command, char const *arguments)
|
| 125 |
+
{
|
| 126 |
+
CommandReceiver *receiver = g_gui->GetWidgetByName(target);
|
| 127 |
+
|
| 128 |
+
if (!receiver)
|
| 129 |
+
{
|
| 130 |
+
for (int i = 0; i < m_receivers.Size(); ++i)
|
| 131 |
+
{
|
| 132 |
+
CommandReceiver *thisReceiver = m_receivers[i];
|
| 133 |
+
if (stricmp(thisReceiver->m_receiverName, target) == 0)
|
| 134 |
+
{
|
| 135 |
+
receiver = thisReceiver;
|
| 136 |
+
break;
|
| 137 |
+
}
|
| 138 |
+
}
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
if (receiver)
|
| 142 |
+
{
|
| 143 |
+
// TODO - re-add CommandHistory
|
| 144 |
+
// CommandHistory *cv = (CommandHistory*)g_guiManager->GetWidgetByName(COMMAND_VIEW_WINDOW_NAME);
|
| 145 |
+
// ReleaseAssert(cv, "CommandSender::SendCommand: command view window not found");
|
| 146 |
+
// cv->AddCommand(from, target, command, arguments);
|
| 147 |
+
|
| 148 |
+
return receiver->ExecuteCommand(from, command, arguments);
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
return NULL;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
void CommandSender::SendCommandDeferred(char const *from, char const *target,
|
| 156 |
+
char const *command, char const *arguments)
|
| 157 |
+
{
|
| 158 |
+
MutexLocker lock(m_deferredCommandsMutex);
|
| 159 |
+
DeferredCommand *dc = new DeferredCommand(from, target, command, arguments);
|
| 160 |
+
m_deferredCommands.PutDataAtEnd(dc);
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
void CommandSender::ProcessDeferredCommands()
|
| 165 |
+
{
|
| 166 |
+
MutexLocker lock(m_deferredCommandsMutex);
|
| 167 |
+
while (m_deferredCommands.Size())
|
| 168 |
+
{
|
| 169 |
+
DeferredCommand *dc = m_deferredCommands[0];
|
| 170 |
+
m_deferredCommands.RemoveData(0);
|
| 171 |
+
SendCommandNoRV(dc->m_from, dc->m_target, dc->m_command, dc->m_arguments);
|
| 172 |
+
delete dc;
|
| 173 |
+
}
|
| 174 |
+
}
|
pool/shard008/C++/0096473_FontHostStreamTest.cpp
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright 2011 Google Inc.
|
| 3 |
+
*
|
| 4 |
+
* Use of this source code is governed by a BSD-style license that can be
|
| 5 |
+
* found in the LICENSE file.
|
| 6 |
+
*/
|
| 7 |
+
|
| 8 |
+
#include "SkBitmap.h"
|
| 9 |
+
#include "SkCanvas.h"
|
| 10 |
+
#include "SkColor.h"
|
| 11 |
+
#include "SkFontDescriptor.h"
|
| 12 |
+
#include "SkGraphics.h"
|
| 13 |
+
#include "SkPaint.h"
|
| 14 |
+
#include "SkPoint.h"
|
| 15 |
+
#include "SkRect.h"
|
| 16 |
+
#include "SkStream.h"
|
| 17 |
+
#include "SkTypeface.h"
|
| 18 |
+
#include "SkTypes.h"
|
| 19 |
+
#include "Test.h"
|
| 20 |
+
|
| 21 |
+
static const SkColor bgColor = SK_ColorWHITE;
|
| 22 |
+
|
| 23 |
+
static void create(SkBitmap* bm, SkIRect bound) {
|
| 24 |
+
bm->allocN32Pixels(bound.width(), bound.height());
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
static void drawBG(SkCanvas* canvas) {
|
| 28 |
+
canvas->drawColor(bgColor);
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
/** Assumes that the ref draw was completely inside ref canvas --
|
| 32 |
+
implies that everything outside is "bgColor".
|
| 33 |
+
Checks that all overlap is the same and that all non-overlap on the
|
| 34 |
+
ref is "bgColor".
|
| 35 |
+
*/
|
| 36 |
+
static bool compare(const SkBitmap& ref, const SkIRect& iref,
|
| 37 |
+
const SkBitmap& test, const SkIRect& itest)
|
| 38 |
+
{
|
| 39 |
+
const int xOff = itest.fLeft - iref.fLeft;
|
| 40 |
+
const int yOff = itest.fTop - iref.fTop;
|
| 41 |
+
|
| 42 |
+
SkAutoLockPixels alpRef(ref);
|
| 43 |
+
SkAutoLockPixels alpTest(test);
|
| 44 |
+
|
| 45 |
+
for (int y = 0; y < test.height(); ++y) {
|
| 46 |
+
for (int x = 0; x < test.width(); ++x) {
|
| 47 |
+
SkColor testColor = test.getColor(x, y);
|
| 48 |
+
int refX = x + xOff;
|
| 49 |
+
int refY = y + yOff;
|
| 50 |
+
SkColor refColor;
|
| 51 |
+
if (refX >= 0 && refX < ref.width() &&
|
| 52 |
+
refY >= 0 && refY < ref.height())
|
| 53 |
+
{
|
| 54 |
+
refColor = ref.getColor(refX, refY);
|
| 55 |
+
} else {
|
| 56 |
+
refColor = bgColor;
|
| 57 |
+
}
|
| 58 |
+
if (refColor != testColor) {
|
| 59 |
+
return false;
|
| 60 |
+
}
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
return true;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
DEF_TEST(FontHostStream, reporter) {
|
| 67 |
+
{
|
| 68 |
+
SkPaint paint;
|
| 69 |
+
paint.setColor(SK_ColorGRAY);
|
| 70 |
+
paint.setTextSize(SkIntToScalar(30));
|
| 71 |
+
|
| 72 |
+
SkTypeface* fTypeface = SkTypeface::CreateFromName("Georgia",
|
| 73 |
+
SkTypeface::kNormal);
|
| 74 |
+
SkSafeUnref(paint.setTypeface(fTypeface));
|
| 75 |
+
|
| 76 |
+
SkIRect origRect = SkIRect::MakeWH(64, 64);
|
| 77 |
+
SkBitmap origBitmap;
|
| 78 |
+
create(&origBitmap, origRect);
|
| 79 |
+
SkCanvas origCanvas(origBitmap);
|
| 80 |
+
|
| 81 |
+
SkIRect streamRect = SkIRect::MakeWH(64, 64);
|
| 82 |
+
SkBitmap streamBitmap;
|
| 83 |
+
create(&streamBitmap, streamRect);
|
| 84 |
+
SkCanvas streamCanvas(streamBitmap);
|
| 85 |
+
|
| 86 |
+
SkPoint point = SkPoint::Make(24, 32);
|
| 87 |
+
|
| 88 |
+
// Test: origTypeface and streamTypeface from orig data draw the same
|
| 89 |
+
drawBG(&origCanvas);
|
| 90 |
+
origCanvas.drawText("A", 1, point.fX, point.fY, paint);
|
| 91 |
+
|
| 92 |
+
SkTypeface* origTypeface = paint.getTypeface();
|
| 93 |
+
SkAutoTUnref<SkTypeface> aur;
|
| 94 |
+
if (NULL == origTypeface) {
|
| 95 |
+
origTypeface = aur.reset(SkTypeface::RefDefault());
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
int ttcIndex;
|
| 99 |
+
SkAutoTDelete<SkStreamAsset> fontData(origTypeface->openStream(&ttcIndex));
|
| 100 |
+
SkTypeface* streamTypeface = SkTypeface::CreateFromStream(fontData.detach());
|
| 101 |
+
|
| 102 |
+
SkFontDescriptor desc;
|
| 103 |
+
bool isLocalStream = false;
|
| 104 |
+
streamTypeface->getFontDescriptor(&desc, &isLocalStream);
|
| 105 |
+
REPORTER_ASSERT(reporter, isLocalStream);
|
| 106 |
+
|
| 107 |
+
SkSafeUnref(paint.setTypeface(streamTypeface));
|
| 108 |
+
drawBG(&streamCanvas);
|
| 109 |
+
streamCanvas.drawPosText("A", 1, &point, paint);
|
| 110 |
+
|
| 111 |
+
REPORTER_ASSERT(reporter,
|
| 112 |
+
compare(origBitmap, origRect, streamBitmap, streamRect));
|
| 113 |
+
}
|
| 114 |
+
//Make sure the typeface is deleted and removed.
|
| 115 |
+
SkGraphics::PurgeFontCache();
|
| 116 |
+
}
|
pool/shard008/C++/0096474_QuotaVirtualMachine.cc
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* -------------------------------------------------------------------------- */
|
| 2 |
+
/* Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs */
|
| 3 |
+
/* */
|
| 4 |
+
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
| 5 |
+
/* not use this file except in compliance with the License. You may obtain */
|
| 6 |
+
/* a copy of the License at */
|
| 7 |
+
/* */
|
| 8 |
+
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
| 9 |
+
/* */
|
| 10 |
+
/* Unless required by applicable law or agreed to in writing, software */
|
| 11 |
+
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
| 12 |
+
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
| 13 |
+
/* See the License for the specific language governing permissions and */
|
| 14 |
+
/* limitations under the License. */
|
| 15 |
+
/* -------------------------------------------------------------------------- */
|
| 16 |
+
|
| 17 |
+
#include "QuotaVirtualMachine.h"
|
| 18 |
+
#include "Quotas.h"
|
| 19 |
+
|
| 20 |
+
/* -------------------------------------------------------------------------- */
|
| 21 |
+
/* -------------------------------------------------------------------------- */
|
| 22 |
+
|
| 23 |
+
const char * QuotaVirtualMachine::VM_METRICS[] = {"VMS", "CPU", "MEMORY"};
|
| 24 |
+
|
| 25 |
+
const int QuotaVirtualMachine::NUM_VM_METRICS = 3;
|
| 26 |
+
|
| 27 |
+
/* -------------------------------------------------------------------------- */
|
| 28 |
+
/* -------------------------------------------------------------------------- */
|
| 29 |
+
|
| 30 |
+
int QuotaVirtualMachine::get_quota(const string& id, VectorAttribute **va)
|
| 31 |
+
{
|
| 32 |
+
vector<Attribute*> values;
|
| 33 |
+
int num;
|
| 34 |
+
|
| 35 |
+
*va = 0;
|
| 36 |
+
|
| 37 |
+
num = get(template_name, values);
|
| 38 |
+
|
| 39 |
+
if ( num == 0 )
|
| 40 |
+
{
|
| 41 |
+
return 0;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
*va = dynamic_cast<VectorAttribute *>(values[0]);
|
| 45 |
+
|
| 46 |
+
return 0;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
/* -------------------------------------------------------------------------- */
|
| 50 |
+
/* -------------------------------------------------------------------------- */
|
| 51 |
+
|
| 52 |
+
bool QuotaVirtualMachine::check(Template * tmpl,
|
| 53 |
+
Quotas& default_quotas,
|
| 54 |
+
string& error)
|
| 55 |
+
{
|
| 56 |
+
map<string, float> vm_request;
|
| 57 |
+
|
| 58 |
+
int memory;
|
| 59 |
+
float cpu;
|
| 60 |
+
|
| 61 |
+
if ( tmpl->get("MEMORY", memory) == false || memory <= 0 )
|
| 62 |
+
{
|
| 63 |
+
error = "MEMORY attribute must be a positive integer value";
|
| 64 |
+
return false;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
if ( tmpl->get("CPU", cpu) == false || cpu <= 0 )
|
| 68 |
+
{
|
| 69 |
+
error = "CPU attribute must be a positive float or integer value";
|
| 70 |
+
return false;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
vm_request.insert(make_pair("VMS",1));
|
| 74 |
+
vm_request.insert(make_pair("MEMORY", memory));
|
| 75 |
+
vm_request.insert(make_pair("CPU", cpu));
|
| 76 |
+
|
| 77 |
+
return check_quota("", vm_request, default_quotas, error);
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
/* -------------------------------------------------------------------------- */
|
| 81 |
+
/* -------------------------------------------------------------------------- */
|
| 82 |
+
|
| 83 |
+
void QuotaVirtualMachine::del(Template * tmpl)
|
| 84 |
+
{
|
| 85 |
+
map<string, float> vm_request;
|
| 86 |
+
|
| 87 |
+
int memory;
|
| 88 |
+
float cpu;
|
| 89 |
+
|
| 90 |
+
if ( tmpl->get("MEMORY", memory) == false )
|
| 91 |
+
{
|
| 92 |
+
memory = 0;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
if ( tmpl->get("CPU", cpu) == false )
|
| 96 |
+
{
|
| 97 |
+
cpu = 0;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
vm_request.insert(make_pair("VMS",1));
|
| 101 |
+
vm_request.insert(make_pair("MEMORY", memory));
|
| 102 |
+
vm_request.insert(make_pair("CPU", cpu));
|
| 103 |
+
|
| 104 |
+
del_quota("", vm_request);
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
/* -------------------------------------------------------------------------- */
|
| 108 |
+
/* -------------------------------------------------------------------------- */
|
| 109 |
+
|
| 110 |
+
int QuotaVirtualMachine::get_default_quota(
|
| 111 |
+
const string& id,
|
| 112 |
+
Quotas& default_quotas,
|
| 113 |
+
VectorAttribute **va)
|
| 114 |
+
{
|
| 115 |
+
return default_quotas.vm_get(id, va);
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
/* -------------------------------------------------------------------------- */
|
| 119 |
+
/* -------------------------------------------------------------------------- */
|
| 120 |
+
|
| 121 |
+
bool QuotaVirtualMachine::update(Template * tmpl,
|
| 122 |
+
Quotas& default_quotas,
|
| 123 |
+
string& error)
|
| 124 |
+
{
|
| 125 |
+
map<string, float> vm_request;
|
| 126 |
+
|
| 127 |
+
int delta_memory;
|
| 128 |
+
float delta_cpu;
|
| 129 |
+
|
| 130 |
+
if ( tmpl->get("MEMORY", delta_memory) == true )
|
| 131 |
+
{
|
| 132 |
+
vm_request.insert(make_pair("MEMORY", delta_memory));
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
if ( tmpl->get("CPU", delta_cpu) == true )
|
| 136 |
+
{
|
| 137 |
+
vm_request.insert(make_pair("CPU", delta_cpu));
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
return check_quota("", vm_request, default_quotas, error);
|
| 141 |
+
}
|
pool/shard008/C++/0096475_qgscurvev2.cpp
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/***************************************************************************
|
| 2 |
+
qgscurvev2.cpp
|
| 3 |
+
--------------
|
| 4 |
+
begin : November 2014
|
| 5 |
+
copyright : (C) 2014 by Marco Hugentobler
|
| 6 |
+
email : marco at sourcepole dot ch
|
| 7 |
+
***************************************************************************/
|
| 8 |
+
|
| 9 |
+
/***************************************************************************
|
| 10 |
+
* *
|
| 11 |
+
* This program is free software; you can redistribute it and/or modify *
|
| 12 |
+
* it under the terms of the GNU General Public License as published by *
|
| 13 |
+
* the Free Software Foundation; either version 2 of the License, or *
|
| 14 |
+
* (at your option) any later version. *
|
| 15 |
+
* *
|
| 16 |
+
***************************************************************************/
|
| 17 |
+
|
| 18 |
+
#include "qgscurvev2.h"
|
| 19 |
+
#include "qgslinestringv2.h"
|
| 20 |
+
|
| 21 |
+
QgsCurveV2::QgsCurveV2(): QgsAbstractGeometryV2()
|
| 22 |
+
{}
|
| 23 |
+
|
| 24 |
+
QgsCurveV2::~QgsCurveV2()
|
| 25 |
+
{}
|
| 26 |
+
|
| 27 |
+
bool QgsCurveV2::isClosed() const
|
| 28 |
+
{
|
| 29 |
+
if ( numPoints() == 0 )
|
| 30 |
+
return false;
|
| 31 |
+
|
| 32 |
+
//don't consider M-coordinates when testing closedness
|
| 33 |
+
QgsPointV2 start = startPoint();
|
| 34 |
+
QgsPointV2 end = endPoint();
|
| 35 |
+
return ( qgsDoubleNear( start.x(), end.x(), 1E-8 ) &&
|
| 36 |
+
qgsDoubleNear( start.y(), end.y(), 1E-8 ) &&
|
| 37 |
+
qgsDoubleNear( start.z(), end.z(), 1E-8 ) );
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
bool QgsCurveV2::isRing() const
|
| 41 |
+
{
|
| 42 |
+
return ( isClosed() && numPoints() >= 4 );
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
QgsCoordinateSequenceV2 QgsCurveV2::coordinateSequence() const
|
| 46 |
+
{
|
| 47 |
+
if ( !mCoordinateSequence.isEmpty() )
|
| 48 |
+
return mCoordinateSequence;
|
| 49 |
+
|
| 50 |
+
mCoordinateSequence.append( QgsRingSequenceV2() );
|
| 51 |
+
mCoordinateSequence.back().append( QgsPointSequenceV2() );
|
| 52 |
+
points( mCoordinateSequence.back().back() );
|
| 53 |
+
|
| 54 |
+
return mCoordinateSequence;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
bool QgsCurveV2::nextVertex( QgsVertexId& id, QgsPointV2& vertex ) const
|
| 58 |
+
{
|
| 59 |
+
if ( id.vertex < 0 )
|
| 60 |
+
{
|
| 61 |
+
id.vertex = 0;
|
| 62 |
+
if ( id.part < 0 )
|
| 63 |
+
{
|
| 64 |
+
id.part = 0;
|
| 65 |
+
}
|
| 66 |
+
if ( id.ring < 0 )
|
| 67 |
+
{
|
| 68 |
+
id.ring = 0;
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
else
|
| 72 |
+
{
|
| 73 |
+
if ( id.vertex + 1 >= numPoints() )
|
| 74 |
+
{
|
| 75 |
+
return false;
|
| 76 |
+
}
|
| 77 |
+
++id.vertex;
|
| 78 |
+
}
|
| 79 |
+
return pointAt( id.vertex, vertex, id.type );
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
QgsCurveV2* QgsCurveV2::segmentize() const
|
| 83 |
+
{
|
| 84 |
+
return curveToLine();
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
QgsPointV2 QgsCurveV2::vertexAt( QgsVertexId id ) const
|
| 88 |
+
{
|
| 89 |
+
QgsPointV2 v;
|
| 90 |
+
QgsVertexId::VertexType type;
|
| 91 |
+
pointAt( id.vertex, v, type );
|
| 92 |
+
return v;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
QgsRectangle QgsCurveV2::boundingBox() const
|
| 96 |
+
{
|
| 97 |
+
if ( mBoundingBox.isNull() )
|
| 98 |
+
{
|
| 99 |
+
mBoundingBox = calculateBoundingBox();
|
| 100 |
+
}
|
| 101 |
+
return mBoundingBox;
|
| 102 |
+
}
|
| 103 |
+
|
pool/shard008/C++/0096476_generate.cpp
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Boost.Range library
|
| 2 |
+
//
|
| 3 |
+
// Copyright Neil Groves 2009. Use, modification and
|
| 4 |
+
// distribution is subject to the Boost Software License, Version
|
| 5 |
+
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
| 6 |
+
// http://www.boost.org/LICENSE_1_0.txt)
|
| 7 |
+
//
|
| 8 |
+
//
|
| 9 |
+
// For more information, see http://www.boost.org/libs/range/
|
| 10 |
+
//
|
| 11 |
+
#include <boost/range/algorithm/generate.hpp>
|
| 12 |
+
|
| 13 |
+
#include <boost/test/test_tools.hpp>
|
| 14 |
+
#include <boost/test/unit_test.hpp>
|
| 15 |
+
|
| 16 |
+
#include <boost/assign.hpp>
|
| 17 |
+
#include <boost/bind.hpp>
|
| 18 |
+
#include <algorithm>
|
| 19 |
+
#include <functional>
|
| 20 |
+
#include <list>
|
| 21 |
+
#include <numeric>
|
| 22 |
+
#include <deque>
|
| 23 |
+
#include <vector>
|
| 24 |
+
|
| 25 |
+
namespace boost
|
| 26 |
+
{
|
| 27 |
+
namespace
|
| 28 |
+
{
|
| 29 |
+
class generator_fn
|
| 30 |
+
{
|
| 31 |
+
public:
|
| 32 |
+
typedef int result_type;
|
| 33 |
+
|
| 34 |
+
generator_fn() : m_count(0) {}
|
| 35 |
+
int operator()() { return ++m_count; }
|
| 36 |
+
|
| 37 |
+
private:
|
| 38 |
+
int m_count;
|
| 39 |
+
};
|
| 40 |
+
|
| 41 |
+
template< class Container >
|
| 42 |
+
void test_generate_impl(Container& cont)
|
| 43 |
+
{
|
| 44 |
+
Container reference(cont);
|
| 45 |
+
std::generate(reference.begin(), reference.end(), generator_fn());
|
| 46 |
+
|
| 47 |
+
Container test(cont);
|
| 48 |
+
boost::generate(test, generator_fn());
|
| 49 |
+
|
| 50 |
+
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
| 51 |
+
test.begin(), test.end() );
|
| 52 |
+
|
| 53 |
+
Container test2(cont);
|
| 54 |
+
boost::generate(boost::make_iterator_range(test2), generator_fn());
|
| 55 |
+
|
| 56 |
+
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
| 57 |
+
test2.begin(), test2.end() );
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
template< class Container >
|
| 61 |
+
void test_generate_impl()
|
| 62 |
+
{
|
| 63 |
+
using namespace boost::assign;
|
| 64 |
+
|
| 65 |
+
Container cont;
|
| 66 |
+
test_generate_impl(cont);
|
| 67 |
+
|
| 68 |
+
cont.clear();
|
| 69 |
+
cont += 9;
|
| 70 |
+
test_generate_impl(cont);
|
| 71 |
+
|
| 72 |
+
cont.clear();
|
| 73 |
+
cont += 9,8,7,6,5,4,3,2,1;
|
| 74 |
+
test_generate_impl(cont);
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
void test_generate()
|
| 78 |
+
{
|
| 79 |
+
test_generate_impl< std::vector<int> >();
|
| 80 |
+
test_generate_impl< std::list<int> >();
|
| 81 |
+
test_generate_impl< std::deque<int> >();
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
boost::unit_test::test_suite*
|
| 88 |
+
init_unit_test_suite(int argc, char* argv[])
|
| 89 |
+
{
|
| 90 |
+
boost::unit_test::test_suite* test
|
| 91 |
+
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.generate" );
|
| 92 |
+
|
| 93 |
+
test->add( BOOST_TEST_CASE( &boost::test_generate ) );
|
| 94 |
+
|
| 95 |
+
return test;
|
| 96 |
+
}
|
pool/shard008/C++/0096477_matcher.cc
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// Copyright RIME Developers
|
| 3 |
+
// Distributed under the BSD License
|
| 4 |
+
//
|
| 5 |
+
// 2012-01-01 GONG Chen <chen.sst@gmail.com>
|
| 6 |
+
//
|
| 7 |
+
#include <rime/common.h>
|
| 8 |
+
#include <rime/config.h>
|
| 9 |
+
#include <rime/schema.h>
|
| 10 |
+
#include <rime/segmentation.h>
|
| 11 |
+
#include <rime/gear/matcher.h>
|
| 12 |
+
|
| 13 |
+
namespace rime {
|
| 14 |
+
|
| 15 |
+
Matcher::Matcher(const Ticket& ticket) : Segmentor(ticket) {
|
| 16 |
+
// read schema settings
|
| 17 |
+
if (!ticket.schema)
|
| 18 |
+
return;
|
| 19 |
+
Config* config = ticket.schema->config();
|
| 20 |
+
patterns_.LoadConfig(config);
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
bool Matcher::Proceed(Segmentation* segmentation) {
|
| 24 |
+
if (patterns_.empty())
|
| 25 |
+
return true;
|
| 26 |
+
auto match = patterns_.GetMatch(segmentation->input(), *segmentation);
|
| 27 |
+
if (match.found()) {
|
| 28 |
+
DLOG(INFO) << "match: " << match.tag
|
| 29 |
+
<< " [" << match.start << ", " << match.end << ")";
|
| 30 |
+
while (segmentation->GetCurrentStartPosition() > match.start)
|
| 31 |
+
segmentation->pop_back();
|
| 32 |
+
Segment segment(match.start, match.end);
|
| 33 |
+
segment.tags.insert(match.tag);
|
| 34 |
+
segmentation->AddSegment(segment);
|
| 35 |
+
// terminate this round?
|
| 36 |
+
//return false;
|
| 37 |
+
}
|
| 38 |
+
return true;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
} // namespace rime
|
pool/shard008/C++/0096480_match_test.cc
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Copyright 2015 Google Inc. All Rights Reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
you may not use this file except in compliance with the License.
|
| 5 |
+
You may obtain a copy of the License at
|
| 6 |
+
|
| 7 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
|
| 9 |
+
Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
See the License for the specific language governing permissions and
|
| 13 |
+
limitations under the License.
|
| 14 |
+
==============================================================================*/
|
| 15 |
+
|
| 16 |
+
#include <algorithm>
|
| 17 |
+
#include <gtest/gtest.h>
|
| 18 |
+
#include "tensorflow/core/lib/core/status_test_util.h"
|
| 19 |
+
#include "tensorflow/core/lib/io/match.h"
|
| 20 |
+
#include "tensorflow/core/lib/io/path.h"
|
| 21 |
+
#include "tensorflow/core/lib/strings/strcat.h"
|
| 22 |
+
#include "tensorflow/core/platform/test.h"
|
| 23 |
+
#include "tensorflow/core/public/env.h"
|
| 24 |
+
|
| 25 |
+
namespace tensorflow {
|
| 26 |
+
namespace io {
|
| 27 |
+
|
| 28 |
+
static string Match(Env* env, const string& suffix_pattern) {
|
| 29 |
+
std::vector<string> results;
|
| 30 |
+
Status s = GetMatchingFiles(env, JoinPath(testing::TmpDir(), suffix_pattern),
|
| 31 |
+
&results);
|
| 32 |
+
if (!s.ok()) {
|
| 33 |
+
return s.ToString();
|
| 34 |
+
} else {
|
| 35 |
+
string r;
|
| 36 |
+
std::sort(results.begin(), results.end());
|
| 37 |
+
for (size_t i = 0; i < results.size(); i++) {
|
| 38 |
+
strings::StrAppend(&r, (i > 0) ? "," : "", Basename(results[i]));
|
| 39 |
+
}
|
| 40 |
+
return r;
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
TEST(GetMatchingFiles, Simple) {
|
| 44 |
+
Env* env = Env::Default();
|
| 45 |
+
EXPECT_EQ(Match(env, "thereisnosuchfile"), "");
|
| 46 |
+
EXPECT_EQ(Match(env, "thereisnosuchfile*"), "");
|
| 47 |
+
|
| 48 |
+
// Populate a few files
|
| 49 |
+
EXPECT_OK(WriteStringToFile(Env::Default(),
|
| 50 |
+
JoinPath(testing::TmpDir(), "match-00"), ""));
|
| 51 |
+
EXPECT_OK(WriteStringToFile(Env::Default(),
|
| 52 |
+
JoinPath(testing::TmpDir(), "match-0a"), ""));
|
| 53 |
+
EXPECT_OK(WriteStringToFile(Env::Default(),
|
| 54 |
+
JoinPath(testing::TmpDir(), "match-01"), ""));
|
| 55 |
+
EXPECT_OK(WriteStringToFile(Env::Default(),
|
| 56 |
+
JoinPath(testing::TmpDir(), "match-aaa"), ""));
|
| 57 |
+
|
| 58 |
+
EXPECT_EQ(Match(env, "match-*"), "match-00,match-01,match-0a,match-aaa");
|
| 59 |
+
EXPECT_EQ(Match(env, "match-0[0-9]"), "match-00,match-01");
|
| 60 |
+
EXPECT_EQ(Match(env, "match-?[0-9]"), "match-00,match-01");
|
| 61 |
+
EXPECT_EQ(Match(env, "match-?a*"), "match-0a,match-aaa");
|
| 62 |
+
EXPECT_EQ(Match(env, "match-??"), "match-00,match-01,match-0a");
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
} // namespace io
|
| 66 |
+
} // namespace tensorflow
|
pool/shard008/C++/0096483_HardwareCAN.cpp
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @brief HardwareCAN "wiring-like" api for CAN
|
| 3 |
+
*/
|
| 4 |
+
|
| 5 |
+
#include "wirish.h"
|
| 6 |
+
#include "utility/can.h"
|
| 7 |
+
#include "HardwareCAN.h"
|
| 8 |
+
|
| 9 |
+
/**
|
| 10 |
+
* @brief Initialize a CAN peripheral
|
| 11 |
+
* @param freq frequency to run at, must one of the following values:
|
| 12 |
+
* - CAN_SPEED_1000
|
| 13 |
+
* - CAN_SPEED_500
|
| 14 |
+
* - CAN_SPEED_250
|
| 15 |
+
* - CAN_SPEED_125
|
| 16 |
+
* - CAN_SPEED_95
|
| 17 |
+
* - CAN_SPEED_33
|
| 18 |
+
*/
|
| 19 |
+
CAN_STATUS HardwareCAN::begin(CAN_SPEED speed, uint32 mode)
|
| 20 |
+
{
|
| 21 |
+
/* Begin Fix JMD
|
| 22 |
+
if (can_init(Port, CAN_MCR_NART, CAN_SPEED_250) == CAN_OK)
|
| 23 |
+
// NART empêche la réémission en cas de perte d'arbitrage d'où trames perdues
|
| 24 |
+
*/
|
| 25 |
+
Serial.end(); // disable USB interface -- JMD
|
| 26 |
+
if (can_init(Port, 0, speed) == CAN_OK)
|
| 27 |
+
// End Fix JMD
|
| 28 |
+
return can_set_mode(Port, mode);
|
| 29 |
+
return can_status();
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
void HardwareCAN::set_pool_mode(void)
|
| 33 |
+
{
|
| 34 |
+
return can_set_pool_mode(Port);
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
void HardwareCAN::set_irq_mode(void)
|
| 38 |
+
{
|
| 39 |
+
return can_set_irq_mode(Port);
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
CAN_STATUS HardwareCAN::filter(uint8 idx, uint32 id, uint32 mask)
|
| 43 |
+
{
|
| 44 |
+
return can_filter(Port, idx, CAN_FIFO0, CAN_FILTER_32BIT, CAN_FILTER_MASK, id, mask);
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
CAN_STATUS HardwareCAN::status(void)
|
| 48 |
+
{
|
| 49 |
+
return can_status();
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
CAN_TX_MBX HardwareCAN::send(CanMsg* message)
|
| 53 |
+
{
|
| 54 |
+
return can_transmit(Port, message);
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
uint8 HardwareCAN::available(void)
|
| 58 |
+
{
|
| 59 |
+
return can_rx_available();
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
CanMsg* HardwareCAN::recv(void)
|
| 63 |
+
{
|
| 64 |
+
return can_rx_queue_get();
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
void HardwareCAN::clear(void)
|
| 68 |
+
{
|
| 69 |
+
can_rx_queue_clear();
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
void HardwareCAN::free(void)
|
| 73 |
+
{
|
| 74 |
+
can_rx_queue_free();
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
void HardwareCAN::cancel(CAN_TX_MBX mbx)
|
| 78 |
+
{
|
| 79 |
+
can_cancel(Port, mbx);
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
/**
|
| 83 |
+
* @brief Initialize a CAN peripheral
|
| 84 |
+
*/
|
| 85 |
+
CAN_STATUS HardwareCAN::begin(void)
|
| 86 |
+
{
|
| 87 |
+
return begin(CAN_SPEED_250, CAN_MODE_NORMAL);
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
void HardwareCAN::end(void)
|
| 91 |
+
{
|
| 92 |
+
can_deinit(Port);
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
CanMsg* HardwareCAN::read(CAN_FIFO fifo, CanMsg* msg)
|
| 96 |
+
{
|
| 97 |
+
return can_read(Port, fifo, msg);
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
void HardwareCAN::release(CAN_FIFO fifo)
|
| 101 |
+
{
|
| 102 |
+
can_rx_release(Port, fifo);
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
/**
|
| 106 |
+
* @brief Initialize a CAN peripheral
|
| 107 |
+
*/
|
| 108 |
+
CAN_STATUS HardwareCAN::map(CAN_GPIO_MAP remap)
|
| 109 |
+
{
|
| 110 |
+
return can_gpio_map(Port, remap);
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
uint8 HardwareCAN::fifo_ready(CAN_FIFO fifo)
|
| 114 |
+
{
|
| 115 |
+
return can_fifo_ready(Port, fifo);
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
HardwareCAN::HardwareCAN(CAN_Port* CANx)
|
| 119 |
+
{
|
| 120 |
+
Port = CANx;
|
| 121 |
+
}
|
| 122 |
+
|
pool/shard008/C++/0096489_BenchGfxCommmands.cpp
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*****************************************************************************
|
| 2 |
+
* Copyright (c) 2014-2019 OpenRCT2 developers
|
| 3 |
+
*
|
| 4 |
+
* For a complete list of all authors, please refer to contributors.md
|
| 5 |
+
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
| 6 |
+
*
|
| 7 |
+
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
| 8 |
+
*****************************************************************************/
|
| 9 |
+
|
| 10 |
+
#include "../interface/Screenshot.h"
|
| 11 |
+
#include "CommandLine.hpp"
|
| 12 |
+
|
| 13 |
+
static exitcode_t HandleBenchGfx(CommandLineArgEnumerator* argEnumerator);
|
| 14 |
+
|
| 15 |
+
const CommandLineCommand CommandLine::BenchGfxCommands[]{
|
| 16 |
+
// Main commands
|
| 17 |
+
DefineCommand("", "<file> [iterations count]", nullptr, HandleBenchGfx), CommandTableEnd
|
| 18 |
+
};
|
| 19 |
+
|
| 20 |
+
static exitcode_t HandleBenchGfx(CommandLineArgEnumerator* argEnumerator)
|
| 21 |
+
{
|
| 22 |
+
const char** argv = (const char**)argEnumerator->GetArguments() + argEnumerator->GetIndex();
|
| 23 |
+
int32_t argc = argEnumerator->GetCount() - argEnumerator->GetIndex();
|
| 24 |
+
int32_t result = cmdline_for_gfxbench(argv, argc);
|
| 25 |
+
if (result < 0)
|
| 26 |
+
{
|
| 27 |
+
return EXITCODE_FAIL;
|
| 28 |
+
}
|
| 29 |
+
return EXITCODE_OK;
|
| 30 |
+
}
|
pool/shard008/C++/0096504_math_test.cc
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* -*- mode: C++ c-basic-offset: 4 -*-
|
| 2 |
+
*
|
| 3 |
+
* Copyright (c) 1999 Joe Yandle <joey@divisionbyzero.com>
|
| 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
| 18 |
+
*
|
| 19 |
+
*/
|
| 20 |
+
|
| 21 |
+
#include <iostream>
|
| 22 |
+
#include <sstream>
|
| 23 |
+
#include <string>
|
| 24 |
+
|
| 25 |
+
#include <jlib/math/math.hh>
|
| 26 |
+
#include <jlib/math/polynomial.hh>
|
| 27 |
+
#include <jlib/util/util.hh>
|
| 28 |
+
|
| 29 |
+
using jlib::math::matrix;
|
| 30 |
+
using jlib::math::cuboid;
|
| 31 |
+
using jlib::math::vertex;
|
| 32 |
+
using jlib::math::Polynomial;
|
| 33 |
+
using jlib::util::tokenize;
|
| 34 |
+
using jlib::util::int_value;
|
| 35 |
+
using jlib::util::double_value;
|
| 36 |
+
|
| 37 |
+
int main(int argc, char** argv) {
|
| 38 |
+
std::string ss[] = {
|
| 39 |
+
"2 3\n"
|
| 40 |
+
"4 0",
|
| 41 |
+
|
| 42 |
+
"10 15\n"
|
| 43 |
+
"20 0",
|
| 44 |
+
|
| 45 |
+
"1 2 0\n"
|
| 46 |
+
"5 -1 0",
|
| 47 |
+
|
| 48 |
+
"17 1 0\n"
|
| 49 |
+
"4 8 0",
|
| 50 |
+
|
| 51 |
+
"1 1 1\n"
|
| 52 |
+
"1 1 3\n"
|
| 53 |
+
"2 5 8",
|
| 54 |
+
|
| 55 |
+
"0 0 1\n"
|
| 56 |
+
"1 1 3\n"
|
| 57 |
+
"0 5 8",
|
| 58 |
+
|
| 59 |
+
"0 1\n"
|
| 60 |
+
"1 2" };
|
| 61 |
+
|
| 62 |
+
uint n = sizeof(ss) / sizeof(std::string);
|
| 63 |
+
std::vector< matrix<int> > m;
|
| 64 |
+
|
| 65 |
+
for (uint i = 0; i < n; i++) {
|
| 66 |
+
std::vector<std::string> tok = tokenize(ss[i], "\n", false);
|
| 67 |
+
|
| 68 |
+
uint x = tok.size();
|
| 69 |
+
uint y = tokenize(tok[0], " ", false).size();
|
| 70 |
+
|
| 71 |
+
std::istringstream is(ss[i]);
|
| 72 |
+
matrix<int> ma(x, y);
|
| 73 |
+
|
| 74 |
+
is >> ma;
|
| 75 |
+
|
| 76 |
+
m.push_back(ma);
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
matrix<int> mi = matrix<int>::identity(2);
|
| 80 |
+
matrix<int> md = matrix<int>::diagonal(2, 5);
|
| 81 |
+
|
| 82 |
+
try {
|
| 83 |
+
matrix<int> m4 = (m[0] * m[2]);
|
| 84 |
+
if(m4 != m[3]) {
|
| 85 |
+
std::cerr << m[0] << std::endl << "*" << std::endl
|
| 86 |
+
<< m[2] << std::endl << "=" << std::endl
|
| 87 |
+
<< m4 << std::endl << "rather than" << std::endl
|
| 88 |
+
<< m[3] << std::endl << std::endl;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
matrix<int> m5 = (m[0] * mi);
|
| 92 |
+
if(m5 != m[0]) {
|
| 93 |
+
std::cerr << m[0] << std::endl << "*" << std::endl
|
| 94 |
+
<< mi << std::endl << "=" << std::endl
|
| 95 |
+
<< m5 << std::endl << "rather than" << std::endl
|
| 96 |
+
<< m[0] << std::endl << std::endl;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
matrix<int> m6 = (m[0] * md);
|
| 100 |
+
if(m6 != m[1]) {
|
| 101 |
+
std::cerr << m[0] << std::endl << "*" << std::endl
|
| 102 |
+
<< md << std::endl << "=" << std::endl
|
| 103 |
+
<< m6 << std::endl << "rather than" << std::endl
|
| 104 |
+
<< m[1] << std::endl << std::endl;
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
std::map<std::string, matrix<int> > factors =
|
| 108 |
+
m[5].factor(matrix<int>::LU);
|
| 109 |
+
|
| 110 |
+
std::cout << factors.find("P")->second << "*" << std::endl
|
| 111 |
+
<< m[5] << "=" << std::endl
|
| 112 |
+
<< (m[5] * factors.find("P")->second) << std::endl << std::endl;
|
| 113 |
+
|
| 114 |
+
std::vector< std::pair<double,double> > clip;
|
| 115 |
+
clip.push_back(std::make_pair(-1.0, 1.0));
|
| 116 |
+
clip.push_back(std::make_pair(-1.0, 1.0));
|
| 117 |
+
clip.push_back(std::make_pair(-1.0, 1.0));
|
| 118 |
+
clip.push_back(std::make_pair(1.0, 4.0));
|
| 119 |
+
matrix<double> tp4 = matrix<double>::project(4, clip);
|
| 120 |
+
std::cout << tp4 << std::endl << std::endl;
|
| 121 |
+
|
| 122 |
+
cuboid<double> square(2);
|
| 123 |
+
|
| 124 |
+
matrix<int> reg(3, 1);
|
| 125 |
+
|
| 126 |
+
reg(0, 0) = 0;
|
| 127 |
+
reg(1, 0) = 1;
|
| 128 |
+
reg(2, 0) = 2;
|
| 129 |
+
|
| 130 |
+
matrix<int> trans = reg.transpose();
|
| 131 |
+
|
| 132 |
+
std::cout << reg << std::endl;
|
| 133 |
+
std::cout << trans << std::endl;
|
| 134 |
+
|
| 135 |
+
Polynomial<int> x = std::vector<int>{ 1, 1 };
|
| 136 |
+
Polynomial<int> y = std::vector<int>{ 1, 1 };
|
| 137 |
+
Polynomial<int> z = x * y;
|
| 138 |
+
Polynomial<int> zz = z * x;
|
| 139 |
+
Polynomial<int> zzz = zz * x;
|
| 140 |
+
|
| 141 |
+
std::cout << "(" << x << ") * (" << y << ") = " << z << std::endl;
|
| 142 |
+
std::cout << "(" << z << ") * (" << x << ") = " << zz << std::endl;
|
| 143 |
+
std::cout << "(" << zz << ") * (" << x << ") = " << zzz << std::endl;
|
| 144 |
+
|
| 145 |
+
if(z != Polynomial<int>(std::vector<int>{1, 2, 1})) {
|
| 146 |
+
std::cerr << "first binomial expansion failed" << std::endl;
|
| 147 |
+
return 1;
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
if(zz != Polynomial<int>(std::vector<int>{1, 3, 3, 1})) {
|
| 151 |
+
std::cerr << "second binomial expansion failed" << std::endl;
|
| 152 |
+
return 1;
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
// now try something more complicated
|
| 156 |
+
Polynomial<int> a = std::vector<int>{ -1, 0, 2 };
|
| 157 |
+
Polynomial<int> b = std::vector<int>{ -6, 0, -1 };
|
| 158 |
+
Polynomial<int> c = a * b;
|
| 159 |
+
|
| 160 |
+
std::cout << "(" << a << ") * (" << b << ") = " << c << std::endl;
|
| 161 |
+
if(c != Polynomial<int>(std::vector<int>{6, 0, -11, 0, -2})) {
|
| 162 |
+
std::cerr << "weird expansion failed" << std::endl;
|
| 163 |
+
return 1;
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
Polynomial<int> a1 = std::vector<int>{ -1, 2, 1 };
|
| 167 |
+
Polynomial<int> b1 = std::vector<int>{ 6, -3, 2 };
|
| 168 |
+
Polynomial<int> c1 = a1 * b1;
|
| 169 |
+
|
| 170 |
+
std::cout << "(" << a1 << ") * (" << b1 << ") = " << c1 << std::endl;
|
| 171 |
+
if(c1 != Polynomial<int>(std::vector<int>{-6, 15, -2, 1, 2})) {
|
| 172 |
+
std::cerr << "super weird expansion failed" << std::endl;
|
| 173 |
+
return 1;
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
int eval0 = a1(0);
|
| 177 |
+
if(eval0 != -1) {
|
| 178 |
+
std::cerr << "(" << a1 << ")(0) = " << eval0 << " not -1" << std::endl;
|
| 179 |
+
return 1;
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
int eval1 = a1(1);
|
| 183 |
+
if(eval1 != 2) {
|
| 184 |
+
std::cerr << "(" << a1 << ")(1) = " << eval1 << " not -1" << std::endl;
|
| 185 |
+
return 1;
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
int eval2 = a1(2);
|
| 189 |
+
if(eval2 != 7) {
|
| 190 |
+
std::cerr << "(" << a1 << ")(2) = " << eval2 << " not -1" << std::endl;
|
| 191 |
+
return 1;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
int eval3 = a1(3);
|
| 195 |
+
if(eval3 != 14) {
|
| 196 |
+
std::cerr << "(" << a1 << ")(3) = " << eval3 << " not -1" << std::endl;
|
| 197 |
+
return 1;
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
} catch (matrix<int>::mismatch) {
|
| 202 |
+
std::cerr << "matrices are mismatched" << std::endl;
|
| 203 |
+
return 1;
|
| 204 |
+
} catch (...) {
|
| 205 |
+
std::cerr << "caught error" << std::endl;
|
| 206 |
+
return 1;
|
| 207 |
+
}
|
| 208 |
+
return 0;
|
| 209 |
+
}
|
| 210 |
+
|
pool/shard008/C++/0096507_dicomimagelabel.cpp
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "dicomimagelabel.h"
|
| 2 |
+
#include "imageinstance.h"
|
| 3 |
+
|
| 4 |
+
#include <QFrame>
|
| 5 |
+
#include <QMouseEvent>
|
| 6 |
+
#include <QDrag>
|
| 7 |
+
#include <QMimeData>
|
| 8 |
+
#include <QApplication>
|
| 9 |
+
|
| 10 |
+
DicomImageLabel::DicomImageLabel(ImageInstance *image, QWidget *parent) :
|
| 11 |
+
imageInst(image),
|
| 12 |
+
QLabel(parent)
|
| 13 |
+
{
|
| 14 |
+
setStyleSheet(QString::fromLatin1("background-color: rgb(0, 0, 0);"));
|
| 15 |
+
setFrameShape(QFrame::Box);
|
| 16 |
+
setFrameShadow(QFrame::Plain);
|
| 17 |
+
setLineWidth(2);
|
| 18 |
+
setAlignment(Qt::AlignCenter);
|
| 19 |
+
init();
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
DicomImageLabel::~DicomImageLabel()
|
| 23 |
+
{
|
| 24 |
+
delete imageInst;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
void DicomImageLabel::init()
|
| 28 |
+
{
|
| 29 |
+
if (imageInst) {
|
| 30 |
+
QPixmap pixmap;
|
| 31 |
+
imageInst->setImageType(false);
|
| 32 |
+
imageInst->getPixmap(pixmap);
|
| 33 |
+
setPixmap(pixmap.scaled(IMAGE_LABEL_SIZE-2, IMAGE_LABEL_SIZE-2, Qt::KeepAspectRatio));
|
| 34 |
+
}
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
void DicomImageLabel::setHighlight(bool yes)
|
| 38 |
+
{
|
| 39 |
+
QPalette p = palette();
|
| 40 |
+
if (yes) p.setColor(QPalette::WindowText, Qt::green);
|
| 41 |
+
else p.setColor(QPalette::WindowText, Qt::black);
|
| 42 |
+
setPalette(p);
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
void DicomImageLabel::mousePressEvent(QMouseEvent *e)
|
| 46 |
+
{
|
| 47 |
+
emit imageClicked(this);
|
| 48 |
+
dragOrg = e->pos();
|
| 49 |
+
QLabel::mousePressEvent(e);
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
void DicomImageLabel::mouseMoveEvent(QMouseEvent *e)
|
| 53 |
+
{
|
| 54 |
+
if ((e->buttons() & Qt::LeftButton) &&
|
| 55 |
+
((e->pos()-dragOrg).manhattanLength() > QApplication::startDragDistance())) {
|
| 56 |
+
QDrag *drag = new QDrag(this);
|
| 57 |
+
QMimeData *data = new QMimeData;
|
| 58 |
+
data->setImageData((qulonglong)imageInst);
|
| 59 |
+
drag->setMimeData(data);
|
| 60 |
+
drag->exec(Qt::CopyAction);
|
| 61 |
+
}
|
| 62 |
+
QLabel::mouseMoveEvent(e);
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
void DicomImageLabel::mouseDoubleClickEvent(QMouseEvent *e)
|
| 66 |
+
{
|
| 67 |
+
emit imageDoubleClicked(this);
|
| 68 |
+
QLabel::mouseDoubleClickEvent(e);
|
| 69 |
+
}
|
pool/shard008/C++/0096510_GLTextureRectangle.cpp
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (c) 2009 Stef Busking
|
| 2 |
+
// Distributed under the terms of the MIT License.
|
| 3 |
+
|
| 4 |
+
#include "GLTextureRectangle.h"
|
| 5 |
+
|
| 6 |
+
#include "GLUtility.h"
|
| 7 |
+
|
| 8 |
+
#ifndef NDEBUG
|
| 9 |
+
#include <iostream>
|
| 10 |
+
#endif
|
| 11 |
+
|
| 12 |
+
using namespace std;
|
| 13 |
+
|
| 14 |
+
// ----------------------------------------------------------------------------
|
| 15 |
+
GLTextureRectangle *GLTextureRectangle::New(
|
| 16 |
+
int width, int height, int internalformat,
|
| 17 |
+
int format, int type, void *data)
|
| 18 |
+
{
|
| 19 |
+
// Check if rectangular textures are supported
|
| 20 |
+
if (GLEW_ARB_texture_rectangle)
|
| 21 |
+
{
|
| 22 |
+
GLTextureRectangle *tex = new GLTextureRectangle(
|
| 23 |
+
width, height, internalformat);
|
| 24 |
+
if (!tex->Allocate(format, type, data))
|
| 25 |
+
{
|
| 26 |
+
delete tex;
|
| 27 |
+
return 0;
|
| 28 |
+
}
|
| 29 |
+
return tex;
|
| 30 |
+
}
|
| 31 |
+
else
|
| 32 |
+
{
|
| 33 |
+
#ifndef NDEBUG
|
| 34 |
+
cerr << "GLTextureRectangle: rectangular textures not supported"
|
| 35 |
+
<< endl;
|
| 36 |
+
#endif
|
| 37 |
+
return 0;
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
// ----------------------------------------------------------------------------
|
| 42 |
+
GLTextureRectangle::GLTextureRectangle(
|
| 43 |
+
int width, int height, int internalformat)
|
| 44 |
+
: GLTexture(width, height, internalformat)
|
| 45 |
+
{
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
// ----------------------------------------------------------------------------
|
| 49 |
+
GLTextureRectangle::~GLTextureRectangle()
|
| 50 |
+
{
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
// ----------------------------------------------------------------------------
|
| 54 |
+
bool GLTextureRectangle::Allocate(int format, int type, void *data)
|
| 55 |
+
{
|
| 56 |
+
// Store old binding to avoid messing up the state
|
| 57 |
+
glPushAttrib(GL_TEXTURE_BIT);
|
| 58 |
+
|
| 59 |
+
// Store new params
|
| 60 |
+
this->dataformat = format;
|
| 61 |
+
this->datatype = type;
|
| 62 |
+
|
| 63 |
+
BindToCurrent();
|
| 64 |
+
|
| 65 |
+
// Set texture object parameters
|
| 66 |
+
glTexParameterf(GetTextureTarget(), GL_TEXTURE_MAG_FILTER, GL_LINEAR );
|
| 67 |
+
glTexParameterf(GetTextureTarget(), GL_TEXTURE_MIN_FILTER, GL_LINEAR );
|
| 68 |
+
glTexParameterf(GetTextureTarget(), GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
|
| 69 |
+
glTexParameterf(GetTextureTarget(), GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
|
| 70 |
+
|
| 71 |
+
// Try a proxy allocation to check available memory and parameters
|
| 72 |
+
glTexImage2D(GL_PROXY_TEXTURE_RECTANGLE_ARB, 0, internalformat,
|
| 73 |
+
width, height, 0, format, type, data);
|
| 74 |
+
GLint w;
|
| 75 |
+
glGetTexLevelParameteriv(GL_PROXY_TEXTURE_RECTANGLE_ARB, 0,
|
| 76 |
+
GL_TEXTURE_WIDTH, &w);
|
| 77 |
+
|
| 78 |
+
GLUtility::CheckOpenGLError(
|
| 79 |
+
"GLTextureRectangle: Allocate() - proxy allocation");
|
| 80 |
+
|
| 81 |
+
bool eflag = GLUtility::GetErrorFlag();
|
| 82 |
+
if (w == 0 || eflag)
|
| 83 |
+
{
|
| 84 |
+
#ifndef NDEBUG
|
| 85 |
+
cerr << "GLTextureRectangle: "
|
| 86 |
+
<< "Proxy allocation failed, out of video memory?" << endl;
|
| 87 |
+
#endif
|
| 88 |
+
UnbindCurrent();
|
| 89 |
+
glPopAttrib();
|
| 90 |
+
return false;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
// Allocate the texture
|
| 94 |
+
glTexImage2D(GetTextureTarget(), 0, internalformat,
|
| 95 |
+
width, height, 0, format, type, data);
|
| 96 |
+
GLUtility::CheckOpenGLError("GLTextureRectangle: Allocate - glTexImage2D");
|
| 97 |
+
|
| 98 |
+
UnbindCurrent();
|
| 99 |
+
glPopAttrib();
|
| 100 |
+
|
| 101 |
+
if (GLUtility::GetErrorFlag())
|
| 102 |
+
{
|
| 103 |
+
#ifndef NDEBUG
|
| 104 |
+
cerr << "GLTextureRectangle: "
|
| 105 |
+
<< "An error occurred while allocating the texture" << endl;
|
| 106 |
+
#endif
|
| 107 |
+
GLUtility::ClearOpenGLError();
|
| 108 |
+
return false;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
return true;
|
| 112 |
+
}
|
pool/shard008/C++/0096511_mesh2d.cpp
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2017 Rafael Pagés
|
| 3 |
+
*
|
| 4 |
+
* This file is part of SSMVtex
|
| 5 |
+
*
|
| 6 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 7 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 8 |
+
* in the Software without restriction, including without limitation the rights
|
| 9 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
| 10 |
+
* of the Software, and to permit persons to whom the Software is furnished to do
|
| 11 |
+
* so, subject to the following conditions:
|
| 12 |
+
*
|
| 13 |
+
* The above copyright notice and this permission notice shall be included in all
|
| 14 |
+
* copies or substantial portions of the Software.
|
| 15 |
+
*
|
| 16 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 17 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
| 18 |
+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
| 19 |
+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
| 20 |
+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
| 21 |
+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
| 22 |
+
*
|
| 23 |
+
*/
|
| 24 |
+
|
| 25 |
+
#include "mesh2d.h"
|
| 26 |
+
|
| 27 |
+
Mesh2D::Mesh2D(){
|
| 28 |
+
nVtx_ = nTri_ = 0;
|
| 29 |
+
triarea_ = 0.0;
|
| 30 |
+
bBoxMax_ = bBoxMin_ = Vector2f(0.0,0.0);
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
Mesh2D::~Mesh2D(){
|
| 34 |
+
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
void Mesh2D::addVector(const Vector2f& _vector){
|
| 38 |
+
vtx_.push_back(_vector);
|
| 39 |
+
origVtx_.push_back(-1);
|
| 40 |
+
nVtx_++;
|
| 41 |
+
|
| 42 |
+
// Update the bounding box
|
| 43 |
+
bBoxMin_(0) = bBoxMin_(0) < _vector(0) ? bBoxMin_(0) : _vector(0);
|
| 44 |
+
bBoxMin_(1) = bBoxMin_(1) < _vector(1) ? bBoxMin_(1) : _vector(1);
|
| 45 |
+
bBoxMax_(0) = bBoxMax_(0) > _vector(0) ? bBoxMax_(0) : _vector(0);
|
| 46 |
+
bBoxMax_(1) = bBoxMax_(1) > _vector(1) ? bBoxMax_(1) : _vector(1);
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
void Mesh2D::addVector(const Vector2f& _vector, unsigned int _3dindex){
|
| 50 |
+
vtx_.push_back(_vector);
|
| 51 |
+
origVtx_.push_back((int)_3dindex);
|
| 52 |
+
nVtx_++;
|
| 53 |
+
|
| 54 |
+
// Update the bounding box
|
| 55 |
+
bBoxMin_(0) = bBoxMin_(0) < _vector(0) ? bBoxMin_(0) : _vector(0);
|
| 56 |
+
bBoxMin_(1) = bBoxMin_(1) < _vector(1) ? bBoxMin_(1) : _vector(1);
|
| 57 |
+
bBoxMax_(0) = bBoxMax_(0) > _vector(0) ? bBoxMax_(0) : _vector(0);
|
| 58 |
+
bBoxMax_(1) = bBoxMax_(1) > _vector(1) ? bBoxMax_(1) : _vector(1);
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
void Mesh2D::addTriangle(const Triangle& _triangle){
|
| 62 |
+
tri_.push_back(_triangle);
|
| 63 |
+
origTri_.push_back(-1);
|
| 64 |
+
nTri_++;
|
| 65 |
+
|
| 66 |
+
const float area = triangleArea(tri_.size()-1);
|
| 67 |
+
triarea_ += area;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
void Mesh2D::addTriangle(const Triangle& _triangle, unsigned int _3dindex){
|
| 71 |
+
tri_.push_back(_triangle);
|
| 72 |
+
origTri_.push_back(_3dindex);
|
| 73 |
+
nTri_++;
|
| 74 |
+
|
| 75 |
+
const float area = triangleArea(tri_.size()-1);
|
| 76 |
+
triarea_ += area;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
void Mesh2D::replaceTriangles(const std::vector<Triangle>& _newTriangles){
|
| 80 |
+
|
| 81 |
+
tri_.clear();
|
| 82 |
+
tri_ = _newTriangles;
|
| 83 |
+
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
float Mesh2D::getHypotheticalBBoxArea (const Vector2f& _nv) const {
|
| 87 |
+
const float minx = bBoxMin_(0) < _nv(0) ? bBoxMin_(0) : _nv(0);
|
| 88 |
+
const float maxx = bBoxMax_(0) > _nv(0) ? bBoxMax_(0) : _nv(0);
|
| 89 |
+
const float miny = bBoxMin_(1) < _nv(1) ? bBoxMin_(1) : _nv(1);
|
| 90 |
+
const float maxy = bBoxMax_(1) > _nv(1) ? bBoxMax_(1) : _nv(1);
|
| 91 |
+
return (maxx - minx) * (maxy - miny);
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
void Mesh2D::setOrigVtx(unsigned int _2dindex, unsigned int _3dindex){
|
| 96 |
+
origVtx_[_2dindex] = (int)_3dindex;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
void Mesh2D::setOrigTri(unsigned int _2dindex, unsigned int _3dindex){
|
| 100 |
+
origTri_[_2dindex] = (int)_3dindex;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
int Mesh2D::getOrigVtx(unsigned int _index) const {
|
| 104 |
+
return origVtx_[_index];
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
int Mesh2D::getOrigTri(unsigned int _index) const {
|
| 108 |
+
return origTri_[_index];
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
void Mesh2D::replaceOrigTri(const std::vector<int>& _newOrigTri){
|
| 112 |
+
origTri_.clear();
|
| 113 |
+
origTri_ = _newOrigTri;
|
| 114 |
+
nTri_ = tri_.size();
|
| 115 |
+
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
float Mesh2D::triangleArea(unsigned int _v0, unsigned int _v1, unsigned int _v2) const{
|
| 119 |
+
|
| 120 |
+
const Vector2f v1v0 = vtx_[_v1] - vtx_[_v0];
|
| 121 |
+
const Vector2f v2v0 = vtx_[_v2] - vtx_[_v0];
|
| 122 |
+
|
| 123 |
+
return (v1v0(0) * v2v0(1) - v1v0(1) * v2v0(0)) * 0.5;
|
| 124 |
+
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
float Mesh2D::triangleArea(unsigned int _index) const {
|
| 128 |
+
|
| 129 |
+
return triangleArea(tri_[_index].getIndex(0), tri_[_index].getIndex(1), tri_[_index].getIndex(2));
|
| 130 |
+
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
float Mesh2D::triangleArea(const Vector2f &_v0, const Vector2f &_v1, const Vector2f &_v2){
|
| 134 |
+
|
| 135 |
+
const Vector2f v1v0 = _v1 - _v0;
|
| 136 |
+
const Vector2f v2v0 = _v2 - _v0;
|
| 137 |
+
|
| 138 |
+
return (v1v0(0) * v2v0(1) - v1v0(1) * v2v0(0)) * 0.5;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
void Mesh2D::displaceMesh(const Vector2f& _v){
|
| 143 |
+
|
| 144 |
+
std::vector<Vector2f>::iterator it;
|
| 145 |
+
for (it = vtx_.begin(); it != vtx_.end(); ++it){
|
| 146 |
+
(*it) = (*it) + _v;
|
| 147 |
+
}
|
| 148 |
+
bBoxMax_ = bBoxMax_ + _v;
|
| 149 |
+
bBoxMin_ = bBoxMin_ + _v;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
void Mesh2D::rotateMesh(){
|
| 153 |
+
std::vector<Vector2f>::iterator it;
|
| 154 |
+
for (it = vtx_.begin(); it != vtx_.end(); ++it){
|
| 155 |
+
const Vector2f thisv = (*it);
|
| 156 |
+
Vector2f rot;
|
| 157 |
+
// x' = -y ; y' = x
|
| 158 |
+
rot(0) = (-1) * thisv(1);
|
| 159 |
+
rot(1) = thisv(0);
|
| 160 |
+
(*it) = rot;
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
// The new min and max values are the opposite
|
| 164 |
+
// corners of the bounding box
|
| 165 |
+
const Vector2f b1 (bBoxMin_(0), bBoxMax_(1));
|
| 166 |
+
const Vector2f b2 (bBoxMax_(0), bBoxMin_(1));
|
| 167 |
+
// And now we rotate them
|
| 168 |
+
bBoxMin_(0) = (-1) * b1(1);
|
| 169 |
+
bBoxMin_(1) = b1(0);
|
| 170 |
+
bBoxMax_(0) = (-1) * b2(1);
|
| 171 |
+
bBoxMax_(1) = b2(0);
|
| 172 |
+
|
| 173 |
+
// Vertices are displaced so the mesh is aligned with the origin
|
| 174 |
+
const Vector2f origin(0.0,0.0);
|
| 175 |
+
displaceMesh(origin - bBoxMin_);
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
void Mesh2D::addOffset2BoundingBox(float _offset){
|
| 179 |
+
|
| 180 |
+
const Vector2f off(_offset, _offset);
|
| 181 |
+
const Vector2f aux = bBoxMax_ + off;
|
| 182 |
+
bBoxMax_ = aux;
|
| 183 |
+
|
| 184 |
+
std::vector<Vector2f>::iterator it;
|
| 185 |
+
for (it = vtx_.begin(); it != vtx_.end(); ++it){
|
| 186 |
+
(*it) = (*it) + off * 0.5;
|
| 187 |
+
}
|
| 188 |
+
}
|
| 189 |
+
|
pool/shard008/C++/0096512_CWE590_Free_Memory_Not_on_Heap__delete_array_int_static_67b.cpp
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* TEMPLATE GENERATED TESTCASE FILE
|
| 2 |
+
Filename: CWE590_Free_Memory_Not_on_Heap__delete_array_int_static_67b.cpp
|
| 3 |
+
Label Definition File: CWE590_Free_Memory_Not_on_Heap__delete_array.label.xml
|
| 4 |
+
Template File: sources-sink-67b.tmpl.cpp
|
| 5 |
+
*/
|
| 6 |
+
/*
|
| 7 |
+
* @description
|
| 8 |
+
* CWE: 590 Free Memory Not on Heap
|
| 9 |
+
* BadSource: static Data buffer is declared static on the stack
|
| 10 |
+
* GoodSource: Allocate memory on the heap
|
| 11 |
+
* Sinks:
|
| 12 |
+
* BadSink : Print then free data
|
| 13 |
+
* Flow Variant: 67 Data flow: data passed in a struct from one function to another in different source files
|
| 14 |
+
*
|
| 15 |
+
* */
|
| 16 |
+
|
| 17 |
+
#include "std_testcase.h"
|
| 18 |
+
|
| 19 |
+
#include <wchar.h>
|
| 20 |
+
|
| 21 |
+
namespace CWE590_Free_Memory_Not_on_Heap__delete_array_int_static_67
|
| 22 |
+
{
|
| 23 |
+
|
| 24 |
+
typedef struct _structType
|
| 25 |
+
{
|
| 26 |
+
int * structFirst;
|
| 27 |
+
} structType;
|
| 28 |
+
|
| 29 |
+
#ifndef OMITBAD
|
| 30 |
+
|
| 31 |
+
void badSink(structType myStruct)
|
| 32 |
+
{
|
| 33 |
+
int * data = myStruct.structFirst;
|
| 34 |
+
printIntLine(data[0]);
|
| 35 |
+
/* POTENTIAL FLAW: Possibly deallocating memory allocated on the stack */
|
| 36 |
+
delete [] data;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
#endif /* OMITBAD */
|
| 40 |
+
|
| 41 |
+
#ifndef OMITGOOD
|
| 42 |
+
|
| 43 |
+
/* goodG2B uses the GoodSource with the BadSink */
|
| 44 |
+
void goodG2BSink(structType myStruct)
|
| 45 |
+
{
|
| 46 |
+
int * data = myStruct.structFirst;
|
| 47 |
+
printIntLine(data[0]);
|
| 48 |
+
/* POTENTIAL FLAW: Possibly deallocating memory allocated on the stack */
|
| 49 |
+
delete [] data;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
#endif /* OMITGOOD */
|
| 53 |
+
|
| 54 |
+
} /* close namespace */
|
pool/shard008/C++/0096515_TestReverse.cpp
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <stx/algorithm/Reverse.h>
|
| 2 |
+
#include <gtest/gtest.h>
|
| 3 |
+
|
| 4 |
+
testing::AssertionResult AreEqual(int* a, int* b, int count)
|
| 5 |
+
{
|
| 6 |
+
for (int i = 0; i < count; ++i) {
|
| 7 |
+
if (a[i] != b[i]) {
|
| 8 |
+
return testing::AssertionFailure() << " mismatch at index " << i;
|
| 9 |
+
}
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
return testing::AssertionSuccess();
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
TEST(Reverse, Basic)
|
| 16 |
+
{
|
| 17 |
+
int a[] = { 1, 2, 3 };
|
| 18 |
+
int b[] = { 3, 2, 1 };
|
| 19 |
+
int count = sizeof(a) / sizeof(a[0]);
|
| 20 |
+
|
| 21 |
+
stx::Reverse(a, a + count);
|
| 22 |
+
|
| 23 |
+
EXPECT_TRUE(AreEqual(a, b, count));
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
TEST(Reverse, DoubleReverse)
|
| 27 |
+
{
|
| 28 |
+
int a[] = { 1, 2, 3 };
|
| 29 |
+
int b[] = { 1, 2, 3 };
|
| 30 |
+
int count = sizeof(a) / sizeof(a[0]);
|
| 31 |
+
|
| 32 |
+
stx::Reverse(a, a + count);
|
| 33 |
+
stx::Reverse(a, a + count);
|
| 34 |
+
|
| 35 |
+
EXPECT_TRUE(AreEqual(a , b, count));
|
| 36 |
+
}
|
| 37 |
+
|
pool/shard008/C++/0096517_ST_NUCLEO-F042K6-spis.cpp
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* \file
|
| 3 |
+
* \brief Definitions of low-level SPI master drivers for SPIv2 in ST,NUCLEO-F042K6 (ST,STM32F042K6 chip)
|
| 4 |
+
*
|
| 5 |
+
* \author Copyright (C) 2016-2020 Kamil Szczygiel https://distortec.com https://freddiechopin.info
|
| 6 |
+
*
|
| 7 |
+
* \par License
|
| 8 |
+
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not
|
| 9 |
+
* distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
| 10 |
+
*
|
| 11 |
+
* \warning
|
| 12 |
+
* Automatically generated file - do not edit!
|
| 13 |
+
*/
|
| 14 |
+
|
| 15 |
+
#include "distortos/chip/spis.hpp"
|
| 16 |
+
|
| 17 |
+
#include "distortos/chip/dmas.hpp"
|
| 18 |
+
#include "distortos/chip/PinInitializer.hpp"
|
| 19 |
+
#include "distortos/chip/SpiMasterLowLevelDmaBased.hpp"
|
| 20 |
+
#include "distortos/chip/SpiMasterLowLevelInterruptBased.hpp"
|
| 21 |
+
#include "distortos/chip/STM32-SPIv2-SpiPeripheral.hpp"
|
| 22 |
+
|
| 23 |
+
#include "distortos/BIND_LOW_LEVEL_INITIALIZER.h"
|
| 24 |
+
|
| 25 |
+
/**
|
| 26 |
+
* \brief Generates name of DMA channel object in the form `dma<dmaId>Channel<channelId>`.
|
| 27 |
+
*
|
| 28 |
+
* \param [in] dmaId is a DMA identifier
|
| 29 |
+
* \param [in] channelId is a DMA channel identifier
|
| 30 |
+
*/
|
| 31 |
+
|
| 32 |
+
#define DMA_CHANNEL(dmaId, channelId) CONCATENATE4(dma, dmaId, Channel, channelId)
|
| 33 |
+
|
| 34 |
+
namespace distortos
|
| 35 |
+
{
|
| 36 |
+
|
| 37 |
+
namespace chip
|
| 38 |
+
{
|
| 39 |
+
|
| 40 |
+
#ifdef DISTORTOS_CHIP_SPI1_ENABLE
|
| 41 |
+
|
| 42 |
+
/*---------------------------------------------------------------------------------------------------------------------+
|
| 43 |
+
| SPI1
|
| 44 |
+
+---------------------------------------------------------------------------------------------------------------------*/
|
| 45 |
+
|
| 46 |
+
namespace
|
| 47 |
+
{
|
| 48 |
+
|
| 49 |
+
/**
|
| 50 |
+
* \brief Low-level chip initializer for SPI1
|
| 51 |
+
*
|
| 52 |
+
* This function is called before constructors for global and static objects via BIND_LOW_LEVEL_INITIALIZER().
|
| 53 |
+
*/
|
| 54 |
+
|
| 55 |
+
void spi1LowLevelInitializer()
|
| 56 |
+
{
|
| 57 |
+
#if defined(RCC_APB1ENR_SPI1EN)
|
| 58 |
+
RCC->APB1ENR |= RCC_APB1ENR_SPI1EN;
|
| 59 |
+
#elif defined(RCC_APB1ENR1_SPI1EN)
|
| 60 |
+
RCC->APB1ENR1 |= RCC_APB1ENR1_SPI1EN;
|
| 61 |
+
#elif defined(RCC_APB2ENR_SPI1EN)
|
| 62 |
+
RCC->APB2ENR |= RCC_APB2ENR_SPI1EN;
|
| 63 |
+
#else
|
| 64 |
+
#error "Unsupported bus for SPI1!"
|
| 65 |
+
#endif
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
BIND_LOW_LEVEL_INITIALIZER(50, spi1LowLevelInitializer);
|
| 69 |
+
|
| 70 |
+
/// raw SPI1 peripheral
|
| 71 |
+
const SpiPeripheral spi1Peripheral {SPI1_BASE};
|
| 72 |
+
|
| 73 |
+
} // namespace
|
| 74 |
+
|
| 75 |
+
#ifdef DISTORTOS_CHIP_SPI1_DMA_BASED
|
| 76 |
+
|
| 77 |
+
SpiMasterLowLevelDmaBased spi1
|
| 78 |
+
{
|
| 79 |
+
spi1Peripheral,
|
| 80 |
+
DMA_CHANNEL(DISTORTOS_CHIP_SPI1_RX_DMA, DISTORTOS_CHIP_SPI1_RX_DMA_CHANNEL),
|
| 81 |
+
DISTORTOS_CHIP_SPI1_RX_DMA_REQUEST,
|
| 82 |
+
DMA_CHANNEL(DISTORTOS_CHIP_SPI1_TX_DMA, DISTORTOS_CHIP_SPI1_TX_DMA_CHANNEL),
|
| 83 |
+
DISTORTOS_CHIP_SPI1_TX_DMA_REQUEST
|
| 84 |
+
};
|
| 85 |
+
|
| 86 |
+
#else // !def DISTORTOS_CHIP_SPI1_DMA_BASED
|
| 87 |
+
|
| 88 |
+
SpiMasterLowLevelInterruptBased spi1 {spi1Peripheral};
|
| 89 |
+
|
| 90 |
+
/**
|
| 91 |
+
* \brief SPI1 interrupt handler
|
| 92 |
+
*/
|
| 93 |
+
|
| 94 |
+
extern "C" void SPI1_IRQHandler()
|
| 95 |
+
{
|
| 96 |
+
spi1.interruptHandler();
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
#endif // !def DISTORTOS_CHIP_SPI1_DMA_BASED
|
| 100 |
+
|
| 101 |
+
#endif // def DISTORTOS_CHIP_SPI1_ENABLE
|
| 102 |
+
|
| 103 |
+
} // namespace chip
|
| 104 |
+
|
| 105 |
+
} // namespace distortos
|
pool/shard008/C++/0096519_tcpMessageClient.cpp
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/***
|
| 2 |
+
* Inferno Engine v4 2015-2017
|
| 3 |
+
* Written by Tomasz "Rex Dex" Jonarski
|
| 4 |
+
*
|
| 5 |
+
* [#filter: messages\tcp #]
|
| 6 |
+
***/
|
| 7 |
+
|
| 8 |
+
#include "build.h"
|
| 9 |
+
#include "tcpMessageClient.h"
|
| 10 |
+
#include "tcpMessageInternal.h"
|
| 11 |
+
|
| 12 |
+
#include "messageReassembler.h"
|
| 13 |
+
#include "messagePool.h"
|
| 14 |
+
#include "messageObjectRepository.h"
|
| 15 |
+
#include "messageObjectExecutor.h"
|
| 16 |
+
#include "messageReplicator.h"
|
| 17 |
+
|
| 18 |
+
#include "base/replication/include/replicationDataModelRepository.h"
|
| 19 |
+
|
| 20 |
+
namespace base
|
| 21 |
+
{
|
| 22 |
+
namespace net
|
| 23 |
+
{
|
| 24 |
+
|
| 25 |
+
//--
|
| 26 |
+
|
| 27 |
+
RTTI_BEGIN_TYPE_NOCOPY_CLASS(TcpMessageClient);
|
| 28 |
+
RTTI_END_TYPE();
|
| 29 |
+
|
| 30 |
+
TcpMessageClient::TcpMessageClient()
|
| 31 |
+
: m_connectionId(1)
|
| 32 |
+
, m_client(this)
|
| 33 |
+
, m_fatalError(false)
|
| 34 |
+
{
|
| 35 |
+
m_objects = CreateSharedPtr<MessageObjectRepository>();
|
| 36 |
+
m_models = CreateSharedPtr<replication::DataModelRepository>();
|
| 37 |
+
|
| 38 |
+
m_pool.create();
|
| 39 |
+
m_replicator.create(m_models, m_objects);
|
| 40 |
+
m_executor.create(MessageConnection::GetStaticClass());
|
| 41 |
+
m_reassembler.create(&TcpMessageReassemblerHandler::GetInstance());
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
TcpMessageClient::~TcpMessageClient()
|
| 45 |
+
{}
|
| 46 |
+
|
| 47 |
+
///---
|
| 48 |
+
|
| 49 |
+
Bool TcpMessageClient::connect(const socket::Address& address)
|
| 50 |
+
{
|
| 51 |
+
if (!m_client.connect(address))
|
| 52 |
+
return false;
|
| 53 |
+
|
| 54 |
+
m_connectionId += 1;
|
| 55 |
+
m_fatalError = false;
|
| 56 |
+
return true;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
Bool TcpMessageClient::isConnected() const
|
| 60 |
+
{
|
| 61 |
+
return m_client.isConnected() && !m_fatalError;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
Uint32 TcpMessageClient::getConnectionId() const
|
| 65 |
+
{
|
| 66 |
+
return m_connectionId;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
StringBuf TcpMessageClient::getLocalAddress() const
|
| 70 |
+
{
|
| 71 |
+
TempString str;
|
| 72 |
+
m_client.getLocalAddress().print(str);
|
| 73 |
+
return str;
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
StringBuf TcpMessageClient::getRemoteAddress() const
|
| 77 |
+
{
|
| 78 |
+
TempString str;
|
| 79 |
+
m_client.getRemoteAddress().print(str);
|
| 80 |
+
return str;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
///---
|
| 84 |
+
|
| 85 |
+
Uint32 TcpMessageClient::allocObjectId()
|
| 86 |
+
{
|
| 87 |
+
return m_objects->allocateObjectId();
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
void TcpMessageClient::attachObject(const Uint32 id, const obj::ObjectPtr& ptr)
|
| 91 |
+
{
|
| 92 |
+
m_objects->attachObject(id, ptr);
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
void TcpMessageClient::dettachObject(const Uint32 id)
|
| 96 |
+
{
|
| 97 |
+
m_objects->detachObject(id);
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
obj::ObjectPtr TcpMessageClient::resolveObject(const Uint32 id) const
|
| 101 |
+
{
|
| 102 |
+
return m_objects->resolveObject(id);
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
//---
|
| 106 |
+
|
| 107 |
+
void TcpMessageClient::executePendingMessages()
|
| 108 |
+
{
|
| 109 |
+
m_executor->executeQueuedMessges(getSharedFromThis());
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
//---
|
| 113 |
+
|
| 114 |
+
void TcpMessageClient::sendPtr(Uint32 targetObjectId, const void* messageData, const rtti::IType* messageClass)
|
| 115 |
+
{
|
| 116 |
+
// if we are in error state don't do anything more
|
| 117 |
+
if (m_fatalError)
|
| 118 |
+
return;
|
| 119 |
+
|
| 120 |
+
TcpMessageClientReplicatorDataSink dataSink(m_client);
|
| 121 |
+
m_replicator->send(targetObjectId, messageData, messageClass, &dataSink);
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
void TcpMessageClient::handleConnectionClosed(socket::tcp::Client* client, const socket::Address& address)
|
| 125 |
+
{
|
| 126 |
+
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
void TcpMessageClient::handleConnectionData(socket::tcp::Client* client, const socket::Address& address, const void* data, const Uint32 dataSize)
|
| 130 |
+
{
|
| 131 |
+
// if we are in error state don't do anything more
|
| 132 |
+
if (m_fatalError)
|
| 133 |
+
return;
|
| 134 |
+
|
| 135 |
+
// push data to reassembler, we will buffer it until we can assemble a packet
|
| 136 |
+
if (!m_reassembler->pushData(data, dataSize))
|
| 137 |
+
{
|
| 138 |
+
TRACE_ERROR("TcpMessageClient: Fatal error on message reassembly from '{}'", m_client.getRemoteAddress());
|
| 139 |
+
m_fatalError = true;
|
| 140 |
+
return;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
// process messages
|
| 144 |
+
Bool needsMore = true;
|
| 145 |
+
while (needsMore)
|
| 146 |
+
{
|
| 147 |
+
const Uint8* messageData = nullptr;
|
| 148 |
+
Uint32 messageSize = 0;
|
| 149 |
+
switch (m_reassembler->reassemble(messageData, messageSize))
|
| 150 |
+
{
|
| 151 |
+
case ReassemblerResult::NeedsMore:
|
| 152 |
+
{
|
| 153 |
+
needsMore = false;
|
| 154 |
+
break;
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
case ReassemblerResult::Valid:
|
| 158 |
+
{
|
| 159 |
+
const auto* header = (const TcpMessageTransportHeader*) messageData;
|
| 160 |
+
|
| 161 |
+
TRACE_INFO("TcpMessageClient: reassembled message, size {} from '{}'", header->m_length, m_client.getRemoteAddress());
|
| 162 |
+
|
| 163 |
+
TcpMessageExecutorForwarder executor(*m_executor, *m_pool, *m_objects);
|
| 164 |
+
m_replicator->processMessageData(messageData + sizeof(TcpMessageTransportHeader), header->m_length - sizeof(TcpMessageTransportHeader), &executor);
|
| 165 |
+
break;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
case ReassemblerResult::Corruption:
|
| 169 |
+
{
|
| 170 |
+
TRACE_ERROR("TcpMessageClient: Fatal error on message reassembly from '{}'", m_client.getRemoteAddress());
|
| 171 |
+
m_fatalError = true;
|
| 172 |
+
break;
|
| 173 |
+
}
|
| 174 |
+
}
|
| 175 |
+
}
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
//---
|
| 179 |
+
|
| 180 |
+
} // net
|
| 181 |
+
} // base
|
pool/shard008/C++/0096521_basic_sspi_auth.cc
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C) 1996-2015 The Squid Software Foundation and contributors
|
| 3 |
+
*
|
| 4 |
+
* Squid software is distributed under GPLv2+ license and includes
|
| 5 |
+
* contributions from numerous individuals and organizations.
|
| 6 |
+
* Please see the COPYING and CONTRIBUTORS files for details.
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
/*
|
| 10 |
+
NT_auth - Version 2.0
|
| 11 |
+
|
| 12 |
+
Returns OK for a successful authentication, or ERR upon error.
|
| 13 |
+
|
| 14 |
+
Guido Serassio, Torino - Italy
|
| 15 |
+
|
| 16 |
+
Uses code from -
|
| 17 |
+
Antonino Iannella 2000
|
| 18 |
+
Andrew Tridgell 1997
|
| 19 |
+
Richard Sharpe 1996
|
| 20 |
+
Bill Welliver 1999
|
| 21 |
+
|
| 22 |
+
* Distributed freely under the terms of the GNU General Public License,
|
| 23 |
+
* version 2 or later. See the file COPYING for licensing details
|
| 24 |
+
*
|
| 25 |
+
* This program is distributed in the hope that it will be useful,
|
| 26 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 27 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 28 |
+
* GNU General Public License for more details.
|
| 29 |
+
|
| 30 |
+
* You should have received a copy of the GNU General Public License
|
| 31 |
+
* along with this program; if not, write to the Free Software
|
| 32 |
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
|
| 33 |
+
*/
|
| 34 |
+
|
| 35 |
+
#include "squid.h"
|
| 36 |
+
#include "helpers/defines.h"
|
| 37 |
+
#include "rfc1738.h"
|
| 38 |
+
#include "util.h"
|
| 39 |
+
#include "valid.h"
|
| 40 |
+
|
| 41 |
+
#if GETOPT_H
|
| 42 |
+
#include <getopt.h>
|
| 43 |
+
#endif
|
| 44 |
+
|
| 45 |
+
/* Check if we try to compile on a Windows Platform */
|
| 46 |
+
#if !_SQUID_WINDOWS_
|
| 47 |
+
/* NON Windows Platform !!! */
|
| 48 |
+
#error NON WINDOWS PLATFORM
|
| 49 |
+
#endif
|
| 50 |
+
|
| 51 |
+
static char NTGroup[256];
|
| 52 |
+
char * NTAllowedGroup;
|
| 53 |
+
char * NTDisAllowedGroup;
|
| 54 |
+
int UseDisallowedGroup = 0;
|
| 55 |
+
int UseAllowedGroup = 0;
|
| 56 |
+
int debug_enabled = 0;
|
| 57 |
+
|
| 58 |
+
/*
|
| 59 |
+
* options:
|
| 60 |
+
* -A can specify a Windows Local Group name allowed to authenticate.
|
| 61 |
+
* -D can specify a Windows Local Group name not allowed to authenticate.
|
| 62 |
+
* -O can specify the default Domain against to authenticate.
|
| 63 |
+
*/
|
| 64 |
+
static void
|
| 65 |
+
usage(const char *name)
|
| 66 |
+
{
|
| 67 |
+
fprintf(stderr, "Usage:\n%s [-A|D UserGroup][-O DefaultDomain][-d]\n"
|
| 68 |
+
"-A can specify a Windows Local Group name allowed to authenticate\n"
|
| 69 |
+
"-D can specify a Windows Local Group name not allowed to authenticate\n"
|
| 70 |
+
"-O can specify the default Domain against to authenticate\n"
|
| 71 |
+
"-d enable debugging.\n"
|
| 72 |
+
"-h this message\n\n",
|
| 73 |
+
name);
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
void
|
| 77 |
+
process_options(int argc, char *argv[])
|
| 78 |
+
{
|
| 79 |
+
int opt;
|
| 80 |
+
while (-1 != (opt = getopt(argc, argv, "dhA:D:O:"))) {
|
| 81 |
+
switch (opt) {
|
| 82 |
+
case 'A':
|
| 83 |
+
safe_free(NTAllowedGroup);
|
| 84 |
+
NTAllowedGroup=xstrdup(optarg);
|
| 85 |
+
UseAllowedGroup = 1;
|
| 86 |
+
break;
|
| 87 |
+
case 'D':
|
| 88 |
+
safe_free(NTDisAllowedGroup);
|
| 89 |
+
NTDisAllowedGroup=xstrdup(optarg);
|
| 90 |
+
UseDisallowedGroup = 1;
|
| 91 |
+
break;
|
| 92 |
+
case 'O':
|
| 93 |
+
strncpy(Default_NTDomain, optarg, DNLEN);
|
| 94 |
+
break;
|
| 95 |
+
case 'd':
|
| 96 |
+
debug_enabled = 1;
|
| 97 |
+
break;
|
| 98 |
+
case 'h':
|
| 99 |
+
usage(argv[0]);
|
| 100 |
+
exit(0);
|
| 101 |
+
case '?':
|
| 102 |
+
opt = optopt;
|
| 103 |
+
/* fall thru to default */
|
| 104 |
+
default:
|
| 105 |
+
fprintf(stderr, "FATAL: Unknown option: -%c\n", opt);
|
| 106 |
+
usage(argv[0]);
|
| 107 |
+
exit(1);
|
| 108 |
+
}
|
| 109 |
+
}
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
/* Main program for simple authentication.
|
| 113 |
+
Scans and checks for Squid input, and attempts to validate the user.
|
| 114 |
+
*/
|
| 115 |
+
int
|
| 116 |
+
main(int argc, char **argv)
|
| 117 |
+
{
|
| 118 |
+
char wstr[HELPER_INPUT_BUFFER];
|
| 119 |
+
char username[256];
|
| 120 |
+
char password[256];
|
| 121 |
+
char *p;
|
| 122 |
+
int err = 0;
|
| 123 |
+
|
| 124 |
+
process_options(argc, argv);
|
| 125 |
+
|
| 126 |
+
if (LoadSecurityDll(SSP_BASIC, NTLM_PACKAGE_NAME) == NULL) {
|
| 127 |
+
fprintf(stderr, "FATAL: can't initialize SSPI, exiting.\n");
|
| 128 |
+
exit(1);
|
| 129 |
+
}
|
| 130 |
+
debug("SSPI initialized OK\n");
|
| 131 |
+
|
| 132 |
+
atexit(UnloadSecurityDll);
|
| 133 |
+
|
| 134 |
+
/* initialize FDescs */
|
| 135 |
+
setbuf(stdout, NULL);
|
| 136 |
+
setbuf(stderr, NULL);
|
| 137 |
+
|
| 138 |
+
while (fgets(wstr, HELPER_INPUT_BUFFER, stdin) != NULL) {
|
| 139 |
+
|
| 140 |
+
if (NULL == strchr(wstr, '\n')) {
|
| 141 |
+
err = 1;
|
| 142 |
+
continue;
|
| 143 |
+
}
|
| 144 |
+
if (err) {
|
| 145 |
+
SEND_ERR("Oversized message");
|
| 146 |
+
err = 0;
|
| 147 |
+
fflush(stdout);
|
| 148 |
+
continue;
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
if ((p = strchr(wstr, '\n')) != NULL)
|
| 152 |
+
*p = '\0'; /* strip \n */
|
| 153 |
+
if ((p = strchr(wstr, '\r')) != NULL)
|
| 154 |
+
*p = '\0'; /* strip \r */
|
| 155 |
+
/* Clear any current settings */
|
| 156 |
+
username[0] = '\0';
|
| 157 |
+
password[0] = '\0';
|
| 158 |
+
sscanf(wstr, "%s %s", username, password); /* Extract parameters */
|
| 159 |
+
|
| 160 |
+
debug("Got %s from Squid\n", wstr);
|
| 161 |
+
|
| 162 |
+
/* Check for invalid or blank entries */
|
| 163 |
+
if ((username[0] == '\0') || (password[0] == '\0')) {
|
| 164 |
+
SEND_ERR("Invalid Request");
|
| 165 |
+
fflush(stdout);
|
| 166 |
+
continue;
|
| 167 |
+
}
|
| 168 |
+
rfc1738_unescape(username);
|
| 169 |
+
rfc1738_unescape(password);
|
| 170 |
+
|
| 171 |
+
debug("Trying to validate; %s %s\n", username, password);
|
| 172 |
+
|
| 173 |
+
if (Valid_User(username, password, NTGroup) == NTV_NO_ERROR)
|
| 174 |
+
SEND_OK("");
|
| 175 |
+
else
|
| 176 |
+
SEND_ERR(errormsg);
|
| 177 |
+
err = 0;
|
| 178 |
+
fflush(stdout);
|
| 179 |
+
}
|
| 180 |
+
return 0;
|
| 181 |
+
}
|
| 182 |
+
|
pool/shard008/C++/0096533_kate.cpp
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
mkvmerge -- utility for splicing together matroska files
|
| 3 |
+
from component media subtypes
|
| 4 |
+
|
| 5 |
+
Distributed under the GPL
|
| 6 |
+
see the file COPYING for details
|
| 7 |
+
or visit http://www.gnu.org/copyleft/gpl.html
|
| 8 |
+
|
| 9 |
+
Kate helper functions
|
| 10 |
+
|
| 11 |
+
Written by ogg.k.ogg.k <ogg.k.ogg.k@googlemail.com>.
|
| 12 |
+
Adapted from code by Moritz Bunkus <moritz@bunkus.org>.
|
| 13 |
+
*/
|
| 14 |
+
|
| 15 |
+
#include "common/common_pch.h"
|
| 16 |
+
|
| 17 |
+
#include "common/bit_cursor.h"
|
| 18 |
+
#include "common/kate.h"
|
| 19 |
+
|
| 20 |
+
kate_identification_header_t::kate_identification_header_t() {
|
| 21 |
+
memset(this, 0, sizeof(kate_identification_header_t));
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
static int32_t
|
| 25 |
+
get_bits32_le(bit_reader_c &bc) {
|
| 26 |
+
int32_t v = 0;
|
| 27 |
+
|
| 28 |
+
for (int n = 0; n < 4; ++n) {
|
| 29 |
+
v |= bc.get_bits(8) << (n * 8);
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
return v;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
void
|
| 36 |
+
kate_parse_identification_header(const unsigned char *buffer,
|
| 37 |
+
int size,
|
| 38 |
+
kate_identification_header_t &header) {
|
| 39 |
+
bit_reader_c bc(buffer, size);
|
| 40 |
+
int i;
|
| 41 |
+
|
| 42 |
+
header.headertype = bc.get_bits(8);
|
| 43 |
+
if (KATE_HEADERTYPE_IDENTIFICATION != header.headertype)
|
| 44 |
+
throw mtx::kate::header_parsing_x(boost::format(Y("Wrong header type: 0x%|1$02x| != 0x%|2$02x|")) % header.headertype % KATE_HEADERTYPE_IDENTIFICATION);
|
| 45 |
+
|
| 46 |
+
for (i = 0; 7 > i; ++i)
|
| 47 |
+
header.kate_string[i] = bc.get_bits(8);
|
| 48 |
+
if (memcmp(header.kate_string, "kate\0\0\0", 7))
|
| 49 |
+
throw mtx::kate::header_parsing_x(boost::format(Y("Wrong identification string: '%|1$7s|' != 'kate\\0\\0\\0'")) % header.kate_string); /* won't print NULs well, but hey */
|
| 50 |
+
|
| 51 |
+
bc.get_bits(8); // we don't need those - they are reserved
|
| 52 |
+
|
| 53 |
+
header.vmaj = bc.get_bits(8);
|
| 54 |
+
header.vmin = bc.get_bits(8);
|
| 55 |
+
|
| 56 |
+
// do not test vmin, as the header is stable for minor version changes
|
| 57 |
+
static const int supported_version = 0;
|
| 58 |
+
if (header.vmaj > supported_version)
|
| 59 |
+
throw mtx::kate::header_parsing_x(boost::format(Y("Wrong Kate version: %1%.%2% > %3%.x")) % header.vmaj % header.vmin % supported_version);
|
| 60 |
+
|
| 61 |
+
header.nheaders = bc.get_bits(8);
|
| 62 |
+
header.tenc = bc.get_bits(8);
|
| 63 |
+
header.tdir = bc.get_bits(8);
|
| 64 |
+
bc.get_bits(8); // we don't need those - they are reserved
|
| 65 |
+
header.kfgshift = bc.get_bits(8);
|
| 66 |
+
|
| 67 |
+
bc.skip_bits(32); // from bitstream 0.3, these 32 bits are allocated
|
| 68 |
+
bc.skip_bits(32); // we don't need those - they are reserved
|
| 69 |
+
|
| 70 |
+
header.gnum = get_bits32_le(bc);
|
| 71 |
+
header.gden = get_bits32_le(bc);
|
| 72 |
+
|
| 73 |
+
for (i = 0; 16 > i; ++i)
|
| 74 |
+
header.language[i] = bc.get_bits(8);
|
| 75 |
+
if (header.language[15])
|
| 76 |
+
throw mtx::kate::header_parsing_x(Y("Language is not NUL terminated"));
|
| 77 |
+
for (i = 0; 16 > i; ++i)
|
| 78 |
+
header.category[i] = bc.get_bits(8);
|
| 79 |
+
if (header.category[15])
|
| 80 |
+
throw mtx::kate::header_parsing_x(Y("Category is not NUL terminated"));
|
| 81 |
+
}
|
pool/shard008/C++/0096536_pepper_broker.cc
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 "content/renderer/pepper/pepper_broker.h"
|
| 6 |
+
|
| 7 |
+
#include "build/build_config.h"
|
| 8 |
+
#include "content/renderer/pepper/pepper_proxy_channel_delegate_impl.h"
|
| 9 |
+
#include "content/renderer/pepper/plugin_module.h"
|
| 10 |
+
#include "content/renderer/pepper/ppb_broker_impl.h"
|
| 11 |
+
#include "content/renderer/pepper/renderer_restrict_dispatch_group.h"
|
| 12 |
+
#include "ipc/ipc_channel_handle.h"
|
| 13 |
+
#include "ppapi/proxy/broker_dispatcher.h"
|
| 14 |
+
#include "ppapi/proxy/ppapi_messages.h"
|
| 15 |
+
#include "ppapi/shared_impl/platform_file.h"
|
| 16 |
+
|
| 17 |
+
#if defined(OS_WIN)
|
| 18 |
+
#include <windows.h>
|
| 19 |
+
#endif
|
| 20 |
+
|
| 21 |
+
namespace content {
|
| 22 |
+
|
| 23 |
+
namespace {
|
| 24 |
+
|
| 25 |
+
base::SyncSocket::Handle DuplicateHandle(base::SyncSocket::Handle handle) {
|
| 26 |
+
base::SyncSocket::Handle out_handle = base::SyncSocket::kInvalidHandle;
|
| 27 |
+
#if defined(OS_WIN)
|
| 28 |
+
DWORD options = DUPLICATE_SAME_ACCESS;
|
| 29 |
+
if (!::DuplicateHandle(::GetCurrentProcess(),
|
| 30 |
+
handle,
|
| 31 |
+
::GetCurrentProcess(),
|
| 32 |
+
&out_handle,
|
| 33 |
+
0,
|
| 34 |
+
FALSE,
|
| 35 |
+
options)) {
|
| 36 |
+
out_handle = base::SyncSocket::kInvalidHandle;
|
| 37 |
+
}
|
| 38 |
+
#elif defined(OS_POSIX)
|
| 39 |
+
// If asked to close the source, we can simply re-use the source fd instead of
|
| 40 |
+
// dup()ing and close()ing.
|
| 41 |
+
out_handle = ::dup(handle);
|
| 42 |
+
#else
|
| 43 |
+
#error Not implemented.
|
| 44 |
+
#endif
|
| 45 |
+
return out_handle;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
} // namespace
|
| 49 |
+
|
| 50 |
+
PepperBrokerDispatcherWrapper::PepperBrokerDispatcherWrapper() {}
|
| 51 |
+
|
| 52 |
+
PepperBrokerDispatcherWrapper::~PepperBrokerDispatcherWrapper() {}
|
| 53 |
+
|
| 54 |
+
bool PepperBrokerDispatcherWrapper::Init(
|
| 55 |
+
base::ProcessId broker_pid,
|
| 56 |
+
const IPC::ChannelHandle& channel_handle) {
|
| 57 |
+
if (channel_handle.name.empty())
|
| 58 |
+
return false;
|
| 59 |
+
|
| 60 |
+
#if defined(OS_POSIX)
|
| 61 |
+
DCHECK_NE(-1, channel_handle.socket.fd);
|
| 62 |
+
if (channel_handle.socket.fd == -1)
|
| 63 |
+
return false;
|
| 64 |
+
#endif
|
| 65 |
+
|
| 66 |
+
dispatcher_delegate_.reset(new PepperProxyChannelDelegateImpl);
|
| 67 |
+
dispatcher_.reset(new ppapi::proxy::BrokerHostDispatcher());
|
| 68 |
+
|
| 69 |
+
if (!dispatcher_->InitBrokerWithChannel(dispatcher_delegate_.get(),
|
| 70 |
+
broker_pid,
|
| 71 |
+
channel_handle,
|
| 72 |
+
true)) { // Client.
|
| 73 |
+
dispatcher_.reset();
|
| 74 |
+
dispatcher_delegate_.reset();
|
| 75 |
+
return false;
|
| 76 |
+
}
|
| 77 |
+
dispatcher_->channel()->SetRestrictDispatchChannelGroup(
|
| 78 |
+
kRendererRestrictDispatchGroup_Pepper);
|
| 79 |
+
return true;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
// Does not take ownership of the local pipe.
|
| 83 |
+
int32_t PepperBrokerDispatcherWrapper::SendHandleToBroker(
|
| 84 |
+
PP_Instance instance,
|
| 85 |
+
base::SyncSocket::Handle handle) {
|
| 86 |
+
IPC::PlatformFileForTransit foreign_socket_handle =
|
| 87 |
+
dispatcher_->ShareHandleWithRemote(handle, false);
|
| 88 |
+
if (foreign_socket_handle == IPC::InvalidPlatformFileForTransit())
|
| 89 |
+
return PP_ERROR_FAILED;
|
| 90 |
+
|
| 91 |
+
int32_t result = PP_ERROR_FAILED;
|
| 92 |
+
if (!dispatcher_->Send(new PpapiMsg_ConnectToPlugin(
|
| 93 |
+
instance, foreign_socket_handle, &result))) {
|
| 94 |
+
// The plugin did not receive the handle, so it must be closed.
|
| 95 |
+
// The easiest way to clean it up is to just put it in an object
|
| 96 |
+
// and then close it. This failure case is not performance critical.
|
| 97 |
+
// The handle could still leak if Send succeeded but the IPC later failed.
|
| 98 |
+
base::SyncSocket temp_socket(
|
| 99 |
+
IPC::PlatformFileForTransitToPlatformFile(foreign_socket_handle));
|
| 100 |
+
return PP_ERROR_FAILED;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
return result;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
PepperBroker::PepperBroker(PluginModule* plugin_module)
|
| 107 |
+
: plugin_module_(plugin_module) {
|
| 108 |
+
DCHECK(plugin_module_);
|
| 109 |
+
|
| 110 |
+
plugin_module_->SetBroker(this);
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
PepperBroker::~PepperBroker() {
|
| 114 |
+
ReportFailureToClients(PP_ERROR_ABORTED);
|
| 115 |
+
plugin_module_->SetBroker(NULL);
|
| 116 |
+
plugin_module_ = NULL;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
// If the channel is not ready, queue the connection.
|
| 120 |
+
void PepperBroker::AddPendingConnect(PPB_Broker_Impl* client) {
|
| 121 |
+
DCHECK(pending_connects_.find(client) == pending_connects_.end())
|
| 122 |
+
<< "Connect was already called for this client";
|
| 123 |
+
|
| 124 |
+
// Ensure this object and the associated broker exist as long as the
|
| 125 |
+
// client exists. There is a corresponding Release() call in Disconnect(),
|
| 126 |
+
// which is called when the PPB_Broker_Impl is destroyed. The only other
|
| 127 |
+
// possible reference is in pending_connect_broker_, which only holds a
|
| 128 |
+
// transient reference. This ensures the broker is available as long as the
|
| 129 |
+
// plugin needs it and allows the plugin to release the broker when it is no
|
| 130 |
+
// longer using it.
|
| 131 |
+
AddRef();
|
| 132 |
+
|
| 133 |
+
pending_connects_[client].client = client->AsWeakPtr();
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
void PepperBroker::Disconnect(PPB_Broker_Impl* client) {
|
| 137 |
+
// Remove the pending connect if one exists. This class will not call client's
|
| 138 |
+
// callback.
|
| 139 |
+
pending_connects_.erase(client);
|
| 140 |
+
|
| 141 |
+
// TODO(ddorwin): Send message disconnect message using dispatcher_.
|
| 142 |
+
|
| 143 |
+
// Release the reference added in Connect().
|
| 144 |
+
// This must be the last statement because it may delete this object.
|
| 145 |
+
Release();
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
void PepperBroker::OnBrokerChannelConnected(
|
| 149 |
+
base::ProcessId broker_pid,
|
| 150 |
+
const IPC::ChannelHandle& channel_handle) {
|
| 151 |
+
scoped_ptr<PepperBrokerDispatcherWrapper> dispatcher(
|
| 152 |
+
new PepperBrokerDispatcherWrapper);
|
| 153 |
+
if (!dispatcher->Init(broker_pid, channel_handle)) {
|
| 154 |
+
ReportFailureToClients(PP_ERROR_FAILED);
|
| 155 |
+
return;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
dispatcher_.reset(dispatcher.release());
|
| 159 |
+
|
| 160 |
+
// Process all pending channel requests from the plugins.
|
| 161 |
+
for (ClientMap::iterator i = pending_connects_.begin();
|
| 162 |
+
i != pending_connects_.end();) {
|
| 163 |
+
base::WeakPtr<PPB_Broker_Impl>& weak_ptr = i->second.client;
|
| 164 |
+
if (!i->second.is_authorized) {
|
| 165 |
+
++i;
|
| 166 |
+
continue;
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
if (weak_ptr.get())
|
| 170 |
+
ConnectPluginToBroker(weak_ptr.get());
|
| 171 |
+
|
| 172 |
+
pending_connects_.erase(i++);
|
| 173 |
+
}
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
void PepperBroker::OnBrokerPermissionResult(PPB_Broker_Impl* client,
|
| 177 |
+
bool result) {
|
| 178 |
+
ClientMap::iterator entry = pending_connects_.find(client);
|
| 179 |
+
if (entry == pending_connects_.end())
|
| 180 |
+
return;
|
| 181 |
+
|
| 182 |
+
if (!entry->second.client.get()) {
|
| 183 |
+
// Client has gone away.
|
| 184 |
+
pending_connects_.erase(entry);
|
| 185 |
+
return;
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
if (!result) {
|
| 189 |
+
// Report failure.
|
| 190 |
+
client->BrokerConnected(
|
| 191 |
+
ppapi::PlatformFileToInt(base::SyncSocket::kInvalidHandle),
|
| 192 |
+
PP_ERROR_NOACCESS);
|
| 193 |
+
pending_connects_.erase(entry);
|
| 194 |
+
return;
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
if (dispatcher_) {
|
| 198 |
+
ConnectPluginToBroker(client);
|
| 199 |
+
pending_connects_.erase(entry);
|
| 200 |
+
return;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
// Mark the request as authorized, continue waiting for the broker
|
| 204 |
+
// connection.
|
| 205 |
+
DCHECK(!entry->second.is_authorized);
|
| 206 |
+
entry->second.is_authorized = true;
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
PepperBroker::PendingConnection::PendingConnection() : is_authorized(false) {}
|
| 210 |
+
|
| 211 |
+
PepperBroker::PendingConnection::PendingConnection(
|
| 212 |
+
const PendingConnection& other) = default;
|
| 213 |
+
|
| 214 |
+
PepperBroker::PendingConnection::~PendingConnection() {}
|
| 215 |
+
|
| 216 |
+
void PepperBroker::ReportFailureToClients(int error_code) {
|
| 217 |
+
DCHECK_NE(PP_OK, error_code);
|
| 218 |
+
for (ClientMap::iterator i = pending_connects_.begin();
|
| 219 |
+
i != pending_connects_.end();
|
| 220 |
+
++i) {
|
| 221 |
+
base::WeakPtr<PPB_Broker_Impl>& weak_ptr = i->second.client;
|
| 222 |
+
if (weak_ptr.get()) {
|
| 223 |
+
weak_ptr->BrokerConnected(
|
| 224 |
+
ppapi::PlatformFileToInt(base::SyncSocket::kInvalidHandle),
|
| 225 |
+
error_code);
|
| 226 |
+
}
|
| 227 |
+
}
|
| 228 |
+
pending_connects_.clear();
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
void PepperBroker::ConnectPluginToBroker(PPB_Broker_Impl* client) {
|
| 232 |
+
base::SyncSocket::Handle plugin_handle = base::SyncSocket::kInvalidHandle;
|
| 233 |
+
int32_t result = PP_OK;
|
| 234 |
+
|
| 235 |
+
// The socket objects will be deleted when this function exits, closing the
|
| 236 |
+
// handles. Any uses of the socket must duplicate them.
|
| 237 |
+
scoped_ptr<base::SyncSocket> broker_socket(new base::SyncSocket());
|
| 238 |
+
scoped_ptr<base::SyncSocket> plugin_socket(new base::SyncSocket());
|
| 239 |
+
if (base::SyncSocket::CreatePair(broker_socket.get(), plugin_socket.get())) {
|
| 240 |
+
result = dispatcher_->SendHandleToBroker(client->pp_instance(),
|
| 241 |
+
broker_socket->handle());
|
| 242 |
+
|
| 243 |
+
// If the broker has its pipe handle, duplicate the plugin's handle.
|
| 244 |
+
// Otherwise, the plugin's handle will be automatically closed.
|
| 245 |
+
if (result == PP_OK)
|
| 246 |
+
plugin_handle = DuplicateHandle(plugin_socket->handle());
|
| 247 |
+
} else {
|
| 248 |
+
result = PP_ERROR_FAILED;
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
// TOOD(ddorwin): Change the IPC to asynchronous: Queue an object containing
|
| 252 |
+
// client and plugin_socket.release(), then return.
|
| 253 |
+
// That message handler will then call client->BrokerConnected() with the
|
| 254 |
+
// saved pipe handle.
|
| 255 |
+
// Temporarily, just call back.
|
| 256 |
+
client->BrokerConnected(ppapi::PlatformFileToInt(plugin_handle), result);
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
} // namespace content
|
pool/shard008/C++/0096537_tictactoe.cpp
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/****************************************************************************
|
| 2 |
+
**
|
| 3 |
+
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
| 4 |
+
** All rights reserved.
|
| 5 |
+
** Contact: Nokia Corporation (qt-info@nokia.com)
|
| 6 |
+
**
|
| 7 |
+
** This file is part of the examples of the Qt Toolkit.
|
| 8 |
+
**
|
| 9 |
+
** $QT_BEGIN_LICENSE:LGPL$
|
| 10 |
+
** Commercial Usage
|
| 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 |
+
** 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, Nokia gives you certain additional
|
| 25 |
+
** rights. These rights are described in the Nokia Qt LGPL Exception
|
| 26 |
+
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
| 27 |
+
**
|
| 28 |
+
** GNU General Public License Usage
|
| 29 |
+
** Alternatively, this file may be used under the terms of the GNU
|
| 30 |
+
** General Public License version 3.0 as published by the Free Software
|
| 31 |
+
** Foundation and appearing in the file LICENSE.GPL included in the
|
| 32 |
+
** packaging of this file. Please review the following information to
|
| 33 |
+
** ensure the GNU General Public License version 3.0 requirements will be
|
| 34 |
+
** met: http://www.gnu.org/copyleft/gpl.html.
|
| 35 |
+
**
|
| 36 |
+
** If you have questions regarding the use of this file, please contact
|
| 37 |
+
** Nokia at qt-info@nokia.com.
|
| 38 |
+
** $QT_END_LICENSE$
|
| 39 |
+
**
|
| 40 |
+
****************************************************************************/
|
| 41 |
+
|
| 42 |
+
#include <QtGui>
|
| 43 |
+
|
| 44 |
+
#include "tictactoe.h"
|
| 45 |
+
|
| 46 |
+
TicTacToe::TicTacToe(QWidget *parent)
|
| 47 |
+
: QWidget(parent)
|
| 48 |
+
{
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
QSize TicTacToe::minimumSizeHint() const
|
| 52 |
+
{
|
| 53 |
+
return QSize(200, 200);
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
QSize TicTacToe::sizeHint() const
|
| 57 |
+
{
|
| 58 |
+
return QSize(200, 200);
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
void TicTacToe::setState(const QString &newState)
|
| 62 |
+
{
|
| 63 |
+
turnNumber = 0;
|
| 64 |
+
myState = "---------";
|
| 65 |
+
int position = 0;
|
| 66 |
+
while (position < 9 && position < newState.length()) {
|
| 67 |
+
QChar mark = newState.at(position);
|
| 68 |
+
if (mark == Cross || mark == Nought) {
|
| 69 |
+
++turnNumber;
|
| 70 |
+
myState.replace(position, 1, mark);
|
| 71 |
+
}
|
| 72 |
+
position++;
|
| 73 |
+
}
|
| 74 |
+
update();
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
QString TicTacToe::state() const
|
| 78 |
+
{
|
| 79 |
+
return myState;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
void TicTacToe::clearBoard()
|
| 83 |
+
{
|
| 84 |
+
myState = "---------";
|
| 85 |
+
turnNumber = 0;
|
| 86 |
+
update();
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
void TicTacToe::mousePressEvent(QMouseEvent *event)
|
| 90 |
+
{
|
| 91 |
+
if (turnNumber == 9) {
|
| 92 |
+
clearBoard();
|
| 93 |
+
update();
|
| 94 |
+
} else {
|
| 95 |
+
for (int position = 0; position < 9; ++position) {
|
| 96 |
+
QRect cell = cellRect(position / 3, position % 3);
|
| 97 |
+
if (cell.contains(event->pos())) {
|
| 98 |
+
if (myState.at(position) == Empty) {
|
| 99 |
+
if (turnNumber % 2 == 0)
|
| 100 |
+
myState.replace(position, 1, Cross);
|
| 101 |
+
else
|
| 102 |
+
myState.replace(position, 1, Nought);
|
| 103 |
+
++turnNumber;
|
| 104 |
+
update();
|
| 105 |
+
}
|
| 106 |
+
}
|
| 107 |
+
}
|
| 108 |
+
}
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
void TicTacToe::paintEvent(QPaintEvent * /* event */)
|
| 112 |
+
{
|
| 113 |
+
QPainter painter(this);
|
| 114 |
+
painter.setRenderHint(QPainter::Antialiasing);
|
| 115 |
+
|
| 116 |
+
painter.setPen(QPen(Qt::darkGreen, 1));
|
| 117 |
+
painter.drawLine(cellWidth(), 0, cellWidth(), height());
|
| 118 |
+
painter.drawLine(2 * cellWidth(), 0, 2 * cellWidth(), height());
|
| 119 |
+
painter.drawLine(0, cellHeight(), width(), cellHeight());
|
| 120 |
+
painter.drawLine(0, 2 * cellHeight(), width(), 2 * cellHeight());
|
| 121 |
+
|
| 122 |
+
painter.setPen(QPen(Qt::darkBlue, 2));
|
| 123 |
+
|
| 124 |
+
for (int position = 0; position < 9; ++position) {
|
| 125 |
+
QRect cell = cellRect(position / 3, position % 3);
|
| 126 |
+
|
| 127 |
+
if (myState.at(position) == Cross) {
|
| 128 |
+
painter.drawLine(cell.topLeft(), cell.bottomRight());
|
| 129 |
+
painter.drawLine(cell.topRight(), cell.bottomLeft());
|
| 130 |
+
} else if (myState.at(position) == Nought) {
|
| 131 |
+
painter.drawEllipse(cell);
|
| 132 |
+
}
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
painter.setPen(QPen(Qt::yellow, 3));
|
| 136 |
+
|
| 137 |
+
for (int position = 0; position < 9; position = position + 3) {
|
| 138 |
+
if (myState.at(position) != Empty
|
| 139 |
+
&& myState.at(position + 1) == myState.at(position)
|
| 140 |
+
&& myState.at(position + 2) == myState.at(position)) {
|
| 141 |
+
int y = cellRect((position / 3), 0).center().y();
|
| 142 |
+
painter.drawLine(0, y, width(), y);
|
| 143 |
+
turnNumber = 9;
|
| 144 |
+
}
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
for (int position = 0; position < 3; ++position) {
|
| 148 |
+
if (myState.at(position) != Empty
|
| 149 |
+
&& myState.at(position + 3) == myState.at(position)
|
| 150 |
+
&& myState.at(position + 6) == myState.at(position)) {
|
| 151 |
+
int x = cellRect(0, position).center().x();
|
| 152 |
+
painter.drawLine(x, 0, x, height());
|
| 153 |
+
turnNumber = 9;
|
| 154 |
+
}
|
| 155 |
+
}
|
| 156 |
+
if (myState.at(0) != Empty && myState.at(4) == myState.at(0)
|
| 157 |
+
&& myState.at(8) == myState.at(0)) {
|
| 158 |
+
painter.drawLine(0, 0, width(), height());
|
| 159 |
+
turnNumber = 9;
|
| 160 |
+
}
|
| 161 |
+
if (myState.at(2) != Empty && myState.at(4) == myState.at(2)
|
| 162 |
+
&& myState.at(6) == myState.at(2)) {
|
| 163 |
+
painter.drawLine(0, height(), width(), 0);
|
| 164 |
+
turnNumber = 9;
|
| 165 |
+
}
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
QRect TicTacToe::cellRect(int row, int column) const
|
| 169 |
+
{
|
| 170 |
+
const int HMargin = width() / 30;
|
| 171 |
+
const int VMargin = height() / 30;
|
| 172 |
+
return QRect(column * cellWidth() + HMargin,
|
| 173 |
+
row * cellHeight() + VMargin,
|
| 174 |
+
cellWidth() - 2 * HMargin,
|
| 175 |
+
cellHeight() - 2 * VMargin);
|
| 176 |
+
}
|
pool/shard008/C++/0096542_Sch.cpp
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "Browser.h"
|
| 2 |
+
|
| 3 |
+
String ReadId(CParser& p, String& rr)
|
| 4 |
+
{
|
| 5 |
+
p.Char('(');
|
| 6 |
+
String id = p.ReadId();
|
| 7 |
+
p.Char(',');
|
| 8 |
+
if(p.IsNumber())
|
| 9 |
+
p.ReadNumber();
|
| 10 |
+
p.Char(',');
|
| 11 |
+
if(p.IsNumber())
|
| 12 |
+
p.ReadNumber();
|
| 13 |
+
p.Char(')');
|
| 14 |
+
rr << "SqlId " << id << "(\"" << id << "\");";
|
| 15 |
+
return id;
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
void ScanSchFile(const char *fn)
|
| 19 |
+
{
|
| 20 |
+
String s = LoadFile(fn);
|
| 21 |
+
CParser p(s);
|
| 22 |
+
String r, rr;
|
| 23 |
+
String S_name;
|
| 24 |
+
int line;
|
| 25 |
+
while(!p.IsEof())
|
| 26 |
+
try {
|
| 27 |
+
line = p.GetLine();
|
| 28 |
+
if(p.Id("TABLE") || p.Id("TABLE_") || p.Id("TYPE") || p.Id("TYPE_")) {
|
| 29 |
+
S_name = "S_" + ReadId(p, rr);
|
| 30 |
+
r << "struct " << S_name << " {";
|
| 31 |
+
}
|
| 32 |
+
else
|
| 33 |
+
if(p.Id("END_TABLE") || p.Id("END_TYPE"))
|
| 34 |
+
r <<
|
| 35 |
+
"static const char TableName[];"
|
| 36 |
+
"static const SqlSet& ColumnSet();"
|
| 37 |
+
"static SqlSet ColumnSet(const String& prefix);"
|
| 38 |
+
"static SqlSet Of(SqlId table);"
|
| 39 |
+
"static const Vector<SqlId>& GetColumnIds();"
|
| 40 |
+
""
|
| 41 |
+
"void Clear();"
|
| 42 |
+
""
|
| 43 |
+
"void FieldLayoutRaw(FieldOperator& f, const String& prefix = String());"
|
| 44 |
+
"void FieldLayout(FieldOperator& f);"
|
| 45 |
+
"operator Fields();"
|
| 46 |
+
""
|
| 47 |
+
"bool operator==(const " << S_name << "& x) const;"
|
| 48 |
+
"bool operator!=(const " << S_name << "& x) const;"
|
| 49 |
+
"String ToString() const;"
|
| 50 |
+
""
|
| 51 |
+
"int GetCount() const;"
|
| 52 |
+
"SqlId GetId(int i) const;"
|
| 53 |
+
"Ref GetRef(int i);"
|
| 54 |
+
"Ref GetRef(const SqlId& id);"
|
| 55 |
+
"Value Get(const SqlId& id) const;"
|
| 56 |
+
"Value Get(int i) const;"
|
| 57 |
+
"ValueMap Get() const;"
|
| 58 |
+
"void Set(int i, const Value& v);"
|
| 59 |
+
"void Set(const SqlId& id, const Value& v);"
|
| 60 |
+
"void Set(const ValueMap& m);"
|
| 61 |
+
<< S_name << "();"
|
| 62 |
+
<< S_name << "(const ValueMap& m);"
|
| 63 |
+
"};";
|
| 64 |
+
else
|
| 65 |
+
if(p.Id("LONGRAW") || p.Id("LONGRAW_") || p.Id("BLOB") || p.Id("BLOB_") ||
|
| 66 |
+
p.Id("STRING_") || p.Id("STRING") || p.Id("CLOB") || p.Id("CLOB_"))
|
| 67 |
+
r << "\tString " << ReadId(p, rr) << ";";
|
| 68 |
+
else
|
| 69 |
+
if(p.Id("INT") || p.Id("INT_") || p.Id("SERIAL") || p.Id("ISERIAL"))
|
| 70 |
+
r << "\tint " << ReadId(p, rr) << ";";
|
| 71 |
+
else
|
| 72 |
+
if(p.Id("DOUBLE") || p.Id("DOUBLE_"))
|
| 73 |
+
r << "\tdouble " << ReadId(p, rr) << ";";
|
| 74 |
+
else
|
| 75 |
+
if(p.Id("TIME") || p.Id("TIME_"))
|
| 76 |
+
r << "\tTime " << ReadId(p, rr) << ";";
|
| 77 |
+
else
|
| 78 |
+
if(p.Id("DATE") || p.Id("DATE_"))
|
| 79 |
+
r << "\tDate " << ReadId(p, rr) << ";";
|
| 80 |
+
else
|
| 81 |
+
if(p.Id("BIT") || p.Id("BIT_") || p.Id("BOOL") || p.Id("BOOL_"))
|
| 82 |
+
r << "\tbool " << ReadId(p, rr) << ";";
|
| 83 |
+
else
|
| 84 |
+
if(p.Id("INT_ARRAY") || p.Id("INT_ARRAY_"))
|
| 85 |
+
r << "\tint " << ReadId(p, rr) << "[1];";
|
| 86 |
+
else
|
| 87 |
+
if(p.Id("DOUBLE_ARRAY") || p.Id("DOUBLE_ARRAY_"))
|
| 88 |
+
r << "\tdouble " << ReadId(p, rr) << "[1];";
|
| 89 |
+
else
|
| 90 |
+
if(p.Id("TIME_ARRAY") || p.Id("TIME_ARRAY_"))
|
| 91 |
+
r << "\tTime " << ReadId(p, rr) << "[1];";
|
| 92 |
+
else
|
| 93 |
+
if(p.Id("DATE_ARRAY") || p.Id("DATE_ARRAY_"))
|
| 94 |
+
r << "\tDate " << ReadId(p, rr) << "[1];";
|
| 95 |
+
else
|
| 96 |
+
if(p.Id("BOOL_ARRAY") || p.Id("BOOL_ARRAY_") || p.Id("BIT_ARRAY") || p.Id("BIT_ARRAY_"))
|
| 97 |
+
r << "\tbool " << ReadId(p, rr) << "[1];";
|
| 98 |
+
else
|
| 99 |
+
if(p.Id("SEQUENCE") || p.Id("SEQUENCE_"))
|
| 100 |
+
ReadId(p, rr);
|
| 101 |
+
else
|
| 102 |
+
p.SkipTerm();
|
| 103 |
+
line = p.GetLine() - line;
|
| 104 |
+
for(int i = 0; i < line; ++i) {
|
| 105 |
+
r << '\n';
|
| 106 |
+
rr << '\n';
|
| 107 |
+
}
|
| 108 |
+
}
|
| 109 |
+
catch(CParser::Error)
|
| 110 |
+
{}
|
| 111 |
+
StringStream ss(r), sr(rr);
|
| 112 |
+
CppBase& base = CodeBase();
|
| 113 |
+
Parse(sr, IgnoreList(), base, fn, CNULL);
|
| 114 |
+
Parse(ss, IgnoreList(), base, fn, CNULL);
|
| 115 |
+
}
|
pool/shard008/C++/0096543_ContainerTraitsTest.cpp
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright 2017 Facebook, Inc.
|
| 3 |
+
*
|
| 4 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
* you may not use this file except in compliance with the License.
|
| 6 |
+
* You may obtain a copy of the License at
|
| 7 |
+
*
|
| 8 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
*
|
| 10 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
* See the License for the specific language governing permissions and
|
| 14 |
+
* limitations under the License.
|
| 15 |
+
*/
|
| 16 |
+
|
| 17 |
+
#include <folly/ContainerTraits.h>
|
| 18 |
+
|
| 19 |
+
#include <folly/portability/GTest.h>
|
| 20 |
+
|
| 21 |
+
using namespace std;
|
| 22 |
+
using namespace folly;
|
| 23 |
+
|
| 24 |
+
struct Node {
|
| 25 |
+
size_t copies = 0;
|
| 26 |
+
Node() noexcept {}
|
| 27 |
+
Node(const Node& n) noexcept { copies = n.copies; ++copies; }
|
| 28 |
+
Node(Node&& n) noexcept { swap(copies, n.copies); ++copies; }
|
| 29 |
+
};
|
| 30 |
+
|
| 31 |
+
template <class T>
|
| 32 |
+
class VectorWrapper {
|
| 33 |
+
public:
|
| 34 |
+
using value_type = T;
|
| 35 |
+
vector<T>& underlying;
|
| 36 |
+
explicit VectorWrapper(vector<T>& v) : underlying(v) {}
|
| 37 |
+
void push_back(const T& t) { underlying.push_back(t); }
|
| 38 |
+
};
|
| 39 |
+
|
| 40 |
+
TEST(ContainerTraits, WithoutEmplaceBack) {
|
| 41 |
+
vector<Node> v;
|
| 42 |
+
VectorWrapper<Node> vw(v);
|
| 43 |
+
container_emplace_back_or_push_back(vw);
|
| 44 |
+
EXPECT_EQ(1, v.at(0).copies);
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
TEST(ContainerTraits, WithEmplaceBack) {
|
| 48 |
+
vector<Node> v;
|
| 49 |
+
container_emplace_back_or_push_back(v);
|
| 50 |
+
EXPECT_EQ(0, v.at(0).copies);
|
| 51 |
+
}
|
pool/shard008/C++/0096547_obstacle-shadowing-propagation-loss-model.cc
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
| 2 |
+
/*
|
| 3 |
+
* Copyright (c) 2014 North Carolina State University
|
| 4 |
+
*
|
| 5 |
+
* This program is free software; you can redistribute it and/or modify
|
| 6 |
+
* it under the terms of the GNU General Public License version 2 as
|
| 7 |
+
* published by the Free Software Foundation;
|
| 8 |
+
*
|
| 9 |
+
* This program is distributed in the hope that it will be useful,
|
| 10 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12 |
+
* GNU General Public License for more details.
|
| 13 |
+
*
|
| 14 |
+
* You should have received a copy of the GNU General Public License
|
| 15 |
+
* along with this program; if not, write to the Free Software
|
| 16 |
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
| 17 |
+
*
|
| 18 |
+
* Author: Scott E. Carpenter <scarpen@ncsu.edu>
|
| 19 |
+
*
|
| 20 |
+
*/
|
| 21 |
+
|
| 22 |
+
#include "ns3/log.h"
|
| 23 |
+
#include "ns3/double.h"
|
| 24 |
+
#include "ns3/enum.h"
|
| 25 |
+
#include "ns3/mobility-model.h"
|
| 26 |
+
#include <cmath>
|
| 27 |
+
#include "ns3/topology.h"
|
| 28 |
+
|
| 29 |
+
#include "obstacle-shadowing-propagation-loss-model.h"
|
| 30 |
+
|
| 31 |
+
NS_LOG_COMPONENT_DEFINE ("ObstacleShadowingPropagationLossModel");
|
| 32 |
+
|
| 33 |
+
namespace ns3 {
|
| 34 |
+
|
| 35 |
+
NS_OBJECT_ENSURE_REGISTERED (ObstacleShadowingPropagationLossModel);
|
| 36 |
+
|
| 37 |
+
TypeId
|
| 38 |
+
ObstacleShadowingPropagationLossModel::GetTypeId (void)
|
| 39 |
+
{
|
| 40 |
+
static TypeId tid = TypeId ("ns3::ObstacleShadowingPropagationLossModel")
|
| 41 |
+
|
| 42 |
+
.SetParent<PropagationLossModel> ()
|
| 43 |
+
.AddConstructor<ObstacleShadowingPropagationLossModel> ()
|
| 44 |
+
.AddAttribute ("ForBeacon", "beacons",
|
| 45 |
+
UintegerValue (0),
|
| 46 |
+
MakeUintegerAccessor (&ObstacleShadowingPropagationLossModel::m_forbeacon),
|
| 47 |
+
MakeUintegerChecker<uint32_t> (0))
|
| 48 |
+
// .AddAttribute ("IsSub1G", "sub 1Ghz beacon",
|
| 49 |
+
// UintegerValue (0),
|
| 50 |
+
// MakeUintegerAccessor (&ObstacleShadowingPropagationLossModel::m_isSub1G),
|
| 51 |
+
// MakeUintegerChecker<uint32_t> (0))
|
| 52 |
+
.AddAttribute ("MaxDistance", "Maximum allowed transmission distance (m)",
|
| 53 |
+
UintegerValue (500),
|
| 54 |
+
MakeUintegerAccessor (&ObstacleShadowingPropagationLossModel::m_maxDistance),
|
| 55 |
+
MakeUintegerChecker<uint32_t> (0))
|
| 56 |
+
|
| 57 |
+
;
|
| 58 |
+
return tid;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
ObstacleShadowingPropagationLossModel::ObstacleShadowingPropagationLossModel ()
|
| 62 |
+
: PropagationLossModel (),
|
| 63 |
+
m_forbeacon(0),
|
| 64 |
+
m_isSub1G(0),
|
| 65 |
+
m_maxDistance(500)
|
| 66 |
+
{
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
ObstacleShadowingPropagationLossModel::~ObstacleShadowingPropagationLossModel ()
|
| 70 |
+
{
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
double
|
| 74 |
+
ObstacleShadowingPropagationLossModel::GetLoss (Ptr<MobilityModel> a, Ptr<MobilityModel> b) const
|
| 75 |
+
{
|
| 76 |
+
NS_LOG_FUNCTION (this);
|
| 77 |
+
|
| 78 |
+
// initialize = no loss
|
| 79 |
+
|
| 80 |
+
double L_obs = 0.0;
|
| 81 |
+
|
| 82 |
+
// get the topology instance, to search for obstacles
|
| 83 |
+
Topology * topology = Topology::GetTopology();
|
| 84 |
+
NS_ASSERT(topology != 0);
|
| 85 |
+
|
| 86 |
+
if (topology->HasObstacles() == true)
|
| 87 |
+
{
|
| 88 |
+
// additional loss for obstacles
|
| 89 |
+
double p1_x = a->GetPosition ().x;
|
| 90 |
+
double p1_y = a->GetPosition ().y;
|
| 91 |
+
double p2_x = b->GetPosition ().x;
|
| 92 |
+
double p2_y = b->GetPosition ().y;
|
| 93 |
+
// for two points, p1 and p2
|
| 94 |
+
Point p1(p1_x, p1_y);
|
| 95 |
+
Point p2(p2_x, p2_y);
|
| 96 |
+
|
| 97 |
+
double r = m_maxDistance;
|
| 98 |
+
|
| 99 |
+
// get the obstructed loss, from the topology class
|
| 100 |
+
L_obs = topology->GetObstructedLossBetween(p1, p2, r, m_forbeacon, m_isSub1G);
|
| 101 |
+
NS_LOG_DEBUG("LOSS:"<<L_obs);
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
return L_obs;
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
double
|
| 108 |
+
ObstacleShadowingPropagationLossModel::DoCalcRxPower (double txPowerDbm,
|
| 109 |
+
Ptr<MobilityModel> a,
|
| 110 |
+
Ptr<MobilityModel> b) const
|
| 111 |
+
{
|
| 112 |
+
double retVal = 0.0;
|
| 113 |
+
double loss = GetLoss (a, b);
|
| 114 |
+
retVal = txPowerDbm - loss;
|
| 115 |
+
return (retVal);
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
int64_t
|
| 119 |
+
ObstacleShadowingPropagationLossModel::DoAssignStreams (int64_t stream)
|
| 120 |
+
{
|
| 121 |
+
return 0;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
} // namespace ns3
|
pool/shard008/C++/0096548_animgoals_stackentry.cpp
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
#include "stdafx.h"
|
| 3 |
+
|
| 4 |
+
#include <temple/dll.h>
|
| 5 |
+
|
| 6 |
+
#include "gamesystems/gamesystems.h"
|
| 7 |
+
#include "gamesystems/objects/objsystem.h"
|
| 8 |
+
#include "gamesystems/mapsystem.h"
|
| 9 |
+
#include "animgoals_stackentry.h"
|
| 10 |
+
|
| 11 |
+
static_assert(temple::validate_size<AnimSlotGoalStackEntry, 0x220>::value);
|
| 12 |
+
static_assert(temple::validate_size<AnimParam, 0x10>::value);
|
| 13 |
+
|
| 14 |
+
// Originally @ 0x100556C0
|
| 15 |
+
bool AnimSlotGoalStackEntry::InitWithInterrupt(objHndl handle, AnimGoalType goalType) {
|
| 16 |
+
return Init(handle, goalType, true);
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
bool AnimSlotGoalStackEntry::Push(AnimSlotId* idNew) {
|
| 20 |
+
return gameSystems->GetAnim().PushGoal(*this, idNew);
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
// Originally @ 0x10055570
|
| 24 |
+
bool AnimSlotGoalStackEntry::Init(objHndl handle, AnimGoalType goalType, bool withInterrupt) {
|
| 25 |
+
auto gdata = this;
|
| 26 |
+
|
| 27 |
+
if (!gdata) {
|
| 28 |
+
logger->error("Null goalData ptr");
|
| 29 |
+
gameSystems->GetAnim().Debug();
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
if ((goalType & 0x80000000) || goalType >= ag_count) {
|
| 33 |
+
logger->error("Illegal goalType");
|
| 34 |
+
gameSystems->GetAnim().Debug();
|
| 35 |
+
}
|
| 36 |
+
gdata->animId.number = -1;
|
| 37 |
+
gdata->animIdPrevious.number = -1;
|
| 38 |
+
gdata->animData.number = -1;
|
| 39 |
+
gdata->spellData.number = -1;
|
| 40 |
+
gdata->flagsData.number = -1;
|
| 41 |
+
gdata->soundStreamId = -1;
|
| 42 |
+
gdata->goalType = goalType;
|
| 43 |
+
gdata->self.obj = handle;
|
| 44 |
+
gdata->target.obj = objHndl::null;
|
| 45 |
+
gdata->block.obj = objHndl::null;
|
| 46 |
+
gdata->scratch.obj = objHndl::null;
|
| 47 |
+
gdata->parent.obj = objHndl::null;
|
| 48 |
+
gdata->targetTile.location = LocAndOffsets::null;
|
| 49 |
+
gdata->range.location = LocAndOffsets::null;
|
| 50 |
+
gdata->skillData.number = 0;
|
| 51 |
+
gdata->scratchVal1.number = 0;
|
| 52 |
+
gdata->scratchVal2.number = 0;
|
| 53 |
+
gdata->scratchVal3.number = 0;
|
| 54 |
+
gdata->scratchVal4.number = 0;
|
| 55 |
+
gdata->scratchVal5.number = 0;
|
| 56 |
+
gdata->scratchVal6.number = 0;
|
| 57 |
+
gdata->soundHandle.number = 0;
|
| 58 |
+
if (withInterrupt)
|
| 59 |
+
{
|
| 60 |
+
auto ag = gameSystems->GetAnim().GetGoal(goalType);
|
| 61 |
+
if (!ag) {
|
| 62 |
+
logger->error("pGoalNode != NULL assertion failed");
|
| 63 |
+
gameSystems->GetAnim().Debug();
|
| 64 |
+
}
|
| 65 |
+
return gameSystems->GetAnim().Interrupt(handle, ag->priority, ag->interruptAll);
|
| 66 |
+
}
|
| 67 |
+
return TRUE;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
void AnimSlotGoalStackEntry::FreezeObjectRefs()
|
| 71 |
+
{
|
| 72 |
+
selfTracking = FrozenObjRef::Freeze(self.obj);
|
| 73 |
+
targetTracking = FrozenObjRef::Freeze(target.obj);
|
| 74 |
+
blockTracking = FrozenObjRef::Freeze(block.obj);
|
| 75 |
+
scratchTracking = FrozenObjRef::Freeze(scratch.obj);
|
| 76 |
+
parentTracking = FrozenObjRef::Freeze(parent.obj);
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
static bool ValidateObjectRef(objHndl &handle, const FrozenObjRef &frozenRef) {
|
| 80 |
+
if (!objSystem->IsValidHandle(handle)) {
|
| 81 |
+
if (FrozenObjRef::Unfreeze(frozenRef, &handle)) {
|
| 82 |
+
logger->error("Failed to recover object reference in anim goal");
|
| 83 |
+
handle = objHndl::null;
|
| 84 |
+
return false;
|
| 85 |
+
}
|
| 86 |
+
}
|
| 87 |
+
return true;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
bool AnimSlotGoalStackEntry::ValidateObjectRefs()
|
| 91 |
+
{
|
| 92 |
+
if (gameSystems->GetMap().IsClearingMap()) {
|
| 93 |
+
self.obj = objHndl::null;
|
| 94 |
+
target.obj = objHndl::null;
|
| 95 |
+
block.obj = objHndl::null;
|
| 96 |
+
scratch.obj = objHndl::null;
|
| 97 |
+
parent.obj = objHndl::null;
|
| 98 |
+
return false;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
if (!ValidateObjectRef(self.obj, selfTracking)) {
|
| 102 |
+
return false;
|
| 103 |
+
}
|
| 104 |
+
if (!ValidateObjectRef(target.obj, targetTracking)) {
|
| 105 |
+
return false;
|
| 106 |
+
}
|
| 107 |
+
if (!ValidateObjectRef(block.obj, blockTracking)) {
|
| 108 |
+
return false;
|
| 109 |
+
}
|
| 110 |
+
if (!ValidateObjectRef(scratch.obj, scratchTracking)) {
|
| 111 |
+
return false;
|
| 112 |
+
}
|
| 113 |
+
if (!ValidateObjectRef(parent.obj, parentTracking)) {
|
| 114 |
+
return false;
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
return true;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
AnimSlotGoalStackEntry::AnimSlotGoalStackEntry(objHndl handle, AnimGoalType GoalType, bool withInterrupt) {
|
| 121 |
+
Init(handle, GoalType, withInterrupt);
|
| 122 |
+
}
|
pool/shard008/C++/0096549_qgsfieldformatter.cpp
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/***************************************************************************
|
| 2 |
+
qgsfieldformatter.cpp - QgsFieldFormatter
|
| 3 |
+
|
| 4 |
+
---------------------
|
| 5 |
+
begin : 2.12.2016
|
| 6 |
+
copyright : (C) 2016 by Matthias Kuhn
|
| 7 |
+
email : matthias@opengis.ch
|
| 8 |
+
***************************************************************************
|
| 9 |
+
* *
|
| 10 |
+
* This program is free software; you can redistribute it and/or modify *
|
| 11 |
+
* it under the terms of the GNU General Public License as published by *
|
| 12 |
+
* the Free Software Foundation; either version 2 of the License, or *
|
| 13 |
+
* (at your option) any later version. *
|
| 14 |
+
* *
|
| 15 |
+
***************************************************************************/
|
| 16 |
+
#include "qgsfieldformatter.h"
|
| 17 |
+
|
| 18 |
+
#include "qgsfield.h"
|
| 19 |
+
#include "qgsfields.h"
|
| 20 |
+
#include "qgsvectorlayer.h"
|
| 21 |
+
#include "qgsvectordataprovider.h"
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
QString QgsFieldFormatter::representValue( QgsVectorLayer *layer, int fieldIndex, const QVariantMap &config, const QVariant &cache, const QVariant &value ) const
|
| 25 |
+
{
|
| 26 |
+
Q_UNUSED( config )
|
| 27 |
+
Q_UNUSED( cache )
|
| 28 |
+
|
| 29 |
+
QString defVal;
|
| 30 |
+
if ( layer->fields().fieldOrigin( fieldIndex ) == QgsFields::OriginProvider && layer->dataProvider() )
|
| 31 |
+
defVal = layer->dataProvider()->defaultValueClause( layer->fields().fieldOriginIndex( fieldIndex ) );
|
| 32 |
+
|
| 33 |
+
if ( ! layer->fields().exists( fieldIndex ) )
|
| 34 |
+
{
|
| 35 |
+
return defVal;
|
| 36 |
+
}
|
| 37 |
+
else
|
| 38 |
+
{
|
| 39 |
+
return layer->fields().at( fieldIndex ).displayString( value.isNull() ? defVal : value );
|
| 40 |
+
}
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
QVariant QgsFieldFormatter::sortValue( QgsVectorLayer *layer, int fieldIndex, const QVariantMap &config, const QVariant &cache, const QVariant &value ) const
|
| 44 |
+
{
|
| 45 |
+
Q_UNUSED( layer )
|
| 46 |
+
Q_UNUSED( fieldIndex )
|
| 47 |
+
Q_UNUSED( config )
|
| 48 |
+
Q_UNUSED( cache )
|
| 49 |
+
|
| 50 |
+
return value;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
Qt::AlignmentFlag QgsFieldFormatter::alignmentFlag( QgsVectorLayer *layer, int fieldIndex, const QVariantMap &config ) const
|
| 54 |
+
{
|
| 55 |
+
Q_UNUSED( config )
|
| 56 |
+
|
| 57 |
+
QgsField field = layer->fields().at( fieldIndex );
|
| 58 |
+
if ( field.isNumeric() || field.isDateOrTime() )
|
| 59 |
+
return Qt::AlignRight;
|
| 60 |
+
else
|
| 61 |
+
return Qt::AlignLeft;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
QVariant QgsFieldFormatter::createCache( QgsVectorLayer *layer, int fieldIndex, const QVariantMap &config ) const
|
| 65 |
+
{
|
| 66 |
+
Q_UNUSED( layer )
|
| 67 |
+
Q_UNUSED( fieldIndex )
|
| 68 |
+
Q_UNUSED( config )
|
| 69 |
+
|
| 70 |
+
return QVariant();
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
QList<QgsVectorLayerRef> QgsFieldFormatter::layerDependencies( const QVariantMap &config ) const
|
| 74 |
+
{
|
| 75 |
+
Q_UNUSED( config )
|
| 76 |
+
return QList<QgsVectorLayerRef>();
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
QVariantList QgsFieldFormatter::availableValues( const QVariantMap &config, int countLimit, const QgsFieldFormatterContext &context ) const
|
| 80 |
+
{
|
| 81 |
+
Q_UNUSED( config )
|
| 82 |
+
Q_UNUSED( countLimit )
|
| 83 |
+
Q_UNUSED( context )
|
| 84 |
+
|
| 85 |
+
return QVariantList();
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
void QgsFieldFormatter::setFlags( const Flags &flags )
|
| 89 |
+
{
|
| 90 |
+
mFlags = flags;
|
| 91 |
+
}
|
pool/shard008/C++/0096551_nofCarpenter.cpp
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (c) 2005 - 2015 Settlers Freaks (sf-team at siedler25.org)
|
| 2 |
+
//
|
| 3 |
+
// This file is part of Return To The Roots.
|
| 4 |
+
//
|
| 5 |
+
// Return To The Roots is free software: you can redistribute it and/or modify
|
| 6 |
+
// it under the terms of the GNU General Public License as published by
|
| 7 |
+
// the Free Software Foundation, either version 2 of the License, or
|
| 8 |
+
// (at your option) any later version.
|
| 9 |
+
//
|
| 10 |
+
// Return To The Roots 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 Return To The Roots. If not, see <http://www.gnu.org/licenses/>.
|
| 17 |
+
|
| 18 |
+
///////////////////////////////////////////////////////////////////////////////
|
| 19 |
+
// Header
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
#include "defines.h"
|
| 23 |
+
#include "nofCarpenter.h"
|
| 24 |
+
#include "Loader.h"
|
| 25 |
+
#include "macros.h"
|
| 26 |
+
#include "GameClient.h"
|
| 27 |
+
#include "buildings/nobUsual.h"
|
| 28 |
+
#include "SoundManager.h"
|
| 29 |
+
|
| 30 |
+
///////////////////////////////////////////////////////////////////////////////
|
| 31 |
+
// Makros / Defines
|
| 32 |
+
#if defined _WIN32 && defined _DEBUG && defined _MSC_VER
|
| 33 |
+
#define new new(_NORMAL_BLOCK, THIS_FILE, __LINE__)
|
| 34 |
+
#undef THIS_FILE
|
| 35 |
+
static char THIS_FILE[] = __FILE__;
|
| 36 |
+
#endif
|
| 37 |
+
|
| 38 |
+
nofCarpenter::nofCarpenter(const MapPoint pos, const unsigned char player, nobUsual* workplace)
|
| 39 |
+
: nofWorkman(JOB_CARPENTER, pos, player, workplace)
|
| 40 |
+
{
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
nofCarpenter::nofCarpenter(SerializedGameData* sgd, const unsigned obj_id) : nofWorkman(sgd, obj_id)
|
| 44 |
+
{
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
void nofCarpenter::DrawWorking(int x, int y)
|
| 48 |
+
{
|
| 49 |
+
signed char offsets[NAT_COUNT][2] = { {30, 3}, {38, 3}, {30, 8}, {17, -2}, {38, 3} };
|
| 50 |
+
|
| 51 |
+
unsigned now_id;
|
| 52 |
+
|
| 53 |
+
LOADER.GetImageN("rom_bobs", 32 + ((now_id = GAMECLIENT.Interpolate(136, current_ev)) % 8))
|
| 54 |
+
->Draw(x + offsets[workplace->GetNation()][0], y + offsets[workplace->GetNation()][1], 0, 0, 0, 0, 0, 0, COLOR_WHITE, COLORS[gwg->GetPlayer(workplace->GetPlayer()).color]);
|
| 55 |
+
|
| 56 |
+
// Evtl Sound abspielen
|
| 57 |
+
if(now_id % 8 == 3 || now_id % 8 == 7)
|
| 58 |
+
{
|
| 59 |
+
SOUNDMANAGER.PlayNOSound(54 + ((now_id) % 8) / 4, this, now_id / 4);
|
| 60 |
+
was_sounding = true;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
last_id = now_id;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
GoodType nofCarpenter::ProduceWare()
|
| 67 |
+
{
|
| 68 |
+
return GD_BOARDS;
|
| 69 |
+
}
|
pool/shard008/C++/0096563_fingerprint_calculator.cpp
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Chromaprint -- Audio fingerprinting toolkit
|
| 3 |
+
* Copyright (C) 2010 Lukas Lalinsky <lalinsky@gmail.com>
|
| 4 |
+
*
|
| 5 |
+
* This library is free software; you can redistribute it and/or
|
| 6 |
+
* modify it under the terms of the GNU Lesser General Public
|
| 7 |
+
* License as published by the Free Software Foundation; either
|
| 8 |
+
* version 2.1 of the License, or (at your option) any later version.
|
| 9 |
+
*
|
| 10 |
+
* This library is distributed in the hope that it will be useful,
|
| 11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 13 |
+
* Lesser General Public License for more details.
|
| 14 |
+
*
|
| 15 |
+
* You should have received a copy of the GNU Lesser General Public
|
| 16 |
+
* License along with this library; if not, write to the Free Software
|
| 17 |
+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
| 18 |
+
* USA
|
| 19 |
+
*/
|
| 20 |
+
|
| 21 |
+
#include "fingerprint_calculator.h"
|
| 22 |
+
#include "classifier.h"
|
| 23 |
+
#include "debug.h"
|
| 24 |
+
#include "utils.h"
|
| 25 |
+
|
| 26 |
+
using namespace std;
|
| 27 |
+
using namespace Chromaprint;
|
| 28 |
+
|
| 29 |
+
FingerprintCalculator::FingerprintCalculator(const Classifier *classifiers, int num_classifiers)
|
| 30 |
+
: m_classifiers(classifiers), m_num_classifiers(num_classifiers)
|
| 31 |
+
{
|
| 32 |
+
m_max_filter_width = 0;
|
| 33 |
+
for (int i = 0; i < num_classifiers; i++) {
|
| 34 |
+
m_max_filter_width = max(m_max_filter_width, classifiers[i].filter().width());
|
| 35 |
+
}
|
| 36 |
+
assert(m_max_filter_width > 0);
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
vector<int32_t> FingerprintCalculator::Calculate(Image *image)
|
| 41 |
+
{
|
| 42 |
+
int length = image->NumRows() - m_max_filter_width + 1;
|
| 43 |
+
if (length <= 0) {
|
| 44 |
+
DEBUG() << "Chromaprint::FingerprintCalculator::Calculate() -- Not "
|
| 45 |
+
<< "enough data. Image has " << image->NumRows() << " rows, "
|
| 46 |
+
<< "needs at least " << m_max_filter_width << " rows.\n";
|
| 47 |
+
return vector<int32_t>();
|
| 48 |
+
}
|
| 49 |
+
IntegralImage integral_image(image);
|
| 50 |
+
vector<int32_t> fingerprint(length);
|
| 51 |
+
for (int i = 0; i < length; i++) {
|
| 52 |
+
fingerprint[i] = CalculateSubfingerprint(&integral_image, i);
|
| 53 |
+
}
|
| 54 |
+
return fingerprint;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
int32_t FingerprintCalculator::CalculateSubfingerprint(IntegralImage *image, int offset)
|
| 58 |
+
{
|
| 59 |
+
uint32_t bits = 0;
|
| 60 |
+
for (int i = 0; i < m_num_classifiers; i++) {
|
| 61 |
+
//for (int i = m_num_classifiers - 1; i >= 0; i--) {
|
| 62 |
+
bits = (bits << 2) | GrayCode(m_classifiers[i].Classify(image, offset));
|
| 63 |
+
//bits = (bits << 2) | m_classifiers[i].Classify(image, offset);
|
| 64 |
+
}
|
| 65 |
+
return UnsignedToSigned(bits);
|
| 66 |
+
}
|
| 67 |
+
|
pool/shard008/C++/0096564_desktop_native_cursor_manager.cc
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h"
|
| 6 |
+
|
| 7 |
+
#include "ui/aura/root_window.h"
|
| 8 |
+
#include "ui/base/cursor/cursor_loader.h"
|
| 9 |
+
#include "ui/views/widget/desktop_aura/desktop_cursor_loader_updater.h"
|
| 10 |
+
|
| 11 |
+
namespace views {
|
| 12 |
+
|
| 13 |
+
DesktopNativeCursorManager::DesktopNativeCursorManager(
|
| 14 |
+
aura::RootWindow* window,
|
| 15 |
+
scoped_ptr<DesktopCursorLoaderUpdater> cursor_loader_updater)
|
| 16 |
+
: root_window_(window),
|
| 17 |
+
cursor_loader_updater_(cursor_loader_updater.Pass()),
|
| 18 |
+
cursor_loader_(ui::CursorLoader::Create()) {
|
| 19 |
+
if (cursor_loader_updater_.get())
|
| 20 |
+
cursor_loader_updater_->OnCreate(root_window_, cursor_loader_.get());
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
DesktopNativeCursorManager::~DesktopNativeCursorManager() {
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
gfx::NativeCursor DesktopNativeCursorManager::GetInitializedCursor(int type) {
|
| 27 |
+
gfx::NativeCursor cursor(type);
|
| 28 |
+
cursor_loader_->SetPlatformCursor(&cursor);
|
| 29 |
+
return cursor;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
void DesktopNativeCursorManager::SetDisplay(
|
| 33 |
+
const gfx::Display& display,
|
| 34 |
+
views::corewm::NativeCursorManagerDelegate* delegate) {
|
| 35 |
+
cursor_loader_->UnloadAll();
|
| 36 |
+
cursor_loader_->set_display(display);
|
| 37 |
+
|
| 38 |
+
if (cursor_loader_updater_.get())
|
| 39 |
+
cursor_loader_updater_->OnDisplayUpdated(display, cursor_loader_.get());
|
| 40 |
+
|
| 41 |
+
SetCursor(delegate->GetCurrentCursor(), delegate);
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
void DesktopNativeCursorManager::SetCursor(
|
| 45 |
+
gfx::NativeCursor cursor,
|
| 46 |
+
views::corewm::NativeCursorManagerDelegate* delegate) {
|
| 47 |
+
gfx::NativeCursor new_cursor = cursor;
|
| 48 |
+
cursor_loader_->SetPlatformCursor(&new_cursor);
|
| 49 |
+
delegate->CommitCursor(new_cursor);
|
| 50 |
+
|
| 51 |
+
if (delegate->GetCurrentVisibility())
|
| 52 |
+
root_window_->SetCursor(new_cursor);
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
void DesktopNativeCursorManager::SetVisibility(
|
| 56 |
+
bool visible,
|
| 57 |
+
views::corewm::NativeCursorManagerDelegate* delegate) {
|
| 58 |
+
delegate->CommitVisibility(visible);
|
| 59 |
+
|
| 60 |
+
if (visible) {
|
| 61 |
+
SetCursor(delegate->GetCurrentCursor(), delegate);
|
| 62 |
+
} else {
|
| 63 |
+
gfx::NativeCursor invisible_cursor(ui::kCursorNone);
|
| 64 |
+
cursor_loader_->SetPlatformCursor(&invisible_cursor);
|
| 65 |
+
root_window_->SetCursor(invisible_cursor);
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
root_window_->OnCursorVisibilityChanged(visible);
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
void DesktopNativeCursorManager::SetCursorSet(
|
| 72 |
+
ui::CursorSetType cursor_set,
|
| 73 |
+
views::corewm::NativeCursorManagerDelegate* delegate) {
|
| 74 |
+
NOTIMPLEMENTED();
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
void DesktopNativeCursorManager::SetScale(
|
| 78 |
+
float scale,
|
| 79 |
+
views::corewm::NativeCursorManagerDelegate* delegate) {
|
| 80 |
+
NOTIMPLEMENTED();
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
void DesktopNativeCursorManager::SetMouseEventsEnabled(
|
| 84 |
+
bool enabled,
|
| 85 |
+
views::corewm::NativeCursorManagerDelegate* delegate) {
|
| 86 |
+
delegate->CommitMouseEventsEnabled(enabled);
|
| 87 |
+
|
| 88 |
+
// TODO(erg): In the ash version, we set the last mouse location on Env. I'm
|
| 89 |
+
// not sure this concept makes sense on the desktop.
|
| 90 |
+
|
| 91 |
+
SetVisibility(delegate->GetCurrentVisibility(), delegate);
|
| 92 |
+
|
| 93 |
+
root_window_->OnMouseEventsEnableStateChanged(enabled);
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
} // namespace views
|
pool/shard008/C++/0096566_HashMap_Test.cpp
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright 2016-2018 Jerome Pasquier
|
| 3 |
+
*
|
| 4 |
+
* This file is part of librlgl.
|
| 5 |
+
*
|
| 6 |
+
* librlgl is free software: you can redistribute it and/or modify
|
| 7 |
+
* it under the terms of the GNU General Public License as published by
|
| 8 |
+
* the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
* (at your option) any later version.
|
| 10 |
+
*
|
| 11 |
+
* librlgl is distributed in the hope that it will be useful,
|
| 12 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
* GNU General Public License for more details.
|
| 15 |
+
*
|
| 16 |
+
* You should have received a copy of the GNU General Public License
|
| 17 |
+
* along with librlgl. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
*
|
| 19 |
+
*/
|
| 20 |
+
|
| 21 |
+
#include "HashMap.hpp"
|
| 22 |
+
|
| 23 |
+
#include <gtest/gtest.h>
|
| 24 |
+
#include <iostream>
|
| 25 |
+
#include <string>
|
| 26 |
+
|
| 27 |
+
using namespace std;
|
| 28 |
+
using namespace RLGL;
|
| 29 |
+
|
| 30 |
+
class SerializableObject
|
| 31 |
+
{
|
| 32 |
+
public:
|
| 33 |
+
int a;
|
| 34 |
+
string b;
|
| 35 |
+
|
| 36 |
+
friend ostream& operator<< (ostream &out, SerializableObject const& c)
|
| 37 |
+
{
|
| 38 |
+
return out << c.a << c.b;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
friend istream& operator>> (istream &in, SerializableObject& c)
|
| 42 |
+
{
|
| 43 |
+
return in >> c.a >> c.b ;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
};
|
| 47 |
+
|
| 48 |
+
// Test a string value
|
| 49 |
+
TEST( HashMap, str )
|
| 50 |
+
{
|
| 51 |
+
HashMap hm;
|
| 52 |
+
hm.set<string>("key", "aze");
|
| 53 |
+
string str = hm.get<string>("key");
|
| 54 |
+
ASSERT_EQ( str, "aze" );
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
TEST( HashMap, grouped_str )
|
| 58 |
+
{
|
| 59 |
+
HashMap hm;
|
| 60 |
+
hm.addGroup("gr1");
|
| 61 |
+
hm.set<string>("key", "aze");
|
| 62 |
+
string str = hm.get<string>("gr1::key");
|
| 63 |
+
ASSERT_EQ( str, "aze" );
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
TEST( HashMap, cant_find )
|
| 67 |
+
{
|
| 68 |
+
HashMap hm;
|
| 69 |
+
hm.addGroup("gr1");
|
| 70 |
+
hm.set<string>("key", "aze");
|
| 71 |
+
ASSERT_THROW(hm.get<string>("gr1::key2"), KeyException );
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
TEST( HashMap, unserializable )
|
| 75 |
+
{
|
| 76 |
+
HashMap hm;
|
| 77 |
+
SerializableObject so;
|
| 78 |
+
so.a = 8;
|
| 79 |
+
so.b = "aze";
|
| 80 |
+
hm.addGroup("gr1");
|
| 81 |
+
hm.set<SerializableObject>("key", so);
|
| 82 |
+
|
| 83 |
+
SerializableObject so2 = hm.get<SerializableObject>("gr1::key");
|
| 84 |
+
ASSERT_EQ( so2.a, 8 );
|
| 85 |
+
ASSERT_EQ( so2.b, "aze" );
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
TEST( HashMap, already_exist )
|
| 89 |
+
{
|
| 90 |
+
HashMap hm;
|
| 91 |
+
hm.addGroup("gr1");
|
| 92 |
+
hm.set<string>("key", "aze");
|
| 93 |
+
ASSERT_THROW(hm.set<string>("key", "zer"), KeyException );
|
| 94 |
+
}
|
pool/shard008/C++/0096567_media_stream_device_permission_context_unittest.cc
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2015 The Chromium Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style license that can be
|
| 3 |
+
// found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
#include "chrome/browser/media/webrtc/media_stream_device_permission_context.h"
|
| 6 |
+
|
| 7 |
+
#include "base/bind.h"
|
| 8 |
+
#include "base/macros.h"
|
| 9 |
+
#include "build/build_config.h"
|
| 10 |
+
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
|
| 11 |
+
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
|
| 12 |
+
#include "chrome/test/base/testing_profile.h"
|
| 13 |
+
#include "components/content_settings/core/browser/host_content_settings_map.h"
|
| 14 |
+
#include "components/content_settings/core/common/content_settings.h"
|
| 15 |
+
#include "components/content_settings/core/common/content_settings_types.h"
|
| 16 |
+
#include "components/infobars/content/content_infobar_manager.h"
|
| 17 |
+
#include "components/permissions/permission_request_id.h"
|
| 18 |
+
#include "content/public/browser/web_contents.h"
|
| 19 |
+
#include "content/public/common/content_features.h"
|
| 20 |
+
#include "content/public/test/mock_render_process_host.h"
|
| 21 |
+
#include "content/public/test/web_contents_tester.h"
|
| 22 |
+
#include "testing/gtest/include/gtest/gtest.h"
|
| 23 |
+
|
| 24 |
+
#if !defined(OS_ANDROID)
|
| 25 |
+
#include "components/permissions/permission_request_manager.h"
|
| 26 |
+
#endif
|
| 27 |
+
|
| 28 |
+
namespace {
|
| 29 |
+
class TestPermissionContext : public MediaStreamDevicePermissionContext {
|
| 30 |
+
public:
|
| 31 |
+
TestPermissionContext(Profile* profile,
|
| 32 |
+
const ContentSettingsType content_settings_type)
|
| 33 |
+
: MediaStreamDevicePermissionContext(profile, content_settings_type) {}
|
| 34 |
+
|
| 35 |
+
~TestPermissionContext() override {}
|
| 36 |
+
};
|
| 37 |
+
|
| 38 |
+
} // anonymous namespace
|
| 39 |
+
|
| 40 |
+
// TODO(raymes): many tests in MediaStreamDevicesControllerTest should be
|
| 41 |
+
// converted to tests in this file.
|
| 42 |
+
class MediaStreamDevicePermissionContextTests
|
| 43 |
+
: public ChromeRenderViewHostTestHarness {
|
| 44 |
+
public:
|
| 45 |
+
MediaStreamDevicePermissionContextTests(
|
| 46 |
+
const MediaStreamDevicePermissionContextTests&) = delete;
|
| 47 |
+
MediaStreamDevicePermissionContextTests& operator=(
|
| 48 |
+
const MediaStreamDevicePermissionContextTests&) = delete;
|
| 49 |
+
|
| 50 |
+
protected:
|
| 51 |
+
MediaStreamDevicePermissionContextTests() = default;
|
| 52 |
+
|
| 53 |
+
void TestInsecureQueryingUrl(ContentSettingsType content_settings_type) {
|
| 54 |
+
TestPermissionContext permission_context(profile(), content_settings_type);
|
| 55 |
+
GURL insecure_url("http://www.example.com");
|
| 56 |
+
GURL secure_url("https://www.example.com");
|
| 57 |
+
|
| 58 |
+
// Check that there is no saved content settings.
|
| 59 |
+
EXPECT_EQ(CONTENT_SETTING_ASK,
|
| 60 |
+
HostContentSettingsMapFactory::GetForProfile(profile())
|
| 61 |
+
->GetContentSetting(insecure_url.DeprecatedGetOriginAsURL(),
|
| 62 |
+
insecure_url.DeprecatedGetOriginAsURL(),
|
| 63 |
+
content_settings_type));
|
| 64 |
+
EXPECT_EQ(CONTENT_SETTING_ASK,
|
| 65 |
+
HostContentSettingsMapFactory::GetForProfile(profile())
|
| 66 |
+
->GetContentSetting(secure_url.DeprecatedGetOriginAsURL(),
|
| 67 |
+
insecure_url.DeprecatedGetOriginAsURL(),
|
| 68 |
+
content_settings_type));
|
| 69 |
+
EXPECT_EQ(CONTENT_SETTING_ASK,
|
| 70 |
+
HostContentSettingsMapFactory::GetForProfile(profile())
|
| 71 |
+
->GetContentSetting(insecure_url.DeprecatedGetOriginAsURL(),
|
| 72 |
+
secure_url.DeprecatedGetOriginAsURL(),
|
| 73 |
+
content_settings_type));
|
| 74 |
+
|
| 75 |
+
EXPECT_EQ(CONTENT_SETTING_BLOCK,
|
| 76 |
+
permission_context
|
| 77 |
+
.GetPermissionStatus(nullptr /* render_frame_host */,
|
| 78 |
+
insecure_url, insecure_url)
|
| 79 |
+
.content_setting);
|
| 80 |
+
|
| 81 |
+
EXPECT_EQ(CONTENT_SETTING_BLOCK,
|
| 82 |
+
permission_context
|
| 83 |
+
.GetPermissionStatus(nullptr /* render_frame_host */,
|
| 84 |
+
insecure_url, secure_url)
|
| 85 |
+
.content_setting);
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
void TestSecureQueryingUrl(ContentSettingsType content_settings_type) {
|
| 89 |
+
TestPermissionContext permission_context(profile(), content_settings_type);
|
| 90 |
+
GURL secure_url("https://www.example.com");
|
| 91 |
+
|
| 92 |
+
// Check that there is no saved content settings.
|
| 93 |
+
EXPECT_EQ(CONTENT_SETTING_ASK,
|
| 94 |
+
HostContentSettingsMapFactory::GetForProfile(profile())
|
| 95 |
+
->GetContentSetting(secure_url.DeprecatedGetOriginAsURL(),
|
| 96 |
+
secure_url.DeprecatedGetOriginAsURL(),
|
| 97 |
+
content_settings_type));
|
| 98 |
+
|
| 99 |
+
EXPECT_EQ(CONTENT_SETTING_ASK,
|
| 100 |
+
permission_context
|
| 101 |
+
.GetPermissionStatus(nullptr /* render_frame_host */,
|
| 102 |
+
secure_url, secure_url)
|
| 103 |
+
.content_setting);
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
private:
|
| 107 |
+
// ChromeRenderViewHostTestHarness:
|
| 108 |
+
void SetUp() override {
|
| 109 |
+
ChromeRenderViewHostTestHarness::SetUp();
|
| 110 |
+
#if defined(OS_ANDROID)
|
| 111 |
+
infobars::ContentInfoBarManager::CreateForWebContents(web_contents());
|
| 112 |
+
#else
|
| 113 |
+
permissions::PermissionRequestManager::CreateForWebContents(web_contents());
|
| 114 |
+
#endif
|
| 115 |
+
}
|
| 116 |
+
};
|
| 117 |
+
|
| 118 |
+
// MEDIASTREAM_MIC permission status should be ask for insecure origin to
|
| 119 |
+
// accommodate the usage case of Flash.
|
| 120 |
+
TEST_F(MediaStreamDevicePermissionContextTests, TestMicInsecureQueryingUrl) {
|
| 121 |
+
TestInsecureQueryingUrl(ContentSettingsType::MEDIASTREAM_MIC);
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
// MEDIASTREAM_CAMERA permission status should be ask for insecure origin to
|
| 125 |
+
// accommodate the usage case of Flash.
|
| 126 |
+
TEST_F(MediaStreamDevicePermissionContextTests, TestCameraInsecureQueryingUrl) {
|
| 127 |
+
TestInsecureQueryingUrl(ContentSettingsType::MEDIASTREAM_CAMERA);
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
// MEDIASTREAM_MIC permission status should be ask for Secure origin.
|
| 131 |
+
TEST_F(MediaStreamDevicePermissionContextTests, TestMicSecureQueryingUrl) {
|
| 132 |
+
TestSecureQueryingUrl(ContentSettingsType::MEDIASTREAM_MIC);
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
// MEDIASTREAM_CAMERA permission status should be ask for Secure origin.
|
| 136 |
+
TEST_F(MediaStreamDevicePermissionContextTests, TestCameraSecureQueryingUrl) {
|
| 137 |
+
TestSecureQueryingUrl(ContentSettingsType::MEDIASTREAM_CAMERA);
|
| 138 |
+
}
|
pool/shard008/C++/0096568_UrlFilter.cpp
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Simple Chat
|
| 2 |
+
* Copyright (c) 2008-2014 Alexander Sedov <imp@schat.me>
|
| 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 3 of the License, or
|
| 7 |
+
* (at your option) any later version.
|
| 8 |
+
*
|
| 9 |
+
* This program is distributed in the hope that it will be useful,
|
| 10 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12 |
+
* GNU General Public License for more details.
|
| 13 |
+
*
|
| 14 |
+
* You should have received a copy of the GNU General Public License
|
| 15 |
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 16 |
+
*/
|
| 17 |
+
|
| 18 |
+
#include <QUrl>
|
| 19 |
+
|
| 20 |
+
#include "ChatUrls.h"
|
| 21 |
+
#include "net/SimpleID.h"
|
| 22 |
+
#include "QtEscape.h"
|
| 23 |
+
#include "sglobal.h"
|
| 24 |
+
#include "text/UrlFilter.h"
|
| 25 |
+
|
| 26 |
+
bool UrlFilter::filter(QList<HtmlToken> &tokens, const ChatId &id) const
|
| 27 |
+
{
|
| 28 |
+
Q_UNUSED(id)
|
| 29 |
+
|
| 30 |
+
QString name;
|
| 31 |
+
bool modified;
|
| 32 |
+
|
| 33 |
+
for (int i = 0; i < tokens.size(); ++i) {
|
| 34 |
+
const HtmlToken &token = tokens.at(i);
|
| 35 |
+
if (token.type == HtmlToken::StartTag && token.tag == LS("a")) {
|
| 36 |
+
HtmlATag tag(tokens.at(i));
|
| 37 |
+
modified = false;
|
| 38 |
+
|
| 39 |
+
if (tag.url.startsWith(LS("chat://channel/"))) {
|
| 40 |
+
tag.classes = LS("nick");
|
| 41 |
+
ClientChannel user = ChatUrls::channel(QUrl(tag.url));
|
| 42 |
+
if (user) {
|
| 43 |
+
tag.classes += LC(' ') + SimpleID::encode(user->id());
|
| 44 |
+
name = user->name();
|
| 45 |
+
|
| 46 |
+
tag.classes += LS(" color-") + Gender::colorToString(user->gender().color());
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
modified = true;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
if (QUrl(tag.url).scheme() == LS("javascript")) {
|
| 53 |
+
tag.url = QString();
|
| 54 |
+
modified = true;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
if (tag.title.isEmpty()) {
|
| 58 |
+
tag.title = tag.url;
|
| 59 |
+
modified = true;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
if (modified)
|
| 63 |
+
tokens[i].text = tag.toText();
|
| 64 |
+
}
|
| 65 |
+
else if (token.type == HtmlToken::Text && !name.isEmpty()) {
|
| 66 |
+
tokens[i].text = Qt::escape(name);
|
| 67 |
+
name.clear();
|
| 68 |
+
}
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
return true;
|
| 72 |
+
}
|
pool/shard008/C++/0096569_ImportDeviceDialog.cpp
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "ImportDeviceDialog.h"
|
| 2 |
+
|
| 3 |
+
#include <iostream>
|
| 4 |
+
|
| 5 |
+
#include <QtCore/QTextCodec>
|
| 6 |
+
#include <QtCore/QTextStream>
|
| 7 |
+
|
| 8 |
+
#include <QtGui/QCloseEvent>
|
| 9 |
+
|
| 10 |
+
#include <QtWidgets/QAbstractButton>
|
| 11 |
+
#include <QtWidgets/QMessageBox>
|
| 12 |
+
|
| 13 |
+
ImportDeviceDialog::ImportDeviceDialog(QWidget* parent)
|
| 14 |
+
: QDialog(parent)
|
| 15 |
+
{
|
| 16 |
+
setupUi(this);
|
| 17 |
+
|
| 18 |
+
this->treeWidgetDevice->headerItem()->setText(0, "");
|
| 19 |
+
this->treeWidgetDevice->setColumnWidth(0, 25);
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
void ImportDeviceDialog::setImportFile(const QString& path)
|
| 23 |
+
{
|
| 24 |
+
QFile file(path);
|
| 25 |
+
if (file.open(QFile::ReadOnly | QIODevice::Text))
|
| 26 |
+
{
|
| 27 |
+
QTextStream stream(&file);
|
| 28 |
+
stream.setCodec(QTextCodec::codecForName("UTF-8"));
|
| 29 |
+
|
| 30 |
+
std::wstringstream wstringstream;
|
| 31 |
+
wstringstream << stream.readAll().toStdWString();
|
| 32 |
+
|
| 33 |
+
boost::property_tree::wptree pt;
|
| 34 |
+
boost::property_tree::xml_parser::read_xml(wstringstream, pt);
|
| 35 |
+
|
| 36 |
+
BOOST_FOREACH(boost::property_tree::wptree::value_type& parentValue, pt.get_child(L"servers"))
|
| 37 |
+
{
|
| 38 |
+
this->models.push_back(parseData(parentValue.second));
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
foreach (DeviceModel model, this->models)
|
| 42 |
+
{
|
| 43 |
+
QTreeWidgetItem* treeItem = new QTreeWidgetItem(this->treeWidgetDevice);
|
| 44 |
+
treeItem->setIcon(0, QIcon(":/Graphics/Images/ServerSmall.png"));
|
| 45 |
+
treeItem->setText(1, model.getName());
|
| 46 |
+
treeItem->setText(2, model.getDescription());
|
| 47 |
+
}
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
DeviceModel ImportDeviceDialog::parseData(boost::property_tree::wptree& pt)
|
| 52 |
+
{
|
| 53 |
+
QString name = QString::fromStdWString(pt.get(L"name", L""));
|
| 54 |
+
QString address = QString::fromStdWString(pt.get(L"address", L""));
|
| 55 |
+
QString port = QString::fromStdWString(pt.get(L"port", L"5250"));
|
| 56 |
+
QString username = QString::fromStdWString(pt.get(L"username", L""));
|
| 57 |
+
QString password = QString::fromStdWString(pt.get(L"password", L""));
|
| 58 |
+
QString description = QString::fromStdWString(pt.get(L"description", L""));
|
| 59 |
+
QString shadow = QString::fromStdWString(pt.get(L"shadow", L"No"));
|
| 60 |
+
QString previewChannel = QString::fromStdWString(pt.get(L"previewchannel", L"0"));
|
| 61 |
+
QString lockedChannel = QString::fromStdWString(pt.get(L"lockedchannel", L"0"));
|
| 62 |
+
|
| 63 |
+
return DeviceModel(0, name, address, port.toInt(), username, password, description, "", shadow, 0, "", previewChannel.toInt(), lockedChannel.toInt());
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
const QList<DeviceModel> ImportDeviceDialog::getDevice() const
|
| 67 |
+
{
|
| 68 |
+
QList<DeviceModel> models;
|
| 69 |
+
for (int i = 0; i < this->treeWidgetDevice->invisibleRootItem()->childCount(); i++)
|
| 70 |
+
{
|
| 71 |
+
QTreeWidgetItem* item = this->treeWidgetDevice->invisibleRootItem()->child(i);
|
| 72 |
+
if (item->isSelected())
|
| 73 |
+
models.push_back(this->models.at(i));
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
return models;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
void ImportDeviceDialog::accept()
|
| 80 |
+
{
|
| 81 |
+
QDialog::accept();
|
| 82 |
+
}
|
pool/shard008/C++/0096571_chown.cpp
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 1992, Brian Berliner and Jeff Polk
|
| 3 |
+
* Copyright (c) 1989-1992, Brian Berliner
|
| 4 |
+
*
|
| 5 |
+
* You may distribute under the terms of the GNU General Public License as
|
| 6 |
+
* specified in the README file that comes with the CVS 1.4 kit.
|
| 7 |
+
*
|
| 8 |
+
* chown
|
| 9 |
+
*
|
| 10 |
+
* Changes the owner of a directory to the given name.
|
| 11 |
+
*/
|
| 12 |
+
|
| 13 |
+
#include "cvs.h"
|
| 14 |
+
#include "fileattr.h"
|
| 15 |
+
|
| 16 |
+
static const char *chown_user;
|
| 17 |
+
|
| 18 |
+
static const char *const chown_usage[] =
|
| 19 |
+
{
|
| 20 |
+
"Usage: %s %s [-R] user directory...\n",
|
| 21 |
+
"\t-R\tChange owner recursively\n",
|
| 22 |
+
NULL
|
| 23 |
+
};
|
| 24 |
+
|
| 25 |
+
static const char *const rchown_usage[] =
|
| 26 |
+
{
|
| 27 |
+
"Usage: %s %s [-R] user module...\n",
|
| 28 |
+
"\t-R\tChange owner recursively\n",
|
| 29 |
+
NULL
|
| 30 |
+
};
|
| 31 |
+
|
| 32 |
+
static Dtype chown_dirproc (void *callerdat, char *dir, char *repos, char *update_dir, List *entries, const char *virtual_repository, Dtype hint);
|
| 33 |
+
static int rchown_proc(int argc, char **argv, const char *xwhere,
|
| 34 |
+
const char *mwhere, const char *mfile, int shorten,
|
| 35 |
+
int local_specified, const char *mname, const char *msg);
|
| 36 |
+
|
| 37 |
+
int chowner (int argc, char **argv)
|
| 38 |
+
{
|
| 39 |
+
int c;
|
| 40 |
+
int err = 0;
|
| 41 |
+
int local = 1;
|
| 42 |
+
int is_rchown = !strcmp(command_name,"rchown");
|
| 43 |
+
|
| 44 |
+
if (argc == 1 || argc == -1)
|
| 45 |
+
usage (is_rchown?rchown_usage:chown_usage);
|
| 46 |
+
|
| 47 |
+
optind = 0;
|
| 48 |
+
while ((c = getopt (argc, argv, "+R")) != -1)
|
| 49 |
+
{
|
| 50 |
+
switch (c)
|
| 51 |
+
{
|
| 52 |
+
case 'R':
|
| 53 |
+
local = 0;
|
| 54 |
+
break;
|
| 55 |
+
case '?':
|
| 56 |
+
default:
|
| 57 |
+
usage (chown_usage);
|
| 58 |
+
break;
|
| 59 |
+
}
|
| 60 |
+
}
|
| 61 |
+
argc -= optind;
|
| 62 |
+
argv += optind;
|
| 63 |
+
|
| 64 |
+
if (argc <= 0)
|
| 65 |
+
usage (chown_usage);
|
| 66 |
+
|
| 67 |
+
if (current_parsed_root->isremote)
|
| 68 |
+
{
|
| 69 |
+
if(is_rchown)
|
| 70 |
+
{
|
| 71 |
+
if (!supported_request ("rchown"))
|
| 72 |
+
error (1, 0, "server does not support rchown");
|
| 73 |
+
}
|
| 74 |
+
else
|
| 75 |
+
{
|
| 76 |
+
if (!supported_request ("chown"))
|
| 77 |
+
error (1, 0, "server does not support chown");
|
| 78 |
+
}
|
| 79 |
+
if(!local)
|
| 80 |
+
{
|
| 81 |
+
send_arg("-R");
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
send_arg("--");
|
| 85 |
+
send_arg(argv[0]);
|
| 86 |
+
argv++;
|
| 87 |
+
argc--;
|
| 88 |
+
if (is_rchown)
|
| 89 |
+
{
|
| 90 |
+
for (int i = 0; i < argc; i++)
|
| 91 |
+
send_arg (argv[i]);
|
| 92 |
+
send_to_server ("rchown\n", 0);
|
| 93 |
+
}
|
| 94 |
+
else
|
| 95 |
+
{
|
| 96 |
+
send_file_names (argc, argv, SEND_EXPAND_WILD);
|
| 97 |
+
send_files (argc, argv, local, 0, SEND_NO_CONTENTS);
|
| 98 |
+
send_to_server ("chown\n", 0);
|
| 99 |
+
}
|
| 100 |
+
return get_responses_and_close ();
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
chown_user = argv[0];
|
| 104 |
+
argv++;
|
| 105 |
+
argc--;
|
| 106 |
+
|
| 107 |
+
if(!acl_mode)
|
| 108 |
+
error(1,0,"Access control is disabled on this repository.");
|
| 109 |
+
|
| 110 |
+
if (is_rchown)
|
| 111 |
+
{
|
| 112 |
+
DBM *db;
|
| 113 |
+
int i;
|
| 114 |
+
db = open_module ();
|
| 115 |
+
for (i = 0; i < argc; i++)
|
| 116 |
+
{
|
| 117 |
+
err += do_module (db, argv[i], MISC, "Changing", rchown_proc,
|
| 118 |
+
(char *) NULL, 0, local, 0, 0, (char *) NULL);
|
| 119 |
+
}
|
| 120 |
+
close_module (db);
|
| 121 |
+
}
|
| 122 |
+
else
|
| 123 |
+
{
|
| 124 |
+
/* start the recursion processor */
|
| 125 |
+
err = start_recursion ((FILEPROC) NULL, (FILESDONEPROC) NULL,
|
| 126 |
+
(PREDIRENTPROC) NULL, chown_dirproc, (DIRLEAVEPROC) NULL, NULL,
|
| 127 |
+
argc, argv, local,
|
| 128 |
+
W_LOCAL, 0, 1, (char *) NULL, NULL, 1, verify_control);
|
| 129 |
+
}
|
| 130 |
+
return (err);
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
static Dtype chown_dirproc (void *callerdat, char *dir, char *repos, char *update_dir, List *entries, const char *virtual_repository, Dtype hint)
|
| 134 |
+
{
|
| 135 |
+
if(hint!=R_PROCESS)
|
| 136 |
+
return hint;
|
| 137 |
+
|
| 138 |
+
if(!quiet)
|
| 139 |
+
printf("Changing owner for directory %s\n",update_dir);
|
| 140 |
+
change_owner(chown_user);
|
| 141 |
+
return R_PROCESS;
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
static int rchown_proc(int argc, char **argv, const char *xwhere,
|
| 145 |
+
const char *mwhere, const char *mfile, int shorten,
|
| 146 |
+
int local_specified, const char *mname, const char *msg)
|
| 147 |
+
{
|
| 148 |
+
/* Begin section which is identical to patch_proc--should this
|
| 149 |
+
be abstracted out somehow? */
|
| 150 |
+
char *myargv[2];
|
| 151 |
+
int err = 0;
|
| 152 |
+
char *repository, *mapped_repository;
|
| 153 |
+
char *where;
|
| 154 |
+
|
| 155 |
+
repository = (char*)xmalloc (strlen (current_parsed_root->directory) + strlen (argv[0])
|
| 156 |
+
+ (mfile == NULL ? 0 : strlen (mfile) + 1) + 2);
|
| 157 |
+
(void) sprintf (repository, "%s/%s", current_parsed_root->directory, argv[0]);
|
| 158 |
+
where = (char*)xmalloc (strlen (argv[0]) + (mfile == NULL ? 0 : strlen (mfile) + 1)
|
| 159 |
+
+ 1);
|
| 160 |
+
(void) strcpy (where, argv[0]);
|
| 161 |
+
|
| 162 |
+
/* if mfile isn't null, we need to set up to do only part of the module */
|
| 163 |
+
if (mfile != NULL)
|
| 164 |
+
{
|
| 165 |
+
char *cp;
|
| 166 |
+
char *path;
|
| 167 |
+
|
| 168 |
+
/* if the portion of the module is a path, put the dir part on repos */
|
| 169 |
+
if ((cp = (char*)strrchr (mfile, '/')) != NULL)
|
| 170 |
+
{
|
| 171 |
+
*cp = '\0';
|
| 172 |
+
(void) strcat (repository, "/");
|
| 173 |
+
(void) strcat (repository, mfile);
|
| 174 |
+
(void) strcat (where, "/");
|
| 175 |
+
(void) strcat (where, mfile);
|
| 176 |
+
mfile = cp + 1;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
/* take care of the rest */
|
| 180 |
+
path = (char*)xmalloc (strlen (repository) + strlen (mfile) + 5);
|
| 181 |
+
(void) sprintf (path, "%s/%s", repository, mfile);
|
| 182 |
+
if (isdir (path))
|
| 183 |
+
{
|
| 184 |
+
/* directory means repository gets the dir tacked on */
|
| 185 |
+
(void) strcpy (repository, path);
|
| 186 |
+
(void) strcat (where, "/");
|
| 187 |
+
(void) strcat (where, mfile);
|
| 188 |
+
}
|
| 189 |
+
else
|
| 190 |
+
{
|
| 191 |
+
myargv[0] = argv[0];
|
| 192 |
+
myargv[1] = (char*)mfile;
|
| 193 |
+
argc = 2;
|
| 194 |
+
argv = myargv;
|
| 195 |
+
}
|
| 196 |
+
xfree (path);
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
mapped_repository = map_repository(repository);
|
| 200 |
+
|
| 201 |
+
/* cd to the starting repository */
|
| 202 |
+
if ( CVS_CHDIR (mapped_repository) < 0)
|
| 203 |
+
{
|
| 204 |
+
error (0, errno, "cannot chdir to %s", fn_root(repository));
|
| 205 |
+
xfree (repository);
|
| 206 |
+
xfree (mapped_repository);
|
| 207 |
+
return (1);
|
| 208 |
+
}
|
| 209 |
+
xfree (repository);
|
| 210 |
+
/* End section which is identical to patch_proc. */
|
| 211 |
+
|
| 212 |
+
err = start_recursion (NULL, (FILESDONEPROC) NULL, (PREDIRENTPROC) NULL, chown_dirproc,
|
| 213 |
+
(DIRLEAVEPROC) NULL, NULL,
|
| 214 |
+
argc - 1, argv + 1, local_specified, W_REPOS, 0, 1,
|
| 215 |
+
where, mapped_repository, 1, verify_control);
|
| 216 |
+
|
| 217 |
+
xfree (mapped_repository);
|
| 218 |
+
return err;
|
| 219 |
+
}
|
pool/shard008/C++/0096575_firstrun.cpp
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*****************************************************************************
|
| 2 |
+
* firstrun.cpp : First Run dialogs
|
| 3 |
+
****************************************************************************
|
| 4 |
+
* Copyright © 2009 VideoLAN
|
| 5 |
+
* $Id$
|
| 6 |
+
*
|
| 7 |
+
* Authors: Jean-Baptiste Kempf <jb (at) videolan.org>
|
| 8 |
+
*
|
| 9 |
+
* This program is free software; you can redistribute it and/or modify
|
| 10 |
+
* it under the terms of the GNU General Public License as published by
|
| 11 |
+
* the Free Software Foundation; either version 2 of the License, or
|
| 12 |
+
* (at your option) any later version.
|
| 13 |
+
*
|
| 14 |
+
* This program is distributed in the hope that it will be useful,
|
| 15 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 16 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 17 |
+
* GNU General Public License for more details.
|
| 18 |
+
*
|
| 19 |
+
* You should have received a copy of the GNU General Public License
|
| 20 |
+
* along with this program; if not, write to the Free Software Foundation, Inc.,
|
| 21 |
+
* 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
|
| 22 |
+
*****************************************************************************/
|
| 23 |
+
|
| 24 |
+
#include "dialogs/firstrun.hpp"
|
| 25 |
+
|
| 26 |
+
#include <QGridLayout>
|
| 27 |
+
#include <QGroupBox>
|
| 28 |
+
#include <QCheckBox>
|
| 29 |
+
#include <QLabel>
|
| 30 |
+
#include <QDialogButtonBox>
|
| 31 |
+
|
| 32 |
+
FirstRun::FirstRun( QWidget *_p, intf_thread_t *_p_intf )
|
| 33 |
+
: QWidget( _p ), p_intf( _p_intf )
|
| 34 |
+
{
|
| 35 |
+
msg_Dbg( p_intf, "Boring first Run Wizard" );
|
| 36 |
+
buildPrivDialog();
|
| 37 |
+
setVisible( true );
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
#define ALBUM_ART_WHEN_ASKED 0
|
| 41 |
+
#define ALBUM_ART_ALL 2
|
| 42 |
+
|
| 43 |
+
void FirstRun::save()
|
| 44 |
+
{
|
| 45 |
+
config_PutInt( p_intf, "album-art", checkbox->isChecked() ? ALBUM_ART_ALL: ALBUM_ART_WHEN_ASKED );
|
| 46 |
+
#ifdef UPDATE_CHECK
|
| 47 |
+
config_PutInt( p_intf, "qt-updates-notif", checkbox2->isChecked() );
|
| 48 |
+
#endif
|
| 49 |
+
config_PutInt( p_intf, "qt-privacy-ask", 0 );
|
| 50 |
+
|
| 51 |
+
/* FIXME Should not save here. This will not work as expected if another
|
| 52 |
+
* plugin overwrote items of its own. */
|
| 53 |
+
#warning FIXME
|
| 54 |
+
/* We have to save here because the user may not launch Prefs */
|
| 55 |
+
config_SaveConfigFile( p_intf );
|
| 56 |
+
close();
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
void FirstRun::buildPrivDialog()
|
| 60 |
+
{
|
| 61 |
+
setWindowTitle( qtr( "Privacy and Network Access Policy" ) );
|
| 62 |
+
setWindowRole( "vlc-privacy" );
|
| 63 |
+
setWindowModality( Qt::ApplicationModal );
|
| 64 |
+
setWindowFlags( Qt::Dialog );
|
| 65 |
+
setAttribute( Qt::WA_DeleteOnClose );
|
| 66 |
+
|
| 67 |
+
QGridLayout *gLayout = new QGridLayout( this );
|
| 68 |
+
|
| 69 |
+
QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Access Policy" ) );
|
| 70 |
+
QGridLayout *blablaLayout = new QGridLayout( blabla );
|
| 71 |
+
QLabel *text = new QLabel( qtr(
|
| 72 |
+
"<p>In order to protect your privacy, <i>VLC media player</i> "
|
| 73 |
+
"does <b>not</b> collect personal data or transmit them, "
|
| 74 |
+
"not even in anonymized form, to anyone."
|
| 75 |
+
"</p>\n"
|
| 76 |
+
"<p>Nevertheless, <i>VLC</i> is able to automatically retrieve "
|
| 77 |
+
"information about the media in your playlist from third party "
|
| 78 |
+
"Internet-based services. This includes cover art, track names, "
|
| 79 |
+
"artist names and other meta-data."
|
| 80 |
+
"</p>\n"
|
| 81 |
+
"<p>Consequently, this may entail identifying some of your media files to third party "
|
| 82 |
+
"entities. Therefore the <i>VLC</i> developers require your express "
|
| 83 |
+
"consent for the media player to access the Internet automatically."
|
| 84 |
+
"</p>\n"
|
| 85 |
+
) );
|
| 86 |
+
text->setWordWrap( true );
|
| 87 |
+
text->setTextFormat( Qt::RichText );
|
| 88 |
+
|
| 89 |
+
blablaLayout->addWidget( text, 0, 0 ) ;
|
| 90 |
+
|
| 91 |
+
QGroupBox *options = new QGroupBox( qtr( "Network Access Policy" ) );
|
| 92 |
+
QGridLayout *optionsLayout = new QGridLayout( options );
|
| 93 |
+
|
| 94 |
+
gLayout->addWidget( blabla, 0, 0, 1, 3 );
|
| 95 |
+
gLayout->addWidget( options, 1, 0, 1, 3 );
|
| 96 |
+
int line = 0;
|
| 97 |
+
|
| 98 |
+
checkbox = new QCheckBox( qtr( "Automatically retrieve media info" ) );
|
| 99 |
+
checkbox->setChecked( true );
|
| 100 |
+
optionsLayout->addWidget( checkbox, line++, 0 );
|
| 101 |
+
|
| 102 |
+
#ifdef UPDATE_CHECK
|
| 103 |
+
checkbox2 = new QCheckBox( qtr( "Regularly check for VLC updates" ) );
|
| 104 |
+
checkbox2->setChecked( true );
|
| 105 |
+
optionsLayout->addWidget( checkbox2, line++, 0 );
|
| 106 |
+
#endif
|
| 107 |
+
|
| 108 |
+
QDialogButtonBox *buttonsBox = new QDialogButtonBox( this );
|
| 109 |
+
buttonsBox->addButton( qtr( "Continue" ), QDialogButtonBox::AcceptRole );
|
| 110 |
+
|
| 111 |
+
gLayout->addWidget( buttonsBox, 2, 0, 2, 3 );
|
| 112 |
+
|
| 113 |
+
CONNECT( buttonsBox, accepted(), this, save() );
|
| 114 |
+
buttonsBox->setFocus();
|
| 115 |
+
}
|
pool/shard008/C++/0096577_catv_randomizer_bb_impl.cc
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* -*- c++ -*- */
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2016,2017 Free Software Foundation, Inc.
|
| 4 |
+
*
|
| 5 |
+
* This is free software; you can redistribute it and/or modify
|
| 6 |
+
* it under the terms of the GNU General Public License as published by
|
| 7 |
+
* the Free Software Foundation; either version 3, or (at your option)
|
| 8 |
+
* any later version.
|
| 9 |
+
*
|
| 10 |
+
* This software 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 software; see the file COPYING. If not, write to
|
| 17 |
+
* the Free Software Foundation, Inc., 51 Franklin Street,
|
| 18 |
+
* Boston, MA 02110-1301, USA.
|
| 19 |
+
*/
|
| 20 |
+
|
| 21 |
+
#include "catv_randomizer_bb_impl.h"
|
| 22 |
+
#include <gnuradio/io_signature.h>
|
| 23 |
+
|
| 24 |
+
namespace gr {
|
| 25 |
+
namespace dtv {
|
| 26 |
+
|
| 27 |
+
catv_randomizer_bb::sptr catv_randomizer_bb::make(catv_constellation_t constellation)
|
| 28 |
+
{
|
| 29 |
+
return gnuradio::get_initial_sptr(new catv_randomizer_bb_impl(constellation));
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
/*
|
| 33 |
+
* The private constructor
|
| 34 |
+
*/
|
| 35 |
+
catv_randomizer_bb_impl::catv_randomizer_bb_impl(catv_constellation_t constellation)
|
| 36 |
+
: gr::sync_block("catv_randomizer_bb",
|
| 37 |
+
gr::io_signature::make(1, 1, sizeof(unsigned char)),
|
| 38 |
+
gr::io_signature::make(1, 1, sizeof(unsigned char)))
|
| 39 |
+
{
|
| 40 |
+
offset = 0;
|
| 41 |
+
if (constellation == CATV_MOD_64QAM) {
|
| 42 |
+
max_offset = 60 * 128;
|
| 43 |
+
} else {
|
| 44 |
+
max_offset = 88 * 128;
|
| 45 |
+
}
|
| 46 |
+
init_rand();
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
/*
|
| 50 |
+
* Our virtual destructor.
|
| 51 |
+
*/
|
| 52 |
+
catv_randomizer_bb_impl::~catv_randomizer_bb_impl() {}
|
| 53 |
+
|
| 54 |
+
void catv_randomizer_bb_impl::init_rand()
|
| 55 |
+
{
|
| 56 |
+
unsigned char c2 = 0x7F, c1 = 0x7F, c0 = 0x7F;
|
| 57 |
+
unsigned char c2_new, c1_new, c0_new;
|
| 58 |
+
int n, i;
|
| 59 |
+
|
| 60 |
+
for (n = 0; n < max_offset; n++) {
|
| 61 |
+
rseq[n] = c2;
|
| 62 |
+
c2_new = c1;
|
| 63 |
+
c1_new = c0 ^ c2;
|
| 64 |
+
c0_new = c2;
|
| 65 |
+
for (i = 0; i < 3; i++) {
|
| 66 |
+
c0_new <<= 1;
|
| 67 |
+
if (c0_new & 0x80) {
|
| 68 |
+
c0_new = (c0_new & 0x7F) ^ 0x09;
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
c2 = c2_new;
|
| 72 |
+
c1 = c1_new;
|
| 73 |
+
c0 = c0_new;
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
int catv_randomizer_bb_impl::work(int noutput_items,
|
| 78 |
+
gr_vector_const_void_star& input_items,
|
| 79 |
+
gr_vector_void_star& output_items)
|
| 80 |
+
{
|
| 81 |
+
const unsigned char* in = (const unsigned char*)input_items[0];
|
| 82 |
+
unsigned char* out = (unsigned char*)output_items[0];
|
| 83 |
+
|
| 84 |
+
for (int i = 0; i < noutput_items; i++) {
|
| 85 |
+
out[i] = in[i] ^ rseq[offset++];
|
| 86 |
+
if (offset == max_offset) {
|
| 87 |
+
offset = 0;
|
| 88 |
+
}
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
// Tell runtime system how many output items we produced.
|
| 92 |
+
return noutput_items;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
} /* namespace dtv */
|
| 96 |
+
} /* namespace gr */
|
pool/shard008/C++/0096578_AP_Follow.cpp
ADDED
|
@@ -0,0 +1,392 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
This program is free software: you can redistribute it and/or modify
|
| 3 |
+
it under the terms of the GNU General Public License as published by
|
| 4 |
+
the Free Software Foundation, either version 3 of the License, or
|
| 5 |
+
(at your option) any later version.
|
| 6 |
+
|
| 7 |
+
This program is distributed in the hope that it will be useful,
|
| 8 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 9 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 10 |
+
GNU General Public License for more details.
|
| 11 |
+
|
| 12 |
+
You should have received a copy of the GNU General Public License
|
| 13 |
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 14 |
+
*/
|
| 15 |
+
|
| 16 |
+
#include <AP_HAL/AP_HAL.h>
|
| 17 |
+
#include <GCS_MAVLink/GCS.h>
|
| 18 |
+
#include "AP_Follow.h"
|
| 19 |
+
#include <ctype.h>
|
| 20 |
+
#include <stdio.h>
|
| 21 |
+
|
| 22 |
+
extern const AP_HAL::HAL& hal;
|
| 23 |
+
|
| 24 |
+
#define AP_FOLLOW_TIMEOUT_MS 3000 // position estimate timeout after 1 second
|
| 25 |
+
#define AP_FOLLOW_SYSID_TIMEOUT_MS 10000 // forget sysid we are following if we haave not heard from them in 10 seconds
|
| 26 |
+
|
| 27 |
+
#define AP_FOLLOW_OFFSET_TYPE_NED 0 // offsets are in north-east-down frame
|
| 28 |
+
#define AP_FOLLOW_OFFSET_TYPE_RELATIVE 1 // offsets are relative to lead vehicle's heading
|
| 29 |
+
|
| 30 |
+
#define AP_FOLLOW_ALTITUDE_TYPE_RELATIVE 1 // relative altitude is used by default
|
| 31 |
+
|
| 32 |
+
#define AP_FOLLOW_POS_P_DEFAULT 0.1f // position error gain default
|
| 33 |
+
|
| 34 |
+
// table of user settable parameters
|
| 35 |
+
const AP_Param::GroupInfo AP_Follow::var_info[] = {
|
| 36 |
+
|
| 37 |
+
// @Param: _ENABLE
|
| 38 |
+
// @DisplayName: Follow enable/disable
|
| 39 |
+
// @Description: Enabled/disable following a target
|
| 40 |
+
// @Values: 0:Disabled,1:Enabled
|
| 41 |
+
// @User: Standard
|
| 42 |
+
AP_GROUPINFO_FLAGS("_ENABLE", 1, AP_Follow, _enabled, 0, AP_PARAM_FLAG_ENABLE),
|
| 43 |
+
|
| 44 |
+
// 2 is reserved for TYPE parameter
|
| 45 |
+
|
| 46 |
+
// @Param: _SYSID
|
| 47 |
+
// @DisplayName: Follow target's mavlink system id
|
| 48 |
+
// @Description: Follow target's mavlink system id
|
| 49 |
+
// @Range: 0 255
|
| 50 |
+
// @User: Standard
|
| 51 |
+
AP_GROUPINFO("_SYSID", 3, AP_Follow, _sysid, 0),
|
| 52 |
+
|
| 53 |
+
// 4 is reserved for MARGIN parameter
|
| 54 |
+
|
| 55 |
+
// @Param: _DIST_MAX
|
| 56 |
+
// @DisplayName: Follow distance maximum
|
| 57 |
+
// @Description: Follow distance maximum. targets further than this will be ignored
|
| 58 |
+
// @Units: m
|
| 59 |
+
// @Range: 1 1000
|
| 60 |
+
// @User: Standard
|
| 61 |
+
AP_GROUPINFO("_DIST_MAX", 5, AP_Follow, _dist_max, 100),
|
| 62 |
+
|
| 63 |
+
// @Param: _OFS_TYPE
|
| 64 |
+
// @DisplayName: Follow offset type
|
| 65 |
+
// @Description: Follow offset type
|
| 66 |
+
// @Values: 0:North-East-Down, 1:Relative to lead vehicle heading
|
| 67 |
+
// @User: Standard
|
| 68 |
+
AP_GROUPINFO("_OFS_TYPE", 6, AP_Follow, _offset_type, AP_FOLLOW_OFFSET_TYPE_NED),
|
| 69 |
+
|
| 70 |
+
// @Param: _OFS_X
|
| 71 |
+
// @DisplayName: Follow offsets in meters north/forward
|
| 72 |
+
// @Description: Follow offsets in meters north/forward. If positive, this vehicle fly ahead or north of lead vehicle. Depends on FOLL_OFS_TYPE
|
| 73 |
+
// @Range: -100 100
|
| 74 |
+
// @Units: m
|
| 75 |
+
// @Increment: 1
|
| 76 |
+
// @User: Standard
|
| 77 |
+
|
| 78 |
+
// @Param: _OFS_Y
|
| 79 |
+
// @DisplayName: Follow offsets in meters east/right
|
| 80 |
+
// @Description: Follow offsets in meters east/right. If positive, this vehicle fly to the right or east of lead vehicle. Depends on FOLL_OFS_TYPE
|
| 81 |
+
// @Range: -100 100
|
| 82 |
+
// @Units: m
|
| 83 |
+
// @Increment: 1
|
| 84 |
+
// @User: Standard
|
| 85 |
+
|
| 86 |
+
// @Param: _OFS_Z
|
| 87 |
+
// @DisplayName: Follow offsets in meters down
|
| 88 |
+
// @Description: Follow offsets in meters down. If positive, this vehicle fly below the lead vehicle
|
| 89 |
+
// @Range: -100 100
|
| 90 |
+
// @Units: m
|
| 91 |
+
// @Increment: 1
|
| 92 |
+
// @User: Standard
|
| 93 |
+
AP_GROUPINFO("_OFS", 7, AP_Follow, _offset, 0),
|
| 94 |
+
|
| 95 |
+
// @Param: _YAW_BEHAVE
|
| 96 |
+
// @DisplayName: Follow yaw behaviour
|
| 97 |
+
// @Description: Follow yaw behaviour
|
| 98 |
+
// @Values: 0:None,1:Face Lead Vehicle,2:Same as Lead vehicle,3:Direction of Flight
|
| 99 |
+
// @User: Standard
|
| 100 |
+
AP_GROUPINFO("_YAW_BEHAVE", 8, AP_Follow, _yaw_behave, 1),
|
| 101 |
+
|
| 102 |
+
// @Param: _POS_P
|
| 103 |
+
// @DisplayName: Follow position error P gain
|
| 104 |
+
// @Description: Follow position error P gain. Converts the difference between desired vertical speed and actual speed into a desired acceleration that is passed to the throttle acceleration controller
|
| 105 |
+
// @Range: 0.01 1.00
|
| 106 |
+
// @Increment: 0.01
|
| 107 |
+
// @User: Standard
|
| 108 |
+
AP_SUBGROUPINFO(_p_pos, "_POS_", 9, AP_Follow, AC_P),
|
| 109 |
+
|
| 110 |
+
// @Param: _ALT_TYPE
|
| 111 |
+
// @DisplayName: Follow altitude type
|
| 112 |
+
// @Description: Follow altitude type
|
| 113 |
+
// @Values: 0:absolute, 1: relative
|
| 114 |
+
// @User: Standard
|
| 115 |
+
AP_GROUPINFO("_ALT_TYPE", 10, AP_Follow, _alt_type, AP_FOLLOW_ALTITUDE_TYPE_RELATIVE),
|
| 116 |
+
|
| 117 |
+
AP_GROUPEND
|
| 118 |
+
};
|
| 119 |
+
|
| 120 |
+
/*
|
| 121 |
+
The constructor also initialises the proximity sensor. Note that this
|
| 122 |
+
constructor is not called until detect() returns true, so we
|
| 123 |
+
already know that we should setup the proximity sensor
|
| 124 |
+
*/
|
| 125 |
+
AP_Follow::AP_Follow() :
|
| 126 |
+
_p_pos(AP_FOLLOW_POS_P_DEFAULT)
|
| 127 |
+
{
|
| 128 |
+
AP_Param::setup_object_defaults(this, var_info);
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
// get target's estimated location
|
| 132 |
+
bool AP_Follow::get_target_location_and_velocity(Location &loc, Vector3f &vel_ned) const
|
| 133 |
+
{
|
| 134 |
+
// exit immediately if not enabled
|
| 135 |
+
if (!_enabled) {
|
| 136 |
+
return false;
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
// check for timeout
|
| 140 |
+
if ((_last_location_update_ms == 0) || (AP_HAL::millis() - _last_location_update_ms > AP_FOLLOW_TIMEOUT_MS)) {
|
| 141 |
+
return false;
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
// calculate time since last actual position update
|
| 145 |
+
const float dt = (AP_HAL::millis() - _last_location_update_ms) * 0.001f;
|
| 146 |
+
|
| 147 |
+
// get velocity estimate
|
| 148 |
+
if (!get_velocity_ned(vel_ned, dt)) {
|
| 149 |
+
return false;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
// project the vehicle position
|
| 153 |
+
Location last_loc = _target_location;
|
| 154 |
+
location_offset(last_loc, vel_ned.x * dt, vel_ned.y * dt);
|
| 155 |
+
last_loc.alt -= vel_ned.z * 100.0f * dt; // convert m/s to cm/s, multiply by dt. minus because NED
|
| 156 |
+
|
| 157 |
+
// return latest position estimate
|
| 158 |
+
loc = last_loc;
|
| 159 |
+
return true;
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
// get distance vector to target (in meters) and target's velocity all in NED frame
|
| 163 |
+
bool AP_Follow::get_target_dist_and_vel_ned(Vector3f &dist_ned, Vector3f &dist_with_offs, Vector3f &vel_ned)
|
| 164 |
+
{
|
| 165 |
+
// get our location
|
| 166 |
+
Location current_loc;
|
| 167 |
+
if (!AP::ahrs().get_position(current_loc)) {
|
| 168 |
+
clear_dist_and_bearing_to_target();
|
| 169 |
+
return false;
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
// get target location and velocity
|
| 173 |
+
Location target_loc;
|
| 174 |
+
Vector3f veh_vel;
|
| 175 |
+
if (!get_target_location_and_velocity(target_loc, veh_vel)) {
|
| 176 |
+
clear_dist_and_bearing_to_target();
|
| 177 |
+
return false;
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
// change to altitude above home if relative altitude is being used
|
| 181 |
+
if (target_loc.flags.relative_alt == 1) {
|
| 182 |
+
current_loc.alt -= AP::ahrs().get_home().alt;
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
// calculate difference
|
| 186 |
+
const Vector3f dist_vec = location_3d_diff_NED(current_loc, target_loc);
|
| 187 |
+
|
| 188 |
+
// fail if too far
|
| 189 |
+
if (is_positive(_dist_max.get()) && (dist_vec.length() > _dist_max)) {
|
| 190 |
+
clear_dist_and_bearing_to_target();
|
| 191 |
+
return false;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
// initialise offsets from distance vector if required
|
| 195 |
+
init_offsets_if_required(dist_vec);
|
| 196 |
+
|
| 197 |
+
// get offsets
|
| 198 |
+
Vector3f offsets;
|
| 199 |
+
if (!get_offsets_ned(offsets)) {
|
| 200 |
+
clear_dist_and_bearing_to_target();
|
| 201 |
+
return false;
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
// calculate results
|
| 205 |
+
dist_ned = dist_vec;
|
| 206 |
+
dist_with_offs = dist_vec + offsets;
|
| 207 |
+
vel_ned = veh_vel;
|
| 208 |
+
|
| 209 |
+
// record distance and heading for reporting purposes
|
| 210 |
+
if (is_zero(dist_with_offs.x) && is_zero(dist_with_offs.y)) {
|
| 211 |
+
clear_dist_and_bearing_to_target();
|
| 212 |
+
} else {
|
| 213 |
+
_dist_to_target = safe_sqrt(sq(dist_with_offs.x) + sq(dist_with_offs.y));
|
| 214 |
+
_bearing_to_target = degrees(atan2f(dist_with_offs.y, dist_with_offs.x));
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
return true;
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
// get target's heading in degrees (0 = north, 90 = east)
|
| 221 |
+
bool AP_Follow::get_target_heading(float &heading) const
|
| 222 |
+
{
|
| 223 |
+
// exit immediately if not enabled
|
| 224 |
+
if (!_enabled) {
|
| 225 |
+
return false;
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
// check for timeout
|
| 229 |
+
if ((_last_heading_update_ms == 0) || (AP_HAL::millis() - _last_heading_update_ms > AP_FOLLOW_TIMEOUT_MS)) {
|
| 230 |
+
return false;
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
// return latest heading estimate
|
| 234 |
+
heading = _target_heading;
|
| 235 |
+
return true;
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
// handle mavlink DISTANCE_SENSOR messages
|
| 239 |
+
void AP_Follow::handle_msg(const mavlink_message_t &msg)
|
| 240 |
+
{
|
| 241 |
+
// exit immediately if not enabled
|
| 242 |
+
if (!_enabled) {
|
| 243 |
+
return;
|
| 244 |
+
}
|
| 245 |
+
|
| 246 |
+
// skip our own messages
|
| 247 |
+
if (msg.sysid == mavlink_system.sysid) {
|
| 248 |
+
return;
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
// skip message if not from our target
|
| 252 |
+
if (_sysid != 0 && msg.sysid != _sysid) {
|
| 253 |
+
if (_automatic_sysid) {
|
| 254 |
+
// maybe timeout who we were following...
|
| 255 |
+
if ((_last_location_update_ms == 0) || (AP_HAL::millis() - _last_location_update_ms > AP_FOLLOW_SYSID_TIMEOUT_MS)) {
|
| 256 |
+
_sysid.set(0);
|
| 257 |
+
}
|
| 258 |
+
}
|
| 259 |
+
return;
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
// decode global-position-int message
|
| 263 |
+
if (msg.msgid == MAVLINK_MSG_ID_GLOBAL_POSITION_INT) {
|
| 264 |
+
|
| 265 |
+
// get estimated location and velocity (for logging)
|
| 266 |
+
Location loc_estimate{};
|
| 267 |
+
Vector3f vel_estimate;
|
| 268 |
+
UNUSED_RESULT(get_target_location_and_velocity(loc_estimate, vel_estimate));
|
| 269 |
+
|
| 270 |
+
// decode message
|
| 271 |
+
mavlink_global_position_int_t packet;
|
| 272 |
+
mavlink_msg_global_position_int_decode(&msg, &packet);
|
| 273 |
+
|
| 274 |
+
// ignore message if lat and lon are (exactly) zero
|
| 275 |
+
if ((packet.lat == 0 && packet.lon == 0)) {
|
| 276 |
+
return;
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
_target_location.lat = packet.lat;
|
| 280 |
+
_target_location.lng = packet.lon;
|
| 281 |
+
|
| 282 |
+
// select altitude source based on FOLL_ALT_TYPE param
|
| 283 |
+
if (_alt_type == AP_FOLLOW_ALTITUDE_TYPE_RELATIVE) {
|
| 284 |
+
// relative altitude
|
| 285 |
+
_target_location.alt = packet.relative_alt / 10; // convert millimeters to cm
|
| 286 |
+
_target_location.flags.relative_alt = 1; // set relative_alt flag
|
| 287 |
+
} else {
|
| 288 |
+
// absolute altitude
|
| 289 |
+
_target_location.alt = packet.alt / 10; // convert millimeters to cm
|
| 290 |
+
_target_location.flags.relative_alt = 0; // reset relative_alt flag
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
_target_velocity_ned.x = packet.vx * 0.01f; // velocity north
|
| 294 |
+
_target_velocity_ned.y = packet.vy * 0.01f; // velocity east
|
| 295 |
+
_target_velocity_ned.z = packet.vz * 0.01f; // velocity down
|
| 296 |
+
|
| 297 |
+
// get a local timestamp with correction for transport jitter
|
| 298 |
+
_last_location_update_ms = _jitter.correct_offboard_timestamp_msec(packet.time_boot_ms, AP_HAL::millis());
|
| 299 |
+
if (packet.hdg <= 36000) { // heading (UINT16_MAX if unknown)
|
| 300 |
+
_target_heading = packet.hdg * 0.01f; // convert centi-degrees to degrees
|
| 301 |
+
_last_heading_update_ms = _last_location_update_ms;
|
| 302 |
+
}
|
| 303 |
+
// initialise _sysid if zero to sender's id
|
| 304 |
+
if (_sysid == 0) {
|
| 305 |
+
_sysid.set(msg.sysid);
|
| 306 |
+
_automatic_sysid = true;
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
// log lead's estimated vs reported position
|
| 310 |
+
DataFlash_Class::instance()->Log_Write("FOLL",
|
| 311 |
+
"TimeUS,Lat,Lon,Alt,VelN,VelE,VelD,LatE,LonE,AltE", // labels
|
| 312 |
+
"sDUmnnnDUm", // units
|
| 313 |
+
"F--B000--B", // mults
|
| 314 |
+
"QLLifffLLi", // fmt
|
| 315 |
+
AP_HAL::micros64(),
|
| 316 |
+
_target_location.lat,
|
| 317 |
+
_target_location.lng,
|
| 318 |
+
_target_location.alt,
|
| 319 |
+
(double)_target_velocity_ned.x,
|
| 320 |
+
(double)_target_velocity_ned.y,
|
| 321 |
+
(double)_target_velocity_ned.z,
|
| 322 |
+
loc_estimate.lat,
|
| 323 |
+
loc_estimate.lng,
|
| 324 |
+
loc_estimate.alt
|
| 325 |
+
);
|
| 326 |
+
}
|
| 327 |
+
}
|
| 328 |
+
|
| 329 |
+
// get velocity estimate in m/s in NED frame using dt since last update
|
| 330 |
+
bool AP_Follow::get_velocity_ned(Vector3f &vel_ned, float dt) const
|
| 331 |
+
{
|
| 332 |
+
vel_ned = _target_velocity_ned + (_target_accel_ned * dt);
|
| 333 |
+
return true;
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
// initialise offsets to provided distance vector to other vehicle (in meters in NED frame) if required
|
| 337 |
+
void AP_Follow::init_offsets_if_required(const Vector3f &dist_vec_ned)
|
| 338 |
+
{
|
| 339 |
+
// return immediately if offsets have already been set
|
| 340 |
+
if (!_offset.get().is_zero()) {
|
| 341 |
+
return;
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
float target_heading_deg;
|
| 345 |
+
if ((_offset_type == AP_FOLLOW_OFFSET_TYPE_RELATIVE) && get_target_heading(target_heading_deg)) {
|
| 346 |
+
// rotate offsets from north facing to vehicle's perspective
|
| 347 |
+
_offset = rotate_vector(-dist_vec_ned, -target_heading_deg);
|
| 348 |
+
} else {
|
| 349 |
+
// initialise offset in NED frame
|
| 350 |
+
_offset = -dist_vec_ned;
|
| 351 |
+
// ensure offset_type used matches frame of offsets saved
|
| 352 |
+
_offset_type = AP_FOLLOW_OFFSET_TYPE_NED;
|
| 353 |
+
}
|
| 354 |
+
}
|
| 355 |
+
|
| 356 |
+
// get offsets in meters in NED frame
|
| 357 |
+
bool AP_Follow::get_offsets_ned(Vector3f &offset) const
|
| 358 |
+
{
|
| 359 |
+
const Vector3f &off = _offset.get();
|
| 360 |
+
|
| 361 |
+
// if offsets are zero or type is NED, simply return offset vector
|
| 362 |
+
if (off.is_zero() || (_offset_type == AP_FOLLOW_OFFSET_TYPE_NED)) {
|
| 363 |
+
offset = off;
|
| 364 |
+
return true;
|
| 365 |
+
}
|
| 366 |
+
|
| 367 |
+
// offset type is relative, exit if we cannot get vehicle's heading
|
| 368 |
+
float target_heading_deg;
|
| 369 |
+
if (!get_target_heading(target_heading_deg)) {
|
| 370 |
+
return false;
|
| 371 |
+
}
|
| 372 |
+
|
| 373 |
+
// rotate offsets from vehicle's perspective to NED
|
| 374 |
+
offset = rotate_vector(off, target_heading_deg);
|
| 375 |
+
return true;
|
| 376 |
+
}
|
| 377 |
+
|
| 378 |
+
// rotate 3D vector clockwise by specified angle (in degrees)
|
| 379 |
+
Vector3f AP_Follow::rotate_vector(const Vector3f &vec, float angle_deg) const
|
| 380 |
+
{
|
| 381 |
+
// rotate roll, pitch input from north facing to vehicle's perspective
|
| 382 |
+
const float cos_yaw = cosf(radians(angle_deg));
|
| 383 |
+
const float sin_yaw = sinf(radians(angle_deg));
|
| 384 |
+
return Vector3f((vec.x * cos_yaw) - (vec.y * sin_yaw), (vec.y * cos_yaw) + (vec.x * sin_yaw), vec.z);
|
| 385 |
+
}
|
| 386 |
+
|
| 387 |
+
// set recorded distance and bearing to target to zero
|
| 388 |
+
void AP_Follow::clear_dist_and_bearing_to_target()
|
| 389 |
+
{
|
| 390 |
+
_dist_to_target = 0.0f;
|
| 391 |
+
_bearing_to_target = 0.0f;
|
| 392 |
+
}
|
pool/shard008/C++/0096579_GameFieldText.cpp
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "GameFieldText.h"
|
| 2 |
+
#include "Resources.h"
|
| 3 |
+
#include "textures.h"
|
| 4 |
+
#include <cmath>
|
| 5 |
+
using std::to_string;
|
| 6 |
+
|
| 7 |
+
GameFieldText::GameFieldText(Resources& _resources) : resources(_resources) {
|
| 8 |
+
nameTag.setFont(resources.gfx->typewriter);
|
| 9 |
+
nameTag.setCharacterSize(32);
|
| 10 |
+
readyText.setFont(resources.gfx->typewriter);
|
| 11 |
+
readyText.setCharacterSize(32);
|
| 12 |
+
readyText.setPosition(100, 75); readyText.setString("Ready");
|
| 13 |
+
awayText.setFont(resources.gfx->typewriter);
|
| 14 |
+
awayText.setCharacterSize(48);
|
| 15 |
+
awayText.setPosition(110, 150); awayText.setString("Away");
|
| 16 |
+
positionText.setFont(resources.gfx->typewriter);
|
| 17 |
+
positionText.setCharacterSize(48);
|
| 18 |
+
positionText.setPosition(130, 200);
|
| 19 |
+
countdownText.setFont(resources.gfx->typewriter);
|
| 20 |
+
countdownText.setCharacterSize(96);
|
| 21 |
+
countdownText.setPosition(130,210);
|
| 22 |
+
|
| 23 |
+
comboText.setFont(resources.gfx->typewriter); comboText.setString("0");
|
| 24 |
+
pendingText.setFont(resources.gfx->typewriter); pendingText.setString("0");
|
| 25 |
+
bpmText.setFont(resources.gfx->typewriter); bpmText.setString("0");
|
| 26 |
+
comboText.setCharacterSize(48);
|
| 27 |
+
comboText.setPosition(360,320);
|
| 28 |
+
pendingText.setCharacterSize(48);
|
| 29 |
+
pendingText.setPosition(360,500);
|
| 30 |
+
bpmText.setCharacterSize(48);
|
| 31 |
+
bpmText.setPosition(360, 420);
|
| 32 |
+
gameOverText.setFont(resources.gfx->typewriter);
|
| 33 |
+
gameOverText.setPosition(50,250);
|
| 34 |
+
gameOverText.setCharacterSize(48);
|
| 35 |
+
|
| 36 |
+
comboTimer.setPosition(315, 290);
|
| 37 |
+
comboTimer.setFillColor(sf::Color(255,0,0));
|
| 38 |
+
setComboTimer(0);
|
| 39 |
+
|
| 40 |
+
combo = 0; pending = 0; bpm = 0; position = 0; countdown = 0; gameover = 0;
|
| 41 |
+
away = false; ready = false;
|
| 42 |
+
|
| 43 |
+
setColor(resources.gfx->gameFieldTextColor);
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
GameFieldText::GameFieldText(const GameFieldText& text) : resources(text.resources) {
|
| 47 |
+
nameTag=text.nameTag; readyText=text.readyText; awayText=text.awayText; positionText = text.positionText;
|
| 48 |
+
countdownText = text.countdownText; comboText = text.comboText; pendingText = text.pendingText;
|
| 49 |
+
bpmText = text.bpmText; gameOverText = text.gameOverText;
|
| 50 |
+
|
| 51 |
+
comboTimer.setPosition(315, 240);
|
| 52 |
+
comboTimer.setFillColor(sf::Color(255,0,0));
|
| 53 |
+
setComboTimer(0);
|
| 54 |
+
|
| 55 |
+
combo = 0; pending = 0; bpm = 0; position = 0; countdown = 0; gameover = 0;
|
| 56 |
+
away = false; ready = false;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
void GameFieldText::setName(const std::string& n) {
|
| 60 |
+
std::lock_guard<std::mutex> mute(fieldTextMutex);
|
| 61 |
+
name = n;
|
| 62 |
+
nameTag.setString(n);
|
| 63 |
+
short x = (310-nameTag.getLocalBounds().width)/2;
|
| 64 |
+
if (x<0)
|
| 65 |
+
x=0;
|
| 66 |
+
nameTag.setPosition(x, 555);
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
void GameFieldText::setPosition(const int8_t _position) {
|
| 70 |
+
std::lock_guard<std::mutex> mute(fieldTextMutex);
|
| 71 |
+
position = _position;
|
| 72 |
+
if (position == 1)
|
| 73 |
+
positionText.setString("1st");
|
| 74 |
+
else if (position == 2)
|
| 75 |
+
positionText.setString("2nd");
|
| 76 |
+
else if (position == 3)
|
| 77 |
+
positionText.setString("3rd");
|
| 78 |
+
else if (position)
|
| 79 |
+
positionText.setString(to_string((int)position) + "th");
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
void GameFieldText::setCountdown(const int8_t _countdown) {
|
| 83 |
+
std::lock_guard<std::mutex> mute(fieldTextMutex);
|
| 84 |
+
countdown = _countdown;
|
| 85 |
+
if (countdown)
|
| 86 |
+
countdownText.setString(to_string(countdown));
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
void GameFieldText::setGameover(const int8_t _gameover) {
|
| 90 |
+
std::lock_guard<std::mutex> mute(fieldTextMutex);
|
| 91 |
+
gameover = _gameover;
|
| 92 |
+
if (gameover == 1)
|
| 93 |
+
gameOverText.setString("Game Over");
|
| 94 |
+
else if (gameover == 2)
|
| 95 |
+
gameOverText.setString("Winner");
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
const float PI = 3.14159265;
|
| 99 |
+
bool GameFieldText::setComboTimer(uint8_t count) {
|
| 100 |
+
std::lock_guard<std::mutex> mute(fieldTextMutex);
|
| 101 |
+
if (count>100)
|
| 102 |
+
count=100;
|
| 103 |
+
if (comboTimer.getPointCount() == static_cast<unsigned int>(count+2))
|
| 104 |
+
return false;
|
| 105 |
+
comboTimer.setPointCount(count+2);
|
| 106 |
+
|
| 107 |
+
comboTimer.setPoint(0, sf::Vector2f(60, 60));
|
| 108 |
+
for (int x=1; x<(count+2); x++)
|
| 109 |
+
comboTimer.setPoint(x, sf::Vector2f(60 + 60*cos((PI*2)/100 * (x-26)), 60 + 60*sin((PI*2)/100 * (x-26) )));
|
| 110 |
+
|
| 111 |
+
return true;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
void GameFieldText::setBpm(const uint16_t _bpm) {
|
| 115 |
+
std::lock_guard<std::mutex> mute(fieldTextMutex);
|
| 116 |
+
if (bpm != _bpm) {
|
| 117 |
+
bpm = _bpm;
|
| 118 |
+
bpmText.setString(to_string(bpm));
|
| 119 |
+
}
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
void GameFieldText::setCombo(const uint8_t _combo) {
|
| 123 |
+
std::lock_guard<std::mutex> mute(fieldTextMutex);
|
| 124 |
+
if (combo != _combo) {
|
| 125 |
+
combo = _combo;
|
| 126 |
+
comboText.setString(to_string(combo));
|
| 127 |
+
}
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
void GameFieldText::setPending(const uint8_t _pending) {
|
| 131 |
+
std::lock_guard<std::mutex> mute(fieldTextMutex);
|
| 132 |
+
if (pending != _pending) {
|
| 133 |
+
pending = _pending;
|
| 134 |
+
pendingText.setString(to_string(pending));
|
| 135 |
+
}
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
void GameFieldText::setColor(sf::Color color) {
|
| 139 |
+
std::lock_guard<std::mutex> mute(fieldTextMutex);
|
| 140 |
+
nameTag.setFillColor(color);
|
| 141 |
+
awayText.setFillColor(color);
|
| 142 |
+
positionText.setFillColor(color);
|
| 143 |
+
readyText.setFillColor(color);
|
| 144 |
+
comboText.setFillColor(color);
|
| 145 |
+
pendingText.setFillColor(color);
|
| 146 |
+
countdownText.setFillColor(color);
|
| 147 |
+
bpmText.setFillColor(color);
|
| 148 |
+
gameOverText.setFillColor(color);
|
| 149 |
+
|
| 150 |
+
nameTag.setOutlineColor(color);
|
| 151 |
+
awayText.setOutlineColor(color);
|
| 152 |
+
positionText.setOutlineColor(color);
|
| 153 |
+
readyText.setOutlineColor(color);
|
| 154 |
+
comboText.setOutlineColor(color);
|
| 155 |
+
pendingText.setOutlineColor(color);
|
| 156 |
+
countdownText.setOutlineColor(color);
|
| 157 |
+
bpmText.setOutlineColor(color);
|
| 158 |
+
gameOverText.setOutlineColor(color);
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
void GameFieldText::clear() {
|
| 162 |
+
setComboTimer(0);
|
| 163 |
+
setCombo(0);
|
| 164 |
+
setPending(0);
|
| 165 |
+
setBpm(0);
|
| 166 |
+
setPosition(0);
|
| 167 |
+
setCountdown(0);
|
| 168 |
+
setGameover(0);
|
| 169 |
+
ready=false;
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
void GameFieldText::drawText() {
|
| 173 |
+
std::lock_guard<std::mutex> mute(fieldTextMutex);
|
| 174 |
+
if (away)
|
| 175 |
+
texture->draw(awayText);
|
| 176 |
+
if (position)
|
| 177 |
+
texture->draw(positionText);
|
| 178 |
+
if (ready)
|
| 179 |
+
texture->draw(readyText);
|
| 180 |
+
if (countdown)
|
| 181 |
+
texture->draw(countdownText);
|
| 182 |
+
if (gameover)
|
| 183 |
+
texture->draw(gameOverText);
|
| 184 |
+
|
| 185 |
+
texture->draw(nameTag);
|
| 186 |
+
texture->draw(comboTimer);
|
| 187 |
+
texture->draw(comboText);
|
| 188 |
+
texture->draw(pendingText);
|
| 189 |
+
texture->draw(bpmText);
|
| 190 |
+
}
|
pool/shard008/C++/0096580_opimport.cpp
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @file opimport.cpp
|
| 3 |
+
* Import sample files from other ABI
|
| 4 |
+
*
|
| 5 |
+
* @remark Copyright 2002 OProfile authors
|
| 6 |
+
* @remark Read the file COPYING
|
| 7 |
+
*
|
| 8 |
+
* @author Graydon Hoare
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
#include "abi.h"
|
| 12 |
+
#include "odb.h"
|
| 13 |
+
#include "popt_options.h"
|
| 14 |
+
#include "op_sample_file.h"
|
| 15 |
+
|
| 16 |
+
#include <fstream>
|
| 17 |
+
#include <iostream>
|
| 18 |
+
#include <sstream>
|
| 19 |
+
#include <vector>
|
| 20 |
+
#include <cassert>
|
| 21 |
+
#include <cstring>
|
| 22 |
+
#include <cstdlib>
|
| 23 |
+
|
| 24 |
+
#include <sys/types.h>
|
| 25 |
+
#include <sys/stat.h>
|
| 26 |
+
#include <fcntl.h>
|
| 27 |
+
#include <unistd.h>
|
| 28 |
+
#include <sys/mman.h>
|
| 29 |
+
#include <cstdlib>
|
| 30 |
+
#include <cstring>
|
| 31 |
+
|
| 32 |
+
using namespace std;
|
| 33 |
+
|
| 34 |
+
namespace {
|
| 35 |
+
string output_filename;
|
| 36 |
+
string abi_filename;
|
| 37 |
+
bool verbose;
|
| 38 |
+
bool force;
|
| 39 |
+
};
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
popt::option options_array[] = {
|
| 43 |
+
popt::option(verbose, "verbose", 'V', "verbose output"),
|
| 44 |
+
popt::option(output_filename, "output", 'o', "output to file", "filename"),
|
| 45 |
+
popt::option(abi_filename, "abi", 'a', "abi description", "filename"),
|
| 46 |
+
popt::option(force, "force", 'f', "force conversion, even if identical")
|
| 47 |
+
};
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
struct extractor {
|
| 51 |
+
|
| 52 |
+
abi const & theabi;
|
| 53 |
+
|
| 54 |
+
unsigned char const * begin;
|
| 55 |
+
unsigned char const * end;
|
| 56 |
+
bool little_endian;
|
| 57 |
+
|
| 58 |
+
explicit
|
| 59 |
+
extractor(abi const & a, unsigned char const * src, size_t len)
|
| 60 |
+
: theabi(a), begin(src), end(src + len) {
|
| 61 |
+
little_endian = theabi.need(string("little_endian")) == 1;
|
| 62 |
+
if (verbose) {
|
| 63 |
+
cerr << "source byte order is: "
|
| 64 |
+
<< string(little_endian ? "little" : "big")
|
| 65 |
+
<< " endian" << endl;
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
template <typename T>
|
| 70 |
+
void extract(T & targ, void const * src_,
|
| 71 |
+
char const * sz, char const * off);
|
| 72 |
+
};
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
template <typename T>
|
| 76 |
+
void extractor::extract(T & targ, void const * src_,
|
| 77 |
+
char const * sz, char const * off)
|
| 78 |
+
{
|
| 79 |
+
unsigned char const * src = static_cast<unsigned char const *>(src_)
|
| 80 |
+
+ theabi.need(string(off));
|
| 81 |
+
size_t nbytes = theabi.need(string(sz));
|
| 82 |
+
|
| 83 |
+
targ = 0;
|
| 84 |
+
if (nbytes == 0)
|
| 85 |
+
return;
|
| 86 |
+
|
| 87 |
+
assert(nbytes <= sizeof(T));
|
| 88 |
+
assert(src >= begin);
|
| 89 |
+
assert(src + nbytes <= end);
|
| 90 |
+
|
| 91 |
+
if (verbose) {
|
| 92 |
+
ostringstream message;
|
| 93 |
+
message << hex << "get " << sz << " = " << nbytes
|
| 94 |
+
<< " bytes @ " << off << " = " << (src - begin)
|
| 95 |
+
<< " : ";
|
| 96 |
+
cerr << message.str();
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
if (little_endian)
|
| 100 |
+
while(nbytes--)
|
| 101 |
+
targ = (targ << 8) | src[nbytes];
|
| 102 |
+
else
|
| 103 |
+
for(size_t i = 0; i < nbytes; ++i)
|
| 104 |
+
targ = (targ << 8) | src[i];
|
| 105 |
+
|
| 106 |
+
if (verbose)
|
| 107 |
+
cerr << " = " << targ << endl;
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
void import_from_abi(abi const & abi, void const * srcv,
|
| 112 |
+
size_t len, odb_t * dest)
|
| 113 |
+
{
|
| 114 |
+
struct opd_header * head =
|
| 115 |
+
static_cast<opd_header *>(odb_get_data(dest));
|
| 116 |
+
unsigned char const * src = static_cast<unsigned char const *>(srcv);
|
| 117 |
+
unsigned char const * const begin = src;
|
| 118 |
+
extractor ext(abi, src, len);
|
| 119 |
+
|
| 120 |
+
memcpy(head->magic, src + abi.need("offsetof_header_magic"), 4);
|
| 121 |
+
|
| 122 |
+
// begin extracting opd header
|
| 123 |
+
ext.extract(head->version, src, "sizeof_u32", "offsetof_header_version");
|
| 124 |
+
ext.extract(head->cpu_type, src, "sizeof_u32", "offsetof_header_cpu_type");
|
| 125 |
+
ext.extract(head->ctr_event, src, "sizeof_u32", "offsetof_header_ctr_event");
|
| 126 |
+
ext.extract(head->ctr_um, src, "sizeof_u32", "offsetof_header_ctr_um");
|
| 127 |
+
ext.extract(head->ctr_count, src, "sizeof_u32", "offsetof_header_ctr_count");
|
| 128 |
+
ext.extract(head->is_kernel, src, "sizeof_u32", "offsetof_header_is_kernel");
|
| 129 |
+
// "double" extraction is unlikely to work
|
| 130 |
+
head->cpu_speed = 0.0;
|
| 131 |
+
ext.extract(head->mtime, src, "sizeof_u64", "offsetof_header_mtime");
|
| 132 |
+
ext.extract(head->cg_to_is_kernel, src, "sizeof_u32",
|
| 133 |
+
"offsetof_header_cg_to_is_kernel");
|
| 134 |
+
ext.extract(head->anon_start, src, "sizeof_u32",
|
| 135 |
+
"offsetof_header_anon_start");
|
| 136 |
+
ext.extract(head->cg_to_anon_start, src, "sizeof_u32",
|
| 137 |
+
"offsetof_header_cg_to_anon_start");
|
| 138 |
+
src += abi.need("sizeof_struct_opd_header");
|
| 139 |
+
// done extracting opd header
|
| 140 |
+
|
| 141 |
+
// begin extracting necessary parts of descr
|
| 142 |
+
odb_node_nr_t node_nr;
|
| 143 |
+
ext.extract(node_nr, src, "sizeof_odb_node_nr_t", "offsetof_descr_current_size");
|
| 144 |
+
src += abi.need("sizeof_odb_descr_t");
|
| 145 |
+
// done extracting descr
|
| 146 |
+
|
| 147 |
+
// skip node zero, it is reserved and contains nothing usefull
|
| 148 |
+
src += abi.need("sizeof_odb_node_t");
|
| 149 |
+
|
| 150 |
+
// begin extracting nodes
|
| 151 |
+
unsigned int step = abi.need("sizeof_odb_node_t");
|
| 152 |
+
if (verbose)
|
| 153 |
+
cerr << "extracting " << node_nr << " nodes of " << step << " bytes each " << endl;
|
| 154 |
+
|
| 155 |
+
assert(src + (node_nr * step) <= begin + len);
|
| 156 |
+
|
| 157 |
+
for (odb_node_nr_t i = 1 ; i < node_nr ; ++i, src += step) {
|
| 158 |
+
odb_key_t key;
|
| 159 |
+
odb_value_t val;
|
| 160 |
+
ext.extract(key, src, "sizeof_odb_key_t", "offsetof_node_key");
|
| 161 |
+
ext.extract(val, src, "sizeof_odb_value_t", "offsetof_node_value");
|
| 162 |
+
int rc = odb_add_node(dest, key, val);
|
| 163 |
+
if (rc != EXIT_SUCCESS) {
|
| 164 |
+
cerr << strerror(rc) << endl;
|
| 165 |
+
exit(EXIT_FAILURE);
|
| 166 |
+
}
|
| 167 |
+
}
|
| 168 |
+
// done extracting nodes
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
int main(int argc, char const ** argv)
|
| 173 |
+
{
|
| 174 |
+
|
| 175 |
+
vector<string> inputs;
|
| 176 |
+
popt::parse_options(argc, argv, inputs);
|
| 177 |
+
|
| 178 |
+
if (inputs.size() != 1) {
|
| 179 |
+
cerr << "error: must specify exactly 1 input file" << endl;
|
| 180 |
+
exit(1);
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
if (inputs[0].rfind(".jo") == inputs[0].size() - 3) {
|
| 184 |
+
if (verbose) {
|
| 185 |
+
cerr << "Found a .jo file. Import is not allowed or necessary. Done." << endl;
|
| 186 |
+
cerr << inputs[0] << endl;
|
| 187 |
+
}
|
| 188 |
+
// Silently exit with success.
|
| 189 |
+
exit(EXIT_SUCCESS);
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
abi current_abi, input_abi;
|
| 193 |
+
|
| 194 |
+
{
|
| 195 |
+
ifstream abi_file(abi_filename.c_str());
|
| 196 |
+
if (!abi_file) {
|
| 197 |
+
cerr << "error: cannot open abi file "
|
| 198 |
+
<< abi_filename << endl;
|
| 199 |
+
exit(1);
|
| 200 |
+
}
|
| 201 |
+
abi_file >> input_abi;
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
if (!force && current_abi == input_abi) {
|
| 205 |
+
cerr << "input abi is identical to native. "
|
| 206 |
+
<< "no conversion necessary." << endl;
|
| 207 |
+
exit(1);
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
int in_fd;
|
| 211 |
+
struct stat statb;
|
| 212 |
+
void * in;
|
| 213 |
+
odb_t dest;
|
| 214 |
+
int rc;
|
| 215 |
+
|
| 216 |
+
in_fd = open(inputs[0].c_str(), O_RDONLY);
|
| 217 |
+
assert(in_fd > 0);
|
| 218 |
+
assert(fstat(in_fd, &statb) == 0);
|
| 219 |
+
in = mmap(0, statb.st_size, PROT_READ, MAP_PRIVATE, in_fd, 0);
|
| 220 |
+
assert(in != (void *)-1);
|
| 221 |
+
|
| 222 |
+
rc = odb_open(&dest, output_filename.c_str(), ODB_RDWR,
|
| 223 |
+
sizeof(struct opd_header));
|
| 224 |
+
if (rc) {
|
| 225 |
+
cerr << "odb_open() fail:\n"
|
| 226 |
+
<< strerror(rc) << endl;
|
| 227 |
+
exit(EXIT_FAILURE);
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
try {
|
| 231 |
+
import_from_abi(input_abi, in, statb.st_size, &dest);
|
| 232 |
+
} catch (abi_exception & e) {
|
| 233 |
+
cerr << "caught abi exception: " << e.desc << endl;
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
odb_close(&dest);
|
| 237 |
+
|
| 238 |
+
assert(munmap(in, statb.st_size) == 0);
|
| 239 |
+
}
|
pool/shard008/C++/0096581_OrderAmount.cpp
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <TaoApiCpp/domain/OrderAmount.h>
|
| 2 |
+
QString OrderAmount::getAdjustFee() const {
|
| 3 |
+
return adjustFee;
|
| 4 |
+
}
|
| 5 |
+
void OrderAmount::setAdjustFee (QString adjustFee) {
|
| 6 |
+
this->adjustFee = adjustFee;
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
QString OrderAmount::getDiscountFee() const {
|
| 10 |
+
return discountFee;
|
| 11 |
+
}
|
| 12 |
+
void OrderAmount::setDiscountFee (QString discountFee) {
|
| 13 |
+
this->discountFee = discountFee;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
qlonglong OrderAmount::getNum() const {
|
| 17 |
+
return num;
|
| 18 |
+
}
|
| 19 |
+
void OrderAmount::setNum (qlonglong num) {
|
| 20 |
+
this->num = num;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
qlonglong OrderAmount::getNumIid() const {
|
| 24 |
+
return numIid;
|
| 25 |
+
}
|
| 26 |
+
void OrderAmount::setNumIid (qlonglong numIid) {
|
| 27 |
+
this->numIid = numIid;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
qlonglong OrderAmount::getOid() const {
|
| 31 |
+
return oid;
|
| 32 |
+
}
|
| 33 |
+
void OrderAmount::setOid (qlonglong oid) {
|
| 34 |
+
this->oid = oid;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
QString OrderAmount::getPayment() const {
|
| 38 |
+
return payment;
|
| 39 |
+
}
|
| 40 |
+
void OrderAmount::setPayment (QString payment) {
|
| 41 |
+
this->payment = payment;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
QString OrderAmount::getPrice() const {
|
| 45 |
+
return price;
|
| 46 |
+
}
|
| 47 |
+
void OrderAmount::setPrice (QString price) {
|
| 48 |
+
this->price = price;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
QString OrderAmount::getPromotionName() const {
|
| 52 |
+
return promotionName;
|
| 53 |
+
}
|
| 54 |
+
void OrderAmount::setPromotionName (QString promotionName) {
|
| 55 |
+
this->promotionName = promotionName;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
qlonglong OrderAmount::getSkuId() const {
|
| 59 |
+
return skuId;
|
| 60 |
+
}
|
| 61 |
+
void OrderAmount::setSkuId (qlonglong skuId) {
|
| 62 |
+
this->skuId = skuId;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
QString OrderAmount::getSkuPropertiesName() const {
|
| 66 |
+
return skuPropertiesName;
|
| 67 |
+
}
|
| 68 |
+
void OrderAmount::setSkuPropertiesName (QString skuPropertiesName) {
|
| 69 |
+
this->skuPropertiesName = skuPropertiesName;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
QString OrderAmount::getTitle() const {
|
| 73 |
+
return title;
|
| 74 |
+
}
|
| 75 |
+
void OrderAmount::setTitle (QString title) {
|
| 76 |
+
this->title = title;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
void OrderAmount::parseResponse() {
|
| 81 |
+
if (responseParser->hasName("adjust_fee")) {
|
| 82 |
+
adjustFee = responseParser->getStrByName("adjust_fee");
|
| 83 |
+
}
|
| 84 |
+
if (responseParser->hasName("discount_fee")) {
|
| 85 |
+
discountFee = responseParser->getStrByName("discount_fee");
|
| 86 |
+
}
|
| 87 |
+
if (responseParser->hasName("num")) {
|
| 88 |
+
num = responseParser->getNumByName("num");
|
| 89 |
+
}
|
| 90 |
+
if (responseParser->hasName("num_iid")) {
|
| 91 |
+
numIid = responseParser->getNumByName("num_iid");
|
| 92 |
+
}
|
| 93 |
+
if (responseParser->hasName("oid")) {
|
| 94 |
+
oid = responseParser->getNumByName("oid");
|
| 95 |
+
}
|
| 96 |
+
if (responseParser->hasName("payment")) {
|
| 97 |
+
payment = responseParser->getStrByName("payment");
|
| 98 |
+
}
|
| 99 |
+
if (responseParser->hasName("price")) {
|
| 100 |
+
price = responseParser->getStrByName("price");
|
| 101 |
+
}
|
| 102 |
+
if (responseParser->hasName("promotion_name")) {
|
| 103 |
+
promotionName = responseParser->getStrByName("promotion_name");
|
| 104 |
+
}
|
| 105 |
+
if (responseParser->hasName("sku_id")) {
|
| 106 |
+
skuId = responseParser->getNumByName("sku_id");
|
| 107 |
+
}
|
| 108 |
+
if (responseParser->hasName("sku_properties_name")) {
|
| 109 |
+
skuPropertiesName = responseParser->getStrByName("sku_properties_name");
|
| 110 |
+
}
|
| 111 |
+
if (responseParser->hasName("title")) {
|
| 112 |
+
title = responseParser->getStrByName("title");
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
}
|
| 116 |
+
|
pool/shard008/C++/0096582_test.cpp
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* +---------------------------------------------------------------------------+
|
| 2 |
+
| The Mobile Robot Programming Toolkit (MRPT) |
|
| 3 |
+
| |
|
| 4 |
+
| http://www.mrpt.org/ |
|
| 5 |
+
| |
|
| 6 |
+
| Copyright (c) 2005-2013, Individual contributors, see AUTHORS file |
|
| 7 |
+
| Copyright (c) 2005-2013, MAPIR group, University of Malaga |
|
| 8 |
+
| Copyright (c) 2012-2013, University of Almeria |
|
| 9 |
+
| All rights reserved. |
|
| 10 |
+
| |
|
| 11 |
+
| Redistribution and use in source and binary forms, with or without |
|
| 12 |
+
| modification, are permitted provided that the following conditions are |
|
| 13 |
+
| met: |
|
| 14 |
+
| * Redistributions of source code must retain the above copyright |
|
| 15 |
+
| notice, this list of conditions and the following disclaimer. |
|
| 16 |
+
| * Redistributions in binary form must reproduce the above copyright |
|
| 17 |
+
| notice, this list of conditions and the following disclaimer in the |
|
| 18 |
+
| documentation and/or other materials provided with the distribution. |
|
| 19 |
+
| * Neither the name of the copyright holders nor the |
|
| 20 |
+
| names of its contributors may be used to endorse or promote products |
|
| 21 |
+
| derived from this software without specific prior written permission.|
|
| 22 |
+
| |
|
| 23 |
+
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
| 24 |
+
| 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
|
| 25 |
+
| TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR|
|
| 26 |
+
| PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE |
|
| 27 |
+
| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL|
|
| 28 |
+
| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR|
|
| 29 |
+
| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|
| 30 |
+
| HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
|
| 31 |
+
| STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
| 32 |
+
| ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
| 33 |
+
| POSSIBILITY OF SUCH DAMAGE. |
|
| 34 |
+
+---------------------------------------------------------------------------+ */
|
| 35 |
+
|
| 36 |
+
#include <mrpt/gui.h>
|
| 37 |
+
#include <mrpt/opengl.h>
|
| 38 |
+
#include <mrpt/hwdrivers/CCameraSensor.h>
|
| 39 |
+
|
| 40 |
+
using namespace mrpt;
|
| 41 |
+
using namespace mrpt::gui;
|
| 42 |
+
using namespace mrpt::opengl;
|
| 43 |
+
using namespace mrpt::math;
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
// ------------------------------------------------------
|
| 47 |
+
// TestOpenGLVideo
|
| 48 |
+
// ------------------------------------------------------
|
| 49 |
+
void TestOpenGLVideo()
|
| 50 |
+
{
|
| 51 |
+
// Show to the user a list of possible camera drivers and creates and open the selected camera.
|
| 52 |
+
cout << "Please, select the input video file or camera...\n";
|
| 53 |
+
|
| 54 |
+
mrpt::hwdrivers::CCameraSensorPtr cam = mrpt::hwdrivers::prepareVideoSourceFromUserSelection();
|
| 55 |
+
if (!cam) return;
|
| 56 |
+
|
| 57 |
+
cout << "Video stream open OK\n";
|
| 58 |
+
|
| 59 |
+
// Create 3D window:
|
| 60 |
+
CDisplayWindow3D win("Demo of video textures with MRPT's OpenGL objects",640,480);
|
| 61 |
+
|
| 62 |
+
// XY Grid
|
| 63 |
+
opengl::CGridPlaneXYPtr gl_ground = opengl::CGridPlaneXY::Create(-7,7,-7,7,0,1);
|
| 64 |
+
gl_ground->setColor(0.7,0.7,0.7);
|
| 65 |
+
|
| 66 |
+
// An opengl plane with the video texture
|
| 67 |
+
opengl::CTexturedPlanePtr gl_plane1 = opengl::CTexturedPlane::Create(0,1,0,0.75); // 4/3 aspect ratio
|
| 68 |
+
opengl::CTexturedPlanePtr gl_plane2 = opengl::CTexturedPlane::Create(0,1,0,0.75);
|
| 69 |
+
opengl::CTexturedPlanePtr gl_plane3 = opengl::CTexturedPlane::Create(0,1,0,0.75);
|
| 70 |
+
|
| 71 |
+
gl_plane1->setPose(mrpt::poses::CPose3D(0,0,1, DEG2RAD(0), DEG2RAD(0), DEG2RAD(-90)));
|
| 72 |
+
gl_plane2->setPose(mrpt::poses::CPose3D(1,0,1, DEG2RAD(120), DEG2RAD(0), DEG2RAD(-90)));
|
| 73 |
+
gl_plane3->setPose(mrpt::poses::CPose3D(0,0,1, DEG2RAD(60), DEG2RAD(0), DEG2RAD(-90)));
|
| 74 |
+
|
| 75 |
+
win.setCameraZoom(5);
|
| 76 |
+
|
| 77 |
+
// Insert objects in scene:
|
| 78 |
+
{
|
| 79 |
+
COpenGLScenePtr &theScene = win.get3DSceneAndLock();
|
| 80 |
+
theScene->insert( gl_ground );
|
| 81 |
+
theScene->insert( gl_plane1 );
|
| 82 |
+
theScene->insert( gl_plane2 );
|
| 83 |
+
theScene->insert( gl_plane3 );
|
| 84 |
+
// IMPORTANT!!! IF NOT UNLOCKED, THE WINDOW WILL NOT BE UPDATED!
|
| 85 |
+
win.unlockAccess3DScene();
|
| 86 |
+
}
|
| 87 |
+
win.repaint();
|
| 88 |
+
|
| 89 |
+
cout << "Close the window to end.\n";
|
| 90 |
+
while (win.isOpen())
|
| 91 |
+
{
|
| 92 |
+
win.addTextMessage(5,5, format("%.02fFPS", win.getRenderingFPS()));
|
| 93 |
+
mrpt::system::sleep(1);
|
| 94 |
+
|
| 95 |
+
// Grab new video frame:
|
| 96 |
+
CObservationPtr obs = cam->getNextFrame();
|
| 97 |
+
if (obs)
|
| 98 |
+
{
|
| 99 |
+
if (IS_CLASS(obs,CObservationImage))
|
| 100 |
+
{
|
| 101 |
+
CObservationImagePtr o = CObservationImagePtr(obs);
|
| 102 |
+
win.get3DSceneAndLock();
|
| 103 |
+
gl_plane1->assignImage( o->image );
|
| 104 |
+
gl_plane2->assignImage( o->image );
|
| 105 |
+
gl_plane3->assignImage( o->image );
|
| 106 |
+
win.unlockAccess3DScene();
|
| 107 |
+
win.repaint();
|
| 108 |
+
}
|
| 109 |
+
}
|
| 110 |
+
}
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
// ------------------------------------------------------
|
| 114 |
+
// MAIN
|
| 115 |
+
// ------------------------------------------------------
|
| 116 |
+
int main()
|
| 117 |
+
{
|
| 118 |
+
try
|
| 119 |
+
{
|
| 120 |
+
TestOpenGLVideo();
|
| 121 |
+
|
| 122 |
+
return 0;
|
| 123 |
+
} catch (std::exception &e)
|
| 124 |
+
{
|
| 125 |
+
std::cout << "MRPT exception caught: " << e.what() << std::endl;
|
| 126 |
+
return -1;
|
| 127 |
+
}
|
| 128 |
+
catch (...)
|
| 129 |
+
{
|
| 130 |
+
printf("Untyped exception!!");
|
| 131 |
+
return -1;
|
| 132 |
+
}
|
| 133 |
+
}
|
pool/shard008/C++/0096584_csvr.cpp
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "csvr.hpp"
|
| 2 |
+
#include "utility/style.hpp"
|
| 3 |
+
#include "utility/common_utils.hpp"
|
| 4 |
+
|
| 5 |
+
using style::Color;
|
| 6 |
+
|
| 7 |
+
#include <cfloat> // For FLT_MAX as an internal error code
|
| 8 |
+
#include <cmath>
|
| 9 |
+
#include <limits>
|
| 10 |
+
#include <iostream>
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
csvr::csvr(std::string const& file_name, bool suppress_file_not_found) :
|
| 14 |
+
iFile{}, iLine(1) {
|
| 15 |
+
|
| 16 |
+
auto file { std14::make_unique<std::ifstream>(file_name) };
|
| 17 |
+
// Check if open successful
|
| 18 |
+
if (!file->is_open() && !suppress_file_not_found) {
|
| 19 |
+
std::cout << style::apply(Color::red) << "CSV file input failed. CSV file \'" <<
|
| 20 |
+
file_name << "\' not found or open." << style::reset() << '\n';
|
| 21 |
+
return;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
iFile = std::move(file);
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
bool csvr::has_stream() const {
|
| 28 |
+
return iFile.get();
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
bool csvr::skip_next() {
|
| 32 |
+
return csvr::get_next(static_cast<Real *>(nullptr));
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
bool csvr::get_next(int* rate) {
|
| 36 |
+
Real result;
|
| 37 |
+
bool success = get_next(&result);
|
| 38 |
+
if (success && rate) *rate = std::round(result);
|
| 39 |
+
return success;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
bool csvr::get_next(Real* pnRate) {
|
| 43 |
+
return csvr::get_real(*iFile, pnRate);
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
bool csvr::get_real(std::istream& iFile, Real* pnRate) {
|
| 47 |
+
// tParam data from file to be "pushed" to pfRate
|
| 48 |
+
std::string tParam; int iLine = 0;
|
| 49 |
+
|
| 50 |
+
char c;
|
| 51 |
+
while (iFile >> c) {
|
| 52 |
+
// Skip line comments
|
| 53 |
+
if (c == '#') {
|
| 54 |
+
iFile.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
|
| 55 |
+
tParam.clear();
|
| 56 |
+
++iLine;
|
| 57 |
+
}
|
| 58 |
+
// Parse only if not whitespace except for \n
|
| 59 |
+
else if (c != ' ' && c != '\t')
|
| 60 |
+
{
|
| 61 |
+
// Ignore non-numeric, non data seperator, non e, -, and + characters
|
| 62 |
+
if (!( (c >= '0' && c <= '9') || c == '.' || c == ',' || c == '\n' ||
|
| 63 |
+
c == 'e' || c == '-' || c == '+') )
|
| 64 |
+
{
|
| 65 |
+
iFile.ignore(std::numeric_limits<std::streamsize>::max(), ',');
|
| 66 |
+
tParam.clear();
|
| 67 |
+
}
|
| 68 |
+
// If hit data seperator, add data to respective array
|
| 69 |
+
// '\n' is there in case there is no comma after last item
|
| 70 |
+
else if (c != ',' && c != '\n') {
|
| 71 |
+
tParam += c;
|
| 72 |
+
}
|
| 73 |
+
else if (!tParam.empty()) {
|
| 74 |
+
char* tInvalidAt;
|
| 75 |
+
Real tRate = strtold(tParam.c_str(), &tInvalidAt);
|
| 76 |
+
|
| 77 |
+
// If found invalid while parsing
|
| 78 |
+
if (*tInvalidAt)
|
| 79 |
+
{
|
| 80 |
+
std::cout << style::apply(Color::red) <<
|
| 81 |
+
"CSV parsing failed. Invalid data contained "
|
| 82 |
+
"at line " << "(unknown)" << "." <<
|
| 83 |
+
style::reset() << '\n';
|
| 84 |
+
return false;
|
| 85 |
+
}
|
| 86 |
+
// Else was success
|
| 87 |
+
if (pnRate) { *pnRate = tRate; }
|
| 88 |
+
return true;
|
| 89 |
+
}
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
// Increment line counter
|
| 93 |
+
if (c == '\n') {
|
| 94 |
+
++iLine;
|
| 95 |
+
}
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
// End of file
|
| 99 |
+
return false;
|
| 100 |
+
}
|
pool/shard008/C++/0096586_storage_monitor.cc
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style license that can be
|
| 3 |
+
// found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
#include "chrome/browser/storage_monitor/storage_monitor.h"
|
| 6 |
+
|
| 7 |
+
#include "base/stl_util.h"
|
| 8 |
+
#include "base/strings/utf_string_conversions.h"
|
| 9 |
+
#include "chrome/browser/storage_monitor/removable_storage_observer.h"
|
| 10 |
+
#include "chrome/browser/storage_monitor/transient_device_ids.h"
|
| 11 |
+
|
| 12 |
+
namespace chrome {
|
| 13 |
+
|
| 14 |
+
static StorageMonitor* g_storage_monitor = NULL;
|
| 15 |
+
|
| 16 |
+
StorageMonitor::Receiver::~Receiver() {
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
class StorageMonitor::ReceiverImpl : public StorageMonitor::Receiver {
|
| 20 |
+
public:
|
| 21 |
+
explicit ReceiverImpl(StorageMonitor* notifications)
|
| 22 |
+
: notifications_(notifications) {}
|
| 23 |
+
|
| 24 |
+
virtual ~ReceiverImpl() {}
|
| 25 |
+
|
| 26 |
+
virtual void ProcessAttach(const StorageInfo& info) OVERRIDE;
|
| 27 |
+
|
| 28 |
+
virtual void ProcessDetach(const std::string& id) OVERRIDE;
|
| 29 |
+
|
| 30 |
+
virtual void MarkInitialized() OVERRIDE;
|
| 31 |
+
|
| 32 |
+
private:
|
| 33 |
+
StorageMonitor* notifications_;
|
| 34 |
+
};
|
| 35 |
+
|
| 36 |
+
void StorageMonitor::ReceiverImpl::ProcessAttach(const StorageInfo& info) {
|
| 37 |
+
notifications_->ProcessAttach(info);
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
void StorageMonitor::ReceiverImpl::ProcessDetach(const std::string& id) {
|
| 41 |
+
notifications_->ProcessDetach(id);
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
void StorageMonitor::ReceiverImpl::MarkInitialized() {
|
| 45 |
+
notifications_->MarkInitialized();
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
StorageMonitor* StorageMonitor::GetInstance() {
|
| 49 |
+
return g_storage_monitor;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
std::vector<StorageInfo> StorageMonitor::GetAllAvailableStorages() const {
|
| 53 |
+
std::vector<StorageInfo> results;
|
| 54 |
+
|
| 55 |
+
base::AutoLock lock(storage_lock_);
|
| 56 |
+
for (StorageMap::const_iterator it = storage_map_.begin();
|
| 57 |
+
it != storage_map_.end();
|
| 58 |
+
++it) {
|
| 59 |
+
results.push_back(it->second);
|
| 60 |
+
}
|
| 61 |
+
return results;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
void StorageMonitor::EnsureInitialized(base::Closure callback) {
|
| 65 |
+
DCHECK(thread_checker_.CalledOnValidThread());
|
| 66 |
+
if (initialized_) {
|
| 67 |
+
if (!callback.is_null())
|
| 68 |
+
callback.Run();
|
| 69 |
+
return;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
if (!callback.is_null()) {
|
| 73 |
+
on_initialize_callbacks_.push_back(callback);
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
if (initializing_)
|
| 77 |
+
return;
|
| 78 |
+
|
| 79 |
+
initializing_ = true;
|
| 80 |
+
Init();
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
bool StorageMonitor::IsInitialized() {
|
| 84 |
+
return initialized_;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
void StorageMonitor::AddObserver(RemovableStorageObserver* obs) {
|
| 88 |
+
observer_list_->AddObserver(obs);
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
void StorageMonitor::RemoveObserver(
|
| 92 |
+
RemovableStorageObserver* obs) {
|
| 93 |
+
observer_list_->RemoveObserver(obs);
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
std::string StorageMonitor::GetTransientIdForDeviceId(
|
| 97 |
+
const std::string& device_id) {
|
| 98 |
+
return transient_device_ids_->GetTransientIdForDeviceId(device_id);
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
std::string StorageMonitor::GetDeviceIdForTransientId(
|
| 102 |
+
const std::string& transient_id) const {
|
| 103 |
+
return transient_device_ids_->DeviceIdFromTransientId(transient_id);
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
void StorageMonitor::EjectDevice(
|
| 107 |
+
const std::string& device_id,
|
| 108 |
+
base::Callback<void(EjectStatus)> callback) {
|
| 109 |
+
// Platform-specific implementations will override this method to
|
| 110 |
+
// perform actual device ejection.
|
| 111 |
+
callback.Run(EJECT_FAILURE);
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
StorageMonitor::StorageMonitor()
|
| 115 |
+
: observer_list_(new ObserverListThreadSafe<RemovableStorageObserver>()),
|
| 116 |
+
initializing_(false),
|
| 117 |
+
initialized_(false),
|
| 118 |
+
transient_device_ids_(new TransientDeviceIds) {
|
| 119 |
+
receiver_.reset(new ReceiverImpl(this));
|
| 120 |
+
|
| 121 |
+
DCHECK(!g_storage_monitor);
|
| 122 |
+
g_storage_monitor = this;
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
StorageMonitor::~StorageMonitor() {
|
| 126 |
+
g_storage_monitor = NULL;
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
// static
|
| 130 |
+
void StorageMonitor::RemoveSingletonForTesting() {
|
| 131 |
+
g_storage_monitor = NULL;
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
StorageMonitor::Receiver* StorageMonitor::receiver() const {
|
| 135 |
+
return receiver_.get();
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
void StorageMonitor::MarkInitialized() {
|
| 139 |
+
initialized_ = true;
|
| 140 |
+
for (std::vector<base::Closure>::iterator iter =
|
| 141 |
+
on_initialize_callbacks_.begin();
|
| 142 |
+
iter != on_initialize_callbacks_.end(); ++iter) {
|
| 143 |
+
iter->Run();
|
| 144 |
+
}
|
| 145 |
+
on_initialize_callbacks_.clear();
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
void StorageMonitor::ProcessAttach(const StorageInfo& info) {
|
| 149 |
+
{
|
| 150 |
+
base::AutoLock lock(storage_lock_);
|
| 151 |
+
if (ContainsKey(storage_map_, info.device_id())) {
|
| 152 |
+
// This can happen if our unique id scheme fails. Ignore the incoming
|
| 153 |
+
// non-unique attachment.
|
| 154 |
+
return;
|
| 155 |
+
}
|
| 156 |
+
storage_map_.insert(std::make_pair(info.device_id(), info));
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
DVLOG(1) << "RemovableStorageAttached with name " << UTF16ToUTF8(info.name())
|
| 160 |
+
<< " and id " << info.device_id();
|
| 161 |
+
if (StorageInfo::IsRemovableDevice(info.device_id())) {
|
| 162 |
+
observer_list_->Notify(
|
| 163 |
+
&RemovableStorageObserver::OnRemovableStorageAttached, info);
|
| 164 |
+
}
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
void StorageMonitor::ProcessDetach(const std::string& id) {
|
| 168 |
+
StorageInfo info;
|
| 169 |
+
{
|
| 170 |
+
base::AutoLock lock(storage_lock_);
|
| 171 |
+
StorageMap::iterator it = storage_map_.find(id);
|
| 172 |
+
if (it == storage_map_.end())
|
| 173 |
+
return;
|
| 174 |
+
info = it->second;
|
| 175 |
+
storage_map_.erase(it);
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
DVLOG(1) << "RemovableStorageDetached for id " << id;
|
| 179 |
+
if (StorageInfo::IsRemovableDevice(info.device_id())) {
|
| 180 |
+
observer_list_->Notify(
|
| 181 |
+
&RemovableStorageObserver::OnRemovableStorageDetached, info);
|
| 182 |
+
}
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
} // namespace chrome
|
pool/shard008/C++/0096587_point_set_read_xyz.cpp
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
| 2 |
+
#include <CGAL/Point_set_3.h>
|
| 3 |
+
#include <CGAL/Point_set_3/IO.h>
|
| 4 |
+
|
| 5 |
+
#include <fstream>
|
| 6 |
+
#include <limits>
|
| 7 |
+
|
| 8 |
+
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
|
| 9 |
+
typedef Kernel::FT FT;
|
| 10 |
+
typedef Kernel::Point_3 Point;
|
| 11 |
+
typedef Kernel::Vector_3 Vector;
|
| 12 |
+
|
| 13 |
+
typedef CGAL::Point_set_3<Point> Point_set;
|
| 14 |
+
|
| 15 |
+
int main (int argc, char** argv)
|
| 16 |
+
{
|
| 17 |
+
std::ifstream f (argc > 1 ? argv[1] : "data/oni.xyz");
|
| 18 |
+
|
| 19 |
+
Point_set point_set;
|
| 20 |
+
|
| 21 |
+
// Reading input in XYZ format
|
| 22 |
+
if (!f || !CGAL::read_xyz_point_set (f, point_set))
|
| 23 |
+
{
|
| 24 |
+
std::cerr << "Can't read input file " << std::endl;
|
| 25 |
+
return EXIT_FAILURE;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
if (point_set.has_normal_map())
|
| 29 |
+
{
|
| 30 |
+
// Normalization + inversion of normal vectors
|
| 31 |
+
for (Point_set::iterator it = point_set.begin(); it != point_set.end(); ++ it)
|
| 32 |
+
{
|
| 33 |
+
Vector n = point_set.normal(*it);
|
| 34 |
+
n = - n / std::sqrt (n * n);
|
| 35 |
+
point_set.normal(*it) = n;
|
| 36 |
+
}
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
// Writing result in OFF format
|
| 40 |
+
std::ofstream out("normalized_normals.off");
|
| 41 |
+
if (!out || !CGAL::write_off_point_set (out, point_set))
|
| 42 |
+
{
|
| 43 |
+
return EXIT_FAILURE;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
return EXIT_SUCCESS;
|
| 47 |
+
}
|
pool/shard008/C++/0096589_utils.cpp
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "utils.hpp"
|
| 2 |
+
|
| 3 |
+
std::string replace(std::string source, std::string target, std::string replacement) {
|
| 4 |
+
size_t start = source.find(target);
|
| 5 |
+
|
| 6 |
+
if (start != std::string::npos) {
|
| 7 |
+
size_t end = start + target.size();
|
| 8 |
+
std::string left = source.substr(0, start);
|
| 9 |
+
std::string right = source.substr(end, source.size() - end);
|
| 10 |
+
return left + replacement + right;
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
return source;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
std::string params(std::vector<std::string> params_) {
|
| 17 |
+
if (params_.size() == 0)
|
| 18 |
+
return "";
|
| 19 |
+
|
| 20 |
+
std::string source = params_[0];
|
| 21 |
+
|
| 22 |
+
for (size_t i = 1; i < params_.size(); ++i) {
|
| 23 |
+
source += ", " + params_[i];
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
return source;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
std::string braces(std::string inner) {
|
| 30 |
+
return "{" + inner + "}";
|
| 31 |
+
}
|
pool/shard008/C++/0096590_configsettingslog.cpp
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "configsettingslog.h"
|
| 2 |
+
#include "util.h"
|
| 3 |
+
#include "configsettings.h"
|
| 4 |
+
#include "logfile.h"
|
| 5 |
+
#include <assert.h>
|
| 6 |
+
#include <list>
|
| 7 |
+
#include <algorithm>
|
| 8 |
+
#include <iostream>
|
| 9 |
+
|
| 10 |
+
using namespace std;
|
| 11 |
+
|
| 12 |
+
void ConfigSettingsLog::addConfigSettings(double t, const ConfigSettings &config)
|
| 13 |
+
{
|
| 14 |
+
string timeString = strprintf("%10.10f", t);
|
| 15 |
+
|
| 16 |
+
if (m_configLog.size() == 0) // first entry
|
| 17 |
+
{
|
| 18 |
+
vector<string> keys;
|
| 19 |
+
config.getKeys(keys);
|
| 20 |
+
|
| 21 |
+
for (size_t k = 0 ; k < keys.size() ; k++)
|
| 22 |
+
{
|
| 23 |
+
string key = keys[k];
|
| 24 |
+
string value;
|
| 25 |
+
bool used = false;
|
| 26 |
+
|
| 27 |
+
if (!config.getStringKeyValue(key, value, used))
|
| 28 |
+
abortWithMessage("Unexpected error: couldn't retrieve config value for key '" + key + "' even though it was reported to exist");
|
| 29 |
+
|
| 30 |
+
vector<string> initialValue { value };
|
| 31 |
+
m_configLog[key] = initialValue;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
vector<string> initialTime { timeString };
|
| 35 |
+
m_configLog["t"] = initialTime;
|
| 36 |
+
}
|
| 37 |
+
else
|
| 38 |
+
{
|
| 39 |
+
const size_t numEntries = m_configLog.begin()->second.size();
|
| 40 |
+
|
| 41 |
+
vector<string> keys;
|
| 42 |
+
config.getKeys(keys);
|
| 43 |
+
|
| 44 |
+
for (size_t k = 0 ; k < keys.size() ; k++)
|
| 45 |
+
{
|
| 46 |
+
string key = keys[k];
|
| 47 |
+
string value;
|
| 48 |
+
bool used = false;
|
| 49 |
+
|
| 50 |
+
if (!config.getStringKeyValue(key, value, used))
|
| 51 |
+
abortWithMessage("Unexpected error: couldn't retrieve config value for key '" + key + "' even though it was reported to exist");
|
| 52 |
+
|
| 53 |
+
auto it = m_configLog.find(key);
|
| 54 |
+
|
| 55 |
+
if (it == m_configLog.end()) // not found yet, add empty entry
|
| 56 |
+
{
|
| 57 |
+
vector<string> empty;
|
| 58 |
+
|
| 59 |
+
m_configLog[key] = empty;
|
| 60 |
+
it = m_configLog.find(key);
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
vector<string> &knownValues = it->second;
|
| 64 |
+
if (knownValues.size() < numEntries)
|
| 65 |
+
{
|
| 66 |
+
const size_t s = knownValues.size();
|
| 67 |
+
|
| 68 |
+
for (size_t i = s ; i < numEntries ; i++)
|
| 69 |
+
knownValues.push_back("NA");
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
// Finally, add the current value
|
| 73 |
+
knownValues.push_back(value);
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
// And log the time
|
| 77 |
+
m_configLog["t"].push_back(timeString);
|
| 78 |
+
|
| 79 |
+
/*
|
| 80 |
+
for (auto it = m_configLog.begin() ; it != m_configLog.end() ; ++it)
|
| 81 |
+
{
|
| 82 |
+
cout << it->first;
|
| 83 |
+
for (auto it2 = it->second.begin() ; it2 != it->second.end() ; ++it2)
|
| 84 |
+
cout << "\t" << *it2;
|
| 85 |
+
cout << endl;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
abortWithMessage("TODO");
|
| 89 |
+
*/
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
map<string, vector<string> > ConfigSettingsLog::m_configLog;
|
| 95 |
+
|
| 96 |
+
void ConfigSettingsLog::writeConfigSettings(LogFile &s)
|
| 97 |
+
{
|
| 98 |
+
if (!s.isOpen()) // no logging requested
|
| 99 |
+
return;
|
| 100 |
+
|
| 101 |
+
list<string> keys;
|
| 102 |
+
|
| 103 |
+
// Order the keys, but skip 't' for now
|
| 104 |
+
for (auto it = m_configLog.begin() ; it != m_configLog.end() ; ++it)
|
| 105 |
+
{
|
| 106 |
+
string key = it->first;
|
| 107 |
+
|
| 108 |
+
if (key != "t")
|
| 109 |
+
keys.push_back(key);
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
// Order the keys
|
| 113 |
+
keys.sort();
|
| 114 |
+
|
| 115 |
+
// Make sure 't' is first
|
| 116 |
+
keys.push_front("t");
|
| 117 |
+
|
| 118 |
+
bool first = true;
|
| 119 |
+
for (auto it = keys.begin() ; it != keys.end() ; ++it)
|
| 120 |
+
{
|
| 121 |
+
if (!first)
|
| 122 |
+
s.printNoNewLine(",");
|
| 123 |
+
s.printNoNewLine("\"%s\"", it->c_str());
|
| 124 |
+
first = false;
|
| 125 |
+
}
|
| 126 |
+
s.print("");
|
| 127 |
+
|
| 128 |
+
const size_t numEntries = m_configLog["t"].size();
|
| 129 |
+
for (size_t i = 0 ; i < numEntries ; i++)
|
| 130 |
+
{
|
| 131 |
+
bool first = true;
|
| 132 |
+
for (auto it = keys.begin() ; it != keys.end() ; ++it)
|
| 133 |
+
{
|
| 134 |
+
if (!first)
|
| 135 |
+
s.printNoNewLine(",");
|
| 136 |
+
|
| 137 |
+
vector<string> &vals = m_configLog[*it];
|
| 138 |
+
if (vals.size() != numEntries)
|
| 139 |
+
abortWithMessage(strprintf("key %s, numEntries: %d vals.size(): %d", it->c_str(), (int)numEntries, (int)vals.size()));
|
| 140 |
+
|
| 141 |
+
assert(vals.size() == numEntries);
|
| 142 |
+
|
| 143 |
+
string value = vals[i];
|
| 144 |
+
if (value.find(",") != string::npos)
|
| 145 |
+
value = "\"" + value + "\"";
|
| 146 |
+
|
| 147 |
+
s.printNoNewLine("%s", value.c_str());
|
| 148 |
+
first = false;
|
| 149 |
+
}
|
| 150 |
+
s.print("");
|
| 151 |
+
}
|
| 152 |
+
}
|
| 153 |
+
|