#ifndef __XMLIO_CObjectTemplate_impl__ #define __XMLIO_CObjectTemplate_impl__ #include "object_factory.hpp" #include "context.hpp" #include "buffer_in.hpp" #include "attribute.hpp" #include "event_client.hpp" #include "context_client.hpp" #include "object_template.hpp" namespace xmlioserver { /// ////////////////////// Définitions ////////////////////// /// template xios_map > > CObjectTemplate::AllMapObj; template xios_map > > CObjectTemplate::AllVectObj; template xios_map CObjectTemplate::GenId; template CObjectTemplate::CObjectTemplate(void) : tree::CAttributeMap() , CObject() { /* Ne rien faire de plus */ } template CObjectTemplate::CObjectTemplate(const StdString & id) : tree::CAttributeMap() , CObject(id) { /* Ne rien faire de plus */ } template CObjectTemplate::CObjectTemplate (const CObjectTemplate & object, bool withAttrList, bool withId) : tree::CAttributeMap() , CObject() { if (object.hasId() && withId) this->setId(object.getId()); ERROR("CObjectTemplate construtor 3", << "Not completly implemented yet !"); } template CObjectTemplate::~CObjectTemplate(void) { /* Ne rien faire de plus */ } ///-------------------------------------------------------------- template std::vector > & CObjectTemplate::GetAllVectobject(const StdString & contextId) { return (CObjectTemplate::AllVectObj[contextId]); } //--------------------------------------------------------------- template StdString CObjectTemplate::toString(void) const { StdOStringStream oss; oss << "<" << T::GetName(); if (this->hasId()) oss << " id=\"" << this->getId() << "\""; oss << " " << SuperClassMap::toString() << "/>"; return (oss.str()); } template void CObjectTemplate::fromString(const StdString & str) { ERROR("CObjectTemplate::fromString(str)", << "[ str = " << str << "] Not implemented yet !"); } //--------------------------------------------------------------- template void CObjectTemplate::toBinary(StdOStream & os) const { SuperClassMap::toBinary(os); } template void CObjectTemplate::fromBinary(StdIStream & is) { SuperClassMap::fromBinary(is); } //--------------------------------------------------------------- template void CObjectTemplate::parse(xml::CXMLNode & node) { xml::THashAttributes attributes = node.getAttributes(); CAttributeMap::setAttributes(attributes); } //--------------------------------------------------------------- template tree::ENodeType CObjectTemplate::getType(void) const { return (T::GetType()); } template string CObjectTemplate::getName(void) const { return (T::GetName()); } //--------------------------------------------------------------- template bool CObjectTemplate::hasChild(void) const { return (false); } //--------------------------------------------------------------- template void CObjectTemplate::solveDescInheritance(const CAttributeMap * const parent) { SuperClassMap::setAttributes(parent); } //--------------------------------------------------------------- template void CObjectTemplate::ClearAllAttributes(void) { std::vector > & avect = CObjectTemplate::GetAllVectobject(CObjectFactory::GetCurrentContextId()); typename std::vector >::iterator it = avect.begin(), end = avect.end(); for (;it != end; it++) { CAttributeMap & amap = **it; amap.clearAllAttributes(); } } template void CObjectTemplate::sendAttributToServer(const string& id) { CAttributeMap & attrMap = *this; CAttribute* attr=attrMap[id] ; sendAttributToServer(*attr) ; } template void CObjectTemplate::sendAttributToServer(tree::CAttribute& attr) { shared_ptr context=CObjectFactory::GetObject(CObjectFactory::GetCurrentContextId()) ; if (!context->hasServer) { CContextClient* client=context->client ; CEventClient event(getType(),EVENT_ID_SEND_ATTRIBUTE) ; if (client->isServerLeader()) { CMessage msg ; msg<getId() ; msg<getServerLeader(),1,msg) ; client->sendEvent(event) ; } else client->sendEvent(event) ; } } template void CObjectTemplate::recvAttributFromClient(CEventServer& event) { CBufferIn* buffer=event.subEvents.begin()->buffer; string id,attrId; *buffer>>id ; CAttributeMap & attrMap = *get(id); *buffer>>attrId ; CAttribute* attr=attrMap[attrId] ; info(50)<<"attribut recu "<isEmpty()) info(50)<<"--> empty"<getValue()*/<>*attr ; info(50)<<"attribut recu "<isEmpty()) info(50)<<"--> empty"<getValue()*/< bool CObjectTemplate::dispatchEvent(CEventServer& event) { switch(event.type) { case EVENT_ID_SEND_ATTRIBUTE : recvAttributFromClient(event) ; return true ; break ; default : return false ; // ERROR("void CObjectTemplate::recvEvent(CEventServer& event)", // <<"Unknown Event") ; } } template bool CObjectTemplate::has(const string & id) { return CObjectFactory::HasObject(id) ; } template boost::shared_ptr CObjectTemplate::get(const string & id) { return CObjectFactory::GetObject(id) ; } template boost::shared_ptr CObjectTemplate::create(const string & id) { return CObjectFactory::CreateObject(id) ; } ///-------------------------------------------------------------- template boost::shared_ptr CObjectTemplate::get(void) { return CObjectFactory::GetObject((T*)this) ; } template void CObjectTemplate::generateCInterface(ostream& oss) { string className=getName() ; int found=className.find_first_of("_") ; if (found!=string::npos) className.replace(found,1,0,'x') ; oss<<"/* ************************************************************************** *"<"<"<()<<"* "< void CObjectTemplate::generateFortran2003Interface(ostream& oss) { string className=getName() ; int found=className.find_first_of("_") ; if (found!=string::npos) className.replace(found,1,0,'x') ; oss<<"! * ************************************************************************** *"< C99"< void CObjectTemplate::generateFortranInterface(ostream& oss) { string className=getName() ; int found=className.find_first_of('_') ; if (found!=string::npos) className.erase(found,1) ; string superClassName=getName(); found=superClassName.find("_group") ; if (found!=string::npos) superClassName.erase(found,6) ; oss<<"! * ************************************************************************** *"<