Ignore:
Timestamp:
11/19/18 15:52:54 (5 years ago)
Author:
yushan
Message:

branch_openmp merged with trunk r1597

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/dev/dev_trunk_omp/src/object_factory_impl.hpp

    r1542 r1601  
    1010       int CObjectFactory::GetObjectNum(void) 
    1111   { 
    12       if (CurrContext.size() == 0) 
     12      if (CurrContext_ptr->size() == 0) 
    1313         ERROR("CObjectFactory::GetObjectNum(void)", 
    1414               << "please define current context id !"); 
    15       return (U::AllVectObj[CObjectFactory::CurrContext].size()); 
     15      if(U::AllVectObj_ptr == NULL) return 0; 
     16      return (*U::AllVectObj_ptr)[*CObjectFactory::CurrContext_ptr].size(); 
    1617   } 
    1718 
     
    1920      int CObjectFactory::GetObjectIdNum(void) 
    2021   { 
    21       if (CurrContext.size() == 0) 
     22      if (CurrContext_ptr->size() == 0) 
    2223         ERROR("CObjectFactory::GetObjectIdNum(void)", 
    2324               << "please define current context id !"); 
    24       return (U::AllMapObj[CObjectFactory::CurrContext].size()); 
     25      if(U::AllMapObj_ptr == NULL) return 0; 
     26      return (*U::AllMapObj_ptr)[*CObjectFactory::CurrContext_ptr].size(); 
    2527   } 
    2628 
     
    2830      bool CObjectFactory::HasObject(const StdString & id) 
    2931   { 
    30       if (CurrContext.size() == 0) 
     32      if (CurrContext_ptr->size() == 0) 
    3133         ERROR("CObjectFactory::HasObject(const StdString & id)", 
    3234               << "[ id = " << id << " ] please define current context id !"); 
    33       return (U::AllMapObj[CObjectFactory::CurrContext].find(id) != 
    34               U::AllMapObj[CObjectFactory::CurrContext].end()); 
     35      if(U::AllMapObj_ptr  == NULL)  return false; 
     36      return ((*U::AllMapObj_ptr)[*CObjectFactory::CurrContext_ptr].find(id) != 
     37              (*U::AllMapObj_ptr)[*CObjectFactory::CurrContext_ptr].end()); 
     38 
    3539   } 
    3640 
     
    3842      bool CObjectFactory::HasObject(const StdString & context, const StdString & id) 
    3943   { 
    40       if (U::AllMapObj.find(context) == U::AllMapObj.end()) return false ; 
    41       else return (U::AllMapObj[context].find(id) !=  U::AllMapObj[context].end()); 
     44      if(U::AllMapObj_ptr  == NULL) return false; 
     45 
     46      if (U::AllMapObj_ptr->find(context) == U::AllMapObj_ptr->end()) return false ; 
     47      else return ((*U::AllMapObj_ptr)[context].find(id) !=  (*U::AllMapObj_ptr)[context].end()); 
    4248   } 
    4349 
     
    4551      std::shared_ptr<U> CObjectFactory::GetObject(const U * const object) 
    4652   { 
    47       if (CurrContext.size() == 0) 
     53      if(U::AllVectObj_ptr == NULL) return (std::shared_ptr<U>()); 
     54      if (CurrContext_ptr->size() == 0) 
    4855         ERROR("CObjectFactory::GetObject(const U * const object)", 
    4956               << "please define current context id !"); 
    50       std::vector<std::shared_ptr<U> > & vect = 
    51                      U::AllVectObj[CObjectFactory::CurrContext]; 
     57      std::vector<std::shared_ptr<U> > & vect = (*U::AllVectObj_ptr)[*CObjectFactory::CurrContext_ptr]; 
    5258 
    5359      typename std::vector<std::shared_ptr<U> >::const_iterator 
     
    7076      std::shared_ptr<U> CObjectFactory::GetObject(const StdString & id) 
    7177   { 
    72       if (CurrContext.size() == 0) 
     78      if(U::AllMapObj_ptr  == NULL) return (std::shared_ptr<U>()); 
     79      if (CurrContext_ptr->size() == 0) 
    7380         ERROR("CObjectFactory::GetObject(const StdString & id)", 
    7481               << "[ id = " << id << " ] please define current context id !"); 
     
    7784               << "[ id = " << id << ", U = " << U::GetName() << " ] " 
    7885               << "object was not found."); 
    79       return (U::AllMapObj[CObjectFactory::CurrContext][id]); 
     86      return (*U::AllMapObj_ptr)[*CObjectFactory::CurrContext_ptr][id]; 
    8087   } 
    8188 
     
    8390      std::shared_ptr<U> CObjectFactory::GetObject(const StdString & context, const StdString & id) 
    8491   { 
     92      if(U::AllMapObj_ptr  == NULL) return (std::shared_ptr<U>()); 
     93 
    8594      if (!CObjectFactory::HasObject<U>(context,id)) 
    8695         ERROR("CObjectFactory::GetObject(const StdString & id)", 
    8796               << "[ id = " << id << ", U = " << U::GetName() <<", context = "<<context<< " ] " 
    8897               << "object was not found."); 
    89       return (U::AllMapObj[context][id]); 
     98      return (*U::AllMapObj_ptr)[context][id]; 
    9099   } 
    91100 
     
    93102   std::shared_ptr<U> CObjectFactory::CreateObject(const StdString& id) 
    94103   { 
    95       if (CurrContext.empty()) 
     104      if(U::AllVectObj_ptr == NULL) U::AllVectObj_ptr = new xios_map<StdString, std::vector<std::shared_ptr<U> > >; 
     105      if(U::AllMapObj_ptr  == NULL) U::AllMapObj_ptr  = new xios_map<StdString, xios_map<StdString, std::shared_ptr<U> > >; 
     106 
     107      if (CurrContext_ptr->empty()) 
    96108         ERROR("CObjectFactory::CreateObject(const StdString& id)", 
    97109               << "[ id = " << id << " ] please define current context id !"); 
     
    105117         std::shared_ptr<U> value(new U(id.empty() ? CObjectFactory::GenUId<U>() : id)); 
    106118 
    107          U::AllVectObj[CObjectFactory::CurrContext].insert(U::AllVectObj[CObjectFactory::CurrContext].end(), value); 
    108          U::AllMapObj[CObjectFactory::CurrContext].insert(std::make_pair(value->getId(), value)); 
     119         (*U::AllVectObj_ptr)[*CObjectFactory::CurrContext_ptr].insert((*U::AllVectObj_ptr)[*CObjectFactory::CurrContext_ptr].end(), value); 
     120         (*U::AllMapObj_ptr) [*CObjectFactory::CurrContext_ptr].insert(std::make_pair(value->getId(), value)); 
    109121 
    110122         return value; 
     
    116128         CObjectFactory::GetObjectVector(const StdString & context) 
    117129   { 
    118       return (U::AllVectObj[context]); 
     130      return (*U::AllVectObj_ptr)[context]; 
    119131   } 
    120132 
     
    130142   { 
    131143      StdOStringStream oss; 
    132       oss << GetUIdBase<U>() << U::GenId[CObjectFactory::CurrContext]++; 
     144      if(U::GenId_ptr == NULL) U::GenId_ptr = new xios_map< StdString, long int >; 
     145      oss << GetUIdBase<U>() << (*U::GenId_ptr)[*CObjectFactory::CurrContext_ptr]++; 
    133146      return oss.str(); 
    134147   } 
Note: See TracChangeset for help on using the changeset viewer.