Changeset 769 for XIOS/trunk/src/object_factory_impl.hpp
- Timestamp:
- 10/30/15 16:33:48 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.