Upload folder using huggingface_hub (part 30)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- pool/shard002/C++/0024344_GameLevel.cpp +150 -0
- pool/shard002/C++/0024353_ministellar.cpp +137 -0
- pool/shard002/C++/0024356_sys_net_native_System_Net_NetworkInformation_IPGlobalProperties.cpp +90 -0
- pool/shard002/C++/0024362_cpp.cc +86 -0
- pool/shard002/C++/0024364_HorizonWidget.cpp +116 -0
- pool/shard002/C++/0024366_process_shield_symbolizer.cpp +98 -0
- pool/shard002/C++/0024368_colorsource.cpp +160 -0
- pool/shard002/C++/0024375_qgsfeaturelistviewdelegate.cpp +149 -0
- pool/shard002/C++/0024381_sample_activity.cc +102 -0
- pool/shard002/C++/0024388_727A.cpp +40 -0
- pool/shard002/C++/0024389_cxxhello.cc +26 -0
- pool/shard002/C++/0024396_FakeGPIO.cpp +88 -0
- pool/shard002/C++/0024397_main.cpp +28 -0
- pool/shard002/C++/0024399_supervised_user_manager_impl.cc +282 -0
- pool/shard002/C++/0024406_B.cpp +49 -0
- pool/shard002/C++/0024409_math_util.cpp +146 -0
- pool/shard002/C++/0024412_haj_weapon_shovel.cpp +213 -0
- pool/shard002/C++/0024414_lock_view.cc +109 -0
- pool/shard002/C++/0024416_MsPacman.cpp +106 -0
- pool/shard002/C++/0024426_config.cpp +227 -0
- pool/shard002/C++/0024430_solve.cpp +179 -0
- pool/shard002/C++/0024433_RtmpGuesterImpl.cc +107 -0
- pool/shard002/C++/0024435_dist1.cpp +58 -0
- pool/shard002/C++/0024438_directory.cpp +56 -0
- pool/shard002/C++/0024446_cpredictivesearchsettingstable.cpp +203 -0
- pool/shard002/C++/0024455_ObjectManager.cpp +85 -0
- pool/shard002/C++/0024457_Vector4_TEST.cc +137 -0
- pool/shard002/C++/0024464_CRendererOGLES1_1.cpp +174 -0
- pool/shard002/C++/0024468_rpc_stream.cpp +87 -0
- pool/shard002/C++/0024470_CheckBox.cpp +150 -0
- pool/shard002/C++/0024474_cs_lfg.cpp +169 -0
- pool/shard002/C++/0024479_audio_hash_unittest.cc +168 -0
- pool/shard002/C++/0024484_iwBuildingProductivities.cpp +98 -0
- pool/shard002/C++/0024488_billboards.cpp +156 -0
- pool/shard002/C++/0024490_sighash_tests.cpp +217 -0
- pool/shard002/C++/0024496_WKBundleFileHandle_Bundle.cpp +99 -0
- pool/shard002/C++/0024497_virtual_machine.cpp +93 -0
- pool/shard002/C++/0024502_RullerSplliterWnd.cpp +87 -0
- pool/shard002/C++/0024504_1_.cpp +19 -0
- pool/shard002/C++/0024508_mission_list_model.cpp +75 -0
- pool/shard002/C++/0024511_snipPartMerger.cpp +121 -0
- pool/shard002/C++/0024513_EnumParameterType.cpp +350 -0
- pool/shard002/C++/0024522_NuiMayaMeshGenerator.cpp +341 -0
- pool/shard002/C++/0024528_ASN1_ValueUTF8String.cpp +30 -0
- pool/shard002/C++/0024533_Versions.cpp +226 -0
- pool/shard002/C++/0024534_Plot2DProfile.cpp +204 -0
- pool/shard002/C++/0024537_Local.cpp +156 -0
- pool/shard002/C++/0024539_test_idt_x64.cpp +101 -0
- pool/shard002/C++/0024548_raw.cpp +73 -0
- pool/shard002/C++/0024550_PrimitiveParsing.cpp +75 -0
pool/shard002/C++/0024344_GameLevel.cpp
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "GameLevel.h"
|
| 2 |
+
|
| 3 |
+
#include <istream>
|
| 4 |
+
#include <sstream>
|
| 5 |
+
|
| 6 |
+
GameLevel::~GameLevel(){
|
| 7 |
+
delete space;
|
| 8 |
+
delete heightmap;
|
| 9 |
+
// delete water;
|
| 10 |
+
delete skybox;
|
| 11 |
+
}
|
| 12 |
+
void GameLevel::parseFile(const char *filename){
|
| 13 |
+
std::ifstream is;
|
| 14 |
+
is.open(filename);
|
| 15 |
+
if(!is.is_open()) {
|
| 16 |
+
throw YGEExceptionFileNotFound(filename);
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
while(!is.eof()){
|
| 20 |
+
std::string line, type;
|
| 21 |
+
getline(is, line);
|
| 22 |
+
std::istringstream istr(line);
|
| 23 |
+
|
| 24 |
+
istr >> type;
|
| 25 |
+
|
| 26 |
+
if(type == "sky:") {
|
| 27 |
+
istr >> skymapName;
|
| 28 |
+
}
|
| 29 |
+
if(type == "sunposition:") {
|
| 30 |
+
istr >> sunposition.x;
|
| 31 |
+
istr >> sunposition.y;
|
| 32 |
+
istr >> sunposition.z;
|
| 33 |
+
}
|
| 34 |
+
if(type == "suncolor:") {
|
| 35 |
+
istr >> suncolor.x;
|
| 36 |
+
istr >> suncolor.y;
|
| 37 |
+
istr >> suncolor.z;
|
| 38 |
+
}
|
| 39 |
+
if(type == "timeToComplete:") {
|
| 40 |
+
istr >> timeToComplete;
|
| 41 |
+
|
| 42 |
+
}
|
| 43 |
+
if(type == "mapFileName:") {
|
| 44 |
+
istr >> mapFileName;
|
| 45 |
+
|
| 46 |
+
}
|
| 47 |
+
if(type == "textureFileName:") {
|
| 48 |
+
istr >> textureFileName;
|
| 49 |
+
|
| 50 |
+
}
|
| 51 |
+
if(type == "mapScale:") {
|
| 52 |
+
istr >> mapScale.x;
|
| 53 |
+
istr >> mapScale.y;
|
| 54 |
+
istr >> mapScale.z;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
if(type == "startPos:") {
|
| 58 |
+
istr >> startPos.x;
|
| 59 |
+
istr >> startPos.y;
|
| 60 |
+
istr >> startPos.z;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
if(type == "ball:") {
|
| 64 |
+
YGEMath::Vector3 position;
|
| 65 |
+
|
| 66 |
+
std::string color;
|
| 67 |
+
istr >> color;
|
| 68 |
+
|
| 69 |
+
istr >> position.x;
|
| 70 |
+
istr >> position.y;
|
| 71 |
+
istr >> position.z;
|
| 72 |
+
|
| 73 |
+
ballPositions.push_back(std::pair<YGEMath::Vector3, std::string>(position, color));
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
void GameLevel::createFromFile(const char* filename){
|
| 82 |
+
|
| 83 |
+
mapScale.x = 100;
|
| 84 |
+
mapScale.y = 100;
|
| 85 |
+
mapScale.z = 100;
|
| 86 |
+
|
| 87 |
+
parseFile(YGECore::YGEResourceManager::getInstance()->absoluteFilename( filename ).c_str() );
|
| 88 |
+
|
| 89 |
+
// create a space
|
| 90 |
+
space = new YGETimeSpace::YGESpace();
|
| 91 |
+
space->initTime();
|
| 92 |
+
space->setSoundEnabled(true);
|
| 93 |
+
|
| 94 |
+
// create the heightmap
|
| 95 |
+
heightmap = new YGEGraphics::YGEHeightmap();
|
| 96 |
+
heightmap->create(mapFileName.c_str(), textureFileName.c_str(), mapScale.x, mapScale.z, mapScale.y);
|
| 97 |
+
space->getRootEntity()->addAsset(heightmap);
|
| 98 |
+
|
| 99 |
+
heightmap->makeSolid();
|
| 100 |
+
|
| 101 |
+
//water = new YGEGraphics::YGEWater(heightmap, 10);
|
| 102 |
+
//space->getRootEntity()->addAsset(water);
|
| 103 |
+
|
| 104 |
+
skybox = new YGEGraphics::YGESkybox();
|
| 105 |
+
skybox->loadTextures(skymapName.c_str());
|
| 106 |
+
space->setSkybox(skybox);
|
| 107 |
+
space->getSunlight()->setColor((float)suncolor.x, (float)suncolor.y, (float)suncolor.z);
|
| 108 |
+
space->getSunlight()->setDirection(sunposition);
|
| 109 |
+
|
| 110 |
+
for(std::list<std::pair<YGEMath::Vector3, std::string> >::iterator iter = ballPositions.begin(); iter != ballPositions.end(); iter++){
|
| 111 |
+
|
| 112 |
+
GameBall* ball;
|
| 113 |
+
|
| 114 |
+
if(iter->second == "blue") {
|
| 115 |
+
ball = new GameBall(7, 0, 0, 1);
|
| 116 |
+
} else if(iter->second == "red") {
|
| 117 |
+
ball = new GameBall(5, 1, 0, 0);
|
| 118 |
+
} else if(iter->second == "pink") {
|
| 119 |
+
ball = new GameBall(2, 1, 0, 1);
|
| 120 |
+
} else {
|
| 121 |
+
ball = new GameBall(10, 1, 1, 1);
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
space->getRootEntity()->addChild(ball);
|
| 126 |
+
ball->setPosition(iter->first);
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
YGEMath::Vector3 GameLevel::getPlayerStartPosition(){
|
| 135 |
+
return startPos;
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
void GameLevel::addEntity(YGETimeSpace::YGEEntity* entity){
|
| 139 |
+
space->getRootEntity()->addChild(entity);
|
| 140 |
+
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
int GameLevel::getNumberOfBalls(){
|
| 144 |
+
return ballPositions.size();
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
int GameLevel::getTimeToComplete(){
|
| 148 |
+
|
| 149 |
+
return timeToComplete;
|
| 150 |
+
}
|
pool/shard002/C++/0024353_ministellar.cpp
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <seqan/stream.h>
|
| 2 |
+
#include <seqan/index.h>
|
| 3 |
+
#include <seqan/align.h>
|
| 4 |
+
#include <seqan/seeds2.h>
|
| 5 |
+
|
| 6 |
+
using namespace seqan;
|
| 7 |
+
|
| 8 |
+
// set parameters
|
| 9 |
+
|
| 10 |
+
unsigned const minimalLength = 12;
|
| 11 |
+
float const errorRate = 0.05;
|
| 12 |
+
//unsigned const qGramLength = 8;
|
| 13 |
+
CharString const filename = "ministellar.out";
|
| 14 |
+
|
| 15 |
+
typedef int TScoreValue;
|
| 16 |
+
TScoreValue const matchScore = 1;
|
| 17 |
+
TScoreValue const mismatchScore = -2;
|
| 18 |
+
TScoreValue const gapScore = -2;
|
| 19 |
+
TScoreValue const minScore = 9;
|
| 20 |
+
TScoreValue const xDrop = 3;
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
int main(int argc, char const ** argv)
|
| 24 |
+
{
|
| 25 |
+
if (argc != 3)
|
| 26 |
+
{
|
| 27 |
+
std::cerr << "ERROR: Invalid argument count!" << std::endl;
|
| 28 |
+
std::cerr << "USAGE: ministallar IN1.fa IN2.fa" << std::endl;
|
| 29 |
+
return 1;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
Score<int, Simple> scoring = Score<int, Simple>(matchScore, mismatchScore, gapScore);
|
| 33 |
+
// DONE: Define a scoring scheme 'score' with linear gap costs using the above defined
|
| 34 |
+
// score values for scoring matches, mismatches, and gaps.
|
| 35 |
+
// HINT: You can find a section on Schoring Schemes in the Alignments tutorial.
|
| 36 |
+
|
| 37 |
+
// read sequences from fasta files
|
| 38 |
+
typedef Dna5String TSequence;
|
| 39 |
+
StringSet<CharString> ids1, ids2;
|
| 40 |
+
StringSet<TSequence> seqs1, seqs2;
|
| 41 |
+
|
| 42 |
+
std::ifstream streamIn1(argv[1], std::ios::in | std::ios::binary);
|
| 43 |
+
RecordReader<std::ifstream, SinglePass<> > reader1(streamIn1);
|
| 44 |
+
if (read2(ids1, seqs1, reader1, Fasta()) != 0)
|
| 45 |
+
{
|
| 46 |
+
std::cerr << "Could not read file " << argv[1] << std::endl;
|
| 47 |
+
return 1;
|
| 48 |
+
}
|
| 49 |
+
// DONE: Do the same for the second file.
|
| 50 |
+
|
| 51 |
+
std::ifstream streamIn2(argv[2], std::ios::in | std::ios::binary);
|
| 52 |
+
RecordReader<std::ifstream, SinglePass<> > reader2(streamIn2);
|
| 53 |
+
if (read2(ids2, seqs2, reader2, Fasta()) != 0)
|
| 54 |
+
{
|
| 55 |
+
std::cerr << "Could not read file " << argv[2] << std::endl;
|
| 56 |
+
return 1;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
// prepare output file
|
| 60 |
+
std::ofstream outFile;
|
| 61 |
+
outFile.open(toCString(filename));
|
| 62 |
+
|
| 63 |
+
// define finder and pattern
|
| 64 |
+
// TODO: Define types for finder and pattern using SeqAn's find interface from the index
|
| 65 |
+
// module. Both should be specialized for the approproiate swift filter algorithm.
|
| 66 |
+
// The pattern will need the definition of a q-gram-index. Use q-grams of length 8
|
| 67 |
+
// for now, and open addressing.
|
| 68 |
+
// HINT: The tutorial on Pattern Matching describes the find interface. At the end of that
|
| 69 |
+
// tutorial page, you will find a link to a Swift HowTo page.
|
| 70 |
+
|
| 71 |
+
typedef Index<TSequence, IndexQGram<UngappedShape<8> > > TQIndex;
|
| 72 |
+
typedef Finder<TSequence, Swift<SwiftLocal> > TFinder;
|
| 73 |
+
typedef Pattern<TQIndex, Swift<SwiftLocal> > TPattern;
|
| 74 |
+
|
| 75 |
+
// TODO: Define variables of your pattern and finder types, and initialize them with the
|
| 76 |
+
// first sequences in the sequence sets seqs1 and seqs2.
|
| 77 |
+
TQIndex index1 = TQIndex(seqs1[0]);
|
| 78 |
+
TPattern pattern = TPattern(index1);
|
| 79 |
+
TFinder finder = TFinder(seqs2[0]);
|
| 80 |
+
|
| 81 |
+
// TODO: Repeat the following steps for all hits of the finder.
|
| 82 |
+
//typedef Iterator<TFinder> TFinderIt;
|
| 83 |
+
//TFinderIt it = TFinderIt(finder);
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
// call the function find to obtain a swift hit
|
| 87 |
+
// TODO: uncomment the following line
|
| 88 |
+
|
| 89 |
+
while (find(finder, pattern, errorRate, int(minimalLength))) {
|
| 90 |
+
|
| 91 |
+
// extract infixes from hit
|
| 92 |
+
// TODO: uncomment the following three lines
|
| 93 |
+
|
| 94 |
+
typedef Infix<TSequence>::Type TInfix;
|
| 95 |
+
TInfix infix1 = infix(finder, seqs1[0]);
|
| 96 |
+
TInfix infix2 = infix(pattern, seqs2[0]);
|
| 97 |
+
|
| 98 |
+
// find best local alignment of infixes, and check for minimal score
|
| 99 |
+
// TODO: Define an align object and initialize it with the infixes. Find the best local
|
| 100 |
+
// alignment of the infixes. Use the above defined scoring scheme. Make sure that
|
| 101 |
+
// it reaches the minimal score minScore.
|
| 102 |
+
|
| 103 |
+
//std::cout << infix1 << std::endl;
|
| 104 |
+
//std::cout << infix2 << std::endl;
|
| 105 |
+
typedef Align<TSequence> TAlign;
|
| 106 |
+
typedef Row<TAlign> TRow;
|
| 107 |
+
TAlign aln = TAlign();
|
| 108 |
+
resize(rows(aln), 2);
|
| 109 |
+
assignSource(row(aln, 0), infix1);
|
| 110 |
+
assignSource(row(aln, 1), infix2);
|
| 111 |
+
int scr = localAlignment(aln, scoring);
|
| 112 |
+
if (scr < minScore) {
|
| 113 |
+
continue;
|
| 114 |
+
}
|
| 115 |
+
// create a seed for the local alignment, and conduct gapped X-drop extension
|
| 116 |
+
// TODO: Define a seed on the original sequences but for the subsequences of the local
|
| 117 |
+
// alignment. Extend this seed in both directions using gapped X-drop extension.
|
| 118 |
+
// Check that the extended seed has a length of at least minimalLength.
|
| 119 |
+
// HINT: Have a look at the Seed-and-Extend tutorial.
|
| 120 |
+
typedef Seed<Simple> TSeed;
|
| 121 |
+
TSeed seed = TSeed(beginPosition(infix1) + clippedBeginPosition(row(aln, 0)),
|
| 122 |
+
beginPosition(infix2) + clippedBeginPosition(row(aln, 1)),
|
| 123 |
+
beginPosition(infix1) + clippedEndPosition(row(aln, 0)),
|
| 124 |
+
beginPosition(infix2) + clippedEndPosition(row(aln, 1)));
|
| 125 |
+
|
| 126 |
+
extendSeed(seed, xDrop, scoring, seqs1[0], seqs2[0], 2, GappedXDrop());
|
| 127 |
+
}
|
| 128 |
+
// find best global alignment of extended seed
|
| 129 |
+
// TODO: Compute the best global alignment of extended seed and its score.
|
| 130 |
+
// HINT: Create an align object on infixes of the sequences.
|
| 131 |
+
|
| 132 |
+
// TODO: Output the alignment as a match to the output file.
|
| 133 |
+
|
| 134 |
+
outFile.close();
|
| 135 |
+
|
| 136 |
+
return 0;
|
| 137 |
+
}
|
pool/shard002/C++/0024356_sys_net_native_System_Net_NetworkInformation_IPGlobalProperties.cpp
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// Copyright (c) .NET Foundation and Contributors
|
| 3 |
+
// See LICENSE file in the project root for full license information.
|
| 4 |
+
//
|
| 5 |
+
|
| 6 |
+
#include "sys_net_native.h"
|
| 7 |
+
#include <nanoPAL_Sockets.h>
|
| 8 |
+
|
| 9 |
+
HRESULT Library_sys_net_native_System_Net_NetworkInformation_IPGlobalProperties::
|
| 10 |
+
GetIPAddress___STATIC__SystemNetIPAddress(CLR_RT_StackFrame &stack)
|
| 11 |
+
{
|
| 12 |
+
NANOCLR_HEADER();
|
| 13 |
+
|
| 14 |
+
HAL_Configuration_NetworkInterface config;
|
| 15 |
+
|
| 16 |
+
CLR_RT_TypeDef_Index ipAddressTypeDef;
|
| 17 |
+
CLR_RT_HeapBlock *ipAddressHbObj;
|
| 18 |
+
CLR_RT_HeapBlock ipAddress;
|
| 19 |
+
CLR_INT64 *pRes;
|
| 20 |
+
bool ipAddressValid = false;
|
| 21 |
+
|
| 22 |
+
CLR_RT_HeapBlock &top = stack.PushValue();
|
| 23 |
+
|
| 24 |
+
// find <IPAddress> type, don't bother checking the result as it exists for sure
|
| 25 |
+
g_CLR_RT_TypeSystem.FindTypeDef("IPAddress", "System.Net", ipAddressTypeDef);
|
| 26 |
+
|
| 27 |
+
// create an instance of <IPAddress>
|
| 28 |
+
NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.NewObjectFromIndex(ipAddress, ipAddressTypeDef));
|
| 29 |
+
|
| 30 |
+
// dereference the object in order to reach its fields
|
| 31 |
+
ipAddressHbObj = ipAddress.Dereference();
|
| 32 |
+
|
| 33 |
+
{
|
| 34 |
+
// IPAddress _address field
|
| 35 |
+
// CLR_INT64 fields need to be accessed by pointer
|
| 36 |
+
CLR_RT_HeapBlock &addressFieldRef = ipAddressHbObj[Library_sys_net_native_System_Net_IPAddress::FIELD__Address];
|
| 37 |
+
pRes = (CLR_INT64 *)&addressFieldRef.NumericByRef().s8;
|
| 38 |
+
|
| 39 |
+
// IPAddress _family field
|
| 40 |
+
// IP v4: AddressFamily.InterNetwork
|
| 41 |
+
ipAddressHbObj[Library_sys_net_native_System_Net_IPAddress::FIELD___family].NumericByRef().s4 = SOCK_AF_INET;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
// loop through all the network interface and check if any is up
|
| 45 |
+
for (int interfaceIndex = 0; interfaceIndex < g_TargetConfiguration.NetworkInterfaceConfigs->Count;
|
| 46 |
+
interfaceIndex++)
|
| 47 |
+
{
|
| 48 |
+
NANOCLR_CLEAR(config);
|
| 49 |
+
|
| 50 |
+
// load network interface configuration from storage
|
| 51 |
+
if (!ConfigurationManager_GetConfigurationBlock(
|
| 52 |
+
(void *)&config,
|
| 53 |
+
DeviceConfigurationOption_Network,
|
| 54 |
+
interfaceIndex))
|
| 55 |
+
{
|
| 56 |
+
NANOCLR_SET_AND_LEAVE(CLR_E_FAIL);
|
| 57 |
+
}
|
| 58 |
+
_ASSERTE(config.StartupAddressMode > 0);
|
| 59 |
+
|
| 60 |
+
// load adapter configuration on top of the stored config
|
| 61 |
+
NANOCLR_CHECK_HRESULT(SOCK_CONFIGURATION_LoadConfiguration(&config, interfaceIndex));
|
| 62 |
+
|
| 63 |
+
// has IP v4?
|
| 64 |
+
if (config.IPv4Address > 0)
|
| 65 |
+
{
|
| 66 |
+
*pRes = config.IPv4Address;
|
| 67 |
+
|
| 68 |
+
// we have an IP...
|
| 69 |
+
ipAddressValid = true;
|
| 70 |
+
|
| 71 |
+
// .. no need to check any other
|
| 72 |
+
break;
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
if (ipAddressValid)
|
| 77 |
+
{
|
| 78 |
+
// set address field with IPAddress heap block object
|
| 79 |
+
top.SetObjectReference(ipAddressHbObj);
|
| 80 |
+
}
|
| 81 |
+
else
|
| 82 |
+
{
|
| 83 |
+
// default to IP Any Address
|
| 84 |
+
top.SetObjectReference(g_CLR_RT_TypeSystem.m_assemblies[ipAddressTypeDef.Assembly() - 1]
|
| 85 |
+
->GetStaticField(Library_sys_net_native_System_Net_IPAddress::FIELD_STATIC__Any)
|
| 86 |
+
->Dereference());
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
NANOCLR_NOCLEANUP();
|
| 90 |
+
}
|
pool/shard002/C++/0024362_cpp.cc
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <iostream>
|
| 2 |
+
#include <unordered_map>
|
| 3 |
+
|
| 4 |
+
using namespace std;
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class Solution {
|
| 10 |
+
struct ninfo{
|
| 11 |
+
int maxpos;
|
| 12 |
+
int maxneg;
|
| 13 |
+
};
|
| 14 |
+
public:
|
| 15 |
+
int maxProduct(int A[], int n) {
|
| 16 |
+
if (n == 1)
|
| 17 |
+
return A[0];
|
| 18 |
+
int maxpos(0), maxneg(0), max(INT_MIN), tp(0), tn(0);
|
| 19 |
+
for (auto i = n - 1; i >= 0; --i)
|
| 20 |
+
{
|
| 21 |
+
tp = A[i] * maxpos;
|
| 22 |
+
tn = A[i] * maxneg;
|
| 23 |
+
if (tn>tp)
|
| 24 |
+
swap(tn, tp);
|
| 25 |
+
if (tp>max)
|
| 26 |
+
max = tp;
|
| 27 |
+
if (A[i]>max)
|
| 28 |
+
max = A[i];
|
| 29 |
+
maxpos = tp>A[i] ? tp : A[i];
|
| 30 |
+
maxneg = tn<A[i] ? tn : A[i];
|
| 31 |
+
}
|
| 32 |
+
return max;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
int maxPro2(int A[], int n)
|
| 36 |
+
{
|
| 37 |
+
int maxpro(INT_MIN);
|
| 38 |
+
int maxneg(INT_MAX);
|
| 39 |
+
return 0;
|
| 40 |
+
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
int maxPro(int A[], int n){
|
| 44 |
+
ninfo start = { 0, 0 };
|
| 45 |
+
int max(INT_MIN);
|
| 46 |
+
for (auto i = n - 1; i >= 0; --i)
|
| 47 |
+
{
|
| 48 |
+
if (A[i] > 0)
|
| 49 |
+
{
|
| 50 |
+
int t = A[i] * start.maxpos;
|
| 51 |
+
start.maxpos = A[i] > t ? A[i] : t;
|
| 52 |
+
start.maxneg *= A[i];
|
| 53 |
+
|
| 54 |
+
}
|
| 55 |
+
else if(A[i] < 0)
|
| 56 |
+
{
|
| 57 |
+
int t = A[i] * start.maxneg;
|
| 58 |
+
if (t>start.maxpos)
|
| 59 |
+
start.maxpos = t;
|
| 60 |
+
start.maxneg = start.maxpos * A[i];
|
| 61 |
+
}
|
| 62 |
+
else
|
| 63 |
+
{
|
| 64 |
+
start.maxpos = 0;
|
| 65 |
+
start.maxneg = 0;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
if (start.maxpos > max)
|
| 69 |
+
max = start.maxpos;
|
| 70 |
+
}
|
| 71 |
+
return max;
|
| 72 |
+
}
|
| 73 |
+
private:
|
| 74 |
+
unordered_map<int, int> cache;
|
| 75 |
+
|
| 76 |
+
};
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
int main()
|
| 80 |
+
{
|
| 81 |
+
Solution s;
|
| 82 |
+
//vector<int> test = { 2, 3, -2, 4 };
|
| 83 |
+
int test[4] = { 2, 3, -2, 4 };
|
| 84 |
+
cout << s.maxProduct(test, 4)<<endl;
|
| 85 |
+
system("pause");
|
| 86 |
+
}
|
pool/shard002/C++/0024364_HorizonWidget.cpp
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Copyright_License {
|
| 3 |
+
|
| 4 |
+
XCSoar Glide Computer - http://www.xcsoar.org/
|
| 5 |
+
Copyright (C) 2000-2013 The XCSoar Project
|
| 6 |
+
A detailed list of copyright holders can be found in the file "AUTHORS".
|
| 7 |
+
|
| 8 |
+
This program is free software; you can redistribute it and/or
|
| 9 |
+
modify it under the terms of the GNU General Public License
|
| 10 |
+
as published by the Free Software Foundation; either version 2
|
| 11 |
+
of the License, or (at your option) any later version.
|
| 12 |
+
|
| 13 |
+
This program is distributed in the hope that it will be useful,
|
| 14 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 15 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 16 |
+
GNU General Public License for more details.
|
| 17 |
+
|
| 18 |
+
You should have received a copy of the GNU General Public License
|
| 19 |
+
along with this program; if not, write to the Free Software
|
| 20 |
+
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
| 21 |
+
}
|
| 22 |
+
*/
|
| 23 |
+
|
| 24 |
+
#include "HorizonWidget.hpp"
|
| 25 |
+
#include "UIGlobals.hpp"
|
| 26 |
+
#include "Look/Look.hpp"
|
| 27 |
+
#include "Interface.hpp"
|
| 28 |
+
#include "Screen/AntiFlickerWindow.hpp"
|
| 29 |
+
#include "Screen/Canvas.hpp"
|
| 30 |
+
#include "Renderer/HorizonRenderer.hpp"
|
| 31 |
+
|
| 32 |
+
/**
|
| 33 |
+
* A Window which renders a terrain and airspace cross-section
|
| 34 |
+
*/
|
| 35 |
+
class HorizonWindow : public AntiFlickerWindow {
|
| 36 |
+
const HorizonLook &look;
|
| 37 |
+
|
| 38 |
+
AttitudeState attitude;
|
| 39 |
+
|
| 40 |
+
public:
|
| 41 |
+
/**
|
| 42 |
+
* Constructor. Initializes most class members.
|
| 43 |
+
*/
|
| 44 |
+
HorizonWindow(const HorizonLook &_look):look(_look) {
|
| 45 |
+
attitude.Reset();
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
void ReadBlackboard(const AttitudeState _attitude) {
|
| 49 |
+
attitude = _attitude;
|
| 50 |
+
Invalidate();
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
protected:
|
| 54 |
+
/* virtual methods from AntiFlickerWindow */
|
| 55 |
+
virtual void OnPaintBuffer(Canvas &canvas) override {
|
| 56 |
+
canvas.ClearWhite();
|
| 57 |
+
|
| 58 |
+
if (!CommonInterface::Basic().attitude.bank_angle_available &&
|
| 59 |
+
!CommonInterface::Basic().attitude.pitch_angle_available)
|
| 60 |
+
// TODO: paint "no data" hint
|
| 61 |
+
return;
|
| 62 |
+
|
| 63 |
+
HorizonRenderer::Draw(canvas, canvas.GetRect(), look, attitude);
|
| 64 |
+
}
|
| 65 |
+
};
|
| 66 |
+
|
| 67 |
+
void
|
| 68 |
+
HorizonWidget::Update(const MoreData &basic)
|
| 69 |
+
{
|
| 70 |
+
HorizonWindow &w = (HorizonWindow &)GetWindow();
|
| 71 |
+
w.ReadBlackboard(basic.attitude);
|
| 72 |
+
w.Invalidate();
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
void
|
| 76 |
+
HorizonWidget::Prepare(ContainerWindow &parent, const PixelRect &rc)
|
| 77 |
+
{
|
| 78 |
+
const Look &look = UIGlobals::GetLook();
|
| 79 |
+
|
| 80 |
+
WindowStyle style;
|
| 81 |
+
style.Hide();
|
| 82 |
+
style.Disable();
|
| 83 |
+
|
| 84 |
+
HorizonWindow *w = new HorizonWindow(look.horizon);
|
| 85 |
+
w->Create(parent, rc, style);
|
| 86 |
+
SetWindow(w);
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
void
|
| 90 |
+
HorizonWidget::Unprepare()
|
| 91 |
+
{
|
| 92 |
+
DeleteWindow();
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
void
|
| 96 |
+
HorizonWidget::Show(const PixelRect &rc)
|
| 97 |
+
{
|
| 98 |
+
Update(CommonInterface::Basic());
|
| 99 |
+
CommonInterface::GetLiveBlackboard().AddListener(*this);
|
| 100 |
+
|
| 101 |
+
WindowWidget::Show(rc);
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
void
|
| 105 |
+
HorizonWidget::Hide()
|
| 106 |
+
{
|
| 107 |
+
WindowWidget::Hide();
|
| 108 |
+
|
| 109 |
+
CommonInterface::GetLiveBlackboard().RemoveListener(*this);
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
void
|
| 113 |
+
HorizonWidget::OnGPSUpdate(const MoreData &basic)
|
| 114 |
+
{
|
| 115 |
+
Update(basic);
|
| 116 |
+
}
|
pool/shard002/C++/0024366_process_shield_symbolizer.cpp
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*****************************************************************************
|
| 2 |
+
*
|
| 3 |
+
* This file is part of Mapnik (c++ mapping toolkit)
|
| 4 |
+
*
|
| 5 |
+
* Copyright (C) 2015 Artem Pavlenko
|
| 6 |
+
*
|
| 7 |
+
* This library is free software; you can redistribute it and/or
|
| 8 |
+
* modify it under the terms of the GNU Lesser General Public
|
| 9 |
+
* License as published by the Free Software Foundation; either
|
| 10 |
+
* version 2.1 of the License, or (at your option) any later version.
|
| 11 |
+
*
|
| 12 |
+
* This library is distributed in the hope that it will be useful,
|
| 13 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 14 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 15 |
+
* Lesser General Public License for more details.
|
| 16 |
+
*
|
| 17 |
+
* You should have received a copy of the GNU Lesser General Public
|
| 18 |
+
* License along with this library; if not, write to the Free Software
|
| 19 |
+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 20 |
+
*
|
| 21 |
+
*****************************************************************************/
|
| 22 |
+
|
| 23 |
+
#if defined(GRID_RENDERER)
|
| 24 |
+
|
| 25 |
+
// mapnik
|
| 26 |
+
#include <mapnik/feature.hpp>
|
| 27 |
+
#include <mapnik/grid/grid_rasterizer.hpp>
|
| 28 |
+
#include <mapnik/grid/grid_renderer.hpp>
|
| 29 |
+
#include <mapnik/grid/grid_renderer_base.hpp>
|
| 30 |
+
#include <mapnik/grid/grid.hpp>
|
| 31 |
+
#include <mapnik/text/symbolizer_helpers.hpp>
|
| 32 |
+
#include <mapnik/pixel_position.hpp>
|
| 33 |
+
#include <mapnik/text/renderer.hpp>
|
| 34 |
+
#include <mapnik/text/glyph_positions.hpp>
|
| 35 |
+
|
| 36 |
+
#pragma GCC diagnostic push
|
| 37 |
+
#include <mapnik/warning_ignore_agg.hpp>
|
| 38 |
+
#include "agg_trans_affine.h"
|
| 39 |
+
#include "agg_gamma_functions.h"
|
| 40 |
+
#pragma GCC diagnostic pop
|
| 41 |
+
|
| 42 |
+
namespace mapnik {
|
| 43 |
+
|
| 44 |
+
template <typename T>
|
| 45 |
+
void grid_renderer<T>::process(shield_symbolizer const& sym,
|
| 46 |
+
mapnik::feature_impl & feature,
|
| 47 |
+
proj_transform const& prj_trans)
|
| 48 |
+
{
|
| 49 |
+
METRIC_UNUSED auto t = this->metrics_.measure_time("Grid_PShieldS");
|
| 50 |
+
agg::trans_affine tr;
|
| 51 |
+
auto transform = get_optional<transform_type>(sym, keys::geometry_transform);
|
| 52 |
+
if (transform) evaluate_transform(tr, feature, common_.vars_, *transform, common_.scale_factor_);
|
| 53 |
+
|
| 54 |
+
text_symbolizer_helper helper(
|
| 55 |
+
sym, feature, common_.vars_, prj_trans,
|
| 56 |
+
common_.width_, common_.height_,
|
| 57 |
+
common_.scale_factor_,
|
| 58 |
+
common_.t_, common_.font_manager_, *common_.detector_,
|
| 59 |
+
common_.query_extent_, tr);
|
| 60 |
+
bool placement_found = false;
|
| 61 |
+
|
| 62 |
+
composite_mode_e comp_op = get<composite_mode_e>(sym, keys::comp_op, feature, common_.vars_, src_over);
|
| 63 |
+
double opacity = get<double>(sym, keys::opacity, feature, common_.vars_, 1.0);
|
| 64 |
+
|
| 65 |
+
grid_text_renderer<T> ren(pixmap_,
|
| 66 |
+
comp_op,
|
| 67 |
+
common_.scale_factor_);
|
| 68 |
+
|
| 69 |
+
placements_list const& placements = helper.get();
|
| 70 |
+
value_integer feature_id = feature.id();
|
| 71 |
+
|
| 72 |
+
for (auto const& glyphs : placements)
|
| 73 |
+
{
|
| 74 |
+
marker_info_ptr mark = glyphs->get_marker();
|
| 75 |
+
if (mark)
|
| 76 |
+
{
|
| 77 |
+
render_marker(feature,
|
| 78 |
+
glyphs->marker_pos(),
|
| 79 |
+
*mark->marker_,
|
| 80 |
+
mark->transform_,
|
| 81 |
+
opacity, comp_op);
|
| 82 |
+
}
|
| 83 |
+
ren.render(*glyphs, feature_id);
|
| 84 |
+
placement_found = true;
|
| 85 |
+
}
|
| 86 |
+
if (placement_found)
|
| 87 |
+
{
|
| 88 |
+
pixmap_.add_feature(feature);
|
| 89 |
+
}
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
template void grid_renderer<grid>::process(shield_symbolizer const&,
|
| 93 |
+
mapnik::feature_impl &,
|
| 94 |
+
proj_transform const&);
|
| 95 |
+
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
#endif
|
pool/shard002/C++/0024368_colorsource.cpp
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
//
|
| 3 |
+
// This source file is part of appleseed.
|
| 4 |
+
// Visit https://appleseedhq.net/ for additional information and resources.
|
| 5 |
+
//
|
| 6 |
+
// This software is released under the MIT license.
|
| 7 |
+
//
|
| 8 |
+
// Copyright (c) 2010-2013 Francois Beaune, Jupiter Jazz Limited
|
| 9 |
+
// Copyright (c) 2014-2018 Francois Beaune, The appleseedhq Organization
|
| 10 |
+
//
|
| 11 |
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 12 |
+
// of this software and associated documentation files (the "Software"), to deal
|
| 13 |
+
// in the Software without restriction, including without limitation the rights
|
| 14 |
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 15 |
+
// copies of the Software, and to permit persons to whom the Software is
|
| 16 |
+
// furnished to do so, subject to the following conditions:
|
| 17 |
+
//
|
| 18 |
+
// The above copyright notice and this permission notice shall be included in
|
| 19 |
+
// all copies or substantial portions of the Software.
|
| 20 |
+
//
|
| 21 |
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 22 |
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 23 |
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 24 |
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 25 |
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 26 |
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 27 |
+
// THE SOFTWARE.
|
| 28 |
+
//
|
| 29 |
+
|
| 30 |
+
// Interface header.
|
| 31 |
+
#include "colorsource.h"
|
| 32 |
+
|
| 33 |
+
// appleseed.renderer headers.
|
| 34 |
+
#include "renderer/modeling/color/colorentity.h"
|
| 35 |
+
#include "renderer/modeling/color/colorspace.h"
|
| 36 |
+
#include "renderer/modeling/color/wavelengths.h"
|
| 37 |
+
#include "renderer/modeling/entity/entity.h"
|
| 38 |
+
|
| 39 |
+
// appleseed.foundation headers.
|
| 40 |
+
#include "foundation/image/colorspace.h"
|
| 41 |
+
#include "foundation/image/regularspectrum.h"
|
| 42 |
+
#include "foundation/utility/api/specializedapiarrays.h"
|
| 43 |
+
|
| 44 |
+
// Standard headers.
|
| 45 |
+
#include <cassert>
|
| 46 |
+
|
| 47 |
+
using namespace foundation;
|
| 48 |
+
|
| 49 |
+
namespace renderer
|
| 50 |
+
{
|
| 51 |
+
|
| 52 |
+
//
|
| 53 |
+
// ColorSource class implementation.
|
| 54 |
+
//
|
| 55 |
+
|
| 56 |
+
ColorSource::ColorSource(const ColorEntity& color_entity)
|
| 57 |
+
: Source(true)
|
| 58 |
+
, m_color_entity(color_entity)
|
| 59 |
+
{
|
| 60 |
+
// Retrieve the color values.
|
| 61 |
+
if (color_entity.get_color_space() == ColorSpaceSpectral)
|
| 62 |
+
initialize_from_spectrum(color_entity);
|
| 63 |
+
else initialize_from_color3(color_entity);
|
| 64 |
+
|
| 65 |
+
// Apply the multiplier to the color values.
|
| 66 |
+
const float multiplier = color_entity.get_multiplier();
|
| 67 |
+
m_scalar *= multiplier;
|
| 68 |
+
m_linear_rgb *= multiplier;
|
| 69 |
+
m_spectrum *= multiplier;
|
| 70 |
+
|
| 71 |
+
// Store the alpha values.
|
| 72 |
+
// In the case of multiple alpha values, we keep the first one.
|
| 73 |
+
const ColorValueArray& alpha = color_entity.get_alpha();
|
| 74 |
+
m_alpha[0] = alpha.size() >= 1 ? alpha[0] : 0.0f;
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
std::uint64_t ColorSource::compute_signature() const
|
| 78 |
+
{
|
| 79 |
+
return m_color_entity.compute_signature();
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
ColorSource::Hints ColorSource::get_hints() const
|
| 83 |
+
{
|
| 84 |
+
Hints hints;
|
| 85 |
+
hints.m_width = 1;
|
| 86 |
+
hints.m_height = 1;
|
| 87 |
+
return hints;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
void ColorSource::initialize_from_spectrum(const ColorEntity& color_entity)
|
| 91 |
+
{
|
| 92 |
+
const ColorValueArray& values = color_entity.get_values();
|
| 93 |
+
|
| 94 |
+
if (values.empty())
|
| 95 |
+
{
|
| 96 |
+
m_scalar = 0.0f;
|
| 97 |
+
m_linear_rgb.set(0.0f);
|
| 98 |
+
m_spectrum.set(0.0f);
|
| 99 |
+
return;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
m_scalar = values[0];
|
| 103 |
+
|
| 104 |
+
RegularSpectrum31f s;
|
| 105 |
+
spectral_values_to_spectrum(
|
| 106 |
+
color_entity.get_wavelength_range()[0],
|
| 107 |
+
color_entity.get_wavelength_range()[1],
|
| 108 |
+
values.size(),
|
| 109 |
+
&values[0],
|
| 110 |
+
s);
|
| 111 |
+
|
| 112 |
+
m_linear_rgb =
|
| 113 |
+
ciexyz_to_linear_rgb(
|
| 114 |
+
spectrum_to_ciexyz<float>(g_std_lighting_conditions, s));
|
| 115 |
+
|
| 116 |
+
m_spectrum.set(s, g_std_lighting_conditions, Spectrum::Reflectance);
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
void ColorSource::initialize_from_color3(const ColorEntity& color_entity)
|
| 120 |
+
{
|
| 121 |
+
Color3f color;
|
| 122 |
+
|
| 123 |
+
const ColorValueArray& values = color_entity.get_values();
|
| 124 |
+
if (values.size() == 1)
|
| 125 |
+
color.set(values[0]);
|
| 126 |
+
else if (values.size() == 3)
|
| 127 |
+
color = Color3f(values[0], values[1], values[2]);
|
| 128 |
+
else
|
| 129 |
+
{
|
| 130 |
+
m_scalar = 0.0f;
|
| 131 |
+
m_linear_rgb.set(0.0f);
|
| 132 |
+
m_spectrum.set(0.0f);
|
| 133 |
+
return;
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
m_scalar = color[0];
|
| 137 |
+
|
| 138 |
+
switch (color_entity.get_color_space())
|
| 139 |
+
{
|
| 140 |
+
case ColorSpaceLinearRGB:
|
| 141 |
+
m_linear_rgb = color;
|
| 142 |
+
break;
|
| 143 |
+
|
| 144 |
+
case ColorSpaceSRGB:
|
| 145 |
+
m_linear_rgb = fast_srgb_to_linear_rgb(color);
|
| 146 |
+
break;
|
| 147 |
+
|
| 148 |
+
case ColorSpaceCIEXYZ:
|
| 149 |
+
m_linear_rgb = ciexyz_to_linear_rgb(color);
|
| 150 |
+
break;
|
| 151 |
+
|
| 152 |
+
default:
|
| 153 |
+
assert(!"Invalid color space.");
|
| 154 |
+
break;
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
m_spectrum.set(m_linear_rgb, g_std_lighting_conditions, Spectrum::Reflectance);
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
} // namespace renderer
|
pool/shard002/C++/0024375_qgsfeaturelistviewdelegate.cpp
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/***************************************************************************
|
| 2 |
+
qgsfeaturelistviewdelegate.cpp
|
| 3 |
+
---------------------
|
| 4 |
+
begin : February 2013
|
| 5 |
+
copyright : (C) 2013 by Matthias Kuhn
|
| 6 |
+
email : matthias at opengis dot ch
|
| 7 |
+
***************************************************************************
|
| 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 |
+
***************************************************************************/
|
| 15 |
+
#include "qgsfeaturelistviewdelegate.h"
|
| 16 |
+
#include "qgsvectorlayer.h"
|
| 17 |
+
#include "qgsattributetablemodel.h"
|
| 18 |
+
#include "qgsfeaturelistmodel.h"
|
| 19 |
+
#include "qgsapplication.h"
|
| 20 |
+
#include "qgsvectorlayereditbuffer.h"
|
| 21 |
+
#include "qgsfeatureselectionmodel.h"
|
| 22 |
+
|
| 23 |
+
#include <QHBoxLayout>
|
| 24 |
+
#include <QPushButton>
|
| 25 |
+
#include <QLabel>
|
| 26 |
+
#include <QApplication>
|
| 27 |
+
#include <QMouseEvent>
|
| 28 |
+
#include <QObject>
|
| 29 |
+
|
| 30 |
+
QgsFeatureListViewDelegate::QgsFeatureListViewDelegate( QgsFeatureListModel *listModel, QObject *parent )
|
| 31 |
+
: QItemDelegate( parent )
|
| 32 |
+
, mListModel( listModel )
|
| 33 |
+
, mCurrentFeatureEdited( false )
|
| 34 |
+
{
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
QgsFeatureListViewDelegate::Element QgsFeatureListViewDelegate::positionToElement( QPoint pos )
|
| 38 |
+
{
|
| 39 |
+
if ( pos.x() > ICON_SIZE )
|
| 40 |
+
{
|
| 41 |
+
return EditElement;
|
| 42 |
+
}
|
| 43 |
+
else
|
| 44 |
+
{
|
| 45 |
+
return SelectionElement;
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
void QgsFeatureListViewDelegate::setFeatureSelectionModel( QgsFeatureSelectionModel *featureSelectionModel )
|
| 50 |
+
{
|
| 51 |
+
mFeatureSelectionModel = featureSelectionModel;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
void QgsFeatureListViewDelegate::setCurrentFeatureEdited( bool state )
|
| 55 |
+
{
|
| 56 |
+
mCurrentFeatureEdited = state;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
void QgsFeatureListViewDelegate::setEditSelectionModel( QItemSelectionModel *editSelectionModel )
|
| 60 |
+
{
|
| 61 |
+
mEditSelectionModel = editSelectionModel;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
QSize QgsFeatureListViewDelegate::sizeHint( const QStyleOptionViewItem &option, const QModelIndex &index ) const
|
| 65 |
+
{
|
| 66 |
+
Q_UNUSED( index )
|
| 67 |
+
int height = ICON_SIZE;
|
| 68 |
+
return QSize( option.rect.width(), std::max( height, option.fontMetrics.height() ) );
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
void QgsFeatureListViewDelegate::paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const
|
| 72 |
+
{
|
| 73 |
+
const bool isEditSelection = mEditSelectionModel && mEditSelectionModel->isSelected( mListModel->mapToMaster( index ) );
|
| 74 |
+
|
| 75 |
+
QStyleOptionViewItem textOption = option;
|
| 76 |
+
textOption.state |= QStyle::State_Enabled;
|
| 77 |
+
if ( isEditSelection )
|
| 78 |
+
{
|
| 79 |
+
textOption.state |= QStyle::State_Selected;
|
| 80 |
+
}
|
| 81 |
+
drawBackground( painter, textOption, index );
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
static QPixmap sSelectedIcon;
|
| 85 |
+
if ( sSelectedIcon.isNull() )
|
| 86 |
+
sSelectedIcon = QgsApplication::getThemePixmap( QStringLiteral( "/mIconSelected.svg" ) );
|
| 87 |
+
static QPixmap sDeselectedIcon;
|
| 88 |
+
if ( sDeselectedIcon.isNull() )
|
| 89 |
+
sDeselectedIcon = QgsApplication::getThemePixmap( QStringLiteral( "/mIconDeselected.svg" ) );
|
| 90 |
+
|
| 91 |
+
QString text = index.model()->data( index, Qt::EditRole ).toString();
|
| 92 |
+
QgsFeatureListModel::FeatureInfo featInfo = index.model()->data( index, Qt::UserRole ).value<QgsFeatureListModel::FeatureInfo>();
|
| 93 |
+
|
| 94 |
+
// Icon layout options
|
| 95 |
+
QStyleOptionViewItem iconOption;
|
| 96 |
+
|
| 97 |
+
QRect iconLayoutBounds( option.rect.x(), option.rect.y(), option.rect.height(), option.rect.height() );
|
| 98 |
+
|
| 99 |
+
QPixmap icon = mFeatureSelectionModel->isSelected( index ) ? sSelectedIcon : sDeselectedIcon;
|
| 100 |
+
|
| 101 |
+
// Scale up the icon if needed
|
| 102 |
+
if ( option.rect.height() > ICON_SIZE )
|
| 103 |
+
{
|
| 104 |
+
icon = icon.scaledToHeight( option.rect.height(), Qt::SmoothTransformation );
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
drawDecoration( painter, iconOption, iconLayoutBounds, icon );
|
| 108 |
+
|
| 109 |
+
// if conditional style also has an icon, draw that too
|
| 110 |
+
const QVariant conditionalIcon = index.model()->data( index, Qt::DecorationRole );
|
| 111 |
+
if ( conditionalIcon.isValid() )
|
| 112 |
+
{
|
| 113 |
+
const QPixmap pixmap = conditionalIcon.value< QPixmap >();
|
| 114 |
+
iconLayoutBounds.moveLeft( iconLayoutBounds.x() + icon.width() + QFontMetrics( textOption.font ).width( 'X' ) );
|
| 115 |
+
iconLayoutBounds.setTop( option.rect.y() + ( option.rect.height() - pixmap.height() ) / 2.0 );
|
| 116 |
+
iconLayoutBounds.setHeight( pixmap.height() );
|
| 117 |
+
drawDecoration( painter, iconOption, iconLayoutBounds, pixmap );
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
// Text layout options
|
| 121 |
+
QRect textLayoutBounds( iconLayoutBounds.x() + iconLayoutBounds.width(), option.rect.y(), option.rect.width() - ( iconLayoutBounds.x() + iconLayoutBounds.width() ), option.rect.height() );
|
| 122 |
+
|
| 123 |
+
// start with font and foreground color from model's FontRole
|
| 124 |
+
const QVariant font = index.model()->data( index, Qt::FontRole );
|
| 125 |
+
if ( font.isValid() )
|
| 126 |
+
{
|
| 127 |
+
textOption.font = font.value< QFont >();
|
| 128 |
+
}
|
| 129 |
+
const QVariant textColor = index.model()->data( index, Qt::TextColorRole );
|
| 130 |
+
if ( textColor.isValid() )
|
| 131 |
+
{
|
| 132 |
+
textOption.palette.setColor( QPalette::Text, textColor.value< QColor >() );
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
if ( featInfo.isNew )
|
| 136 |
+
{
|
| 137 |
+
textOption.font.setStyle( QFont::StyleItalic );
|
| 138 |
+
textOption.palette.setColor( QPalette::Text, Qt::darkGreen );
|
| 139 |
+
textOption.palette.setColor( QPalette::HighlightedText, Qt::darkGreen );
|
| 140 |
+
}
|
| 141 |
+
else if ( featInfo.isEdited || ( mCurrentFeatureEdited && isEditSelection ) )
|
| 142 |
+
{
|
| 143 |
+
textOption.font.setStyle( QFont::StyleItalic );
|
| 144 |
+
textOption.palette.setColor( QPalette::Text, Qt::red );
|
| 145 |
+
textOption.palette.setColor( QPalette::HighlightedText, Qt::red );
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
drawDisplay( painter, textOption, textLayoutBounds, text );
|
| 149 |
+
}
|
pool/shard002/C++/0024381_sample_activity.cc
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2014 The Chromium Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style license that can be
|
| 3 |
+
// found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
#include "athena/test/base/sample_activity.h"
|
| 6 |
+
|
| 7 |
+
#include "athena/input/public/accelerator_manager.h"
|
| 8 |
+
#include "ui/gfx/image/image_skia.h"
|
| 9 |
+
#include "ui/views/background.h"
|
| 10 |
+
#include "ui/views/view.h"
|
| 11 |
+
#include "ui/views/widget/widget.h"
|
| 12 |
+
|
| 13 |
+
namespace athena {
|
| 14 |
+
namespace test {
|
| 15 |
+
|
| 16 |
+
SampleActivity::SampleActivity(SkColor color,
|
| 17 |
+
SkColor contents_color,
|
| 18 |
+
const base::string16& title)
|
| 19 |
+
: color_(color),
|
| 20 |
+
contents_color_(contents_color),
|
| 21 |
+
title_(title),
|
| 22 |
+
contents_view_(nullptr),
|
| 23 |
+
current_state_(ACTIVITY_UNLOADED) {
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
SampleActivity::~SampleActivity() {
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
athena::ActivityViewModel* SampleActivity::GetActivityViewModel() {
|
| 30 |
+
return this;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
void SampleActivity::SetCurrentState(Activity::ActivityState state) {
|
| 34 |
+
current_state_ = state;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
Activity::ActivityState SampleActivity::GetCurrentState() {
|
| 38 |
+
return current_state_;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
bool SampleActivity::IsVisible() {
|
| 42 |
+
return contents_view_ && contents_view_->IsDrawn();
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
Activity::ActivityMediaState SampleActivity::GetMediaState() {
|
| 46 |
+
return Activity::ACTIVITY_MEDIA_STATE_NONE;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
aura::Window* SampleActivity::GetWindow() {
|
| 50 |
+
return !contents_view_ ? nullptr
|
| 51 |
+
: contents_view_->GetWidget()->GetNativeWindow();
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
content::WebContents* SampleActivity::GetWebContents() {
|
| 55 |
+
return nullptr;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
void SampleActivity::Init() {
|
| 59 |
+
accelerator_manager_ = AcceleratorManager::CreateForFocusManager(
|
| 60 |
+
GetContentsView()->GetWidget()->GetFocusManager());
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
SkColor SampleActivity::GetRepresentativeColor() const {
|
| 64 |
+
return color_;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
base::string16 SampleActivity::GetTitle() const {
|
| 68 |
+
return title_;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
gfx::ImageSkia SampleActivity::GetIcon() const {
|
| 72 |
+
return gfx::ImageSkia();
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
void SampleActivity::SetActivityView(ActivityView* view) {
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
bool SampleActivity::UsesFrame() const {
|
| 79 |
+
return true;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
views::View* SampleActivity::GetContentsView() {
|
| 83 |
+
if (!contents_view_) {
|
| 84 |
+
contents_view_ = new views::View;
|
| 85 |
+
contents_view_->set_background(
|
| 86 |
+
views::Background::CreateSolidBackground(contents_color_));
|
| 87 |
+
}
|
| 88 |
+
return contents_view_;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
gfx::ImageSkia SampleActivity::GetOverviewModeImage() {
|
| 92 |
+
return gfx::ImageSkia();
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
void SampleActivity::PrepareContentsForOverview() {
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
void SampleActivity::ResetContentsView() {
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
} // namespace test
|
| 102 |
+
} // namespace athena
|
pool/shard002/C++/0024388_727A.cpp
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <stdio.h>
|
| 2 |
+
#include <queue>
|
| 3 |
+
#include <map>
|
| 4 |
+
#include <algorithm>
|
| 5 |
+
using namespace std;
|
| 6 |
+
queue <int> q;
|
| 7 |
+
map <int,int> pre;
|
| 8 |
+
int a,b;
|
| 9 |
+
int main()
|
| 10 |
+
{
|
| 11 |
+
scanf("%d%d",&a,&b);
|
| 12 |
+
q.push(b);
|
| 13 |
+
while(!q.empty())
|
| 14 |
+
{
|
| 15 |
+
int x=q.front();
|
| 16 |
+
q.pop();
|
| 17 |
+
if(x==0)
|
| 18 |
+
break;
|
| 19 |
+
if(x==a)
|
| 20 |
+
break;
|
| 21 |
+
if(x%10==1)
|
| 22 |
+
q.push(x/10),pre[x/10]=x;
|
| 23 |
+
if(x%2==0)
|
| 24 |
+
q.push(x/2),pre[x/2]=x;
|
| 25 |
+
}
|
| 26 |
+
if(pre[a])
|
| 27 |
+
{
|
| 28 |
+
puts("YES");
|
| 29 |
+
int cnt=0;
|
| 30 |
+
for(int i=a;i!=b;i=pre[i])
|
| 31 |
+
++cnt;
|
| 32 |
+
++cnt;
|
| 33 |
+
printf("%d\n",cnt);
|
| 34 |
+
for(int i=a;i!=b;i=pre[i])
|
| 35 |
+
printf("%d ",i);
|
| 36 |
+
printf("%d\n",b);
|
| 37 |
+
}
|
| 38 |
+
else
|
| 39 |
+
puts("NO");
|
| 40 |
+
}
|
pool/shard002/C++/0024389_cxxhello.cc
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// -*- c++ -*-
|
| 2 |
+
//
|
| 3 |
+
// $Id: cxxhello.cc,v 1.1 2002/10/31 00:01:19 mchasal Exp $
|
| 4 |
+
//
|
| 5 |
+
// $COPYRIGHT$
|
| 6 |
+
//
|
| 7 |
+
|
| 8 |
+
#include <iostream>
|
| 9 |
+
#include "mpi.h"
|
| 10 |
+
|
| 11 |
+
using namespace std;
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
int
|
| 15 |
+
main(int argc, char *argv[])
|
| 16 |
+
{
|
| 17 |
+
MPI::Init(argc, argv);
|
| 18 |
+
|
| 19 |
+
int rank = MPI::COMM_WORLD.Get_rank();
|
| 20 |
+
int size = MPI::COMM_WORLD.Get_size();
|
| 21 |
+
|
| 22 |
+
cout << "Hello World! I am " << rank << " of " << size << endl;
|
| 23 |
+
|
| 24 |
+
MPI::Finalize();
|
| 25 |
+
return 0;
|
| 26 |
+
}
|
pool/shard002/C++/0024396_FakeGPIO.cpp
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Copyright (C) 2014-2016 Leosac
|
| 3 |
+
|
| 4 |
+
This file is part of Leosac.
|
| 5 |
+
|
| 6 |
+
Leosac is free software: you can redistribute it and/or modify
|
| 7 |
+
it under the terms of the GNU Affero 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 |
+
Leosac 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 Affero General Public License for more details.
|
| 15 |
+
|
| 16 |
+
You should have received a copy of the GNU Affero General Public License
|
| 17 |
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#include "FakeGPIO.hpp"
|
| 21 |
+
|
| 22 |
+
using namespace Leosac::Test::Helper;
|
| 23 |
+
|
| 24 |
+
FakeGPIO::FakeGPIO(zmqpp::context &ctx, const std::string &name)
|
| 25 |
+
: ctx_(ctx)
|
| 26 |
+
, name_(name)
|
| 27 |
+
, push_(ctx, zmqpp::socket_type::push)
|
| 28 |
+
, rep_(ctx, zmqpp::socket_type::rep)
|
| 29 |
+
, value_(false)
|
| 30 |
+
{
|
| 31 |
+
push_.connect("inproc://zmq-bus-pull");
|
| 32 |
+
rep_.bind("inproc://" + name);
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
void FakeGPIO::interrupt()
|
| 36 |
+
{
|
| 37 |
+
push_.send("S_INT:" + name_);
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
bool FakeGPIO::run(zmqpp::socket *pipe)
|
| 41 |
+
{
|
| 42 |
+
zmqpp::poller poller;
|
| 43 |
+
|
| 44 |
+
poller.add(*pipe);
|
| 45 |
+
poller.add(rep_);
|
| 46 |
+
|
| 47 |
+
pipe->send(zmqpp::signal::ok);
|
| 48 |
+
|
| 49 |
+
while (true)
|
| 50 |
+
{
|
| 51 |
+
poller.poll(-1);
|
| 52 |
+
if (poller.has_input(*pipe))
|
| 53 |
+
break;
|
| 54 |
+
|
| 55 |
+
if (poller.has_input(rep_))
|
| 56 |
+
{
|
| 57 |
+
handle_cmd();
|
| 58 |
+
}
|
| 59 |
+
}
|
| 60 |
+
return true;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
void FakeGPIO::handle_cmd()
|
| 64 |
+
{
|
| 65 |
+
zmqpp::message_t msg;
|
| 66 |
+
std::string frame1;
|
| 67 |
+
rep_.receive(msg);
|
| 68 |
+
|
| 69 |
+
msg >> frame1;
|
| 70 |
+
if (frame1 == "ON")
|
| 71 |
+
value_ = true;
|
| 72 |
+
else if (frame1 == "OFF")
|
| 73 |
+
value_ = false;
|
| 74 |
+
else if (frame1 == "TOGGLE")
|
| 75 |
+
value_ = !value_;
|
| 76 |
+
else if (frame1 == "STATE")
|
| 77 |
+
return send_state();
|
| 78 |
+
else
|
| 79 |
+
assert(0);
|
| 80 |
+
|
| 81 |
+
push_.send(zmqpp::message() << ("S_" + name_) << (value_ ? "ON" : "OFF"));
|
| 82 |
+
rep_.send("OK");
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
void FakeGPIO::send_state()
|
| 86 |
+
{
|
| 87 |
+
rep_.send((value_ ? "ON" : "OFF"));
|
| 88 |
+
}
|
pool/shard002/C++/0024397_main.cpp
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <iostream>
|
| 2 |
+
#include <algorithm>
|
| 3 |
+
#include <string>
|
| 4 |
+
#include <iomanip>
|
| 5 |
+
using namespace std;
|
| 6 |
+
|
| 7 |
+
int main()
|
| 8 |
+
{
|
| 9 |
+
string s;
|
| 10 |
+
while(cin >> s && s != "#")
|
| 11 |
+
{
|
| 12 |
+
string ss = s;
|
| 13 |
+
sort(ss.begin(),ss.end());
|
| 14 |
+
int counts = 1;
|
| 15 |
+
do
|
| 16 |
+
{
|
| 17 |
+
//cout << ss << " " << s <<endl;
|
| 18 |
+
if(ss == s)
|
| 19 |
+
{
|
| 20 |
+
cout << std::setw(10);
|
| 21 |
+
cout << counts <<endl;
|
| 22 |
+
break;
|
| 23 |
+
}
|
| 24 |
+
counts++;
|
| 25 |
+
}while(next_permutation(ss.begin(),ss.end()));
|
| 26 |
+
}
|
| 27 |
+
return 0;
|
| 28 |
+
}
|
pool/shard002/C++/0024399_supervised_user_manager_impl.cc
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2014 The Chromium Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style license that can be
|
| 3 |
+
// found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
#include "chrome/browser/ash/login/users/supervised_user_manager_impl.h"
|
| 6 |
+
|
| 7 |
+
#include <memory>
|
| 8 |
+
|
| 9 |
+
#include "ash/components/settings/cros_settings_names.h"
|
| 10 |
+
#include "base/bind.h"
|
| 11 |
+
#include "base/strings/string_util.h"
|
| 12 |
+
#include "base/strings/utf_string_conversions.h"
|
| 13 |
+
#include "base/values.h"
|
| 14 |
+
#include "chrome/browser/ash/login/users/chrome_user_manager_impl.h"
|
| 15 |
+
#include "chrome/browser/ash/settings/cros_settings.h"
|
| 16 |
+
#include "chrome/browser/browser_process.h"
|
| 17 |
+
#include "components/prefs/pref_registry_simple.h"
|
| 18 |
+
#include "components/prefs/pref_service.h"
|
| 19 |
+
#include "components/prefs/scoped_user_pref_update.h"
|
| 20 |
+
#include "components/user_manager/user_type.h"
|
| 21 |
+
#include "content/public/browser/browser_thread.h"
|
| 22 |
+
#include "google_apis/gaia/gaia_auth_util.h"
|
| 23 |
+
#include "third_party/abseil-cpp/absl/types/optional.h"
|
| 24 |
+
|
| 25 |
+
using content::BrowserThread;
|
| 26 |
+
|
| 27 |
+
namespace {
|
| 28 |
+
|
| 29 |
+
// Names for pref keys in Local State.
|
| 30 |
+
// A map from supervised user local user id to sync user id.
|
| 31 |
+
const char kSupervisedUserSyncId[] = "ManagedUserSyncId";
|
| 32 |
+
|
| 33 |
+
// A map from supervised user id to manager user id.
|
| 34 |
+
const char kSupervisedUserManagers[] = "ManagedUserManagers";
|
| 35 |
+
|
| 36 |
+
// A map from supervised user id to manager display name.
|
| 37 |
+
const char kSupervisedUserManagerNames[] = "ManagedUserManagerNames";
|
| 38 |
+
|
| 39 |
+
// A map from supervised user id to manager display e-mail.
|
| 40 |
+
const char kSupervisedUserManagerDisplayEmails[] =
|
| 41 |
+
"ManagedUserManagerDisplayEmails";
|
| 42 |
+
|
| 43 |
+
// A vector pref of the supervised accounts defined on this device, that had
|
| 44 |
+
// not logged in yet.
|
| 45 |
+
const char kSupervisedUsersFirstRun[] = "LocallyManagedUsersFirstRun";
|
| 46 |
+
|
| 47 |
+
// A map from user id to password schema id.
|
| 48 |
+
const char kSupervisedUserPasswordSchema[] = "SupervisedUserPasswordSchema";
|
| 49 |
+
|
| 50 |
+
// A map from user id to password salt.
|
| 51 |
+
const char kSupervisedUserPasswordSalt[] = "SupervisedUserPasswordSalt";
|
| 52 |
+
|
| 53 |
+
// A map from user id to password revision.
|
| 54 |
+
const char kSupervisedUserPasswordRevision[] = "SupervisedUserPasswordRevision";
|
| 55 |
+
|
| 56 |
+
// A map from user id to flag indicating if password should be updated upon
|
| 57 |
+
// signin.
|
| 58 |
+
const char kSupervisedUserNeedPasswordUpdate[] =
|
| 59 |
+
"SupervisedUserNeedPasswordUpdate";
|
| 60 |
+
|
| 61 |
+
// A map from user id to flag indicating if cryptohome does not have signature
|
| 62 |
+
// key.
|
| 63 |
+
const char kSupervisedUserIncompleteKey[] = "SupervisedUserHasIncompleteKey";
|
| 64 |
+
|
| 65 |
+
} // namespace
|
| 66 |
+
|
| 67 |
+
namespace ash {
|
| 68 |
+
|
| 69 |
+
const char kSchemaVersion[] = "SchemaVersion";
|
| 70 |
+
const char kPasswordRevision[] = "PasswordRevision";
|
| 71 |
+
const char kSalt[] = "PasswordSalt";
|
| 72 |
+
const char kRequirePasswordUpdate[] = "RequirePasswordUpdate";
|
| 73 |
+
const char kHasIncompleteKey[] = "HasIncompleteKey";
|
| 74 |
+
|
| 75 |
+
// static
|
| 76 |
+
void SupervisedUserManager::RegisterLocalStatePrefs(
|
| 77 |
+
PrefRegistrySimple* registry) {
|
| 78 |
+
registry->RegisterListPref(kSupervisedUsersFirstRun);
|
| 79 |
+
registry->RegisterDictionaryPref(kSupervisedUserSyncId);
|
| 80 |
+
registry->RegisterDictionaryPref(kSupervisedUserManagers);
|
| 81 |
+
registry->RegisterDictionaryPref(kSupervisedUserManagerNames);
|
| 82 |
+
registry->RegisterDictionaryPref(kSupervisedUserManagerDisplayEmails);
|
| 83 |
+
|
| 84 |
+
registry->RegisterDictionaryPref(kSupervisedUserPasswordSchema);
|
| 85 |
+
registry->RegisterDictionaryPref(kSupervisedUserPasswordSalt);
|
| 86 |
+
registry->RegisterDictionaryPref(kSupervisedUserPasswordRevision);
|
| 87 |
+
|
| 88 |
+
registry->RegisterDictionaryPref(kSupervisedUserNeedPasswordUpdate);
|
| 89 |
+
registry->RegisterDictionaryPref(kSupervisedUserIncompleteKey);
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
SupervisedUserManagerImpl::SupervisedUserManagerImpl(
|
| 93 |
+
ChromeUserManagerImpl* owner)
|
| 94 |
+
: owner_(owner), cros_settings_(CrosSettings::Get()) {
|
| 95 |
+
// SupervisedUserManager instance should be used only on UI thread.
|
| 96 |
+
// (or in unit_tests)
|
| 97 |
+
if (base::ThreadTaskRunnerHandle::IsSet())
|
| 98 |
+
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
SupervisedUserManagerImpl::~SupervisedUserManagerImpl() {}
|
| 102 |
+
|
| 103 |
+
std::string SupervisedUserManagerImpl::GetUserSyncId(
|
| 104 |
+
const std::string& user_id) const {
|
| 105 |
+
std::string result;
|
| 106 |
+
GetUserStringValue(user_id, kSupervisedUserSyncId, &result);
|
| 107 |
+
return result;
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
std::u16string SupervisedUserManagerImpl::GetManagerDisplayName(
|
| 111 |
+
const std::string& user_id) const {
|
| 112 |
+
PrefService* local_state = g_browser_process->local_state();
|
| 113 |
+
const base::Value* manager_names =
|
| 114 |
+
local_state->GetDictionary(kSupervisedUserManagerNames);
|
| 115 |
+
const std::string* result = manager_names->FindStringKey(user_id);
|
| 116 |
+
if (result && !result->empty())
|
| 117 |
+
return base::UTF8ToUTF16(*result);
|
| 118 |
+
return base::UTF8ToUTF16(GetManagerDisplayEmail(user_id));
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
std::string SupervisedUserManagerImpl::GetManagerUserId(
|
| 122 |
+
const std::string& user_id) const {
|
| 123 |
+
std::string result;
|
| 124 |
+
GetUserStringValue(user_id, kSupervisedUserManagers, &result);
|
| 125 |
+
return result;
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
std::string SupervisedUserManagerImpl::GetManagerDisplayEmail(
|
| 129 |
+
const std::string& user_id) const {
|
| 130 |
+
std::string result;
|
| 131 |
+
if (GetUserStringValue(user_id, kSupervisedUserManagerDisplayEmails,
|
| 132 |
+
&result) &&
|
| 133 |
+
!result.empty())
|
| 134 |
+
return result;
|
| 135 |
+
return GetManagerUserId(user_id);
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
void SupervisedUserManagerImpl::GetPasswordInformation(
|
| 139 |
+
const std::string& user_id,
|
| 140 |
+
base::DictionaryValue* result) {
|
| 141 |
+
int value;
|
| 142 |
+
if (GetUserIntegerValue(user_id, kSupervisedUserPasswordSchema, &value))
|
| 143 |
+
result->SetKey(kSchemaVersion, base::Value(value));
|
| 144 |
+
if (GetUserIntegerValue(user_id, kSupervisedUserPasswordRevision, &value))
|
| 145 |
+
result->SetKey(kPasswordRevision, base::Value(value));
|
| 146 |
+
|
| 147 |
+
bool flag;
|
| 148 |
+
if (GetUserBooleanValue(user_id, kSupervisedUserNeedPasswordUpdate, &flag))
|
| 149 |
+
result->SetKey(kRequirePasswordUpdate, base::Value(flag));
|
| 150 |
+
if (GetUserBooleanValue(user_id, kSupervisedUserIncompleteKey, &flag))
|
| 151 |
+
result->SetKey(kHasIncompleteKey, base::Value(flag));
|
| 152 |
+
|
| 153 |
+
std::string salt;
|
| 154 |
+
if (GetUserStringValue(user_id, kSupervisedUserPasswordSalt, &salt))
|
| 155 |
+
result->SetKey(kSalt, base::Value(salt));
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
void SupervisedUserManagerImpl::SetPasswordInformation(
|
| 159 |
+
const std::string& user_id,
|
| 160 |
+
const base::DictionaryValue* password_info) {
|
| 161 |
+
absl::optional<int> schema_version =
|
| 162 |
+
password_info->FindIntKey(kSchemaVersion);
|
| 163 |
+
if (schema_version.has_value())
|
| 164 |
+
SetUserIntegerValue(user_id, kSupervisedUserPasswordSchema,
|
| 165 |
+
schema_version.value());
|
| 166 |
+
absl::optional<int> password_revision =
|
| 167 |
+
password_info->FindIntKey(kPasswordRevision);
|
| 168 |
+
if (password_revision.has_value())
|
| 169 |
+
SetUserIntegerValue(user_id, kSupervisedUserPasswordRevision,
|
| 170 |
+
password_revision.value());
|
| 171 |
+
|
| 172 |
+
absl::optional<bool> flag =
|
| 173 |
+
password_info->FindBoolKey(kRequirePasswordUpdate);
|
| 174 |
+
if (flag.has_value()) {
|
| 175 |
+
SetUserBooleanValue(user_id, kSupervisedUserNeedPasswordUpdate,
|
| 176 |
+
flag.value());
|
| 177 |
+
}
|
| 178 |
+
flag = password_info->FindBoolKey(kHasIncompleteKey);
|
| 179 |
+
if (flag.has_value())
|
| 180 |
+
SetUserBooleanValue(user_id, kSupervisedUserIncompleteKey, flag.value());
|
| 181 |
+
|
| 182 |
+
const std::string* salt = password_info->FindStringKey(kSalt);
|
| 183 |
+
if (salt)
|
| 184 |
+
SetUserStringValue(user_id, kSupervisedUserPasswordSalt, *salt);
|
| 185 |
+
g_browser_process->local_state()->CommitPendingWrite();
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
bool SupervisedUserManagerImpl::GetUserStringValue(
|
| 189 |
+
const std::string& user_id,
|
| 190 |
+
const char* key,
|
| 191 |
+
std::string* out_value) const {
|
| 192 |
+
PrefService* local_state = g_browser_process->local_state();
|
| 193 |
+
const base::Value* dictionary = local_state->GetDictionary(key);
|
| 194 |
+
const std::string* value = dictionary->FindStringKey(user_id);
|
| 195 |
+
if (!value)
|
| 196 |
+
return false;
|
| 197 |
+
|
| 198 |
+
*out_value = *value;
|
| 199 |
+
return true;
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
bool SupervisedUserManagerImpl::GetUserIntegerValue(const std::string& user_id,
|
| 203 |
+
const char* key,
|
| 204 |
+
int* out_value) const {
|
| 205 |
+
PrefService* local_state = g_browser_process->local_state();
|
| 206 |
+
const base::Value* dictionary = local_state->GetDictionary(key);
|
| 207 |
+
absl::optional<int> value = dictionary->FindIntKey(user_id);
|
| 208 |
+
if (!value)
|
| 209 |
+
return false;
|
| 210 |
+
|
| 211 |
+
*out_value = value.value();
|
| 212 |
+
return true;
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
bool SupervisedUserManagerImpl::GetUserBooleanValue(const std::string& user_id,
|
| 216 |
+
const char* key,
|
| 217 |
+
bool* out_value) const {
|
| 218 |
+
PrefService* local_state = g_browser_process->local_state();
|
| 219 |
+
const base::Value* dictionary = local_state->GetDictionary(key);
|
| 220 |
+
absl::optional<bool> flag = dictionary->FindBoolKey(user_id);
|
| 221 |
+
if (!flag)
|
| 222 |
+
return false;
|
| 223 |
+
|
| 224 |
+
*out_value = flag.value();
|
| 225 |
+
return true;
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
void SupervisedUserManagerImpl::SetUserStringValue(const std::string& user_id,
|
| 229 |
+
const char* key,
|
| 230 |
+
const std::string& value) {
|
| 231 |
+
PrefService* local_state = g_browser_process->local_state();
|
| 232 |
+
DictionaryPrefUpdate update(local_state, key);
|
| 233 |
+
update->SetStringKey(user_id, value);
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
void SupervisedUserManagerImpl::SetUserIntegerValue(const std::string& user_id,
|
| 237 |
+
const char* key,
|
| 238 |
+
const int value) {
|
| 239 |
+
PrefService* local_state = g_browser_process->local_state();
|
| 240 |
+
DictionaryPrefUpdate update(local_state, key);
|
| 241 |
+
update->SetIntKey(user_id, value);
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
void SupervisedUserManagerImpl::SetUserBooleanValue(const std::string& user_id,
|
| 245 |
+
const char* key,
|
| 246 |
+
const bool value) {
|
| 247 |
+
PrefService* local_state = g_browser_process->local_state();
|
| 248 |
+
DictionaryPrefUpdate update(local_state, key);
|
| 249 |
+
update->SetBoolKey(user_id, value);
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
void SupervisedUserManagerImpl::RemoveNonCryptohomeData(
|
| 253 |
+
const std::string& user_id) {
|
| 254 |
+
PrefService* prefs = g_browser_process->local_state();
|
| 255 |
+
ListPrefUpdate prefs_new_users_update(prefs, kSupervisedUsersFirstRun);
|
| 256 |
+
prefs_new_users_update->EraseListValue(base::Value(user_id));
|
| 257 |
+
|
| 258 |
+
CleanPref(user_id, kSupervisedUserSyncId);
|
| 259 |
+
CleanPref(user_id, kSupervisedUserManagers);
|
| 260 |
+
CleanPref(user_id, kSupervisedUserManagerNames);
|
| 261 |
+
CleanPref(user_id, kSupervisedUserManagerDisplayEmails);
|
| 262 |
+
CleanPref(user_id, kSupervisedUserPasswordSalt);
|
| 263 |
+
CleanPref(user_id, kSupervisedUserPasswordSchema);
|
| 264 |
+
CleanPref(user_id, kSupervisedUserPasswordRevision);
|
| 265 |
+
CleanPref(user_id, kSupervisedUserNeedPasswordUpdate);
|
| 266 |
+
CleanPref(user_id, kSupervisedUserIncompleteKey);
|
| 267 |
+
}
|
| 268 |
+
|
| 269 |
+
void SupervisedUserManagerImpl::CleanPref(const std::string& user_id,
|
| 270 |
+
const char* key) {
|
| 271 |
+
PrefService* prefs = g_browser_process->local_state();
|
| 272 |
+
DictionaryPrefUpdate dict_update(prefs, key);
|
| 273 |
+
dict_update->RemoveKey(user_id);
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
bool SupervisedUserManagerImpl::CheckForFirstRun(const std::string& user_id) {
|
| 277 |
+
ListPrefUpdate prefs_new_users_update(g_browser_process->local_state(),
|
| 278 |
+
kSupervisedUsersFirstRun);
|
| 279 |
+
return prefs_new_users_update->EraseListValue(base::Value(user_id));
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
} // namespace ash
|
pool/shard002/C++/0024406_B.cpp
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <bits/stdc++.h>
|
| 2 |
+
using namespace std;
|
| 3 |
+
|
| 4 |
+
#define endl "\n"
|
| 5 |
+
|
| 6 |
+
double pos[60001], spd[60001];
|
| 7 |
+
|
| 8 |
+
bool meet(int n, double t) {
|
| 9 |
+
double rng[60001][2];
|
| 10 |
+
|
| 11 |
+
double L = rng[0][0] = pos[0] - spd[0]*t;
|
| 12 |
+
double R = rng[0][1] = pos[0] + spd[0]*t;
|
| 13 |
+
for (int i=1; i<n; ++i) {
|
| 14 |
+
rng[i][0] = pos[i] - spd[i]*t;
|
| 15 |
+
if (rng[i][0] > L)
|
| 16 |
+
L = rng[i][0];
|
| 17 |
+
|
| 18 |
+
rng[i][1] = pos[i] + spd[i]*t;
|
| 19 |
+
if (rng[i][1] < R)
|
| 20 |
+
R = rng[i][1];
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
return (L <= R);
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
int main(void) {
|
| 27 |
+
|
| 28 |
+
int n;
|
| 29 |
+
scanf("%d", &n);
|
| 30 |
+
|
| 31 |
+
for (int i=0; i<n; ++i)
|
| 32 |
+
scanf("%lf", &pos[i]);
|
| 33 |
+
|
| 34 |
+
for (int i=0; i<n; ++i)
|
| 35 |
+
scanf("%lf", &spd[i]);
|
| 36 |
+
|
| 37 |
+
double max_t = 1e9, min_t = 0;
|
| 38 |
+
// binary search
|
| 39 |
+
double mid;
|
| 40 |
+
while(min_t < max_t){
|
| 41 |
+
mid = (max_t + min_t)/2.0;
|
| 42 |
+
if (meet(n, mid))
|
| 43 |
+
max_t = mid - 0.000001;
|
| 44 |
+
else
|
| 45 |
+
min_t = mid + 0.000001;
|
| 46 |
+
}
|
| 47 |
+
printf("%lf\n",max_t);
|
| 48 |
+
return 0;
|
| 49 |
+
}
|
pool/shard002/C++/0024409_math_util.cpp
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Author: qiyiping@gmail.com (Yiping Qi)
|
| 2 |
+
|
| 3 |
+
#include "math_util.hpp"
|
| 4 |
+
#include "tree.hpp"
|
| 5 |
+
#include <algorithm>
|
| 6 |
+
#include <iostream>
|
| 7 |
+
|
| 8 |
+
#ifdef USE_OPENMP
|
| 9 |
+
#include <parallel/algorithm> // openmp
|
| 10 |
+
#endif
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
namespace {
|
| 14 |
+
struct ResidualCompare {
|
| 15 |
+
bool operator () (const gbdt::Tuple *t1, const gbdt::Tuple *t2) {
|
| 16 |
+
return t1->residual < t2->residual;
|
| 17 |
+
}
|
| 18 |
+
};
|
| 19 |
+
|
| 20 |
+
struct LabelCompare {
|
| 21 |
+
bool operator () (const gbdt::Tuple *t1, const gbdt::Tuple *t2) {
|
| 22 |
+
return t1->label < t2->label;
|
| 23 |
+
}
|
| 24 |
+
};
|
| 25 |
+
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
namespace gbdt {
|
| 29 |
+
|
| 30 |
+
bool AlmostEqual(ValueType v1, ValueType v2) {
|
| 31 |
+
ValueType diff = Abs(v1-v2);
|
| 32 |
+
if (diff < 1.0e-5)
|
| 33 |
+
return true;
|
| 34 |
+
return false;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
bool Same(const DataVector &data, size_t len) {
|
| 38 |
+
assert(len <= data.size());
|
| 39 |
+
if (len <= 1)
|
| 40 |
+
return true;
|
| 41 |
+
|
| 42 |
+
ValueType t = data[0]->target;
|
| 43 |
+
for (size_t i = 1; i < len; ++i) {
|
| 44 |
+
if (!AlmostEqual(t, data[i]->target))
|
| 45 |
+
return false;
|
| 46 |
+
}
|
| 47 |
+
return true;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
ValueType Average(const DataVector & data, size_t len) {
|
| 51 |
+
assert(len <= data.size());
|
| 52 |
+
if (len == 0)
|
| 53 |
+
return 0;
|
| 54 |
+
double s = 0;
|
| 55 |
+
double c = 0;
|
| 56 |
+
for (size_t i = 0; i < len; ++i) {
|
| 57 |
+
s += data[i]->target * data[i]->weight;
|
| 58 |
+
c += data[i]->weight;
|
| 59 |
+
}
|
| 60 |
+
return static_cast<ValueType>(s / c);
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
double RMSE(const DataVector &data, const PredictVector &predict, size_t len) {
|
| 64 |
+
assert(data.size() >= len);
|
| 65 |
+
assert(predict.size() >= len);
|
| 66 |
+
double s = 0;
|
| 67 |
+
double c = 0;
|
| 68 |
+
|
| 69 |
+
for (size_t i = 0; i < data.size(); ++i) {
|
| 70 |
+
s += Squared(predict[i] - data[i]->label) * data[i]->weight;
|
| 71 |
+
c += data[i]->weight;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
return std::sqrt(s / c);
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
double MAE(const DataVector &data, const PredictVector &predict, size_t len) {
|
| 78 |
+
assert(data.size() >= len);
|
| 79 |
+
assert(predict.size() >= len);
|
| 80 |
+
double s = 0;
|
| 81 |
+
double c = 0;
|
| 82 |
+
|
| 83 |
+
for (size_t i = 0; i < data.size(); ++i) {
|
| 84 |
+
s += Abs(predict[i] - data[i]->label) * data[i]->weight;
|
| 85 |
+
c += data[i]->weight;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
return s / c;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
ValueType WeightedResidualMedian(DataVector &d, size_t len) {
|
| 92 |
+
assert(d.size() >= len);
|
| 93 |
+
// simplest implementation using sorting
|
| 94 |
+
// sophisticated approch to find the weighted median is selection algorithm(partition algorithm).
|
| 95 |
+
std::sort(d.begin(), d.begin() + len, ResidualCompare());
|
| 96 |
+
double all_weight = 0.0;
|
| 97 |
+
for (size_t i = 0; i < len; ++i) {
|
| 98 |
+
all_weight += d[i]->weight;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
ValueType weighted_median = 0.0;
|
| 102 |
+
double weight = 0.0;
|
| 103 |
+
for (int i = 0; i < len; ++i) {
|
| 104 |
+
weight += d[i]->weight;
|
| 105 |
+
if (weight * 2 > all_weight) {
|
| 106 |
+
if (i-1 >= 0) {
|
| 107 |
+
weighted_median = (d[i]->residual + d[i-1]->residual) / 2.0;
|
| 108 |
+
} else {
|
| 109 |
+
weighted_median = d[i]->residual;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
break;
|
| 113 |
+
}
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
return weighted_median;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
ValueType WeightedLabelMedian(DataVector &d, size_t len) {
|
| 120 |
+
assert(d.size() >= len);
|
| 121 |
+
// simplest implementation using sorting
|
| 122 |
+
// sophisticated approch to find the weighted median is selection algorithm(partition algorithm).
|
| 123 |
+
std::sort(d.begin(), d.begin() + len, LabelCompare());
|
| 124 |
+
double all_weight = 0.0;
|
| 125 |
+
for (size_t i = 0; i < len; ++i) {
|
| 126 |
+
all_weight += d[i]->weight;
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
ValueType weighted_median = 0.0;
|
| 130 |
+
double weight = 0.0;
|
| 131 |
+
for (int i = 0; i < len; ++i) {
|
| 132 |
+
weight += d[i]->weight;
|
| 133 |
+
if (weight * 2 > all_weight) {
|
| 134 |
+
if (i-1 >= 0) {
|
| 135 |
+
weighted_median = (d[i]->label + d[i-1]->label) / 2.0;
|
| 136 |
+
} else {
|
| 137 |
+
weighted_median = d[i]->label;
|
| 138 |
+
}
|
| 139 |
+
break;
|
| 140 |
+
}
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
return weighted_median;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
}
|
pool/shard002/C++/0024412_haj_weapon_shovel.cpp
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//========= Copyright © 2007, Ham and Jam. ==============================//
|
| 2 |
+
// Purpose: German Entrenching Tool
|
| 3 |
+
// Notes: Spong!
|
| 4 |
+
//=======================================================================//
|
| 5 |
+
|
| 6 |
+
#include "cbase.h"
|
| 7 |
+
#include "weapon_hl2mpbasehlmpcombatweapon.h"
|
| 8 |
+
#include "gamerules.h"
|
| 9 |
+
#include "ammodef.h"
|
| 10 |
+
#include "mathlib.h"
|
| 11 |
+
#include "in_buttons.h"
|
| 12 |
+
#include "weapon_hl2mpbasebasebludgeon.h"
|
| 13 |
+
#include "npcevent.h"
|
| 14 |
+
|
| 15 |
+
// memdbgon must be the last include file in a .cpp file!!!
|
| 16 |
+
#include "tier0/memdbgon.h"
|
| 17 |
+
|
| 18 |
+
#define SHOVEL_RANGE_NORMAL 62.0f // effective range normally
|
| 19 |
+
#define SHOVEL_REFIRE 0.75f // time between stabs/slash/swings, etc.
|
| 20 |
+
|
| 21 |
+
#ifdef CLIENT_DLL
|
| 22 |
+
#define CWeaponShovel C_WeaponShovel
|
| 23 |
+
#endif
|
| 24 |
+
|
| 25 |
+
//-----------------------------------------------------------------------------
|
| 26 |
+
// CWeaponShovel
|
| 27 |
+
//-----------------------------------------------------------------------------
|
| 28 |
+
|
| 29 |
+
class CWeaponShovel : public CBaseHL2MPBludgeonWeapon
|
| 30 |
+
{
|
| 31 |
+
public:
|
| 32 |
+
DECLARE_CLASS( CWeaponShovel, CBaseHL2MPBludgeonWeapon );
|
| 33 |
+
|
| 34 |
+
DECLARE_NETWORKCLASS();
|
| 35 |
+
DECLARE_PREDICTABLE();
|
| 36 |
+
|
| 37 |
+
DECLARE_ACTTABLE();
|
| 38 |
+
|
| 39 |
+
CWeaponShovel();
|
| 40 |
+
|
| 41 |
+
float GetRange( void ) { return SHOVEL_RANGE_NORMAL; }
|
| 42 |
+
float GetFireRate( void ) { return SHOVEL_REFIRE; }
|
| 43 |
+
|
| 44 |
+
float GetDamageForActivity( Activity hitActivity );
|
| 45 |
+
void SecondaryAttack( void ) { return; } // tweak this to add stealth mode
|
| 46 |
+
|
| 47 |
+
void Drop( const Vector &vecVelocity );
|
| 48 |
+
|
| 49 |
+
// Animation event
|
| 50 |
+
#ifndef CLIENT_DLL
|
| 51 |
+
virtual void Operator_HandleAnimEvent( animevent_t *pEvent, CBaseCombatCharacter *pOperator );
|
| 52 |
+
void HandleAnimEventMeleeHit( animevent_t *pEvent, CBaseCombatCharacter *pOperator );
|
| 53 |
+
virtual bool ShouldDrawPickup() { return false; }
|
| 54 |
+
#endif
|
| 55 |
+
|
| 56 |
+
CWeaponShovel( const CWeaponShovel & );
|
| 57 |
+
|
| 58 |
+
private:
|
| 59 |
+
|
| 60 |
+
};
|
| 61 |
+
|
| 62 |
+
IMPLEMENT_NETWORKCLASS_ALIASED( WeaponShovel, DT_WeaponShovel )
|
| 63 |
+
|
| 64 |
+
BEGIN_NETWORK_TABLE( CWeaponShovel, DT_WeaponShovel )
|
| 65 |
+
END_NETWORK_TABLE()
|
| 66 |
+
|
| 67 |
+
BEGIN_PREDICTION_DATA( CWeaponShovel )
|
| 68 |
+
END_PREDICTION_DATA()
|
| 69 |
+
|
| 70 |
+
LINK_ENTITY_TO_CLASS( weapon_shovel, CWeaponShovel );
|
| 71 |
+
PRECACHE_WEAPON_REGISTER( weapon_shovel );
|
| 72 |
+
|
| 73 |
+
acttable_t CWeaponShovel::m_acttable[] =
|
| 74 |
+
{
|
| 75 |
+
// attack
|
| 76 |
+
{ ACT_MP_ATTACK_STAND_PRIMARYFIRE, ACT_HAJ_PRIMARYATTACK_SPADE, false },
|
| 77 |
+
{ ACT_MP_ATTACK_CROUCH_PRIMARYFIRE, ACT_HAJ_PRIMARYATTACK_SPADE, false },
|
| 78 |
+
{ ACT_MP_ATTACK_PRONE_PRIMARYFIRE, ACT_HAJ_PRIMARYATTACK_PRONE_SPADE, false },
|
| 79 |
+
|
| 80 |
+
// aiming down sight, recent attack
|
| 81 |
+
{ ACT_HAJ_IDLE_AIM, ACT_HAJ_STAND_AIM_SPADE, false },
|
| 82 |
+
{ ACT_HAJ_WALK_AIM, ACT_HAJ_WALK_AIM_SPADE, false },
|
| 83 |
+
{ ACT_HAJ_IDLE_CROUCH_AIM, ACT_HAJ_CROUCH_AIM_SPADE, false },
|
| 84 |
+
{ ACT_HAJ_WALK_CROUCH_AIM, ACT_HAJ_CROUCHWALK_IDLE_SPADE, false },
|
| 85 |
+
{ ACT_HAJ_RUN_AIM, ACT_HAJ_RUN_AIM_SPADE, false },
|
| 86 |
+
|
| 87 |
+
// movement
|
| 88 |
+
{ ACT_MP_STAND_IDLE, ACT_HAJ_STAND_AIM_SPADE, false },
|
| 89 |
+
{ ACT_MP_RUN, ACT_HAJ_RUN_AIM_SPADE, false },
|
| 90 |
+
{ ACT_MP_SPRINT, ACT_HAJ_SPRINT_AIM_SPADE, false },
|
| 91 |
+
{ ACT_MP_WALK, ACT_HAJ_WALK_AIM_SPADE, false },
|
| 92 |
+
{ ACT_MP_PRONE_IDLE, ACT_HAJ_PRONE_AIM_SPADE, false },
|
| 93 |
+
{ ACT_MP_PRONE_CRAWL, ACT_HAJ_PRONEWALK_AIM_SPADE, false },
|
| 94 |
+
{ ACT_MP_CROUCH_IDLE, ACT_HAJ_CROUCH_AIM_SPADE, false },
|
| 95 |
+
{ ACT_MP_CROUCHWALK, ACT_HAJ_CROUCHWALK_AIM_SPADE, false },
|
| 96 |
+
};
|
| 97 |
+
|
| 98 |
+
IMPLEMENT_ACTTABLE(CWeaponShovel);
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
//-----------------------------------------------------------------------------
|
| 102 |
+
// Constructor
|
| 103 |
+
//-----------------------------------------------------------------------------
|
| 104 |
+
CWeaponShovel::CWeaponShovel( void )
|
| 105 |
+
{
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
//-----------------------------------------------------------------------------
|
| 109 |
+
// Purpose: Get the damage amount for the animation we're doing
|
| 110 |
+
// Input : hitActivity - currently played activity
|
| 111 |
+
// Output : Damage amount
|
| 112 |
+
//-----------------------------------------------------------------------------
|
| 113 |
+
float CWeaponShovel::GetDamageForActivity( Activity hitActivity )
|
| 114 |
+
{
|
| 115 |
+
#ifndef CLIENT_DLL
|
| 116 |
+
// TODO - tune this so that it does a different ammount for the stealth kill
|
| 117 |
+
CBaseCombatCharacter* pOwner = ToBaseCombatCharacter( GetOwner() );
|
| 118 |
+
|
| 119 |
+
if( pOwner )
|
| 120 |
+
{
|
| 121 |
+
Vector vecDirection;
|
| 122 |
+
AngleVectors( GetAbsAngles(), &vecDirection );
|
| 123 |
+
|
| 124 |
+
Vector vecEnd;
|
| 125 |
+
VectorMA( pOwner->Weapon_ShootPosition(), SHOVEL_RANGE_NORMAL, vecDirection, vecEnd );
|
| 126 |
+
|
| 127 |
+
trace_t traceHit;
|
| 128 |
+
UTIL_TraceLine( pOwner->Weapon_ShootPosition(), vecEnd, MASK_SHOT_HULL, pOwner, COLLISION_GROUP_NONE, &traceHit );
|
| 129 |
+
|
| 130 |
+
if( traceHit.DidHit() && traceHit.m_pEnt && traceHit.hitgroup == HITGROUP_HEAD )
|
| 131 |
+
{
|
| 132 |
+
return 100.0f;
|
| 133 |
+
}
|
| 134 |
+
}
|
| 135 |
+
#endif
|
| 136 |
+
|
| 137 |
+
return 75.0f;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
//-----------------------------------------------------------------------------
|
| 141 |
+
// Purpose:
|
| 142 |
+
//-----------------------------------------------------------------------------
|
| 143 |
+
void CWeaponShovel::Drop( const Vector &vecVelocity )
|
| 144 |
+
{
|
| 145 |
+
// You can't drop a shovel so if, somehow, you do manage to, delete it.
|
| 146 |
+
#ifndef CLIENT_DLL
|
| 147 |
+
UTIL_Remove( this );
|
| 148 |
+
#endif
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
#ifndef CLIENT_DLL
|
| 152 |
+
//-----------------------------------------------------------------------------
|
| 153 |
+
// Animation event handlers
|
| 154 |
+
//-----------------------------------------------------------------------------
|
| 155 |
+
void CWeaponShovel::HandleAnimEventMeleeHit( animevent_t *pEvent, CBaseCombatCharacter *pOperator )
|
| 156 |
+
{
|
| 157 |
+
// Trace up or down based on where the enemy is...
|
| 158 |
+
// But only if we're basically facing that direction
|
| 159 |
+
Vector vecDirection;
|
| 160 |
+
AngleVectors( GetAbsAngles(), &vecDirection );
|
| 161 |
+
|
| 162 |
+
Vector vecEnd;
|
| 163 |
+
VectorMA( pOperator->Weapon_ShootPosition(), 50, vecDirection, vecEnd );
|
| 164 |
+
|
| 165 |
+
CBaseEntity *pHurt = pOperator->CheckTraceHullAttack( pOperator->Weapon_ShootPosition(),
|
| 166 |
+
vecEnd,
|
| 167 |
+
Vector(-16,-16,-16),
|
| 168 |
+
Vector(36,36,36),
|
| 169 |
+
GetDamageForActivity( GetActivity() ),
|
| 170 |
+
DMG_CLUB,
|
| 171 |
+
0.75 ); // check this force scale value?
|
| 172 |
+
|
| 173 |
+
// did I hit someone?
|
| 174 |
+
if ( pHurt )
|
| 175 |
+
{
|
| 176 |
+
|
| 177 |
+
// Fake a trace impact, so the effects work out like a player's crowbaw
|
| 178 |
+
trace_t traceHit;
|
| 179 |
+
UTIL_TraceLine( pOperator->Weapon_ShootPosition(),
|
| 180 |
+
pHurt->GetAbsOrigin(),
|
| 181 |
+
MASK_SHOT_HULL | CONTENTS_HITBOX,
|
| 182 |
+
pOperator,
|
| 183 |
+
COLLISION_GROUP_NONE,
|
| 184 |
+
&traceHit );
|
| 185 |
+
|
| 186 |
+
// do the slash decal
|
| 187 |
+
ImpactEffect( traceHit );
|
| 188 |
+
|
| 189 |
+
}
|
| 190 |
+
else
|
| 191 |
+
{
|
| 192 |
+
//WeaponSound( MELEE_MISS );
|
| 193 |
+
}
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
//-----------------------------------------------------------------------------
|
| 197 |
+
// Animation event
|
| 198 |
+
//-----------------------------------------------------------------------------
|
| 199 |
+
void CWeaponShovel::Operator_HandleAnimEvent( animevent_t *pEvent, CBaseCombatCharacter *pOperator )
|
| 200 |
+
{
|
| 201 |
+
switch( pEvent->event )
|
| 202 |
+
{
|
| 203 |
+
case EVENT_WEAPON_MELEE_HIT:
|
| 204 |
+
HandleAnimEventMeleeHit( pEvent, pOperator );
|
| 205 |
+
break;
|
| 206 |
+
|
| 207 |
+
default:
|
| 208 |
+
BaseClass::Operator_HandleAnimEvent( pEvent, pOperator );
|
| 209 |
+
break;
|
| 210 |
+
}
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
#endif
|
pool/shard002/C++/0024414_lock_view.cc
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 "ash/shell.h"
|
| 6 |
+
#include "ash/shell_delegate.h"
|
| 7 |
+
#include "ash/shell_window_ids.h"
|
| 8 |
+
#include "ash/shell/example_factory.h"
|
| 9 |
+
#include "base/utf_string_conversions.h"
|
| 10 |
+
#include "ui/aura/root_window.h"
|
| 11 |
+
#include "ui/aura/window.h"
|
| 12 |
+
#include "ui/gfx/canvas.h"
|
| 13 |
+
#include "ui/gfx/font.h"
|
| 14 |
+
#include "ui/views/controls/button/text_button.h"
|
| 15 |
+
#include "ui/views/corewm/tooltip_controller.h"
|
| 16 |
+
#include "ui/views/widget/widget.h"
|
| 17 |
+
#include "ui/views/widget/widget_delegate.h"
|
| 18 |
+
|
| 19 |
+
using ash::Shell;
|
| 20 |
+
|
| 21 |
+
namespace ash {
|
| 22 |
+
namespace shell {
|
| 23 |
+
|
| 24 |
+
class LockView : public views::WidgetDelegateView,
|
| 25 |
+
public views::ButtonListener {
|
| 26 |
+
public:
|
| 27 |
+
LockView() : unlock_button_(ALLOW_THIS_IN_INITIALIZER_LIST(
|
| 28 |
+
new views::NativeTextButton(this, ASCIIToUTF16("Unlock")))) {
|
| 29 |
+
AddChildView(unlock_button_);
|
| 30 |
+
unlock_button_->set_focusable(true);
|
| 31 |
+
}
|
| 32 |
+
virtual ~LockView() {}
|
| 33 |
+
|
| 34 |
+
// Overridden from views::View:
|
| 35 |
+
virtual gfx::Size GetPreferredSize() OVERRIDE {
|
| 36 |
+
return gfx::Size(500, 400);
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
private:
|
| 40 |
+
// Overridden from views::View:
|
| 41 |
+
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
|
| 42 |
+
canvas->FillRect(GetLocalBounds(), SK_ColorYELLOW);
|
| 43 |
+
string16 text = ASCIIToUTF16("LOCKED!");
|
| 44 |
+
int string_width = font_.GetStringWidth(text);
|
| 45 |
+
canvas->DrawStringInt(text, font_, SK_ColorRED, (width() - string_width)/ 2,
|
| 46 |
+
(height() - font_.GetHeight()) / 2,
|
| 47 |
+
string_width, font_.GetHeight());
|
| 48 |
+
}
|
| 49 |
+
virtual void Layout() OVERRIDE {
|
| 50 |
+
gfx::Rect bounds = GetLocalBounds();
|
| 51 |
+
gfx::Size ps = unlock_button_->GetPreferredSize();
|
| 52 |
+
bounds.set_y(bounds.bottom() - ps.height() - 5);
|
| 53 |
+
bounds.set_x((bounds.width() - ps.width()) / 2);
|
| 54 |
+
bounds.set_size(ps);
|
| 55 |
+
unlock_button_->SetBoundsRect(bounds);
|
| 56 |
+
}
|
| 57 |
+
virtual void ViewHierarchyChanged(bool is_add,
|
| 58 |
+
views::View* parent,
|
| 59 |
+
views::View* child) OVERRIDE {
|
| 60 |
+
if (is_add && child == this)
|
| 61 |
+
unlock_button_->RequestFocus();
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
// Overridden from views::WidgetDelegateView:
|
| 65 |
+
virtual void WindowClosing() OVERRIDE {
|
| 66 |
+
Shell::GetInstance()->delegate()->UnlockScreen();
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
// Overridden from views::ButtonListener:
|
| 70 |
+
virtual void ButtonPressed(views::Button* sender,
|
| 71 |
+
const ui::Event& event) OVERRIDE {
|
| 72 |
+
DCHECK(sender == unlock_button_);
|
| 73 |
+
GetWidget()->Close();
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
gfx::Font font_;
|
| 77 |
+
views::NativeTextButton* unlock_button_;
|
| 78 |
+
|
| 79 |
+
DISALLOW_COPY_AND_ASSIGN(LockView);
|
| 80 |
+
};
|
| 81 |
+
|
| 82 |
+
void CreateLockScreen() {
|
| 83 |
+
LockView* lock_view = new LockView;
|
| 84 |
+
views::Widget* widget = new views::Widget;
|
| 85 |
+
views::Widget::InitParams params(
|
| 86 |
+
views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
|
| 87 |
+
gfx::Size ps = lock_view->GetPreferredSize();
|
| 88 |
+
|
| 89 |
+
gfx::Size root_window_size = Shell::GetPrimaryRootWindow()->bounds().size();
|
| 90 |
+
params.bounds = gfx::Rect((root_window_size.width() - ps.width()) / 2,
|
| 91 |
+
(root_window_size.height() - ps.height()) / 2,
|
| 92 |
+
ps.width(), ps.height());
|
| 93 |
+
params.delegate = lock_view;
|
| 94 |
+
params.parent = Shell::GetContainer(
|
| 95 |
+
Shell::GetPrimaryRootWindow(),
|
| 96 |
+
internal::kShellWindowId_LockScreenContainer);
|
| 97 |
+
widget->Init(params);
|
| 98 |
+
widget->SetContentsView(lock_view);
|
| 99 |
+
widget->Show();
|
| 100 |
+
widget->GetNativeView()->SetName("LockView");
|
| 101 |
+
widget->GetNativeView()->Focus();
|
| 102 |
+
|
| 103 |
+
// TODO: it shouldn't be necessary to invoke UpdateTooltip() here.
|
| 104 |
+
Shell::GetInstance()->tooltip_controller()->UpdateTooltip(
|
| 105 |
+
widget->GetNativeView());
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
} // namespace shell
|
| 109 |
+
} // namespace ash
|
pool/shard002/C++/0024416_MsPacman.cpp
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* *****************************************************************************
|
| 2 |
+
* A.L.E (Arcade Learning Environment)
|
| 3 |
+
* Copyright (c) 2009-2013 by Yavar Naddaf, Joel Veness, Marc G. Bellemare and
|
| 4 |
+
* the Reinforcement Learning and Artificial Intelligence Laboratory
|
| 5 |
+
* Released under the GNU General Public License; see License.txt for details.
|
| 6 |
+
*
|
| 7 |
+
* Based on: Stella -- "An Atari 2600 VCS Emulator"
|
| 8 |
+
* Copyright (c) 1995-2007 by Bradford W. Mott and the Stella team
|
| 9 |
+
*
|
| 10 |
+
* *****************************************************************************
|
| 11 |
+
*/
|
| 12 |
+
#include "MsPacman.hpp"
|
| 13 |
+
|
| 14 |
+
#include "../RomUtils.hpp"
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
MsPacmanSettings::MsPacmanSettings() {
|
| 18 |
+
|
| 19 |
+
reset();
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
/* create a new instance of the rom */
|
| 24 |
+
RomSettings* MsPacmanSettings::clone() const {
|
| 25 |
+
|
| 26 |
+
RomSettings* rval = new MsPacmanSettings();
|
| 27 |
+
*rval = *this;
|
| 28 |
+
return rval;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
/* process the latest information from ALE */
|
| 33 |
+
void MsPacmanSettings::step(const System& system) {
|
| 34 |
+
|
| 35 |
+
// update the reward
|
| 36 |
+
int score = getDecimalScore(0xF8, 0xF9, 0xFA, &system);
|
| 37 |
+
int reward = score - m_score;
|
| 38 |
+
m_reward = reward;
|
| 39 |
+
m_score = score;
|
| 40 |
+
|
| 41 |
+
// update terminal status
|
| 42 |
+
int lives = readRam(&system, 0xFB) & 0xF;
|
| 43 |
+
// MGB Did not work int black_screen_byte = readRam(&system, 0x94);
|
| 44 |
+
int death_timer = readRam(&system, 0xA7);
|
| 45 |
+
m_terminal = lives == 0 && death_timer == 0x53;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
/* is end of game */
|
| 50 |
+
bool MsPacmanSettings::isTerminal() const {
|
| 51 |
+
|
| 52 |
+
return m_terminal;
|
| 53 |
+
};
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
/* get the most recently observed reward */
|
| 57 |
+
reward_t MsPacmanSettings::getReward() const {
|
| 58 |
+
|
| 59 |
+
return m_reward;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
/* is an action part of the minimal set? */
|
| 64 |
+
bool MsPacmanSettings::isMinimal(const Action &a) const {
|
| 65 |
+
|
| 66 |
+
switch (a) {
|
| 67 |
+
case PLAYER_A_NOOP:
|
| 68 |
+
case PLAYER_A_UP:
|
| 69 |
+
case PLAYER_A_RIGHT:
|
| 70 |
+
case PLAYER_A_LEFT:
|
| 71 |
+
case PLAYER_A_DOWN:
|
| 72 |
+
case PLAYER_A_UPRIGHT:
|
| 73 |
+
case PLAYER_A_UPLEFT:
|
| 74 |
+
case PLAYER_A_DOWNRIGHT:
|
| 75 |
+
case PLAYER_A_DOWNLEFT:
|
| 76 |
+
return true;
|
| 77 |
+
default:
|
| 78 |
+
return false;
|
| 79 |
+
}
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
/* reset the state of the game */
|
| 84 |
+
void MsPacmanSettings::reset() {
|
| 85 |
+
|
| 86 |
+
m_reward = 0;
|
| 87 |
+
m_score = 0;
|
| 88 |
+
m_terminal = false;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
/* saves the state of the rom settings */
|
| 94 |
+
void MsPacmanSettings::saveState(Serializer & ser) {
|
| 95 |
+
ser.putInt(m_reward);
|
| 96 |
+
ser.putInt(m_score);
|
| 97 |
+
ser.putBool(m_terminal);
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
// loads the state of the rom settings
|
| 101 |
+
void MsPacmanSettings::loadState(Deserializer & ser) {
|
| 102 |
+
m_reward = ser.getInt();
|
| 103 |
+
m_score = ser.getInt();
|
| 104 |
+
m_terminal = ser.getBool();
|
| 105 |
+
}
|
| 106 |
+
|
pool/shard002/C++/0024426_config.cpp
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* File: config.cpp
|
| 3 |
+
* Author: yvan
|
| 4 |
+
*
|
| 5 |
+
* Created on December 8, 2013, 9:45 PM
|
| 6 |
+
*/
|
| 7 |
+
|
| 8 |
+
#include <iostream>
|
| 9 |
+
#include <vector>
|
| 10 |
+
#include "config.h"
|
| 11 |
+
#include "convert.h"
|
| 12 |
+
#include "../system/workDir.h"
|
| 13 |
+
#include "log.h"
|
| 14 |
+
|
| 15 |
+
y::utils::config & y::utils::Config() {
|
| 16 |
+
static config c;
|
| 17 |
+
return c;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
using namespace boost::program_options;
|
| 21 |
+
|
| 22 |
+
y::utils::config::config() : general("general options"),
|
| 23 |
+
file("config file options"),
|
| 24 |
+
configReady(false){
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
void y::utils::config::load() {
|
| 28 |
+
load(0, nullptr);
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
void y::utils::config::load(int argc, char** argv) {
|
| 32 |
+
std::lock_guard<std::mutex> lock(m);
|
| 33 |
+
if(configReady) {
|
| 34 |
+
//Log().add("y::sys::config::load is called more than once!");
|
| 35 |
+
return;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
general.add_options()
|
| 39 |
+
("help", "print help message")
|
| 40 |
+
("work-directory,w", value<std::string>(), "set working directory")
|
| 41 |
+
("config,c",
|
| 42 |
+
value<std::string>(&configFile)->default_value("/etc/yATools.cfg"),
|
| 43 |
+
"Name of the config file to be used."
|
| 44 |
+
)
|
| 45 |
+
;
|
| 46 |
+
|
| 47 |
+
file.add_options()
|
| 48 |
+
("ldapPasswd" , value<std::string>(), "set ldap admin password")
|
| 49 |
+
("ldapHost" , value<std::string>(), "set ldap host" )
|
| 50 |
+
("ldapBaseDN" , value<std::string>(), "set ldap base DN" )
|
| 51 |
+
("ldapAdminDN" , value<std::string>(), "set ldap admin DN" )
|
| 52 |
+
("ldapTestUID" , value<std::string>(), "set ldap test account" )
|
| 53 |
+
("ldapTestPassword" , value<std::string>(), "set ldap test account password")
|
| 54 |
+
("ldapTestUIDNumber", value<std::string>(), "set ldap test account UID number")
|
| 55 |
+
("ldapTestDN" , value<std::string>(), "set ldap test account DN")
|
| 56 |
+
("mysqlRootPassword", value<std::string>(), "set mysql root password")
|
| 57 |
+
("domain" , value<std::string>(), "set network domain" )
|
| 58 |
+
("smartschoolPw" , value<std::string>(), "set smartschool password")
|
| 59 |
+
("yearbookAdmin" , value< std::vector<std::string> >(), "set yearbook administrators" )
|
| 60 |
+
;
|
| 61 |
+
|
| 62 |
+
all.add(general).add(file);
|
| 63 |
+
|
| 64 |
+
store(parse_command_line(argc, argv, all), map);
|
| 65 |
+
notify(map);
|
| 66 |
+
|
| 67 |
+
std::wifstream ifs(configFile.c_str());
|
| 68 |
+
if(!ifs) {
|
| 69 |
+
string out("cannot open config file: ");
|
| 70 |
+
out += configFile.c_str();
|
| 71 |
+
Log().add(out);
|
| 72 |
+
} else {
|
| 73 |
+
/*std::string out = "loading config file: ";
|
| 74 |
+
out.append(configFile);
|
| 75 |
+
Log().add(out);*/
|
| 76 |
+
store(parse_config_file(ifs, file), map);
|
| 77 |
+
notify(map);
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
if(map.count("help")) {
|
| 81 |
+
std::cout << general << std::endl;
|
| 82 |
+
exit(0);
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
if(map.count("work-directory")) {
|
| 86 |
+
y::sys::WorkDir.set(map["work-directory"].as<std::string>());
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
if(map.count("ldapPasswd")) {
|
| 90 |
+
ldapPasswd = map["ldapPasswd"].as<std::string>();
|
| 91 |
+
} else {
|
| 92 |
+
y::utils::Log().add("Config warning: ldap password is not set.");
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
if(map.count("ldapHost")) {
|
| 96 |
+
ldapHost = map["ldapHost"].as<std::string>();
|
| 97 |
+
} else {
|
| 98 |
+
y::utils::Log().add("Config warning: ldap host is not set.");
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
if(map.count("ldapBaseDN")) {
|
| 102 |
+
ldapBaseDN = map["ldapBaseDN"].as<std::string>();
|
| 103 |
+
} else {
|
| 104 |
+
y::utils::Log().add("Config warning: ldap Base DN is not set.");
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
if(map.count("ldapAdminDN")) {
|
| 108 |
+
ldapAdminDN = map["ldapAdminDN"].as<std::string>();
|
| 109 |
+
} else {
|
| 110 |
+
y::utils::Log().add("Config warning: ldap admin DN is not set.");
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
if(map.count("ldapTestUID")) {
|
| 114 |
+
ldapTestUID = map["ldapTestUID"].as<std::string>();
|
| 115 |
+
} else {
|
| 116 |
+
y::utils::Log().add("Config warning: ldap test UID is not set.");
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
if(map.count("ldapTestPassword")) {
|
| 120 |
+
ldapTestPassword = map["ldapTestPassword"].as<std::string>();
|
| 121 |
+
} else {
|
| 122 |
+
y::utils::Log().add("Config warning: ldap test password is not set.");
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
if(map.count("ldapTestUIDNumber")) {
|
| 126 |
+
ldapTestUidNumber = map["ldapTestUIDNumber"].as<std::string>();
|
| 127 |
+
} else {
|
| 128 |
+
y::utils::Log().add("Config warning: ldap test UID number is not set.");
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
if(map.count("ldapTestDN")) {
|
| 132 |
+
ldapTestDN = map["ldapTestDN"].as<std::string>();
|
| 133 |
+
} else {
|
| 134 |
+
y::utils::Log().add("Config warning: ldap test DN is not set.");
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
if(map.count("mysqlRootPassword")) {
|
| 138 |
+
mysqlPassword = map["mysqlRootPassword"].as<std::string>();
|
| 139 |
+
} else {
|
| 140 |
+
y::utils::Log().add("Config warning: mysql password is not set.");
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
if(map.count("domain")) {
|
| 144 |
+
domain = map["domain"].as<std::string>();
|
| 145 |
+
} else {
|
| 146 |
+
y::utils::Log().add("Config warning: domain is not set.");
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
if(map.count("smartschoolPw")) {
|
| 150 |
+
smartschoolPw = map["smartschoolPw"].as<std::string>();
|
| 151 |
+
} else {
|
| 152 |
+
y::utils::Log().add("Config warning: smartschool password is not set.");
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
if(map.count("yearbookAdmin")) {
|
| 156 |
+
const std::vector<std::string> & admin = map["yearbookAdmin"].as< std::vector<std::string> >();
|
| 157 |
+
for(unsigned int i = 0; i < admin.size(); i++) {
|
| 158 |
+
yearbookAdmin.New() = admin[i];
|
| 159 |
+
}
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
configReady = true;
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
const string & y::utils::config::getLdapPasswd() const {
|
| 166 |
+
std::lock_guard<std::mutex> lock(m);
|
| 167 |
+
return ldapPasswd;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
const string & y::utils::config::getLdapHost() const {
|
| 171 |
+
std::lock_guard<std::mutex> lock(m);
|
| 172 |
+
return ldapHost;
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
const string & y::utils::config::getLdapBaseDN() const {
|
| 176 |
+
std::lock_guard<std::mutex> lock(m);
|
| 177 |
+
return ldapBaseDN;
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
const string & y::utils::config::getLdapAdminDN() const {
|
| 181 |
+
std::lock_guard<std::mutex> lock(m);
|
| 182 |
+
return ldapAdminDN;
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
const string & y::utils::config::getLdapTestUID() const {
|
| 186 |
+
std::lock_guard<std::mutex> lock(m);
|
| 187 |
+
return ldapTestUID;
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
const string & y::utils::config::getLdapTestPassword() const {
|
| 191 |
+
std::lock_guard<std::mutex> lock(m);
|
| 192 |
+
return ldapTestPassword;
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
const string & y::utils::config::getLdapTestUidNumber() const {
|
| 196 |
+
std::lock_guard<std::mutex> lock(m);
|
| 197 |
+
return ldapTestUidNumber;
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
const string & y::utils::config::getLdapTestDN() const {
|
| 201 |
+
std::lock_guard<std::mutex> lock(m);
|
| 202 |
+
return ldapTestDN;
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
const string & y::utils::config::getMysqlPassword() const {
|
| 206 |
+
std::lock_guard<std::mutex> lock(m);
|
| 207 |
+
return mysqlPassword;
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
const string & y::utils::config::getDomain() const {
|
| 211 |
+
std::lock_guard<std::mutex> lock(m);
|
| 212 |
+
return domain;
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
const string & y::utils::config::getSSPw() const {
|
| 216 |
+
std::lock_guard<std::mutex> lock(m);
|
| 217 |
+
return smartschoolPw;
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
bool y::utils::config::isYearbookAdmin(const string& uid) {
|
| 221 |
+
std::lock_guard<std::mutex> lock(m);
|
| 222 |
+
for(int i = 0; i < yearbookAdmin.elms(); i++) {
|
| 223 |
+
if(yearbookAdmin[i] == uid) return true;
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
return false;
|
| 227 |
+
}
|
pool/shard002/C++/0024430_solve.cpp
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* TASK: Given a binary search tree and one of its nodes, determine the in-order
|
| 3 |
+
* successor of this node.
|
| 4 |
+
*/
|
| 5 |
+
|
| 6 |
+
#include <algorithm>
|
| 7 |
+
#include <cassert>
|
| 8 |
+
#include <iostream>
|
| 9 |
+
|
| 10 |
+
/** @brief A node of a binary search tree. */
|
| 11 |
+
struct tree_node
|
| 12 |
+
{
|
| 13 |
+
size_t key;
|
| 14 |
+
tree_node* left;
|
| 15 |
+
tree_node* right;
|
| 16 |
+
tree_node* parent;
|
| 17 |
+
|
| 18 |
+
~tree_node()
|
| 19 |
+
{
|
| 20 |
+
delete left;
|
| 21 |
+
delete right;
|
| 22 |
+
}
|
| 23 |
+
};
|
| 24 |
+
|
| 25 |
+
/**
|
| 26 |
+
* @brief Returns a pointer to a node in a binary search containing a given key
|
| 27 |
+
* or nullptr is no such node exists.
|
| 28 |
+
* @param root The root node of the tree.
|
| 29 |
+
* @param key The key to search for.
|
| 30 |
+
* @note Complexity: O(n) in both time and space, where n is the number of tree
|
| 31 |
+
* nodes.
|
| 32 |
+
*/
|
| 33 |
+
const tree_node* find(const tree_node* root, const size_t key)
|
| 34 |
+
{
|
| 35 |
+
if (root == nullptr || key == root->key)
|
| 36 |
+
{
|
| 37 |
+
return root;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
return (key < root->key) ? find(root->left, key) : find(root->right, key);
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
/**
|
| 44 |
+
* @brief Inserts a node with a given key into a binary search tree.
|
| 45 |
+
* @param root The root node of the tree.
|
| 46 |
+
* @param key The key to be inserted.
|
| 47 |
+
* @note Complexity: O(n) in both time and space, where n is the number of tree
|
| 48 |
+
* nodes.
|
| 49 |
+
*/
|
| 50 |
+
void insert(tree_node* root, const size_t key)
|
| 51 |
+
{
|
| 52 |
+
if (key < root->key)
|
| 53 |
+
{
|
| 54 |
+
if (root->left == nullptr)
|
| 55 |
+
{
|
| 56 |
+
root->left = new tree_node{key, nullptr, nullptr, root};
|
| 57 |
+
}
|
| 58 |
+
else
|
| 59 |
+
{
|
| 60 |
+
insert(root->left, key);
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
else if (key > root->key)
|
| 64 |
+
{
|
| 65 |
+
if (root->right == nullptr)
|
| 66 |
+
{
|
| 67 |
+
root->right = new tree_node{key, nullptr, nullptr, root};
|
| 68 |
+
}
|
| 69 |
+
else
|
| 70 |
+
{
|
| 71 |
+
insert(root->right, key);
|
| 72 |
+
}
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
/**
|
| 77 |
+
* @brief Returns a pointer to the in-order successor of a given node.
|
| 78 |
+
* @note Complexity: O(n) in time, O(1) in space, where n is the number of tree
|
| 79 |
+
* nodes.
|
| 80 |
+
*/
|
| 81 |
+
const tree_node* successor(const tree_node* node)
|
| 82 |
+
{
|
| 83 |
+
/*
|
| 84 |
+
* if node has a right subtree, its successor is the leftmost node
|
| 85 |
+
* of that subtree; if node has no right subtree, its successor can
|
| 86 |
+
* only be one of its ancestors
|
| 87 |
+
*/
|
| 88 |
+
if (node->right != nullptr)
|
| 89 |
+
{
|
| 90 |
+
const tree_node* current = node->right;
|
| 91 |
+
|
| 92 |
+
while (current->left != nullptr)
|
| 93 |
+
{
|
| 94 |
+
current = current->left;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
return current;
|
| 98 |
+
}
|
| 99 |
+
else
|
| 100 |
+
{
|
| 101 |
+
const tree_node* current = node->parent;
|
| 102 |
+
|
| 103 |
+
while (current != nullptr && current->key < node->key)
|
| 104 |
+
{
|
| 105 |
+
current = current->parent;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
return current;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
return nullptr;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
/**
|
| 115 |
+
* @brief Generates a random binary search tree with n nodes and returns a
|
| 116 |
+
* pointer to its root node (the node keys are 0, 1, ..., n-1).
|
| 117 |
+
* @note Complexity: O(n²) in time, O(n) in space.
|
| 118 |
+
*/
|
| 119 |
+
const tree_node* random_binary_search_tree(const size_t n)
|
| 120 |
+
{
|
| 121 |
+
if (n == 0)
|
| 122 |
+
{
|
| 123 |
+
return nullptr;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
std::vector<size_t> keys;
|
| 127 |
+
|
| 128 |
+
for (size_t i = 0; i < n; ++i)
|
| 129 |
+
{
|
| 130 |
+
keys.push_back(i);
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
static std::random_device device;
|
| 134 |
+
static std::mt19937 generator(device());
|
| 135 |
+
|
| 136 |
+
std::shuffle(keys.begin(), keys.end(), generator);
|
| 137 |
+
|
| 138 |
+
/* start with the root node */
|
| 139 |
+
tree_node* root = new tree_node{keys[0], nullptr, nullptr, nullptr};
|
| 140 |
+
|
| 141 |
+
for (size_t i = 1; i < n; ++i)
|
| 142 |
+
{
|
| 143 |
+
insert(root, keys[i]);
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
return root;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
int main()
|
| 150 |
+
{
|
| 151 |
+
for (size_t n = 0; n <= 100; ++n)
|
| 152 |
+
{
|
| 153 |
+
for (int i = 0; i < 1000; ++i)
|
| 154 |
+
{
|
| 155 |
+
const tree_node* root = random_binary_search_tree(n);
|
| 156 |
+
|
| 157 |
+
for (size_t key = 0; key < n; ++key)
|
| 158 |
+
{
|
| 159 |
+
const tree_node* node = find(root, key);
|
| 160 |
+
assert(node != nullptr && node->key == key);
|
| 161 |
+
|
| 162 |
+
if (key == n - 1)
|
| 163 |
+
{
|
| 164 |
+
assert(successor(node) == nullptr);
|
| 165 |
+
}
|
| 166 |
+
else
|
| 167 |
+
{
|
| 168 |
+
assert(successor(node)->key == key + 1);
|
| 169 |
+
}
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
delete root;
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
std::cout << "passed random tests for trees of size " << n << std::endl;
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
return EXIT_SUCCESS;
|
| 179 |
+
}
|
pool/shard002/C++/0024433_RtmpGuesterImpl.cc
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2016 The AnyRTC project authors. All Rights Reserved.
|
| 3 |
+
*
|
| 4 |
+
* Please visit https://www.anyrtc.io for detail.
|
| 5 |
+
*
|
| 6 |
+
* The GNU General Public License is a free, copyleft license for
|
| 7 |
+
* software and other kinds of works.
|
| 8 |
+
*
|
| 9 |
+
* The licenses for most software and other practical works are designed
|
| 10 |
+
* to take away your freedom to share and change the works. By contrast,
|
| 11 |
+
* the GNU General Public License is intended to guarantee your freedom to
|
| 12 |
+
* share and change all versions of a program--to make sure it remains free
|
| 13 |
+
* software for all its users. We, the Free Software Foundation, use the
|
| 14 |
+
* GNU General Public License for most of our software; it applies also to
|
| 15 |
+
* any other work released this way by its authors. You can apply it to
|
| 16 |
+
* your programs, too.
|
| 17 |
+
* See the GNU LICENSE file for more info.
|
| 18 |
+
*/
|
| 19 |
+
#include "RtmpGuesterImpl.h"
|
| 20 |
+
|
| 21 |
+
RTMPGuester* RTMPGuester::Create(RTMPGuesterEvent&callback)
|
| 22 |
+
{
|
| 23 |
+
return new RtmpGuesterImpl(callback);
|
| 24 |
+
}
|
| 25 |
+
void RTMPGuester::Destory(RTMPGuester*guester)
|
| 26 |
+
{
|
| 27 |
+
RtmpGuesterImpl* impl = (RtmpGuesterImpl*)guester->GotSelfPtr();
|
| 28 |
+
delete impl;
|
| 29 |
+
guester = NULL;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
RtmpGuesterImpl::RtmpGuesterImpl(RTMPGuesterEvent&callback)
|
| 33 |
+
: callback_(callback)
|
| 34 |
+
, worker_thread_(&webrtc::AnyRtmpCore::Inst())
|
| 35 |
+
, av_rtmp_started_(NULL)
|
| 36 |
+
, av_rtmp_player_(NULL)
|
| 37 |
+
, video_render_(NULL)
|
| 38 |
+
{
|
| 39 |
+
av_rtmp_player_ = AnyRtmplayer::Create(*this);
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
RtmpGuesterImpl::~RtmpGuesterImpl()
|
| 44 |
+
{
|
| 45 |
+
StopRtmpPlay();
|
| 46 |
+
if (av_rtmp_player_ != NULL) {
|
| 47 |
+
av_rtmp_player_->StopPlay();
|
| 48 |
+
delete av_rtmp_player_;
|
| 49 |
+
av_rtmp_player_ = NULL;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
if (video_render_ != NULL) {
|
| 53 |
+
delete video_render_;
|
| 54 |
+
video_render_ = NULL;
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
//* Rtmp function for pull rtmp stream
|
| 59 |
+
void RtmpGuesterImpl::StartRtmpPlay(const char* url, void* render)
|
| 60 |
+
{
|
| 61 |
+
if (!av_rtmp_started_) {
|
| 62 |
+
rtmp_url_ = url;
|
| 63 |
+
av_rtmp_started_ = true;
|
| 64 |
+
video_render_ = webrtc::VideoRenderer::Create(render, 640, 480);
|
| 65 |
+
av_rtmp_player_->SetVideoRender(video_render_);
|
| 66 |
+
av_rtmp_player_->StartPlay(url);
|
| 67 |
+
webrtc::AnyRtmpCore::Inst().StartAudioTrack(this);
|
| 68 |
+
}
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
void RtmpGuesterImpl::StopRtmpPlay()
|
| 72 |
+
{
|
| 73 |
+
if (av_rtmp_started_) {
|
| 74 |
+
av_rtmp_started_ = false;
|
| 75 |
+
rtmp_url_ = "";
|
| 76 |
+
webrtc::AnyRtmpCore::Inst().StopAudioTrack();
|
| 77 |
+
av_rtmp_player_->StopPlay();
|
| 78 |
+
if (video_render_ != NULL) {
|
| 79 |
+
delete video_render_;
|
| 80 |
+
video_render_ = NULL;
|
| 81 |
+
}
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
//* For AnyRtmplayerEvent
|
| 86 |
+
void RtmpGuesterImpl::OnRtmplayerOK()
|
| 87 |
+
{
|
| 88 |
+
callback_.OnRtmplayerOK();
|
| 89 |
+
}
|
| 90 |
+
void RtmpGuesterImpl::OnRtmplayerStatus(int cacheTime, int curBitrate)
|
| 91 |
+
{
|
| 92 |
+
callback_.OnRtmplayerStatus(cacheTime, curBitrate);
|
| 93 |
+
}
|
| 94 |
+
void RtmpGuesterImpl::OnRtmplayerCache(int time)
|
| 95 |
+
{
|
| 96 |
+
callback_.OnRtmplayerCache(time);
|
| 97 |
+
}
|
| 98 |
+
void RtmpGuesterImpl::OnRtmplayerClose(int errcode)
|
| 99 |
+
{
|
| 100 |
+
callback_.OnRtmplayerClosed(errcode);
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
//* For webrtc::AVAudioTrackCallback
|
| 104 |
+
int RtmpGuesterImpl::OnNeedPlayAudio(void* audioSamples, uint32_t& samplesPerSec, size_t& nChannels)
|
| 105 |
+
{
|
| 106 |
+
return ((webrtc::AnyRtmplayerImpl*)av_rtmp_player_)->GetNeedPlayAudio(audioSamples, samplesPerSec, nChannels);
|
| 107 |
+
}
|
pool/shard002/C++/0024435_dist1.cpp
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* The following code example is taken from the book
|
| 2 |
+
* "The C++ Standard Library - A Tutorial and Reference, 2nd Edition"
|
| 3 |
+
* by Nicolai M. Josuttis, Addison-Wesley, 2012
|
| 4 |
+
*
|
| 5 |
+
* (C) Copyright Nicolai M. Josuttis 2012.
|
| 6 |
+
* Permission to copy, use, modify, sell and distribute this software
|
| 7 |
+
* is granted provided this copyright notice appears in all copies.
|
| 8 |
+
* This software is provided "as is" without express or implied
|
| 9 |
+
* warranty, and with no claim as to its suitability for any purpose.
|
| 10 |
+
*/
|
| 11 |
+
#include <random>
|
| 12 |
+
#include <map>
|
| 13 |
+
#include <string>
|
| 14 |
+
#include <iostream>
|
| 15 |
+
#include <iomanip>
|
| 16 |
+
|
| 17 |
+
template <typename Distr, typename Eng>
|
| 18 |
+
void distr (Distr d, Eng e, const std::string& name)
|
| 19 |
+
{
|
| 20 |
+
// print min, max and four example values
|
| 21 |
+
std::cout << name << ":" << std::endl;
|
| 22 |
+
std::cout << "- min(): " << d.min() << std::endl;
|
| 23 |
+
std::cout << "- max(): " << d.max() << std::endl;
|
| 24 |
+
std::cout << "- values: " << d(e) << ' ' << d(e) << ' '
|
| 25 |
+
<< d(e) << ' ' << d(e) << std::endl;
|
| 26 |
+
|
| 27 |
+
// count the generated values (converted to integral values)
|
| 28 |
+
std::map<long long,int> valuecounter;
|
| 29 |
+
for (int i=0; i<200000; ++i) {
|
| 30 |
+
valuecounter[d(e)]++;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
// and print the resulting distribution
|
| 34 |
+
std::cout << "====" << std::endl;
|
| 35 |
+
for (auto elem : valuecounter) {
|
| 36 |
+
std::cout << std::setw(3) << elem.first << ": "
|
| 37 |
+
<< elem.second << std::endl;
|
| 38 |
+
}
|
| 39 |
+
std::cout << "====" << std::endl;
|
| 40 |
+
std::cout << std::endl;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
int main()
|
| 44 |
+
{
|
| 45 |
+
std::knuth_b e;
|
| 46 |
+
|
| 47 |
+
std::uniform_real_distribution<> ud(0, 10);
|
| 48 |
+
distr(ud,e,"uniform_real_distribution");
|
| 49 |
+
|
| 50 |
+
std::normal_distribution<> nd;
|
| 51 |
+
distr(nd,e,"normal_distribution");
|
| 52 |
+
|
| 53 |
+
std::exponential_distribution<> ed;
|
| 54 |
+
distr(ed,e,"exponential_distribution");
|
| 55 |
+
|
| 56 |
+
std::gamma_distribution<> gd;
|
| 57 |
+
distr(gd,e,"gamma_distribution");
|
| 58 |
+
}
|
pool/shard002/C++/0024438_directory.cpp
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @file
|
| 3 |
+
* @author shrek0 (shrek0.tk@gmail.com)
|
| 4 |
+
* @class
|
| 5 |
+
* @section LICENSE
|
| 6 |
+
*
|
| 7 |
+
* Process copyright (C) 2015 shrek0
|
| 8 |
+
*
|
| 9 |
+
* Process 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 3 of the License, or
|
| 12 |
+
* (at your option) any later version.
|
| 13 |
+
*
|
| 14 |
+
* Process 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, see <http://www.gnu.org/licenses/>.
|
| 21 |
+
*
|
| 22 |
+
* @section DESCRIPTION
|
| 23 |
+
*
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
#include "directory.h"
|
| 27 |
+
|
| 28 |
+
#include <stdexcept>
|
| 29 |
+
|
| 30 |
+
Directory::Directory(const std::string &directoryPath)
|
| 31 |
+
{
|
| 32 |
+
mPDir = opendir(directoryPath.c_str());
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
std::list<dirent> Directory::getFiles() {
|
| 36 |
+
dirent *directoryEntry = nullptr;
|
| 37 |
+
std::list<dirent> files;
|
| 38 |
+
|
| 39 |
+
while((directoryEntry = readdir(mPDir)) > 0)
|
| 40 |
+
{
|
| 41 |
+
files.push_front(*directoryEntry);
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
return files;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
dirent Directory::find(const std::string &entryName) {
|
| 48 |
+
dirent *directoryEntry = nullptr;
|
| 49 |
+
|
| 50 |
+
while((directoryEntry = readdir(mPDir)) > 0) {
|
| 51 |
+
if(entryName == directoryEntry->d_name)
|
| 52 |
+
return *directoryEntry;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
throw std::invalid_argument("find: Not Found");
|
| 56 |
+
}
|
pool/shard002/C++/0024446_cpredictivesearchsettingstable.cpp
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
| 3 |
+
* All rights reserved.
|
| 4 |
+
* This component and the accompanying materials are made available
|
| 5 |
+
* under the terms of "Eclipse Public License v1.0"
|
| 6 |
+
* which accompanies this distribution, and is available
|
| 7 |
+
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
| 8 |
+
*
|
| 9 |
+
* Initial Contributors:
|
| 10 |
+
* Nokia Corporation - initial contribution.
|
| 11 |
+
*
|
| 12 |
+
* Contributors:
|
| 13 |
+
*
|
| 14 |
+
* Description:
|
| 15 |
+
*
|
| 16 |
+
*/
|
| 17 |
+
|
| 18 |
+
#include "cpredictivesearchsettingstable.h"
|
| 19 |
+
#include "dbsqlconstants.h"
|
| 20 |
+
|
| 21 |
+
// This macro suppresses log writes
|
| 22 |
+
//#define NO_PRED_SEARCH_LOGS
|
| 23 |
+
#include "predictivesearchlog.h"
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
_LIT(KSqlContactPredSearchSettingsTable, "pred_search_settings");
|
| 27 |
+
|
| 28 |
+
_LIT(KCreatePredSearchSettingsTable, "CREATE TABLE pred_search_settings (language INTEGER);");
|
| 29 |
+
|
| 30 |
+
_LIT(KPredSearchSettingsLanguage, "language");
|
| 31 |
+
|
| 32 |
+
// How many characters the decimal representation of enum QLocale::Language
|
| 33 |
+
// requires.
|
| 34 |
+
const TInt KSizeOfLanguageValue = 8;
|
| 35 |
+
|
| 36 |
+
//_LIT(KInsertFormat, "INSERT INTO pred_search_settings (language) VALUES (%d);");
|
| 37 |
+
// e.g. "INSERT INTO pred_search_settings (language) VALUES (8);"
|
| 38 |
+
_LIT(KInsertFormat, "INSERT INTO %S (%S) VALUES (%d);");
|
| 39 |
+
|
| 40 |
+
// e.g. "UPDATE pred_search_settings SET language = 9;"
|
| 41 |
+
_LIT(KUpdateFormat, "UPDATE %S SET %S = %d;");
|
| 42 |
+
|
| 43 |
+
// e.g. "SELECT language FROM pred_search_settings;"
|
| 44 |
+
_LIT(KSelectFormat, "SELECT %S FROM %S;");
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
CPredictiveSearchSettingsTable*
|
| 49 |
+
CPredictiveSearchSettingsTable::NewL(RSqlDatabase& aDatabase)
|
| 50 |
+
{
|
| 51 |
+
PRINT(_L("CPredictiveSearchSettingsTable::NewL"));
|
| 52 |
+
CPredictiveSearchSettingsTable* self =
|
| 53 |
+
CPredictiveSearchSettingsTable::NewLC(aDatabase);
|
| 54 |
+
CleanupStack::Pop(self);
|
| 55 |
+
PRINT(_L("CPredictiveSearchSettingsTable::NewL ends"));
|
| 56 |
+
return self;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
CPredictiveSearchSettingsTable*
|
| 60 |
+
CPredictiveSearchSettingsTable::NewLC(RSqlDatabase& aDatabase)
|
| 61 |
+
{
|
| 62 |
+
PRINT(_L("CPredictiveSearchSettingsTable::NewLC"));
|
| 63 |
+
CPredictiveSearchSettingsTable* self =
|
| 64 |
+
new (ELeave) CPredictiveSearchSettingsTable(aDatabase);
|
| 65 |
+
CleanupStack::PushL(self);
|
| 66 |
+
self->ConstructL();
|
| 67 |
+
PRINT(_L("CPredictiveSearchSettingsTable::NewLC ends"));
|
| 68 |
+
return self;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
CPredictiveSearchSettingsTable::~CPredictiveSearchSettingsTable()
|
| 72 |
+
{
|
| 73 |
+
PRINT(_L("CPredictiveSearchSettingsTable dtor"));
|
| 74 |
+
PRINT(_L("CPredictiveSearchSettingsTable dtor ends"));
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
void CPredictiveSearchSettingsTable::CreateInDbL(CContactItem& /*aItem*/)
|
| 78 |
+
{
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
void CPredictiveSearchSettingsTable::UpdateL(const CContactItem& /*aItem*/)
|
| 82 |
+
{
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
void CPredictiveSearchSettingsTable::DeleteL(const CContactItem& /*aItem*/,
|
| 86 |
+
TBool& /*aLowDiskErrorOccurred*/)
|
| 87 |
+
{
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
// Create table to an empty database, so there is no need to re-generate QWERTY
|
| 91 |
+
// tables.
|
| 92 |
+
void CPredictiveSearchSettingsTable::CreateTableL()
|
| 93 |
+
{
|
| 94 |
+
PRINT(_L("CPredictiveSearchSettingsTable::CreateTableL"));
|
| 95 |
+
|
| 96 |
+
User::LeaveIfError(iDatabase.Exec(KCreatePredSearchSettingsTable));
|
| 97 |
+
enum QLocale::Language language = GetCurrentLanguageL();
|
| 98 |
+
HBufC* insert = HBufC::NewLC(KInsertFormat().Length() +
|
| 99 |
+
KSqlContactPredSearchSettingsTable().Length() +
|
| 100 |
+
KPredSearchSettingsLanguage().Length() +
|
| 101 |
+
KSizeOfLanguageValue);
|
| 102 |
+
insert->Des().AppendFormat(KInsertFormat,
|
| 103 |
+
&KSqlContactPredSearchSettingsTable,
|
| 104 |
+
&KPredSearchSettingsLanguage,
|
| 105 |
+
language);
|
| 106 |
+
User::LeaveIfError(iDatabase.Exec(*insert));
|
| 107 |
+
CleanupStack::PopAndDestroy(insert);
|
| 108 |
+
|
| 109 |
+
PRINT(_L("CPredictiveSearchSettingsTable::CreateTableL ends"));
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
QList<QChar> CPredictiveSearchSettingsTable::FillAllTables() const
|
| 113 |
+
{
|
| 114 |
+
QList<QChar> tables;
|
| 115 |
+
tables.append('1'); // Add one character (does not matter what the character is)
|
| 116 |
+
return tables;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
HBufC* CPredictiveSearchSettingsTable::TableNameL(const QChar /*aCh*/) const
|
| 120 |
+
{
|
| 121 |
+
return KSqlContactPredSearchSettingsTable().AllocL();
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
TBool CPredictiveSearchSettingsTable::IsLanguageValidL() const
|
| 125 |
+
{
|
| 126 |
+
PRINT(_L("CPredictiveSearchSettingsTable::IsLanguageValidL"));
|
| 127 |
+
return ReadStoredLanguageL() == GetCurrentLanguageL();
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
void CPredictiveSearchSettingsTable::StoreCurrentLanguageL() const
|
| 131 |
+
{
|
| 132 |
+
PRINT(_L("CPredictiveSearchSettingsTable::StoreCurrentLanguageL"));
|
| 133 |
+
|
| 134 |
+
enum QLocale::Language language = GetCurrentLanguageL();
|
| 135 |
+
HBufC* update = HBufC::NewLC(KUpdateFormat().Length() +
|
| 136 |
+
KSqlContactPredSearchSettingsTable().Length() +
|
| 137 |
+
KPredSearchSettingsLanguage().Length() +
|
| 138 |
+
KSizeOfLanguageValue);
|
| 139 |
+
update->Des().AppendFormat(KUpdateFormat,
|
| 140 |
+
&KSqlContactPredSearchSettingsTable,
|
| 141 |
+
&KPredSearchSettingsLanguage,
|
| 142 |
+
language);
|
| 143 |
+
User::LeaveIfError(iDatabase.Exec(*update));
|
| 144 |
+
CleanupStack::PopAndDestroy(update);
|
| 145 |
+
|
| 146 |
+
PRINT(_L("CPredictiveSearchSettingsTable::StoreCurrentLanguageL ends"));
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
void CPredictiveSearchSettingsTable::ConstructL()
|
| 150 |
+
{
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
enum QLocale::Language CPredictiveSearchSettingsTable::GetCurrentLanguageL() const
|
| 154 |
+
{
|
| 155 |
+
enum QLocale::Language language(QLocale::C);
|
| 156 |
+
QT_TRYCATCH_LEAVING(language = QLocale::system().language());
|
| 157 |
+
PRINT1(_L("CPredictiveSearchSettingsTable::GetCurrentLanguageL ret=%d"), language);
|
| 158 |
+
return language;
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
enum QLocale::Language CPredictiveSearchSettingsTable::ReadStoredLanguageL() const
|
| 162 |
+
{
|
| 163 |
+
TInt bufSize = KSelectFormat().Length() +
|
| 164 |
+
KPredSearchSettingsLanguage().Length() +
|
| 165 |
+
KSqlContactPredSearchSettingsTable().Length();
|
| 166 |
+
HBufC* select = HBufC::NewLC(bufSize);
|
| 167 |
+
select->Des().AppendFormat(KSelectFormat,
|
| 168 |
+
&KPredSearchSettingsLanguage,
|
| 169 |
+
&KSqlContactPredSearchSettingsTable);
|
| 170 |
+
|
| 171 |
+
RSqlStatement stmnt;
|
| 172 |
+
CleanupClosePushL(stmnt);
|
| 173 |
+
PRINT1(_L("CPredictiveSearchSettingsTable::ReadStoredLanguageL SQL:%S"), select);
|
| 174 |
+
stmnt.PrepareL(iDatabase, *select);
|
| 175 |
+
|
| 176 |
+
const TInt KLanguageIndex = 0;
|
| 177 |
+
TInt err = stmnt.Next();
|
| 178 |
+
enum QLocale::Language language(QLocale::C);
|
| 179 |
+
if (err == KSqlAtRow)
|
| 180 |
+
{
|
| 181 |
+
language = static_cast<QLocale::Language>(stmnt.ColumnInt(KLanguageIndex));
|
| 182 |
+
PRINT1(_L("read language=%d from DB"), language);
|
| 183 |
+
}
|
| 184 |
+
CleanupStack::PopAndDestroy(&stmnt);
|
| 185 |
+
CleanupStack::PopAndDestroy(select);
|
| 186 |
+
|
| 187 |
+
if (err != KSqlAtRow)
|
| 188 |
+
{
|
| 189 |
+
PRINT1(_L("CPredictiveSearchSettingsTable::ReadStoredLanguageL err=%d"), err);
|
| 190 |
+
User::Leave(err);
|
| 191 |
+
}
|
| 192 |
+
PRINT1(_L("CPredictiveSearchSettingsTable::ReadStoredLanguageL ret=%d"), language);
|
| 193 |
+
return language;
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
/**
|
| 197 |
+
Constructor
|
| 198 |
+
*/
|
| 199 |
+
CPredictiveSearchSettingsTable::CPredictiveSearchSettingsTable(
|
| 200 |
+
RSqlDatabase& aDatabase) :
|
| 201 |
+
CPplPredictiveSearchTableBase(aDatabase, 0, 0)
|
| 202 |
+
{
|
| 203 |
+
}
|
pool/shard002/C++/0024455_ObjectManager.cpp
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "ObjectManager.h"
|
| 2 |
+
#include <cmath>
|
| 3 |
+
#include <vector>
|
| 4 |
+
#include "types.h"
|
| 5 |
+
#include "Object.h"
|
| 6 |
+
#include <cstring>
|
| 7 |
+
#include <iostream>
|
| 8 |
+
//#include "Pond.h"
|
| 9 |
+
#include "Camera.h"
|
| 10 |
+
|
| 11 |
+
ObjectManager::ObjectManager()
|
| 12 |
+
{
|
| 13 |
+
Init();
|
| 14 |
+
//pool = new Pond(this);
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
bool ObjectManager::Init(){
|
| 18 |
+
distance=0;
|
| 19 |
+
return true;
|
| 20 |
+
}
|
| 21 |
+
bool ObjectManager::Update()
|
| 22 |
+
{
|
| 23 |
+
//iterate through the objectList vector and check each collison
|
| 24 |
+
|
| 25 |
+
for(std::vector<Object*>::iterator it=objectList.begin();it!=objectList.end();++it){
|
| 26 |
+
//for each object after this object
|
| 27 |
+
Object* a = *it;
|
| 28 |
+
/*if(a->type==0){
|
| 29 |
+
continue;
|
| 30 |
+
}*/
|
| 31 |
+
for(std::vector<Object*>::iterator ti=(it + 1);ti!=objectList.end();++ti){
|
| 32 |
+
|
| 33 |
+
Object* b = *ti;
|
| 34 |
+
/*if(b->type==0){
|
| 35 |
+
continue;
|
| 36 |
+
}*/
|
| 37 |
+
distance = std::sqrt(std::pow((a->position.x+a->velocity.x)-(b->position.x+b->velocity.x),2)+
|
| 38 |
+
std::pow((a->position.y+a->velocity.y)-(b->position.y+b->velocity.y),2)+
|
| 39 |
+
std::pow((a->position.z+a->velocity.z)-(b->position.z+b->velocity.z),2));
|
| 40 |
+
|
| 41 |
+
if(distance<(a->collisionRadius+b->collisionRadius)){
|
| 42 |
+
//we have a collision, set both objects' velocity to 0
|
| 43 |
+
a->velocity.x=0;
|
| 44 |
+
a->velocity.y=0;
|
| 45 |
+
a->velocity.z=0;
|
| 46 |
+
|
| 47 |
+
b->velocity.x=0;
|
| 48 |
+
b->velocity.y=0;
|
| 49 |
+
b->velocity.z=0;
|
| 50 |
+
|
| 51 |
+
}
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
//Now we have the correct velocities for each object and can move them.
|
| 55 |
+
|
| 56 |
+
for(std::vector<Object*>::iterator it=objectList.begin();it!=objectList.end();++it){
|
| 57 |
+
Object* a = *it;
|
| 58 |
+
/*if(a->type==0){
|
| 59 |
+
a->Update();
|
| 60 |
+
continue;
|
| 61 |
+
}*/
|
| 62 |
+
a->position.x=(a->velocity.x)+(a->position.x);
|
| 63 |
+
a->position.y=(a->velocity.y)+(a->position.y);
|
| 64 |
+
a->position.z=(a->velocity.z)+(a->position.z);
|
| 65 |
+
|
| 66 |
+
a->Update();
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
return true;
|
| 70 |
+
}
|
| 71 |
+
bool ObjectManager::addObject(Object* object)
|
| 72 |
+
{
|
| 73 |
+
this->objectList.push_back(object);
|
| 74 |
+
return true;
|
| 75 |
+
}
|
| 76 |
+
Object* ObjectManager::getObjectById(char name[])
|
| 77 |
+
{
|
| 78 |
+
for(std::vector<Object*>::iterator it=objectList.begin();it!=objectList.end();++it){
|
| 79 |
+
Object* a = *it;
|
| 80 |
+
if(std::strcmp(name,a->id)==0){
|
| 81 |
+
return a;
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
return 0;
|
| 85 |
+
}
|
pool/shard002/C++/0024457_Vector4_TEST.cc
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C) 2012-2014 Open Source Robotics Foundation
|
| 3 |
+
*
|
| 4 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
* you may not use this file except in compliance with the License.
|
| 6 |
+
* You may obtain a copy of the License at
|
| 7 |
+
*
|
| 8 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
*
|
| 10 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
* See the License for the specific language governing permissions and
|
| 14 |
+
* limitations under the License.
|
| 15 |
+
*
|
| 16 |
+
*/
|
| 17 |
+
|
| 18 |
+
#include <gtest/gtest.h>
|
| 19 |
+
|
| 20 |
+
#include "gazebo/math/Vector4.hh"
|
| 21 |
+
|
| 22 |
+
using namespace gazebo;
|
| 23 |
+
|
| 24 |
+
TEST(Vector4Test, Vector4)
|
| 25 |
+
{
|
| 26 |
+
{
|
| 27 |
+
math::Vector4 v;
|
| 28 |
+
EXPECT_TRUE(math::equal(v.x, 0.0));
|
| 29 |
+
EXPECT_TRUE(math::equal(v.y, 0.0));
|
| 30 |
+
EXPECT_TRUE(math::equal(v.z, 0.0));
|
| 31 |
+
EXPECT_TRUE(math::equal(v.w, 0.0));
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
math::Vector4 v1(1, 2, 3, 4);
|
| 35 |
+
EXPECT_TRUE(math::equal(v1.x, 1.0));
|
| 36 |
+
EXPECT_TRUE(math::equal(v1.y, 2.0));
|
| 37 |
+
EXPECT_TRUE(math::equal(v1.z, 3.0));
|
| 38 |
+
EXPECT_TRUE(math::equal(v1.w, 4.0));
|
| 39 |
+
|
| 40 |
+
math::Vector4 v(v1);
|
| 41 |
+
EXPECT_TRUE(v == v1);
|
| 42 |
+
|
| 43 |
+
EXPECT_TRUE(math::equal(v.Distance(math::Vector4(0, 0, 0, 0)), 5.4772, 1e-3));
|
| 44 |
+
|
| 45 |
+
// ::GetLength()
|
| 46 |
+
v.Set(1, 2, 3, 4);
|
| 47 |
+
EXPECT_TRUE(math::equal(v.GetLength(), 5.4772, 1e-3));
|
| 48 |
+
|
| 49 |
+
// ::GetSquaredLength()
|
| 50 |
+
EXPECT_TRUE(math::equal(v.GetSquaredLength(), 30.0));
|
| 51 |
+
|
| 52 |
+
// ::Normalize
|
| 53 |
+
v.Normalize();
|
| 54 |
+
EXPECT_TRUE(v == math::Vector4(0.182574, 0.365148, 0.547723, 0.730297));
|
| 55 |
+
|
| 56 |
+
// ::Set
|
| 57 |
+
v.Set(2, 4, 6, 8);
|
| 58 |
+
EXPECT_TRUE(v == math::Vector4(2, 4, 6, 8));
|
| 59 |
+
|
| 60 |
+
// ::operator= vector4
|
| 61 |
+
v = v1;
|
| 62 |
+
EXPECT_TRUE(v == v1);
|
| 63 |
+
|
| 64 |
+
// ::operator= double
|
| 65 |
+
v = 1.2;
|
| 66 |
+
EXPECT_TRUE(v == math::Vector4(1.2, 1.2, 1.2, 1.2));
|
| 67 |
+
|
| 68 |
+
// ::operator+ vector4
|
| 69 |
+
v = v + math::Vector4(1, 2, 3, 4);
|
| 70 |
+
EXPECT_TRUE(v == math::Vector4(2.2, 3.2, 4.2, 5.2));
|
| 71 |
+
|
| 72 |
+
// ::operator+=
|
| 73 |
+
v += v;
|
| 74 |
+
EXPECT_TRUE(v == math::Vector4(4.4, 6.4, 8.4, 10.4));
|
| 75 |
+
|
| 76 |
+
// ::operator- vector4
|
| 77 |
+
v = v - math::Vector4(1, 1, 1, 1);
|
| 78 |
+
EXPECT_TRUE(v == math::Vector4(3.4, 5.4, 7.4, 9.4));
|
| 79 |
+
|
| 80 |
+
// ::operator-= vector4
|
| 81 |
+
v -= math::Vector4(1, 1, 1, 1);
|
| 82 |
+
EXPECT_TRUE(v == math::Vector4(2.4, 4.4, 6.4, 8.4));
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
// ::operator/ vector4
|
| 86 |
+
v = v / math::Vector4(.1, .1, .1, .1);
|
| 87 |
+
EXPECT_TRUE(v == math::Vector4(24, 44, 64, 84));
|
| 88 |
+
|
| 89 |
+
// ::operator/ double
|
| 90 |
+
v = v / 2.0;
|
| 91 |
+
EXPECT_TRUE(v == math::Vector4(12, 22, 32, 42));
|
| 92 |
+
|
| 93 |
+
// ::operator/= vector4
|
| 94 |
+
v /= math::Vector4(4, 4, 4, 4);
|
| 95 |
+
EXPECT_TRUE(v == math::Vector4(3, 5.5, 8, 10.5));
|
| 96 |
+
|
| 97 |
+
// ::operator/= double
|
| 98 |
+
v /= .1;
|
| 99 |
+
EXPECT_TRUE(v == math::Vector4(30, 55, 80, 105));
|
| 100 |
+
|
| 101 |
+
// ::operator * matrix4
|
| 102 |
+
v = v * math::Matrix4(1, 2, 3, 4,
|
| 103 |
+
5, 6, 7, 8,
|
| 104 |
+
9, 10, 11, 12,
|
| 105 |
+
13, 14, 15, 16);
|
| 106 |
+
EXPECT_TRUE(v == math::Vector4(2390, 2660, 2930, 3200));
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
// ::operator * vector4
|
| 110 |
+
v = v * math::Vector4(.2, .3, .4, .5);
|
| 111 |
+
EXPECT_TRUE(v == math::Vector4(478, 798, 1172, 1600));
|
| 112 |
+
|
| 113 |
+
// ::operator *= vector4
|
| 114 |
+
v *= math::Vector4(2, 4, 6, 8);
|
| 115 |
+
EXPECT_TRUE(v == math::Vector4(956, 3192, 7032, 12800));
|
| 116 |
+
|
| 117 |
+
// ::operator * double
|
| 118 |
+
v = v * 5.2;
|
| 119 |
+
EXPECT_TRUE(v == math::Vector4(4971.2, 16598.4, 36566.4, 66560));
|
| 120 |
+
|
| 121 |
+
// ::operator *= double
|
| 122 |
+
v *= 10.0;
|
| 123 |
+
EXPECT_TRUE(v == math::Vector4(49712, 1.65984e+05, 3.65664e+05, 6.656e+05));
|
| 124 |
+
|
| 125 |
+
// ::operator != vector4
|
| 126 |
+
EXPECT_TRUE(v != math::Vector4());
|
| 127 |
+
|
| 128 |
+
// ::IsFinite
|
| 129 |
+
EXPECT_TRUE(v.IsFinite());
|
| 130 |
+
|
| 131 |
+
// ::operator[]
|
| 132 |
+
v.Set(1, 2, 3, 4);
|
| 133 |
+
EXPECT_DOUBLE_EQ(v[0], 1);
|
| 134 |
+
EXPECT_DOUBLE_EQ(v[1], 2);
|
| 135 |
+
EXPECT_DOUBLE_EQ(v[2], 3);
|
| 136 |
+
EXPECT_DOUBLE_EQ(v[3], 4);
|
| 137 |
+
}
|
pool/shard002/C++/0024464_CRendererOGLES1_1.cpp
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// CRendererOGLES1_1.h
|
| 3 |
+
// OpenJam
|
| 4 |
+
//
|
| 5 |
+
// Created by Yevgeniy Logachev
|
| 6 |
+
// Copyright (c) 2014 yev. All rights reserved.
|
| 7 |
+
//
|
| 8 |
+
#if defined(RENDER_OGLES1_1)
|
| 9 |
+
|
| 10 |
+
#include "CRendererOGLES1_1.h"
|
| 11 |
+
|
| 12 |
+
#include "CVertexBufferOGLES1_1.h"
|
| 13 |
+
#include "CIndexBufferOGLES1_1.h"
|
| 14 |
+
#include "CMaterialOGLES1_1.h"
|
| 15 |
+
#include "CTextureOGLES1_1.h"
|
| 16 |
+
#include "CMeshOGLES1_1.h"
|
| 17 |
+
#include "CShaderOGLES1_1.h"
|
| 18 |
+
#include "CShaderProgramOGLES1_1.h"
|
| 19 |
+
#include "CFrameBufferOGLES1_1.h"
|
| 20 |
+
#include "CRenderTargetColorOGLES1_1.h"
|
| 21 |
+
#include "CRenderTargetDepthOGLES1_1.h"
|
| 22 |
+
#include "CRenderTargetStencilOGLES1_1.h"
|
| 23 |
+
#include "CRenderTargetTextureOGLES1_1.h"
|
| 24 |
+
|
| 25 |
+
using namespace jam;
|
| 26 |
+
|
| 27 |
+
// *****************************************************************************
|
| 28 |
+
// Constants
|
| 29 |
+
// *****************************************************************************
|
| 30 |
+
|
| 31 |
+
// *****************************************************************************
|
| 32 |
+
// Public Methods
|
| 33 |
+
// *****************************************************************************
|
| 34 |
+
|
| 35 |
+
CRendererOGLES1_1::CRendererOGLES1_1(IRenderViewPtr renderView)
|
| 36 |
+
: CRendererOGLBase(renderView)
|
| 37 |
+
{
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
CRendererOGLES1_1::~CRendererOGLES1_1()
|
| 41 |
+
{
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
IFrameBufferPtr CRendererOGLES1_1::CreateFrameBuffer(uint32_t width, uint32_t height)
|
| 45 |
+
{
|
| 46 |
+
IFrameBufferPtr frameBuffer(new CFrameBufferOGLES1_1(width, height));
|
| 47 |
+
return frameBuffer;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
CRenderTargetColorPtr CRendererOGLES1_1::CreateColorRenderTarget()
|
| 51 |
+
{
|
| 52 |
+
CRenderTargetColorPtr colorTarget(new CRenderTargetColorOGLES1_1());
|
| 53 |
+
return colorTarget;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
CRenderTargetDepthPtr CRendererOGLES1_1::CreateDepthRenderTarget()
|
| 57 |
+
{
|
| 58 |
+
CRenderTargetDepthPtr depthTarget(new CRenderTargetDepthOGLES1_1());
|
| 59 |
+
return depthTarget;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
CRenderTargetStencilPtr CRendererOGLES1_1::CreateStencilRenderTarget()
|
| 63 |
+
{
|
| 64 |
+
CRenderTargetStencilPtr stencilTarget(new CRenderTargetStencilOGLES1_1());
|
| 65 |
+
return stencilTarget;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
CRenderTargetTexturePtr CRendererOGLES1_1::CreateTextureRenderTarget()
|
| 69 |
+
{
|
| 70 |
+
CRenderTargetTexturePtr textureTarget(new CRenderTargetTextureOGLES1_1());
|
| 71 |
+
return textureTarget;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
IVertexBufferPtr CRendererOGLES1_1::CreateVertexBuffer()
|
| 75 |
+
{
|
| 76 |
+
IVertexBufferPtr vertexBuffer(new CVertexBufferOGLES1_1());
|
| 77 |
+
return vertexBuffer;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
IIndexBufferPtr CRendererOGLES1_1::CreateIndexBuffer()
|
| 81 |
+
{
|
| 82 |
+
IIndexBufferPtr indexBuffer(new CIndexBufferOGLES1_1());
|
| 83 |
+
return indexBuffer;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
ITexturePtr CRendererOGLES1_1::CreateTexture()
|
| 87 |
+
{
|
| 88 |
+
ITexturePtr texture(new CTextureOGLES1_1());
|
| 89 |
+
return texture;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
IMaterialPtr CRendererOGLES1_1::CreateMaterial()
|
| 93 |
+
{
|
| 94 |
+
IMaterialPtr material(new CMaterialOGLES1_1());
|
| 95 |
+
return material;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
IMeshPtr CRendererOGLES1_1::CreateMesh()
|
| 99 |
+
{
|
| 100 |
+
IMeshPtr mesh(new CMeshOGLES1_1());
|
| 101 |
+
return mesh;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
IShaderPtr CRendererOGLES1_1::CreateShader()
|
| 105 |
+
{
|
| 106 |
+
IShaderPtr shader(new CShaderOGLES1_1());
|
| 107 |
+
return shader;
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
IShaderProgramPtr CRendererOGLES1_1::CreateShaderProgram()
|
| 111 |
+
{
|
| 112 |
+
IShaderProgramPtr shaderProgram(new CShaderProgramOGLES1_1());
|
| 113 |
+
return shaderProgram;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
void CRendererOGLES1_1::Draw(IMeshPtr mesh, IMaterialPtr material, IShaderProgramPtr shader)
|
| 117 |
+
{
|
| 118 |
+
if (!mesh || !material) {
|
| 119 |
+
return;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
const IShaderProgram::TUniMatrix4Float& uniforms = shader->UniformsMatrix4x4f();
|
| 123 |
+
IShaderProgram::TUniMatrix4Float::const_iterator it = uniforms.find(shader->ProjectionMatrix());
|
| 124 |
+
glMatrixMode(GL_PROJECTION);
|
| 125 |
+
if (it != uniforms.end()) {
|
| 126 |
+
glLoadMatrixf(glm::value_ptr(it->second));
|
| 127 |
+
} else {
|
| 128 |
+
glLoadMatrixf(glm::value_ptr(glm::mat4(1.0)));
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
glMatrixMode(GL_MODELVIEW);
|
| 132 |
+
it = uniforms.find(shader->ModelMatrix());
|
| 133 |
+
if (it != uniforms.end()) {
|
| 134 |
+
glLoadMatrixf(glm::value_ptr(it->second));
|
| 135 |
+
} else {
|
| 136 |
+
glLoadMatrixf(glm::value_ptr(glm::mat4(1.0)));
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
if (mesh->IndexBuffer()) {
|
| 140 |
+
Draw(mesh->VertexBuffer(), mesh->IndexBuffer(), material);
|
| 141 |
+
} else {
|
| 142 |
+
Draw(mesh->VertexBuffer(), material);
|
| 143 |
+
}
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
void CRendererOGLES1_1::Draw(IVertexBufferPtr vertexBuffer, IMaterialPtr material)
|
| 147 |
+
{
|
| 148 |
+
if (!vertexBuffer || !material) {
|
| 149 |
+
return;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
int primitiveType = ConvertPrimitiveType(material->PrimitiveType());
|
| 153 |
+
glDrawArrays(primitiveType, 0, (GLsizei)vertexBuffer->Size());
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
void CRendererOGLES1_1::Draw(IVertexBufferPtr vertexBuffer, IIndexBufferPtr indexBuffer, IMaterialPtr material)
|
| 157 |
+
{
|
| 158 |
+
if (!vertexBuffer || !indexBuffer || !material) {
|
| 159 |
+
return;
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
int primitiveType = ConvertPrimitiveType(material->PrimitiveType());
|
| 163 |
+
glDrawElements(primitiveType, (GLsizei)indexBuffer->Size(), GL_UNSIGNED_SHORT, nullptr);
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
// *****************************************************************************
|
| 167 |
+
// Protected Methods
|
| 168 |
+
// *****************************************************************************
|
| 169 |
+
|
| 170 |
+
// *****************************************************************************
|
| 171 |
+
// Private Methods
|
| 172 |
+
// *****************************************************************************
|
| 173 |
+
|
| 174 |
+
#endif /* defined(RENDER_OGLES1_1) */
|
pool/shard002/C++/0024468_rpc_stream.cpp
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
#include "rpc_stream.h"
|
| 4 |
+
|
| 5 |
+
//extern Serial pc;
|
| 6 |
+
|
| 7 |
+
void stream_init()
|
| 8 |
+
{
|
| 9 |
+
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
char stream_read()
|
| 13 |
+
{
|
| 14 |
+
int c = getchar();
|
| 15 |
+
if (c == EOF) return '\r';
|
| 16 |
+
return c;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
bool stream_write(char c)
|
| 20 |
+
{
|
| 21 |
+
return putchar(c);
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
bool stream_write_string(char *str, int len)
|
| 25 |
+
{
|
| 26 |
+
for (int i = 0; str[i] && i < len; i++)
|
| 27 |
+
{
|
| 28 |
+
stream_write(str[i]);
|
| 29 |
+
}
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
void writer_print(type_t type, const void *data, bool append_comma)
|
| 33 |
+
{
|
| 34 |
+
char buff[32];
|
| 35 |
+
switch (type)
|
| 36 |
+
{
|
| 37 |
+
case TYPE_BOOL:
|
| 38 |
+
case TYPE_UINT8:
|
| 39 |
+
sprintf(buff, "%hhu", *(uint8_t *)data);
|
| 40 |
+
break;
|
| 41 |
+
case TYPE_UINT16:
|
| 42 |
+
sprintf(buff, "%u", *(uint16_t *)data);
|
| 43 |
+
break;
|
| 44 |
+
case TYPE_UINT32:
|
| 45 |
+
sprintf(buff, "%lu", *(uint32_t *)data);
|
| 46 |
+
break;
|
| 47 |
+
case TYPE_INT8:
|
| 48 |
+
sprintf(buff, "%hhd", *(int8_t *)data);
|
| 49 |
+
break;
|
| 50 |
+
case TYPE_INT:
|
| 51 |
+
sprintf(buff, "%d", *(int *)data);
|
| 52 |
+
break;
|
| 53 |
+
case TYPE_INT16:
|
| 54 |
+
sprintf(buff, "%d", *(int16_t *)data);
|
| 55 |
+
break;
|
| 56 |
+
case TYPE_INT32:
|
| 57 |
+
sprintf(buff, "%ld", *(int32_t *)data);
|
| 58 |
+
break;
|
| 59 |
+
case TYPE_FLOAT:
|
| 60 |
+
sprintf(buff, "%f", *(float *)data);
|
| 61 |
+
break;
|
| 62 |
+
case TYPE_STRING:
|
| 63 |
+
stream_write('"');
|
| 64 |
+
stream_write_string((char *)data, 32);
|
| 65 |
+
stream_write('"');
|
| 66 |
+
return;
|
| 67 |
+
default:
|
| 68 |
+
break;
|
| 69 |
+
}
|
| 70 |
+
stream_write_string(buff, 32);
|
| 71 |
+
if(append_comma) stream_write(',');
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
void response_msg_open(char *msg_type)
|
| 75 |
+
{
|
| 76 |
+
char *msg1 = "{\"msg_type\":\"";
|
| 77 |
+
char *msg2 = "\", \"msg\":\"";
|
| 78 |
+
stream_write_string(msg1, strlen(msg1));
|
| 79 |
+
stream_write_string(msg_type, strlen(msg_type));
|
| 80 |
+
stream_write_string(msg2, strlen(msg2));
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
void response_msg_close()
|
| 84 |
+
{
|
| 85 |
+
char *msg3 = "\"}\r\n";
|
| 86 |
+
stream_write_string(msg3, strlen(msg3));
|
| 87 |
+
}
|
pool/shard002/C++/0024470_CheckBox.cpp
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "CheckBox.h"
|
| 2 |
+
#include "../GUIFactory.h"
|
| 3 |
+
|
| 4 |
+
CheckBox::CheckBox(GUIFactory* factory, MouseController* mouseController,
|
| 5 |
+
unique_ptr<Sprite> unchkdSprite, unique_ptr<Sprite> chckdSprite,
|
| 6 |
+
const pugi::char_t* font) : GUIControl(factory, mouseController) {
|
| 7 |
+
|
| 8 |
+
uncheckedSprite = move(unchkdSprite);
|
| 9 |
+
checkedSprite = move(chckdSprite);
|
| 10 |
+
|
| 11 |
+
uncheckedSprite->setOrigin(Vector2(0, 0));
|
| 12 |
+
checkedSprite->setOrigin(Vector2(0, 0));
|
| 13 |
+
Vector2 size = Vector2((float) uncheckedSprite->getWidth(), (float) uncheckedSprite->getHeight());
|
| 14 |
+
|
| 15 |
+
hitArea.size = size;
|
| 16 |
+
|
| 17 |
+
label.reset(guiFactory->createTextLabel(Vector2::Zero, L"", font));
|
| 18 |
+
|
| 19 |
+
texture = uncheckedSprite->getTexture();
|
| 20 |
+
currentRECT = uncheckedSprite->getRect();
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
CheckBox::~CheckBox() {
|
| 24 |
+
|
| 25 |
+
if (actionListener != NULL)
|
| 26 |
+
delete actionListener;
|
| 27 |
+
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
void CheckBox::reloadGraphicsAsset() {
|
| 31 |
+
texture.Reset();
|
| 32 |
+
uncheckedSprite->reloadGraphicsAsset(guiFactory);
|
| 33 |
+
checkedSprite->reloadGraphicsAsset(guiFactory);
|
| 34 |
+
label->reloadGraphicsAsset();
|
| 35 |
+
|
| 36 |
+
if (isClicked) {
|
| 37 |
+
texture = checkedSprite->getTexture();
|
| 38 |
+
currentRECT = checkedSprite->getRect();
|
| 39 |
+
} else {
|
| 40 |
+
texture = uncheckedSprite->getTexture();
|
| 41 |
+
currentRECT = uncheckedSprite->getRect();
|
| 42 |
+
}
|
| 43 |
+
}
|
| 44 |
+
#include "../StringHelper.h"
|
| 45 |
+
bool CheckBox::update(double deltaTime) {
|
| 46 |
+
|
| 47 |
+
refreshed = false;
|
| 48 |
+
if (hitArea.contains(mouse->getPosition()) || label->contains(mouse->getPosition())) {
|
| 49 |
+
|
| 50 |
+
if (!isHover) {
|
| 51 |
+
isHover = true;
|
| 52 |
+
onHover();
|
| 53 |
+
}
|
| 54 |
+
} else if (isHover) {
|
| 55 |
+
resetState();
|
| 56 |
+
isHover = false;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
if (isHover) {
|
| 60 |
+
if (mouse->pressed()) {
|
| 61 |
+
isClicked = !isClicked;
|
| 62 |
+
onClick();
|
| 63 |
+
}
|
| 64 |
+
}
|
| 65 |
+
if (label->update(deltaTime))
|
| 66 |
+
refreshed = true;
|
| 67 |
+
|
| 68 |
+
return refreshed;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
void CheckBox::draw(SpriteBatch* batch) {
|
| 72 |
+
|
| 73 |
+
batch->Draw(texture.Get(), position, ¤tRECT, tint, rotation,
|
| 74 |
+
origin, scale, SpriteEffects_None, layerDepth);
|
| 75 |
+
label->draw(batch);
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
void CheckBox::setFont(const pugi::char_t* font) {
|
| 80 |
+
label->setFont(guiFactory->getFont(font));
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
void CheckBox::setText(wstring text) {
|
| 85 |
+
label->setText(text);
|
| 86 |
+
centerText();
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
void CheckBox::setPosition(const Vector2& pos) {
|
| 91 |
+
|
| 92 |
+
GUIControl::setPosition(pos);
|
| 93 |
+
|
| 94 |
+
uncheckedSprite->setPosition(position);
|
| 95 |
+
checkedSprite->setPosition(position);
|
| 96 |
+
|
| 97 |
+
centerText();
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
void CheckBox::setChecked(bool checked) {
|
| 102 |
+
isClicked = checked;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
void CheckBox::centerText() {
|
| 106 |
+
|
| 107 |
+
Vector2 labelSize = label->measureString();
|
| 108 |
+
labelOffset.y = (getHeight() - labelSize.y) / 2;
|
| 109 |
+
|
| 110 |
+
Vector2 labelPos = position;
|
| 111 |
+
labelPos.x += labelOffset.x + getWidth();
|
| 112 |
+
labelPos.y += labelOffset.y;
|
| 113 |
+
label->setPosition(labelPos);
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
void CheckBox::setScale(const Vector2& scl) {
|
| 117 |
+
|
| 118 |
+
GUIControl::setScale(scl);
|
| 119 |
+
uncheckedSprite->setScale(scale);
|
| 120 |
+
checkedSprite->setScale(scale);
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
const Vector2 XM_CALLCONV CheckBox::measureString() const {
|
| 125 |
+
return label->measureString();
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
const Vector2& CheckBox::getPosition() const {
|
| 129 |
+
return position;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
const int CheckBox::getWidth() const {
|
| 133 |
+
return uncheckedSprite->getWidth();
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
const int CheckBox::getHeight() const {
|
| 137 |
+
return uncheckedSprite->getHeight();
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
bool CheckBox::clicked() {
|
| 141 |
+
return isClicked;
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
bool CheckBox::pressed() {
|
| 145 |
+
return isPressed;
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
bool CheckBox::hovering() {
|
| 149 |
+
return isHover;
|
| 150 |
+
}
|
pool/shard002/C++/0024474_cs_lfg.cpp
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/>
|
| 3 |
+
*
|
| 4 |
+
* This program is free software; you can redistribute it and/or modify it
|
| 5 |
+
* under the terms of the GNU General Public License as published by the
|
| 6 |
+
* Free Software Foundation; either version 2 of the License, or (at your
|
| 7 |
+
* option) any later version.
|
| 8 |
+
*
|
| 9 |
+
* This program is distributed in the hope that it will be useful, but WITHOUT
|
| 10 |
+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
| 11 |
+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
| 12 |
+
* more details.
|
| 13 |
+
*
|
| 14 |
+
* You should have received a copy of the GNU General Public License along
|
| 15 |
+
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 16 |
+
*/
|
| 17 |
+
|
| 18 |
+
#include "ScriptMgr.h"
|
| 19 |
+
#include "Chat.h"
|
| 20 |
+
#include "DatabaseEnv.h"
|
| 21 |
+
#include "Group.h"
|
| 22 |
+
#include "GroupMgr.h"
|
| 23 |
+
#include "Language.h"
|
| 24 |
+
#include "LFGMgr.h"
|
| 25 |
+
#include "ObjectAccessor.h"
|
| 26 |
+
#include "ObjectMgr.h"
|
| 27 |
+
#include "Player.h"
|
| 28 |
+
#include "RBAC.h"
|
| 29 |
+
|
| 30 |
+
void GetPlayerInfo(ChatHandler* handler, Player* player)
|
| 31 |
+
{
|
| 32 |
+
if (!player)
|
| 33 |
+
return;
|
| 34 |
+
|
| 35 |
+
ObjectGuid guid = player->GetGUID();
|
| 36 |
+
lfg::LfgDungeonSet dungeons = sLFGMgr->GetSelectedDungeons(guid);
|
| 37 |
+
|
| 38 |
+
std::string const& state = lfg::GetStateString(sLFGMgr->GetState(guid));
|
| 39 |
+
handler->PSendSysMessage(LANG_LFG_PLAYER_INFO, player->GetName().c_str(),
|
| 40 |
+
state.c_str(), uint8(dungeons.size()), lfg::ConcatenateDungeons(dungeons).c_str(),
|
| 41 |
+
lfg::GetRolesString(sLFGMgr->GetRoles(guid)).c_str());
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
class lfg_commandscript : public CommandScript
|
| 45 |
+
{
|
| 46 |
+
public:
|
| 47 |
+
lfg_commandscript() : CommandScript("lfg_commandscript") { }
|
| 48 |
+
|
| 49 |
+
std::vector<ChatCommand> GetCommands() const override
|
| 50 |
+
{
|
| 51 |
+
static std::vector<ChatCommand> lfgCommandTable =
|
| 52 |
+
{
|
| 53 |
+
{ "player", rbac::RBAC_PERM_COMMAND_LFG_PLAYER, false, &HandleLfgPlayerInfoCommand, "" },
|
| 54 |
+
{ "group", rbac::RBAC_PERM_COMMAND_LFG_GROUP, false, &HandleLfgGroupInfoCommand, "" },
|
| 55 |
+
{ "queue", rbac::RBAC_PERM_COMMAND_LFG_QUEUE, true, &HandleLfgQueueInfoCommand, "" },
|
| 56 |
+
{ "clean", rbac::RBAC_PERM_COMMAND_LFG_CLEAN, true, &HandleLfgCleanCommand, "" },
|
| 57 |
+
{ "options", rbac::RBAC_PERM_COMMAND_LFG_OPTIONS, true, &HandleLfgOptionsCommand, "" },
|
| 58 |
+
};
|
| 59 |
+
|
| 60 |
+
static std::vector<ChatCommand> commandTable =
|
| 61 |
+
{
|
| 62 |
+
{ "lfg", rbac::RBAC_PERM_COMMAND_LFG, true, NULL, "", lfgCommandTable },
|
| 63 |
+
};
|
| 64 |
+
return commandTable;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
static bool HandleLfgPlayerInfoCommand(ChatHandler* handler, char const* args)
|
| 68 |
+
{
|
| 69 |
+
Player* target = NULL;
|
| 70 |
+
std::string playerName;
|
| 71 |
+
if (!handler->extractPlayerTarget((char*)args, &target, NULL, &playerName))
|
| 72 |
+
return false;
|
| 73 |
+
|
| 74 |
+
GetPlayerInfo(handler, target);
|
| 75 |
+
return true;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
static bool HandleLfgGroupInfoCommand(ChatHandler* handler, char const* args)
|
| 79 |
+
{
|
| 80 |
+
Player* playerTarget;
|
| 81 |
+
ObjectGuid guidTarget;
|
| 82 |
+
std::string nameTarget;
|
| 83 |
+
|
| 84 |
+
ObjectGuid parseGUID = ObjectGuid::Create<HighGuid::Player>(uint64(atoull(args)));
|
| 85 |
+
|
| 86 |
+
if (sObjectMgr->GetPlayerNameByGUID(parseGUID, nameTarget))
|
| 87 |
+
{
|
| 88 |
+
playerTarget = ObjectAccessor::FindPlayer(parseGUID);
|
| 89 |
+
guidTarget = parseGUID;
|
| 90 |
+
}
|
| 91 |
+
else if (!handler->extractPlayerTarget((char*)args, &playerTarget, &guidTarget, &nameTarget))
|
| 92 |
+
return false;
|
| 93 |
+
|
| 94 |
+
Group* groupTarget = NULL;
|
| 95 |
+
|
| 96 |
+
if (playerTarget)
|
| 97 |
+
groupTarget = playerTarget->GetGroup();
|
| 98 |
+
else
|
| 99 |
+
{
|
| 100 |
+
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_GROUP_MEMBER);
|
| 101 |
+
stmt->setUInt32(0, guidTarget.GetCounter());
|
| 102 |
+
PreparedQueryResult resultGroup = CharacterDatabase.Query(stmt);
|
| 103 |
+
if (resultGroup)
|
| 104 |
+
groupTarget = sGroupMgr->GetGroupByDbStoreId((*resultGroup)[0].GetUInt32());
|
| 105 |
+
}
|
| 106 |
+
if (!groupTarget)
|
| 107 |
+
{
|
| 108 |
+
handler->PSendSysMessage(LANG_LFG_NOT_IN_GROUP, nameTarget.c_str());
|
| 109 |
+
handler->SetSentErrorMessage(true);
|
| 110 |
+
return false;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
ObjectGuid guid = groupTarget->GetGUID();
|
| 114 |
+
std::string const& state = lfg::GetStateString(sLFGMgr->GetState(guid));
|
| 115 |
+
handler->PSendSysMessage(LANG_LFG_GROUP_INFO, groupTarget->isLFGGroup(),
|
| 116 |
+
state.c_str(), sLFGMgr->GetDungeon(guid));
|
| 117 |
+
|
| 118 |
+
Group::MemberSlotList const& members = groupTarget->GetMemberSlots();
|
| 119 |
+
|
| 120 |
+
for (Group::MemberSlotList::const_iterator itr = members.begin(); itr != members.end(); ++itr)
|
| 121 |
+
{
|
| 122 |
+
Group::MemberSlot const& slot = *itr;
|
| 123 |
+
Player* p = ObjectAccessor::FindPlayer((*itr).guid);
|
| 124 |
+
if (p)
|
| 125 |
+
GetPlayerInfo(handler, p);
|
| 126 |
+
else
|
| 127 |
+
handler->PSendSysMessage("%s is offline.", slot.name.c_str());
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
return true;
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
static bool HandleLfgOptionsCommand(ChatHandler* handler, char const* args)
|
| 134 |
+
{
|
| 135 |
+
int32 options = -1;
|
| 136 |
+
if (char* str = strtok((char*)args, " "))
|
| 137 |
+
{
|
| 138 |
+
int32 tmp = atoi(str);
|
| 139 |
+
if (tmp > -1)
|
| 140 |
+
options = tmp;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
if (options != -1)
|
| 144 |
+
{
|
| 145 |
+
sLFGMgr->SetOptions(options);
|
| 146 |
+
handler->PSendSysMessage(LANG_LFG_OPTIONS_CHANGED);
|
| 147 |
+
}
|
| 148 |
+
handler->PSendSysMessage(LANG_LFG_OPTIONS, sLFGMgr->GetOptions());
|
| 149 |
+
return true;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
static bool HandleLfgQueueInfoCommand(ChatHandler* handler, char const* args)
|
| 153 |
+
{
|
| 154 |
+
handler->SendSysMessage(sLFGMgr->DumpQueueInfo(*args != '\0').c_str(), true);
|
| 155 |
+
return true;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
static bool HandleLfgCleanCommand(ChatHandler* handler, char const* /*args*/)
|
| 159 |
+
{
|
| 160 |
+
handler->PSendSysMessage(LANG_LFG_CLEAN);
|
| 161 |
+
sLFGMgr->Clean();
|
| 162 |
+
return true;
|
| 163 |
+
}
|
| 164 |
+
};
|
| 165 |
+
|
| 166 |
+
void AddSC_lfg_commandscript()
|
| 167 |
+
{
|
| 168 |
+
new lfg_commandscript();
|
| 169 |
+
}
|
pool/shard002/C++/0024479_audio_hash_unittest.cc
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2013 The Chromium Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style license that can be
|
| 3 |
+
// found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
#include "base/logging.h"
|
| 6 |
+
#include "base/macros.h"
|
| 7 |
+
#include "media/base/audio_bus.h"
|
| 8 |
+
#include "media/base/audio_hash.h"
|
| 9 |
+
#include "media/base/fake_audio_render_callback.h"
|
| 10 |
+
#include "testing/gtest/include/gtest/gtest.h"
|
| 11 |
+
|
| 12 |
+
namespace media {
|
| 13 |
+
|
| 14 |
+
static const int kChannelCount = 2;
|
| 15 |
+
static const int kFrameCount = 1024;
|
| 16 |
+
|
| 17 |
+
class AudioHashTest : public testing::Test {
|
| 18 |
+
public:
|
| 19 |
+
AudioHashTest()
|
| 20 |
+
: bus_one_(AudioBus::Create(kChannelCount, kFrameCount)),
|
| 21 |
+
bus_two_(AudioBus::Create(kChannelCount, kFrameCount)),
|
| 22 |
+
fake_callback_(0.01) {
|
| 23 |
+
|
| 24 |
+
// Fill each channel in each bus with unique data.
|
| 25 |
+
GenerateUniqueChannels(bus_one_.get());
|
| 26 |
+
GenerateUniqueChannels(bus_two_.get());
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
void GenerateUniqueChannels(AudioBus* audio_bus) {
|
| 30 |
+
// Use an AudioBus wrapper to avoid an extra memcpy when filling channels.
|
| 31 |
+
scoped_ptr<AudioBus> wrapped_bus = AudioBus::CreateWrapper(1);
|
| 32 |
+
wrapped_bus->set_frames(audio_bus->frames());
|
| 33 |
+
|
| 34 |
+
// Since FakeAudioRenderCallback generates only a single channel of unique
|
| 35 |
+
// audio data, we need to fill each channel manually.
|
| 36 |
+
for (int ch = 0; ch < audio_bus->channels(); ++ch) {
|
| 37 |
+
wrapped_bus->SetChannelData(0, audio_bus->channel(ch));
|
| 38 |
+
fake_callback_.Render(wrapped_bus.get(), 0, 0);
|
| 39 |
+
}
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
~AudioHashTest() override {}
|
| 43 |
+
|
| 44 |
+
protected:
|
| 45 |
+
scoped_ptr<AudioBus> bus_one_;
|
| 46 |
+
scoped_ptr<AudioBus> bus_two_;
|
| 47 |
+
FakeAudioRenderCallback fake_callback_;
|
| 48 |
+
|
| 49 |
+
DISALLOW_COPY_AND_ASSIGN(AudioHashTest);
|
| 50 |
+
};
|
| 51 |
+
|
| 52 |
+
// Ensure the same data hashes the same.
|
| 53 |
+
TEST_F(AudioHashTest, Equivalence) {
|
| 54 |
+
AudioHash hash_one;
|
| 55 |
+
hash_one.Update(bus_one_.get(), bus_one_->frames());
|
| 56 |
+
|
| 57 |
+
AudioHash hash_two;
|
| 58 |
+
hash_two.Update(bus_one_.get(), bus_one_->frames());
|
| 59 |
+
|
| 60 |
+
EXPECT_EQ(hash_one.ToString(), hash_two.ToString());
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
// Ensure sample order matters to the hash.
|
| 64 |
+
TEST_F(AudioHashTest, SampleOrder) {
|
| 65 |
+
AudioHash original_hash;
|
| 66 |
+
original_hash.Update(bus_one_.get(), bus_one_->frames());
|
| 67 |
+
|
| 68 |
+
// Swap a sample in the bus.
|
| 69 |
+
std::swap(bus_one_->channel(0)[0], bus_one_->channel(0)[1]);
|
| 70 |
+
|
| 71 |
+
AudioHash swapped_hash;
|
| 72 |
+
swapped_hash.Update(bus_one_.get(), bus_one_->frames());
|
| 73 |
+
|
| 74 |
+
EXPECT_NE(original_hash.ToString(), swapped_hash.ToString());
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
// Ensure channel order matters to the hash.
|
| 78 |
+
TEST_F(AudioHashTest, ChannelOrder) {
|
| 79 |
+
AudioHash original_hash;
|
| 80 |
+
original_hash.Update(bus_one_.get(), bus_one_->frames());
|
| 81 |
+
|
| 82 |
+
// Reverse channel order for the same sample data.
|
| 83 |
+
const int channels = bus_one_->channels();
|
| 84 |
+
scoped_ptr<AudioBus> swapped_ch_bus = AudioBus::CreateWrapper(channels);
|
| 85 |
+
swapped_ch_bus->set_frames(bus_one_->frames());
|
| 86 |
+
for (int i = channels - 1; i >= 0; --i)
|
| 87 |
+
swapped_ch_bus->SetChannelData(channels - (i + 1), bus_one_->channel(i));
|
| 88 |
+
|
| 89 |
+
AudioHash swapped_hash;
|
| 90 |
+
swapped_hash.Update(swapped_ch_bus.get(), swapped_ch_bus->frames());
|
| 91 |
+
|
| 92 |
+
EXPECT_NE(original_hash.ToString(), swapped_hash.ToString());
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
// Ensure bus order matters to the hash.
|
| 96 |
+
TEST_F(AudioHashTest, BusOrder) {
|
| 97 |
+
AudioHash original_hash;
|
| 98 |
+
original_hash.Update(bus_one_.get(), bus_one_->frames());
|
| 99 |
+
original_hash.Update(bus_two_.get(), bus_two_->frames());
|
| 100 |
+
|
| 101 |
+
AudioHash reordered_hash;
|
| 102 |
+
reordered_hash.Update(bus_two_.get(), bus_two_->frames());
|
| 103 |
+
reordered_hash.Update(bus_one_.get(), bus_one_->frames());
|
| 104 |
+
|
| 105 |
+
EXPECT_NE(original_hash.ToString(), reordered_hash.ToString());
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
// Ensure bus order matters to the hash even with empty buses.
|
| 109 |
+
TEST_F(AudioHashTest, EmptyBusOrder) {
|
| 110 |
+
bus_one_->Zero();
|
| 111 |
+
bus_two_->Zero();
|
| 112 |
+
|
| 113 |
+
AudioHash one_bus_hash;
|
| 114 |
+
one_bus_hash.Update(bus_one_.get(), bus_one_->frames());
|
| 115 |
+
|
| 116 |
+
AudioHash two_bus_hash;
|
| 117 |
+
two_bus_hash.Update(bus_one_.get(), bus_one_->frames());
|
| 118 |
+
two_bus_hash.Update(bus_two_.get(), bus_two_->frames());
|
| 119 |
+
|
| 120 |
+
EXPECT_NE(one_bus_hash.ToString(), two_bus_hash.ToString());
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
// Where A = [0, n], ensure hash(A[0:n/2]), hash(A[n/2:n]) and hash(A) result
|
| 124 |
+
// in the same value.
|
| 125 |
+
TEST_F(AudioHashTest, HashIgnoresUpdateOrder) {
|
| 126 |
+
AudioHash full_hash;
|
| 127 |
+
full_hash.Update(bus_one_.get(), bus_one_->frames());
|
| 128 |
+
|
| 129 |
+
AudioHash half_hash;
|
| 130 |
+
half_hash.Update(bus_one_.get(), bus_one_->frames() / 2);
|
| 131 |
+
|
| 132 |
+
// Create a new bus representing the second half of |bus_one_|.
|
| 133 |
+
const int half_frames = bus_one_->frames() / 2;
|
| 134 |
+
const int channels = bus_one_->channels();
|
| 135 |
+
scoped_ptr<AudioBus> half_bus = AudioBus::CreateWrapper(channels);
|
| 136 |
+
half_bus->set_frames(half_frames);
|
| 137 |
+
for (int i = 0; i < channels; ++i)
|
| 138 |
+
half_bus->SetChannelData(i, bus_one_->channel(i) + half_frames);
|
| 139 |
+
|
| 140 |
+
half_hash.Update(half_bus.get(), half_bus->frames());
|
| 141 |
+
EXPECT_EQ(full_hash.ToString(), half_hash.ToString());
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
// Ensure approximate hashes pass verification.
|
| 145 |
+
TEST_F(AudioHashTest, VerifySimilarHash) {
|
| 146 |
+
AudioHash hash_one;
|
| 147 |
+
hash_one.Update(bus_one_.get(), bus_one_->frames());
|
| 148 |
+
|
| 149 |
+
// Twiddle the values inside the first bus.
|
| 150 |
+
float* channel = bus_one_->channel(0);
|
| 151 |
+
for (int i = 0; i < bus_one_->frames(); i += bus_one_->frames() / 64)
|
| 152 |
+
channel[i] += 0.0001f;
|
| 153 |
+
|
| 154 |
+
AudioHash hash_two;
|
| 155 |
+
hash_two.Update(bus_one_.get(), bus_one_->frames());
|
| 156 |
+
|
| 157 |
+
EXPECT_EQ(hash_one.ToString(), hash_two.ToString());
|
| 158 |
+
|
| 159 |
+
// Twiddle the values too much...
|
| 160 |
+
for (int i = 0; i < bus_one_->frames(); ++i)
|
| 161 |
+
channel[i] += 0.0001f;
|
| 162 |
+
|
| 163 |
+
AudioHash hash_three;
|
| 164 |
+
hash_three.Update(bus_one_.get(), bus_one_->frames());
|
| 165 |
+
EXPECT_NE(hash_one.ToString(), hash_three.ToString());
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
} // namespace media
|
pool/shard002/C++/0024484_iwBuildingProductivities.cpp
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (c) 2005 - 2017 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 |
+
#include "rttrDefines.h" // IWYU pragma: keep
|
| 19 |
+
#include "iwBuildingProductivities.h"
|
| 20 |
+
#include "GamePlayer.h"
|
| 21 |
+
#include "Loader.h"
|
| 22 |
+
#include "files.h"
|
| 23 |
+
#include "gameData/BuildingConsts.h"
|
| 24 |
+
#include "gameData/const_gui_ids.h"
|
| 25 |
+
#include "libutil/colors.h"
|
| 26 |
+
|
| 27 |
+
/// Reihenfolge der Gebäude
|
| 28 |
+
const std::array<BuildingType, 24> bts = {
|
| 29 |
+
BLD_GRANITEMINE, BLD_COALMINE, BLD_IRONMINE, BLD_GOLDMINE, BLD_WOODCUTTER, BLD_FISHERY, BLD_QUARRY, BLD_FORESTER,
|
| 30 |
+
BLD_SLAUGHTERHOUSE, BLD_HUNTER, BLD_BREWERY, BLD_ARMORY, BLD_METALWORKS, BLD_IRONSMELTER, BLD_PIGFARM, BLD_MILL,
|
| 31 |
+
BLD_BAKERY, BLD_SAWMILL, BLD_MINT, BLD_WELL, BLD_SHIPYARD, BLD_FARM, BLD_DONKEYBREEDER, BLD_CHARBURNER};
|
| 32 |
+
|
| 33 |
+
/// Abstand vom linken, oberen Fensterrand
|
| 34 |
+
const Extent bldProdContentOffset(50, 30);
|
| 35 |
+
/// Abstand vom rechten Fensterrand
|
| 36 |
+
const unsigned short right_x = 40;
|
| 37 |
+
/// Horizontaler Abstand zwischen Bild und Prozentbar
|
| 38 |
+
const unsigned short image_percent_x = 35;
|
| 39 |
+
/// Horizontaler Abstand zwischen Prozentbar und nächstem Bild
|
| 40 |
+
const unsigned short percent_image_x = 40;
|
| 41 |
+
/// Vertikaler Abstand zwischen 2 nacheinanderfolgenden "Zeilen"
|
| 42 |
+
const unsigned short distance_y = 35;
|
| 43 |
+
|
| 44 |
+
/// Größe der Prozentbalken
|
| 45 |
+
const Extent percentSize(100, 18);
|
| 46 |
+
|
| 47 |
+
iwBuildingProductivities::iwBuildingProductivities(const GamePlayer& player)
|
| 48 |
+
: IngameWindow(CGI_BUILDINGSPRODUCTIVITY, IngameWindow::posLastOrCenter,
|
| 49 |
+
Extent(2 * percentSize.x + 2 * image_percent_x + percent_image_x + right_x, (bts.size() / 2 + 1) * (distance_y + 1))
|
| 50 |
+
+ bldProdContentOffset,
|
| 51 |
+
_("Productivity"), LOADER.GetImageN("resource", 41)),
|
| 52 |
+
player(player), percents(NUM_BUILDING_TYPES, 0)
|
| 53 |
+
{
|
| 54 |
+
const Nation playerNation = player.nation;
|
| 55 |
+
for(unsigned y = 0; y < bts.size() / 2 + bts.size() % 2; ++y)
|
| 56 |
+
{
|
| 57 |
+
for(unsigned x = 0; x < 2; ++x)
|
| 58 |
+
{
|
| 59 |
+
if(y * 2 + x >= bts.size()) //-V547
|
| 60 |
+
break;
|
| 61 |
+
unsigned imgId = (y * 2 + x) * 2;
|
| 62 |
+
DrawPoint imgPos(x * (percent_image_x + percentSize.x + image_percent_x), distance_y * y + percentSize.y / 2);
|
| 63 |
+
imgPos = imgPos + bldProdContentOffset;
|
| 64 |
+
if(player.IsBuildingEnabled(bts[y * 2 + x]))
|
| 65 |
+
{
|
| 66 |
+
glArchivItem_Bitmap* img;
|
| 67 |
+
if(bts[y * 2 + x] != BLD_CHARBURNER)
|
| 68 |
+
img = LOADER.GetImageN(NATION_ICON_IDS[playerNation], bts[y * 2 + x]);
|
| 69 |
+
else
|
| 70 |
+
img = LOADER.GetImageN("charburner", playerNation * 8 + 8);
|
| 71 |
+
AddImage(imgId, imgPos, img, _(BUILDING_NAMES[bts[y * 2 + x]]));
|
| 72 |
+
DrawPoint percentPos(image_percent_x + x * (percent_image_x + percentSize.x + image_percent_x), distance_y * y);
|
| 73 |
+
AddPercent(imgId + 1, percentPos + bldProdContentOffset, percentSize, TC_GREY, COLOR_YELLOW, SmallFont,
|
| 74 |
+
&percents[bts[y * 2 + x]]);
|
| 75 |
+
} else
|
| 76 |
+
AddImage(imgId, imgPos, LOADER.GetImageN("io", 188));
|
| 77 |
+
}
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
UpdatePercents();
|
| 81 |
+
|
| 82 |
+
// Hilfe-Button
|
| 83 |
+
// Original S2 does not have a Help button in this window. Add it if you have something to say.
|
| 84 |
+
// AddImageButton(500, GetSize().x - 14 - 30, GetSize().y - 20 - 32, 30, 32, TC_GREY, LOADER.GetImageN("io", 225), _("Help"));
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
/// Aktualisieren der Prozente
|
| 88 |
+
void iwBuildingProductivities::UpdatePercents()
|
| 89 |
+
{
|
| 90 |
+
player.GetBuildingRegister().CalcProductivities(percents);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
/// Produktivitäts-percentbars aktualisieren
|
| 94 |
+
void iwBuildingProductivities::Msg_PaintAfter()
|
| 95 |
+
{
|
| 96 |
+
IngameWindow::Msg_PaintAfter();
|
| 97 |
+
UpdatePercents();
|
| 98 |
+
}
|
pool/shard002/C++/0024488_billboards.cpp
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (C) 2008-2012 Colin MacDonald
|
| 2 |
+
// No rights reserved: this software is in the public domain.
|
| 3 |
+
|
| 4 |
+
#include "testUtils.h"
|
| 5 |
+
|
| 6 |
+
using namespace irr;
|
| 7 |
+
|
| 8 |
+
namespace
|
| 9 |
+
{
|
| 10 |
+
// Test billboard sizing
|
| 11 |
+
bool billboardSize(void)
|
| 12 |
+
{
|
| 13 |
+
// Use EDT_BURNINGSVIDEO since it is not dependent on (e.g.) OpenGL driver versions.
|
| 14 |
+
IrrlichtDevice *device = createDevice(video::EDT_BURNINGSVIDEO, core::dimension2d<u32>(160, 120), 32);
|
| 15 |
+
assert_log(device);
|
| 16 |
+
if (!device)
|
| 17 |
+
return false;
|
| 18 |
+
|
| 19 |
+
video::IVideoDriver* driver = device->getVideoDriver();
|
| 20 |
+
scene::ISceneManager * smgr = device->getSceneManager();
|
| 21 |
+
|
| 22 |
+
smgr->addCameraSceneNode();
|
| 23 |
+
scene::IBillboardSceneNode* bill = smgr->addBillboardSceneNode();
|
| 24 |
+
bill->setPosition(core::vector3df(0,0,50));
|
| 25 |
+
bill = smgr->addBillboardSceneNode();
|
| 26 |
+
bill->setPosition(core::vector3df(-30,0,50));
|
| 27 |
+
bill->getMaterial(0).Lighting=false;
|
| 28 |
+
bill = smgr->addBillboardSceneNode();
|
| 29 |
+
bill->setPosition(core::vector3df(30,0,50));
|
| 30 |
+
bill->getMaterial(0).Lighting=false;
|
| 31 |
+
bill->getMaterial(0).Wireframe=true;
|
| 32 |
+
bill = smgr->addBillboardSceneNode();
|
| 33 |
+
bill->setPosition(core::vector3df(30,0,50));
|
| 34 |
+
bill->setSize(2,2,2);
|
| 35 |
+
|
| 36 |
+
bill = smgr->addBillboardSceneNode();
|
| 37 |
+
bill->setSize(10,20,2);
|
| 38 |
+
bill->setPosition(core::vector3df(0,30,50));
|
| 39 |
+
bill = smgr->addBillboardSceneNode();
|
| 40 |
+
bill->setSize(10,2,20);
|
| 41 |
+
bill->setPosition(core::vector3df(-30,30,50));
|
| 42 |
+
bill->getMaterial(0).Lighting=false;
|
| 43 |
+
bill = smgr->addBillboardSceneNode();
|
| 44 |
+
bill->setSize(10,2,20);
|
| 45 |
+
bill->setPosition(core::vector3df(30,30,50));
|
| 46 |
+
bill->getMaterial(0).Lighting=false;
|
| 47 |
+
bill->getMaterial(0).Wireframe=true;
|
| 48 |
+
bill = smgr->addBillboardSceneNode();
|
| 49 |
+
bill->setPosition(core::vector3df(30,30,50));
|
| 50 |
+
bill->setSize(2,2,2);
|
| 51 |
+
|
| 52 |
+
video::ITexture* tex = driver->getTexture("../media/fireball.bmp");
|
| 53 |
+
bill = smgr->addBillboardSceneNode();
|
| 54 |
+
bill->getMaterial(0).Lighting=false;
|
| 55 |
+
bill->getMaterial(0).TextureLayer[0].AnisotropicFilter=true;
|
| 56 |
+
bill->getMaterial(0).setTexture(0, tex);
|
| 57 |
+
bill->setSize(10,20,2);
|
| 58 |
+
bill->setPosition(core::vector3df(0,-30,50));
|
| 59 |
+
bill = smgr->addBillboardSceneNode();
|
| 60 |
+
bill->setSize(10,2,20);
|
| 61 |
+
bill->setPosition(core::vector3df(-30,-30,50));
|
| 62 |
+
bill->getMaterial(0).TextureLayer[0].AnisotropicFilter=true;
|
| 63 |
+
bill->getMaterial(0).setTexture(0, tex);
|
| 64 |
+
bill->getMaterial(0).Lighting=false;
|
| 65 |
+
bill = smgr->addBillboardSceneNode();
|
| 66 |
+
bill->setSize(10,2,20);
|
| 67 |
+
bill->setPosition(core::vector3df(30,-30,50));
|
| 68 |
+
bill->getMaterial(0).TextureLayer[0].AnisotropicFilter=true;
|
| 69 |
+
bill->getMaterial(0).setTexture(0, tex);
|
| 70 |
+
bill->getMaterial(0).Lighting=false;
|
| 71 |
+
bill->getMaterial(0).Wireframe=true;
|
| 72 |
+
bill = smgr->addBillboardSceneNode();
|
| 73 |
+
bill->setPosition(core::vector3df(30,-30,50));
|
| 74 |
+
bill->setSize(2,2,2);
|
| 75 |
+
|
| 76 |
+
bill = smgr->addBillboardSceneNode();
|
| 77 |
+
bill->getMaterial(0).Lighting=false;
|
| 78 |
+
bill->getMaterial(0).setTexture(0, tex);
|
| 79 |
+
bill->setSize(10,20,14);
|
| 80 |
+
bill->setPosition(core::vector3df(0,-15,50));
|
| 81 |
+
bill = smgr->addBillboardSceneNode();
|
| 82 |
+
bill->setSize(10,14,20);
|
| 83 |
+
bill->setPosition(core::vector3df(-30,-15,50));
|
| 84 |
+
bill->getMaterial(0).setTexture(0, tex);
|
| 85 |
+
bill->getMaterial(0).Lighting=false;
|
| 86 |
+
bill = smgr->addBillboardSceneNode();
|
| 87 |
+
bill->setSize(10,14,20);
|
| 88 |
+
bill->setPosition(core::vector3df(30,-15,50));
|
| 89 |
+
bill->getMaterial(0).setTexture(0, tex);
|
| 90 |
+
bill->getMaterial(0).Lighting=false;
|
| 91 |
+
bill->getMaterial(0).Wireframe=true;
|
| 92 |
+
bill = smgr->addBillboardSceneNode();
|
| 93 |
+
bill->setPosition(core::vector3df(30,-15,50));
|
| 94 |
+
bill->setSize(2,2,2);
|
| 95 |
+
|
| 96 |
+
bool result = false;
|
| 97 |
+
|
| 98 |
+
device->run();
|
| 99 |
+
driver->beginScene(true, true, video::SColor(255, 60, 60, 60));
|
| 100 |
+
smgr->drawAll();
|
| 101 |
+
driver->endScene();
|
| 102 |
+
|
| 103 |
+
result = takeScreenshotAndCompareAgainstReference(driver, "-billboard.png");
|
| 104 |
+
|
| 105 |
+
device->closeDevice();
|
| 106 |
+
device->run();
|
| 107 |
+
device->drop();
|
| 108 |
+
|
| 109 |
+
return result;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
// Test billboard orientation
|
| 113 |
+
// Should generate a properly readable (i.e. not mirrored or flipped)
|
| 114 |
+
// font file display.
|
| 115 |
+
bool billboardOrientation(void)
|
| 116 |
+
{
|
| 117 |
+
// Use EDT_BURNINGSVIDEO since it is not dependent on (e.g.) OpenGL driver versions.
|
| 118 |
+
IrrlichtDevice *device = createDevice(video::EDT_BURNINGSVIDEO, core::dimension2d<u32>(160, 120), 32);
|
| 119 |
+
assert_log(device);
|
| 120 |
+
if (!device)
|
| 121 |
+
return false;
|
| 122 |
+
|
| 123 |
+
video::IVideoDriver* driver = device->getVideoDriver();
|
| 124 |
+
scene::ISceneManager * smgr = device->getSceneManager();
|
| 125 |
+
|
| 126 |
+
smgr->addCameraSceneNode();
|
| 127 |
+
scene::IBillboardSceneNode* bill = smgr->addBillboardSceneNode(0, core::dimension2df(40,40));
|
| 128 |
+
bill->setPosition(core::vector3df(0,-15,10));
|
| 129 |
+
bill->getMaterial(0).Lighting=false;
|
| 130 |
+
bill->getMaterial(0).setTexture(0, driver->getTexture("../media/fontcourier.bmp"));
|
| 131 |
+
|
| 132 |
+
bool result = false;
|
| 133 |
+
|
| 134 |
+
device->run();
|
| 135 |
+
driver->beginScene(true, true, video::SColor(255, 60, 60, 60));
|
| 136 |
+
smgr->drawAll();
|
| 137 |
+
driver->endScene();
|
| 138 |
+
|
| 139 |
+
result = takeScreenshotAndCompareAgainstReference(driver, "-billboardOrientation.png");
|
| 140 |
+
|
| 141 |
+
device->closeDevice();
|
| 142 |
+
device->run();
|
| 143 |
+
device->drop();
|
| 144 |
+
|
| 145 |
+
return result;
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
} // end anonymous namespace
|
| 149 |
+
|
| 150 |
+
// Test billboards
|
| 151 |
+
bool billboards(void)
|
| 152 |
+
{
|
| 153 |
+
bool result = billboardSize();
|
| 154 |
+
result &= billboardOrientation();
|
| 155 |
+
return result;
|
| 156 |
+
}
|
pool/shard002/C++/0024490_sighash_tests.cpp
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (c) 2013 The BeCoin Core developers
|
| 2 |
+
// Distributed under the MIT software license, see the accompanying
|
| 3 |
+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
| 4 |
+
|
| 5 |
+
#include "consensus/validation.h"
|
| 6 |
+
#include "data/sighash.json.h"
|
| 7 |
+
#include "hash.h"
|
| 8 |
+
#include "main.h" // For CheckTransaction
|
| 9 |
+
#include "random.h"
|
| 10 |
+
#include "script/interpreter.h"
|
| 11 |
+
#include "script/script.h"
|
| 12 |
+
#include "serialize.h"
|
| 13 |
+
#include "streams.h"
|
| 14 |
+
#include "test/test_becoin.h"
|
| 15 |
+
#include "util.h"
|
| 16 |
+
#include "utilstrencodings.h"
|
| 17 |
+
#include "version.h"
|
| 18 |
+
|
| 19 |
+
#include <iostream>
|
| 20 |
+
|
| 21 |
+
#include <boost/test/unit_test.hpp>
|
| 22 |
+
|
| 23 |
+
#include "univalue/univalue.h"
|
| 24 |
+
|
| 25 |
+
extern UniValue read_json(const std::string& jsondata);
|
| 26 |
+
|
| 27 |
+
// Old script.cpp SignatureHash function
|
| 28 |
+
uint256 static SignatureHashOld(CScript scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType)
|
| 29 |
+
{
|
| 30 |
+
static const uint256 one(uint256S("0000000000000000000000000000000000000000000000000000000000000001"));
|
| 31 |
+
if (nIn >= txTo.vin.size())
|
| 32 |
+
{
|
| 33 |
+
printf("ERROR: SignatureHash(): nIn=%d out of range\n", nIn);
|
| 34 |
+
return one;
|
| 35 |
+
}
|
| 36 |
+
CMutableTransaction txTmp(txTo);
|
| 37 |
+
|
| 38 |
+
// In case concatenating two scripts ends up with two codeseparators,
|
| 39 |
+
// or an extra one at the end, this prevents all those possible incompatibilities.
|
| 40 |
+
scriptCode.FindAndDelete(CScript(OP_CODESEPARATOR));
|
| 41 |
+
|
| 42 |
+
// Blank out other inputs' signatures
|
| 43 |
+
for (unsigned int i = 0; i < txTmp.vin.size(); i++)
|
| 44 |
+
txTmp.vin[i].scriptSig = CScript();
|
| 45 |
+
txTmp.vin[nIn].scriptSig = scriptCode;
|
| 46 |
+
|
| 47 |
+
// Blank out some of the outputs
|
| 48 |
+
if ((nHashType & 0x1f) == SIGHASH_NONE)
|
| 49 |
+
{
|
| 50 |
+
// Wildcard payee
|
| 51 |
+
txTmp.vout.clear();
|
| 52 |
+
|
| 53 |
+
// Let the others update at will
|
| 54 |
+
for (unsigned int i = 0; i < txTmp.vin.size(); i++)
|
| 55 |
+
if (i != nIn)
|
| 56 |
+
txTmp.vin[i].nSequence = 0;
|
| 57 |
+
}
|
| 58 |
+
else if ((nHashType & 0x1f) == SIGHASH_SINGLE)
|
| 59 |
+
{
|
| 60 |
+
// Only lock-in the txout payee at same index as txin
|
| 61 |
+
unsigned int nOut = nIn;
|
| 62 |
+
if (nOut >= txTmp.vout.size())
|
| 63 |
+
{
|
| 64 |
+
printf("ERROR: SignatureHash(): nOut=%d out of range\n", nOut);
|
| 65 |
+
return one;
|
| 66 |
+
}
|
| 67 |
+
txTmp.vout.resize(nOut+1);
|
| 68 |
+
for (unsigned int i = 0; i < nOut; i++)
|
| 69 |
+
txTmp.vout[i].SetNull();
|
| 70 |
+
|
| 71 |
+
// Let the others update at will
|
| 72 |
+
for (unsigned int i = 0; i < txTmp.vin.size(); i++)
|
| 73 |
+
if (i != nIn)
|
| 74 |
+
txTmp.vin[i].nSequence = 0;
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
// Blank out other inputs completely, not recommended for open transactions
|
| 78 |
+
if (nHashType & SIGHASH_ANYONECANPAY)
|
| 79 |
+
{
|
| 80 |
+
txTmp.vin[0] = txTmp.vin[nIn];
|
| 81 |
+
txTmp.vin.resize(1);
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
// Serialize and hash
|
| 85 |
+
CHashWriter ss(SER_GETHASH, 0);
|
| 86 |
+
ss << txTmp << nHashType;
|
| 87 |
+
return ss.GetHash();
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
void static RandomScript(CScript &script) {
|
| 91 |
+
static const opcodetype oplist[] = {OP_FALSE, OP_1, OP_2, OP_3, OP_CHECKSIG, OP_IF, OP_VERIF, OP_RETURN, OP_CODESEPARATOR};
|
| 92 |
+
script = CScript();
|
| 93 |
+
int ops = (insecure_rand() % 10);
|
| 94 |
+
for (int i=0; i<ops; i++)
|
| 95 |
+
script << oplist[insecure_rand() % (sizeof(oplist)/sizeof(oplist[0]))];
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
void static RandomTransaction(CMutableTransaction &tx, bool fSingle) {
|
| 99 |
+
tx.nVersion = insecure_rand();
|
| 100 |
+
tx.vin.clear();
|
| 101 |
+
tx.vout.clear();
|
| 102 |
+
tx.nLockTime = (insecure_rand() % 2) ? insecure_rand() : 0;
|
| 103 |
+
int ins = (insecure_rand() % 4) + 1;
|
| 104 |
+
int outs = fSingle ? ins : (insecure_rand() % 4) + 1;
|
| 105 |
+
for (int in = 0; in < ins; in++) {
|
| 106 |
+
tx.vin.push_back(CTxIn());
|
| 107 |
+
CTxIn &txin = tx.vin.back();
|
| 108 |
+
txin.prevout.hash = GetRandHash();
|
| 109 |
+
txin.prevout.n = insecure_rand() % 4;
|
| 110 |
+
RandomScript(txin.scriptSig);
|
| 111 |
+
txin.nSequence = (insecure_rand() % 2) ? insecure_rand() : (unsigned int)-1;
|
| 112 |
+
}
|
| 113 |
+
for (int out = 0; out < outs; out++) {
|
| 114 |
+
tx.vout.push_back(CTxOut());
|
| 115 |
+
CTxOut &txout = tx.vout.back();
|
| 116 |
+
txout.nValue = insecure_rand() % 100000000;
|
| 117 |
+
RandomScript(txout.scriptPubKey);
|
| 118 |
+
}
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
BOOST_FIXTURE_TEST_SUITE(sighash_tests, BasicTestingSetup)
|
| 122 |
+
|
| 123 |
+
BOOST_AUTO_TEST_CASE(sighash_test)
|
| 124 |
+
{
|
| 125 |
+
seed_insecure_rand(false);
|
| 126 |
+
|
| 127 |
+
#if defined(PRINT_SIGHASH_JSON)
|
| 128 |
+
std::cout << "[\n";
|
| 129 |
+
std::cout << "\t[\"raw_transaction, script, input_index, hashType, signature_hash (result)\"],\n";
|
| 130 |
+
#endif
|
| 131 |
+
int nRandomTests = 50000;
|
| 132 |
+
|
| 133 |
+
#if defined(PRINT_SIGHASH_JSON)
|
| 134 |
+
nRandomTests = 500;
|
| 135 |
+
#endif
|
| 136 |
+
for (int i=0; i<nRandomTests; i++) {
|
| 137 |
+
int nHashType = insecure_rand();
|
| 138 |
+
CMutableTransaction txTo;
|
| 139 |
+
RandomTransaction(txTo, (nHashType & 0x1f) == SIGHASH_SINGLE);
|
| 140 |
+
CScript scriptCode;
|
| 141 |
+
RandomScript(scriptCode);
|
| 142 |
+
int nIn = insecure_rand() % txTo.vin.size();
|
| 143 |
+
|
| 144 |
+
uint256 sh, sho;
|
| 145 |
+
sho = SignatureHashOld(scriptCode, txTo, nIn, nHashType);
|
| 146 |
+
sh = SignatureHash(scriptCode, txTo, nIn, nHashType);
|
| 147 |
+
#if defined(PRINT_SIGHASH_JSON)
|
| 148 |
+
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
|
| 149 |
+
ss << txTo;
|
| 150 |
+
|
| 151 |
+
std::cout << "\t[\"" ;
|
| 152 |
+
std::cout << HexStr(ss.begin(), ss.end()) << "\", \"";
|
| 153 |
+
std::cout << HexStr(scriptCode) << "\", ";
|
| 154 |
+
std::cout << nIn << ", ";
|
| 155 |
+
std::cout << nHashType << ", \"";
|
| 156 |
+
std::cout << sho.GetHex() << "\"]";
|
| 157 |
+
if (i+1 != nRandomTests) {
|
| 158 |
+
std::cout << ",";
|
| 159 |
+
}
|
| 160 |
+
std::cout << "\n";
|
| 161 |
+
#endif
|
| 162 |
+
BOOST_CHECK(sh == sho);
|
| 163 |
+
}
|
| 164 |
+
#if defined(PRINT_SIGHASH_JSON)
|
| 165 |
+
std::cout << "]\n";
|
| 166 |
+
#endif
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
// Goal: check that SignatureHash generates correct hash
|
| 170 |
+
BOOST_AUTO_TEST_CASE(sighash_from_data)
|
| 171 |
+
{
|
| 172 |
+
UniValue tests = read_json(std::string(json_tests::sighash, json_tests::sighash + sizeof(json_tests::sighash)));
|
| 173 |
+
|
| 174 |
+
for (unsigned int idx = 0; idx < tests.size(); idx++) {
|
| 175 |
+
UniValue test = tests[idx];
|
| 176 |
+
std::string strTest = test.write();
|
| 177 |
+
if (test.size() < 1) // Allow for extra stuff (useful for comments)
|
| 178 |
+
{
|
| 179 |
+
BOOST_ERROR("Bad test: " << strTest);
|
| 180 |
+
continue;
|
| 181 |
+
}
|
| 182 |
+
if (test.size() == 1) continue; // comment
|
| 183 |
+
|
| 184 |
+
std::string raw_tx, raw_script, sigHashHex;
|
| 185 |
+
int nIn, nHashType;
|
| 186 |
+
uint256 sh;
|
| 187 |
+
CTransaction tx;
|
| 188 |
+
CScript scriptCode = CScript();
|
| 189 |
+
|
| 190 |
+
try {
|
| 191 |
+
// deserialize test data
|
| 192 |
+
raw_tx = test[0].get_str();
|
| 193 |
+
raw_script = test[1].get_str();
|
| 194 |
+
nIn = test[2].get_int();
|
| 195 |
+
nHashType = test[3].get_int();
|
| 196 |
+
sigHashHex = test[4].get_str();
|
| 197 |
+
|
| 198 |
+
uint256 sh;
|
| 199 |
+
CDataStream stream(ParseHex(raw_tx), SER_NETWORK, PROTOCOL_VERSION);
|
| 200 |
+
stream >> tx;
|
| 201 |
+
|
| 202 |
+
CValidationState state;
|
| 203 |
+
BOOST_CHECK_MESSAGE(CheckTransaction(tx, state), strTest);
|
| 204 |
+
BOOST_CHECK(state.IsValid());
|
| 205 |
+
|
| 206 |
+
std::vector<unsigned char> raw = ParseHex(raw_script);
|
| 207 |
+
scriptCode.insert(scriptCode.end(), raw.begin(), raw.end());
|
| 208 |
+
} catch (...) {
|
| 209 |
+
BOOST_ERROR("Bad test, couldn't deserialize data: " << strTest);
|
| 210 |
+
continue;
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
sh = SignatureHash(scriptCode, tx, nIn, nHashType);
|
| 214 |
+
BOOST_CHECK_MESSAGE(sh.GetHex() == sigHashHex, strTest);
|
| 215 |
+
}
|
| 216 |
+
}
|
| 217 |
+
BOOST_AUTO_TEST_SUITE_END()
|
pool/shard002/C++/0024496_WKBundleFileHandle_Bundle.cpp
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C) 2015 Apple Inc. All rights reserved.
|
| 3 |
+
*
|
| 4 |
+
* Redistribution and use in source and binary forms, with or without
|
| 5 |
+
* modification, are permitted provided that the following conditions
|
| 6 |
+
* are met:
|
| 7 |
+
* 1. Redistributions of source code must retain the above copyright
|
| 8 |
+
* notice, this list of conditions and the following disclaimer.
|
| 9 |
+
* 2. Redistributions in binary form must reproduce the above copyright
|
| 10 |
+
* notice, this list of conditions and the following disclaimer in the
|
| 11 |
+
* documentation and/or other materials provided with the distribution.
|
| 12 |
+
*
|
| 13 |
+
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
|
| 14 |
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
| 15 |
+
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
| 16 |
+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
|
| 17 |
+
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
| 18 |
+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
| 19 |
+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
| 20 |
+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
| 21 |
+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
| 22 |
+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
| 23 |
+
* THE POSSIBILITY OF SUCH DAMAGE.
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
#include "config.h"
|
| 27 |
+
|
| 28 |
+
#if WK_HAVE_C_SPI
|
| 29 |
+
|
| 30 |
+
#include "InjectedBundleTest.h"
|
| 31 |
+
|
| 32 |
+
#include "PlatformUtilities.h"
|
| 33 |
+
#include <WebKit/WKBundlePage.h>
|
| 34 |
+
#include <WebKit/WKBundleFileHandleRef.h>
|
| 35 |
+
#include <WebKit/WKBundleFrame.h>
|
| 36 |
+
#include <WebKit/WKBundleScriptWorld.h>
|
| 37 |
+
|
| 38 |
+
namespace TestWebKitAPI {
|
| 39 |
+
|
| 40 |
+
static WKBundlePageRef loadedPage;
|
| 41 |
+
|
| 42 |
+
class WKBundleFileHandleTest : public InjectedBundleTest {
|
| 43 |
+
public:
|
| 44 |
+
WKBundleFileHandleTest(const std::string& identifier)
|
| 45 |
+
: InjectedBundleTest(identifier)
|
| 46 |
+
{
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
private:
|
| 50 |
+
virtual void didReceiveMessage(WKBundleRef bundle, WKStringRef messageName, WKTypeRef messageBody) override
|
| 51 |
+
{
|
| 52 |
+
if (!WKStringIsEqualToUTF8CString(messageName, "TestFile")) {
|
| 53 |
+
WKBundlePostMessage(bundle, Util::toWK("FAIL").get(), Util::toWK("Recieved invalid message").get());
|
| 54 |
+
return;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
if (!loadedPage) {
|
| 58 |
+
WKBundlePostMessage(bundle, Util::toWK("FAIL").get(), Util::toWK("No loaded page").get());
|
| 59 |
+
return;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
if (WKGetTypeID(messageBody) != WKStringGetTypeID()) {
|
| 63 |
+
WKBundlePostMessage(bundle, Util::toWK("FAIL").get(), Util::toWK("Message body has invalid type").get());
|
| 64 |
+
return;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(loadedPage);
|
| 68 |
+
WKBundleScriptWorldRef world = WKBundleScriptWorldNormalWorld();
|
| 69 |
+
|
| 70 |
+
JSGlobalContextRef globalContext = WKBundleFrameGetJavaScriptContextForWorld(mainFrame, world);
|
| 71 |
+
|
| 72 |
+
auto fileHandle = adoptWK(WKBundleFileHandleCreateWithPath((WKStringRef)messageBody));
|
| 73 |
+
JSValueRef jsFileHandle = WKBundleFrameGetJavaScriptWrapperForFileForWorld(mainFrame, fileHandle.get(), world);
|
| 74 |
+
|
| 75 |
+
JSObjectRef globalObject = JSContextGetGlobalObject(globalContext);
|
| 76 |
+
|
| 77 |
+
JSStringRef jsString = JSStringCreateWithUTF8CString("testFile");
|
| 78 |
+
JSValueRef function = JSObjectGetProperty(globalContext, globalObject, jsString, nullptr);
|
| 79 |
+
JSStringRelease(jsString);
|
| 80 |
+
|
| 81 |
+
JSValueRef result = JSObjectCallAsFunction(globalContext, (JSObjectRef)function, globalObject, 1, &jsFileHandle, nullptr);
|
| 82 |
+
|
| 83 |
+
if (JSValueToBoolean(globalContext, result))
|
| 84 |
+
WKBundlePostMessage(bundle, Util::toWK("SUCCESS").get(), nullptr);
|
| 85 |
+
else
|
| 86 |
+
WKBundlePostMessage(bundle, Util::toWK("FAIL").get(), Util::toWK("Script failed").get());
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
virtual void didCreatePage(WKBundleRef bundle, WKBundlePageRef page) override
|
| 90 |
+
{
|
| 91 |
+
loadedPage = page;
|
| 92 |
+
}
|
| 93 |
+
};
|
| 94 |
+
|
| 95 |
+
static InjectedBundleTest::Register<WKBundleFileHandleTest> registrar("WKBundleFileHandleTest");
|
| 96 |
+
|
| 97 |
+
} // namespace TestWebKitAPI
|
| 98 |
+
|
| 99 |
+
#endif
|
pool/shard002/C++/0024497_virtual_machine.cpp
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (C) 2016 Tomoyuki Fujimori <moyu@dromozoa.com>
|
| 2 |
+
//
|
| 3 |
+
// This file is part of dromozoa-prl.
|
| 4 |
+
//
|
| 5 |
+
// dromozoa-prl is free software: you can redistribute it and/or modify
|
| 6 |
+
// it under the terms of the GNU General Public License as published by
|
| 7 |
+
// the Free Software Foundation, either version 3 of the License, or
|
| 8 |
+
// (at your option) any later version.
|
| 9 |
+
//
|
| 10 |
+
// dromozoa-prl 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 dromozoa-prl. If not, see <http://www.gnu.org/licenses/>.
|
| 17 |
+
|
| 18 |
+
#include "common.hpp"
|
| 19 |
+
|
| 20 |
+
namespace dromozoa {
|
| 21 |
+
namespace {
|
| 22 |
+
void impl_connect_to_vm(lua_State* L) {
|
| 23 |
+
PRL_HANDLE handle = PrlDevDisplay_ConnectToVm(
|
| 24 |
+
check_handle(L, 1),
|
| 25 |
+
luaX_opt_enum(L, 2, PDCT_HIGH_QUALITY_WITHOUT_COMPRESSION));
|
| 26 |
+
if (handle == PRL_INVALID_HANDLE) {
|
| 27 |
+
push_error(L, PRL_ERR_INVALID_HANDLE);
|
| 28 |
+
} else {
|
| 29 |
+
new_handle(L, handle);
|
| 30 |
+
}
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
void impl_disconnect_from_vm(lua_State* L) {
|
| 34 |
+
PRL_RESULT result = PrlDevDisplay_DisconnectFromVm(check_handle(L, 1));
|
| 35 |
+
if (PRL_SUCCEEDED(result)) {
|
| 36 |
+
luaX_push_success(L);
|
| 37 |
+
} else {
|
| 38 |
+
push_error(L, result);
|
| 39 |
+
}
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
void impl_get_config(lua_State* L) {
|
| 43 |
+
PRL_HANDLE handle = PRL_INVALID_HANDLE;
|
| 44 |
+
PRL_RESULT result = PrlVm_GetConfig(check_handle(L, 1), &handle);
|
| 45 |
+
if (PRL_SUCCEEDED(result)) {
|
| 46 |
+
new_handle(L, handle);
|
| 47 |
+
} else {
|
| 48 |
+
push_error(L, result);
|
| 49 |
+
}
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
void impl_send_key_event_ex(lua_State* L) {
|
| 53 |
+
PRL_RESULT result = PrlDevKeyboard_SendKeyEventEx(
|
| 54 |
+
check_handle(L, 1),
|
| 55 |
+
luaX_check_enum<PRL_KEY>(L, 2),
|
| 56 |
+
luaX_check_enum<PRL_KEY_EVENT>(L, 3));
|
| 57 |
+
if (PRL_SUCCEEDED(result)) {
|
| 58 |
+
luaX_push_success(L);
|
| 59 |
+
} else {
|
| 60 |
+
push_error(L, result);
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
void impl_send_key_pressed_and_released(lua_State* L) {
|
| 65 |
+
PRL_RESULT result = PrlDevKeyboard_SendKeyPressedAndReleased(
|
| 66 |
+
check_handle(L, 1),
|
| 67 |
+
luaX_check_enum<PRL_KEY>(L, 2));
|
| 68 |
+
if (PRL_SUCCEEDED(result)) {
|
| 69 |
+
luaX_push_success(L);
|
| 70 |
+
} else {
|
| 71 |
+
push_error(L, result);
|
| 72 |
+
}
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
void initialize_virtual_machine(lua_State* L) {
|
| 77 |
+
lua_newtable(L);
|
| 78 |
+
{
|
| 79 |
+
if (PHT_VIRTUAL_MACHINE == PHT_VM_CONFIGURATION) {
|
| 80 |
+
inherit_handle(L, "dromozoa.prl.virtual_machine", "dromozoa.prl.vm_configuration");
|
| 81 |
+
} else {
|
| 82 |
+
inherit_handle(L, "dromozoa.prl.virtual_machine");
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
luaX_set_field(L, -1, "connect_to_vm", impl_connect_to_vm);
|
| 86 |
+
luaX_set_field(L, -1, "disconnect_from_vm", impl_disconnect_from_vm);
|
| 87 |
+
luaX_set_field(L, -1, "get_config", impl_get_config);
|
| 88 |
+
luaX_set_field(L, -1, "send_key_event_ex", impl_send_key_event_ex);
|
| 89 |
+
luaX_set_field(L, -1, "send_key_pressed_and_released", impl_send_key_pressed_and_released);
|
| 90 |
+
}
|
| 91 |
+
luaX_set_field(L, -2, "virtual_machine");
|
| 92 |
+
}
|
| 93 |
+
}
|
pool/shard002/C++/0024502_RullerSplliterWnd.cpp
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// RullerSplliterWnd.cpp : implementation file
|
| 2 |
+
//
|
| 3 |
+
|
| 4 |
+
#include "stdafx.h"
|
| 5 |
+
#include "RadarDataShow.h"
|
| 6 |
+
#include "RullerSplliterWnd.h"
|
| 7 |
+
|
| 8 |
+
#include "RulerView.h"
|
| 9 |
+
#include "CornerView.h"
|
| 10 |
+
#include "AscanView.h"
|
| 11 |
+
#ifdef _DEBUG
|
| 12 |
+
#define new DEBUG_NEW
|
| 13 |
+
#undef THIS_FILE
|
| 14 |
+
static char THIS_FILE[] = __FILE__;
|
| 15 |
+
#endif
|
| 16 |
+
|
| 17 |
+
/////////////////////////////////////////////////////////////////////////////
|
| 18 |
+
// CRullerSplliterWnd
|
| 19 |
+
IMPLEMENT_DYNCREATE(CRullerSplliterWnd, CMDIChildWnd)
|
| 20 |
+
CRullerSplliterWnd::CRullerSplliterWnd()
|
| 21 |
+
{
|
| 22 |
+
m_cxSplitter = 0;
|
| 23 |
+
m_cySplitter = 0;
|
| 24 |
+
m_cxBorderShare = 0;
|
| 25 |
+
m_cyBorderShare = 0;
|
| 26 |
+
m_cxSplitterGap = 1;
|
| 27 |
+
m_cySplitterGap = 1;
|
| 28 |
+
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
CRullerSplliterWnd::~CRullerSplliterWnd()
|
| 32 |
+
{
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
BEGIN_MESSAGE_MAP(CRullerSplliterWnd, CSplitterWnd)
|
| 37 |
+
//{{AFX_MSG_MAP(CRullerSplliterWnd)
|
| 38 |
+
// NOTE - the ClassWizard will add and remove mapping macros here.
|
| 39 |
+
//}}AFX_MSG_MAP
|
| 40 |
+
END_MESSAGE_MAP()
|
| 41 |
+
|
| 42 |
+
/////////////////////////////////////////////////////////////////////////////
|
| 43 |
+
// CRullerSplliterWnd message handlers
|
| 44 |
+
BOOL CRullerSplliterWnd::CreateRulers(CFrameWnd *pParent, CCreateContext *pContext)
|
| 45 |
+
{
|
| 46 |
+
if (!CreateStatic(pParent, 2, 3)) //Á½ÐÐÈýÁÐ
|
| 47 |
+
return FALSE;
|
| 48 |
+
if (!CreateView(0, 0, RUNTIME_CLASS(CCornerView), CSize(0,0), pContext))//×óÉϽÇÊÓͼ
|
| 49 |
+
return FALSE;
|
| 50 |
+
if (!CreateView(0, 2, RUNTIME_CLASS(CCornerView), CSize(0,0), pContext))//ÓÒÉϽÇÊÓͼ
|
| 51 |
+
return FALSE;
|
| 52 |
+
if (!CreateView(0, 1, RUNTIME_CLASS(CRulerView), CSize(0,0), pContext)) //ˮƽ±ê³ßÊÓͼ
|
| 53 |
+
return FALSE;
|
| 54 |
+
if (!CreateView(1, 0, RUNTIME_CLASS(CRulerView), CSize(0,0), pContext))//´¹Ö±±ê³ßÊÓͼ
|
| 55 |
+
return FALSE;
|
| 56 |
+
if (!CreateView(1, 1, pContext->m_pNewViewClass, CSize(0,0),pContext)) //ͼÏñÊÓͼ
|
| 57 |
+
return FALSE;
|
| 58 |
+
if (!CreateView(1, 2, RUNTIME_CLASS(CAscanView), CSize(0,0), pContext)) //²¨ÐÎÊÓͼ
|
| 59 |
+
return FALSE;
|
| 60 |
+
SetColumnInfo(0, 0, 0);
|
| 61 |
+
SetColumnInfo(1, 0, 0);
|
| 62 |
+
SetRowInfo(0, 0, 0);
|
| 63 |
+
((CRulerView*)GetPane(0, 1))->SetRulerType(RT_HORIZONTAL);//Ö¸¶¨Ë®Æ½±ê³ß
|
| 64 |
+
((CRulerView*)GetPane(1, 0))->SetRulerType(RT_VERTICAL);//Ö¸¶¨´¹Ö±±ê³ß
|
| 65 |
+
SetActivePane(1, 1); //½«Í¼Ïñ´°¸ñÉèÖÃΪ»î¶¯ÊÓͼ
|
| 66 |
+
return TRUE;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
void CRullerSplliterWnd::ShowRulers()
|
| 70 |
+
{
|
| 71 |
+
int nSize = 16;//±ê³ß´°¸ñµÄ³ß´ç
|
| 72 |
+
int nSizeBorder = 3;//·Ö¸îÌõ³ß´ç
|
| 73 |
+
|
| 74 |
+
SetRowInfo(0, nSize, 0);//ˮƽ±ê³ß´°¸ñ¸ß¶È
|
| 75 |
+
SetColumnInfo(0, nSize, 0);//´¹Ö±±ê³ß´°¸ñ¿í¶È
|
| 76 |
+
SetColumnInfo(1,(GetSystemMetrics(SM_CXSCREEN)-128), 0);//ÉèÖÃͼÏñÏÔʾ´°¿Ú³ß´ç
|
| 77 |
+
m_cxSplitterGap = nSizeBorder;//·Ö¸îÌõ³ß´ç
|
| 78 |
+
m_cySplitterGap = nSizeBorder;
|
| 79 |
+
RecalcLayout();//ÖØÐÂÅÅÁд°¸ñ
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
void CRullerSplliterWnd::UpdateRulersInfo(stRULER_INFO stRulerInfo)
|
| 83 |
+
{
|
| 84 |
+
|
| 85 |
+
((CRulerView*)GetPane(0, 1))->UpdateRulersInfo(stRulerInfo);//¸üÐÂˮƽ±ê³ß
|
| 86 |
+
((CRulerView*)GetPane(1, 0))->UpdateRulersInfo(stRulerInfo);//¸üд¹Ö±±ê³ß
|
| 87 |
+
}
|
pool/shard002/C++/0024504_1_.cpp
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
int main() {
|
| 2 |
+
static int mu[N], is_prime[N];
|
| 3 |
+
fill(is_prime, is_prime + MAXV, true);
|
| 4 |
+
mu[1] = 1;
|
| 5 |
+
vector<int> primes;
|
| 6 |
+
for (int i = 2; i < MAXV; i++) {
|
| 7 |
+
if (is_prime[i]) {
|
| 8 |
+
primes.push_back(i); mu[i] = -1;
|
| 9 |
+
}
|
| 10 |
+
for (auto p : primes) {
|
| 11 |
+
if (1LL * i * p >= MAXV) break;
|
| 12 |
+
is_prime[p * i] = false;
|
| 13 |
+
if (i % p == 0) {
|
| 14 |
+
mu[i * p] = 0; break;
|
| 15 |
+
} else { mu[i * p] = -mu[i]; }
|
| 16 |
+
}
|
| 17 |
+
}
|
| 18 |
+
return 0;
|
| 19 |
+
}
|
pool/shard002/C++/0024508_mission_list_model.cpp
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "mission_list_model.h"
|
| 2 |
+
|
| 3 |
+
// Qt
|
| 4 |
+
#include <QDebug>
|
| 5 |
+
|
| 6 |
+
// Internal
|
| 7 |
+
#include "mission.h"
|
| 8 |
+
|
| 9 |
+
using namespace presentation;
|
| 10 |
+
|
| 11 |
+
MissionListModel::MissionListModel(QObject* parent):
|
| 12 |
+
QAbstractListModel(parent)
|
| 13 |
+
{}
|
| 14 |
+
|
| 15 |
+
int MissionListModel::rowCount(const QModelIndex& parent) const
|
| 16 |
+
{
|
| 17 |
+
Q_UNUSED(parent)
|
| 18 |
+
|
| 19 |
+
return m_missions.count();
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
QVariant MissionListModel::data(const QModelIndex& index, int role) const
|
| 23 |
+
{
|
| 24 |
+
if (!index.isValid() || index.row() >= m_missions.count()) return QVariant();
|
| 25 |
+
|
| 26 |
+
dto::MissionPtr mission = m_missions.at(index.row());
|
| 27 |
+
|
| 28 |
+
switch (role)
|
| 29 |
+
{
|
| 30 |
+
case MissionIdRole: return mission->id();
|
| 31 |
+
case MissionNameRole: return mission->name();
|
| 32 |
+
default: return QVariant();
|
| 33 |
+
}
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
void MissionListModel::setMissions(const dto::MissionPtrList& missions)
|
| 37 |
+
{
|
| 38 |
+
this->beginResetModel();
|
| 39 |
+
m_missions = missions;
|
| 40 |
+
this->endResetModel();
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
void MissionListModel::addMission(const dto::MissionPtr& mission)
|
| 44 |
+
{
|
| 45 |
+
this->beginInsertRows(QModelIndex(), this->rowCount(), this->rowCount());
|
| 46 |
+
m_missions.append(mission);
|
| 47 |
+
this->endInsertRows();
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
void MissionListModel::updateMission(const dto::MissionPtr& mission)
|
| 51 |
+
{
|
| 52 |
+
QModelIndex index = this->index(m_missions.indexOf(mission));
|
| 53 |
+
if (!index.isValid()) return;
|
| 54 |
+
|
| 55 |
+
emit dataChanged(index, index, { MissionNameRole });
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
void MissionListModel::removeMission(const dto::MissionPtr& mission)
|
| 59 |
+
{
|
| 60 |
+
int row = m_missions.indexOf(mission);
|
| 61 |
+
|
| 62 |
+
this->beginRemoveRows(QModelIndex(), row, row);
|
| 63 |
+
m_missions.removeOne(mission);
|
| 64 |
+
this->endRemoveRows();
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
QHash<int, QByteArray> MissionListModel::roleNames() const
|
| 68 |
+
{
|
| 69 |
+
QHash<int, QByteArray> roles;
|
| 70 |
+
|
| 71 |
+
roles[MissionIdRole] = "missionId";
|
| 72 |
+
roles[MissionNameRole] = "missionName";
|
| 73 |
+
|
| 74 |
+
return roles;
|
| 75 |
+
}
|
pool/shard002/C++/0024511_snipPartMerger.cpp
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//##################################################################################################
|
| 2 |
+
//
|
| 3 |
+
// Custom Visualization Core library
|
| 4 |
+
// Copyright (C) 2011-2013 Ceetron AS
|
| 5 |
+
//
|
| 6 |
+
// This library may be used under the terms of either the GNU General Public License or
|
| 7 |
+
// the GNU Lesser General Public License as follows:
|
| 8 |
+
//
|
| 9 |
+
// GNU General Public License Usage
|
| 10 |
+
// This library is free software: you can redistribute it and/or modify
|
| 11 |
+
// it under the terms of the GNU General Public License as published by
|
| 12 |
+
// the Free Software Foundation, either version 3 of the License, or
|
| 13 |
+
// (at your option) any later version.
|
| 14 |
+
//
|
| 15 |
+
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
| 16 |
+
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
| 17 |
+
// FITNESS FOR A PARTICULAR PURPOSE.
|
| 18 |
+
//
|
| 19 |
+
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
| 20 |
+
// for more details.
|
| 21 |
+
//
|
| 22 |
+
// GNU Lesser General Public License Usage
|
| 23 |
+
// This library is free software; you can redistribute it and/or modify
|
| 24 |
+
// it under the terms of the GNU Lesser General Public License as published by
|
| 25 |
+
// the Free Software Foundation; either version 2.1 of the License, or
|
| 26 |
+
// (at your option) any later version.
|
| 27 |
+
//
|
| 28 |
+
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
| 29 |
+
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
| 30 |
+
// FITNESS FOR A PARTICULAR PURPOSE.
|
| 31 |
+
//
|
| 32 |
+
// See the GNU Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
| 33 |
+
// for more details.
|
| 34 |
+
//
|
| 35 |
+
//##################################################################################################
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
#include "cvfLibCore.h"
|
| 39 |
+
#include "cvfLibRender.h"
|
| 40 |
+
#include "cvfLibViewing.h"
|
| 41 |
+
|
| 42 |
+
#include "snipPartMerger.h"
|
| 43 |
+
|
| 44 |
+
#include "cvfuPartCompoundGenerator.h"
|
| 45 |
+
|
| 46 |
+
namespace snip {
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
//--------------------------------------------------------------------------------------------------
|
| 50 |
+
///
|
| 51 |
+
//--------------------------------------------------------------------------------------------------
|
| 52 |
+
bool PartMerger::onInitialize()
|
| 53 |
+
{
|
| 54 |
+
PartCompoundGenerator gen;
|
| 55 |
+
gen.setPartDistribution(Vec3i(10, 10, 1));
|
| 56 |
+
gen.setNumEffects(8);
|
| 57 |
+
gen.useRandomEffectAssignment(false);
|
| 58 |
+
gen.setExtent(Vec3f(3,3,3));
|
| 59 |
+
gen.setOrigin(Vec3f(-1.5f, -1.5f, -1.5f));
|
| 60 |
+
gen.setNumDrawableGeos(10);
|
| 61 |
+
|
| 62 |
+
Collection<Part> parts;
|
| 63 |
+
gen.generateSpheres(7, 7, &parts);
|
| 64 |
+
|
| 65 |
+
gen.setPartDistribution(Vec3i(5, 1, 1));
|
| 66 |
+
gen.generateBoxes(&parts);
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
ref<ModelBasicTree> myModel = new ModelBasicTree;
|
| 70 |
+
ModelBasicTreeNode* root = new ModelBasicTreeNode;
|
| 71 |
+
|
| 72 |
+
size_t i = 0;
|
| 73 |
+
myModel->setRoot(root);
|
| 74 |
+
root->addPart(parts[i++].p());
|
| 75 |
+
|
| 76 |
+
ModelBasicTreeNode* c11 = new ModelBasicTreeNode;
|
| 77 |
+
root->addChild(c11);
|
| 78 |
+
c11->addPart(parts[i++].p());
|
| 79 |
+
|
| 80 |
+
ModelBasicTreeNode* c12 = new ModelBasicTreeNode;
|
| 81 |
+
root->addChild(c12);
|
| 82 |
+
c12->addPart(parts[i++].p());
|
| 83 |
+
c12->addPart(parts[i++].p());
|
| 84 |
+
c12->addPart(parts[i++].p());
|
| 85 |
+
c12->addPart(parts[i++].p());
|
| 86 |
+
|
| 87 |
+
ModelBasicTreeNode* c21 = new ModelBasicTreeNode;
|
| 88 |
+
c11->addChild(c21);
|
| 89 |
+
|
| 90 |
+
size_t j;
|
| 91 |
+
for (j = i; j < parts.size(); j++)
|
| 92 |
+
{
|
| 93 |
+
c21->addPart(parts[j].p());
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
myModel->updateBoundingBoxesRecursive();
|
| 97 |
+
|
| 98 |
+
// ModelStatistics stats;
|
| 99 |
+
// stats = myModel->computeStatistics();
|
| 100 |
+
// stats.showLog("before merge");
|
| 101 |
+
//
|
| 102 |
+
myModel->mergeParts(2, 200000);
|
| 103 |
+
|
| 104 |
+
// stats = myModel->computeStatistics();
|
| 105 |
+
// stats.showLog("after merge");
|
| 106 |
+
|
| 107 |
+
myModel->updateBoundingBoxesRecursive();
|
| 108 |
+
m_renderSequence->rendering(0)->scene()->addModel(myModel.p());
|
| 109 |
+
|
| 110 |
+
BoundingBox bb = myModel->boundingBox();
|
| 111 |
+
if (bb.isValid())
|
| 112 |
+
{
|
| 113 |
+
m_camera->fitView(bb, -Vec3d::Z_AXIS, Vec3d::Y_AXIS);
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
return true;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
} // namespace snip
|
| 121 |
+
|
pool/shard002/C++/0024513_EnumParameterType.cpp
ADDED
|
@@ -0,0 +1,350 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2011-2014, Intel Corporation
|
| 3 |
+
* All rights reserved.
|
| 4 |
+
*
|
| 5 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
| 6 |
+
* are permitted provided that the following conditions are met:
|
| 7 |
+
*
|
| 8 |
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
| 9 |
+
* list of conditions and the following disclaimer.
|
| 10 |
+
*
|
| 11 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
| 12 |
+
* this list of conditions and the following disclaimer in the documentation and/or
|
| 13 |
+
* other materials provided with the distribution.
|
| 14 |
+
*
|
| 15 |
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
| 16 |
+
* may be used to endorse or promote products derived from this software without
|
| 17 |
+
* specific prior written permission.
|
| 18 |
+
*
|
| 19 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
| 20 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
| 21 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 22 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
| 23 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 24 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 25 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
| 26 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 27 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
| 28 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 29 |
+
*/
|
| 30 |
+
#include "EnumParameterType.h"
|
| 31 |
+
#include <stdlib.h>
|
| 32 |
+
#include <sstream>
|
| 33 |
+
#include <iomanip>
|
| 34 |
+
#include <ctype.h>
|
| 35 |
+
#include <assert.h>
|
| 36 |
+
#include "ParameterAccessContext.h"
|
| 37 |
+
#include "EnumValuePair.h"
|
| 38 |
+
#include <errno.h>
|
| 39 |
+
|
| 40 |
+
#define base CParameterType
|
| 41 |
+
|
| 42 |
+
using std::string;
|
| 43 |
+
|
| 44 |
+
CEnumParameterType::CEnumParameterType(const string& strName) : base(strName)
|
| 45 |
+
{
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
string CEnumParameterType::getKind() const
|
| 49 |
+
{
|
| 50 |
+
return "EnumParameter";
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
bool CEnumParameterType::childrenAreDynamic() const
|
| 54 |
+
{
|
| 55 |
+
return true;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
// Element properties
|
| 59 |
+
void CEnumParameterType::showProperties(string& strResult) const
|
| 60 |
+
{
|
| 61 |
+
base::showProperties(strResult);
|
| 62 |
+
|
| 63 |
+
strResult += "Value Pairs:\n";
|
| 64 |
+
|
| 65 |
+
// Show all value pairs
|
| 66 |
+
size_t uiChild;
|
| 67 |
+
size_t uiNbChildren = getNbChildren();
|
| 68 |
+
|
| 69 |
+
for (uiChild = 0; uiChild < uiNbChildren; uiChild++) {
|
| 70 |
+
|
| 71 |
+
const CEnumValuePair* pValuePair = static_cast<const CEnumValuePair*>(getChild(uiChild));
|
| 72 |
+
|
| 73 |
+
strResult += "\tLiteral: \"";
|
| 74 |
+
strResult += pValuePair->getName();
|
| 75 |
+
strResult += "\", Numerical: ";
|
| 76 |
+
strResult += pValuePair->getNumericalAsString();
|
| 77 |
+
strResult += "\n";
|
| 78 |
+
}
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
bool CEnumParameterType::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext)
|
| 82 |
+
{
|
| 83 |
+
// Size in bits
|
| 84 |
+
uint32_t uiSizeInBits = xmlElement.getAttributeInteger("Size");
|
| 85 |
+
|
| 86 |
+
// Size
|
| 87 |
+
setSize(uiSizeInBits / 8);
|
| 88 |
+
|
| 89 |
+
// Base
|
| 90 |
+
return base::fromXml(xmlElement, serializingContext);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
// Conversion (tuning)
|
| 94 |
+
bool CEnumParameterType::toBlackboard(const string& strValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const
|
| 95 |
+
{
|
| 96 |
+
int64_t iData;
|
| 97 |
+
|
| 98 |
+
if (isNumber(strValue)) {
|
| 99 |
+
|
| 100 |
+
/// Numerical value provided
|
| 101 |
+
|
| 102 |
+
// Hexa
|
| 103 |
+
bool bValueProvidedAsHexa = !strValue.compare(0, 2, "0x");
|
| 104 |
+
|
| 105 |
+
errno = 0;
|
| 106 |
+
char *pcStrEnd;
|
| 107 |
+
|
| 108 |
+
// Get value
|
| 109 |
+
iData = strtoll(strValue.c_str(), &pcStrEnd, 0);
|
| 110 |
+
|
| 111 |
+
// Conversion error when the input string does not contain any digit or the number is out of range (int32_t type)
|
| 112 |
+
bool bConversionSucceeded = !errno && (strValue.c_str() != pcStrEnd);
|
| 113 |
+
|
| 114 |
+
// Check validity against type
|
| 115 |
+
if (!checkValueAgainstRange(strValue, iData, parameterAccessContext, bValueProvidedAsHexa, bConversionSucceeded)) {
|
| 116 |
+
|
| 117 |
+
return false;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
if (bValueProvidedAsHexa) {
|
| 121 |
+
|
| 122 |
+
// Sign extend
|
| 123 |
+
signExtend(iData);
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
// Check validity against lexical space
|
| 127 |
+
string strError;
|
| 128 |
+
if (!isValid(iData, parameterAccessContext)) {
|
| 129 |
+
|
| 130 |
+
parameterAccessContext.setError(strError);
|
| 131 |
+
|
| 132 |
+
return false;
|
| 133 |
+
}
|
| 134 |
+
} else {
|
| 135 |
+
/// Literal value provided
|
| 136 |
+
|
| 137 |
+
// Check validity against lexical space
|
| 138 |
+
int iNumerical;
|
| 139 |
+
if (!getNumerical(strValue, iNumerical)) {
|
| 140 |
+
|
| 141 |
+
parameterAccessContext.setError("Provided value not part of lexical space");
|
| 142 |
+
|
| 143 |
+
return false;
|
| 144 |
+
}
|
| 145 |
+
iData = iNumerical;
|
| 146 |
+
|
| 147 |
+
// Check validity against type
|
| 148 |
+
if (!checkValueAgainstRange(strValue, iData, parameterAccessContext, false, isEncodable((uint64_t)iData, true))) {
|
| 149 |
+
|
| 150 |
+
return false;
|
| 151 |
+
}
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
// Return data
|
| 155 |
+
uiValue = (uint32_t)iData;
|
| 156 |
+
|
| 157 |
+
return true;
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
// Range checking
|
| 161 |
+
bool CEnumParameterType::checkValueAgainstRange(const string& strValue, int64_t value, CParameterAccessContext& parameterAccessContext, bool bHexaValue, bool bConversionSucceeded) const
|
| 162 |
+
{
|
| 163 |
+
// Enums are always signed, it means we have one less util bit
|
| 164 |
+
int64_t maxValue = getMaxValue<uint64_t>();
|
| 165 |
+
int64_t minValue = -maxValue - 1;
|
| 166 |
+
|
| 167 |
+
if (!bConversionSucceeded || value < minValue || value > maxValue) {
|
| 168 |
+
|
| 169 |
+
std::ostringstream strStream;
|
| 170 |
+
|
| 171 |
+
strStream << "Value " << strValue << " standing out of admitted range [";
|
| 172 |
+
|
| 173 |
+
if (bHexaValue) {
|
| 174 |
+
|
| 175 |
+
// Format Min
|
| 176 |
+
strStream << "0x" << std::hex << std::uppercase << std::setw(getSize()*2) << std::setfill('0') << makeEncodable(minValue);
|
| 177 |
+
// Format Max
|
| 178 |
+
strStream << ", 0x" << std::hex << std::uppercase << std::setw(getSize()*2) << std::setfill('0') << makeEncodable(maxValue);
|
| 179 |
+
|
| 180 |
+
} else {
|
| 181 |
+
|
| 182 |
+
strStream << minValue << ", " << maxValue;
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
strStream << "] for " << getKind();
|
| 186 |
+
|
| 187 |
+
parameterAccessContext.setError(strStream.str());
|
| 188 |
+
|
| 189 |
+
return false;
|
| 190 |
+
}
|
| 191 |
+
return true;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
bool CEnumParameterType::fromBlackboard(string& strValue, const uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const
|
| 195 |
+
{
|
| 196 |
+
// Take care of format
|
| 197 |
+
if (parameterAccessContext.valueSpaceIsRaw()) {
|
| 198 |
+
|
| 199 |
+
// Format
|
| 200 |
+
std::ostringstream strStream;
|
| 201 |
+
|
| 202 |
+
// Numerical format requested
|
| 203 |
+
if (parameterAccessContext.outputRawFormatIsHex()) {
|
| 204 |
+
|
| 205 |
+
// Hexa display with unecessary bits cleared out
|
| 206 |
+
strStream << "0x" << std::hex << std::uppercase << std::setw(getSize()*2) << std::setfill('0') << makeEncodable(uiValue);
|
| 207 |
+
|
| 208 |
+
strValue = strStream.str();
|
| 209 |
+
} else {
|
| 210 |
+
|
| 211 |
+
// Integer display
|
| 212 |
+
int32_t iValue = uiValue;
|
| 213 |
+
|
| 214 |
+
// Sign extend
|
| 215 |
+
signExtend(iValue);
|
| 216 |
+
|
| 217 |
+
strStream << iValue;
|
| 218 |
+
|
| 219 |
+
strValue = strStream.str();
|
| 220 |
+
}
|
| 221 |
+
} else {
|
| 222 |
+
|
| 223 |
+
// Integer display
|
| 224 |
+
int32_t iValue = uiValue;
|
| 225 |
+
|
| 226 |
+
// Sign extend
|
| 227 |
+
signExtend(iValue);
|
| 228 |
+
|
| 229 |
+
// Literal display requested (should succeed)
|
| 230 |
+
getLiteral(iValue, strValue);
|
| 231 |
+
}
|
| 232 |
+
return true;
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
// Value access
|
| 236 |
+
bool CEnumParameterType::toBlackboard(int32_t iUserValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const
|
| 237 |
+
{
|
| 238 |
+
if (!isValid(iUserValue, parameterAccessContext)) {
|
| 239 |
+
|
| 240 |
+
return false;
|
| 241 |
+
}
|
| 242 |
+
uiValue = iUserValue;
|
| 243 |
+
|
| 244 |
+
return true;
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
bool CEnumParameterType::fromBlackboard(int32_t& iUserValue, uint32_t uiValue, CParameterAccessContext& parameterAccessContext) const
|
| 248 |
+
{
|
| 249 |
+
(void)parameterAccessContext;
|
| 250 |
+
|
| 251 |
+
int32_t iValue = uiValue;
|
| 252 |
+
|
| 253 |
+
// Sign extend
|
| 254 |
+
signExtend(iValue);
|
| 255 |
+
|
| 256 |
+
iUserValue = iValue;
|
| 257 |
+
|
| 258 |
+
return true;
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
// Default value handling (simulation only)
|
| 262 |
+
uint32_t CEnumParameterType::getDefaultValue() const
|
| 263 |
+
{
|
| 264 |
+
if (!getNbChildren()) {
|
| 265 |
+
|
| 266 |
+
return 0;
|
| 267 |
+
}
|
| 268 |
+
|
| 269 |
+
// Return first available numerical
|
| 270 |
+
return static_cast<const CEnumValuePair*>(getChild(0))->getNumerical();
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
// Check string is a number
|
| 274 |
+
bool CEnumParameterType::isNumber(const string& strValue)
|
| 275 |
+
{
|
| 276 |
+
char cFirst = strValue[0];
|
| 277 |
+
|
| 278 |
+
return isdigit(cFirst) || cFirst == '+' || cFirst == '-';
|
| 279 |
+
}
|
| 280 |
+
|
| 281 |
+
// Literal - numerical conversions
|
| 282 |
+
bool CEnumParameterType::getLiteral(int32_t iNumerical, string& strLiteral) const
|
| 283 |
+
{
|
| 284 |
+
size_t uiChild;
|
| 285 |
+
size_t uiNbChildren = getNbChildren();
|
| 286 |
+
|
| 287 |
+
for (uiChild = 0; uiChild < uiNbChildren; uiChild++) {
|
| 288 |
+
|
| 289 |
+
const CEnumValuePair* pValuePair = static_cast<const CEnumValuePair*>(getChild(uiChild));
|
| 290 |
+
|
| 291 |
+
if (pValuePair->getNumerical() == iNumerical) {
|
| 292 |
+
|
| 293 |
+
strLiteral = pValuePair->getName();
|
| 294 |
+
|
| 295 |
+
return true;
|
| 296 |
+
}
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
return false;
|
| 300 |
+
}
|
| 301 |
+
|
| 302 |
+
bool CEnumParameterType::getNumerical(const string& strLiteral, int& iNumerical) const
|
| 303 |
+
{
|
| 304 |
+
size_t uiChild;
|
| 305 |
+
size_t uiNbChildren = getNbChildren();
|
| 306 |
+
|
| 307 |
+
for (uiChild = 0; uiChild < uiNbChildren; uiChild++) {
|
| 308 |
+
|
| 309 |
+
const CEnumValuePair* pValuePair = static_cast<const CEnumValuePair*>(getChild(uiChild));
|
| 310 |
+
|
| 311 |
+
if (pValuePair->getName() == strLiteral) {
|
| 312 |
+
|
| 313 |
+
iNumerical = pValuePair->getNumerical();
|
| 314 |
+
|
| 315 |
+
return true;
|
| 316 |
+
}
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
return false;
|
| 320 |
+
}
|
| 321 |
+
|
| 322 |
+
// Numerical validity of the enum value
|
| 323 |
+
bool CEnumParameterType::isValid(int iNumerical, CParameterAccessContext& parameterAccessContext) const
|
| 324 |
+
{
|
| 325 |
+
// Check that the value is part of the allowed values for this kind of enum
|
| 326 |
+
size_t uiChild;
|
| 327 |
+
size_t uiNbChildren = getNbChildren();
|
| 328 |
+
|
| 329 |
+
for (uiChild = 0; uiChild < uiNbChildren; uiChild++) {
|
| 330 |
+
|
| 331 |
+
const CEnumValuePair* pValuePair = static_cast<const CEnumValuePair*>(getChild(uiChild));
|
| 332 |
+
|
| 333 |
+
if (pValuePair->getNumerical() == iNumerical) {
|
| 334 |
+
|
| 335 |
+
return true;
|
| 336 |
+
}
|
| 337 |
+
}
|
| 338 |
+
|
| 339 |
+
parameterAccessContext.setError("Provided value not part of numerical space");
|
| 340 |
+
|
| 341 |
+
return false;
|
| 342 |
+
}
|
| 343 |
+
// From IXmlSource
|
| 344 |
+
void CEnumParameterType::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const
|
| 345 |
+
{
|
| 346 |
+
// Size
|
| 347 |
+
xmlElement.setAttributeString("Size", toString(getSize() * 8));
|
| 348 |
+
|
| 349 |
+
base::toXml(xmlElement, serializingContext);
|
| 350 |
+
}
|
pool/shard002/C++/0024522_NuiMayaMeshGenerator.cpp
ADDED
|
@@ -0,0 +1,341 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "NuiMayaMeshGenerator.h"
|
| 2 |
+
#include "NuiMayaMeshData.h"
|
| 3 |
+
#include "../api_macros.h"
|
| 4 |
+
|
| 5 |
+
#include <maya/MFnMesh.h>
|
| 6 |
+
#include <maya/MFnMeshData.h>
|
| 7 |
+
#include <maya/MFnPluginData.h>
|
| 8 |
+
#include <maya/MFnTypedAttribute.h>
|
| 9 |
+
#include <maya/MFnNumericAttribute.h>
|
| 10 |
+
#include <maya/MFloatPointArray.h>
|
| 11 |
+
#include <maya/MFloatArray.h>
|
| 12 |
+
#include <maya/MDistance.h>
|
| 13 |
+
#include <maya/MGlobal.h>
|
| 14 |
+
|
| 15 |
+
#include <map>
|
| 16 |
+
|
| 17 |
+
////////////////////////////////////////////////////////////////////////////////
|
| 18 |
+
//
|
| 19 |
+
// Shape implementation
|
| 20 |
+
//
|
| 21 |
+
////////////////////////////////////////////////////////////////////////////////
|
| 22 |
+
|
| 23 |
+
MObject NuiMayaMeshGenerator::aInputData;
|
| 24 |
+
MObject NuiMayaMeshGenerator::aOutputMesh;
|
| 25 |
+
MObject NuiMayaMeshGenerator::aBodyIndex;
|
| 26 |
+
MObject NuiMayaMeshGenerator::aAssignUV;
|
| 27 |
+
|
| 28 |
+
MTypeId NuiMayaMeshGenerator::id( 0x80190 );
|
| 29 |
+
|
| 30 |
+
NuiMayaMeshGenerator::NuiMayaMeshGenerator()
|
| 31 |
+
: fNeedDirty(true)
|
| 32 |
+
{}
|
| 33 |
+
NuiMayaMeshGenerator::~NuiMayaMeshGenerator() {}
|
| 34 |
+
|
| 35 |
+
///////////////////////////////////////////////////////////////////////////////
|
| 36 |
+
//
|
| 37 |
+
// Overrides
|
| 38 |
+
//
|
| 39 |
+
///////////////////////////////////////////////////////////////////////////////
|
| 40 |
+
|
| 41 |
+
/* override */
|
| 42 |
+
MStatus NuiMayaMeshGenerator::compute( const MPlug& plug, MDataBlock& datablock )
|
| 43 |
+
//
|
| 44 |
+
// Description
|
| 45 |
+
//
|
| 46 |
+
// When input attributes are dirty this method will be called to
|
| 47 |
+
// recompute the output attributes.
|
| 48 |
+
//
|
| 49 |
+
{
|
| 50 |
+
MStatus stat;
|
| 51 |
+
if ( plug == aOutputMesh /*&& fNeedDirty*/) {
|
| 52 |
+
// Create some mesh data and access the
|
| 53 |
+
// geometry so we can set it
|
| 54 |
+
//
|
| 55 |
+
MFnMeshData dataCreator;
|
| 56 |
+
MObject newOutputData = dataCreator.create(&stat);
|
| 57 |
+
MCHECKERROR(stat, "ERROR creating outputData");
|
| 58 |
+
|
| 59 |
+
// If there is an input mesh then copy it's values
|
| 60 |
+
// and construct some apiMeshGeom for it.
|
| 61 |
+
//
|
| 62 |
+
stat = computeOutputMesh( plug, datablock, newOutputData);
|
| 63 |
+
if(stat != MS::kSuccess)
|
| 64 |
+
{
|
| 65 |
+
createEmptyMesh( newOutputData );
|
| 66 |
+
}
|
| 67 |
+
// Assign the new data to the outputSurface handle
|
| 68 |
+
//
|
| 69 |
+
MDataHandle outHandle = datablock.outputValue( aOutputMesh );
|
| 70 |
+
outHandle.set( newOutputData );
|
| 71 |
+
datablock.setClean( plug );
|
| 72 |
+
// Clear the flag.
|
| 73 |
+
fNeedDirty = false;
|
| 74 |
+
return MS::kSuccess;
|
| 75 |
+
}
|
| 76 |
+
else {
|
| 77 |
+
return MS::kUnknownParameter;
|
| 78 |
+
}
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
void NuiMayaMeshGenerator::createEmptyMesh( MObject& out_empytMesh )
|
| 82 |
+
{
|
| 83 |
+
MStatus status;
|
| 84 |
+
MFnMeshData meshData;
|
| 85 |
+
out_empytMesh = meshData.create( &status );
|
| 86 |
+
CHECK_MSTATUS( status );
|
| 87 |
+
|
| 88 |
+
MFloatPointArray vertexArray;
|
| 89 |
+
MIntArray polygonCounts;
|
| 90 |
+
MIntArray polygonConnects;
|
| 91 |
+
|
| 92 |
+
MFnMesh meshCreator;
|
| 93 |
+
MObject newMeshObject = meshCreator.create(
|
| 94 |
+
0, // nb vertices
|
| 95 |
+
0, // nb triangles
|
| 96 |
+
vertexArray,
|
| 97 |
+
polygonCounts,
|
| 98 |
+
polygonConnects,
|
| 99 |
+
out_empytMesh );
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
MStatus NuiMayaMeshGenerator::assignMeshUV( MObject& meshData, const MIntArray& polygonCounts, const MIntArray& uvIds )
|
| 104 |
+
{
|
| 105 |
+
|
| 106 |
+
MStatus stat = MS::kSuccess;
|
| 107 |
+
MString uvSetName("uvset1");
|
| 108 |
+
MFnMesh meshFn(meshData);
|
| 109 |
+
stat = meshFn.getCurrentUVSetName(uvSetName);
|
| 110 |
+
if ( stat != MS::kSuccess )
|
| 111 |
+
{
|
| 112 |
+
uvSetName = MString ("uvset1");
|
| 113 |
+
stat = meshFn.createUVSet(uvSetName);
|
| 114 |
+
stat = meshFn.setCurrentUVSetName(uvSetName);
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
//stat = meshFn.clearUVs();
|
| 118 |
+
//stat = meshFn.setUVs(uArray,vArray,&uvSetName);
|
| 119 |
+
stat = meshFn.assignUVs(polygonCounts, uvIds, &uvSetName);
|
| 120 |
+
if(stat != MS::kSuccess)
|
| 121 |
+
MGlobal::displayError( " Failed to assign UVs." );
|
| 122 |
+
return stat;
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
MStatus NuiMayaMeshGenerator::computeOutputMesh(
|
| 126 |
+
const MPlug& plug,
|
| 127 |
+
MDataBlock& datablock,
|
| 128 |
+
MObject& meshData)
|
| 129 |
+
//
|
| 130 |
+
// Description
|
| 131 |
+
//
|
| 132 |
+
// This function takes an input surface of type kMeshData and converts
|
| 133 |
+
// the geometry into this nodes attributes.
|
| 134 |
+
// Returns kFailure if nothing is connected.
|
| 135 |
+
//
|
| 136 |
+
{
|
| 137 |
+
MStatus stat;
|
| 138 |
+
|
| 139 |
+
MDataHandle inputHandle = datablock.inputValue( aInputData, &stat );
|
| 140 |
+
MCHECKERROR( stat, "computeInputSurface error getting inputSurface")
|
| 141 |
+
|
| 142 |
+
// Check if anything is connected
|
| 143 |
+
//
|
| 144 |
+
MObject thisObj = thisMObject();
|
| 145 |
+
MPlug surfPlug( thisObj, aInputData );
|
| 146 |
+
if ( !surfPlug.isConnected() ) {
|
| 147 |
+
stat = datablock.setClean( plug );
|
| 148 |
+
MCHECKERROR( stat, "compute setClean" )
|
| 149 |
+
return MS::kFailure;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
NuiMayaMeshData* surf = (NuiMayaMeshData*) inputHandle.asPluginData();
|
| 153 |
+
if ( NULL == surf ) {
|
| 154 |
+
cerr << "NULL inputCloudData data found\n";
|
| 155 |
+
return MS::kFailure;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
NuiMeshShape* geomPtr = surf->data().get();
|
| 159 |
+
if ( NULL == geomPtr ) {
|
| 160 |
+
cerr << "NULL pointCloudGeom found\n";
|
| 161 |
+
return MS::kFailure;
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
double distanceUnit = 1.0;
|
| 165 |
+
MDistance::Unit currentUnit = MDistance::internalUnit();
|
| 166 |
+
if(currentUnit != MDistance::kInvalid)
|
| 167 |
+
{
|
| 168 |
+
distanceUnit = MDistance(1.0, MDistance::kMeters).as(currentUnit);
|
| 169 |
+
}
|
| 170 |
+
else
|
| 171 |
+
{
|
| 172 |
+
MGlobal::displayError( " Invalid distance unit." );
|
| 173 |
+
return MS::kFailure;
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
MFloatPointArray vertexArray;
|
| 177 |
+
MIntArray polygonCounts;
|
| 178 |
+
MIntArray polygonConnects;
|
| 179 |
+
MFloatArray uArray;
|
| 180 |
+
MFloatArray vArray;
|
| 181 |
+
MIntArray uvIds;
|
| 182 |
+
|
| 183 |
+
const UINT numPoints = (UINT)geomPtr->pointsNum();
|
| 184 |
+
for (UINT i = 0; i < numPoints; ++i)
|
| 185 |
+
{
|
| 186 |
+
const SgVec3f& pt = geomPtr->getPoint(i);
|
| 187 |
+
MPoint pnt(pt[0], pt[1], pt[2]);
|
| 188 |
+
vertexArray.append(pnt);
|
| 189 |
+
|
| 190 |
+
const SgVec2f& uv = geomPtr->getUV(i);
|
| 191 |
+
uArray.append(uv[0]);
|
| 192 |
+
vArray.append(uv[1]);
|
| 193 |
+
uvIds.append(i);
|
| 194 |
+
}
|
| 195 |
+
const UINT numTris = (UINT)geomPtr->trianglesNum();
|
| 196 |
+
for (UINT i = 0; i < numTris; ++i)
|
| 197 |
+
{
|
| 198 |
+
int index1 = geomPtr->triangleIndex(3*i);
|
| 199 |
+
int index2 = geomPtr->triangleIndex(3*i+1);
|
| 200 |
+
int index3 = geomPtr->triangleIndex(3*i+2);
|
| 201 |
+
if(index1 < 0 || index2 < 0 || index3 < 0)
|
| 202 |
+
continue;
|
| 203 |
+
|
| 204 |
+
polygonConnects.append(index1);
|
| 205 |
+
polygonConnects.append(index2);
|
| 206 |
+
polygonConnects.append(index3);
|
| 207 |
+
polygonCounts.append(3);
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
MFnMesh meshFn;
|
| 211 |
+
meshFn.create(vertexArray.length(), polygonCounts.length(), vertexArray, polygonCounts, polygonConnects, uArray, vArray, meshData, &stat);
|
| 212 |
+
|
| 213 |
+
bool needAssignUV = true;
|
| 214 |
+
/*inputHandle = datablock.inputValue( aAssignUV, &stat );
|
| 215 |
+
if(stat == MS::kSuccess)
|
| 216 |
+
needAssignUV = inputHandle.asBool();*/
|
| 217 |
+
if(needAssignUV)
|
| 218 |
+
// assignMeshUV(meshData, polygonCounts, uvIds);
|
| 219 |
+
{
|
| 220 |
+
MString uvSetName("uvset1");
|
| 221 |
+
/*MFnMesh meshFn(meshData);
|
| 222 |
+
stat = meshFn.getCurrentUVSetName(uvSetName);
|
| 223 |
+
if ( stat != MS::kSuccess )
|
| 224 |
+
{
|
| 225 |
+
uvSetName = MString ("uvset1");
|
| 226 |
+
stat = meshFn.createUVSet(uvSetName);
|
| 227 |
+
stat = meshFn.setCurrentUVSetName(uvSetName);
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
stat = meshFn.clearUVs();
|
| 231 |
+
stat = meshFn.setUVs(uArray,vArray,&uvSetName);*/
|
| 232 |
+
stat = meshFn.assignUVs(polygonCounts, uvIds, &uvSetName);
|
| 233 |
+
if(stat != MS::kSuccess)
|
| 234 |
+
MGlobal::displayError( " Failed to assign UVs." );
|
| 235 |
+
}
|
| 236 |
+
return stat;
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
/* override */
|
| 240 |
+
//
|
| 241 |
+
// Description
|
| 242 |
+
//
|
| 243 |
+
// Horribly abuse the purpose of this method to notify the Viewport 2.0
|
| 244 |
+
// renderer that something about this shape has changed and that it should
|
| 245 |
+
// be retranslated.
|
| 246 |
+
//
|
| 247 |
+
MStatus NuiMayaMeshGenerator::setDependentsDirty( const MPlug& plug, MPlugArray& plugArray)
|
| 248 |
+
{
|
| 249 |
+
// if the dirty attribute is the output mesh then we need to signal the
|
| 250 |
+
// the renderer that it needs to update the object
|
| 251 |
+
|
| 252 |
+
/*if ( plug == aInputPointCloud)
|
| 253 |
+
{
|
| 254 |
+
fNeedDirty = true;
|
| 255 |
+
}*/
|
| 256 |
+
return MS::kSuccess;
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
MStatus NuiMayaMeshGenerator::connectionMade( const MPlug& plug,
|
| 260 |
+
const MPlug& otherPlug,
|
| 261 |
+
bool asSrc )
|
| 262 |
+
//
|
| 263 |
+
// Description
|
| 264 |
+
//
|
| 265 |
+
// Whenever a connection to this node is broken, this method
|
| 266 |
+
// will get called.
|
| 267 |
+
//
|
| 268 |
+
{
|
| 269 |
+
if ( plug == aInputData ) {
|
| 270 |
+
fNeedDirty = true;
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
return MPxNode::connectionBroken( plug, otherPlug, asSrc );
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
void* NuiMayaMeshGenerator::creator()
|
| 277 |
+
//
|
| 278 |
+
// Description
|
| 279 |
+
// Called internally to create a new instance of the users MPx node.
|
| 280 |
+
//
|
| 281 |
+
{
|
| 282 |
+
return new NuiMayaMeshGenerator();
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
MStatus NuiMayaMeshGenerator::initialize()
|
| 286 |
+
//
|
| 287 |
+
// Description
|
| 288 |
+
//
|
| 289 |
+
// Attribute (static) initialization. See api_macros.h.
|
| 290 |
+
//
|
| 291 |
+
{
|
| 292 |
+
MStatus stat;
|
| 293 |
+
MFnTypedAttribute typedAttr;
|
| 294 |
+
MFnNumericAttribute nAttr;
|
| 295 |
+
|
| 296 |
+
// ----------------------- INPUTS -------------------------
|
| 297 |
+
aInputData = typedAttr.create( "inputMesh", "ipc",
|
| 298 |
+
NuiMayaMeshData::id,
|
| 299 |
+
MObject::kNullObj, &stat );
|
| 300 |
+
MCHECKERROR( stat, "create inputMesh attribute" )
|
| 301 |
+
typedAttr.setStorable( false );
|
| 302 |
+
ADD_ATTRIBUTE( aInputData );
|
| 303 |
+
|
| 304 |
+
aBodyIndex = nAttr.create( "bodyIndex", "bi", MFnNumericData::kByte, 6 );
|
| 305 |
+
// Attribute will be written to files when this type of node is stored
|
| 306 |
+
nAttr.setStorable(true);
|
| 307 |
+
// Attribute is keyable and will show up in the channel box
|
| 308 |
+
nAttr.setKeyable(true);
|
| 309 |
+
nAttr.setMin(0);
|
| 310 |
+
nAttr.setMax(6);
|
| 311 |
+
// Add the attributes we have created to the node
|
| 312 |
+
//
|
| 313 |
+
stat = addAttribute( aBodyIndex );
|
| 314 |
+
if (!stat) { stat.perror("addAttribute"); return stat;}
|
| 315 |
+
|
| 316 |
+
aAssignUV = nAttr.create( "assignUV", "uv", MFnNumericData::kBoolean, true );
|
| 317 |
+
// Attribute will be written to files when this type of node is stored
|
| 318 |
+
nAttr.setStorable(true);
|
| 319 |
+
// Attribute is keyable and will show up in the channel box
|
| 320 |
+
nAttr.setKeyable(true);
|
| 321 |
+
// Add the attributes we have created to the node
|
| 322 |
+
//
|
| 323 |
+
stat = addAttribute( aAssignUV );
|
| 324 |
+
if (!stat) { stat.perror("addAttribute"); return stat;}
|
| 325 |
+
|
| 326 |
+
// ----------------------- OUTPUTS -------------------------
|
| 327 |
+
aOutputMesh = typedAttr.create( "outputMesh", "out",
|
| 328 |
+
MFnData::kMesh,
|
| 329 |
+
MObject::kNullObj, &stat );
|
| 330 |
+
MCHECKERROR( stat, "create outputSurface attribute" )
|
| 331 |
+
typedAttr.setWritable( false );
|
| 332 |
+
ADD_ATTRIBUTE( aOutputMesh );
|
| 333 |
+
|
| 334 |
+
// ---------- Specify what inputs affect the outputs ----------
|
| 335 |
+
//
|
| 336 |
+
ATTRIBUTE_AFFECTS( aInputData, aOutputMesh );
|
| 337 |
+
ATTRIBUTE_AFFECTS( aBodyIndex, aOutputMesh );
|
| 338 |
+
ATTRIBUTE_AFFECTS( aAssignUV, aOutputMesh );
|
| 339 |
+
|
| 340 |
+
return MS::kSuccess;
|
| 341 |
+
}
|
pool/shard002/C++/0024528_ASN1_ValueUTF8String.cpp
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2016, 2017 Alexandre SZYDLOWSKI <alexandre.szydlowski@gmail.com>. All rights reserved.
|
| 3 |
+
* Redistribution and modifications are permitted subject to GPL-V3 license.
|
| 4 |
+
*/
|
| 5 |
+
#include "ASN1_Value_Nodes.h"
|
| 6 |
+
|
| 7 |
+
using namespace Utils;
|
| 8 |
+
|
| 9 |
+
namespace Value {
|
| 10 |
+
|
| 11 |
+
void ASN1_ValueUTF8String::UTF8StringToHex(const std::string& input, ByteArray& output, std::string& error) {
|
| 12 |
+
error.clear();
|
| 13 |
+
output = "";
|
| 14 |
+
if (Utils::IsValidUTF8String(input))
|
| 15 |
+
output = Utils::StringToHex(input);
|
| 16 |
+
else
|
| 17 |
+
error = "Input string does not match the UTF8 format";
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
void ASN1_ValueUTF8String::HexToUTF8String(const ByteArray& input, std::string& output, std::string& error) {
|
| 21 |
+
error.clear();
|
| 22 |
+
output = "";
|
| 23 |
+
std::string s = Utils::HexToString(input);
|
| 24 |
+
if (Utils::IsValidUTF8String(s))
|
| 25 |
+
output = s;
|
| 26 |
+
else
|
| 27 |
+
error = "Input string does not match the UTF8 format";
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
}
|
pool/shard002/C++/0024533_Versions.cpp
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Versions.h
|
| 3 |
+
*
|
| 4 |
+
* This file is part of the IHMC DSPro Library/Component
|
| 5 |
+
* Copyright (c) 2008-2016 IHMC.
|
| 6 |
+
*
|
| 7 |
+
* This program is free software; you can redistribute it and/or
|
| 8 |
+
* modify it under the terms of the GNU General Public License
|
| 9 |
+
* version 3 (GPLv3) as published by the Free Software Foundation.
|
| 10 |
+
*
|
| 11 |
+
* U.S. Government agencies and organizations may redistribute
|
| 12 |
+
* and/or modify this program under terms equivalent to
|
| 13 |
+
* "Government Purpose Rights" as defined by DFARS
|
| 14 |
+
* 252.227-7014(a)(12) (February 2014).
|
| 15 |
+
*
|
| 16 |
+
* Alternative licenses that allow for use within commercial products may be
|
| 17 |
+
* available. Contact Niranjan Suri at IHMC (nsuri@ihmc.us) for details.
|
| 18 |
+
*
|
| 19 |
+
* Author: Giacomo Benincasa (gbenincasa@ihmc.us)
|
| 20 |
+
* Created on December 22, 2016, 12:45 PM
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
#include "Versions.h"
|
| 24 |
+
|
| 25 |
+
#include "Defs.h"
|
| 26 |
+
|
| 27 |
+
#include "Logger.h"
|
| 28 |
+
#include "Writer.h"
|
| 29 |
+
|
| 30 |
+
#include "Json.h"
|
| 31 |
+
#include <stdlib.h>
|
| 32 |
+
|
| 33 |
+
using namespace IHMC_ACI;
|
| 34 |
+
using namespace NOMADSUtil;
|
| 35 |
+
|
| 36 |
+
const char * Versions::VERSIONS_OBJECT_NAME = "versions";
|
| 37 |
+
const char * Versions::STARTING_TIME = "startingTime";
|
| 38 |
+
const char * Versions::INFO_VERSION = "nodeInfo";
|
| 39 |
+
const char * Versions::PATH_VERSION = "path";
|
| 40 |
+
const char * Versions::WAYPOINT_VERSION = "waypoint";
|
| 41 |
+
const char * Versions::CLASSIFIER_VERSION = "classifier";
|
| 42 |
+
const char * Versions::MATCHMAKING_VERSION = "matchmaking";
|
| 43 |
+
|
| 44 |
+
Versions::Versions (void)
|
| 45 |
+
: _i64StartingTime (0), _ui16InfoVersion (0), _ui16PathVersion (0),
|
| 46 |
+
_ui16WaypointVersion (0), _ui16ClassifierVersion (0), _ui16MatchmakerQualifierVersion (0),
|
| 47 |
+
_ui16AreasOfInterestVersion (0)
|
| 48 |
+
{
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
Versions::Versions (int64 i64StartingTime, uint16 ui16InfoVersion, uint16 ui16PathVersion,
|
| 52 |
+
uint16 ui16WaypointVersion, uint16 ui16ClassifierVersion, uint16 ui16MatchmakerQualifierVersion,
|
| 53 |
+
uint16 ui16AreasOfInterestVersion)
|
| 54 |
+
: _i64StartingTime (i64StartingTime), _ui16InfoVersion (ui16InfoVersion),
|
| 55 |
+
_ui16PathVersion (ui16PathVersion), _ui16WaypointVersion (ui16WaypointVersion),
|
| 56 |
+
_ui16ClassifierVersion (ui16ClassifierVersion), _ui16MatchmakerQualifierVersion (ui16MatchmakerQualifierVersion),
|
| 57 |
+
_ui16AreasOfInterestVersion (ui16AreasOfInterestVersion)
|
| 58 |
+
{
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
Versions::Versions (const Versions &version)
|
| 62 |
+
: _i64StartingTime (version._i64StartingTime), _ui16InfoVersion (version._ui16InfoVersion),
|
| 63 |
+
_ui16PathVersion (version._ui16PathVersion), _ui16WaypointVersion (version._ui16WaypointVersion),
|
| 64 |
+
_ui16ClassifierVersion (version._ui16ClassifierVersion), _ui16MatchmakerQualifierVersion (version._ui16MatchmakerQualifierVersion),
|
| 65 |
+
_ui16AreasOfInterestVersion (version._ui16AreasOfInterestVersion)
|
| 66 |
+
{
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
Versions::~Versions (void)
|
| 70 |
+
{
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
void Versions::reset (void)
|
| 74 |
+
{
|
| 75 |
+
_i64StartingTime = (int64)0;
|
| 76 |
+
_ui16InfoVersion = (uint16)0;
|
| 77 |
+
_ui16PathVersion = (uint16)0;
|
| 78 |
+
_ui16WaypointVersion = (uint16)0;
|
| 79 |
+
_ui16ClassifierVersion = (uint16)0;
|
| 80 |
+
_ui16MatchmakerQualifierVersion = (uint16)0;
|
| 81 |
+
_ui16AreasOfInterestVersion = (uint16)0;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
void Versions::set (int64 i64StartingTime, uint16 ui16InfoVersion, uint16 ui16PathVersion,
|
| 85 |
+
uint16 ui16WaypointVersion, uint16 ui16ClassifierVersion, uint16 ui16MatchmakerQualifierVersion,
|
| 86 |
+
uint16 ui16AreasOfInterestVersion)
|
| 87 |
+
{
|
| 88 |
+
_i64StartingTime = i64StartingTime;
|
| 89 |
+
_ui16InfoVersion = ui16InfoVersion;
|
| 90 |
+
_ui16PathVersion = ui16PathVersion;
|
| 91 |
+
_ui16WaypointVersion = ui16WaypointVersion;
|
| 92 |
+
_ui16ClassifierVersion = ui16ClassifierVersion;
|
| 93 |
+
_ui16MatchmakerQualifierVersion = ui16MatchmakerQualifierVersion;
|
| 94 |
+
_ui16AreasOfInterestVersion = ui16AreasOfInterestVersion;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
bool Versions::greaterThan (const Versions &versions, bool bExcludeWayPointVersion) const
|
| 98 |
+
{
|
| 99 |
+
if ((_ui16InfoVersion > versions._ui16InfoVersion) ||
|
| 100 |
+
(_ui16PathVersion > versions._ui16PathVersion) ||
|
| 101 |
+
(_ui16ClassifierVersion > versions._ui16ClassifierVersion) ||
|
| 102 |
+
(_ui16MatchmakerQualifierVersion > versions._ui16MatchmakerQualifierVersion) ||
|
| 103 |
+
(_ui16AreasOfInterestVersion > versions._ui16AreasOfInterestVersion)) {
|
| 104 |
+
return true;
|
| 105 |
+
}
|
| 106 |
+
if (!bExcludeWayPointVersion) {
|
| 107 |
+
return (_ui16WaypointVersion > versions._ui16WaypointVersion);
|
| 108 |
+
}
|
| 109 |
+
return false;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
bool Versions::lessThan (const Versions &versions, bool bExcludeWayPointVersion) const
|
| 113 |
+
{
|
| 114 |
+
if ((_ui16InfoVersion < versions._ui16InfoVersion) ||
|
| 115 |
+
(_ui16PathVersion < versions._ui16PathVersion) ||
|
| 116 |
+
(_ui16ClassifierVersion < versions._ui16ClassifierVersion) ||
|
| 117 |
+
(_ui16MatchmakerQualifierVersion < versions._ui16MatchmakerQualifierVersion) ||
|
| 118 |
+
(_ui16AreasOfInterestVersion < versions._ui16AreasOfInterestVersion)) {
|
| 119 |
+
return true;
|
| 120 |
+
}
|
| 121 |
+
if (!bExcludeWayPointVersion) {
|
| 122 |
+
return (_ui16WaypointVersion < versions._ui16WaypointVersion);
|
| 123 |
+
}
|
| 124 |
+
return false;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
bool Versions::pathGreater (const Versions &version) const
|
| 128 |
+
{
|
| 129 |
+
if (_i64StartingTime > version._i64StartingTime) {
|
| 130 |
+
return true;
|
| 131 |
+
}
|
| 132 |
+
return (_ui16PathVersion > version._ui16PathVersion);
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
namespace VERSIONS_JSON_NAMES
|
| 136 |
+
{
|
| 137 |
+
const char * INFO = "nodeInfo";
|
| 138 |
+
const char * PATH = "path";
|
| 139 |
+
const char * WAYPOINT = "waypoint";
|
| 140 |
+
const char * CLASSIFIER = "classifier";
|
| 141 |
+
const char * MATCHMAKER = "matchmaker";
|
| 142 |
+
const char * AREAS_OF_INTEREST = "areasOfInterest";
|
| 143 |
+
const char * STARTING_TIME = "startingTime";
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
int Versions::fromJson (const JsonObject *pJson)
|
| 147 |
+
{
|
| 148 |
+
const char *pszMethodName = "Versions::fromJson";
|
| 149 |
+
if (pJson == nullptr) {
|
| 150 |
+
return -1;
|
| 151 |
+
}
|
| 152 |
+
int64 i64StartingTime = _i64StartingTime;
|
| 153 |
+
uint16 ui16InfoVersion = _ui16InfoVersion;
|
| 154 |
+
uint16 ui16PathVersion = _ui16PathVersion;
|
| 155 |
+
uint16 ui16WaypointVersion = _ui16WaypointVersion;
|
| 156 |
+
uint16 ui16ClassifierVersion = _ui16ClassifierVersion;
|
| 157 |
+
uint16 ui16MatchmakerQualifierVersion = _ui16MatchmakerQualifierVersion;
|
| 158 |
+
uint16 ui16AreasOfInterestVersion = _ui16AreasOfInterestVersion;
|
| 159 |
+
int rc = pJson->getNumber (VERSIONS_JSON_NAMES::INFO, ui16InfoVersion);
|
| 160 |
+
rc += pJson->getNumber (VERSIONS_JSON_NAMES::PATH, ui16PathVersion);
|
| 161 |
+
rc += pJson->getNumber (VERSIONS_JSON_NAMES::WAYPOINT, ui16WaypointVersion);
|
| 162 |
+
rc += pJson->getNumber (VERSIONS_JSON_NAMES::CLASSIFIER, ui16ClassifierVersion);
|
| 163 |
+
rc += pJson->getNumber (VERSIONS_JSON_NAMES::MATCHMAKER, ui16MatchmakerQualifierVersion);
|
| 164 |
+
rc += pJson->getNumber (VERSIONS_JSON_NAMES::AREAS_OF_INTEREST, ui16AreasOfInterestVersion);
|
| 165 |
+
rc += pJson->getNumber (VERSIONS_JSON_NAMES::STARTING_TIME, i64StartingTime);
|
| 166 |
+
if (rc != 0) {
|
| 167 |
+
checkAndLogMsg (pszMethodName, Logger::L_Warning, "version message protocol version mismatch.\n");
|
| 168 |
+
}
|
| 169 |
+
set (i64StartingTime, ui16InfoVersion, ui16PathVersion, ui16WaypointVersion,
|
| 170 |
+
ui16ClassifierVersion, ui16MatchmakerQualifierVersion, ui16AreasOfInterestVersion);
|
| 171 |
+
return 0;
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
JsonObject * Versions::toJson (void) const
|
| 175 |
+
{
|
| 176 |
+
JsonObject *pJson = new JsonObject();
|
| 177 |
+
if (pJson == nullptr) {
|
| 178 |
+
return nullptr;
|
| 179 |
+
}
|
| 180 |
+
int rc = pJson->setNumber (VERSIONS_JSON_NAMES::INFO, _ui16InfoVersion);
|
| 181 |
+
rc += pJson->setNumber (VERSIONS_JSON_NAMES::PATH, _ui16PathVersion);
|
| 182 |
+
rc += pJson->setNumber (VERSIONS_JSON_NAMES::WAYPOINT, _ui16WaypointVersion);
|
| 183 |
+
rc += pJson->setNumber (VERSIONS_JSON_NAMES::CLASSIFIER, _ui16ClassifierVersion);
|
| 184 |
+
rc += pJson->setNumber (VERSIONS_JSON_NAMES::MATCHMAKER, _ui16MatchmakerQualifierVersion);
|
| 185 |
+
rc += pJson->setNumber (VERSIONS_JSON_NAMES::AREAS_OF_INTEREST, _ui16AreasOfInterestVersion);
|
| 186 |
+
rc += pJson->setNumber (VERSIONS_JSON_NAMES::STARTING_TIME, _i64StartingTime);
|
| 187 |
+
if (rc != 0) {
|
| 188 |
+
delete pJson;
|
| 189 |
+
return nullptr;
|
| 190 |
+
}
|
| 191 |
+
return pJson;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
int Versions::read (Reader *pReader)
|
| 195 |
+
{
|
| 196 |
+
if (pReader == nullptr) {
|
| 197 |
+
return -1;
|
| 198 |
+
}
|
| 199 |
+
char *pszVersions = nullptr;
|
| 200 |
+
if (pReader->readString (&pszVersions) < 0) {
|
| 201 |
+
if (pReader != nullptr) {
|
| 202 |
+
free (pszVersions);
|
| 203 |
+
}
|
| 204 |
+
}
|
| 205 |
+
if (pszVersions == nullptr) {
|
| 206 |
+
return -2;
|
| 207 |
+
}
|
| 208 |
+
JsonObject json (pszVersions);
|
| 209 |
+
int rc = fromJson (&json);
|
| 210 |
+
free (pszVersions);
|
| 211 |
+
return rc < 0 ? -3 : 0;
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
int Versions::write (Writer *pWriter)
|
| 215 |
+
{
|
| 216 |
+
if (pWriter == nullptr) {
|
| 217 |
+
return -1;
|
| 218 |
+
}
|
| 219 |
+
const JsonObject *pVersions = toJson();
|
| 220 |
+
String json (pVersions->toString());
|
| 221 |
+
if (pWriter->writeString (json) < 0) {
|
| 222 |
+
return -2;
|
| 223 |
+
}
|
| 224 |
+
return 0;
|
| 225 |
+
}
|
| 226 |
+
|
pool/shard002/C++/0024534_Plot2DProfile.cpp
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "Plot2DProfile.h"
|
| 2 |
+
#include "Data/Profile/ProfilePlotStyles.h"
|
| 3 |
+
#include "CartaLib/PixelPipeline/CustomizablePixelPipeline.h"
|
| 4 |
+
#include <qwt_painter.h>
|
| 5 |
+
#include <qwt_symbol.h>
|
| 6 |
+
|
| 7 |
+
#include <QDebug>
|
| 8 |
+
|
| 9 |
+
namespace Carta {
|
| 10 |
+
namespace Plot2D {
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
Plot2DProfile::Plot2DProfile(){
|
| 14 |
+
|
| 15 |
+
setStyle(QwtPlotCurve::Lines);
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
void Plot2DProfile::attachToPlot( QwtPlot* plot ){
|
| 20 |
+
attach( plot );
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
void Plot2DProfile::detachFromPlot(){
|
| 25 |
+
detach();
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
void Plot2DProfile::drawLines (QPainter *painter, const QwtScaleMap &xMap,
|
| 30 |
+
const QwtScaleMap &yMap,
|
| 31 |
+
const QRectF &canvasRect, int from, int to) const{
|
| 32 |
+
if ( painter->isActive() ){
|
| 33 |
+
QPen curvePen( m_defaultColor );
|
| 34 |
+
curvePen.setStyle( m_penStyle );
|
| 35 |
+
painter->setPen( curvePen );
|
| 36 |
+
if ( from != to ){
|
| 37 |
+
QwtPlotCurve::drawLines( painter, xMap, yMap, canvasRect, from, to );
|
| 38 |
+
}
|
| 39 |
+
else {
|
| 40 |
+
drawSymbol( painter, xMap, yMap, canvasRect, from, to );
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
void Plot2DProfile::drawSteps (QPainter *painter, const QwtScaleMap &xMap,
|
| 47 |
+
const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const {
|
| 48 |
+
if ( painter->isActive() ){
|
| 49 |
+
QPen curvePen( m_defaultColor );
|
| 50 |
+
curvePen.setStyle( m_penStyle );
|
| 51 |
+
painter->setPen( curvePen );
|
| 52 |
+
if ( from != to ){
|
| 53 |
+
QwtPlotCurve::drawSteps( painter, xMap, yMap, canvasRect, from, to );
|
| 54 |
+
}
|
| 55 |
+
else {
|
| 56 |
+
drawSymbol( painter, xMap, yMap, canvasRect, from, to );
|
| 57 |
+
}
|
| 58 |
+
}
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
void Plot2DProfile::drawSymbol( QPainter* painter, const QwtScaleMap & xMap,
|
| 62 |
+
const QwtScaleMap & yMap, const QRectF & canvasRect, int from, int to ) const{
|
| 63 |
+
QPen curvePen( m_defaultColor );
|
| 64 |
+
QBrush brush( m_defaultColor );
|
| 65 |
+
QSize symbolSize( 10, 10 );
|
| 66 |
+
QwtSymbol symbol ( QwtSymbol::Diamond, brush, curvePen, symbolSize );
|
| 67 |
+
drawSymbols( painter, symbol, xMap, yMap, canvasRect, from, to );
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
std::pair<double,double> Plot2DProfile::getClosestPoint( double targetX, double targetY,
|
| 71 |
+
double* xError, double* yError ) const {
|
| 72 |
+
int dataCount = m_datasX.size();
|
| 73 |
+
std::pair<double,double> closestPt( targetX, targetY );
|
| 74 |
+
for ( int i = 0; i < dataCount; i++ ){
|
| 75 |
+
double ptErrorX = qAbs( m_datasX[i] - targetX );
|
| 76 |
+
double ptErrorY = qAbs( m_datasY[i] - targetY );
|
| 77 |
+
if ( ptErrorX < *xError && ptErrorY < *yError ){
|
| 78 |
+
*xError = ptErrorX;
|
| 79 |
+
*yError = ptErrorY;
|
| 80 |
+
closestPt.first = m_datasX[i];
|
| 81 |
+
closestPt.second = m_datasY[i];
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
return closestPt;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
QwtGraphic Plot2DProfile::legendIcon( int /*index*/, const QSizeF& iconSize ) const {
|
| 88 |
+
if ( iconSize.isEmpty() ){
|
| 89 |
+
return QwtGraphic();
|
| 90 |
+
}
|
| 91 |
+
QwtGraphic icon;
|
| 92 |
+
icon.setDefaultSize( iconSize );
|
| 93 |
+
icon.setRenderHint( QwtGraphic::RenderPensUnscaled, true );
|
| 94 |
+
|
| 95 |
+
QPainter painter( &icon );
|
| 96 |
+
QPen pen( m_defaultColor );
|
| 97 |
+
pen.setStyle( m_penStyle );
|
| 98 |
+
pen.setWidth( 3 );
|
| 99 |
+
const double y = 0.5 * iconSize.height();
|
| 100 |
+
QPainterPath path;
|
| 101 |
+
path.moveTo( 0.0, y );
|
| 102 |
+
path.lineTo( iconSize.width(), y );
|
| 103 |
+
painter.strokePath( path, pen );
|
| 104 |
+
return icon;
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
void Plot2DProfile::setData ( std::vector<std::pair<double,double> > datas ){
|
| 108 |
+
int dataCount = datas.size();
|
| 109 |
+
m_datasX.resize( dataCount );
|
| 110 |
+
m_datasY.resize( dataCount );
|
| 111 |
+
if ( dataCount > 1 ){
|
| 112 |
+
m_maxValueY = -1 * std::numeric_limits<double>::max();
|
| 113 |
+
m_minValueY = std::numeric_limits<double>::max();
|
| 114 |
+
m_maxValueX = -1 * std::numeric_limits<double>::max();
|
| 115 |
+
m_minValueX = std::numeric_limits<double>::max();
|
| 116 |
+
for ( int i = 0; i < dataCount; i++ ){
|
| 117 |
+
m_datasX[i] = datas[i].first;
|
| 118 |
+
m_datasY[i] = datas[i].second;
|
| 119 |
+
if ( !isinf( datas[i].first ) && !isinf( datas[i].second )){
|
| 120 |
+
if ( m_datasY[i] > m_maxValueY ){
|
| 121 |
+
m_maxValueY = m_datasY[i];
|
| 122 |
+
}
|
| 123 |
+
if ( m_datasY[i] < m_minValueY ){
|
| 124 |
+
m_minValueY = m_datasY[i];
|
| 125 |
+
}
|
| 126 |
+
if ( m_datasX[i] > m_maxValueX ){
|
| 127 |
+
m_maxValueX = m_datasX[i];
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
if ( m_datasX[i] < m_minValueX ){
|
| 131 |
+
m_minValueX = m_datasX[i];
|
| 132 |
+
}
|
| 133 |
+
}
|
| 134 |
+
}
|
| 135 |
+
}
|
| 136 |
+
else if ( dataCount == 1 ){
|
| 137 |
+
const double INC = 0.0000001;
|
| 138 |
+
m_minValueY = m_datasY[0] - INC;
|
| 139 |
+
m_maxValueY = m_datasY[0] + INC;
|
| 140 |
+
m_minValueX = m_datasX[0] - INC;
|
| 141 |
+
m_maxValueX = m_datasX[0] + INC;
|
| 142 |
+
}
|
| 143 |
+
//No data so just use bogus bounds
|
| 144 |
+
else {
|
| 145 |
+
m_maxValueY = 1;
|
| 146 |
+
m_minValueY = 0;
|
| 147 |
+
m_maxValueX = 1;
|
| 148 |
+
m_minValueX = 0;
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
setRawSamples( m_datasX.data(), m_datasY.data(), dataCount );
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
void Plot2DProfile::setBaseLine( double /*val*/ ){
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
void Plot2DProfile::setDrawStyle( const QString& style ){
|
| 159 |
+
Plot2D::setDrawStyle( style );
|
| 160 |
+
if ( m_drawStyle == Carta::Data::ProfilePlotStyles::PLOT_STYLE_LINE ){
|
| 161 |
+
setStyle( QwtPlotCurve::Lines );
|
| 162 |
+
}
|
| 163 |
+
else if ( m_drawStyle == Carta::Data::ProfilePlotStyles::PLOT_STYLE_STEP ){
|
| 164 |
+
setStyle( QwtPlotCurve::Steps );
|
| 165 |
+
}
|
| 166 |
+
else {
|
| 167 |
+
qDebug() << "Unrecognized draw style";
|
| 168 |
+
}
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
void Plot2DProfile::setId( const QString& id ){
|
| 174 |
+
Plot2D::setId( id );
|
| 175 |
+
QwtText dataTitle = title();
|
| 176 |
+
dataTitle.setText( id );
|
| 177 |
+
setTitle( dataTitle );
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
void Plot2DProfile::setLegendLine( bool showLegendLine ){
|
| 181 |
+
QwtText text = title();
|
| 182 |
+
if ( showLegendLine ){
|
| 183 |
+
setLegendIconSize(QSize(36,8));
|
| 184 |
+
text.setColor( "black");
|
| 185 |
+
}
|
| 186 |
+
else {
|
| 187 |
+
setLegendIconSize(QSize(0,0));
|
| 188 |
+
text.setColor( m_defaultColor );
|
| 189 |
+
}
|
| 190 |
+
setTitle( text );
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
void Plot2DProfile::setLegendVisible( bool visible ){
|
| 194 |
+
setItemAttribute( QwtPlotItem::ItemAttribute::Legend, visible );
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
Plot2DProfile::~Plot2DProfile(){
|
| 199 |
+
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
}
|
| 203 |
+
}
|
| 204 |
+
|
pool/shard002/C++/0024537_Local.cpp
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*=======================================================================
|
| 2 |
+
*
|
| 3 |
+
* Copyright (C) 2013-2015 Lysine.
|
| 4 |
+
*
|
| 5 |
+
* Filename: Local.cpp
|
| 6 |
+
* Time: 2013/03/18
|
| 7 |
+
* Author: Lysine
|
| 8 |
+
*
|
| 9 |
+
* Lysine is a student majoring in Software Engineering
|
| 10 |
+
* from the School of Software, SUN YAT-SEN UNIVERSITY.
|
| 11 |
+
*
|
| 12 |
+
* This program is free software: you can redistribute it and/or modify
|
| 13 |
+
* it under the terms of the GNU General Public License as published by
|
| 14 |
+
* the Free Software Foundation, either version 3 of the License, or
|
| 15 |
+
* (at your option) any later version.
|
| 16 |
+
*
|
| 17 |
+
* This program is distributed in the hope that it will be useful,
|
| 18 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 19 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 20 |
+
* GNU General Public License for more details.
|
| 21 |
+
|
| 22 |
+
* You should have received a copy of the GNU General Public License
|
| 23 |
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 24 |
+
*
|
| 25 |
+
=========================================================================*/
|
| 26 |
+
|
| 27 |
+
#include "Local.h"
|
| 28 |
+
#include "Config.h"
|
| 29 |
+
#include "Plugin.h"
|
| 30 |
+
#include "Utils.h"
|
| 31 |
+
#include "Model/Danmaku.h"
|
| 32 |
+
#include "Model/List.h"
|
| 33 |
+
#include "Model/Shield.h"
|
| 34 |
+
#include "Player/APlayer.h"
|
| 35 |
+
#include "Render/ARender.h"
|
| 36 |
+
#include "UI/Interface.h"
|
| 37 |
+
|
| 38 |
+
QHash<QString, QObject *> Local::objects;
|
| 39 |
+
|
| 40 |
+
Local::Local(int &argc, char **argv) :
|
| 41 |
+
QApplication(argc, argv)
|
| 42 |
+
{
|
| 43 |
+
QDir::setCurrent(applicationDirPath());
|
| 44 |
+
setPalette(setStyle("Fusion")->standardPalette());
|
| 45 |
+
setAttribute(Qt::AA_UseOpenGLES);
|
| 46 |
+
thread()->setPriority(QThread::TimeCriticalPriority);
|
| 47 |
+
Config::load();
|
| 48 |
+
qsrand(QTime::currentTime().msec());
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
void Local::exit(int code)
|
| 52 |
+
{
|
| 53 |
+
delete List::instance();
|
| 54 |
+
Config::save();
|
| 55 |
+
delete APlayer::instance();
|
| 56 |
+
delete Danmaku::instance();
|
| 57 |
+
QApplication::exit(code);
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
namespace
|
| 61 |
+
{
|
| 62 |
+
void setDefaultFont()
|
| 63 |
+
{
|
| 64 |
+
QString def = Utils::defaultFont();
|
| 65 |
+
QFontInfo i(qApp->font());
|
| 66 |
+
if (!QFontDatabase().families().contains(def)){
|
| 67 |
+
def = i.family();
|
| 68 |
+
}
|
| 69 |
+
double p = i.pointSizeF();
|
| 70 |
+
QFont f;
|
| 71 |
+
f.setFamily(Config::getValue("/Interface/Font/Family", def));
|
| 72 |
+
f.setPointSizeF(Config::getValue("/Interface/Font/Size", p));
|
| 73 |
+
qApp->setFont(f);
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
void loadTranslator()
|
| 77 |
+
{
|
| 78 |
+
QString locale = Config::getValue("/Interface/Locale", QLocale::system().name());
|
| 79 |
+
QFileInfoList list;
|
| 80 |
+
list += QDir("./locale/" + locale).entryInfoList();
|
| 81 |
+
list += QFileInfo("./locale/" + locale + ".qm");
|
| 82 |
+
locale.resize(2);
|
| 83 |
+
list += QDir("./locale/" + locale).entryInfoList();
|
| 84 |
+
list += QFileInfo("./locale/" + locale + ".qm");
|
| 85 |
+
for (QFileInfo info : list){
|
| 86 |
+
if (!info.isFile()){
|
| 87 |
+
continue;
|
| 88 |
+
}
|
| 89 |
+
QTranslator *trans = new QTranslator(qApp);
|
| 90 |
+
if (trans->load(info.absoluteFilePath())){
|
| 91 |
+
qApp->installTranslator(trans);
|
| 92 |
+
}
|
| 93 |
+
else{
|
| 94 |
+
delete trans;
|
| 95 |
+
}
|
| 96 |
+
}
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
void setToolTipBase()
|
| 100 |
+
{
|
| 101 |
+
QPalette tip = qApp->palette();
|
| 102 |
+
tip.setColor(QPalette::Inactive, QPalette::ToolTipBase, Qt::white);
|
| 103 |
+
qApp->setPalette(tip);
|
| 104 |
+
QToolTip::setPalette(tip);
|
| 105 |
+
}
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
int main(int argc, char *argv[])
|
| 109 |
+
{
|
| 110 |
+
Local a(argc, argv);
|
| 111 |
+
int single;
|
| 112 |
+
if ((single = Config::getValue("/Interface/Single", 1))){
|
| 113 |
+
QLocalSocket socket;
|
| 114 |
+
socket.connectToServer("BiliLocalInstance");
|
| 115 |
+
if (socket.waitForConnected()){
|
| 116 |
+
QDataStream s(&socket);
|
| 117 |
+
s << a.arguments().mid(1);
|
| 118 |
+
socket.waitForBytesWritten();
|
| 119 |
+
return 0;
|
| 120 |
+
}
|
| 121 |
+
}
|
| 122 |
+
loadTranslator();
|
| 123 |
+
setDefaultFont();
|
| 124 |
+
setToolTipBase();
|
| 125 |
+
Interface w;
|
| 126 |
+
Plugin::loadPlugins();
|
| 127 |
+
if (!w.testAttribute(Qt::WA_WState_ExplicitShowHide)){
|
| 128 |
+
w.show();
|
| 129 |
+
}
|
| 130 |
+
w.tryLocal(a.arguments().mid(1));
|
| 131 |
+
QLocalServer *server = nullptr;
|
| 132 |
+
if (single){
|
| 133 |
+
server = new QLocalServer(lApp);
|
| 134 |
+
server->listen("BiliLocalInstance");
|
| 135 |
+
QObject::connect(server, &QLocalServer::newConnection, [&](){
|
| 136 |
+
QLocalSocket *r = server->nextPendingConnection();
|
| 137 |
+
r->waitForReadyRead();
|
| 138 |
+
QDataStream s(r);
|
| 139 |
+
QStringList args;
|
| 140 |
+
s >> args;
|
| 141 |
+
delete r;
|
| 142 |
+
w.tryLocal(args);
|
| 143 |
+
});
|
| 144 |
+
}
|
| 145 |
+
int r;
|
| 146 |
+
if ((r = a.exec()) == 12450){
|
| 147 |
+
if (server){
|
| 148 |
+
delete server;
|
| 149 |
+
}
|
| 150 |
+
QProcess::startDetached(a.applicationFilePath(), QStringList());
|
| 151 |
+
return 0;
|
| 152 |
+
}
|
| 153 |
+
else{
|
| 154 |
+
return r;
|
| 155 |
+
}
|
| 156 |
+
}
|
pool/shard002/C++/0024539_test_idt_x64.cpp
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// Bareflank Hypervisor
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2015 Assured Information Security, Inc.
|
| 5 |
+
// Author: Rian Quinn <quinnr@ainfosec.com>
|
| 6 |
+
// Author: Brendan Kerrigan <kerriganb@ainfosec.com>
|
| 7 |
+
//
|
| 8 |
+
// This library is free software; you can redistribute it and/or
|
| 9 |
+
// modify it under the terms of the GNU Lesser General Public
|
| 10 |
+
// License as published by the Free Software Foundation; either
|
| 11 |
+
// version 2.1 of the License, or (at your option) any later version.
|
| 12 |
+
//
|
| 13 |
+
// This library is distributed in the hope that it will be useful,
|
| 14 |
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 15 |
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 16 |
+
// Lesser General Public License for more details.
|
| 17 |
+
//
|
| 18 |
+
// You should have received a copy of the GNU Lesser General Public
|
| 19 |
+
// License along with this library; if not, write to the Free Software
|
| 20 |
+
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
| 21 |
+
|
| 22 |
+
#include <gsl/gsl>
|
| 23 |
+
|
| 24 |
+
#include <test.h>
|
| 25 |
+
#include <intrinsics/idt_x64.h>
|
| 26 |
+
|
| 27 |
+
std::vector<idt_x64::interrupt_descriptor_type> g_idt =
|
| 28 |
+
{
|
| 29 |
+
0xFFFFFFFFFFFFFFFF,
|
| 30 |
+
0xFFFFFFFFFFFFFFFF,
|
| 31 |
+
0xFFFFFFFFFFFFFFFF,
|
| 32 |
+
0xFFFFFFFFFFFFFFFF
|
| 33 |
+
};
|
| 34 |
+
|
| 35 |
+
idt_reg_x64_t g_idt_reg;
|
| 36 |
+
|
| 37 |
+
extern "C" void
|
| 38 |
+
__read_idt(idt_reg_x64_t *idt_reg) noexcept
|
| 39 |
+
{ *idt_reg = g_idt_reg; }
|
| 40 |
+
|
| 41 |
+
extern "C" void
|
| 42 |
+
__write_idt(idt_reg_x64_t *idt_reg) noexcept
|
| 43 |
+
{ g_idt_reg = *idt_reg; }
|
| 44 |
+
|
| 45 |
+
void
|
| 46 |
+
intrinsics_ut::test_idt_reg_set_get()
|
| 47 |
+
{
|
| 48 |
+
x64::idt::set(g_idt.data(), (4 << 3) - 1);
|
| 49 |
+
|
| 50 |
+
this->expect_true(x64::idt::get().base == g_idt.data());
|
| 51 |
+
this->expect_true(x64::idt::get().limit == (4 << 3) - 1);
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
void
|
| 55 |
+
intrinsics_ut::test_idt_reg_base_set_get()
|
| 56 |
+
{
|
| 57 |
+
x64::idt::base::set(g_idt.data());
|
| 58 |
+
this->expect_true(x64::idt::base::get() == g_idt.data());
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
void
|
| 62 |
+
intrinsics_ut::test_idt_reg_limit_set_get()
|
| 63 |
+
{
|
| 64 |
+
x64::idt::limit::set((4 << 3) - 1);
|
| 65 |
+
this->expect_true(x64::idt::limit::get() == (4 << 3) - 1);
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
void
|
| 69 |
+
intrinsics_ut::test_idt_constructor_no_size()
|
| 70 |
+
{
|
| 71 |
+
idt_x64 idt;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
void
|
| 75 |
+
intrinsics_ut::test_idt_constructor_zero_size()
|
| 76 |
+
{
|
| 77 |
+
this->expect_no_exception([&] { idt_x64{0}; });
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
void
|
| 81 |
+
intrinsics_ut::test_idt_constructor_size()
|
| 82 |
+
{
|
| 83 |
+
idt_x64 idt{4};
|
| 84 |
+
|
| 85 |
+
this->expect_true(idt.base() != 0);
|
| 86 |
+
this->expect_true(idt.limit() == (4 * sizeof(idt_x64::interrupt_descriptor_type)) - 1);
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
void
|
| 90 |
+
intrinsics_ut::test_idt_base()
|
| 91 |
+
{
|
| 92 |
+
idt_x64 idt;
|
| 93 |
+
this->expect_true(idt.base() == reinterpret_cast<idt_x64::integer_pointer>(g_idt.data()));
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
void
|
| 97 |
+
intrinsics_ut::test_idt_limit()
|
| 98 |
+
{
|
| 99 |
+
idt_x64 idt;
|
| 100 |
+
this->expect_true(idt.limit() == (4 * sizeof(idt_x64::interrupt_descriptor_type)) - 1);
|
| 101 |
+
}
|
pool/shard002/C++/0024548_raw.cpp
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "raw.hpp"
|
| 2 |
+
|
| 3 |
+
#include "../program.hpp"
|
| 4 |
+
|
| 5 |
+
#include <cstdio>
|
| 6 |
+
|
| 7 |
+
#include <glm/gtc/type_ptr.hpp>
|
| 8 |
+
#include <glm/gtc/matrix_transform.hpp>
|
| 9 |
+
|
| 10 |
+
using namespace Models;
|
| 11 |
+
|
| 12 |
+
const GLchar *const Raw::attribs[] = {
|
| 13 |
+
"position",
|
| 14 |
+
"normal",
|
| 15 |
+
};
|
| 16 |
+
|
| 17 |
+
const GLchar *const Raw::uniforms[] = {
|
| 18 |
+
"mvp",
|
| 19 |
+
"local_modelview",
|
| 20 |
+
};
|
| 21 |
+
|
| 22 |
+
const std::string Raw::filename(const std::string &name)
|
| 23 |
+
{
|
| 24 |
+
return "/models/" + name;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
Raw::Raw(const Adapter &adapter, const std::string &name)
|
| 28 |
+
{
|
| 29 |
+
exe = adapter.load<Program>("normal")->build(
|
| 30 |
+
__attrib_count, attribs,
|
| 31 |
+
__uniform_count, uniforms
|
| 32 |
+
);
|
| 33 |
+
|
| 34 |
+
FILE *file = fopen(adapter.filename<Raw>(name).c_str(), "r");
|
| 35 |
+
|
| 36 |
+
while (!feof(file))
|
| 37 |
+
{
|
| 38 |
+
std::array<glm::vec3, 3> v;
|
| 39 |
+
|
| 40 |
+
for (int i = 0; i < 3; ++i)
|
| 41 |
+
fscanf(file, "%f %f %f", &v[i].x, &v[i].y, &v[i].z);
|
| 42 |
+
|
| 43 |
+
add3_with_auto_normals(v, glm::vec3(0.0f, -10.0f, 0.0f));
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
fclose(file);
|
| 47 |
+
|
| 48 |
+
positions_id = create_array_buffer(GL_ARRAY_BUFFER, 3 * positions.size() * sizeof(GLfloat), positions.data());
|
| 49 |
+
normals_id = create_array_buffer(GL_ARRAY_BUFFER, 3 * normals.size() * sizeof(GLfloat), normals.data());
|
| 50 |
+
id = create_array_buffer(GL_ELEMENT_ARRAY_BUFFER, elements.size() * sizeof(GLushort), elements.data());
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
void Raw::draw(__attribute__((unused)) const Scene &scene, const glm::mat4 &mvp, const glm::mat4 &transformation) const
|
| 54 |
+
{
|
| 55 |
+
exe->use();
|
| 56 |
+
|
| 57 |
+
const glm::mat4 transform = mvp * transformation;
|
| 58 |
+
glUniformMatrix4fv(exe->uniform(Uniform::mvp), 1, GL_FALSE, glm::value_ptr(transform));
|
| 59 |
+
|
| 60 |
+
const glm::mat3 local_modelview = glm::transpose(glm::inverse(glm::mat3(transformation)));
|
| 61 |
+
glUniformMatrix3fv(exe->uniform(Uniform::local_modelview), 1, GL_FALSE, glm::value_ptr(local_modelview));
|
| 62 |
+
|
| 63 |
+
glEnableVertexAttribArray(position);
|
| 64 |
+
glBindBuffer(GL_ARRAY_BUFFER, positions_id);
|
| 65 |
+
glVertexAttribPointer(position, 3, GL_FLOAT, GL_FALSE, 0, reinterpret_cast<const GLvoid*>(0));
|
| 66 |
+
|
| 67 |
+
glEnableVertexAttribArray(normal);
|
| 68 |
+
glBindBuffer(GL_ARRAY_BUFFER, normals_id);
|
| 69 |
+
glVertexAttribPointer(normal, 3, GL_FLOAT, GL_FALSE, 0, reinterpret_cast<const GLvoid*>(0));
|
| 70 |
+
|
| 71 |
+
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id);
|
| 72 |
+
glDrawElements(GL_TRIANGLES, elements.size(), GL_UNSIGNED_SHORT, 0);
|
| 73 |
+
}
|
pool/shard002/C++/0024550_PrimitiveParsing.cpp
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===--- PrimitiveParsing.cpp - Primitive parsing routines ----------------===//
|
| 2 |
+
//
|
| 3 |
+
// This source file is part of the Swift.org open source project
|
| 4 |
+
//
|
| 5 |
+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
|
| 6 |
+
// Licensed under Apache License v2.0 with Runtime Library Exception
|
| 7 |
+
//
|
| 8 |
+
// See https://swift.org/LICENSE.txt for license information
|
| 9 |
+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
| 10 |
+
//
|
| 11 |
+
//===----------------------------------------------------------------------===//
|
| 12 |
+
///
|
| 13 |
+
/// \file
|
| 14 |
+
/// Primitive parsing routines useful in various places in the compiler.
|
| 15 |
+
///
|
| 16 |
+
//===----------------------------------------------------------------------===//
|
| 17 |
+
|
| 18 |
+
#include "swift/Basic/PrimitiveParsing.h"
|
| 19 |
+
#include "llvm/ADT/SmallVector.h"
|
| 20 |
+
|
| 21 |
+
using namespace llvm;
|
| 22 |
+
|
| 23 |
+
unsigned swift::measureNewline(const char *BufferPtr, const char *BufferEnd) {
|
| 24 |
+
if (BufferPtr == BufferEnd)
|
| 25 |
+
return 0;
|
| 26 |
+
|
| 27 |
+
if (*BufferPtr == '\n')
|
| 28 |
+
return 1;
|
| 29 |
+
|
| 30 |
+
assert(*BufferPtr == '\r');
|
| 31 |
+
unsigned Bytes = 1;
|
| 32 |
+
if (BufferPtr != BufferEnd && *BufferPtr == '\n')
|
| 33 |
+
++Bytes;
|
| 34 |
+
return Bytes;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
void
|
| 38 |
+
swift::trimLeadingWhitespaceFromLines(StringRef RawText,
|
| 39 |
+
unsigned WhitespaceToTrim,
|
| 40 |
+
SmallVectorImpl<StringRef> &OutLines) {
|
| 41 |
+
SmallVector<StringRef, 8> Lines;
|
| 42 |
+
|
| 43 |
+
bool IsFirstLine = true;
|
| 44 |
+
|
| 45 |
+
while (!RawText.empty()) {
|
| 46 |
+
size_t Pos = RawText.find_first_of("\n\r");
|
| 47 |
+
if (Pos == StringRef::npos)
|
| 48 |
+
Pos = RawText.size();
|
| 49 |
+
|
| 50 |
+
StringRef Line = RawText.substr(0, Pos);
|
| 51 |
+
Lines.push_back(Line);
|
| 52 |
+
if (!IsFirstLine) {
|
| 53 |
+
size_t NonWhitespacePos = RawText.find_first_not_of(' ');
|
| 54 |
+
if (NonWhitespacePos != StringRef::npos)
|
| 55 |
+
WhitespaceToTrim =
|
| 56 |
+
std::min(WhitespaceToTrim,
|
| 57 |
+
static_cast<unsigned>(NonWhitespacePos));
|
| 58 |
+
}
|
| 59 |
+
IsFirstLine = false;
|
| 60 |
+
|
| 61 |
+
RawText = RawText.drop_front(Pos);
|
| 62 |
+
unsigned NewlineBytes = measureNewline(RawText);
|
| 63 |
+
RawText = RawText.drop_front(NewlineBytes);
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
IsFirstLine = true;
|
| 67 |
+
for (auto &Line : Lines) {
|
| 68 |
+
if (!IsFirstLine) {
|
| 69 |
+
Line = Line.drop_front(WhitespaceToTrim);
|
| 70 |
+
}
|
| 71 |
+
IsFirstLine = false;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
OutLines.append(Lines.begin(), Lines.end());
|
| 75 |
+
}
|