[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, |
---|
[1601] | 26 | std::shared_ptr<T> > > *CObjectTemplate<T>::AllMapObj_ptr = 0; |
---|
[219] | 27 | |
---|
| 28 | template <class T> |
---|
| 29 | xios_map<StdString, |
---|
[1601] | 30 | std::vector<std::shared_ptr<T> > > *CObjectTemplate<T>::AllVectObj_ptr = 0; |
---|
[219] | 31 | |
---|
| 32 | template <class T> |
---|
[1601] | 33 | xios_map<StdString,long int> *CObjectTemplate<T>::GenId_ptr = 0; |
---|
[286] | 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 | { |
---|
[1601] | 68 | return (CObjectTemplate<T>::AllVectObj_ptr->at(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) |
---|
[1646] | 111 | TRY |
---|
[219] | 112 | { |
---|
| 113 | xml::THashAttributes attributes = node.getAttributes(); |
---|
| 114 | CAttributeMap::setAttributes(attributes); |
---|
| 115 | } |
---|
[1646] | 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 | |
---|
[219] | 159 | //--------------------------------------------------------------- |
---|
| 160 | |
---|
| 161 | template <class T> |
---|
[445] | 162 | void CObjectTemplate<T>::solveDescInheritance(bool apply, const CAttributeMap * const parent) |
---|
[509] | 163 | { |
---|
[549] | 164 | if (parent != NULL) |
---|
| 165 | SuperClassMap::setAttributes(parent, apply); |
---|
[219] | 166 | } |
---|
| 167 | |
---|
| 168 | //--------------------------------------------------------------- |
---|
| 169 | |
---|
| 170 | template <class T> |
---|
| 171 | void CObjectTemplate<T>::ClearAllAttributes(void) |
---|
| 172 | { |
---|
[549] | 173 | vector<T*> avect = CObjectTemplate<T>::getAll(); |
---|
[347] | 174 | typename vector<T*>::iterator |
---|
[219] | 175 | it = avect.begin(), end = avect.end(); |
---|
| 176 | |
---|
| 177 | for (;it != end; it++) |
---|
| 178 | { |
---|
| 179 | CAttributeMap & amap = **it; |
---|
| 180 | amap.clearAllAttributes(); |
---|
| 181 | } |
---|
| 182 | } |
---|
| 183 | |
---|
[509] | 184 | template<typename T> |
---|
[1330] | 185 | std::map<int, size_t> CObjectTemplate<T>::getMinimumBufferSizeForAttributes(CContextClient* client) |
---|
[731] | 186 | { |
---|
[1330] | 187 | std::map<int, size_t> minimumSizes; |
---|
| 188 | |
---|
| 189 | if (client->isServerLeader()) |
---|
[1009] | 190 | { |
---|
[1330] | 191 | size_t minimumSize = 0; |
---|
| 192 | CAttributeMap& attrMap = *this; |
---|
| 193 | CAttributeMap::const_iterator it = attrMap.begin(), itE = attrMap.end(); |
---|
| 194 | for (; it != itE; ++it) |
---|
[731] | 195 | { |
---|
[1330] | 196 | if (!it->second->isEmpty()) |
---|
[731] | 197 | { |
---|
[1330] | 198 | size_t size = it->second->getName().size() + sizeof(size_t) + it->second->size(); |
---|
| 199 | if (size > minimumSize) |
---|
| 200 | minimumSize = size; |
---|
[731] | 201 | } |
---|
[1330] | 202 | } |
---|
[731] | 203 | |
---|
[1330] | 204 | if (minimumSize) |
---|
| 205 | { |
---|
| 206 | // Account for extra header info |
---|
| 207 | minimumSize += CEventClient::headerSize + getIdServer().size() + sizeof(size_t); |
---|
[731] | 208 | |
---|
[1330] | 209 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 210 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 211 | minimumSizes.insert(std::make_pair(*itRank, minimumSize)); |
---|
[731] | 212 | } |
---|
[1009] | 213 | } |
---|
[1330] | 214 | return minimumSizes; |
---|
[731] | 215 | } |
---|
| 216 | |
---|
[1330] | 217 | |
---|
[731] | 218 | template<typename T> |
---|
[509] | 219 | void CObjectTemplate<T>::sendAllAttributesToServer() |
---|
| 220 | { |
---|
| 221 | CAttributeMap& attrMap = *this; |
---|
| 222 | CAttributeMap::const_iterator it = attrMap.begin(), itE = attrMap.end(); |
---|
| 223 | for (; it != itE; ++it) |
---|
| 224 | { |
---|
[1283] | 225 | if (it->second->doSend() && !(it->second)->isEmpty()) sendAttributToServer(*(it->second)); |
---|
[509] | 226 | } |
---|
| 227 | } |
---|
| 228 | |
---|
[1009] | 229 | template<typename T> |
---|
[1021] | 230 | void CObjectTemplate<T>::sendAllAttributesToServer(CContextClient* client) |
---|
[1009] | 231 | { |
---|
| 232 | CAttributeMap& attrMap = *this; |
---|
| 233 | CAttributeMap::const_iterator it = attrMap.begin(), itE = attrMap.end(); |
---|
| 234 | for (; it != itE; ++it) |
---|
| 235 | { |
---|
[1283] | 236 | if (it->second->doSend() && !(it->second)->isEmpty()) sendAttributToServer(*(it->second), client); |
---|
[1009] | 237 | } |
---|
| 238 | } |
---|
| 239 | |
---|
[300] | 240 | template <class T> |
---|
| 241 | void CObjectTemplate<T>::sendAttributToServer(const string& id) |
---|
| 242 | { |
---|
| 243 | CAttributeMap & attrMap = *this; |
---|
[549] | 244 | CAttribute* attr=attrMap[id]; |
---|
[1158] | 245 | sendAttributToServer(*attr); |
---|
[300] | 246 | } |
---|
[219] | 247 | |
---|
[1009] | 248 | template <class T> |
---|
[1021] | 249 | void CObjectTemplate<T>::sendAttributToServer(const string& id, CContextClient* client) |
---|
[1009] | 250 | { |
---|
| 251 | CAttributeMap & attrMap = *this; |
---|
| 252 | CAttribute* attr=attrMap[id]; |
---|
[1021] | 253 | sendAttributToServer(*attr, client); |
---|
[1009] | 254 | } |
---|
| 255 | |
---|
[347] | 256 | template <class T> |
---|
| 257 | void CObjectTemplate<T>::sendAttributToServer(CAttribute& attr) |
---|
| 258 | { |
---|
[1021] | 259 | // Use correct context client to send message |
---|
[549] | 260 | CContext* context=CContext::getCurrent(); |
---|
[987] | 261 | if (context->hasClient) |
---|
[300] | 262 | { |
---|
[1030] | 263 | // int nbSrvPools = (context->hasServer) ? context->clientPrimServer.size() : 1; |
---|
| 264 | int nbSrvPools = (context->hasServer) ? (context->hasClient ? context->clientPrimServer.size() : 0) : 1; |
---|
[1009] | 265 | for (int i = 0; i < nbSrvPools; ++i) |
---|
| 266 | { |
---|
| 267 | CContextClient* contextClientTmp = (context->hasServer) ? context->clientPrimServer[i] : context->client; |
---|
| 268 | CEventClient event(getType(),EVENT_ID_SEND_ATTRIBUTE); |
---|
| 269 | if (contextClientTmp->isServerLeader()) |
---|
| 270 | { |
---|
| 271 | CMessage msg; |
---|
[1021] | 272 | msg<<this->getIdServer(); |
---|
[1009] | 273 | msg << attr.getName(); |
---|
| 274 | msg << attr; |
---|
| 275 | const std::list<int>& ranks = contextClientTmp->getRanksServerLeader(); |
---|
| 276 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 277 | event.push(*itRank,1,msg); |
---|
| 278 | contextClientTmp->sendEvent(event); |
---|
| 279 | } |
---|
| 280 | else contextClientTmp->sendEvent(event); |
---|
| 281 | } |
---|
[300] | 282 | } |
---|
[347] | 283 | } |
---|
[509] | 284 | |
---|
[1009] | 285 | template <class T> |
---|
[1021] | 286 | void CObjectTemplate<T>::sendAttributToServer(CAttribute& attr, CContextClient* client) |
---|
[1009] | 287 | { |
---|
| 288 | CEventClient event(getType(),EVENT_ID_SEND_ATTRIBUTE); |
---|
[1021] | 289 | if (client->isServerLeader()) |
---|
[1009] | 290 | { |
---|
| 291 | CMessage msg; |
---|
| 292 | msg<<this->getIdServer(); |
---|
| 293 | msg << attr.getName(); |
---|
| 294 | msg << attr; |
---|
[1021] | 295 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
[1009] | 296 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 297 | event.push(*itRank,1,msg); |
---|
[1021] | 298 | client->sendEvent(event); |
---|
[1009] | 299 | } |
---|
[1021] | 300 | else client->sendEvent(event); |
---|
[1009] | 301 | } |
---|
| 302 | |
---|
[987] | 303 | /*! |
---|
| 304 | This generic funtion only provides instance for sending, for receving, each |
---|
| 305 | child class must define itself. |
---|
| 306 | \param [in] id Id of added item |
---|
| 307 | \param [in] itemType type of added item |
---|
| 308 | */ |
---|
| 309 | template<class T> |
---|
| 310 | void CObjectTemplate<T>::sendAddItem(const StdString& id, int itemType) |
---|
| 311 | { |
---|
| 312 | CContext* context = CContext::getCurrent(); |
---|
| 313 | typedef typename T::EEventId ItemType; |
---|
| 314 | if (context->hasClient) |
---|
| 315 | { |
---|
[1021] | 316 | // Use correct context client to send message |
---|
[1030] | 317 | // int nbSrvPools = (context->hasServer) ? context->clientPrimServer.size() : 1; |
---|
| 318 | int nbSrvPools = (context->hasServer) ? (context->hasClient ? context->clientPrimServer.size() : 0) : 1; |
---|
[1009] | 319 | for (int i = 0; i < nbSrvPools; ++i) |
---|
| 320 | { |
---|
| 321 | CContextClient* contextClientTmp = (context->hasServer) ? context->clientPrimServer[i] : context->client; |
---|
| 322 | CEventClient event(this->getType(),ItemType(itemType)); |
---|
| 323 | if (contextClientTmp->isServerLeader()) |
---|
| 324 | { |
---|
| 325 | CMessage msg; |
---|
| 326 | msg << this->getId(); |
---|
| 327 | msg << id; |
---|
| 328 | const std::list<int>& ranks = contextClientTmp->getRanksServerLeader(); |
---|
| 329 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 330 | event.push(*itRank,1,msg); |
---|
| 331 | contextClientTmp->sendEvent(event); |
---|
| 332 | } |
---|
| 333 | else contextClientTmp->sendEvent(event); |
---|
| 334 | } |
---|
[987] | 335 | } |
---|
| 336 | } |
---|
| 337 | |
---|
[1009] | 338 | template<class T> |
---|
[1021] | 339 | void CObjectTemplate<T>::sendAddItem(const StdString& id, int itemType, CContextClient* client) |
---|
[1009] | 340 | { |
---|
| 341 | typedef typename T::EEventId ItemType; |
---|
| 342 | CEventClient event(this->getType(),ItemType(itemType)); |
---|
[1021] | 343 | if (client->isServerLeader()) |
---|
[1009] | 344 | { |
---|
| 345 | CMessage msg; |
---|
| 346 | msg << this->getId(); |
---|
| 347 | msg << id; |
---|
[1021] | 348 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
[1009] | 349 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 350 | event.push(*itRank,1,msg); |
---|
[1021] | 351 | client->sendEvent(event); |
---|
[1009] | 352 | } |
---|
[1021] | 353 | else client->sendEvent(event); |
---|
[1009] | 354 | } |
---|
| 355 | |
---|
[347] | 356 | template <class T> |
---|
| 357 | void CObjectTemplate<T>::recvAttributFromClient(CEventServer& event) |
---|
| 358 | { |
---|
[509] | 359 | |
---|
[347] | 360 | CBufferIn* buffer=event.subEvents.begin()->buffer; |
---|
| 361 | string id,attrId; |
---|
[549] | 362 | *buffer>>id; |
---|
[347] | 363 | CAttributeMap & attrMap = *get(id); |
---|
[549] | 364 | *buffer>>attrId; |
---|
| 365 | CAttribute* attr=attrMap[attrId]; |
---|
[1646] | 366 | #pragma omp critical (_output) |
---|
| 367 | { |
---|
| 368 | info(50) << "attribut recu " << attrId << " "; |
---|
| 369 | } |
---|
| 370 | if (attr->isEmpty()) |
---|
| 371 | { |
---|
| 372 | #pragma omp critical (_output) |
---|
| 373 | { |
---|
| 374 | info(50) << "--> empty" << endl; |
---|
| 375 | } |
---|
| 376 | } |
---|
| 377 | else |
---|
| 378 | { |
---|
| 379 | #pragma omp critical (_output) |
---|
| 380 | { |
---|
| 381 | info(50) /*<attr->getValue()*/ << endl; |
---|
| 382 | } |
---|
| 383 | } |
---|
[549] | 384 | *buffer>>*attr; |
---|
[1646] | 385 | #pragma omp critical (_output) |
---|
| 386 | { |
---|
| 387 | info(50) << "attribut recu " << attrId << " "; |
---|
| 388 | } |
---|
| 389 | if (attr->isEmpty()) |
---|
| 390 | { |
---|
| 391 | #pragma omp critical (_output) |
---|
| 392 | { |
---|
| 393 | info(50) << "--> empty" << endl; |
---|
| 394 | } |
---|
| 395 | } |
---|
| 396 | else |
---|
| 397 | { |
---|
| 398 | #pragma omp critical (_output) |
---|
| 399 | { |
---|
| 400 | info(50) /*attr->getValue()*/ << endl; |
---|
| 401 | } |
---|
| 402 | } |
---|
[300] | 403 | } |
---|
| 404 | |
---|
| 405 | template <class T> |
---|
| 406 | bool CObjectTemplate<T>::dispatchEvent(CEventServer& event) |
---|
| 407 | { |
---|
| 408 | switch(event.type) |
---|
| 409 | { |
---|
| 410 | case EVENT_ID_SEND_ATTRIBUTE : |
---|
[549] | 411 | recvAttributFromClient(event); |
---|
| 412 | return true; |
---|
| 413 | break; |
---|
[509] | 414 | |
---|
[300] | 415 | default : |
---|
[549] | 416 | return false; |
---|
[581] | 417 | // ERROR("void CObjectTemplate<T>::recvEvent(CEventServer& event)", << "Unknown Event"); |
---|
[300] | 418 | } |
---|
| 419 | } |
---|
[509] | 420 | |
---|
[300] | 421 | template <typename T> |
---|
| 422 | bool CObjectTemplate<T>::has(const string & id) |
---|
| 423 | { |
---|
[549] | 424 | return CObjectFactory::HasObject<T>(id); |
---|
[300] | 425 | } |
---|
| 426 | |
---|
| 427 | template <typename T> |
---|
[346] | 428 | bool CObjectTemplate<T>::has(const string& contextId, const string & id) |
---|
| 429 | { |
---|
[549] | 430 | return CObjectFactory::HasObject<T>(contextId,id); |
---|
[346] | 431 | } |
---|
| 432 | |
---|
| 433 | template <typename T> |
---|
[347] | 434 | T* CObjectTemplate<T>::get(const string & id) |
---|
[300] | 435 | { |
---|
[549] | 436 | return CObjectFactory::GetObject<T>(id).get(); |
---|
[300] | 437 | } |
---|
| 438 | |
---|
| 439 | template <typename T> |
---|
[347] | 440 | T* CObjectTemplate<T>::get(const T* ptr) |
---|
[346] | 441 | { |
---|
[549] | 442 | return CObjectFactory::GetObject<T>(ptr).get(); |
---|
[347] | 443 | } |
---|
[509] | 444 | |
---|
[347] | 445 | template <typename T> |
---|
[1542] | 446 | std::shared_ptr<T> CObjectTemplate<T>::getShared(const T* ptr) |
---|
[347] | 447 | { |
---|
[549] | 448 | return CObjectFactory::GetObject<T>(ptr); |
---|
[346] | 449 | } |
---|
[347] | 450 | |
---|
| 451 | template <typename T> |
---|
[1542] | 452 | std::shared_ptr<T> CObjectTemplate<T>::getShared(void) |
---|
[347] | 453 | { |
---|
[549] | 454 | return CObjectFactory::GetObject<T>((T*)this); |
---|
[347] | 455 | } |
---|
[509] | 456 | |
---|
[346] | 457 | template <typename T> |
---|
[347] | 458 | const vector<T*> CObjectTemplate<T>::getAll() |
---|
[346] | 459 | { |
---|
[1628] | 460 | int mycheck = CObjectFactory::CheckObjectVector<T>(); |
---|
| 461 | if(mycheck==0) |
---|
| 462 | { |
---|
| 463 | vector<T*> vect; |
---|
| 464 | return vect; |
---|
| 465 | } |
---|
[1601] | 466 | const vector< std::shared_ptr<T> >& shared_vect= CObjectFactory::GetObjectVector<T>(CObjectFactory::GetCurrentContextId()); |
---|
[549] | 467 | vector<T*> vect; |
---|
[509] | 468 | |
---|
[1542] | 469 | typename vector<std::shared_ptr<T> >::const_iterator it; |
---|
[549] | 470 | for(it=shared_vect.begin();it!=shared_vect.end();++it) vect.push_back(it->get()); |
---|
| 471 | return vect; |
---|
[346] | 472 | } |
---|
| 473 | |
---|
| 474 | template <typename T> |
---|
[347] | 475 | const vector<T*> CObjectTemplate<T>::getAll(const string & id) |
---|
[346] | 476 | { |
---|
[1542] | 477 | const vector< std::shared_ptr<T> >& shared_vect= CObjectFactory::GetObjectVector<T>(id); |
---|
[549] | 478 | vector<T*> vect; |
---|
[509] | 479 | |
---|
[1542] | 480 | typename vector<std::shared_ptr<T> >::const_iterator it; |
---|
[549] | 481 | for(it=shared_vect.begin();it!=shared_vect.end();++it) vect.push_back(it->get()); |
---|
| 482 | return vect; |
---|
[346] | 483 | } |
---|
| 484 | |
---|
| 485 | template <typename T> |
---|
[347] | 486 | T* CObjectTemplate<T>::get(const string& contextId, const string & id) |
---|
[346] | 487 | { |
---|
[549] | 488 | return CObjectFactory::GetObject<T>(contextId,id).get(); |
---|
[346] | 489 | } |
---|
| 490 | |
---|
| 491 | template <typename T> |
---|
[347] | 492 | T* CObjectTemplate<T>::create(const string & id) |
---|
[300] | 493 | { |
---|
[549] | 494 | return CObjectFactory::CreateObject<T>(id).get(); |
---|
[300] | 495 | } ///-------------------------------------------------------------- |
---|
| 496 | |
---|
| 497 | template <typename T> |
---|
[347] | 498 | T* CObjectTemplate<T>::get(void) |
---|
[300] | 499 | { |
---|
[549] | 500 | return CObjectFactory::GetObject<T>((T*)this).get(); |
---|
[300] | 501 | } |
---|
[509] | 502 | |
---|
[313] | 503 | template <typename T> |
---|
| 504 | void CObjectTemplate<T>::generateCInterface(ostream& oss) |
---|
| 505 | { |
---|
[549] | 506 | string className=getName(); |
---|
| 507 | int found=className.rfind("_group"); |
---|
| 508 | if (found!=string::npos) className.replace(found,1,0,'x'); |
---|
[509] | 509 | |
---|
[581] | 510 | oss << "/* ************************************************************************** *" << iendl; |
---|
| 511 | oss << " * Interface auto generated - do not modify *" << iendl; |
---|
| 512 | oss << " * ************************************************************************** */" << iendl; |
---|
| 513 | oss << iendl; |
---|
| 514 | oss << "#include <boost/multi_array.hpp>" << iendl; |
---|
[591] | 515 | oss << "#include \"xios.hpp\"" << iendl; |
---|
[581] | 516 | oss << "#include \"attribute_template.hpp\"" << iendl; |
---|
| 517 | oss << "#include \"object_template.hpp\"" << iendl; |
---|
| 518 | oss << "#include \"group_template.hpp\"" << iendl; |
---|
| 519 | oss << "#include \"icutil.hpp\"" << iendl; |
---|
| 520 | oss << "#include \"icdate.hpp\"" << iendl; |
---|
| 521 | oss << "#include \"timer.hpp\"" << iendl; |
---|
| 522 | oss << "#include \"node_type.hpp\"" << iendl; |
---|
| 523 | oss << iendl; |
---|
| 524 | oss << "extern \"C\"" << iendl; |
---|
| 525 | oss << "{" << iendl++; |
---|
| 526 | oss << "typedef xios::" << getStrType<T>() << "* " << className << "_Ptr;"; |
---|
[549] | 527 | SuperClassMap::generateCInterface(oss,className); |
---|
[581] | 528 | oss << "}" << iendl--; |
---|
[313] | 529 | } |
---|
[300] | 530 | |
---|
[313] | 531 | template <typename T> |
---|
| 532 | void CObjectTemplate<T>::generateFortran2003Interface(ostream& oss) |
---|
| 533 | { |
---|
[549] | 534 | string className=getName(); |
---|
| 535 | int found=className.rfind("_group"); |
---|
| 536 | if (found!=string::npos) className.replace(found,1,0,'x'); |
---|
[509] | 537 | |
---|
[581] | 538 | oss << "! * ************************************************************************** *" << iendl; |
---|
| 539 | oss << "! * Interface auto generated - do not modify *" << iendl; |
---|
| 540 | oss << "! * ************************************************************************** *" << iendl; |
---|
| 541 | oss << "#include \"../fortran/xios_fortran_prefix.hpp\"" << iendl; |
---|
| 542 | oss << iendl; |
---|
| 543 | oss << "MODULE " << className << "_interface_attr" << iendl++; |
---|
| 544 | oss << "USE, INTRINSIC :: ISO_C_BINDING" << std::endl; |
---|
| 545 | oss << iendl; |
---|
| 546 | oss << "INTERFACE" << iendl++; |
---|
| 547 | oss << "! Do not call directly / interface FORTRAN 2003 <-> C99"; |
---|
[1646] | 548 | SuperClassMap::generateFortran2003Interface(oss, className); |
---|
[581] | 549 | oss << iendl--; |
---|
| 550 | oss << "END INTERFACE" << iendl--; |
---|
| 551 | oss << iendl; |
---|
| 552 | oss << "END MODULE " << className << "_interface_attr" << iendl; |
---|
[313] | 553 | } |
---|
[509] | 554 | |
---|
[313] | 555 | template <typename T> |
---|
| 556 | void CObjectTemplate<T>::generateFortranInterface(ostream& oss) |
---|
| 557 | { |
---|
[549] | 558 | string className=getName(); |
---|
| 559 | int found=className.rfind("_group"); |
---|
| 560 | if (found!=string::npos) className.erase(found,1); |
---|
[313] | 561 | string superClassName=getName(); |
---|
[549] | 562 | found=superClassName.find("_group"); |
---|
| 563 | if (found!=string::npos) superClassName.erase(found,6); |
---|
[509] | 564 | |
---|
[581] | 565 | oss << "! * ************************************************************************** *" << iendl; |
---|
| 566 | oss << "! * Interface auto generated - do not modify *" << iendl; |
---|
| 567 | oss << "! * ************************************************************************** *" << iendl; |
---|
| 568 | oss << "#include \"xios_fortran_prefix.hpp\"" << iendl; |
---|
| 569 | oss << iendl; |
---|
| 570 | oss << "MODULE i" << className << "_attr" << iendl++; |
---|
| 571 | oss << "USE, INTRINSIC :: ISO_C_BINDING" << iendl; |
---|
| 572 | oss << "USE i" << superClassName << iendl; |
---|
| 573 | oss << "USE " << className << "_interface_attr" << iendl--; |
---|
| 574 | // oss << "TYPE txios(" << className << ")" << iendl; |
---|
| 575 | // oss << " INTEGER(kind = C_INTPTR_T) :: daddr" << iendl; |
---|
| 576 | // oss << "END TYPE txios(" << className << ")" << iendl; |
---|
| 577 | oss << iendl; |
---|
| 578 | oss << "CONTAINS" << iendl; |
---|
| 579 | oss << iendl++; |
---|
[549] | 580 | SuperClassMap::generateFortranInterface_id(oss,className); |
---|
[581] | 581 | oss << iendl; |
---|
[549] | 582 | SuperClassMap::generateFortranInterface_hdl(oss,className); |
---|
[581] | 583 | oss << iendl; |
---|
[549] | 584 | SuperClassMap::generateFortranInterface_hdl_(oss,className); |
---|
[581] | 585 | oss << iendl; |
---|
[549] | 586 | SuperClassMap::generateFortranInterfaceGet_id(oss,className); |
---|
[581] | 587 | oss << iendl; |
---|
[549] | 588 | SuperClassMap::generateFortranInterfaceGet_hdl(oss,className); |
---|
[581] | 589 | oss << iendl; |
---|
[549] | 590 | SuperClassMap::generateFortranInterfaceGet_hdl_(oss,className); |
---|
[581] | 591 | oss << iendl; |
---|
[549] | 592 | SuperClassMap::generateFortranInterfaceIsDefined_id(oss,className); |
---|
[581] | 593 | oss << iendl; |
---|
[549] | 594 | SuperClassMap::generateFortranInterfaceIsDefined_hdl(oss,className); |
---|
[581] | 595 | oss << iendl; |
---|
[549] | 596 | SuperClassMap::generateFortranInterfaceIsDefined_hdl_(oss,className); |
---|
[581] | 597 | oss << iendl--; |
---|
| 598 | oss << "END MODULE i" << className << "_attr" << iendl; |
---|
[313] | 599 | } |
---|
[335] | 600 | } // namespace xios |
---|
[219] | 601 | |
---|
[591] | 602 | #endif // __XIOS_CObjectTemplate_impl__ |
---|