本文整理汇总了C++中pacc::xml::ConstIterator::getFirstChild方法的典型用法代码示例。如果您正苦于以下问题:C++ ConstIterator::getFirstChild方法的具体用法?C++ ConstIterator::getFirstChild怎么用?C++ ConstIterator::getFirstChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pacc::xml::ConstIterator
的用法示例。
在下文中一共展示了ConstIterator::getFirstChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Beagle_IOExceptionNodeM
/*!
* \brief Read an ES vector from a XML subtree.
* \param inIter XML iterator from which the ES vector is read.
* \param ioContext Evolutionary context.
* \throw IOException If a reading error occured (generally bad file format)!
*/
void GA::ESVector::readWithContext(PACC::XML::ConstIterator inIter, Context& ioContext)
{
Beagle_StackTraceBeginM();
if((inIter->getType() != PACC::XML::eData) || (inIter->getValue() != "Genotype")) {
throw Beagle_IOExceptionNodeM(*inIter, "tag <Genotype> expected!");
}
std::string lGenotypeType = inIter->getAttribute("type");
if((lGenotypeType.empty() == false) && (lGenotypeType != getType())) {
std::ostringstream lOSS;
lOSS << "type given '" << lGenotypeType << "' mismatch type of the genotype '";
lOSS << getType() << "'!";
throw Beagle_IOExceptionNodeM(*inIter, lOSS.str());
}
PACC::XML::ConstIterator lChild = inIter->getFirstChild();
if((!lChild) || (lChild->getType()!=PACC::XML::eString)) {
throw Beagle_IOExceptionNodeM(*lChild, "expected content for the ES vector!");
}
clear();
std::istringstream lISS(lChild->getValue());
do {
char lC1='\0', lC2='\0', lC3='\0';
double lValue=DBL_MAX, lStrategy=DBL_MAX;
lISS >> lC1 >> lValue >> lC2 >> lStrategy >> lC3;
if((lC1!='(') || (lC2!=',') || (lC3!=')'))
throw Beagle_IOExceptionNodeM(*lChild, "bad format of ES vector!");
if((lValue==DBL_MAX) || (lStrategy==DBL_MAX))
throw Beagle_IOExceptionNodeM(*lChild, "bad format of ES vector!");
push_back(ESPair(lValue, lStrategy));
} while(lISS.get()==int('/'));
Beagle_StackTraceEndM("void GA::ESVector::readWithContext(PACC::XML::ConstIterator,Context&)");
}
示例2: Beagle_IOExceptionNodeM
/*!
* \brief Read a float vector from a XML subtree.
* \param inIter XML iterator from which the float vector is read.
* \param ioContext Evolutionary context.
* \throw Beagle::IOException If a reading error occured (generally bad file format)!
*/
void GA::IntegerVector::readWithContext(PACC::XML::ConstIterator inIter, Context& ioContext)
{
Beagle_StackTraceBeginM();
if((inIter->getType() != PACC::XML::eData) || (inIter->getValue() != "Genotype")) {
throw Beagle_IOExceptionNodeM(*inIter, "tag <Genotype> expected!");
}
std::string lGenotypeType = inIter->getAttribute("type");
if((lGenotypeType.empty() == false) && (lGenotypeType != getType())) {
std::ostringstream lOSS;
lOSS << "type given '" << lGenotypeType << "' mismatch type of the genotype '";
lOSS << getType() << "'!";
throw Beagle_IOExceptionNodeM(*inIter, lOSS.str());
}
PACC::XML::ConstIterator lChild = inIter->getFirstChild();
if((!lChild) || (lChild->getType()!=PACC::XML::eString))
throw Beagle_IOExceptionNodeM(*lChild, "expected content for the float vector!");
clear();
std::istringstream lISS(lChild->getValue());
while(lISS.good()) {
int lValue=INT_MAX;
lISS >> lValue;
push_back(lValue);
if(lISS.good()==false) break;
int lDelim=lISS.get();
if((lISS.good()==false) || (lDelim==-1)) break;
}
Beagle_StackTraceEndM("void GA::IntegerVector::readWithContext(PACC::XML::ConstIterator,Context&)");
}
示例3: readWithSystem
/*!
* \brief Read object from XML using system.
* \param inIter XML iterator of input document.
* \param ioSystem A reference to the system.
* \throw SCHNAPS::Core::IOException if a wrong tag is encountered.
*/
void PrimitiveTree::readWithSystem(PACC::XML::ConstIterator inIter, System& ioSystem) {
schnaps_StackTraceBeginM();
if (inIter) {
if (inIter->getType() != PACC::XML::eData) {
throw schnaps_IOExceptionNodeM(*inIter, "tag expected!");
}
if (inIter->getValue() != getName()) {
std::ostringstream lOSS;
lOSS << "tag <" << getName() << "> expected, but ";
lOSS << "got tag <" << inIter->getValue() << "> instead!";
throw schnaps_IOExceptionNodeM(*inIter, lOSS.str());
}
// Get size attribute and reserve size accordingly
std::string lSizeText = inIter->getAttribute("size");
if (lSizeText.empty() == false) {
reserve(str2uint(lSizeText));
}
PACC::XML::ConstIterator lChild = inIter->getFirstChild();
if ((!lChild) || (lChild->getType() != PACC::XML::eData)) {
throw schnaps_IOExceptionNodeM(*lChild, "expected a XML tag for the primitive tree!");
}
clear();
readSubTree(lChild, ioSystem);
}
schnaps_StackTraceEndM("void SCHNAPS::Core::PrimitiveTree::readWithSystem(PACC::XML::ConstIterator, SCHNAPS::Core::System&)");
}
示例4: readWithSystem
/*!
* \brief Read a Factory, obtain selection of default types for the different families.
* \param inIter Iterator to the XML node to read the Factory from.
* \param ioSystem System to use to read the type selector.
* \throw Beagle::IOException If the format is invalid.
*/
void Factory::readWithSystem(PACC::XML::ConstIterator inIter, System& ioSystem)
{
Beagle_StackTraceBeginM();
if((inIter->getType()!=PACC::XML::eData) || (inIter->getValue()!="Factory")) {
throw Beagle_IOExceptionNodeM(*inIter, "tag <Factory> expected!");
}
for(PACC::XML::ConstIterator lChild=inIter->getFirstChild(); lChild; ++lChild) {
if((lChild->getType()==PACC::XML::eData) && (lChild->getValue()=="Concept")) {
std::string lConceptName = lChild->getAttribute("name");
if(lConceptName.empty()) {
throw Beagle_IOExceptionNodeM(*lChild, "no name attribute given for current Concept tag!");
}
std::string lTypeName = lChild->getAttribute("type");
if(lTypeName.empty()) {
throw Beagle_IOExceptionNodeM(*lChild, "no type attribute given for current Concept tag!");
}
Factory::AllocatorMap::const_iterator lIterAllocMap = mAllocatorMap.find(lTypeName);
if(lIterAllocMap == mAllocatorMap.end()) {
std::ostringstream lOSS;
lOSS << "Type named '" << lTypeName;
lOSS << "' does not exists in the internal allocator map of the Factory; ";
lOSS << "could not associated to concept '" << lConceptName << "'.";
throw Beagle_IOExceptionNodeM(*lChild, lOSS.str());
}
setConcept(lConceptName, lTypeName);
Beagle_LogTraceM(
ioSystem.getLogger(),
std::string("Type associated to concept '")+lConceptName+
std::string("' is now '")+lTypeName+std::string("'")
);
}
}
Beagle_StackTraceEndM();
}
示例5: Beagle_IOExceptionNodeM
/*!
* \brief Read an instruction super set from a Beagle XML stream.
* \param inIter XML node used to read the super set from.
* \throw Beagle::IOException If size atribute not present.
*/
void LinGP::InstructionSuperSet::read(PACC::XML::ConstIterator inIter)
{
if((inIter->getType() != PACC::XML::eData) || (inIter->getValue() != "InstructionSuperSet"))
throw Beagle_IOExceptionNodeM((*inIter), "tag <InstructionSuperSet> expected!");
unsigned int lPSIndex = 0;
for(PACC::XML::ConstIterator lChild=inIter->getFirstChild(); lChild; ++lChild) {
if((lChild->getType()==PACC::XML::eData) && (lChild->getValue()=="InstructionSet")) {
mInstructionSets[lPSIndex++]->read(lChild);
}
}
}
示例6:
/*!
* \brief Read invoker primitive from XML subtree.
* \param inIter XML iterator to read the primitive from.
* \param ioContext Evolutionary context.
*/
void GP::Invoker::readWithContext(PACC::XML::ConstIterator inIter, GP::Context& ioContext)
{
Beagle_StackTraceBeginM();
GP::Primitive::readWithContext(inIter, ioContext);
std::string lIndexValue = inIter->getAttribute("id");
if(lIndexValue.empty()==false) mIndex = str2uint(lIndexValue);
unsigned int lArgsCount = 0;
for(PACC::XML::ConstIterator lChild=inIter->getFirstChild(); lChild; ++lChild) {
if(lChild->getType()==PACC::XML::eData) ++lArgsCount;
}
setNumberArguments(lArgsCount);
Beagle_StackTraceEndM("void GP::Invoker::readWithContext(PACC::XML::ConstIterator inIter, GP::Context& ioContext)");
}
示例7: readWithSystem
/*!
* \brief Read the state of the quasi-random generator from a XML subtree.
* \param inIter XML iterator to read the mersenne twister randomizer from.
* \param ioSystem
*/
void QuasiRandom::readWithSystem(PACC::XML::ConstIterator inIter, System& ioSystem)
{
Beagle_StackTraceBeginM();
if((inIter->getType()!=PACC::XML::eData) || (inIter->getValue()!="QuasiRandom"))
throw Beagle_IOExceptionNodeM(*inIter, "tag <QuasiRandom> expected!");
PACC::XML::ConstIterator lChild = inIter->getFirstChild();
if(lChild) {
if(lChild->getType()!=PACC::XML::eString)
throw Beagle_IOExceptionNodeM(*lChild, "expected quasi-random state!");
setState(lChild->getValue());
} else reset(0);
Beagle_StackTraceEndM("void QuasiRandom::readWithSystem(PACC::XML::ConstIterator inIter, System& ioSystem)");
}
示例8: readWithContext
/*!
* \brief Read an individual bag with a context.
* \param inIter XML iterator to read the bag from.
* \param ioContext Evolutionary context.
*/
void IndividualBag::readWithContext(PACC::XML::ConstIterator inIter, Context& ioContext)
{
Beagle_StackTraceBeginM();
if((inIter->getType()!=PACC::XML::eData) || (inIter->getValue()!="IndividualBag"))
throw Beagle_IOExceptionNodeM(*inIter, "tag <IndividualBag> expected!");
for(PACC::XML::ConstIterator lChild=inIter->getFirstChild(); lChild; ++lChild) {
if(lChild->getType() == PACC::XML::eData) {
readIndividuals(lChild, ioContext);
break;
}
}
Beagle_StackTraceEndM();
}
示例9: readWithContext
/*!
* \brief Read an individual from an XML node.
* \param inIter XML iterator to read the individual from.
* \param ioContext Evolutionary context to use to read the individual.
* \throw Beagle::IOException If the format is not respected.
*/
void Individual::readWithContext(PACC::XML::ConstIterator inIter, Context& ioContext)
{
Beagle_StackTraceBeginM();
if((inIter->getType()!=PACC::XML::eData) || (inIter->getValue()!="Individual")) {
throw Beagle_IOExceptionNodeM(*inIter, "tag <Individual> expected!");
}
// Be sure that the types are corresponding
const std::string& lIndivType = inIter->getAttribute("type");
if((lIndivType.empty() == false) && (lIndivType != getType())) {
std::ostringstream lOSS;
lOSS << "type given '" << lIndivType << "' mismatch type of the individual '";
lOSS << getType() << "'!";
throw Beagle_IOExceptionNodeM(*inIter, lOSS.str());
}
// Read members
readMembers(inIter->getFirstChild(), ioContext);
// Read fitness
readFitness(inIter->getFirstChild(), ioContext);
// Read genotypes
readGenotypes(inIter->getFirstChild(), ioContext);
Beagle_StackTraceEndM();
}
示例10: readWithContext
/*!
* \brief Read a vivarium from an XML node.
* \param inIter XML iterator to read the vivarium from.
* \param ioContext Evolutionary context to use to read the vivarium.
* \throw Beagle::IOException If the format is not respected.
*/
void Vivarium::readWithContext(PACC::XML::ConstIterator inIter, Context& ioContext)
{
Beagle_StackTraceBeginM();
if((inIter->getType()!=PACC::XML::eData) || (inIter->getValue()!="Vivarium")) {
throw Beagle_IOExceptionNodeM(*inIter, "tag <Vivarium> expected!");
}
// Be sure that the types are corresponding
const std::string& lVivariumType = inIter->getAttribute("type");
if((lVivariumType.empty()==false) && (lVivariumType!=getType())) {
std::ostringstream lOSS;
lOSS << "type given '" << lVivariumType << "' mismatch type of the vivarium '";
lOSS << getType() << "'!";
throw Beagle_IOExceptionNodeM(*inIter, lOSS.str());
}
// Read members
readMembers(inIter->getFirstChild(), ioContext);
// Read population
for(PACC::XML::ConstIterator lChild=inIter->getFirstChild(); lChild; ++lChild) {
if((lChild->getType()==PACC::XML::eData) && (lChild->getValue()=="Population")) {
readPopulation(lChild, ioContext);
}
}
Beagle_StackTraceEndM();
}
示例11: Beagle_IOExceptionNodeM
/*!
* \brief Read an instruction set from a XML node.
* \param inIter XML node to read the instruction set from.
* \throw IOException If size atribute not present or if the size mismatch.
*/
void LinGP::InstructionSet::read(PACC::XML::ConstIterator inIter)
{
if((inIter->getType() != PACC::XML::eData) || (inIter->getValue() != "InstructionSet"))
throw Beagle_IOExceptionNodeM(*inIter, "tag <InstructionSet> expected!");
for(PACC::XML::ConstIterator lChild=inIter->getFirstChild(); lChild; ++lChild) {
if(lChild->getType() == PACC::XML::eData) {
Instruction::Handle lInstruction = getInstructionByName(lChild->getValue());
if(lInstruction == NULL) {
std::ostringstream lOSS;
lOSS << "Instruction '" << lChild->getValue();
lOSS << "' is not in the instruction set!";
throw Beagle_IOExceptionNodeM(*lChild, lOSS.str());
}
lInstruction->read(lChild);
}
}
}
示例12: readSubTree
/*!
* \brief Read a primitive subtree from a XML subtree.
* \param inIter XML iterator to read primitive tree from.
* \param ioSystem A reference to the system.
* \return The size of the subtree read.
* \throw SCHNAPS::Core::IOException if a wrong tag is encountered.
*/
unsigned int PrimitiveTree::readSubTree(PACC::XML::ConstIterator inIter, System& ioSystem) {
schnaps_StackTraceBeginM();
if (inIter->getType() != PACC::XML::eData) {
throw schnaps_IOExceptionNodeM(*inIter, "tag expected!");
}
Primitive::Alloc::Handle lPrimitiveAlloc = castHandleT<Primitive::Alloc>(ioSystem.getFactory().getAllocator(inIter->getValue()));
if(lPrimitiveAlloc == NULL) {
std::ostringstream lOSS;
lOSS << "no primitive named '" << inIter->getValue();
lOSS << "' found in the factory";
throw schnaps_IOExceptionNodeM(*inIter, lOSS.str());
}
Primitive::Handle lPrimitive = castHandleT<Primitive>(lPrimitiveAlloc->allocate());
unsigned int lNodeIdx = size();
push_back(Node(lPrimitive, 0));
(*this)[lNodeIdx].mPrimitive->readWithSystem(inIter, ioSystem);
unsigned int lSubTreeSize = 1;
unsigned int lNbChild = 0;
for (PACC::XML::ConstIterator lChild = inIter->getFirstChild(); lChild; lChild++) {
if (lChild->getType() == PACC::XML::eData) {
lSubTreeSize += readSubTree(lChild, ioSystem);
lNbChild++;
}
}
if ((*this)[lNodeIdx].mPrimitive->getNumberArguments() == Primitive::eAny) {
(*this)[lNodeIdx].mPrimitive->setNumberArguments(lNbChild);
} else {
if (lNbChild != (*this)[lNodeIdx].mPrimitive->getNumberArguments()) {
std::ostringstream lOSS;
lOSS << "number of arguments stated by the primitives (";
lOSS << (*this)[lNodeIdx].mPrimitive->getNumberArguments();
lOSS << ") mismatch the number of arguments read for the tree node (";
lOSS << lNbChild << ")!";
throw schnaps_IOExceptionNodeM(*inIter, lOSS.str());
}
}
(*this)[lNodeIdx].mSubTreeSize = lSubTreeSize;
return lSubTreeSize;
schnaps_StackTraceEndM("void SCHNAPS::Core::PrimitiveTree::readSubTree(PACC::XML::ConstIterator, SCHNAPS::Core::System&)");
}
示例13: readPopulation
/*!
* \brief Read a vivarium population from an XML iterator.
* \param inIter XML iterator to read the vivarium population from.
* \param ioContext Evolutionary context.
* \throw Beagle::IOException If the format is not respected.
*/
void Vivarium::readPopulation(PACC::XML::ConstIterator inIter, Context& ioContext)
{
Beagle_StackTraceBeginM();
if((inIter->getType()!=PACC::XML::eData) || (inIter->getValue()!="Population")) {
throw Beagle_IOExceptionNodeM(*inIter, "tag <Population> expected!");
}
const Factory& lFactory = ioContext.getSystem().getFactory();
unsigned int lPrevDemeIndex = ioContext.getDemeIndex();
Deme::Handle lPrevDemeHandle = ioContext.getDemeHandle();
clear();
for(PACC::XML::ConstIterator lIter=inIter->getFirstChild(); lIter; ++lIter) {
if((lIter->getType()!=PACC::XML::eData) || (lIter->getValue()!="Deme")) continue;
const std::string& lDemeType = lIter->getAttribute("type");
Deme::Alloc::Handle lDemeAlloc = NULL;
if(lDemeType.empty()) {
Deme::Alloc::Handle lDemeAlloc =
castHandleT<Deme::Alloc>(lFactory.getConceptAllocator("Deme"));
if(lDemeAlloc == NULL) {
std::ostringstream lOSS;
lOSS << "Deme object can't be read, ";
lOSS << "it appears that its type is not given and that there is not ";
lOSS << "valid concept allocator associated to it!";
throw Beagle_IOExceptionNodeM(*lIter, lOSS.str());
}
} else {
lDemeAlloc = castHandleT<Deme::Alloc>(lFactory.getAllocator(lDemeType));
if(lDemeAlloc == NULL) {
std::ostringstream lOSS;
lOSS << "Type '" << lDemeType << "' associated to deme object ";
lOSS << "is not valid!";
throw Beagle_IOExceptionNodeM(*lIter, lOSS.str());
}
}
Deme::Handle lDeme = castHandleT<Deme>(lDemeAlloc->allocate());
ioContext.setDemeHandle(lDeme);
ioContext.setDemeIndex(size());
push_back(lDeme);
lDeme->readWithContext(lIter, ioContext);
}
ioContext.setDemeHandle(lPrevDemeHandle);
ioContext.setDemeIndex(lPrevDemeIndex);
Beagle_StackTraceEndM();
}
示例14: read
/*!
* \brief Read a multiobjective fitness from a XML subtree.
* \param inIter XML iterator to use to read the fitness value.
*/
void FitnessMultiObj::read(PACC::XML::ConstIterator inIter)
{
Beagle_StackTraceBeginM();
if((inIter->getType()!=PACC::XML::eData) || (inIter->getValue()!="Fitness"))
throw Beagle_IOExceptionNodeM(*inIter, "tag <Fitness> expected!");
const std::string& lValid = inIter->getAttribute("valid");
if(lValid.empty() || (lValid == "yes")) {
// Check type of fitness read
const std::string& lType = inIter->getAttribute("type");
if((lType.empty() == false) && (lType != getType())) {
std::ostringstream lOSS;
lOSS << "type given '" << lType << "' mismatch type of the fitness '";
lOSS << getType() << "'!";
throw Beagle_IOExceptionNodeM(*inIter, lOSS.str());
}
// Read objective values
clear();
for(PACC::XML::ConstIterator lChild=inIter->getFirstChild(); lChild; ++lChild) {
if((lChild->getType() != PACC::XML::eData) || (lChild->getValue() != "Obj")) continue;
PACC::XML::ConstIterator lChild2 = lChild->getFirstChild();
if(!lChild2) throw Beagle_IOExceptionNodeM(*lChild, "needed a double value in the <Obj> tag!");
if(lChild2->getType() != PACC::XML::eString)
throw Beagle_IOExceptionNodeM(*lChild2, "needed a double value in the <Obj> tag!");
push_back(str2dbl(lChild2->getValue()));
}
setValid();
} else if(lValid == "no") {
clear();
setInvalid();
}
else {
throw Beagle_IOExceptionNodeM(*inIter, "bad fitness validity value!");
}
Beagle_StackTraceEndM();
}
示例15: read
/*!
* \brief Reading a history entry.
*/
void HistoryEntry::read(PACC::XML::ConstIterator inIter)
{
Beagle_StackTraceBeginM();
if((inIter->getType()!=PACC::XML::eData) || (inIter->getValue()!="Entry"))
throw Beagle_IOExceptionNodeM(*inIter, "tag <Entry> expected!");
std::string lIndividualVarText = inIter->getAttribute("var");
if(lIndividualVarText.empty())
throw Beagle_IOExceptionNodeM(*inIter, "attribute 'var' of the tag <Entry> expected!");
else
mIndividualVar = str2uint(lIndividualVarText);
std::string lGenerationText = inIter->getAttribute("generation");
if (lGenerationText.empty())
throw Beagle_IOExceptionNodeM(*inIter, "attribute 'generation' of the tag <Entry> expected!");
else
mGeneration = str2uint(lGenerationText);
mParents.clear();
mActions.clear();
mOpNames.clear();
for(PACC::XML::ConstIterator lChild(inIter->getFirstChild()); lChild; ++lChild) {
if(lChild->getType()==PACC::XML::eData) {
if(lChild->getValue()=="Parent") {
unsigned int lHistoryId = str2uint(lChild->getAttribute("id"));
unsigned int lHistoryVar = str2uint(lChild->getAttribute("var"));
mParents.push_back(HistoryID(lHistoryId, lHistoryVar));
} else if(lChild->getValue()=="Operations") {
mActions.push_back(lChild->getAttribute("action"));
mOpNames.push_back(lChild->getAttribute("opname"));
}
}
}
Beagle_StackTraceEndM();
}