[219] | 1 | #ifndef __XMLIO_CObjectTemplate_impl__ |
---|
| 2 | #define __XMLIO_CObjectTemplate_impl__ |
---|
| 3 | |
---|
[300] | 4 | #include "object_factory.hpp" |
---|
| 5 | #include "context.hpp" |
---|
| 6 | #include "buffer_in.hpp" |
---|
| 7 | #include "attribute.hpp" |
---|
| 8 | #include "event_client.hpp" |
---|
| 9 | #include "context_client.hpp" |
---|
| 10 | #include "object_template.hpp" |
---|
| 11 | |
---|
[219] | 12 | namespace xmlioserver |
---|
| 13 | { |
---|
| 14 | /// ////////////////////// Définitions ////////////////////// /// |
---|
| 15 | template <class T> |
---|
| 16 | xios_map<StdString, |
---|
| 17 | xios_map<StdString, |
---|
| 18 | boost::shared_ptr<T> > > CObjectTemplate<T>::AllMapObj; |
---|
| 19 | |
---|
| 20 | template <class T> |
---|
| 21 | xios_map<StdString, |
---|
| 22 | std::vector<boost::shared_ptr<T> > > CObjectTemplate<T>::AllVectObj; |
---|
| 23 | |
---|
| 24 | template <class T> |
---|
[286] | 25 | xios_map<StdString,long int> CObjectTemplate<T>::GenId; |
---|
| 26 | |
---|
| 27 | template <class T> |
---|
[219] | 28 | CObjectTemplate<T>::CObjectTemplate(void) |
---|
| 29 | : tree::CAttributeMap() |
---|
| 30 | , CObject() |
---|
| 31 | { /* Ne rien faire de plus */ } |
---|
| 32 | |
---|
| 33 | template <class T> |
---|
| 34 | CObjectTemplate<T>::CObjectTemplate(const StdString & id) |
---|
| 35 | : tree::CAttributeMap() |
---|
| 36 | , CObject(id) |
---|
| 37 | { /* Ne rien faire de plus */ } |
---|
| 38 | |
---|
| 39 | template <class T> |
---|
| 40 | CObjectTemplate<T>::CObjectTemplate |
---|
| 41 | (const CObjectTemplate<T> & object, bool withAttrList, bool withId) |
---|
| 42 | : tree::CAttributeMap() |
---|
| 43 | , CObject() |
---|
| 44 | { |
---|
| 45 | if (object.hasId() && withId) |
---|
| 46 | this->setId(object.getId()); |
---|
| 47 | ERROR("CObjectTemplate<T> construtor 3", << "Not completly implemented yet !"); |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | template <class T> |
---|
| 51 | CObjectTemplate<T>::~CObjectTemplate(void) |
---|
| 52 | { /* Ne rien faire de plus */ } |
---|
| 53 | |
---|
| 54 | ///-------------------------------------------------------------- |
---|
| 55 | |
---|
| 56 | template <class T> |
---|
| 57 | std::vector<boost::shared_ptr<T> > & |
---|
| 58 | CObjectTemplate<T>::GetAllVectobject(const StdString & contextId) |
---|
| 59 | { |
---|
| 60 | return (CObjectTemplate<T>::AllVectObj[contextId]); |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | //--------------------------------------------------------------- |
---|
| 64 | |
---|
| 65 | template <class T> |
---|
| 66 | StdString CObjectTemplate<T>::toString(void) const |
---|
| 67 | { |
---|
| 68 | StdOStringStream oss; |
---|
| 69 | oss << "<" << T::GetName(); |
---|
| 70 | if (this->hasId()) |
---|
| 71 | oss << " id=\"" << this->getId() << "\""; |
---|
| 72 | oss << " " << SuperClassMap::toString() << "/>"; |
---|
| 73 | return (oss.str()); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | template <class T> |
---|
| 77 | void CObjectTemplate<T>::fromString(const StdString & str) |
---|
| 78 | { |
---|
| 79 | ERROR("CObjectTemplate<T>::fromString(str)", |
---|
| 80 | << "[ str = " << str << "] Not implemented yet !"); |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | //--------------------------------------------------------------- |
---|
| 84 | |
---|
| 85 | template <class T> |
---|
| 86 | void CObjectTemplate<T>::toBinary(StdOStream & os) const |
---|
| 87 | { |
---|
| 88 | SuperClassMap::toBinary(os); |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | template <class T> |
---|
| 92 | void CObjectTemplate<T>::fromBinary(StdIStream & is) |
---|
| 93 | { |
---|
| 94 | SuperClassMap::fromBinary(is); |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | //--------------------------------------------------------------- |
---|
| 98 | |
---|
| 99 | template <class T> |
---|
| 100 | void CObjectTemplate<T>::parse(xml::CXMLNode & node) |
---|
| 101 | { |
---|
| 102 | xml::THashAttributes attributes = node.getAttributes(); |
---|
| 103 | CAttributeMap::setAttributes(attributes); |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | //--------------------------------------------------------------- |
---|
| 107 | |
---|
| 108 | template <class T> |
---|
| 109 | tree::ENodeType CObjectTemplate<T>::getType(void) const |
---|
| 110 | { |
---|
| 111 | return (T::GetType()); |
---|
| 112 | } |
---|
[313] | 113 | |
---|
| 114 | template <class T> |
---|
| 115 | string CObjectTemplate<T>::getName(void) const |
---|
| 116 | { |
---|
| 117 | return (T::GetName()); |
---|
| 118 | } |
---|
| 119 | |
---|
[219] | 120 | //--------------------------------------------------------------- |
---|
| 121 | |
---|
| 122 | template <class T> |
---|
| 123 | bool CObjectTemplate<T>::hasChild(void) const |
---|
| 124 | { |
---|
| 125 | return (false); |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | //--------------------------------------------------------------- |
---|
| 129 | |
---|
| 130 | template <class T> |
---|
| 131 | void CObjectTemplate<T>::solveDescInheritance(const CAttributeMap * const parent) |
---|
| 132 | { |
---|
| 133 | SuperClassMap::setAttributes(parent); |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | //--------------------------------------------------------------- |
---|
| 137 | |
---|
| 138 | template <class T> |
---|
| 139 | void CObjectTemplate<T>::ClearAllAttributes(void) |
---|
| 140 | { |
---|
| 141 | std::vector<boost::shared_ptr<T> > & avect = |
---|
| 142 | CObjectTemplate<T>::GetAllVectobject(CObjectFactory::GetCurrentContextId()); |
---|
| 143 | typename std::vector<boost::shared_ptr<T> >::iterator |
---|
| 144 | it = avect.begin(), end = avect.end(); |
---|
| 145 | |
---|
| 146 | for (;it != end; it++) |
---|
| 147 | { |
---|
| 148 | CAttributeMap & amap = **it; |
---|
| 149 | amap.clearAllAttributes(); |
---|
| 150 | } |
---|
| 151 | } |
---|
| 152 | |
---|
[300] | 153 | template <class T> |
---|
| 154 | void CObjectTemplate<T>::sendAttributToServer(const string& id) |
---|
| 155 | { |
---|
| 156 | CAttributeMap & attrMap = *this; |
---|
| 157 | CAttribute* attr=attrMap[id] ; |
---|
| 158 | sendAttributToServer(*attr) ; |
---|
| 159 | } |
---|
[219] | 160 | |
---|
[300] | 161 | template <class T> |
---|
| 162 | void CObjectTemplate<T>::sendAttributToServer(tree::CAttribute& attr) |
---|
| 163 | { |
---|
| 164 | shared_ptr<CContext> context=CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId()) ; |
---|
| 165 | |
---|
| 166 | if (!context->hasServer) |
---|
| 167 | { |
---|
| 168 | CContextClient* client=context->client ; |
---|
| 169 | |
---|
| 170 | CEventClient event(getType(),EVENT_ID_SEND_ATTRIBUTE) ; |
---|
| 171 | if (client->isServerLeader()) |
---|
| 172 | { |
---|
| 173 | CMessage msg ; |
---|
| 174 | msg<<this->getId() ; |
---|
| 175 | msg<<attr.getName() ; |
---|
| 176 | msg<<attr ; |
---|
| 177 | event.push(client->getServerLeader(),1,msg) ; |
---|
| 178 | client->sendEvent(event) ; |
---|
| 179 | } |
---|
| 180 | else client->sendEvent(event) ; |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | template <class T> |
---|
| 186 | void CObjectTemplate<T>::recvAttributFromClient(CEventServer& event) |
---|
| 187 | { |
---|
| 188 | |
---|
| 189 | CBufferIn* buffer=event.subEvents.begin()->buffer; |
---|
| 190 | string id,attrId; |
---|
| 191 | *buffer>>id ; |
---|
| 192 | CAttributeMap & attrMap = *get(id); |
---|
| 193 | *buffer>>attrId ; |
---|
| 194 | CAttribute* attr=attrMap[attrId] ; |
---|
| 195 | info(50)<<"attribut recu "<<attrId<<" " ; |
---|
| 196 | if (attr->isEmpty()) info(50)<<"--> empty"<<endl ; |
---|
| 197 | else info(50) /*<attr->getValue()*/<<endl ; |
---|
| 198 | *buffer>>*attr ; |
---|
| 199 | info(50)<<"attribut recu "<<attrId<<" " ; |
---|
| 200 | if (attr->isEmpty()) info(50)<<"--> empty"<<endl ; |
---|
| 201 | else info(50) /*attr->getValue()*/<<endl ; |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | template <class T> |
---|
| 205 | bool CObjectTemplate<T>::dispatchEvent(CEventServer& event) |
---|
| 206 | { |
---|
| 207 | switch(event.type) |
---|
| 208 | { |
---|
| 209 | case EVENT_ID_SEND_ATTRIBUTE : |
---|
| 210 | recvAttributFromClient(event) ; |
---|
| 211 | return true ; |
---|
| 212 | break ; |
---|
| 213 | |
---|
| 214 | default : |
---|
| 215 | return false ; |
---|
| 216 | // ERROR("void CObjectTemplate<T>::recvEvent(CEventServer& event)", |
---|
| 217 | // <<"Unknown Event") ; |
---|
| 218 | } |
---|
| 219 | } |
---|
| 220 | |
---|
| 221 | template <typename T> |
---|
| 222 | bool CObjectTemplate<T>::has(const string & id) |
---|
| 223 | { |
---|
| 224 | return CObjectFactory::HasObject<T>(id) ; |
---|
| 225 | } |
---|
| 226 | |
---|
| 227 | template <typename T> |
---|
| 228 | boost::shared_ptr<T> CObjectTemplate<T>::get(const string & id) |
---|
| 229 | { |
---|
| 230 | return CObjectFactory::GetObject<T>(id) ; |
---|
| 231 | } |
---|
| 232 | |
---|
| 233 | template <typename T> |
---|
| 234 | boost::shared_ptr<T> CObjectTemplate<T>::create(const string & id) |
---|
| 235 | { |
---|
| 236 | return CObjectFactory::CreateObject<T>(id) ; |
---|
| 237 | } ///-------------------------------------------------------------- |
---|
| 238 | |
---|
| 239 | template <typename T> |
---|
| 240 | boost::shared_ptr<T> CObjectTemplate<T>::get(void) |
---|
| 241 | { |
---|
| 242 | return CObjectFactory::GetObject<T>((T*)this) ; |
---|
| 243 | } |
---|
| 244 | |
---|
[313] | 245 | template <typename T> |
---|
| 246 | void CObjectTemplate<T>::generateCInterface(ostream& oss) |
---|
| 247 | { |
---|
| 248 | string className=getName() ; |
---|
| 249 | int found=className.find_first_of("_") ; |
---|
| 250 | if (found!=string::npos) className.replace(found,1,0,'x') ; |
---|
| 251 | |
---|
| 252 | oss<<"/* ************************************************************************** *"<<iendl ; |
---|
| 253 | oss<<" * Interface auto generated - do not modify *"<<iendl ; |
---|
| 254 | oss<<" * ************************************************************************** */"<<iendl; |
---|
| 255 | oss<<iendl ; |
---|
| 256 | oss<<"#include <boost/multi_array.hpp>"<<iendl ; |
---|
| 257 | oss<<"#include <boost/shared_ptr.hpp>"<<iendl ; |
---|
| 258 | oss<<"#include \"xmlioserver.hpp\""<<iendl; |
---|
| 259 | oss<<"#include \"attribute_template_impl.hpp\""<<iendl ; |
---|
| 260 | oss<<"#include \"object_template_impl.hpp\""<<iendl; |
---|
| 261 | oss<<"#include \"group_template_impl.hpp\""<<iendl ; |
---|
| 262 | oss<<"#include \"icutil.hpp\""<<iendl ; |
---|
| 263 | oss<<iendl ; |
---|
| 264 | oss<<"extern \"C\""<<iendl ; |
---|
| 265 | oss<<"{"<<iendl++ ; |
---|
| 266 | oss<<"typedef xmlioserver::tree::"<<getStrType<T>()<<"* "<<className<<"_Ptr;"<<iendl; |
---|
| 267 | oss<<iendl ; |
---|
| 268 | SuperClassMap::generateCInterface(oss,className) ; |
---|
| 269 | oss<<iendl-- ; |
---|
| 270 | oss<<"}"<<iendl ; |
---|
| 271 | } |
---|
[300] | 272 | |
---|
[313] | 273 | template <typename T> |
---|
| 274 | void CObjectTemplate<T>::generateFortran2003Interface(ostream& oss) |
---|
| 275 | { |
---|
| 276 | string className=getName() ; |
---|
| 277 | int found=className.find_first_of("_") ; |
---|
| 278 | if (found!=string::npos) className.replace(found,1,0,'x') ; |
---|
| 279 | |
---|
| 280 | oss<<"! * ************************************************************************** *"<<iendl ; |
---|
| 281 | oss<<"! * Interface auto generated - do not modify *"<<iendl ; |
---|
| 282 | oss<<"! * ************************************************************************** *"<<iendl; |
---|
| 283 | oss<<iendl ; |
---|
| 284 | oss<<"MODULE "<<className<<"_interface_attr"<<iendl++ ; |
---|
| 285 | oss<<"USE, INTRINSIC :: ISO_C_BINDING"<<iendl ; |
---|
| 286 | oss<<iendl ; |
---|
| 287 | oss<<"INTERFACE ! Do not call directly / interface FORTRAN 2003 <-> C99"<<iendl++ ; |
---|
| 288 | oss<<iendl ; |
---|
| 289 | oss<<iendl ; |
---|
| 290 | SuperClassMap::generateFortran2003Interface(oss,className) ; |
---|
| 291 | oss<<"END INTERFACE"<<iendl-- ; |
---|
| 292 | oss<<iendl-- ; |
---|
| 293 | oss<<"END MODULE "<<className<<"_interface_attr"<<iendl ; |
---|
| 294 | } |
---|
[300] | 295 | |
---|
[313] | 296 | template <typename T> |
---|
| 297 | void CObjectTemplate<T>::generateFortranInterface(ostream& oss) |
---|
| 298 | { |
---|
| 299 | string className=getName() ; |
---|
| 300 | int found=className.find_first_of('_') ; |
---|
| 301 | if (found!=string::npos) className.erase(found,1) ; |
---|
| 302 | string superClassName=getName(); |
---|
| 303 | found=superClassName.find("_group") ; |
---|
| 304 | if (found!=string::npos) superClassName.erase(found,6) ; |
---|
| 305 | |
---|
| 306 | oss<<"! * ************************************************************************** *"<<iendl ; |
---|
| 307 | oss<<"! * Interface auto generated - do not modify *"<<iendl ; |
---|
| 308 | oss<<"! * ************************************************************************** *"<<iendl; |
---|
| 309 | oss<<"#include \"xios_fortran_prefix.hpp\""<<iendl ; |
---|
| 310 | oss<<iendl ; |
---|
| 311 | oss<<"MODULE i"<<className<<"_attr"<<iendl++ ; |
---|
| 312 | oss<<"USE, INTRINSIC :: ISO_C_BINDING"<<iendl ; |
---|
| 313 | oss<<"USE i"<<superClassName<<iendl ; |
---|
| 314 | oss<<"USE "<<className<<"_interface_attr"<<iendl ; |
---|
| 315 | // oss<<"TYPE txios("<<className<<")"<<iendl ; |
---|
| 316 | // oss<<" INTEGER(kind = C_INTPTR_T) :: daddr"<<iendl ; |
---|
| 317 | // oss<<"END TYPE txios("<<className<<")"<<iendl ; |
---|
| 318 | oss<<iendl-- ; |
---|
| 319 | oss<<"CONTAINS"<<iendl++ ; |
---|
| 320 | oss<<iendl ; |
---|
| 321 | SuperClassMap::generateFortranInterface_id(oss,className) ; |
---|
| 322 | oss<<iendl ; |
---|
| 323 | SuperClassMap::generateFortranInterface_hdl(oss,className) ; |
---|
| 324 | oss<<iendl ; |
---|
| 325 | SuperClassMap::generateFortranInterface_hdl_(oss,className) ; |
---|
| 326 | oss<<iendl ; |
---|
| 327 | SuperClassMap::generateFortranInterfaceGet_id(oss,className) ; |
---|
| 328 | oss<<iendl ; |
---|
| 329 | SuperClassMap::generateFortranInterfaceGet_hdl(oss,className) ; |
---|
| 330 | oss<<iendl ; |
---|
| 331 | SuperClassMap::generateFortranInterfaceGet_hdl_(oss,className) ; |
---|
| 332 | oss<<iendl-- ; |
---|
| 333 | oss<<"END MODULE i"<<className<<"_attr"<<iendl ; |
---|
| 334 | } |
---|
| 335 | |
---|
| 336 | |
---|
[219] | 337 | } // namespace xmlioserver |
---|
| 338 | |
---|
| 339 | #endif // __XMLIO_CObjectTemplate_impl__ |
---|