void PrototypeManager::removePrototype(Item* prototype) { string ident = prototype->getIdentifier(); CHECK("Has valid identifier", ident != "" && getPrototype(ident) != NULL); prototypes.erase(ident); }
void EvoAlgoTestRandom::runTest() { Logger::info("Start test"); Genotype* g = getPrototype()->clone(); GenotypeFloat* gf; GenotypeInt* gi; if ((gf = dynamic_cast<GenotypeFloat*>(g)) != nullptr) { const float minVal = -5.0; const float maxVal = 5.0; gf->initRandom(minVal, maxVal); } else if ((gi = dynamic_cast<GenotypeInt*>(g)) != nullptr) { const int minVal = 0; const int maxVal = 256; gi->initRandom(minVal, maxVal); } else { salsa::Logger::error("Invalid genotype type"); return; } getGenotypeTester()->setGenotype(g); getGAEvaluator()->evaluate(); Logger::info("End test"); }
bool EvoAlgoTestIndividual::loadGenotypes() { // Removing all old genotypes freeGenotypes(); // Loading all genotypes QFile inData(m_filename); if (inData.open(QFile::ReadOnly)) { QTextStream in(&inData); while (!in.atEnd()) { std::unique_ptr<Genotype> g(getPrototype()->clone()); bool loaded = g->loadGen(in); if (!loaded) { // This could be not a real error, only notifying the user Logger::warning(QString("Error loading the genotype at index %1 from file %2").arg(m_genotypes.size()).arg(m_filename)); break; } m_genotypes.append(g.release()); } inData.close(); } else { Logger::error(QString("Cannot open file %1 to read genotypes").arg(m_filename)); return false; } return true; }
Item* PrototypeManager::createInstance(DataFile* dataFile, string ident) { Item* prototype = getPrototype(ident); if(prototype == NULL) { return NULL; } else { Item* item = static_cast<Item*>(prototype->createInstance(dataFile)); return item; } }
ParameterDescriptor ComponentFactory::getParameterDescriptor( const std::string& component, const std::string& param) { const Component* c = getPrototype(component); if (!c) return ParameterDescriptor(); const ParameterDescriptorList& pList = c->getParameterDescriptorList(); for (size_t i = 0; i < pList.size(); i++) { if (pList[i].m_identifier == param) return pList[i]; } assert(false); return ParameterDescriptor(); }
Item* PrototypeManager::createClone(DataFile* dataFile, string ident) { Item* prototype = getPrototype(ident); if(prototype == NULL) { return NULL; } else { Item* item = static_cast<Item*>(prototype->clone(dataFile)); item->setPrototypeName(prototype->getIdentifier()); return item; } }
/// Returns the Hermann-Mauguin symbols of all point groups that belong to a /// certain crystal system. std::vector<std::string> PointGroupFactoryImpl::getPointGroupSymbols( const PointGroup::CrystalSystem &crystalSystem) { std::vector<std::string> pointGroups; for (auto &generator : m_generatorMap) { PointGroup_sptr pointGroup = getPrototype(generator.first); if (pointGroup->crystalSystem() == crystalSystem) { pointGroups.push_back(generator.first); } } return pointGroups; }
/// Returns the Hermann-Mauguin symbols of all point groups that belong to a /// certain crystal system. std::vector<std::string> PointGroupFactoryImpl::getPointGroupSymbols( const PointGroup::CrystalSystem &crystalSystem) { std::vector<std::string> pointGroups; for (auto it = m_generatorMap.begin(); it != m_generatorMap.end(); ++it) { PointGroup_sptr pointGroup = getPrototype(it->first); if (pointGroup->crystalSystem() == crystalSystem) { pointGroups.push_back(it->first); } } return pointGroups; }
Component* ComponentFactory::createComponent(const std::string& identifier) { const Component* p = getPrototype(identifier); if (p) return p->clone(); return NULL; }
// We come here from syntax like // SELECT * FROM :hv PROTOTYPE 'cat.sch.tbl'; -- host variable, static SQL // TABLE $ev; -- env var, static or dynam // (Internally, both host vars and env vars are HostVar objects.) // // If there's an environment variable, get its value at time of compilation, // and stick that into the internal prototype value. Generator will need // to save these env var name/value pairs in the generated code; // Executor needs to use the saved compile-time value of any name that is not // defined at run-time. // // If there's a prototype value, parse it as an actual table name // (1, 2, or 3-part name) and overwrite the bogus values in *this with the // parsed prototype value. Our caller, applyDefaults, will overwrite any // remaining blank name parts. Generator needs to save the host var names // for actual input at run-time, and to save the prototype values for // similarity check at run-time. // // We avoid re-parsing and re-overwriting this CorrName by checking/setting // its bound state. Note that we do not rely on its prototype's bound state // because that is a separate, pointed at object: some Binder subroutines // make local copies of CorrNames, and any apply methods invoked on the locals // would not be propagated to the caller's originals: relying on the then True // value of the prototype's bound state would be fallacious. // // If no error in proto, node is bound and bindWA errStatus unchanged // (note that not having a proto is not an error). // If error in proto, node is left unbound and bindWA errStatus is set. // void CorrName::applyPrototype(BindWA *bindWA) { if (nodeIsBound()) return; HostVar *proto = getPrototype(); if (!proto) { markAsBound(); return; } // CMPASSERT(this == proto->getPrototypeTarget()); CMPASSERT(!proto->getName().isNull()); if (proto->isEnvVar()) { char *value = getenv(proto->getName()); if (!value) { // Environment variable has no defined value. *CmpCommon::diags() << DgSqlCode(-4086) << DgString0(proto->getName()); bindWA->setErrStatus(); return; } // upcase value returned by getenv #pragma nowarn(1506) // warning elimination Int32 len = strlen(value); #pragma warn(1506) // warning elimination char * ucValue = new (bindWA->wHeap()) char[len+1]; str_cpy_convert(ucValue, value, len, -1/*upshift*/); ucValue[len] = 0; proto->getPrototypeValue() = ucValue; // do not free "ucValue" here, it is still used in "proto" // to prevent Coverity RESOURCE_LEAK error, add the following // coverity[leaked_storage] } // defines can not be used on linux platform if (proto->isDefine()) { *CmpCommon::diags() << DgSqlCode(-4155) << DgString0(proto->getName()); bindWA->setErrStatus(); return; } CMPASSERT(!proto->getPrototypeValue().isNull()); // Some of the following code is cloned from the QualifiedName ctor above Parser parser(bindWA->currentCmpContext()); NAString ns("TABLE " + proto->getPrototypeValue() + ";", CmpCommon::statementHeap()); #pragma nowarn(1506) // warning elimination // save the current parserflags setting ULng32 savedParserFlags = Get_SqlParser_Flags (0xFFFFFFFF); StmtQuery *stmt = (StmtQuery *)parser.parseDML(ns, ns.length(), GetAnsiNameCharSet()); // Restore parser flags settings Set_SqlParser_Flags (savedParserFlags); #pragma warn(1506) // warning elimination if (stmt) { CMPASSERT(stmt->getOperatorType() == STM_QUERY); CorrName &protoCorrName = stmt->getQueryExpression()->getScanNode()->getTableName(); // Unless the hostvar type was forced directly, // copy the special table type to me, the prototype may be a // resource fork if (getSpecialType() == ExtendedQualName::NORMAL_TABLE) setSpecialType(protoCorrName); // This if-test prevents pathologies such as // SELECT col FROM :hv1 PROTOTYPE ':hv2 PROTOTYPE ''tbl'''; // but allows // SELECT col FROM :hv1 PROTOTYPE '$ev'; // // (The assertion below ensures that only host var syntax allows prototypes, // that you can't say ... FROM $ev PROTOTYPE '...'.) // HostVar *proto2 = protoCorrName.getPrototype(); CMPASSERT(!proto2 || !proto->isEnvVar()); if (!proto2 || proto2->isEnvVar()) { if (proto2) { // Here if proto2->isEnvVar. // Recurse (once only; the assertion above ensures that) // to get the value of the var, parse it and all. protoCorrName.applyPrototype(bindWA); if (bindWA->errStatus()) return; } #ifndef NDEBUG if (getenv("HV_DEBUG")) cout << "HostVar/Prototype: parsed (" << (Int32)proto->nodeIsBound() << ") " << proto->getName() << " " << protoCorrName.getExposedNameAsAnsiString() << endl; #endif // assert *before* overwriting with 0 // CMPASSERT(!getQualifiedNameObj().getNamePosition()); getQualifiedNameObj() = protoCorrName.getQualifiedNameObj(); proto->setPrototypeType(HostVar::QUALIFIEDNAME); // mark that we, the trusted CorrName, are bound markAsBound(); } } if (!nodeIsBound()) { // Clear parser syntax error and emit "Prototype value not valid" #ifndef NDEBUG if (!getenv("HV_DEBUG")) #endif CmpCommon::diags()->clear(); *CmpCommon::diags() << DgSqlCode(-4087) << DgString0(proto->getPrototypeValue()); bindWA->setErrStatus(); } delete stmt; } // applyPrototype