Changeset 2614 for XIOS3/trunk/src
- Timestamp:
- 03/12/24 20:02:35 (4 months ago)
- Location:
- XIOS3/trunk/src
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS3/trunk/src/group_template.hpp
r2603 r2614 51 51 virtual void parse(xml::CXMLNode & node); 52 52 virtual void parse(xml::CXMLNode & node, bool withAttr); 53 virtual void parse(xml::CXMLNode & node, bool withAttr, const std::set<StdString>& parseContextList); 54 53 55 virtual void parseChild(xml::CXMLNode & node); 54 56 -
XIOS3/trunk/src/group_template_impl.hpp
r2603 r2614 37 37 { /* Ne rien faire de plus */ } 38 38 39 ///--------------------------------------------------------------40 /*41 template <class U, class V, class W>42 void CGroupTemplate<U, V, W>::toBinary(StdOStream & os) const43 {44 SuperClass::toBinary(os);45 46 const StdSize grpnb = this->groupList.size();47 const StdSize chdnb = this->childList.size();48 ENodeType cenum = U::GetType();49 ENodeType genum = V::GetType();50 51 os.write (reinterpret_cast<const char*>(&grpnb) , sizeof(StdSize));52 os.write (reinterpret_cast<const char*>(&chdnb) , sizeof(StdSize));53 54 typename std::vector<V*>::const_iterator55 itg = this->groupList.begin(), endg = this->groupList.end();56 typename std::vector<U*>::const_iterator57 itc = this->childList.begin(), endc = this->childList.end();58 59 for (; itg != endg; itg++)60 {61 V* group = *itg;62 bool hid = group->hasId();63 64 os.write (reinterpret_cast<const char*>(&genum), sizeof(ENodeType));65 os.write (reinterpret_cast<const char*>(&hid), sizeof(bool));66 67 if (hid)68 {69 const StdString & id = group->getId();70 const StdSize size = id.size();71 72 os.write (reinterpret_cast<const char*>(&size), sizeof(StdSize));73 os.write (id.data(), size * sizeof(char));74 }75 group->toBinary(os);76 }77 78 for (; itc != endc; itc++)79 {80 U* child = *itc;81 bool hid = child->hasId();82 83 os.write (reinterpret_cast<const char*>(&cenum), sizeof(ENodeType));84 os.write (reinterpret_cast<const char*>(&hid), sizeof(bool));85 86 if (hid)87 {88 const StdString & id = child->getId();89 const StdSize size = id.size();90 91 os.write (reinterpret_cast<const char*>(&size), sizeof(StdSize));92 os.write (id.data(), size * sizeof(char));93 }94 child->toBinary(os);95 }96 97 }98 99 template <class U, class V, class W>100 void CGroupTemplate<U, V, W>::fromBinary(StdIStream & is)101 {102 SuperClass::fromBinary(is);103 104 V* group_ptr = (this->hasId())105 ? V::get(this->getId())106 : V::get((V*)this);107 108 StdSize grpnb = 0;109 StdSize chdnb = 0;110 ENodeType renum = Unknown;111 112 is.read (reinterpret_cast<char*>(&grpnb), sizeof(StdSize));113 is.read (reinterpret_cast<char*>(&chdnb), sizeof(StdSize));114 115 for (StdSize i = 0; i < grpnb; i++)116 {117 bool hid = false;118 is.read (reinterpret_cast<char*>(&renum), sizeof(ENodeType));119 is.read (reinterpret_cast<char*>(&hid), sizeof(bool));120 121 if (renum != V::GetType())122 ERROR("CGroupTemplate<U, V, W>::fromBinary(StdIStream & is)",123 << "[ renum = " << renum << "] Bad type !");124 125 if (hid)126 {127 StdSize size = 0;128 is.read (reinterpret_cast<char*>(&size), sizeof(StdSize));129 StdString id(size, ' ');130 is.read (const_cast<char *>(id.data()), size * sizeof(char));131 CGroupFactory::CreateGroup(group_ptr->getShared(), id)->fromBinary(is);132 }133 else134 {135 CGroupFactory::CreateGroup(group_ptr->getShared())->fromBinary(is);136 }137 }138 139 for (StdSize j = 0; j < chdnb; j++)140 {141 bool hid = false;142 is.read (reinterpret_cast<char*>(&renum), sizeof(ENodeType));143 is.read (reinterpret_cast<char*>(&hid), sizeof(bool));144 145 if (renum != U::GetType())146 ERROR("CGroupTemplate<U, V, W>::fromBinary(StdIStream & is)",147 << "[ renum = " << renum << "] Bad type !");148 149 if (hid)150 {151 StdSize size = 0;152 is.read (reinterpret_cast<char*>(&size), sizeof(StdSize));153 StdString id(size, ' ');154 is.read (const_cast<char *>(id.data()), size * sizeof(char));155 CGroupFactory::CreateChild(group_ptr->getShared(), id)->fromBinary(is);156 }157 else158 {159 CGroupFactory::CreateChild(group_ptr->getShared())->fromBinary(is);160 }161 }162 }163 */164 //--------------------------------------------------------------165 166 39 template <class U, class V, class W> 167 40 StdString CGroupTemplate<U, V, W>::toString(void) const … … 255 128 256 129 template <class U, class V, class W> 257 void CGroupTemplate<U, V, W>::parse(xml::CXMLNode & node)258 {259 this->parse(node, true);260 }261 262 //---------------------------------------------------------------263 264 template <class U, class V, class W>265 130 void CGroupTemplate<U, V, W>::solveDescInheritance(bool apply, const CAttributeMap * const parent) 266 131 { … … 319 184 { /* Ne rien faire de plus */ } 320 185 321 // template <class U, class V, class W> 322 // bool CGroupTemplate<U, V, W>::has(const string& id) 323 // { 324 // return CObjectFactory::HasObject<V>(id) ; 325 // } 326 327 // template <class U, class V, class W> 328 // std::shared_ptr<V> CGroupTemplate<U, V, W>::get(const string& id) 329 // { 330 // return CObjectFactory::GetObject<V>(id) ; 331 // } 332 333 // template <class U, class V, class W> 334 // std::shared_ptr<V> CGroupTemplate<U, V, W>::get() 335 // { 336 // return CObjectFactory::GetObject<V>(this) ; 337 // } 338 339 // template <class U, class V, class W> 340 // std::shared_ptr<V> CGroupTemplate<U, V, W>::create(const string& id) 341 // { 342 // return CObjectFactory::CreateObject<V>(id) ; 343 // } 186 344 187 ///-------------------------------------------------------------- 345 188 … … 470 313 471 314 template <class U, class V, class W> 315 void CGroupTemplate<U, V, W>::parse(xml::CXMLNode & node) 316 { 317 this->parse(node, true); 318 } 319 320 template <class U, class V, class W> 321 void CGroupTemplate<U, V, W>::parse(xml::CXMLNode & node, bool withAttr, const std::set<StdString>& parseContextList) 322 { 323 ERROR("void CGroupTemplate<U, V, W>::parse(xml::CXMLNode & node, bool withAttr, const std::set<StdString>& parseContextList)", 324 <<"must not be called by this kind of object : "<<GetName() ) ; 325 } 326 327 template <class U, class V, class W> 472 328 void CGroupTemplate<U, V, W>::parse(xml::CXMLNode & node, bool withAttr) 473 329 { … … 478 334 { 479 335 CGroupTemplate<U, V, W>::SuperClass::parse(node); 480 if (attributes.end() != attributes.find("src")) 481 { 482 StdIFStream ifs ( attributes["src"].c_str() , StdIFStream::in ); 483 if ( (ifs.rdstate() & std::ifstream::failbit ) != 0 ) 484 ERROR("void CGroupTemplate<U, V, W>::parse(xml::CXMLNode & node, bool withAttr)", 485 <<endl<< "Can not open <"<<attributes["src"].c_str()<<"> file" ); 486 487 if (!ifs.good()) 488 ERROR("CGroupTemplate<U, V, W>::parse(xml::CXMLNode & node, bool withAttr)", 489 << "[ filename = " << attributes["src"] << " ] Bad xml stream !"); 490 xml::CXMLParser::ParseInclude(ifs, attributes["src"].c_str(), *this); 491 } 336 if (attributes.end() != attributes.find("src")) xml::CXMLParser::ParseInclude(attributes["src"].c_str(), *this); 492 337 } 493 338 -
XIOS3/trunk/src/mpi_tools.hpp
r2576 r2614 12 12 template<typename T> 13 13 MPI_Datatype MPI_GetType(void) ; 14 15 template<> 16 MPI_Datatype MPI_GetType<bool>(void) ; 14 17 15 18 template<> -
XIOS3/trunk/src/node/context.cpp
r2605 r2614 164 164 xml::THashAttributes attributes = node.getAttributes(); 165 165 166 if (attributes.end() != attributes.find("src")) 167 { 168 StdIFStream ifs ( attributes["src"].c_str() , StdIFStream::in ); 169 if ( (ifs.rdstate() & std::ifstream::failbit ) != 0 ) 170 { 171 ERROR("void CContext::parse(xml::CXMLNode & node)", 172 <<endl<< "Can not open <"<<attributes["src"].c_str()<<"> file" ); 173 } 174 if (!ifs.good()) 175 ERROR("CContext::parse(xml::CXMLNode & node)", 176 << "[ filename = " << attributes["src"] << " ] Bad xml stream !"); 177 xml::CXMLParser::ParseInclude(ifs, attributes["src"], *this); 178 } 179 166 if (attributes.end() != attributes.find("src")) xml::CXMLParser::ParseInclude(attributes["src"], *this); 167 180 168 if (node.getElementName().compare(CContext::GetName())) 181 169 DEBUG("Le noeud is wrong defined but will be considered as a context !"); … … 211 199 } while (node.goToNextElement()); 212 200 201 node.goToParentElement(); // Retour au parent 202 } 203 } 204 CATCH_DUMP_ATTR 205 206 207 template <> 208 void CGroupTemplate<CContext, CContextGroup, CContextAttributes>::parse(xml::CXMLNode & node, bool withAttr, const std::set<StdString>& parseContextList) 209 TRY 210 { 211 StdString name = node.getElementName(); 212 xml::THashAttributes attributes = node.getAttributes(); 213 CGroupTemplate<CContext, CContextGroup, CContextAttributes>::SuperClass::parse(node); 214 if (attributes.end() != attributes.find("src")) xml::CXMLParser::ParseInclude(attributes["src"].c_str(), *this, parseContextList); 215 216 if (!(node.goToChildElement())) 217 { 218 // no children ? 219 } 220 else 221 { 222 do // Parcours pour traitement. 223 { 224 225 StdString name = node.getElementName(); 226 attributes.clear(); 227 attributes = node.getAttributes(); 228 229 if (name.compare(CContextGroup::GetName()) == 0) 230 { 231 CContextGroup contextGroup ; 232 contextGroup.parse(node, true, parseContextList) ; 233 continue; 234 } 235 236 if (name.compare(CContext::GetName()) == 0) 237 { 238 if (attributes.end() == attributes.find("id")) 239 { 240 DEBUG("The context will not be processed because it is not identified (missing id)"); 241 continue; 242 } 243 else 244 { 245 if (parseContextList.empty() || parseContextList.count(attributes["id"]) > 0) 246 { 247 CContext::setCurrent(attributes["id"]) ; 248 CContext* context = CContext::create(attributes["id"]); 249 context->parse(node); 250 attributes.clear(); 251 } 252 continue; 253 } 254 } 255 256 DEBUG(<< "Dans le contexte \'" << CContext::getCurrent()->getId() 257 << "\', un objet de type \'" << CContextGroup::GetName() 258 << "\' ne peut contenir qu'un objet de type \'" << CContextGroup::GetName() 259 << "\' ou de type \'" << CContext::GetName() 260 << "\' (reçu : " << name << ") !"); 261 262 } while (node.goToNextElement()); 213 263 node.goToParentElement(); // Retour au parent 214 264 } -
XIOS3/trunk/src/node/context.hpp
r2547 r2614 409 409 DECLARE_GROUP(CContext); 410 410 411 template <> 412 void CGroupTemplate<CContext, CContextGroup, CContextAttributes>::parse(xml::CXMLNode & node, bool withAttr, const std::set<StdString>& parseContextList) ; 413 411 414 ///-------------------------------------------------------------- 412 415 -
XIOS3/trunk/src/string_tools.hpp
r1585 r2614 9 9 { 10 10 std::vector<std::string> splitRegex(const std::string& input, const std::string& regex) ; 11 std::string strTrim(const std::string& input) ; 11 12 12 13 inline std::vector<std::string> splitRegex(const std::string& input, const std::string& regex) … … 20 21 } 21 22 23 inline std::string strTrim(const std::string& input) 24 { 25 return std::regex_replace(input, std::regex("^ +| +$"), "$1"); 26 } 22 27 } 23 28 #endif -
XIOS3/trunk/src/xml_parser.cpp
r1622 r2614 11 11 namespace xml 12 12 { 13 string CXMLParser::currentIncludePath_="." ; 14 15 string CXMLParser::updateIncludePath(const string& filePath) 16 { 17 string path = strTrim(filePath) ; 18 vector<string> match=splitRegex(path+'/',"/" ) ; 19 20 // check if empty path 21 bool isEmpty=true ; 22 for(auto& m : match) 23 if (!m.empty()) 24 { 25 isEmpty=false ; 26 break ; 27 } 28 29 if (isEmpty) ERROR("string CXMLParser::updatePath(const string& filePath)", 30 << "File path to include an new XML is empty :'"<<filePath<<"'" ); 31 32 if (match.back().empty()) ERROR("string CXMLParser::updatePath(const string& filePath)", 33 << "File path to include an new XML must not be a directory but a file :'"<<filePath<<"'" ); 34 bool isAbsolutePath = match.front().empty() ; 35 36 if (isAbsolutePath) currentIncludePath_="" ; 37 for(int i=0; i<match.size()-1; ++i) if (! match[i].empty()) currentIncludePath_ = currentIncludePath_ + "/" + match[i] ; 38 39 string finalPath = currentIncludePath_ + "/" + match.back() ; 40 41 return finalPath ; 42 } 43 13 44 /// ////////////////////// Définitions ////////////////////// /// 14 45 … … 52 83 << "Root element should be named simulation (actual = \'" 53 84 << node.getElementName() << "\')!"); 54 55 std::set<StdString>::iterator it;56 std::set<StdString>::const_iterator itE = parseContextList.end();57 bool isParseAll = (parseContextList.empty());58 85 try 59 86 { 60 if (node.goToChildElement()) 61 { 62 do 63 { 64 CContextGroup* group_context = CContext::getRoot() ; 65 66 attributes = node.getAttributes(); 67 68 if (attributes.end() == attributes.find("id")) 69 { 70 DEBUG("The context will not be processed because it is not identified (missing id)"); 71 continue; 72 } 73 74 CContext::setCurrent(attributes["id"]) ; 75 76 if (isParseAll) 77 { 78 CContext* context = CContext::create(attributes["id"]); 79 context->parse(node); 80 81 attributes.clear(); 82 } 83 else 84 { 85 it = parseContextList.find(attributes["id"]); 86 if (itE != it) 87 { 88 CContext* context = CContext::create(*it); 89 context->parse(node); 90 91 attributes.clear(); 92 } 93 } 94 } while (node.goToNextElement()); 95 } 87 CContextGroup* rootContext = CContext::getRoot() ; 88 rootContext->parse(node, true, parseContextList) ; 96 89 } 97 90 catch(CException& e) -
XIOS3/trunk/src/xml_parser.hpp
r1622 r2614 21 21 static void ParseString(const StdString & xmlContent); 22 22 static void ParseStream(StdIStream & stream, const string& fluxId, const std::set<StdString>& parseList); 23 24 template <class T> 25 static void ParseInclude(const string& fluxId, T & object); 26 23 27 template <class T> 24 static void ParseInclude(StdIStream & stream, const string& fluxId, T & object);28 static void ParseInclude(const string& fluxId, T & object, const std::set<StdString>& parseContextList); 25 29 30 static string updateIncludePath(const string& filePath) ; 31 32 private: 33 static string currentIncludePath_ ; // current include path for XML file 26 34 }; //class CXMLParser 27 /* 28 template <class T> 29 void CXMLParser::ParseInclude(StdIStream & stream, T& object) 30 { 31 StdOStringStream oss; 32 while(!stream.eof() && !stream.fail ()) 33 oss.put(stream.get()); 34 try 35 { 36 const StdString xmlcontent( oss.str(), 0, oss.str().size()-1 ); 37 rapidxml::xml_document<char> doc; 38 doc.parse<0>(const_cast<char*>(xmlcontent.c_str())); 39 CXMLNode node(doc.first_node()); 40 object.parse(node); 41 } 42 catch (rapidxml::parse_error & exc) 43 { 44 ERROR("CXMLParser::ParseStream(StdIStream & stream)", 45 << "RapidXML error : " << exc.what() << " !"); 46 } 47 } 48 */ 35 49 36 }// namespace xml 50 37 } // namespace xios -
XIOS3/trunk/src/xml_parser_decl.cpp
r2507 r2614 7 7 namespace xml 8 8 { 9 template void CXMLParser::ParseInclude<CContext>( StdIStream & stream,const string& fluxId, CContext& object) ;9 template void CXMLParser::ParseInclude<CContext>(const string& fluxId, CContext& object) ; 10 10 11 11 # define macro(T) \ 12 template void CXMLParser::ParseInclude< CGroupTemplate<C##T, C##T##Group, C##T##Attributes> >( StdIStream & stream,const string& fluxId, CGroupTemplate<C##T, C##T##Group, C##T##Attributes>& object) ;12 template void CXMLParser::ParseInclude< CGroupTemplate<C##T, C##T##Group, C##T##Attributes> >(const string& fluxId, CGroupTemplate<C##T, C##T##Group, C##T##Attributes>& object) ; 13 13 14 14 macro( Context ) … … 47 47 macro( RedistributeAxis ) 48 48 macro( RedistributeScalar ) 49 # undef macro 49 50 51 # define macro(T) \ 52 template void CXMLParser::ParseInclude< CGroupTemplate<C##T, C##T##Group, C##T##Attributes> >(const string& fluxId, CGroupTemplate<C##T, C##T##Group, C##T##Attributes>& object, const std::set<StdString>& parseContextList) ; 53 macro( Context ) 54 # undef macro 50 55 } 51 56 } -
XIOS3/trunk/src/xml_parser_impl.hpp
r1622 r2614 9 9 namespace xml 10 10 { 11 template <class T> void CXMLParser::ParseInclude( StdIStream & stream,const string& fluxId, T& object)11 template <class T> void CXMLParser::ParseInclude(const string& fluxId, T& object) 12 12 { 13 string parentPath = currentIncludePath_ ; 14 string filePath = updateIncludePath(fluxId) ; 15 16 StdIFStream stream(filePath, StdIFStream::in ) ; 17 if ( (stream.rdstate() & std::ifstream::failbit ) != 0 ) 18 ERROR("template <class T> void CXMLParser::ParseInclude(const string& fluxId, T& object)", 19 <<endl<< "Can not open <"<<fluxId<<"> file" ); 20 21 if (!stream.good()) 22 ERROR("template <class T> void CXMLParser::ParseInclude(const string& fluxId, T& object)", 23 << "[ filename = " << fluxId << " ] Bad xml stream !"); 24 13 25 StdOStringStream oss; 14 26 while(!stream.eof() && !stream.fail ()) oss.put(stream.get()); … … 20 32 CXMLNode node(doc.first_node()); 21 33 object.parse(node); 34 currentIncludePath_ = parentPath ; 22 35 } 23 36 catch (rapidxml::parse_error & exc) … … 44 57 } 45 58 59 template <class T> void CXMLParser::ParseInclude(const string& fluxId, T& object, const std::set<StdString>& parseContextList) 60 { 61 62 string parentPath = currentIncludePath_ ; // save current path 63 string filePath = updateIncludePath(fluxId) ; // path is updated 64 65 StdIFStream stream(filePath, StdIFStream::in ) ; 66 if ( (stream.rdstate() & std::ifstream::failbit ) != 0 ) 67 ERROR("template <class T> void CXMLParser::ParseInclude(const string& fluxId, T& object)", 68 <<endl<< "Can not open <"<<fluxId<<"> file" ); 69 70 if (!stream.good()) 71 ERROR("template <class T> void CXMLParser::ParseInclude(const string& fluxId, T& object)", 72 << "[ filename = " << fluxId << " ] Bad xml stream !"); 73 74 75 StdOStringStream oss; 76 while(!stream.eof() && !stream.fail ()) oss.put(stream.get()); 77 const StdString xmlcontent( oss.str(), 0, oss.str().size()-1 ); 78 try 79 { 80 rapidxml::xml_document<char> doc; 81 doc.parse<0>(const_cast<char*>(xmlcontent.c_str())); 82 CXMLNode node(doc.first_node()); 83 object.parse(node, true, parseContextList); 84 currentIncludePath_ = parentPath ; // restore include path 85 } 86 catch (rapidxml::parse_error & exc) 87 { 88 const char* ptr = exc.where<char>() ; 89 const char* begin = xmlcontent.c_str() ; 90 const char* content=oss.str().c_str() ; 91 size_t pos=ptr-begin ; 92 int lineNumber = 1 ; 93 int columnNumber = 0 ; 94 const char* line; 95 const char* endLine; 96 97 for(const char* i=content;i<content+pos; ++i, ++columnNumber) if (*i=='\n') { lineNumber++ ; line=i ; columnNumber=0 ;} 98 for(endLine=content+pos; *endLine!='\n' && *endLine!='\0' ; ++endLine) ; 99 string strLine(line,endLine-line) ; 100 101 ERROR("CXMLParser::ParseStream(StdIStream & stream)", << endl 102 << "Error is occuring when parsing XML flux from <"<<fluxId<<"> at character "<< pos<<" line "<<lineNumber<<" column "<< columnNumber<< endl 103 << strLine<<endl 104 << string(columnNumber-1,'x')<<'^'<<endl) 105 // <<" Error : " << exc.what() ) 106 } 107 } 108 109 46 110 } // namespace xml 47 111 } // namespace xios
Note: See TracChangeset
for help on using the changeset viewer.