[591] | 1 | #ifndef __XIOS_CObjectTemplate_impl__ |
---|
| 2 | #define __XIOS_CObjectTemplate_impl__ |
---|
[219] | 3 | |
---|
[591] | 4 | #include "xios_spl.hpp" |
---|
[327] | 5 | #include "context_client.hpp" |
---|
[300] | 6 | #include "object_factory.hpp" |
---|
| 7 | #include "context.hpp" |
---|
| 8 | #include "buffer_in.hpp" |
---|
| 9 | #include "attribute.hpp" |
---|
| 10 | #include "event_client.hpp" |
---|
[327] | 11 | #include "object_template.hpp" |
---|
[300] | 12 | #include "context_client.hpp" |
---|
[327] | 13 | #include "indent.hpp" |
---|
| 14 | #include "type_util.hpp" |
---|
| 15 | #include "message.hpp" |
---|
| 16 | #include "type.hpp" |
---|
[352] | 17 | #include "type_util.hpp" |
---|
| 18 | #include "group_template.hpp" |
---|
[300] | 19 | |
---|
[335] | 20 | namespace xios |
---|
[219] | 21 | { |
---|
| 22 | /// ////////////////////// Définitions ////////////////////// /// |
---|
| 23 | template <class T> |
---|
| 24 | xios_map<StdString, |
---|
| 25 | xios_map<StdString, |
---|
[1542] | 26 | std::shared_ptr<T> > > CObjectTemplate<T>::AllMapObj; |
---|
[219] | 27 | |
---|
| 28 | template <class T> |
---|
| 29 | xios_map<StdString, |
---|
[1542] | 30 | std::vector<std::shared_ptr<T> > > CObjectTemplate<T>::AllVectObj; |
---|
[219] | 31 | |
---|
| 32 | template <class T> |
---|
[286] | 33 | xios_map<StdString,long int> CObjectTemplate<T>::GenId; |
---|
| 34 | |
---|
| 35 | template <class T> |
---|
[219] | 36 | CObjectTemplate<T>::CObjectTemplate(void) |
---|
[345] | 37 | : CAttributeMap() |
---|
[219] | 38 | , CObject() |
---|
| 39 | { /* Ne rien faire de plus */ } |
---|
| 40 | |
---|
| 41 | template <class T> |
---|
| 42 | CObjectTemplate<T>::CObjectTemplate(const StdString & id) |
---|
[345] | 43 | : CAttributeMap() |
---|
[769] | 44 | , CObject(id, CObjectFactory::IsGenUId<T>(id)) |
---|
[219] | 45 | { /* Ne rien faire de plus */ } |
---|
| 46 | |
---|
| 47 | template <class T> |
---|
| 48 | CObjectTemplate<T>::CObjectTemplate |
---|
| 49 | (const CObjectTemplate<T> & object, bool withAttrList, bool withId) |
---|
[345] | 50 | : CAttributeMap() |
---|
[219] | 51 | , CObject() |
---|
| 52 | { |
---|
| 53 | if (object.hasId() && withId) |
---|
[769] | 54 | this->setId(object.getId(), object.hasAutoGeneratedId()); |
---|
[219] | 55 | ERROR("CObjectTemplate<T> construtor 3", << "Not completly implemented yet !"); |
---|
| 56 | } |
---|
[509] | 57 | |
---|
[219] | 58 | template <class T> |
---|
| 59 | CObjectTemplate<T>::~CObjectTemplate(void) |
---|
| 60 | { /* Ne rien faire de plus */ } |
---|
| 61 | |
---|
| 62 | ///-------------------------------------------------------------- |
---|
| 63 | |
---|
| 64 | template <class T> |
---|
[1542] | 65 | std::vector<std::shared_ptr<T> > & |
---|
[219] | 66 | CObjectTemplate<T>::GetAllVectobject(const StdString & contextId) |
---|
[509] | 67 | { |
---|
| 68 | return (CObjectTemplate<T>::AllVectObj[contextId]); |
---|
[219] | 69 | } |
---|
[509] | 70 | |
---|
[219] | 71 | //--------------------------------------------------------------- |
---|
[509] | 72 | |
---|
[219] | 73 | template <class T> |
---|
| 74 | StdString CObjectTemplate<T>::toString(void) const |
---|
| 75 | { |
---|
| 76 | StdOStringStream oss; |
---|
| 77 | oss << "<" << T::GetName(); |
---|
| 78 | if (this->hasId()) |
---|
| 79 | oss << " id=\"" << this->getId() << "\""; |
---|
| 80 | oss << " " << SuperClassMap::toString() << "/>"; |
---|
| 81 | return (oss.str()); |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | template <class T> |
---|
| 85 | void CObjectTemplate<T>::fromString(const StdString & str) |
---|
[509] | 86 | { |
---|
[219] | 87 | ERROR("CObjectTemplate<T>::fromString(str)", |
---|
[509] | 88 | << "[ str = " << str << "] Not implemented yet !"); |
---|
[219] | 89 | } |
---|
[509] | 90 | |
---|
[219] | 91 | //--------------------------------------------------------------- |
---|
[369] | 92 | |
---|
[509] | 93 | /* |
---|
[219] | 94 | template <class T> |
---|
| 95 | void CObjectTemplate<T>::toBinary(StdOStream & os) const |
---|
| 96 | { |
---|
[509] | 97 | SuperClassMap::toBinary(os); |
---|
[219] | 98 | } |
---|
[509] | 99 | |
---|
[219] | 100 | template <class T> |
---|
| 101 | void CObjectTemplate<T>::fromBinary(StdIStream & is) |
---|
| 102 | { |
---|
[509] | 103 | SuperClassMap::fromBinary(is); |
---|
[219] | 104 | } |
---|
[369] | 105 | */ |
---|
| 106 | |
---|
[219] | 107 | //--------------------------------------------------------------- |
---|
| 108 | |
---|
| 109 | template <class T> |
---|
| 110 | void CObjectTemplate<T>::parse(xml::CXMLNode & node) |
---|
[1622] | 111 | TRY |
---|
[219] | 112 | { |
---|
| 113 | xml::THashAttributes attributes = node.getAttributes(); |
---|
| 114 | CAttributeMap::setAttributes(attributes); |
---|
| 115 | } |
---|
[1622] | 116 | CATCH |
---|
[219] | 117 | |
---|
| 118 | //--------------------------------------------------------------- |
---|
| 119 | |
---|
| 120 | template <class T> |
---|
[345] | 121 | ENodeType CObjectTemplate<T>::getType(void) const |
---|
[219] | 122 | { |
---|
| 123 | return (T::GetType()); |
---|
| 124 | } |
---|
[509] | 125 | |
---|
[313] | 126 | template <class T> |
---|
| 127 | string CObjectTemplate<T>::getName(void) const |
---|
| 128 | { |
---|
| 129 | return (T::GetName()); |
---|
| 130 | } |
---|
[509] | 131 | |
---|
[219] | 132 | //--------------------------------------------------------------- |
---|
| 133 | |
---|
| 134 | template <class T> |
---|
| 135 | bool CObjectTemplate<T>::hasChild(void) const |
---|
[509] | 136 | { |
---|
| 137 | return (false); |
---|
[219] | 138 | } |
---|
| 139 | |
---|
[1158] | 140 | /*! |
---|
| 141 | Compare two object of same type |
---|
| 142 | */ |
---|
| 143 | template <class T> |
---|
| 144 | bool CObjectTemplate<T>::isEqual(const string& id, const vector<StdString>& excludedAttrs) |
---|
| 145 | { |
---|
| 146 | T* obj = CObjectTemplate<T>::get(id); |
---|
| 147 | return this->isEqual(obj, excludedAttrs); |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | template <class T> |
---|
| 151 | bool CObjectTemplate<T>::isEqual(T* obj, const vector<StdString>& excludedAttrs) |
---|
| 152 | { |
---|
| 153 | |
---|
| 154 | CAttributeMap& attrMapThis = *this; |
---|
| 155 | CAttributeMap& attrMapObj = *obj; |
---|
| 156 | return (attrMapThis.isEqual(attrMapObj, excludedAttrs)); |
---|
| 157 | } |
---|
| 158 | |
---|
[2203] | 159 | // --------------------------------------------------------------- |
---|
| 160 | template <class T> |
---|
| 161 | void CObjectTemplate<T>::setInheritedId(T* obj) |
---|
| 162 | { |
---|
| 163 | if (!hasInheritedId_) |
---|
| 164 | { |
---|
| 165 | if (!(hasId() && !hasAutoGeneratedId())) |
---|
| 166 | if (obj->hasId() && !obj->hasAutoGeneratedId()) |
---|
| 167 | { |
---|
| 168 | hasInheritedId_=true ; |
---|
| 169 | inheritedId_=obj->getId() ; |
---|
| 170 | } |
---|
| 171 | } |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | template <class T> |
---|
| 175 | void CObjectTemplate<T>::setTemplateId(T* obj) |
---|
| 176 | { |
---|
| 177 | if (hasId() && !hasAutoGeneratedId()) |
---|
| 178 | { |
---|
| 179 | templateId_ = getId() ; |
---|
| 180 | hasTemplateId_ = true ; |
---|
| 181 | } |
---|
| 182 | else if (obj->hasId() && !obj->hasAutoGeneratedId()) |
---|
| 183 | { |
---|
| 184 | templateId_ = obj->getId() ; |
---|
| 185 | hasTemplateId_ = true ; |
---|
| 186 | } |
---|
| 187 | else if (obj->hasTemplateId()) |
---|
| 188 | { |
---|
| 189 | templateId_= obj->getTemplateId() ; |
---|
| 190 | hasTemplateId_=true ; |
---|
| 191 | } |
---|
| 192 | } |
---|
| 193 | |
---|
| 194 | |
---|
[219] | 195 | //--------------------------------------------------------------- |
---|
| 196 | |
---|
| 197 | template <class T> |
---|
[445] | 198 | void CObjectTemplate<T>::solveDescInheritance(bool apply, const CAttributeMap * const parent) |
---|
[509] | 199 | { |
---|
[549] | 200 | if (parent != NULL) |
---|
| 201 | SuperClassMap::setAttributes(parent, apply); |
---|
[219] | 202 | } |
---|
| 203 | |
---|
| 204 | //--------------------------------------------------------------- |
---|
| 205 | |
---|
| 206 | template <class T> |
---|
| 207 | void CObjectTemplate<T>::ClearAllAttributes(void) |
---|
| 208 | { |
---|
[549] | 209 | vector<T*> avect = CObjectTemplate<T>::getAll(); |
---|
[347] | 210 | typename vector<T*>::iterator |
---|
[219] | 211 | it = avect.begin(), end = avect.end(); |
---|
| 212 | |
---|
| 213 | for (;it != end; it++) |
---|
| 214 | { |
---|
| 215 | CAttributeMap & amap = **it; |
---|
| 216 | amap.clearAllAttributes(); |
---|
| 217 | } |
---|
| 218 | } |
---|
| 219 | |
---|
[509] | 220 | template<typename T> |
---|
[1330] | 221 | std::map<int, size_t> CObjectTemplate<T>::getMinimumBufferSizeForAttributes(CContextClient* client) |
---|
[731] | 222 | { |
---|
[1330] | 223 | std::map<int, size_t> minimumSizes; |
---|
| 224 | |
---|
| 225 | if (client->isServerLeader()) |
---|
[1009] | 226 | { |
---|
[1330] | 227 | size_t minimumSize = 0; |
---|
| 228 | CAttributeMap& attrMap = *this; |
---|
| 229 | CAttributeMap::const_iterator it = attrMap.begin(), itE = attrMap.end(); |
---|
| 230 | for (; it != itE; ++it) |
---|
[731] | 231 | { |
---|
[1330] | 232 | if (!it->second->isEmpty()) |
---|
[731] | 233 | { |
---|
[1330] | 234 | size_t size = it->second->getName().size() + sizeof(size_t) + it->second->size(); |
---|
| 235 | if (size > minimumSize) |
---|
| 236 | minimumSize = size; |
---|
[731] | 237 | } |
---|
[1330] | 238 | } |
---|
[731] | 239 | |
---|
[1330] | 240 | if (minimumSize) |
---|
| 241 | { |
---|
| 242 | // Account for extra header info |
---|
[1848] | 243 | minimumSize += CEventClient::headerSize + getId().size() + sizeof(size_t); |
---|
[731] | 244 | |
---|
[1330] | 245 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 246 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 247 | minimumSizes.insert(std::make_pair(*itRank, minimumSize)); |
---|
[731] | 248 | } |
---|
[1009] | 249 | } |
---|
[1330] | 250 | return minimumSizes; |
---|
[731] | 251 | } |
---|
| 252 | |
---|
| 253 | template<typename T> |
---|
[1875] | 254 | void CObjectTemplate<T>::sendAllAttributesToServer(CContextClient* client, const string& objectId) |
---|
[1009] | 255 | { |
---|
| 256 | CAttributeMap& attrMap = *this; |
---|
| 257 | CAttributeMap::const_iterator it = attrMap.begin(), itE = attrMap.end(); |
---|
| 258 | for (; it != itE; ++it) |
---|
| 259 | { |
---|
[1875] | 260 | if (it->second->doSend() && !(it->second)->isEmpty()) sendAttributToServer(*(it->second), client, objectId); |
---|
[1009] | 261 | } |
---|
| 262 | } |
---|
| 263 | |
---|
[300] | 264 | template <class T> |
---|
[1875] | 265 | void CObjectTemplate<T>::sendAttributToServer(const string& id, CContextClient* client, const string& objectId ) |
---|
[1009] | 266 | { |
---|
| 267 | CAttributeMap & attrMap = *this; |
---|
| 268 | CAttribute* attr=attrMap[id]; |
---|
[1021] | 269 | sendAttributToServer(*attr, client); |
---|
[1009] | 270 | } |
---|
| 271 | |
---|
[347] | 272 | template <class T> |
---|
[1875] | 273 | void CObjectTemplate<T>::sendAttributToServer(CAttribute& attr, CContextClient* client, const string& objectId) |
---|
[1009] | 274 | { |
---|
| 275 | CEventClient event(getType(),EVENT_ID_SEND_ATTRIBUTE); |
---|
[1021] | 276 | if (client->isServerLeader()) |
---|
[1009] | 277 | { |
---|
| 278 | CMessage msg; |
---|
[1875] | 279 | if (objectId.empty()) msg << this->getId(); |
---|
| 280 | else msg << objectId; |
---|
[1009] | 281 | msg << attr.getName(); |
---|
| 282 | msg << attr; |
---|
[1021] | 283 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
[1009] | 284 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 285 | event.push(*itRank,1,msg); |
---|
[1021] | 286 | client->sendEvent(event); |
---|
[1009] | 287 | } |
---|
[1021] | 288 | else client->sendEvent(event); |
---|
[1009] | 289 | } |
---|
| 290 | |
---|
[1848] | 291 | /* specialisation for context, because context Id on client is not the same on server, and no need to transfer context Id */ |
---|
| 292 | template <> |
---|
[1875] | 293 | void CObjectTemplate<CContext>::sendAttributToServer(CAttribute& attr, CContextClient* client, const string& objectId) |
---|
[1848] | 294 | { |
---|
| 295 | CEventClient event(getType(),EVENT_ID_SEND_ATTRIBUTE); |
---|
| 296 | if (client->isServerLeader()) |
---|
| 297 | { |
---|
| 298 | CMessage msg; |
---|
| 299 | msg << attr.getName(); |
---|
| 300 | msg << attr; |
---|
| 301 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 302 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 303 | event.push(*itRank,1,msg); |
---|
| 304 | client->sendEvent(event); |
---|
| 305 | } |
---|
| 306 | else client->sendEvent(event); |
---|
| 307 | } |
---|
| 308 | |
---|
[987] | 309 | /*! |
---|
| 310 | This generic funtion only provides instance for sending, for receving, each |
---|
| 311 | child class must define itself. |
---|
| 312 | \param [in] id Id of added item |
---|
| 313 | \param [in] itemType type of added item |
---|
| 314 | */ |
---|
| 315 | |
---|
[1009] | 316 | template<class T> |
---|
[1875] | 317 | void CObjectTemplate<T>::sendAddItem(const StdString& id, int itemType, CContextClient* client, const string& objectId) |
---|
[1009] | 318 | { |
---|
| 319 | typedef typename T::EEventId ItemType; |
---|
| 320 | CEventClient event(this->getType(),ItemType(itemType)); |
---|
[1021] | 321 | if (client->isServerLeader()) |
---|
[1009] | 322 | { |
---|
| 323 | CMessage msg; |
---|
[1875] | 324 | if (objectId.empty()) msg << this->getId(); |
---|
| 325 | else msg << objectId; |
---|
[1009] | 326 | msg << id; |
---|
[1021] | 327 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
[1009] | 328 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 329 | event.push(*itRank,1,msg); |
---|
[1021] | 330 | client->sendEvent(event); |
---|
[1009] | 331 | } |
---|
[1021] | 332 | else client->sendEvent(event); |
---|
[1009] | 333 | } |
---|
| 334 | |
---|
[347] | 335 | template <class T> |
---|
| 336 | void CObjectTemplate<T>::recvAttributFromClient(CEventServer& event) |
---|
| 337 | { |
---|
[509] | 338 | |
---|
[347] | 339 | CBufferIn* buffer=event.subEvents.begin()->buffer; |
---|
| 340 | string id,attrId; |
---|
[549] | 341 | *buffer>>id; |
---|
[347] | 342 | CAttributeMap & attrMap = *get(id); |
---|
[549] | 343 | *buffer>>attrId; |
---|
| 344 | CAttribute* attr=attrMap[attrId]; |
---|
[581] | 345 | info(50) << "attribut recu " << attrId << " "; |
---|
| 346 | if (attr->isEmpty()) info(50) << "--> empty" << endl; |
---|
| 347 | else info(50) /*<attr->getValue()*/ << endl; |
---|
[549] | 348 | *buffer>>*attr; |
---|
[581] | 349 | info(50) << "attribut recu " << attrId << " "; |
---|
| 350 | if (attr->isEmpty()) info(50) << "--> empty" << endl; |
---|
| 351 | else info(50) /*attr->getValue()*/ << endl; |
---|
[300] | 352 | } |
---|
| 353 | |
---|
[1848] | 354 | /* specialisation for context, because context Id on client is not the same on server and no need to transfer context Id */ |
---|
| 355 | template <> |
---|
| 356 | void CObjectTemplate<CContext>::recvAttributFromClient(CEventServer& event) |
---|
| 357 | { |
---|
| 358 | |
---|
| 359 | CBufferIn* buffer=event.subEvents.begin()->buffer; |
---|
| 360 | string attrId; |
---|
| 361 | CAttributeMap & attrMap = *CContext::getCurrent(); |
---|
| 362 | *buffer>>attrId; |
---|
| 363 | CAttribute* attr=attrMap[attrId]; |
---|
| 364 | info(50) << "attribut recu " << attrId << " "; |
---|
| 365 | if (attr->isEmpty()) info(50) << "--> empty" << endl; |
---|
| 366 | else info(50) /*<attr->getValue()*/ << endl; |
---|
| 367 | *buffer>>*attr; |
---|
| 368 | info(50) << "attribut recu " << attrId << " "; |
---|
| 369 | if (attr->isEmpty()) info(50) << "--> empty" << endl; |
---|
| 370 | else info(50) /*attr->getValue()*/ << endl; |
---|
| 371 | } |
---|
| 372 | |
---|
| 373 | |
---|
[300] | 374 | template <class T> |
---|
| 375 | bool CObjectTemplate<T>::dispatchEvent(CEventServer& event) |
---|
| 376 | { |
---|
| 377 | switch(event.type) |
---|
| 378 | { |
---|
| 379 | case EVENT_ID_SEND_ATTRIBUTE : |
---|
[549] | 380 | recvAttributFromClient(event); |
---|
| 381 | return true; |
---|
| 382 | break; |
---|
[509] | 383 | |
---|
[300] | 384 | default : |
---|
[549] | 385 | return false; |
---|
[581] | 386 | // ERROR("void CObjectTemplate<T>::recvEvent(CEventServer& event)", << "Unknown Event"); |
---|
[300] | 387 | } |
---|
| 388 | } |
---|
[509] | 389 | |
---|
[300] | 390 | template <typename T> |
---|
| 391 | bool CObjectTemplate<T>::has(const string & id) |
---|
| 392 | { |
---|
[549] | 393 | return CObjectFactory::HasObject<T>(id); |
---|
[300] | 394 | } |
---|
| 395 | |
---|
| 396 | template <typename T> |
---|
[346] | 397 | bool CObjectTemplate<T>::has(const string& contextId, const string & id) |
---|
| 398 | { |
---|
[549] | 399 | return CObjectFactory::HasObject<T>(contextId,id); |
---|
[346] | 400 | } |
---|
| 401 | |
---|
| 402 | template <typename T> |
---|
[347] | 403 | T* CObjectTemplate<T>::get(const string & id) |
---|
[300] | 404 | { |
---|
[549] | 405 | return CObjectFactory::GetObject<T>(id).get(); |
---|
[300] | 406 | } |
---|
| 407 | |
---|
| 408 | template <typename T> |
---|
[347] | 409 | T* CObjectTemplate<T>::get(const T* ptr) |
---|
[346] | 410 | { |
---|
[549] | 411 | return CObjectFactory::GetObject<T>(ptr).get(); |
---|
[347] | 412 | } |
---|
[509] | 413 | |
---|
[347] | 414 | template <typename T> |
---|
[1542] | 415 | std::shared_ptr<T> CObjectTemplate<T>::getShared(const T* ptr) |
---|
[347] | 416 | { |
---|
[549] | 417 | return CObjectFactory::GetObject<T>(ptr); |
---|
[346] | 418 | } |
---|
[347] | 419 | |
---|
| 420 | template <typename T> |
---|
[1542] | 421 | std::shared_ptr<T> CObjectTemplate<T>::getShared(void) |
---|
[347] | 422 | { |
---|
[549] | 423 | return CObjectFactory::GetObject<T>((T*)this); |
---|
[347] | 424 | } |
---|
[509] | 425 | |
---|
[346] | 426 | template <typename T> |
---|
[347] | 427 | const vector<T*> CObjectTemplate<T>::getAll() |
---|
[346] | 428 | { |
---|
[1542] | 429 | const vector< std::shared_ptr<T> >& shared_vect= CObjectFactory::GetObjectVector<T>(); |
---|
[549] | 430 | vector<T*> vect; |
---|
[509] | 431 | |
---|
[1542] | 432 | typename vector<std::shared_ptr<T> >::const_iterator it; |
---|
[549] | 433 | for(it=shared_vect.begin();it!=shared_vect.end();++it) vect.push_back(it->get()); |
---|
| 434 | return vect; |
---|
[346] | 435 | } |
---|
| 436 | |
---|
| 437 | template <typename T> |
---|
[347] | 438 | const vector<T*> CObjectTemplate<T>::getAll(const string & id) |
---|
[346] | 439 | { |
---|
[1542] | 440 | const vector< std::shared_ptr<T> >& shared_vect= CObjectFactory::GetObjectVector<T>(id); |
---|
[549] | 441 | vector<T*> vect; |
---|
[509] | 442 | |
---|
[1542] | 443 | typename vector<std::shared_ptr<T> >::const_iterator it; |
---|
[549] | 444 | for(it=shared_vect.begin();it!=shared_vect.end();++it) vect.push_back(it->get()); |
---|
| 445 | return vect; |
---|
[346] | 446 | } |
---|
| 447 | |
---|
| 448 | template <typename T> |
---|
[347] | 449 | T* CObjectTemplate<T>::get(const string& contextId, const string & id) |
---|
[346] | 450 | { |
---|
[549] | 451 | return CObjectFactory::GetObject<T>(contextId,id).get(); |
---|
[346] | 452 | } |
---|
| 453 | |
---|
| 454 | template <typename T> |
---|
[347] | 455 | T* CObjectTemplate<T>::create(const string & id) |
---|
[300] | 456 | { |
---|
[549] | 457 | return CObjectFactory::CreateObject<T>(id).get(); |
---|
[300] | 458 | } ///-------------------------------------------------------------- |
---|
| 459 | |
---|
[1869] | 460 | template <typename T> |
---|
| 461 | T* CObjectTemplate<T>::createAlias(const string & id, const string& alias) |
---|
| 462 | { |
---|
| 463 | return CObjectFactory::CreateAlias<T>(id, alias).get(); |
---|
| 464 | } ///-------------------------------------------------------------- |
---|
| 465 | |
---|
| 466 | template <typename T> |
---|
| 467 | void CObjectTemplate<T>::createAlias(const string& alias) |
---|
| 468 | { |
---|
| 469 | get()->createAlias(getId(),alias) ; |
---|
| 470 | } // |
---|
| 471 | |
---|
[300] | 472 | template <typename T> |
---|
[347] | 473 | T* CObjectTemplate<T>::get(void) |
---|
[300] | 474 | { |
---|
[549] | 475 | return CObjectFactory::GetObject<T>((T*)this).get(); |
---|
[300] | 476 | } |
---|
[509] | 477 | |
---|
[313] | 478 | template <typename T> |
---|
| 479 | void CObjectTemplate<T>::generateCInterface(ostream& oss) |
---|
| 480 | { |
---|
[549] | 481 | string className=getName(); |
---|
| 482 | int found=className.rfind("_group"); |
---|
| 483 | if (found!=string::npos) className.replace(found,1,0,'x'); |
---|
[509] | 484 | |
---|
[581] | 485 | oss << "/* ************************************************************************** *" << iendl; |
---|
| 486 | oss << " * Interface auto generated - do not modify *" << iendl; |
---|
| 487 | oss << " * ************************************************************************** */" << iendl; |
---|
| 488 | oss << iendl; |
---|
| 489 | oss << "#include <boost/multi_array.hpp>" << iendl; |
---|
[591] | 490 | oss << "#include \"xios.hpp\"" << iendl; |
---|
[581] | 491 | oss << "#include \"attribute_template.hpp\"" << iendl; |
---|
| 492 | oss << "#include \"object_template.hpp\"" << iendl; |
---|
| 493 | oss << "#include \"group_template.hpp\"" << iendl; |
---|
| 494 | oss << "#include \"icutil.hpp\"" << iendl; |
---|
| 495 | oss << "#include \"icdate.hpp\"" << iendl; |
---|
| 496 | oss << "#include \"timer.hpp\"" << iendl; |
---|
| 497 | oss << "#include \"node_type.hpp\"" << iendl; |
---|
| 498 | oss << iendl; |
---|
| 499 | oss << "extern \"C\"" << iendl; |
---|
| 500 | oss << "{" << iendl++; |
---|
| 501 | oss << "typedef xios::" << getStrType<T>() << "* " << className << "_Ptr;"; |
---|
[549] | 502 | SuperClassMap::generateCInterface(oss,className); |
---|
[581] | 503 | oss << "}" << iendl--; |
---|
[313] | 504 | } |
---|
[300] | 505 | |
---|
[313] | 506 | template <typename T> |
---|
| 507 | void CObjectTemplate<T>::generateFortran2003Interface(ostream& oss) |
---|
| 508 | { |
---|
[549] | 509 | string className=getName(); |
---|
| 510 | int found=className.rfind("_group"); |
---|
| 511 | if (found!=string::npos) className.replace(found,1,0,'x'); |
---|
[509] | 512 | |
---|
[581] | 513 | oss << "! * ************************************************************************** *" << iendl; |
---|
| 514 | oss << "! * Interface auto generated - do not modify *" << iendl; |
---|
| 515 | oss << "! * ************************************************************************** *" << iendl; |
---|
| 516 | oss << "#include \"../fortran/xios_fortran_prefix.hpp\"" << iendl; |
---|
| 517 | oss << iendl; |
---|
| 518 | oss << "MODULE " << className << "_interface_attr" << iendl++; |
---|
| 519 | oss << "USE, INTRINSIC :: ISO_C_BINDING" << std::endl; |
---|
| 520 | oss << iendl; |
---|
| 521 | oss << "INTERFACE" << iendl++; |
---|
| 522 | oss << "! Do not call directly / interface FORTRAN 2003 <-> C99"; |
---|
[1626] | 523 | SuperClassMap::generateFortran2003Interface(oss, className); |
---|
[581] | 524 | oss << iendl--; |
---|
| 525 | oss << "END INTERFACE" << iendl--; |
---|
| 526 | oss << iendl; |
---|
| 527 | oss << "END MODULE " << className << "_interface_attr" << iendl; |
---|
[313] | 528 | } |
---|
[509] | 529 | |
---|
[313] | 530 | template <typename T> |
---|
| 531 | void CObjectTemplate<T>::generateFortranInterface(ostream& oss) |
---|
| 532 | { |
---|
[549] | 533 | string className=getName(); |
---|
| 534 | int found=className.rfind("_group"); |
---|
| 535 | if (found!=string::npos) className.erase(found,1); |
---|
[313] | 536 | string superClassName=getName(); |
---|
[549] | 537 | found=superClassName.find("_group"); |
---|
| 538 | if (found!=string::npos) superClassName.erase(found,6); |
---|
[509] | 539 | |
---|
[581] | 540 | oss << "! * ************************************************************************** *" << iendl; |
---|
| 541 | oss << "! * Interface auto generated - do not modify *" << iendl; |
---|
| 542 | oss << "! * ************************************************************************** *" << iendl; |
---|
| 543 | oss << "#include \"xios_fortran_prefix.hpp\"" << iendl; |
---|
| 544 | oss << iendl; |
---|
| 545 | oss << "MODULE i" << className << "_attr" << iendl++; |
---|
| 546 | oss << "USE, INTRINSIC :: ISO_C_BINDING" << iendl; |
---|
| 547 | oss << "USE i" << superClassName << iendl; |
---|
| 548 | oss << "USE " << className << "_interface_attr" << iendl--; |
---|
| 549 | // oss << "TYPE txios(" << className << ")" << iendl; |
---|
| 550 | // oss << " INTEGER(kind = C_INTPTR_T) :: daddr" << iendl; |
---|
| 551 | // oss << "END TYPE txios(" << className << ")" << iendl; |
---|
| 552 | oss << iendl; |
---|
| 553 | oss << "CONTAINS" << iendl; |
---|
| 554 | oss << iendl++; |
---|
[549] | 555 | SuperClassMap::generateFortranInterface_id(oss,className); |
---|
[581] | 556 | oss << iendl; |
---|
[549] | 557 | SuperClassMap::generateFortranInterface_hdl(oss,className); |
---|
[581] | 558 | oss << iendl; |
---|
[549] | 559 | SuperClassMap::generateFortranInterface_hdl_(oss,className); |
---|
[581] | 560 | oss << iendl; |
---|
[549] | 561 | SuperClassMap::generateFortranInterfaceGet_id(oss,className); |
---|
[581] | 562 | oss << iendl; |
---|
[549] | 563 | SuperClassMap::generateFortranInterfaceGet_hdl(oss,className); |
---|
[581] | 564 | oss << iendl; |
---|
[549] | 565 | SuperClassMap::generateFortranInterfaceGet_hdl_(oss,className); |
---|
[581] | 566 | oss << iendl; |
---|
[549] | 567 | SuperClassMap::generateFortranInterfaceIsDefined_id(oss,className); |
---|
[581] | 568 | oss << iendl; |
---|
[549] | 569 | SuperClassMap::generateFortranInterfaceIsDefined_hdl(oss,className); |
---|
[581] | 570 | oss << iendl; |
---|
[549] | 571 | SuperClassMap::generateFortranInterfaceIsDefined_hdl_(oss,className); |
---|
[581] | 572 | oss << iendl--; |
---|
| 573 | oss << "END MODULE i" << className << "_attr" << iendl; |
---|
[313] | 574 | } |
---|
[335] | 575 | } // namespace xios |
---|
[219] | 576 | |
---|
[591] | 577 | #endif // __XIOS_CObjectTemplate_impl__ |
---|