Changeset 769
- Timestamp:
- 10/30/15 16:33:48 (9 years ago)
- Location:
- XIOS/trunk/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/trunk/src/object.cpp
r511 r769 3 3 namespace xios 4 4 { 5 5 /// ////////////////////// Définitions ////////////////////// /// 6 6 7 8 : id(), IdDefined(false)9 7 CObject::CObject(void) 8 : id(), idDefined(false), idAutoGenerated(false) 9 { /* Ne rien faire de plus */ } 10 10 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 */ } 14 16 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 */ } 18 22 19 20 23 CObject::~CObject(void) 24 { /* Ne rien faire de plus */ } 21 25 22 const StdString& CObject::getId(void) const23 24 return (this->id);25 26 const StdString& CObject::getId(void) const 27 { 28 return this->id; 29 } 26 30 27 const StdString& CObject::getIdServer()28 29 return (this->id);30 31 const StdString& CObject::getIdServer() const 32 { 33 return this->id; 34 } 31 35 32 33 34 return (this->IdDefined);35 36 bool CObject::hasId(void) const 37 { 38 return this->idDefined; 39 } 36 40 37 void CObject::resetId(void)38 39 this->IdDefined = false;40 41 bool CObject::hasAutoGeneratedId(void) const 42 { 43 return this->idAutoGenerated; 44 } 41 45 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 } 54 50 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 } 65 57 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 } 66 77 } // namespace xios -
XIOS/trunk/src/object.hpp
r591 r769 7 7 namespace xios 8 8 { 9 9 /// ////////////////////// Déclarations ////////////////////// /// 10 10 11 class CObject 12 { 13 public : 11 class CObject 12 { 13 public: 14 /// Destructeur /// 15 virtual ~CObject(void); 14 16 15 /// Destructeur///16 virtual ~CObject(void);17 /// Accesseurs /// 18 const StdString& getId(void) const; 17 19 18 /// Accesseurs /// 19 const StdString & getId(void) const; 20 virtual const StdString& getIdServer() const; 20 21 21 virtual const StdString& getIdServer(); 22 /// Mutateurs /// 23 void resetId(void); 24 void setId(const StdString& id, bool idAutoGenerated = false); 22 25 23 /// Mutateurs ///24 void resetId(void);25 void setId(const StdString & id);26 /// Tests /// 27 bool hasId(void) const; 28 bool hasAutoGeneratedId(void) const; 26 29 27 /// Tests /// 28 bool hasId(void) const; 30 /// Opérateurs /// 31 // bool operator==(const CObject& other) const; 32 // bool operator!=(const CObject& other) const; 29 33 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); 33 36 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; 36 40 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. 40 47 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 57 54 } // namespace xios 58 55 59 56 #endif // __XIOS_CObject__ 60 -
XIOS/trunk/src/object_factory.hpp
r591 r769 52 52 static boost::shared_ptr<U> CreateObject(const StdString & id = StdString("")); 53 53 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); 55 57 56 58 private : -
XIOS/trunk/src/object_factory_decl.cpp
r689 r769 5 5 { 6 6 #define macro(U) \ 7 template shared_ptr<U> CObjectFactory::GetObject<U>(const StdString 8 template shared_ptr<U> CObjectFactory::GetObject<U>(const StdString& context,const StdString 9 template shared_ptr<U> CObjectFactory::GetObject<U>(const 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); \ 10 10 template int CObjectFactory::GetObjectNum<U>(void); \ 11 11 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); \ 17 19 18 20 macro(CField) -
XIOS/trunk/src/object_factory_impl.hpp
r680 r769 50 50 std::vector<boost::shared_ptr<U> > & vect = 51 51 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 54 54 it = vect.begin(), end = vect.end(); 55 55 56 56 for (; it != end; it++) 57 57 { … … 60 60 return (ptr); 61 61 } 62 62 63 63 ERROR("CObjectFactory::GetObject(const U * const object)", 64 64 << "[type = " << U::GetName() << ", adress = " << object << "] " … … 91 91 92 92 template <typename U> 93 boost::shared_ptr<U> CObjectFactory::CreateObject(const StdString& id)93 boost::shared_ptr<U> CObjectFactory::CreateObject(const StdString& id) 94 94 { 95 if (CurrContext. size() == 0)96 ERROR("CObjectFactory::CreateObject(const StdString 95 if (CurrContext.empty()) 96 ERROR("CObjectFactory::CreateObject(const StdString& id)", 97 97 << "[ id = " << id << " ] please define current context id !"); 98 if (id.size() == 0) 98 99 if (CObjectFactory::HasObject<U>(id)) 99 100 { 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); 109 102 } 110 103 else 111 104 { 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; 117 111 } 118 112 } … … 124 118 return (U::AllVectObj[context]); 125 119 } 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 151 143 } // namespace xios 152 144 -
XIOS/trunk/src/object_template_impl.hpp
r735 r769 42 42 CObjectTemplate<T>::CObjectTemplate(const StdString & id) 43 43 : CAttributeMap() 44 , CObject(id )44 , CObject(id, CObjectFactory::IsGenUId<T>(id)) 45 45 { /* Ne rien faire de plus */ } 46 46 … … 52 52 { 53 53 if (object.hasId() && withId) 54 this->setId(object.getId() );54 this->setId(object.getId(), object.hasAutoGeneratedId()); 55 55 ERROR("CObjectTemplate<T> construtor 3", << "Not completly implemented yet !"); 56 56 }
Note: See TracChangeset
for help on using the changeset viewer.