[219] | 1 | #ifndef __XMLIO_GroupParser__ |
---|
| 2 | #define __XMLIO_GroupParser__ |
---|
| 3 | |
---|
| 4 | /// boost headers /// |
---|
| 5 | #include <boost/cast.hpp> |
---|
| 6 | |
---|
| 7 | namespace xmlioserver |
---|
| 8 | { |
---|
| 9 | /// ////////////////////// Définitions ////////////////////// /// |
---|
| 10 | template <class U, class V, class W> |
---|
| 11 | void CGroupTemplate<U, V, W>::parse(xml::CXMLNode & node, bool withAttr) |
---|
| 12 | { |
---|
| 13 | |
---|
| 14 | StdString name = node.getElementName(); |
---|
[278] | 15 | xml::THashAttributes attributes = node.getAttributes(); |
---|
[219] | 16 | if (withAttr) |
---|
[278] | 17 | { |
---|
[219] | 18 | CGroupTemplate<U, V, W>::SuperClass::parse(node); |
---|
[278] | 19 | if (attributes.end() != attributes.find("src")) |
---|
| 20 | { |
---|
| 21 | StdIFStream ifs ( attributes["src"].c_str() , StdIFStream::in ); |
---|
| 22 | if (!ifs.good()) |
---|
| 23 | ERROR("CGroupTemplate<U, V, W>::parse(xml::CXMLNode & node, bool withAttr)", |
---|
| 24 | << "[ filename = " << attributes["src"] << " ] Bad xml stream !"); |
---|
| 25 | xml::CXMLParser::ParseInclude(ifs, *this); |
---|
| 26 | } |
---|
| 27 | } |
---|
[219] | 28 | |
---|
| 29 | // PARSING POUR GESTION DES ENFANTS |
---|
| 30 | boost::shared_ptr<V> group_ptr = (this->hasId()) |
---|
| 31 | ? CObjectFactory::GetObject<V>(this->getId()) |
---|
| 32 | : CObjectFactory::GetObject(boost::polymorphic_downcast<V*>(this)); |
---|
| 33 | |
---|
| 34 | if (!(node.goToChildElement())) |
---|
| 35 | { |
---|
| 36 | if (this->hasId()) |
---|
| 37 | { |
---|
| 38 | DEBUG(<< "L'objet de type \'" << V::GetName() |
---|
| 39 | << "\' nommé \'" << this->getId() |
---|
| 40 | << "\' ne contient pas d\'enfant !"); |
---|
| 41 | } |
---|
| 42 | } |
---|
| 43 | else |
---|
| 44 | { |
---|
| 45 | do { // Parcours pour traitement. |
---|
| 46 | |
---|
| 47 | StdString name = node.getElementName(); |
---|
| 48 | attributes.clear(); |
---|
| 49 | attributes = node.getAttributes(); |
---|
| 50 | |
---|
| 51 | if (name.compare(V::GetName()) == 0) |
---|
| 52 | { |
---|
| 53 | if (attributes.end() == attributes.find("id")) |
---|
| 54 | CGroupFactory::CreateGroup(group_ptr)->parse(node); |
---|
| 55 | else |
---|
| 56 | CGroupFactory::CreateGroup(group_ptr, attributes["id"])->parse(node); |
---|
| 57 | continue; |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | if (name.compare(U::GetName()) == 0) |
---|
| 61 | { |
---|
| 62 | if (attributes.end() == attributes.find("id")) |
---|
| 63 | CGroupFactory::CreateChild(group_ptr)->parse(node); |
---|
| 64 | else |
---|
| 65 | CGroupFactory::CreateChild(group_ptr, attributes["id"])->parse(node); |
---|
| 66 | continue; |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | DEBUG(<< "Dans le contexte \'" << CObjectFactory::GetCurrentContextId() |
---|
| 70 | << "\', un objet de type \'" << V::GetName() |
---|
| 71 | << "\' ne peut contenir qu'un objet de type \'" << V::GetName() |
---|
| 72 | << "\' ou de type \'" << U::GetName() |
---|
[278] | 73 | << "\' (reçu : " << name << ") !"); |
---|
[219] | 74 | |
---|
| 75 | } while (node.goToNextElement()); |
---|
| 76 | node.goToParentElement(); // Retour au parent |
---|
| 77 | } |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | } // namespace xmlioserver |
---|
| 81 | |
---|
| 82 | #endif // __XMLIO_GroupParser__ |
---|