source: XMLIO_V2/dev/dev_rv/src/xmlio/node/context.cpp @ 173

Last change on this file since 173 was 173, checked in by hozdoba, 13 years ago
File size: 7.9 KB
RevLine 
[152]1#include "context.hpp"
2
[173]3#include "tree_manager.hpp"
4
[152]5#include "attribute_template_impl.hpp"
6#include "object_template_impl.hpp"
7#include "group_template_impl.hpp"
8
[168]9namespace xmlioserver {
10namespace tree {
11   
12   /// ////////////////////// Définitions ////////////////////// ///
[152]13
[168]14   CContext::CContext(void)
15      : CObjectTemplate<CContext>(), CContextAttributes()
16   { /* Ne rien faire de plus */ }
[152]17
[168]18   CContext::CContext(const StdString & id)
19      : CObjectTemplate<CContext>(id), CContextAttributes()
20   { /* Ne rien faire de plus */ }
[152]21
[168]22   CContext::~CContext(void)
23   { /* Ne rien faire de plus */ }
[152]24
[168]25   //----------------------------------------------------------------
[152]26
[168]27   StdString CContext::GetName(void)   { return (StdString("context")); }
28   StdString CContext::GetDefName(void){ return (CContext::GetName()); }
29   ENodeType CContext::GetType(void)   { return (eContext); }
[152]30
[168]31   //----------------------------------------------------------------
[152]32
[168]33   boost::shared_ptr<CContextGroup> CContext::GetContextGroup(void)
34   { 
35      static boost::shared_ptr<CContextGroup> group_context
36                          (new CContextGroup(xml::CXMLNode::GetRootName()));
37      return (group_context); 
38   }
[152]39
[168]40   //----------------------------------------------------------------
[152]41
[168]42   void CContext::parse(xml::CXMLNode & node)
43   {
44      CContext::SuperClass::parse(node);
[152]45
[168]46      // PARSING POUR GESTION DES ENFANTS
47      xml::THashAttributes attributes;
[152]48
[168]49      if (node.getElementName().compare(CContext::GetName()))
50         DEBUG("Le noeud est mal nommé mais sera traité comme un contexte !");
[152]51
[168]52      if (!(node.goToChildElement()))
53      {
54         DEBUG("Le context ne contient pas d'enfant !");
55      }
56      else
57      {
58         do { // Parcours des contextes pour traitement.
[152]59
[168]60            StdString name = node.getElementName();
61            attributes.clear();
62            attributes = node.getAttributes();
[152]63
[168]64            if (attributes.end() != attributes.find("id"))
65            { DEBUG(<< "Le noeud de définition possÚde un identifiant,"
66                    << " ce dernier ne sera pas pris en compte lors du traitement !"); }
[152]67
[173]68#define DECLARE_NODE(Name_, name_)    \
69   if (name.compare(C##Name_##Definition::GetDefName()) == 0) \
70   { CObjectFactory::CreateObject<C##Name_##Definition>(C##Name_##Definition::GetDefName()) -> parse(node); \
[168]71   continue; }
[173]72#define DECLARE_NODE_PAR(Name_, name_)
73#include "node_type.conf"
[152]74
[168]75            DEBUG(<< "L'élément nommé \'"     << name
76                  << "\' dans le contexte \'" << CObjectFactory::GetCurrentContextId()
77                  << "\' ne représente pas une définition !");
[152]78
[168]79         } while (node.goToNextElement());
[152]80
[168]81         node.goToParentElement(); // Retour au parent
[152]82      }
[168]83   }
[152]84
[168]85   //----------------------------------------------------------------
[152]86
[168]87   void CContext::ShowTree(StdOStream & out)
88   {
89      StdString currentContextId =
90         CObjectFactory::GetCurrentContextId();
91      std::vector<boost::shared_ptr<CContext> > def_vector =
92         CContext::GetContextGroup()->getChildList();
93      std::vector<boost::shared_ptr<CContext> >::iterator
94         it = def_vector.begin(), end = def_vector.end();
[152]95
[168]96      out << "<? xml version=\"1.0\" ?>" << std::endl;
[173]97      out << "<"  << xml::CXMLNode::GetRootName() << " >" << std::endl;
[168]98     
99      for (; it != end; it++)
100      {
[173]101         boost::shared_ptr<CContext> context = *it;         
102         CTreeManager::SetCurrentContextId(context->getId());         
[168]103         out << *context << std::endl;
104      }
105     
[173]106      out << "</" << xml::CXMLNode::GetRootName() << " >" << std::endl;
107      CTreeManager::SetCurrentContextId(currentContextId); 
[168]108   }
[173]109   
[168]110   //----------------------------------------------------------------
[173]111   
112   void CContext::toBinary(StdOStream & os) const
113   {
114      SuperClass::toBinary(os);
115       
116#define DECLARE_NODE(Name_, name_)                                         \
117   {                                                                       \
118      ENodeType renum = C##Name_##Definition::GetType();                   \
119      bool val = CObjectFactory::HasObject<C##Name_##Definition>           \
120                     (C##Name_##Definition::GetDefName());                 \
121      os.write (reinterpret_cast<const char*>(&renum), sizeof(ENodeType)); \
122      os.write (reinterpret_cast<const char*>(&val), sizeof(bool));        \
123      if (val) CObjectFactory::GetObject<C##Name_##Definition>             \
124                     (C##Name_##Definition::GetDefName())->toBinary(os);   \
125   }   
126#define DECLARE_NODE_PAR(Name_, name_)
127#include "node_type.conf"
128   }
129   
130   //----------------------------------------------------------------
131   
132   void CContext::fromBinary(StdIStream & is)
133   {
134      SuperClass::fromBinary(is);
135#define DECLARE_NODE(Name_, name_)                                         \
136   {                                                                       \
137      bool val = false;                                                    \
138      ENodeType renum = Unknown;                                           \
139      is.read (reinterpret_cast<char*>(&renum), sizeof(ENodeType));        \
140      is.read (reinterpret_cast<char*>(&val), sizeof(bool));               \
141      if (renum != C##Name_##Definition::GetType())                        \
142         ERROR("CContext::fromBinary(StdIStream & is)",                    \
143               << "[ renum = " << renum << "] Bad type !");                \
144      if (val) CObjectFactory::CreateObject<C##Name_##Definition>          \
145                  (C##Name_##Definition::GetDefName()) -> fromBinary(is);  \
146   }   
147#define DECLARE_NODE_PAR(Name_, name_)
148#include "node_type.conf"
149     
150   }
151   
152   
153   //----------------------------------------------------------------
[152]154
[168]155   StdString CContext::toString(void) const
156   {
157      StdOStringStream oss;
[173]158      oss << "<" << CContext::GetName()
[168]159          << " id=\"" << this->getId() << "\" "
160          << SuperClassAttribute::toString() << ">" << std::endl;
161      if (!this->hasChild())
[152]162      {
[168]163         //oss << "<!-- No definition -->" << std::endl; // fait planter l'incrémentation
[152]164      }
[168]165      else
166      {
[152]167
[173]168#define DECLARE_NODE(Name_, name_)    \
169   if (CObjectFactory::HasObject<C##Name_##Definition>(C##Name_##Definition::GetDefName())) \
[168]170   oss << *CObjectFactory::GetObject<C##Name_##Definition>(C##Name_##Definition::GetDefName()) << std::endl;
[173]171#define DECLARE_NODE_PAR(Name_, name_)
172#include "node_type.conf"
[168]173
[152]174      }
175
[173]176      oss << "</" << CContext::GetName() << " >";
[168]177
178      return (oss.str());
179   }
180
181   //----------------------------------------------------------------
182
183   void CContext::solveDescInheritance(const CAttributeMap * const UNUSED(parent))
184   {
[173]185#define DECLARE_NODE(Name_, name_)    \
186   if (CObjectFactory::HasObject<C##Name_##Definition>(C##Name_##Definition::GetDefName())) \
[168]187   CObjectFactory::GetObject<C##Name_##Definition>(C##Name_##Definition::GetDefName())->solveDescInheritance();
[173]188#define DECLARE_NODE_PAR(Name_, name_)
189#include "node_type.conf"
[168]190   }
191
192   //----------------------------------------------------------------
193
194   bool CContext::hasChild(void) const
195   {
[173]196      return (
197#define DECLARE_NODE(Name_, name_)    \
198   CObjectFactory::HasObject<C##Name_##Definition>  (C##Name_##Definition::GetDefName())   ||
199#define DECLARE_NODE_PAR(Name_, name_)
200#include "node_type.conf"
[168]201      false);
[173]202}
[168]203
204   //----------------------------------------------------------------
205
206   void CContext::solveFieldRefInheritance(void)
207   {
208      if (!this->hasId()) return;
209      std::vector<boost::shared_ptr<CField> > allField
210               = CObjectTemplate<CField>::GetAllVectobject(this->getId());
211      std::vector<boost::shared_ptr<CField> >::iterator
212         it = allField.begin(), end = allField.end();
213           
214      for (; it != end; it++)
[152]215      {
[168]216         boost::shared_ptr<CField> field = *it;
217         field->solveRefInheritance();
[152]218      }
[168]219   }
[152]220
[168]221   ///---------------------------------------------------------------
222
223} // namespace tree
[152]224} // namespace xmlioserver
Note: See TracBrowser for help on using the repository browser.