// Find <object> with <name> in <this> context // (String version) int ACE_Registry::Naming_Context::resolve (const ACE_TString &name, Object &object) { // Get object state u_long type; void *data = object.data (); u_long size = object.size (); long result = ACE_TEXT_RegQueryValueEx (this->key_, name.c_str (), 0, &type, (BYTE *)data, &size); if (result == ERROR_SUCCESS) { // Reset object state // No need to set object.data() object.type (type); object.size (size); } ACE_REGISTRY_CALL_RETURN (result); }
void compiler::compile(Object & obj) { string file=obj.filePath; string base=obj.baseName; string root=obj.rootDir; bool isCpp=file.substr(file.find_last_of('.'))==".cpp"; computeDependencies(obj); obj.addInclude(cfg().rootDir+"hardware/arduino/cores/arduino"); // change this to work with tinyX5; obj.addInclude(ofToDataPath(cfg().robotRoot+"/include")); cmd.newCommand(); if(isCpp) cmd.addArgument(cfg().toolDir+"avr-g++"); else cmd.addArgument(cfg().toolDir+"avr-gcc"); cmd.addArgument("-c -g -Os -w"); if(isCpp) cmd.addArgument("-fno-exceptions"); cmd.addArgument("-ffunction-sections -fdata-sections"); cmd.addArgument("-DF_CPU="+cfg().freq+"L"); cmd.addArgument("-DARDUINO=22"); for(unsigned int i=0; i<obj.size(); i++){ cmd.addArgument("-I"+obj[i]); } cmd.addArgument("-mmcu="+cfg().mcu); if(isCpp) cmd.addArgument(root+base+".cpp"); else cmd.addArgument(root+base+".c"); cmd.addArgument("-o " + appletDir+base+ ".o"); percent=0; cmd.execute(); /* path/to/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -DF_CPU=processor_speed -I(includes_for_cpp) -mmcu=processor_name path/to/target.cpp -o target.o */ }
OutputIterator operator()(const Object& obj, OutputIterator dest, int level) { using json::generator_internal::encode_string; OutputIterator result = std::copy(TokenTraits::object_open_token.cbegin(), TokenTraits::object_open_token.cend(), dest); ++level; std::size_t count = obj.size(); for (auto iter : obj) { if ((flags()&pretty_print) != 0) { result = std::fill_n(result, 1, TokenTraits::newline_token[0]); result = std::fill_n(result, level, TokenTraits::tab_token[0]); } std::copy(TokenTraits::quote_token.cbegin(), TokenTraits::quote_token.cend(), dest); auto first = iter.first.begin(); auto last = iter.first.end(); const unsigned int options = (flags()&escape_solidus) ? generator_internal::string_encoder_base::EscapeSolidus : 0; #if !defined (NDEBUG) int cvt_result = #endif encode_string(first, last, key_encoding_type(), result, out_encoding_type(), options); assert(cvt_result == 0); if ((flags()&pretty_print) != 0) { result = std::copy(TokenTraits::quote_token.cbegin(), TokenTraits::quote_token.cend(), result); result = std::copy(TokenTraits::space_token.cbegin(), TokenTraits::space_token.cend(), result); result = std::copy(TokenTraits::colon_token.cbegin(), TokenTraits::colon_token.cend(), result); result = std::copy(TokenTraits::space_token.cbegin(), TokenTraits::space_token.cend(), result); } else { result = std::copy(TokenTraits::quote_token.cbegin(), TokenTraits::quote_token.cend(), result); result = std::copy(TokenTraits::colon_token.cbegin(), TokenTraits::colon_token.cend(), result); } result = _write_value(iter.second, result, *this, level); if (--count > 0) { result = std::copy(TokenTraits::comma_token.cbegin(), TokenTraits::comma_token.cend(), result); } } --level; if (obj.size() and (flags()&pretty_print) != 0) { result = std::fill_n(result, 1, TokenTraits::newline_token[0]); result = std::fill_n(result, level, TokenTraits::tab_token[0]); } return std::copy(TokenTraits::object_close_token.cbegin(), TokenTraits::object_close_token.cend(), result); }
Object *ContainerParser::readVariable(const ObjectType &type, std::streamoff offset) { Object* child = getVariable(type, offset); if (child != nullptr && child->size() == -1LL) { child->parse(); child->setSize(child->_contentSize); } return child; }
/** Import List of Private Keys amd if they import properly or fail with their own code int he output sequenc **/ Value importkeys(const Array& params, bool fHelp) { if (fHelp || params.size() < 1) throw runtime_error( "importkeys\n" "The account and keypair need to \n" "You need to list the imported keys in a JSON array of {[account],[privatekey]}\n"); /** Make sure the Wallet is Unlocked fully before proceeding. **/ if (pwalletMain->IsLocked()) throw JSONRPCError(-13, "Error: Please enter the wallet passphrase with walletpassphrase first."); if (Wallet::fWalletUnlockMintOnly) throw JSONRPCError(-102, "Wallet is unlocked for minting only."); /** Establish the JSON Object from the Parameters. **/ Object entry = params[0].get_obj(); /** Establish a return value JSON object for Error Reporting. **/ Object response; /** Import the Keys one by One. **/ for(int nIndex = 0; nIndex < entry.size(); nIndex++) { Wallet::NexusSecret vchSecret; if(!vchSecret.SetString(entry[nIndex].value_.get_str())){ response.push_back(Pair(entry[nIndex].name_, "Code -5 Invalid Key")); continue; } Wallet::CKey key; bool fCompressed; Wallet::CSecret secret = vchSecret.GetSecret(fCompressed); key.SetSecret(secret, fCompressed); Wallet::NexusAddress vchAddress = Wallet::NexusAddress(key.GetPubKey()); { LOCK2(Core::cs_main, pwalletMain->cs_wallet); pwalletMain->MarkDirty(); pwalletMain->SetAddressBookName(vchAddress, entry[nIndex].name_); if (!pwalletMain->AddKey(key)) { response.push_back(Pair(entry[nIndex].name_, "Code -4 Error Adding to Wallet")); continue; } } response.push_back(Pair(entry[nIndex].name_, "Successfully Imported")); } MainFrameRepaint(); return response; }
void RunMnemonicTests() { // -- fail tests std::vector<uint8_t> vEntropy; std::string sWords = "legals winner thank year wave sausage worth useful legal winner thank yellow"; std::string sError; BOOST_CHECK_MESSAGE(3 == MnemonicDecode(-1, sWords, vEntropy, sError), "MnemonicDecode: " << sError); sWords = "winner legal thank year wave sausage worth useful legal winner thank yellow"; BOOST_CHECK_MESSAGE(5 == MnemonicDecode(-1, sWords, vEntropy, sError), "MnemonicDecode: " << sError); Object vectors = read_json_object("bip39_vectors.json"); int nLanguage; for (Object::size_type i = 0; i < vectors.size(); ++i) { const Pair &pair = vectors[i]; const std::string &name = pair.name_; BOOST_MESSAGE("Language: " << name); if (name == "english") nLanguage = WLL_ENGLISH; else if (name == "japanese") nLanguage = WLL_JAPANESE; else nLanguage = -1; BOOST_CHECK(nLanguage != -1); if (pair.value_.type() != array_type) { BOOST_MESSAGE("Error, not array."); continue; }; const Array &array = pair.value_.get_array(); BOOST_FOREACH(const Value &v, array) { if (v.type() != array_type) { BOOST_MESSAGE("Error, not array."); continue; }; const Array &va = v.get_array(); if (va.size() < 3 || va.size() > 5) continue; TestMnemonic(nLanguage, va); }; }; };
/** Converts ar to a std::pair. atomToNative<T1>() and atomToNative<T2>() are used for the conversions. */ inline ReturnType operator()( Object const & ar ) const { static const StringType str1("k"); static const StringType str2("v"); if( 2 != ar.size() ) { throw Error( "pair<>.size != 2" ); } return std::make_pair( atomToNative<T1>( ar.get(str1) ), atomToNative<T1>( ar.get(str2) ) ); }
// Insert or update <object> with <name> into <this> context // (String version) int ACE_Registry::Naming_Context::bind (const ACE_TString &name, const Object &object) { long result = ACE_TEXT_RegSetValueEx (this->key_, name.c_str (), 0, object.type (), (const BYTE *) object.data (), object.size ()); ACE_REGISTRY_CALL_RETURN (result); }
typename boost::enable_if_c< Level != 0, void >::type assign_fill_recurse( Object &_result, Object const &_source, typename Object::const_reference _value, typename Object::dim _pos, bool const _is_contained ) { size_type const index( Level - 1u ); for( typename Object::dim::value_type i = 0; i < _result.size()[index]; ++i ) { _pos[index] = i; detail::assign_fill_recurse< Level - 1u >( _result, _source, _value, _pos, _is_contained && i < _source.size()[index] ); } }
typename std::enable_if< Level != 0, void >::type print_recurse( Stream &_stream, Object const &_object, typename Object::pos _pos ) { size_type const index( Level - 1u ); _stream << _stream.widen('('); typename Object::dim::value_type sz( _object.size()[index] ); for( typename Object::dim::size_type i = 0; i < sz; ++i ) { _pos[index] = i; fcppt::container::grid::detail::print_recurse< index >( _stream, _object, _pos ); if( i < sz - 1u ) _stream << _stream.widen(','); } _stream << _stream.widen(')'); }
vector< Game > nhl::read_games(int &startIndex, int &refreshInterval) { string s = getNHLScoreJSon(); s.erase(0,15); // starting at position 0, delete 1 character s.erase(s.length()-2); Value value; read( s, value ); vector< Game > games; Object obj = value.get_obj(); for( Object::size_type i = 0; i != obj.size(); ++i ) { const Pair& pair = obj[i]; const string& name = pair.name_; const Value& value = pair.value_; if( name == "games" ) { const Array& games_array = value.get_array(); for( unsigned int i = 0; i < games_array.size(); ++i ) { Game game = nhl::read_game(games_array[i].get_obj()); games.push_back(game); } } else if ( name == "startIndex" ) { startIndex = value.get_int(); } else if ( name == "refreshInterval" ) { refreshInterval = value.get_int(); } } return games; }
std::string Json::ToString( ){ std::ostringstream ostr; switch(_kind){ case kNull: { ostr << "Null" ; break; } case kNumber: { ostr << GetDouble() ; break; } case kString: { ostr << "\"" << GetString() << "\""; break; } case kTrue: case kFalse: { ostr << boolalpha << GetBool() ; break; } case kObject: { ostr << "{"; Object* obj = (Object*)_data; Object::const_iterator iter = obj->begin() ; size_t size = obj->size(), ind = 0; for(; iter != obj->end(); iter++){ ostr << "\"" << iter->first << "\"" << ":" << iter->second->ToString(); if(++ind < size) ostr << ","; } ostr << "}"; break; } case kArray: { ostr << "["; Array& arr = *(Array*)_data; size_t size = arr.size(), ind = -1; for(; ++ind < size;){ ostr << arr[ind]->ToString(); if(ind+1 < size) ostr << ","; } ostr << "]"; break; } default: break; } return ostr.str(); }
hys32 FFI_FUNC(hashCode) (Value selfVal) { if (selfVal.getType()->isPrimitive()) return (hys32) selfVal.data; Object* obj = selfVal.objPtr; size_t size = obj->size(); int size_l = size & 3; // サイズ下位2bit int size_h = size >> 2; hyu32* p = (hyu32*) obj->field(0); hyu32 h = *p; while (--size_h >= 0) { h = h * 0x1f1f1f1f + *++p; } hyu8* q = (hyu8*) p; while (--size_l >= 0) { h = h * 31 + *q++; } return (hys32)h; }
std::string Json::InnerIndentString(const int & indent, const int &level, bool chgLine){ std::string ret; if(chgLine) ret += "\n" + IndentSpace(indent, level); switch(_kind){ case kString: case kNumber: case kTrue: case kFalse: case kNull: { ret += ToString(); break; } case kArray: { ret += "["; Array& arr = *(Array*)_data; size_t size = arr.size(), ind = -1; for(; ++ind < size;){ ret += arr[ind]->InnerIndentString(indent, level+1, true); if(ind+1 < size) ret += ","; } ret += "\n" + IndentSpace(indent, level) + "]"; break; } case kObject: { ret += "{"; Object* obj = (Object*)_data; Object::const_iterator iter = obj->begin() ; size_t size = obj->size(), ind = 0; for(; iter != obj->end(); iter++){ ret += "\n" + IndentSpace(indent, level+1) + std::string("\"") + iter->first + std::string("\"") + ":"; ret += iter->second->InnerIndentString(indent, level+1, false); if(++ind < size) ret += ","; } ret += "\n" + IndentSpace(indent, level) + "}"; break; } default: break; } return ret; }
Address read_address( const Object& obj ) { Address addr; for( Object::size_type i = 0; i != obj.size(); ++i ) { const Pair& pair = obj[i]; const string& name = pair.name_; const Value& value = pair.value_; if( name == "house_number" ) { addr.house_number_ = value.get_int(); } else if( name == "road" ) { addr.road_ = value.get_str(); } else if( name == "town" ) { addr.town_ = value.get_str(); } else if( name == "county" ) { addr.county_ = value.get_str(); } else if( name == "country" ) { addr.country_ = value.get_str(); } else { assert( false ); } } return addr; }
gcm_response_entry::gcm_response_entry(const Object& obj) : status_(push::error::successful) { for(Object::size_type i = 0; i != obj.size(); ++i) { const Pair& pair = obj[i]; const std::string& name = pair.name_; const Value& value = pair.value_; if(name == "message_id") { message_id = value.get_str(); } else if(name == "error") { status_ = status_from_error(value.get_str()); } else if(name == "registration_id") { registration_id = value.get_str(); } } }
Game nhl::read_game( const Object& obj ) { Game game; for( Object::size_type i = 0; i != obj.size(); ++i ) { const Pair& pair = obj[i]; const string& name = pair.name_; const Value& value = pair.value_; if( name == "ts" ) { game.ts = value.get_str(); } else if( name == "tsc" ){ game.tsc = value.get_str(); } else if( name == "atn" ){ game.atn = value.get_str(); stringutil::replace(game.atn, "é", "e"); game.atn = team_short_name(game.atn); } else if( name == "ats" ){ game.ats = value.get_str(); } else if( name == "htn" ){ game.htn = value.get_str(); stringutil::replace(game.htn, "é", "e"); game.htn = team_short_name(game.htn); } else if( name == "hts" ) { game.hts = value.get_str(); } else if( name == "bs" ) { game.bs = value.get_str(); } } return game; }
int generateRSS(string uri, string *output) { #ifndef HAVE_BOOST_REGEX return RSS_ERROR_BOOST_REGEX; #else map<string, string> parameterMap = parseQuery(uri); int max = 20; //default value string account = parameterMap["account"]; string strMax = parameterMap["max"]; if(strMax!="") { try { max = boost::lexical_cast<int>(strMax); } catch(boost::bad_lexical_cast e) { return RSS_ERROR_NOT_A_NUMBER; } } const Array emptyArray; Array accountsArray = listwalletusers(emptyArray,false).get_array(); // if no account was specified, choose the first one if(account=="") { if(accountsArray.size()>0) { account = accountsArray[0].get_str(); } else return RSS_ERROR_NO_ACCOUNT; } // if an account name was specified, check that it exists else { bool accountExists = false; for(int i=0;i<accountsArray.size();i++) { if(accountsArray[i]==account) accountExists=true; } if(!accountExists) return RSS_ERROR_BAD_ACCOUNT; } // get an array of followed usernames and transform it to required format Array params1; params1.push_back(account); Array followingArray = getfollowing(params1,false).get_array(); Array postSources; for(int i=0;i<followingArray.size();i++) { Object item; item.push_back(Pair("username",followingArray[i])); postSources.push_back(item); } Array params2; params2.push_back(max); params2.push_back(postSources); Array posts = getposts(params2,false).get_array(); vector<Object> outputVector; if(GetBoolArg("-rss_dm",false)) //synchronizing direct messages is disabled by default { Array params3; params3.push_back(account); params3.push_back(max); params3.push_back(postSources); Object messages = getdirectmsgs(params3,false).get_obj(); for(int j=0;j<messages.size();j++) { Array userArray = messages[j].value_.get_array(); for(int i=0;i<userArray.size();i++) { try { if(find_value(userArray[i].get_obj(),"fromMe").get_bool()) //only report received messages continue; string postTitle, postAuthor, postMsg; postAuthor=messages[j].name_; postTitle="Direct Message from "+postAuthor; postMsg=find_value(userArray[i].get_obj(),"text").get_str(); Value postTime = find_value(userArray[i].get_obj(),"time"); encodeXmlCharacters(postMsg); Object item; item.push_back(Pair("time",postTime)); item.push_back(Pair("title",postTitle)); item.push_back(Pair("author",postAuthor)); item.push_back(Pair("msg",postMsg)); outputVector.push_back(item); } catch(exception ex) { fprintf(stderr, "Warning: RSS couldn't parse a direct message, skipping.\n"); continue; } } } } for(int i=0;i<posts.size();i++) { try { Object userpost = find_value(posts[i].get_obj(),"userpost").get_obj(); string postTitle, postAuthor, postMsg; Value rt = find_value(userpost,"rt"); if(rt.is_null()) // it's a normal post { postAuthor = find_value(userpost,"n").get_str(); Value reply = find_value(userpost,"reply"); if(!reply.is_null()&&find_value(reply.get_obj(),"n").get_str()==account) { postTitle = "Reply from "+postAuthor; } else postTitle = postAuthor; postMsg = find_value(userpost,"msg").get_str(); } else // it's a retwist { postAuthor = find_value(rt.get_obj(),"n").get_str(); postTitle = postAuthor + " - via " + find_value(userpost,"n").get_str(); postMsg = find_value(rt.get_obj(),"msg").get_str(); } Value postTime = find_value(userpost,"time"); encodeXmlCharacters(postMsg); Object item; item.push_back(Pair("time",postTime)); item.push_back(Pair("title",postTitle)); item.push_back(Pair("author",postAuthor)); item.push_back(Pair("msg",postMsg)); outputVector.push_back(item); } catch(exception ex) { fprintf(stderr, "Warning: RSS couldn't parse a public post, skipping.\n"); continue; } } sort(outputVector.begin(),outputVector.end(),sortByTime); ostringstream ret; ret << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" << "<rss version=\"2.0\">\n" << "<channel>\n" << " <title>Twister Postboard - " << account << "</title>\n" << " <description>New posts from Twister</description>\n"; int outputSize = (outputVector.size()>max)?max:outputVector.size(); for(int i=0;i<outputSize;i++) { Object item = outputVector[i]; time_t postTime(find_value(item,"time").get_int64()); char timeString[100]; strftime(timeString, sizeof(timeString), "%a, %d %b %Y %H:%M:%S %z", gmtime(&postTime)); ret << " <item>\n" << " <title>" << find_value(item,"title").get_str() << "</title>\n" << " <author>" << find_value(item,"author").get_str() << "</author>\n" << " <description>" << find_value(item,"msg").get_str() << "</description>\n" << " <pubDate>" << timeString << "</pubDate>\n" << " </item>\n"; } ret << "</channel>\n" << "</rss>\n"; *output = ret.str(); return RSS_OK; #endif }
////////////////////////////////////////////////////////////// // // This function draws the string // ////////////////////////////////////////////////////////////// void TextString::drawString() { // We need to calculate the coordinates for each character based on // the char width/height for (int charPos = 0, xCounter = 0, yPos = 0; charPos < (int)fontStr.size(); charPos++, xCounter++) { // Get each character and convert it to ASCII int chr = fontStr[charPos]; if (fontStr[charPos] == '\n') { yPos += charHeight; xCounter = -1; continue; } // Start ascii is 32, end is 126 so how many into the bitmap is this? int pos = chr - 32; // Now we find out what row it is on from this // How many chars per row int charPerRow = abs((fontFace->mapWidth / charWidth)); int row = abs(pos / charPerRow) + 1; // How many in is it? int col = pos - ((row - 1) * charPerRow); // Texture coordinates based on 1.0 = max coord (100%) // x = 1 / width * wanted width, y = 1 / height * wanted height Vector2 _pos = Vector2 ( (1.0 / fontFace->mapWidth) * (col * charWidth), (1.0 / fontFace->mapHeight) * ((row - 1) * charHeight) ); Vector2 _pos2 = Vector2 ( (1.0 / fontFace->mapWidth) * ((col * charWidth) + charWidth), (1.0 / fontFace->mapHeight) * (((row - 1) * charHeight) + charHeight) ); // Set the texture coordinates Rect texCoords = Rect(_pos.x, _pos.y, _pos2.x, _pos2.y); // Create the object of the character Object *character = new Object(); character->setTexCoord(texCoords); character->loadTexture(fontFace->getTexture()); character->size(charWidth * scaleMag, charHeight * scaleMag); character->position(fontPosition.x + (xCounter * characterSpacing), fontPosition.y + yPos); character->rotate(fontRotation); character->scale(fontScale); character->setTransparency(true); character->color(fontColour); character->drawObject(); delete character; } }
/** * Example of a test. To be completed. * */ bool testObject() { unsigned int nbok = 0; unsigned int nb = 0; typedef SpaceND< 2 > Z2; typedef Z2::Point Point; typedef Point::Coordinate Coordinate; typedef HyperRectDomain< Z2 > DomainType; Point p1( -449, -449 ); Point p2( 449, 449 ); DomainType domain( p1, p2 ); // typedef DomainMetricAdjacency< DomainType, 1 > Adj4; // typedef DomainMetricAdjacency< DomainType, 2 > Adj8; typedef MetricAdjacency< Z2, 1 > MetricAdj4; typedef MetricAdjacency< Z2, 2 > MetricAdj8; typedef DomainAdjacency< DomainType, MetricAdj4 > Adj4; typedef DomainAdjacency< DomainType, MetricAdj8 > Adj8; typedef DigitalTopology< Adj4, Adj8 > DT48; typedef DigitalSetSelector < DomainType, MEDIUM_DS + HIGH_BEL_DS >::Type MediumSet; // typedef DigitalSetSelector< DomainType, SMALL_DS >::Type // MediumSet; typedef Object<DT48, MediumSet> ObjectType; typedef ObjectType::SmallSet SmallSet; typedef Object<DT48, SmallSet> SmallObjectType; typedef ObjectType::Size Size; // Adj4 adj4( domain ); // Adj8 adj8( domain ); MetricAdj4 madj4; MetricAdj8 madj8; Adj4 adj4( domain, madj4 ); Adj8 adj8( domain, madj8 ); DT48 dt48( adj4, adj8, JORDAN_DT ); Coordinate r = 449; double radius = (double) (r + 1); Point c( 0, 0 ); Point l( r, 0 ); MediumSet disk( domain ); ostringstream sstr; sstr << "Creating disk( r < " << radius << " ) ..."; trace.beginBlock ( sstr.str() ); for ( DomainType::ConstIterator it = domain.begin(); it != domain.end(); ++it ) { if ( (*it - c ).norm() < radius ) // 450.0 // insertNew is very important for vector container. disk.insertNew( *it ); } trace.endBlock(); trace.beginBlock ( "Testing Object instanciation and smart copy ..." ); ObjectType disk_object( dt48, disk ); nbok += disk_object.size() == 636101 ? 1 : 0; nb++; trace.info() << "(" << nbok << "/" << nb << ") " << "Disk (r=450.0) " << disk_object << std::endl; trace.info() << " size=" << disk_object.size() << std::endl; ObjectType disk_object2( disk_object ); nbok += disk_object2.size() == 636101 ? 1 : 0; nb++; trace.info() << "(" << nbok << "/" << nb << ") " << "Disk2 (r=450.0) " << disk_object2 << std::endl; trace.info() << " size=" << disk_object2.size() << std::endl; trace.endBlock(); trace.beginBlock ( "Testing copy on write system ..." ); trace.info() << "Removing center point in Disk." << std::endl; disk_object.pointSet().erase( c ); disk_object2.pointSet().insert( c ); nbok += disk_object.size() == 636100 ? 1 : 0; nb++; trace.info() << "(" << nbok << "/" << nb << ") " << "Disk - c (r=450.0) " << disk_object << std::endl; trace.info() << " size=" << disk_object.size() << std::endl; nbok += disk_object2.size() == 636101 ? 1 : 0; nb++; trace.info() << "(" << nbok << "/" << nb << ") " << "Disk2 + c (r=450.0) " << disk_object2 << std::endl; trace.info() << " size=" << disk_object2.size() << std::endl; trace.endBlock(); trace.beginBlock ( "Testing neighborhoods ..." ); Object<DT48, SmallSet> neigh = disk_object.neighborhood( c ); nbok += neigh.size() == 4 ? 1 : 0; nb++; trace.info() << "(" << nbok << "/" << nb << ") " << "N_4(Disk, c).size() = " << neigh.size() << " == 4" << std::endl; neigh = disk_object.properNeighborhood( l ); nbok += neigh.size() == 3 ? 1 : 0; nb++; trace.info() << "(" << nbok << "/" << nb << ") " << "N*_4(Disk, " << l << ").size() = " << neigh.size() << " == 3" << std::endl; Size size = disk_object.properNeighborhoodSize( l ); nbok += size == 3 ? 1 : 0; nb++; trace.info() << "(" << nbok << "/" << nb << ") " << "#N*_4(Disk, " << l << ") = " << size << " == 3" << std::endl; neigh = disk_object2.neighborhood( c ); nbok += neigh.size() == 5 ? 1 : 0; nb++; trace.info() << "(" << nbok << "/" << nb << ") " << "N_4(Disk2, c).size() = " << neigh.size() << " == 5" << std::endl; trace.endBlock(); trace.beginBlock ( "Testing set converters ..." ); DigitalSetConverter<SmallSet>::assign ( neigh.pointSet(), disk_object.pointSet() ); nbok += neigh.size() == 636100 ? 1 : 0; nb++; trace.info() << "(" << nbok << "/" << nb << ") " << "neigh = disk_object, size() = " << neigh.size() << " == 636100" << std::endl; SmallObjectType neigh2 = disk_object2.neighborhood( c ); DigitalSetConverter<SmallSet>::assign ( neigh.pointSet(), neigh2.pointSet() ); nbok += neigh.size() == 5 ? 1 : 0; nb++; trace.info() << "(" << nbok << "/" << nb << ") " << "neigh = N_4(Disk2, c), size() = " << neigh.size() << " == 5" << std::endl; trace.endBlock(); trace.beginBlock ( "Testing border extraction ..." ); ObjectType bdisk = disk_object.border(); nbok += bdisk.size() == 3372 ? 1 : 0; nb++; trace.info() << "(" << nbok << "/" << nb << ") " << "Border(Disk, c), size() = " << bdisk.size() << " == 3372" << std::endl; ObjectType bdisk2 = disk_object2.border(); nbok += bdisk2.size() == 3364 ? 1 : 0; nb++; trace.info() << "(" << nbok << "/" << nb << ") " << "Border(Disk2, c), size() = " << bdisk2.size() << " == 3364" << std::endl; trace.endBlock(); trace.beginBlock ( "Testing expansion by layers on the boundary ..." ); typedef Expander< ObjectType > ObjectExpander; ObjectExpander expander( bdisk, *(bdisk.pointSet().begin()) ); while ( ! expander.finished() ) { nbok += expander.layer().size() <= 2 ? 1 : 0; nb++; trace.info() << "(" << nbok << "/" << nb << ") " << "expander.layer.size() <= 2 " << expander << std::endl; expander.nextLayer(); } trace.endBlock(); trace.beginBlock ( "Testing expansion by layers on the disk from center..." ); ObjectExpander expander2( disk_object2, c ); while ( ! expander2.finished() ) { trace.info() << expander2 << std::endl; expander2.nextLayer(); } nbok += expander2.distance() <= sqrt(2.0) * radius ? 1 : 0; nb++; trace.info() << "(" << nbok << "/" << nb << ") " << "expander.distance() = " << expander2.distance() << " <= " << sqrt(2.0)*radius << std::endl; trace.endBlock(); return nbok == nb; }
void AggregatePlanNode::loadFromJSONObject(Object &obj, const catalog::Database *catalog_db) { Value outputColumnsValue = find_value(obj, "OUTPUT_COLUMNS"); if (outputColumnsValue == Value::null) { throw SerializableEEException(VOLT_EE_EXCEPTION_TYPE_EEEXCEPTION, "AggregatePlanNode::loadFromJSONObject:" " Can't find OUTPUT_COLUMNS value"); } Array outputColumnsArray = outputColumnsValue.get_array(); VOLT_DEBUG("Initializing output columns for %s", this->debug().c_str()); for (int ii = 0; ii < outputColumnsArray.size(); ii++) { Value outputColumnValue = outputColumnsArray[ii]; PlanColumn outputColumn = PlanColumn(outputColumnValue.get_obj()); m_outputColumnGuids.push_back(outputColumn.getGuid()); m_outputColumnNames.push_back(outputColumn.getName()); m_outputColumnTypes.push_back(outputColumn.getType()); m_outputColumnSizes.push_back(outputColumn.getSize()); VOLT_TRACE("[%02d] %s", ii, outputColumn.debug().c_str()); } Value aggregateColumnsValue = find_value(obj, "AGGREGATE_COLUMNS"); if (aggregateColumnsValue == Value::null) { throw SerializableEEException(VOLT_EE_EXCEPTION_TYPE_EEEXCEPTION, "AggregatePlanNode::loadFromJSONObject:" " Can't find AGGREGATE_COLUMNS value"); } VOLT_DEBUG("Initializing aggregate column information for %s", this->debug().c_str()); Array aggregateColumnsArray = aggregateColumnsValue.get_array(); for (int ii = 0; ii < aggregateColumnsArray.size(); ii++) { Value aggregateColumnValue = aggregateColumnsArray[ii]; Object aggregateColumn = aggregateColumnValue.get_obj(); bool containsType = false; bool containsName = false; bool containsGuid = false; bool containsOutputColumn = false; _UNUSED (containsType); _UNUSED (containsName); _UNUSED (containsGuid); _UNUSED (containsOutputColumn); for (int zz = 0; zz < aggregateColumn.size(); zz++) { if (aggregateColumn[zz].name_ == "AGGREGATE_TYPE") { containsType = true; string aggregateColumnTypeString = aggregateColumn[zz].value_.get_str(); m_aggregates. push_back(stringToExpression(aggregateColumnTypeString)); VOLT_TRACE("Added new AGGREGATE_TYPE record"); } else if (aggregateColumn[zz].name_ == "AGGREGATE_NAME") { containsName = true; m_aggregateColumnNames. push_back(aggregateColumn[zz].value_.get_str()); VOLT_TRACE("Added new AGGREGATE_NAME record"); } else if (aggregateColumn[zz].name_ == "AGGREGATE_GUID") { containsGuid = true; m_aggregateColumnGuids. push_back(aggregateColumn[zz].value_.get_int()); VOLT_TRACE("Added new AGGREGATE_GUID record"); } else if (aggregateColumn[zz].name_ == "AGGREGATE_OUTPUT_COLUMN") { containsOutputColumn = true; m_aggregateOutputColumns. push_back(aggregateColumn[zz].value_.get_int()); VOLT_TRACE("Added new AGGREGATE_OUTPUT_COLUMN record"); } } assert(containsName && containsType && containsOutputColumn); } VOLT_DEBUG("Initializing GROUP BY column information for %s", this->debug().c_str()); Value groupByColumnsValue = find_value(obj, "GROUPBY_COLUMNS"); if (!(groupByColumnsValue == Value::null)) { Array groupByColumnsArray = groupByColumnsValue.get_array(); for (int ii = 0; ii < groupByColumnsArray.size(); ii++) { Value groupByColumnValue = groupByColumnsArray[ii]; PlanColumn groupByColumn = PlanColumn(groupByColumnValue.get_obj()); m_groupByColumnGuids.push_back(groupByColumn.getGuid()); m_groupByColumnNames.push_back(groupByColumn.getName()); VOLT_TRACE("[%02d] %s", ii, groupByColumn.debug().c_str()); } } }
void AggregatePlanNode::loadFromJSONObject(Object &obj) { Value aggregateColumnsValue = find_value(obj, "AGGREGATE_COLUMNS"); if (aggregateColumnsValue == Value::null) { throw SerializableEEException(VOLT_EE_EXCEPTION_TYPE_EEEXCEPTION, "AggregatePlanNode::loadFromJSONObject:" " Can't find AGGREGATE_COLUMNS value"); } Array aggregateColumnsArray = aggregateColumnsValue.get_array(); for (int ii = 0; ii < aggregateColumnsArray.size(); ii++) { Value aggregateColumnValue = aggregateColumnsArray[ii]; Object aggregateColumn = aggregateColumnValue.get_obj(); bool containsType = false; bool containsDistinct = false; bool containsOutputColumn = false; bool containsExpression = false; for (int zz = 0; zz < aggregateColumn.size(); zz++) { if (aggregateColumn[zz].name_ == "AGGREGATE_TYPE") { containsType = true; string aggregateColumnTypeString = aggregateColumn[zz].value_.get_str(); m_aggregates. push_back(stringToExpression(aggregateColumnTypeString)); } else if (aggregateColumn[zz].name_ == "AGGREGATE_DISTINCT") { containsDistinct = true; bool distinct = false; if (aggregateColumn[zz].value_.get_int() == 1) { distinct = true; } m_distinctAggregates.push_back(distinct); } else if (aggregateColumn[zz].name_ == "AGGREGATE_OUTPUT_COLUMN") { containsOutputColumn = true; m_aggregateOutputColumns. push_back(aggregateColumn[zz].value_.get_int()); } else if (aggregateColumn[zz].name_ == "AGGREGATE_EXPRESSION") { containsExpression = true; m_aggregateInputExpressions. push_back(AbstractExpression::buildExpressionTree(aggregateColumn[zz].value_.get_obj())); } } if(!(containsType && containsDistinct && containsOutputColumn)) { throw SerializableEEException(VOLT_EE_EXCEPTION_TYPE_EEEXCEPTION, "AggregatePlanNode::loadFromJSONObject:" " Missing type, distinct, or outputcolumn."); } if ( ! containsExpression) { m_aggregateInputExpressions.push_back(NULL); } } Value groupByExpressionsValue = find_value(obj, "GROUPBY_EXPRESSIONS"); if (!(groupByExpressionsValue == Value::null)) { Array groupByExpressionsArray = groupByExpressionsValue.get_array(); for (int ii = 0; ii < groupByExpressionsArray.size(); ii++) { Value groupByExpressionValue = groupByExpressionsArray[ii]; m_groupByExpressions.push_back(AbstractExpression::buildExpressionTree(groupByExpressionValue.get_obj())); } } }