Changeset 769 for XIOS/trunk


Ignore:
Timestamp:
10/30/15 16:33:48 (8 years ago)
Author:
rlacroix
Message:

Keep track of whether an object id was automatically generated or not.

Location:
XIOS/trunk/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/object.cpp

    r511 r769  
    33namespace xios 
    44{ 
    5    /// ////////////////////// Définitions ////////////////////// /// 
     5  /// ////////////////////// Définitions ////////////////////// /// 
    66 
    7    CObject::CObject(void) 
    8       : id(), IdDefined(false) 
    9    { /* Ne rien faire de plus */ } 
     7  CObject::CObject(void) 
     8    : id(), idDefined(false), idAutoGenerated(false) 
     9  { /* Ne rien faire de plus */ } 
    1010 
    11    CObject::CObject(const StdString & id) 
    12       : id(id), IdDefined(true) 
    13    { /* Ne rien faire de plus */ } 
     11  CObject::CObject(const StdString& id, bool idAutoGenerated /*= false*/) 
     12    : id(id) 
     13    , idDefined(true) 
     14    , idAutoGenerated(idAutoGenerated) 
     15  { /* Ne rien faire de plus */ } 
    1416 
    15    CObject::CObject(const CObject & object) 
    16       : id(object.id), IdDefined(object.IdDefined) 
    17    { /* Ne rien faire de plus */ } 
     17  CObject::CObject(const CObject& object) 
     18    : id(object.id) 
     19    , idDefined(object.idDefined) 
     20    , idAutoGenerated(object.idAutoGenerated) 
     21  { /* Ne rien faire de plus */ } 
    1822 
    19    CObject::~CObject(void) 
    20    { /* Ne rien faire de plus */ } 
     23  CObject::~CObject(void) 
     24  { /* Ne rien faire de plus */ } 
    2125 
    22    const StdString & CObject::getId(void) const 
    23    { 
    24       return (this->id); 
    25    } 
     26  const StdString& CObject::getId(void) const 
     27  { 
     28    return this->id; 
     29  } 
    2630 
    27    const StdString& CObject::getIdServer() 
    28    { 
    29       return (this->id); 
    30    } 
     31  const StdString& CObject::getIdServer() const 
     32  { 
     33    return this->id; 
     34  } 
    3135 
    32    bool CObject::hasId(void) const 
    33    { 
    34       return (this->IdDefined); 
    35    } 
     36  bool CObject::hasId(void) const 
     37  { 
     38    return this->idDefined; 
     39  } 
    3640 
    37    void CObject::resetId(void) 
    38    { 
    39       this->IdDefined = false ; 
    40    } 
     41  bool CObject::hasAutoGeneratedId(void) const 
     42  { 
     43    return this->idAutoGenerated; 
     44  } 
    4145 
    42    void CObject::setId(const StdString & id) 
    43    { 
    44       this->id = id ; 
    45       this->IdDefined = true ; 
    46    } 
    47 /* 
    48    bool CObject::operator==(const CObject & other) const 
    49    { 
    50       if(!this->hasId() || !other.hasId()) 
    51          return (false); 
    52       return (this->id.compare(other.id) == 0); 
    53    } 
     46  void CObject::resetId(void) 
     47  { 
     48    this->idDefined = false; 
     49  } 
    5450 
    55    bool CObject::operator!=(const CObject & other) const 
    56    { 
    57       return (!(*this == other)); 
    58    } 
    59 */ 
    60    StdOStream & operator << (StdOStream & os, const CObject & object) 
    61    { 
    62       os << object.toString(); 
    63       return (os); 
    64    } 
     51  void CObject::setId(const StdString& id, bool idAutoGenerated /*= false*/) 
     52  { 
     53    this->id = id; 
     54    this->idDefined = true; 
     55    this->idAutoGenerated = false; 
     56  } 
    6557 
     58  /* 
     59  bool CObject::operator==(const CObject& other) const 
     60  { 
     61    if(!this->hasId() || !other.hasId()) 
     62    return false; 
     63    return this->id.compare(other.id) == 0; 
     64  } 
     65 
     66  bool CObject::operator!=(const CObject& other) const 
     67  { 
     68    return !(*this == other); 
     69  } 
     70  */ 
     71 
     72  StdOStream& operator<<(StdOStream& os, const CObject& object) 
     73  { 
     74    os << object.toString(); 
     75    return os; 
     76  } 
    6677} // namespace xios 
  • XIOS/trunk/src/object.hpp

    r591 r769  
    77namespace xios 
    88{ 
    9    /// ////////////////////// Déclarations ////////////////////// /// 
     9  /// ////////////////////// Déclarations ////////////////////// /// 
    1010 
    11    class CObject 
    12    { 
    13       public : 
     11  class CObject 
     12  { 
     13    public: 
     14      /// Destructeur /// 
     15      virtual ~CObject(void); 
    1416 
    15          /// Destructeur /// 
    16          virtual ~CObject(void); 
     17      /// Accesseurs /// 
     18      const StdString& getId(void) const; 
    1719 
    18          /// Accesseurs /// 
    19          const StdString & getId(void) const; 
     20      virtual const StdString& getIdServer() const; 
    2021 
    21          virtual const StdString& getIdServer(); 
     22      /// Mutateurs /// 
     23      void resetId(void); 
     24      void setId(const StdString& id, bool idAutoGenerated = false); 
    2225 
    23          /// Mutateurs /// 
    24          void resetId(void); 
    25          void setId(const StdString & id); 
     26      /// Tests /// 
     27      bool hasId(void) const; 
     28      bool hasAutoGeneratedId(void) const; 
    2629 
    27          /// Tests /// 
    28          bool hasId(void) const; 
     30      /// Opérateurs /// 
     31      // bool operator==(const CObject& other) const; 
     32      // bool operator!=(const CObject& other) const; 
    2933 
    30          /// Opérateurs /// 
    31 //         bool operator==(const CObject & other) const; 
    32 //         bool operator!=(const CObject & other) const; 
     34      /// Flux /// 
     35      friend StdOStream& operator<<(StdOStream& os, const CObject& object); 
    3336 
    34          /// Flux /// 
    35          friend StdOStream & operator << (StdOStream & os, const CObject & object); 
     37      /// Autres /// 
     38      virtual StdString toString(void) const = 0; 
     39      virtual void fromString(const StdString& str) = 0; 
    3640 
    37          /// Autres /// 
    38          virtual StdString toString(void) const = 0; 
    39          virtual void fromString(const StdString & str) = 0; 
     41    protected: 
     42      /// Constructeurs /// 
     43      CObject(void); 
     44      explicit CObject(const StdString& id, bool idAutoGenerated = false); 
     45      CObject(const CObject& object); 
     46      CObject(const CObject* const object); // Not implemented. 
    4047 
    41       protected : 
    42  
    43          /// Constructeurs /// 
    44          CObject(void); 
    45          explicit CObject(const StdString & id); 
    46          CObject(const CObject & object); 
    47          CObject(const CObject * const object); // Not implemented. 
    48  
    49       private : 
    50  
    51          /// Propriétés /// 
    52          StdString id ;    // identifiant de l'Object 
    53          bool IdDefined ;  // true si l'object est identifié, false sinon. 
    54  
    55    }; // class CObject 
    56  
     48    private: 
     49      /// Propriétés /// 
     50      StdString id;   // identifiant de l'Object 
     51      bool idDefined; // true si l'object est identifié, false sinon. 
     52      bool idAutoGenerated; //!< true if and only the id was automatically generated 
     53  }; // class CObject 
    5754} // namespace xios 
    5855 
    5956#endif // __XIOS_CObject__ 
    60  
  • XIOS/trunk/src/object_factory.hpp

    r591 r769  
    5252            static  boost::shared_ptr<U> CreateObject(const StdString & id = StdString("")); 
    5353 
    54          template <typename U> static  StdString GenUId(void) ;  
     54         template <typename U> static const StdString& GetUIdBase(void); 
     55         template <typename U> static StdString GenUId(void); 
     56         template <typename U> static bool IsGenUId(const StdString& id); 
    5557 
    5658      private : 
  • XIOS/trunk/src/object_factory_decl.cpp

    r689 r769  
    55{ 
    66#define macro(U) \ 
    7   template shared_ptr<U> CObjectFactory::GetObject<U>(const StdString & id);  \ 
    8   template shared_ptr<U> CObjectFactory::GetObject<U>(const StdString& context,const StdString & id); \ 
    9   template shared_ptr<U> CObjectFactory::GetObject<U>(const U * const object); \ 
     7  template shared_ptr<U> CObjectFactory::GetObject<U>(const StdString& id);  \ 
     8  template shared_ptr<U> CObjectFactory::GetObject<U>(const StdString& context,const StdString& id); \ 
     9  template shared_ptr<U> CObjectFactory::GetObject<U>(const U* const object); \ 
    1010  template int CObjectFactory::GetObjectNum<U>(void); \ 
    1111  template int CObjectFactory::GetObjectIdNum<U>(void); \ 
    12   template const std::vector<shared_ptr<U> >& CObjectFactory::GetObjectVector<U>(const StdString & context ); \ 
    13   template bool CObjectFactory::HasObject<U>(const StdString & id); \ 
    14   template bool CObjectFactory::HasObject<U>(const StdString& context,const StdString & id); \ 
    15   template boost::shared_ptr<U> CObjectFactory::CreateObject<U>(const StdString & id ); \ 
    16   template  StdString CObjectFactory::GenUId<U>(void); 
     12  template const std::vector<shared_ptr<U> >& CObjectFactory::GetObjectVector<U>(const StdString& context ); \ 
     13  template bool CObjectFactory::HasObject<U>(const StdString& id); \ 
     14  template bool CObjectFactory::HasObject<U>(const StdString& context,const StdString& id); \ 
     15  template boost::shared_ptr<U> CObjectFactory::CreateObject<U>(const StdString& id ); \ 
     16  template const StdString& CObjectFactory::GetUIdBase<U>(void); \ 
     17  template StdString CObjectFactory::GenUId<U>(void); \ 
     18  template bool CObjectFactory::IsGenUId<U>(const StdString& id); \ 
    1719 
    1820  macro(CField) 
  • XIOS/trunk/src/object_factory_impl.hpp

    r680 r769  
    5050      std::vector<boost::shared_ptr<U> > & vect = 
    5151                     U::AllVectObj[CObjectFactory::CurrContext]; 
    52                       
    53       typename std::vector<boost::shared_ptr<U> >::const_iterator  
     52 
     53      typename std::vector<boost::shared_ptr<U> >::const_iterator 
    5454         it = vect.begin(), end = vect.end(); 
    55        
     55 
    5656      for (; it != end; it++) 
    5757      { 
     
    6060            return (ptr); 
    6161      } 
    62        
     62 
    6363      ERROR("CObjectFactory::GetObject(const U * const object)", 
    6464               << "[type = " << U::GetName() << ", adress = " << object << "] " 
     
    9191 
    9292   template <typename U> 
    93       boost::shared_ptr<U> CObjectFactory::CreateObject(const StdString & id) 
     93   boost::shared_ptr<U> CObjectFactory::CreateObject(const StdString& id) 
    9494   { 
    95       if (CurrContext.size() == 0) 
    96          ERROR("CObjectFactory::CreateObject(const StdString & id)", 
     95      if (CurrContext.empty()) 
     96         ERROR("CObjectFactory::CreateObject(const StdString& id)", 
    9797               << "[ id = " << id << " ] please define current context id !"); 
    98       if (id.size() == 0) 
     98 
     99      if (CObjectFactory::HasObject<U>(id)) 
    99100      { 
    100          boost::shared_ptr<U> value(new U(CObjectFactory::GenUId<U>())); 
    101          U::AllVectObj[CObjectFactory::CurrContext].insert 
    102             (U::AllVectObj[CObjectFactory::CurrContext].end(), value); 
    103          U::AllMapObj[CObjectFactory::CurrContext].insert(std::make_pair(value->getId(), value)); 
    104          return (value); 
    105       } 
    106       else if (CObjectFactory::HasObject<U>(id)) 
    107       { 
    108          return (CObjectFactory::GetObject<U>(id)); 
     101         return CObjectFactory::GetObject<U>(id); 
    109102      } 
    110103      else 
    111104      { 
    112          boost::shared_ptr<U> value(new U(id)); 
    113          U::AllVectObj[CObjectFactory::CurrContext].insert 
    114             (U::AllVectObj[CObjectFactory::CurrContext].end(), value); 
    115          U::AllMapObj[CObjectFactory::CurrContext].insert(std::make_pair(id, value)); 
    116          return (value); 
     105         boost::shared_ptr<U> value(new U(id.empty() ? CObjectFactory::GenUId<U>() : id)); 
     106 
     107         U::AllVectObj[CObjectFactory::CurrContext].insert(U::AllVectObj[CObjectFactory::CurrContext].end(), value); 
     108         U::AllMapObj[CObjectFactory::CurrContext].insert(std::make_pair(value->getId(), value)); 
     109 
     110         return value; 
    117111      } 
    118112   } 
     
    124118      return (U::AllVectObj[context]); 
    125119   } 
    126     
    127    template <typename U>  
    128        StdString CObjectFactory::GenUId(void) 
    129        { 
    130           long int seed ; 
    131            
    132           xios_map<StdString,long int>::iterator it ; 
    133           it=U::GenId.find(CObjectFactory::CurrContext); 
    134           if (it==U::GenId.end()) 
    135           { 
    136             seed=0 ; 
    137             U::GenId[CObjectFactory::CurrContext]=seed ; 
    138           } 
    139           else 
    140           { 
    141             seed=it->second ; 
    142             seed++ ; 
    143             it->second=seed ; 
    144           } 
    145            
    146           StdOStringStream oss ; 
    147           oss<<"__"<<U::GetName()<<"_undef_id_"<<seed ; 
    148           return StdString(oss.str()) ; 
    149         } 
    150            
     120 
     121   template <typename U> 
     122   const StdString& CObjectFactory::GetUIdBase(void) 
     123   { 
     124      static const StdString base = "__" + U::GetName() + "_undef_id_"; 
     125      return base; 
     126   } 
     127 
     128   template <typename U> 
     129   StdString CObjectFactory::GenUId(void) 
     130   { 
     131      StdOStringStream oss; 
     132      oss << GetUIdBase<U>() << U::GenId[CObjectFactory::CurrContext]++; 
     133      return oss.str(); 
     134   } 
     135 
     136   template <typename U> 
     137   bool CObjectFactory::IsGenUId(const StdString& id) 
     138   { 
     139      const StdString& base = GetUIdBase<U>(); 
     140      return (id.size() > base.size() && id.compare(0, base.size(), base) == 0); 
     141   } 
     142 
    151143} // namespace xios 
    152144 
  • XIOS/trunk/src/object_template_impl.hpp

    r735 r769  
    4242      CObjectTemplate<T>::CObjectTemplate(const StdString & id) 
    4343         : CAttributeMap() 
    44          , CObject(id) 
     44         , CObject(id, CObjectFactory::IsGenUId<T>(id)) 
    4545   { /* Ne rien faire de plus */ } 
    4646 
     
    5252   { 
    5353      if (object.hasId() && withId) 
    54          this->setId(object.getId()); 
     54         this->setId(object.getId(), object.hasAutoGeneratedId()); 
    5555      ERROR("CObjectTemplate<T> construtor 3", << "Not completly implemented yet !"); 
    5656   } 
Note: See TracChangeset for help on using the changeset viewer.