Cycle * XeoTerm::defaultCycle(QString _context, QDateTime _time){ if(contain(_context)){ VariableContextSpec * pcs = (*this->contextCollection)[_context]; if(pcs->get_defCycle()!=NULL){ Cycle * v = new Cycle(); v->set_context(_context); for(std::list<std::pair<QDateTime, QString> >::iterator it = pcs->get_defCycle()->get_vals()->begin();it!=pcs->get_defCycle()->get_vals()->end();++it) { std::pair<DynamicValueBase*,QDateTime> p =std::make_pair(new DynamicValue(it->first,it->second),_time); v->add_cycleValue(p); } if(pcs->get_unitSet()->get_defUnit()!=NULL) { v->set_unit(pcs->get_unitSet()->get_defUnit()->get_symbol()); } v->set_timepoint(_time); return v; } else return NULL; } else{ return NULL; } }
void ContextLessHandler::buildContexts(std::list<AttributeStore*> * _collection){ AttributeStore * currentXeoTermWithContext; for(std::list<AttributeStore*>::iterator it = _collection->begin();it!=_collection->end();++it){ if((*it)->isEnvironmentVariableTerm()){ currentXeoTermWithContext=(*it); for(std::map<QString,ItfDynamicOntologyTerm*>::iterator it2=this->terms.begin();it2!=this->terms.end();++it2){ if(currentXeoTermWithContext->get_id()==(*it2).second->get_termId()){ XeoTerm * currentXeoTerm = static_cast<XeoTerm*>((*it2).second); QString contextName = currentXeoTerm->get_name(); VariableContextSpec * context = createQualityContext(contextName); (*currentXeoTerm->get_contextCollection())[context->get_name()]=context; currentXeoTermWithContext->contextCollection->push_back(context); context=createResponseRangeContext(contextName); (*currentXeoTerm->get_contextCollection())[context->get_name()]=context; currentXeoTermWithContext->contextCollection->push_back(context); context=createFreeTextContext(); (*currentXeoTerm->get_contextCollection())[context->get_name()]=context; currentXeoTermWithContext->contextCollection->push_back(context); } } } } }
VariableContextSpec * ContextLessHandler::createFreeTextContext(){ VariableContextSpec * context =new VariableContextSpec(); context->set_unitSet(new UnitSet()); context->set_typeDefine(new TypeSpecification()); context->set_name("FreeText"); context->get_typeDefine()->set_baseType(Xeml::Document::Text); return context; }
QString XeoTerm::defaultUnitSymbol(QString _context){ if(this->hasDefaultUnit(_context)) { VariableContextSpec * pcs = (*this->contextCollection)[_context]; return pcs->get_unitSet()->get_defUnit()->get_symbol(); } else { return NULL; } }
std::vector<std::pair<QString,QString> > * XeoTerm::getEnums(QString _context){ if (this->contain(_context)){ std::vector<std::pair<QString,QString> > * ret =new std::vector<std::pair<QString,QString> >(); VariableContextSpec * pcs = (*this->contextCollection)[_context]; for(std::list<Enum*>::iterator it=pcs->get_typeDefine()->get_listEnums().begin();it!=pcs->get_typeDefine()->get_listEnums().end();++it){ ret->push_back(std::make_pair((*it)->get_textVal(),(*it)->get_textVal())); } return ret; } else{ throw exception(); } }
bool XeoTerm::hasDefaultUnit(QString _context){ if (this->contain(_context)) { VariableContextSpec * pcs = (*this->contextCollection)[_context]; return pcs->get_unitSet()->get_defUnit() != NULL; } else { std::cerr <<"exception thrown" << std::endl; throw exception(); } }
std::vector<std::pair<QString,QString> > * XeoTerm::listUnits(QString _context){ if (this->contain(_context)) { std::vector<std::pair<QString,QString> > * ret =new std::vector<std::pair<QString,QString> >(); VariableContextSpec * pcs = (*this->contextCollection)[_context]; if(pcs!=NULL) { if(pcs->get_unitSet()->get_defUnit()!=NULL) { ret->push_back(std::make_pair(pcs->get_unitSet()->get_defUnit()->get_name(),pcs->get_unitSet()->get_defUnit()->get_symbol())); } for(std::list<ConvertableUnit*>::iterator it=pcs->get_unitSet()->get_convUnits()->begin();it!=pcs->get_unitSet()->get_convUnits()->end();++it) { ret->push_back(std::make_pair((*it)->get_name(),(*it)->get_symbol())); } } return ret; } else { throw exception(); } }
VariableContextSpec * ContextLessHandler::createResponseRangeContext(QString _contextName){ Q_UNUSED(_contextName); VariableContextSpec * context =new VariableContextSpec(); context->set_unitSet(new UnitSet()); context->set_typeDefine(new TypeSpecification()); context->set_name("ResponseRange"); context->get_typeDefine()->set_baseType(Xeml::Document::Text); for (int i=0;i<=10;i++){ context->get_typeDefine()->get_typeSpecifica()->push_back(new Xeml::Document::EnvironmentalOntology::Enum(QString::number(i))); } context->set_def_value("5"); return context; }
VariableContextSpec * ContextLessHandler::createQualityContext(QString _contextName){ VariableContextSpec * context =new VariableContextSpec(); context->set_unitSet(new UnitSet()); context->set_typeDefine(new TypeSpecification()); context->set_name("Quality"); context->get_typeDefine()->set_baseType(Xeml::Document::Text); TypeSpecifics * ts= new Xeml::Document::EnvironmentalOntology::Enum(); ts->set_textVal(_contextName); context->get_typeDefine()->get_typeSpecifica()->push_back(ts); context->set_def_value(_contextName); return context; }
DynamicValue * XeoTerm::defaultdynamicValue(QString _context, QDateTime _time){ if(contain(_context)){ VariableContextSpec * pcs = (*this->contextCollection)[_context]; DynamicValue * v = new DynamicValue(); v->set_context(_context); QString tmp=pcs->get_defValue(); if((!tmp.isEmpty())||(!tmp.size()==0)){ v->set_value(pcs->get_defValue()); } else { if(this->hasDefaultCycle(_context)) { v->set_value(static_cast<DynamicValue*>(this->defaultCycle(_context)->get_cycleValues()->front().first)->get_value()); } else { switch (pcs->get_typeDefine()->get_baseType()) { case Xeml::Document::Number: { v->set_doubleValue(0.0); break; } case Xeml::Document::Text: { v->set_value(""); break; } case Xeml::Document::Bool: { v->set_booleanValue(false); break; } default: v->set_value(""); break; } } } if(pcs->get_unitSet()->get_defUnit()!=NULL) { v->set_unit(pcs->get_unitSet()->get_defUnit()->get_symbol()); } v->set_timepoint(_time); return v; } else{ return NULL; } }