source: XMLIO_V2/dev/dev_rv/src/xmlio/node/file.cpp @ 191

Last change on this file since 191 was 189, checked in by hozdoba, 13 years ago
File size: 7.5 KB
Line 
1#include "file.hpp"
2
3#include "attribute_template_impl.hpp"
4#include "object_template_impl.hpp"
5#include "group_template_impl.hpp"
6
7#include "object_factory.hpp"
8#include "object_factory_impl.hpp"
9
10namespace xmlioserver {
11namespace tree {
12   
13   /// ////////////////////// Définitions ////////////////////// ///
14
15   CFile::CFile(void)
16      : CObjectTemplate<CFile>(), CFileAttributes()
17      , vFieldGroup(), data_out(), enabledFields()
18   { /* Ne rien faire de plus */ }
19
20   CFile::CFile(const StdString & id)
21      : CObjectTemplate<CFile>(id), CFileAttributes()
22      , vFieldGroup(), data_out(), enabledFields()
23   { /* Ne rien faire de plus */ }
24
25   CFile::~CFile(void)
26   { /* Ne rien faire de plus */ }
27
28   ///---------------------------------------------------------------
29
30   StdString CFile::GetName(void)   { return (StdString("file")); }
31   StdString CFile::GetDefName(void){ return (CFile::GetName()); }
32   ENodeType CFile::GetType(void)   { return (eFile); }
33
34   //----------------------------------------------------------------
35
36   boost::shared_ptr<CFieldGroup> CFile::getVirtualFieldGroup(void) const
37   {
38      return (this->vFieldGroup);
39   }
40
41   std::vector<boost::shared_ptr<CField> > CFile::getAllFields(void) const
42   {
43      return (this->vFieldGroup->getAllChildren());
44   }
45
46   //----------------------------------------------------------------
47
48   std::vector<boost::shared_ptr<CField> > CFile::getEnabledFields
49      (int default_outputlevel, int default_level, bool default_enabled)
50   {
51      if (!this->enabledFields.empty())
52         return (this->enabledFields);
53
54      const int _outputlevel =
55         (!output_level.isEmpty()) ? output_level.getValue() : default_outputlevel;
56      std::vector<boost::shared_ptr<CField> >::iterator it;
57      this->enabledFields = this->getAllFields();
58
59      for ( it = this->enabledFields.begin() ; it != this->enabledFields.end(); it++ )
60      {
61         if (!(*it)->enabled.isEmpty()) // Si l'attribut 'enabled' est défini ...
62         {
63            if (! (*it)->enabled.getValue())
64            { it--; this->enabledFields.erase(it+1); continue; }
65         }
66         else // Si l'attribut 'enabled' n'est pas défini ...
67         {
68            if (!default_enabled)
69            { it--; this->enabledFields.erase(it+1); continue; }
70         }
71
72         if (!(*it)->level.isEmpty()) // Si l'attribut 'level' est défini ...
73         {
74            if ((*it)->level.getValue() > _outputlevel)
75            { it--; this->enabledFields.erase(it+1); continue; }
76         }
77         else // Si l'attribut 'level' n'est pas défini ...
78         {
79            if (default_level > _outputlevel)
80            { it--; this->enabledFields.erase(it+1); continue; }
81         }
82
83         // Le champ est finalement actif, on ajoute la référence au champ de base.
84         (*it)->setRelFile(CObjectFactory::GetObject(this));
85         (*it)->baseRefObject->refObject.push_back(*it);
86      }
87
88      return (this->enabledFields);
89   }
90
91   //----------------------------------------------------------------
92
93   void CFile::setVirtualFieldGroup(boost::shared_ptr<CFieldGroup> newVFieldGroup)
94   { 
95      this->vFieldGroup = newVFieldGroup; 
96   }
97
98   //----------------------------------------------------------------
99
100   void CFile::setVirtualFieldGroup(const StdString & newVFieldGroupId)
101   {
102      this->setVirtualFieldGroup
103         (CObjectFactory::CreateObject<CFieldGroup>(newVFieldGroupId));
104   }
105
106   //----------------------------------------------------------------
107
108   void CFile::initializeDataOutput(boost::shared_ptr<io::CDataOutput> dout)
109   {
110      this->data_out = dout;
111      this->data_out->writeFile(CObjectFactory::GetObject<CFile>(this));
112     
113      std::vector<boost::shared_ptr<CField> >::iterator it, end = this->enabledFields.end();
114
115      for (it = this->enabledFields.begin() ;it != end; it++)
116      {
117         boost::shared_ptr<CField> field = *it;
118         this->data_out->writeFieldGrid(field);
119      }
120         
121      for (it = this->enabledFields.begin() ;it != end; it++)
122      {
123         boost::shared_ptr<CField> field = *it;
124         this->data_out->writeField(field);
125      }
126         
127      this->data_out->definition_end();
128   }
129
130   //----------------------------------------------------------------
131
132   void CFile::parse(xml::CXMLNode & node)
133   {
134      SuperClass::parse(node);
135      if (node.goToChildElement() & this->hasId())
136      { // Si la définition du fichier intégre des champs et si le fichier est identifié.
137         node.goToParentElement();
138         this->setVirtualFieldGroup(this->getId());
139         this->getVirtualFieldGroup()->parse(node, false);
140      }
141   }
142   //----------------------------------------------------------------
143
144   StdString CFile::toString(void) const
145   {
146      StdOStringStream oss;
147
148      oss << "<" << CFile::GetName() << " ";
149      if (this->hasId())
150         oss << " id=\"" << this->getId() << "\" ";
151      oss << SuperClassAttribute::toString() << ">" << std::endl;
152      if (this->getVirtualFieldGroup().get() != NULL)
153         oss << *this->getVirtualFieldGroup() << std::endl;
154      oss << "</" << CFile::GetName() << " >";
155      return (oss.str());
156   }
157
158   //----------------------------------------------------------------
159   
160   void CFile::solveDescInheritance(const CAttributeMap * const parent)
161   {
162      SuperClassAttribute::setAttributes(parent);
163      this->getVirtualFieldGroup()->solveDescInheritance(NULL);
164   }
165
166   //----------------------------------------------------------------
167
168   void CFile::solveFieldRefInheritance(void)
169   {
170      // Résolution des héritages par référence de chacun des champs contenus dans le fichier.
171      std::vector<boost::shared_ptr<CField> > allF = this->getAllFields();
172      for (unsigned int i = 0; i < allF.size(); i++)
173         allF[i]->solveRefInheritance();
174   }
175
176   //----------------------------------------------------------------
177
178   void CFile::solveEFGridRef(void)
179   {
180      for (unsigned int i = 0; i < this->enabledFields.size(); i++)
181         this->enabledFields[i]->solveGridReference();
182   }
183
184   //----------------------------------------------------------------
185
186   void CFile::solveEFOperation(void)
187   {
188      for (unsigned int i = 0; i < this->enabledFields.size(); i++)
189         this->enabledFields[i]->solveOperation();
190   }
191   
192   //---------------------------------------------------------------
193   
194   void CFile::toBinary  (StdOStream & os) const
195   {
196      ENodeType genum = CFileGroup::GetType();
197      bool hasVFG = (this->getVirtualFieldGroup().get() != NULL);
198      SuperClass::toBinary(os);
199     
200      os.write (reinterpret_cast<const char*>(&genum) , sizeof(ENodeType));
201      os.write (reinterpret_cast<const char*>(&hasVFG) , sizeof(bool));
202     
203      if (hasVFG)this->getVirtualFieldGroup()->toBinary(os);
204         
205   }
206   
207   //----------------------------------------------------------------
208   
209   void CFile::fromBinary(StdIStream & is)
210   {
211      ENodeType renum = Unknown;
212      bool hasVFG = false;
213      SuperClass::fromBinary(is);
214     
215      is.read (reinterpret_cast<char*>(&renum), sizeof(ENodeType));
216      is.read (reinterpret_cast<char*>(&hasVFG), sizeof(bool));
217     
218      if (renum != CFileGroup::GetType())
219         ERROR("CFile::fromBinary(StdIStream & is)",
220               << "[ renum = " << renum << "] Bad type !");
221     
222      this->setVirtualFieldGroup(this->getId());
223      if (hasVFG)this->getVirtualFieldGroup()->fromBinary(is);
224     
225   }
226
227   ///---------------------------------------------------------------
228
229} // namespace tree
230} // namespace xmlioserver
Note: See TracBrowser for help on using the repository browser.