[219] | 1 | #ifndef __XMLIO_CObjectTemplate_impl__ |
---|
| 2 | #define __XMLIO_CObjectTemplate_impl__ |
---|
| 3 | |
---|
[327] | 4 | #include "xmlioserver_spl.hpp" |
---|
| 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" |
---|
[300] | 17 | |
---|
[335] | 18 | namespace xios |
---|
[219] | 19 | { |
---|
| 20 | /// ////////////////////// Définitions ////////////////////// /// |
---|
| 21 | template <class T> |
---|
| 22 | xios_map<StdString, |
---|
| 23 | xios_map<StdString, |
---|
| 24 | boost::shared_ptr<T> > > CObjectTemplate<T>::AllMapObj; |
---|
| 25 | |
---|
| 26 | template <class T> |
---|
| 27 | xios_map<StdString, |
---|
| 28 | std::vector<boost::shared_ptr<T> > > CObjectTemplate<T>::AllVectObj; |
---|
| 29 | |
---|
| 30 | template <class T> |
---|
[286] | 31 | xios_map<StdString,long int> CObjectTemplate<T>::GenId; |
---|
| 32 | |
---|
| 33 | template <class T> |
---|
[219] | 34 | CObjectTemplate<T>::CObjectTemplate(void) |
---|
| 35 | : tree::CAttributeMap() |
---|
| 36 | , CObject() |
---|
| 37 | { /* Ne rien faire de plus */ } |
---|
| 38 | |
---|
| 39 | template <class T> |
---|
| 40 | CObjectTemplate<T>::CObjectTemplate(const StdString & id) |
---|
| 41 | : tree::CAttributeMap() |
---|
| 42 | , CObject(id) |
---|
| 43 | { /* Ne rien faire de plus */ } |
---|
| 44 | |
---|
| 45 | template <class T> |
---|
| 46 | CObjectTemplate<T>::CObjectTemplate |
---|
| 47 | (const CObjectTemplate<T> & object, bool withAttrList, bool withId) |
---|
| 48 | : tree::CAttributeMap() |
---|
| 49 | , CObject() |
---|
| 50 | { |
---|
| 51 | if (object.hasId() && withId) |
---|
| 52 | this->setId(object.getId()); |
---|
| 53 | ERROR("CObjectTemplate<T> construtor 3", << "Not completly implemented yet !"); |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | template <class T> |
---|
| 57 | CObjectTemplate<T>::~CObjectTemplate(void) |
---|
| 58 | { /* Ne rien faire de plus */ } |
---|
| 59 | |
---|
| 60 | ///-------------------------------------------------------------- |
---|
| 61 | |
---|
| 62 | template <class T> |
---|
| 63 | std::vector<boost::shared_ptr<T> > & |
---|
| 64 | CObjectTemplate<T>::GetAllVectobject(const StdString & contextId) |
---|
| 65 | { |
---|
| 66 | return (CObjectTemplate<T>::AllVectObj[contextId]); |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | //--------------------------------------------------------------- |
---|
| 70 | |
---|
| 71 | template <class T> |
---|
| 72 | StdString CObjectTemplate<T>::toString(void) const |
---|
| 73 | { |
---|
| 74 | StdOStringStream oss; |
---|
| 75 | oss << "<" << T::GetName(); |
---|
| 76 | if (this->hasId()) |
---|
| 77 | oss << " id=\"" << this->getId() << "\""; |
---|
| 78 | oss << " " << SuperClassMap::toString() << "/>"; |
---|
| 79 | return (oss.str()); |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | template <class T> |
---|
| 83 | void CObjectTemplate<T>::fromString(const StdString & str) |
---|
| 84 | { |
---|
| 85 | ERROR("CObjectTemplate<T>::fromString(str)", |
---|
| 86 | << "[ str = " << str << "] Not implemented yet !"); |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | //--------------------------------------------------------------- |
---|
| 90 | |
---|
| 91 | template <class T> |
---|
| 92 | void CObjectTemplate<T>::toBinary(StdOStream & os) const |
---|
| 93 | { |
---|
| 94 | SuperClassMap::toBinary(os); |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | template <class T> |
---|
| 98 | void CObjectTemplate<T>::fromBinary(StdIStream & is) |
---|
| 99 | { |
---|
| 100 | SuperClassMap::fromBinary(is); |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | //--------------------------------------------------------------- |
---|
| 104 | |
---|
| 105 | template <class T> |
---|
| 106 | void CObjectTemplate<T>::parse(xml::CXMLNode & node) |
---|
| 107 | { |
---|
| 108 | xml::THashAttributes attributes = node.getAttributes(); |
---|
| 109 | CAttributeMap::setAttributes(attributes); |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | //--------------------------------------------------------------- |
---|
| 113 | |
---|
| 114 | template <class T> |
---|
| 115 | tree::ENodeType CObjectTemplate<T>::getType(void) const |
---|
| 116 | { |
---|
| 117 | return (T::GetType()); |
---|
| 118 | } |
---|
[313] | 119 | |
---|
| 120 | template <class T> |
---|
| 121 | string CObjectTemplate<T>::getName(void) const |
---|
| 122 | { |
---|
| 123 | return (T::GetName()); |
---|
| 124 | } |
---|
| 125 | |
---|
[219] | 126 | //--------------------------------------------------------------- |
---|
| 127 | |
---|
| 128 | template <class T> |
---|
| 129 | bool CObjectTemplate<T>::hasChild(void) const |
---|
| 130 | { |
---|
| 131 | return (false); |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | //--------------------------------------------------------------- |
---|
| 135 | |
---|
| 136 | template <class T> |
---|
| 137 | void CObjectTemplate<T>::solveDescInheritance(const CAttributeMap * const parent) |
---|
| 138 | { |
---|
| 139 | SuperClassMap::setAttributes(parent); |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | //--------------------------------------------------------------- |
---|
| 143 | |
---|
| 144 | template <class T> |
---|
| 145 | void CObjectTemplate<T>::ClearAllAttributes(void) |
---|
| 146 | { |
---|
| 147 | std::vector<boost::shared_ptr<T> > & avect = |
---|
| 148 | CObjectTemplate<T>::GetAllVectobject(CObjectFactory::GetCurrentContextId()); |
---|
| 149 | typename std::vector<boost::shared_ptr<T> >::iterator |
---|
| 150 | it = avect.begin(), end = avect.end(); |
---|
| 151 | |
---|
| 152 | for (;it != end; it++) |
---|
| 153 | { |
---|
| 154 | CAttributeMap & amap = **it; |
---|
| 155 | amap.clearAllAttributes(); |
---|
| 156 | } |
---|
| 157 | } |
---|
| 158 | |
---|
[300] | 159 | template <class T> |
---|
| 160 | void CObjectTemplate<T>::sendAttributToServer(const string& id) |
---|
| 161 | { |
---|
| 162 | CAttributeMap & attrMap = *this; |
---|
| 163 | CAttribute* attr=attrMap[id] ; |
---|
| 164 | sendAttributToServer(*attr) ; |
---|
| 165 | } |
---|
[219] | 166 | |
---|
[300] | 167 | template <class T> |
---|
| 168 | void CObjectTemplate<T>::sendAttributToServer(tree::CAttribute& attr) |
---|
| 169 | { |
---|
| 170 | shared_ptr<CContext> context=CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId()) ; |
---|
| 171 | |
---|
| 172 | if (!context->hasServer) |
---|
| 173 | { |
---|
| 174 | CContextClient* client=context->client ; |
---|
| 175 | |
---|
| 176 | CEventClient event(getType(),EVENT_ID_SEND_ATTRIBUTE) ; |
---|
| 177 | if (client->isServerLeader()) |
---|
| 178 | { |
---|
| 179 | CMessage msg ; |
---|
| 180 | msg<<this->getId() ; |
---|
| 181 | msg<<attr.getName() ; |
---|
| 182 | msg<<attr ; |
---|
| 183 | event.push(client->getServerLeader(),1,msg) ; |
---|
| 184 | client->sendEvent(event) ; |
---|
| 185 | } |
---|
| 186 | else client->sendEvent(event) ; |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | } |
---|
| 190 | |
---|
| 191 | template <class T> |
---|
| 192 | void CObjectTemplate<T>::recvAttributFromClient(CEventServer& event) |
---|
| 193 | { |
---|
| 194 | |
---|
| 195 | CBufferIn* buffer=event.subEvents.begin()->buffer; |
---|
| 196 | string id,attrId; |
---|
| 197 | *buffer>>id ; |
---|
| 198 | CAttributeMap & attrMap = *get(id); |
---|
| 199 | *buffer>>attrId ; |
---|
| 200 | CAttribute* attr=attrMap[attrId] ; |
---|
| 201 | info(50)<<"attribut recu "<<attrId<<" " ; |
---|
| 202 | if (attr->isEmpty()) info(50)<<"--> empty"<<endl ; |
---|
| 203 | else info(50) /*<attr->getValue()*/<<endl ; |
---|
| 204 | *buffer>>*attr ; |
---|
| 205 | info(50)<<"attribut recu "<<attrId<<" " ; |
---|
| 206 | if (attr->isEmpty()) info(50)<<"--> empty"<<endl ; |
---|
| 207 | else info(50) /*attr->getValue()*/<<endl ; |
---|
| 208 | } |
---|
| 209 | |
---|
| 210 | template <class T> |
---|
| 211 | bool CObjectTemplate<T>::dispatchEvent(CEventServer& event) |
---|
| 212 | { |
---|
| 213 | switch(event.type) |
---|
| 214 | { |
---|
| 215 | case EVENT_ID_SEND_ATTRIBUTE : |
---|
| 216 | recvAttributFromClient(event) ; |
---|
| 217 | return true ; |
---|
| 218 | break ; |
---|
| 219 | |
---|
| 220 | default : |
---|
| 221 | return false ; |
---|
| 222 | // ERROR("void CObjectTemplate<T>::recvEvent(CEventServer& event)", |
---|
| 223 | // <<"Unknown Event") ; |
---|
| 224 | } |
---|
| 225 | } |
---|
| 226 | |
---|
| 227 | template <typename T> |
---|
| 228 | bool CObjectTemplate<T>::has(const string & id) |
---|
| 229 | { |
---|
| 230 | return CObjectFactory::HasObject<T>(id) ; |
---|
| 231 | } |
---|
| 232 | |
---|
| 233 | template <typename T> |
---|
| 234 | boost::shared_ptr<T> CObjectTemplate<T>::get(const string & id) |
---|
| 235 | { |
---|
| 236 | return CObjectFactory::GetObject<T>(id) ; |
---|
| 237 | } |
---|
| 238 | |
---|
| 239 | template <typename T> |
---|
| 240 | boost::shared_ptr<T> CObjectTemplate<T>::create(const string & id) |
---|
| 241 | { |
---|
| 242 | return CObjectFactory::CreateObject<T>(id) ; |
---|
| 243 | } ///-------------------------------------------------------------- |
---|
| 244 | |
---|
| 245 | template <typename T> |
---|
| 246 | boost::shared_ptr<T> CObjectTemplate<T>::get(void) |
---|
| 247 | { |
---|
| 248 | return CObjectFactory::GetObject<T>((T*)this) ; |
---|
| 249 | } |
---|
| 250 | |
---|
[313] | 251 | template <typename T> |
---|
| 252 | void CObjectTemplate<T>::generateCInterface(ostream& oss) |
---|
| 253 | { |
---|
| 254 | string className=getName() ; |
---|
| 255 | int found=className.find_first_of("_") ; |
---|
| 256 | if (found!=string::npos) className.replace(found,1,0,'x') ; |
---|
| 257 | |
---|
| 258 | oss<<"/* ************************************************************************** *"<<iendl ; |
---|
| 259 | oss<<" * Interface auto generated - do not modify *"<<iendl ; |
---|
| 260 | oss<<" * ************************************************************************** */"<<iendl; |
---|
| 261 | oss<<iendl ; |
---|
| 262 | oss<<"#include <boost/multi_array.hpp>"<<iendl ; |
---|
| 263 | oss<<"#include <boost/shared_ptr.hpp>"<<iendl ; |
---|
| 264 | oss<<"#include \"xmlioserver.hpp\""<<iendl; |
---|
| 265 | oss<<"#include \"attribute_template_impl.hpp\""<<iendl ; |
---|
| 266 | oss<<"#include \"object_template_impl.hpp\""<<iendl; |
---|
| 267 | oss<<"#include \"group_template_impl.hpp\""<<iendl ; |
---|
| 268 | oss<<"#include \"icutil.hpp\""<<iendl ; |
---|
| 269 | oss<<iendl ; |
---|
| 270 | oss<<"extern \"C\""<<iendl ; |
---|
| 271 | oss<<"{"<<iendl++ ; |
---|
[335] | 272 | oss<<"typedef xios::tree::"<<getStrType<T>()<<"* "<<className<<"_Ptr;"<<iendl; |
---|
[313] | 273 | oss<<iendl ; |
---|
| 274 | SuperClassMap::generateCInterface(oss,className) ; |
---|
| 275 | oss<<iendl-- ; |
---|
| 276 | oss<<"}"<<iendl ; |
---|
| 277 | } |
---|
[300] | 278 | |
---|
[313] | 279 | template <typename T> |
---|
| 280 | void CObjectTemplate<T>::generateFortran2003Interface(ostream& oss) |
---|
| 281 | { |
---|
| 282 | string className=getName() ; |
---|
| 283 | int found=className.find_first_of("_") ; |
---|
| 284 | if (found!=string::npos) className.replace(found,1,0,'x') ; |
---|
| 285 | |
---|
| 286 | oss<<"! * ************************************************************************** *"<<iendl ; |
---|
| 287 | oss<<"! * Interface auto generated - do not modify *"<<iendl ; |
---|
| 288 | oss<<"! * ************************************************************************** *"<<iendl; |
---|
| 289 | oss<<iendl ; |
---|
| 290 | oss<<"MODULE "<<className<<"_interface_attr"<<iendl++ ; |
---|
| 291 | oss<<"USE, INTRINSIC :: ISO_C_BINDING"<<iendl ; |
---|
| 292 | oss<<iendl ; |
---|
| 293 | oss<<"INTERFACE ! Do not call directly / interface FORTRAN 2003 <-> C99"<<iendl++ ; |
---|
| 294 | oss<<iendl ; |
---|
| 295 | oss<<iendl ; |
---|
| 296 | SuperClassMap::generateFortran2003Interface(oss,className) ; |
---|
| 297 | oss<<"END INTERFACE"<<iendl-- ; |
---|
| 298 | oss<<iendl-- ; |
---|
| 299 | oss<<"END MODULE "<<className<<"_interface_attr"<<iendl ; |
---|
| 300 | } |
---|
[300] | 301 | |
---|
[313] | 302 | template <typename T> |
---|
| 303 | void CObjectTemplate<T>::generateFortranInterface(ostream& oss) |
---|
| 304 | { |
---|
| 305 | string className=getName() ; |
---|
| 306 | int found=className.find_first_of('_') ; |
---|
| 307 | if (found!=string::npos) className.erase(found,1) ; |
---|
| 308 | string superClassName=getName(); |
---|
| 309 | found=superClassName.find("_group") ; |
---|
| 310 | if (found!=string::npos) superClassName.erase(found,6) ; |
---|
| 311 | |
---|
| 312 | oss<<"! * ************************************************************************** *"<<iendl ; |
---|
| 313 | oss<<"! * Interface auto generated - do not modify *"<<iendl ; |
---|
| 314 | oss<<"! * ************************************************************************** *"<<iendl; |
---|
| 315 | oss<<"#include \"xios_fortran_prefix.hpp\""<<iendl ; |
---|
| 316 | oss<<iendl ; |
---|
| 317 | oss<<"MODULE i"<<className<<"_attr"<<iendl++ ; |
---|
| 318 | oss<<"USE, INTRINSIC :: ISO_C_BINDING"<<iendl ; |
---|
| 319 | oss<<"USE i"<<superClassName<<iendl ; |
---|
| 320 | oss<<"USE "<<className<<"_interface_attr"<<iendl ; |
---|
| 321 | // oss<<"TYPE txios("<<className<<")"<<iendl ; |
---|
| 322 | // oss<<" INTEGER(kind = C_INTPTR_T) :: daddr"<<iendl ; |
---|
| 323 | // oss<<"END TYPE txios("<<className<<")"<<iendl ; |
---|
| 324 | oss<<iendl-- ; |
---|
| 325 | oss<<"CONTAINS"<<iendl++ ; |
---|
| 326 | oss<<iendl ; |
---|
| 327 | SuperClassMap::generateFortranInterface_id(oss,className) ; |
---|
| 328 | oss<<iendl ; |
---|
| 329 | SuperClassMap::generateFortranInterface_hdl(oss,className) ; |
---|
| 330 | oss<<iendl ; |
---|
| 331 | SuperClassMap::generateFortranInterface_hdl_(oss,className) ; |
---|
| 332 | oss<<iendl ; |
---|
| 333 | SuperClassMap::generateFortranInterfaceGet_id(oss,className) ; |
---|
| 334 | oss<<iendl ; |
---|
| 335 | SuperClassMap::generateFortranInterfaceGet_hdl(oss,className) ; |
---|
| 336 | oss<<iendl ; |
---|
| 337 | SuperClassMap::generateFortranInterfaceGet_hdl_(oss,className) ; |
---|
| 338 | oss<<iendl-- ; |
---|
| 339 | oss<<"END MODULE i"<<className<<"_attr"<<iendl ; |
---|
| 340 | } |
---|
| 341 | |
---|
| 342 | |
---|
[335] | 343 | } // namespace xios |
---|
[219] | 344 | |
---|
| 345 | #endif // __XMLIO_CObjectTemplate_impl__ |
---|