#ifndef __XMLIO_CObjectTemplate_impl__ #define __XMLIO_CObjectTemplate_impl__ #include "xmlioserver_spl.hpp" #include "context_client.hpp" #include "object_factory.hpp" #include "context.hpp" #include "buffer_in.hpp" #include "attribute.hpp" #include "event_client.hpp" #include "object_template.hpp" #include "context_client.hpp" #include "indent.hpp" #include "type_util.hpp" #include "message.hpp" #include "type.hpp" #include "type_util.hpp" #include "group_template.hpp" namespace xios { /// ////////////////////// Définitions ////////////////////// /// template xios_map > > CObjectTemplate::AllMapObj; template xios_map > > CObjectTemplate::AllVectObj; template xios_map CObjectTemplate::GenId; template CObjectTemplate::CObjectTemplate(void) : CAttributeMap() , CObject() { /* Ne rien faire de plus */ } template CObjectTemplate::CObjectTemplate(const StdString & id) : CAttributeMap() , CObject(id) { /* Ne rien faire de plus */ } template CObjectTemplate::CObjectTemplate (const CObjectTemplate & object, bool withAttrList, bool withId) : 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 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(bool apply, const CAttributeMap * const parent) { if (parent != NULL) SuperClassMap::setAttributes(parent, apply); } //--------------------------------------------------------------- template void CObjectTemplate::ClearAllAttributes(void) { vector avect = CObjectTemplate::getAll(); typename vector::iterator it = avect.begin(), end = avect.end(); for (;it != end; it++) { CAttributeMap & amap = **it; amap.clearAllAttributes(); } } template void CObjectTemplate::sendAllAttributesToServer() { CAttributeMap& attrMap = *this; CAttributeMap::const_iterator it = attrMap.begin(), itE = attrMap.end(); for (; it != itE; ++it) { if (!(it->second)->isEmpty()) sendAttributToServer(*(it->second)); } } template void CObjectTemplate::sendAttributToServer(const string& id) { CAttributeMap & attrMap = *this; CAttribute* attr=attrMap[id]; sendAttributToServer(*attr); } template void CObjectTemplate::sendAttributToServer(CAttribute& attr) { CContext* context=CContext::getCurrent(); if (!context->hasServer) { CContextClient* client=context->client; CEventClient event(getType(),EVENT_ID_SEND_ATTRIBUTE); if (client->isServerLeader()) { CMessage msg; // msg<getId(); msg<getIdServer(); 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 bool CObjectTemplate::has(const string& contextId, const string & id) { return CObjectFactory::HasObject(contextId,id); } template T* CObjectTemplate::get(const string & id) { return CObjectFactory::GetObject(id).get(); } template T* CObjectTemplate::get(const T* ptr) { return CObjectFactory::GetObject(ptr).get(); } template shared_ptr CObjectTemplate::getShared(const T* ptr) { return CObjectFactory::GetObject(ptr); } template shared_ptr CObjectTemplate::getShared(void) { return CObjectFactory::GetObject((T*)this); } template const vector CObjectTemplate::getAll() { const vector< shared_ptr >& shared_vect= CObjectFactory::GetObjectVector(); vector vect; typename vector >::const_iterator it; for(it=shared_vect.begin();it!=shared_vect.end();++it) vect.push_back(it->get()); return vect; } template const vector CObjectTemplate::getAll(const string & id) { const vector< shared_ptr >& shared_vect= CObjectFactory::GetObjectVector(id); vector vect; typename vector >::const_iterator it; for(it=shared_vect.begin();it!=shared_vect.end();++it) vect.push_back(it->get()); return vect; } template T* CObjectTemplate::get(const string& contextId, const string & id) { return CObjectFactory::GetObject(contextId,id).get(); } template T* CObjectTemplate::create(const string & id) { return CObjectFactory::CreateObject(id).get(); } ///-------------------------------------------------------------- template T* CObjectTemplate::get(void) { return CObjectFactory::GetObject((T*)this).get(); } template void CObjectTemplate::generateCInterface(ostream& oss) { string className=getName(); int found=className.rfind("_group"); if (found!=string::npos) className.replace(found,1,0,'x'); oss<<"/* ************************************************************************** *"<"<"<()<<"* "< void CObjectTemplate::generateFortran2003Interface(ostream& oss) { string className=getName(); int found=className.rfind("_group"); if (found!=string::npos) className.replace(found,1,0,'x'); oss<<"! * ************************************************************************** *"< C99"< void CObjectTemplate::generateFortranInterface(ostream& oss) { string className=getName(); int found=className.rfind("_group"); if (found!=string::npos) className.erase(found,1); string superClassName=getName(); found=superClassName.find("_group"); if (found!=string::npos) superClassName.erase(found,6); oss<<"! * ************************************************************************** *"<