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

Last change on this file since 173 was 173, checked in by hozdoba, 13 years ago
File size: 5.8 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   { this->vFieldGroup = newVFieldGroup; }
95
96   void CFile::setVirtualFieldGroup(const StdString & newVFieldGroupId)
97   {
98      this->setVirtualFieldGroup
99         (CObjectFactory::CreateObject<CFieldGroup>(newVFieldGroupId));
100   }
101
102   void CFile::initializeDataOutput(boost::shared_ptr<io::CDataOutput> dout)
103   {
104      this->data_out = dout;
105      this->data_out->writeFile(CObjectFactory::GetObject<CFile>(this));
106     
107      std::vector<boost::shared_ptr<CField> >::iterator it, end = this->enabledFields.end();
108
109      for (it = this->enabledFields.begin() ;it != end; it++)
110      {
111         boost::shared_ptr<CField> field = *it;
112         this->data_out->writeFieldGrid(field);
113      }
114         
115      for (it = this->enabledFields.begin() ;it != end; it++)
116      {
117         boost::shared_ptr<CField> field = *it;
118         this->data_out->writeField(field);
119      }
120         
121      this->data_out->definition_end();
122   }
123
124   void CFile::parse(xml::CXMLNode & node)
125   {
126      SuperClass::parse(node);
127      if (node.goToChildElement() & this->hasId())
128      { // Si la définition du fichier intégre des champs et si le fichier est identifié.
129         node.goToParentElement();
130         this->setVirtualFieldGroup(this->getId());
131         this->getVirtualFieldGroup()->parse(node, false);
132      }
133   }
134   //----------------------------------------------------------------
135
136   StdString CFile::toString(void) const
137   {
138      StdOStringStream oss;
139
140      oss << "<" << CFile::GetName() << " ";
141      if (this->hasId())
142         oss << " id=\"" << this->getId() << "\" ";
143      oss << SuperClassAttribute::toString() << ">" << std::endl;
144      if (this->getVirtualFieldGroup().get() != NULL)
145         oss << *this->getVirtualFieldGroup() << std::endl;
146      oss << "</" << CFile::GetName() << " >";
147      return (oss.str());
148   }
149
150
151   void CFile::solveDescInheritance(const CAttributeMap * const parent)
152   {
153      SuperClassAttribute::setAttributes(parent);
154      this->getVirtualFieldGroup()->solveDescInheritance(NULL);
155   }
156
157   void CFile::solveFieldRefInheritance(void)
158   {
159      // Résolution des héritages par référence de chacun des champs contenus dans le fichier.
160      std::vector<boost::shared_ptr<CField> > allF = this->getAllFields();
161      for (unsigned int i = 0; i < allF.size(); i++)
162         allF[i]->solveRefInheritance();
163   }
164
165   void CFile::solveEFGridRef(void)
166   {
167      for (unsigned int i = 0; i < this->enabledFields.size(); i++)
168         this->enabledFields[i]->solveGridReference();
169   }
170
171   void CFile::solveEFOperation(void)
172   {
173      for (unsigned int i = 0; i < this->enabledFields.size(); i++)
174         this->enabledFields[i]->solveOperation();
175   }
176
177   ///---------------------------------------------------------------
178
179} // namespace tree
180} // namespace xmlioserver
Note: See TracBrowser for help on using the repository browser.