Tile :: Tile(Params* const pParams, NE::SpriteLoader* pSL, const std::string& folderPath) :pParams(pParams) { assert(pParams); assert(pSL); // Check if the important nodes are present for ( unsigned int i = 0 ; i < sizeof(neededParameters) / sizeof(std::string) ; i++ ) { if ( !pParams->exists(neededParameters[i]) ) { throw MissingParameterException(neededParameters[i]); } } try { this->internalName = pParams->get("internalName"); this->name = pParams->get("name"); this->id = pParams->getAs<unsigned int>("tile-id"); this->menuEntry = pParams->getAs<short int>("tile-menu"); UVec2 spriteSize(pParams->getAs<unsigned int>("size_x"), pParams->getAs<unsigned int>("size_y")); try { this->pSprite = new CE::AnimatedSprite(pSL, folderPath + pParams->get("filename"),spriteSize,pParams->getAs<unsigned int>("animationTime",200)); } catch ( FileNotFoundException& fnfe) // Should be handle as smart ptr { delete pParams; throw fnfe; } if ( this->pSprite == NULL ) { NEError << "Fail to allocate memory for AnimatedSprite for Tile\n"; throw std::bad_alloc(); } this->defence = pParams->getAs<unsigned int>("defence"); } catch ( ParameterNotFoundParamsException& ) { NEError << "The force list is not matching the requested parameters\n"; throw MissingParameterException("unknown"); } }
/** Decrypt. * Do the decryption. * @return size of the plain text message. */ size_t WorldInfoMessageDecryptor::decrypt() { if ( (plain_buffer == NULL) || (plain_buffer_length == 0) || (crypt_buffer == NULL) || (crypt_buffer_length == 0) ) { throw MissingParameterException("Buffer(s) not set for decryption"); } #ifdef HAVE_LIBCRYPTO EVP_CIPHER_CTX ctx; if ( ! EVP_DecryptInit(&ctx, EVP_aes_128_ecb(), key, iv) ) { throw MessageDecryptionException("Could not initialize cipher context"); } int outl = plain_buffer_length; if ( ! EVP_DecryptUpdate(&ctx, (unsigned char *)plain_buffer, &outl, (unsigned char *)crypt_buffer, crypt_buffer_length) ) { throw MessageDecryptionException("DecryptUpdate failed"); } int plen = 0; if ( ! EVP_DecryptFinal(&ctx, (unsigned char *)plain_buffer + outl, &plen) ) { throw MessageDecryptionException("DecryptFinal failed"); } outl += plen; return outl; #else // Plain-text copy-through for debugging. memcpy(plain_buffer, crypt_buffer, crypt_buffer_length); return crypt_buffer_length; #endif }
Parameters::ValueType Parameters::get(KeyViewType name) const { auto ptr = find(m_data, name); if (ptr) return *ptr; throw MissingParameterException("Cannot find parameter: " + String(name)); }
void sanitycheck(libconfig::Config& cfg, libconfig::Setting& cfgnode, const string& branch) { // Check that a branch with the given name exists under cfgnode. // if (!cfgnode.exists(branch)) throw MissingParameterException("Cannot find `" + branch + "' attribute in query subtree."); // Check that the child has a name. // if (!cfgnode[branch].exists("name")) throw MissingParameterException("Cannot find `name' attribute in query subtree."); // Check that the top-level contains a node of this name. // string name = cfgnode[branch]["name"]; if (!cfg.getRoot().exists(name)) throw MissingParameterException("Cannot find description for node `" + name + "'."); // Check that the top-level node of this name names a type. // if (!cfg.getRoot()[name].exists("type")) throw MissingParameterException("Cannot find mandatory `type' parameter in description for node `" + name + "'."); }
void constructsubtree( libconfig::Config& cfg, libconfig::Setting& cfgnode, Operator** rootaddr, //< output Query::UserDefinedOpMapT& udops, int level, Query::OperatorDepthT& depthmap //< output ) { // Lookup name and type. // string name = cfgnode["name"]; string type = cfg.getRoot()[name]["type"]; assert(*rootaddr == 0); // Based on type: // 1. Allocate and chain in appropriate object // 2. Check syntax for child // 3. sanitycheck() branch // 4. Recursively call self for children // 5. Initialize this node // if ( type == "scan" || type == "partitionedscan" || type == "parallelscan" || type == "generator_int" || type == "generator_long" #ifdef ENABLE_HDF5 || type == "hdf5scan" #ifdef ENABLE_FASTBIT || type == "hdf5index" || type == "hdf5random" #endif #endif #ifdef ENABLE_FASTBIT || type == "fastbitscan" #endif ) { // Scan operator, no children. // ZeroInputOp* tmp = NULL; if (type == "scan") tmp = new ScanOp(); else if (type == "partitionedscan") tmp = new PartitionedScanOp(); else if (type == "parallelscan") tmp = new ParallelScanOp(); else if (type == "generator_int") tmp = new IntGeneratorOp(); else if (type == "generator_long") tmp = new LongGeneratorOp(); #ifdef ENABLE_HDF5 else if (type == "hdf5scan") tmp = new ScanHdf5Op(); #ifdef ENABLE_FASTBIT else if (type == "hdf5index") tmp = new IndexHdf5Op(); else if (type == "hdf5random") tmp = new RandomLookupsHdf5Op(); #endif #endif #ifdef ENABLE_FASTBIT else if (type == "fastbitscan") tmp = new FastBitScanOp(); #endif (*rootaddr) = tmp; depthmap[tmp] = level; } else if ( type == "hashjoin" || type == "sortmergejoin" || type == "mpsmjoin" || type == "newmpsmjoin" || type == "preprejoin" || type == "indexhashjoin" ) { // Dual-input operator // DualInputOp* tmp = NULL; if (type == "hashjoin") tmp = new HashJoinOp(); else if (type == "sortmergejoin") tmp = new SortMergeJoinOp(); else if (type == "mpsmjoin") tmp = new OldMPSMJoinOp(); else if (type == "newmpsmjoin") tmp = new MPSMJoinOp(); else if (type == "preprejoin") tmp = new PresortedPrepartitionedMergeJoinOp(); else if (type == "indexhashjoin") tmp = new IndexHashJoinOp(); (*rootaddr) = tmp; depthmap[tmp] = level; sanitycheck(cfg, cfgnode, "build"); constructsubtree(cfg, cfgnode["build"], &(tmp->buildOp), udops, level+1, depthmap); sanitycheck(cfg, cfgnode, "probe"); constructsubtree(cfg, cfgnode["probe"], &(tmp->probeOp), udops, level+1, depthmap); } else { // Single-input operator // SingleInputOp* tmp = NULL; if (type == "aggregate_sum") tmp = new AggregateSum(); else if (type == "aggregate_count") tmp = new AggregateCount(); else if (type == "merge") tmp = new MergeOp(); else if (type == "shmwriter") tmp = new MemSegmentWriter(); else if (type == "filter") tmp = new Filter(); else if (type == "cycle_accountant") tmp = new CycleAccountant(); else if (type == "projection") tmp = new Project(); else if (type == "checker_callstate") tmp = new CallStateChecker(); else if (type == "printer_schema") tmp = new SchemaPrinter(); else if (type == "printer_tuplecount") tmp = new TupleCountPrinter(); else if (type == "printer_perfcount") tmp = new PerfCountPrinter(); else if (type == "sort") tmp = new SortLimit(); else if (type == "printer_bitentropy") tmp = new BitEntropyPrinter(); else if (type == "consumer") tmp = new ConsumeOp(); else if (type == "printer_callcount") tmp = new CallCountPrinter(); else if (type == "threadidprepend") tmp = new ThreadIdPrependOp(); else if (type == "partition") tmp = new PartitionOp(); else { // It's a user-defined type? // Query::UserDefinedOpMapT::iterator it; it = udops.find(type); // Not a user-defined type, no idea what is it. // if (it == udops.end()) throw MissingParameterException("`" + type + "' is neither a built-in nor a user-defined type."); // Claim ownership of operator. // tmp = it->second; it->second = 0; } (*rootaddr) = tmp; depthmap[tmp] = level; sanitycheck(cfg, cfgnode, "input"); constructsubtree(cfg, cfgnode["input"], &(tmp->nextOp), udops, level+1, depthmap); } // Call Operator::init on this node. // assert(*rootaddr != 0); (*rootaddr)->init(cfg, cfg.lookup(name)); }