source: XMLIO_V2/dev/common/src/xmlio/node/file.cpp @ 286

Last change on this file since 286 was 286, checked in by ymipsl, 13 years ago

reprise en main de la version de H. Ozdoba. Correction de différentes erreurs de conception et bug.
Version NEMO operationnel en client/server, interoperabilita avec OASIS, reconstition de fichiers via netcdf4/HDF5

YM

File size: 8.0 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<io::CDataOutput> CFile::getDataOutput(void) const
37   {
38      return (data_out);
39   }
40
41   boost::shared_ptr<CFieldGroup> CFile::getVirtualFieldGroup(void) const
42   {
43      return (this->vFieldGroup);
44   }
45
46   std::vector<boost::shared_ptr<CField> > CFile::getAllFields(void) const
47   {
48      return (this->vFieldGroup->getAllChildren());
49   }
50
51   //----------------------------------------------------------------
52
53   std::vector<boost::shared_ptr<CField> > CFile::getEnabledFields
54      (int default_outputlevel, int default_level, bool default_enabled)
55   {
56      if (!this->enabledFields.empty())
57         return (this->enabledFields);
58
59      const int _outputlevel =
60         (!output_level.isEmpty()) ? output_level.getValue() : default_outputlevel;
61      std::vector<boost::shared_ptr<CField> >::iterator it;
62      this->enabledFields = this->getAllFields();
63
64      std::cout<<"---> File :"<<this->name.getValue()<<std::endl ;
65      for ( it = this->enabledFields.begin() ; it != this->enabledFields.end(); it++ )
66      {
67         if (!(*it)->enabled.isEmpty()) // Si l'attribut 'enabled' est défini ...
68         {
69            if (! (*it)->enabled.getValue())
70            { it--; this->enabledFields.erase(it+1); continue; }
71         }
72         else // Si l'attribut 'enabled' n'est pas défini ...
73         {
74            if (!default_enabled)
75            { it--; this->enabledFields.erase(it+1); continue; }
76         }
77
78         if (!(*it)->level.isEmpty()) // Si l'attribut 'level' est défini ...
79         {
80            if ((*it)->level.getValue() > _outputlevel)
81            { it--; this->enabledFields.erase(it+1); continue; }
82         }
83         else // Si l'attribut 'level' n'est pas défini ...
84         {
85            if (default_level > _outputlevel)
86            { it--; this->enabledFields.erase(it+1); continue; }
87         }
88
89         // Le champ est finalement actif, on y ajoute sa propre reference.
90         (*it)->refObject.push_back(*it);
91         // Le champ est finalement actif, on y ajoute la référence au champ de base.
92         std::cout<<"    Field Enabled : "<<(*it)->getId()<<std::endl ;
93         (*it)->setRelFile(CObjectFactory::GetObject(this));
94         (*it)->baseRefObject->refObject.push_back(*it);
95         // A faire, ajouter les references intermediaires...
96      }
97
98      return (this->enabledFields);
99   }
100
101   //----------------------------------------------------------------
102
103   void CFile::setVirtualFieldGroup(boost::shared_ptr<CFieldGroup> newVFieldGroup)
104   { 
105      this->vFieldGroup = newVFieldGroup; 
106   }
107
108   //----------------------------------------------------------------
109
110   void CFile::setVirtualFieldGroup(const StdString & newVFieldGroupId)
111   {
112      this->setVirtualFieldGroup
113         (CObjectFactory::CreateObject<CFieldGroup>(/*newVFieldGroupId*/));
114   }
115
116   //----------------------------------------------------------------
117
118   void CFile::initializeDataOutput(boost::shared_ptr<io::CDataOutput> dout)
119   {
120      this->data_out = dout;
121      this->data_out->writeFile(CObjectFactory::GetObject<CFile>(this));
122     
123      std::vector<boost::shared_ptr<CField> >::iterator it, end = this->enabledFields.end();
124
125      for (it = this->enabledFields.begin() ;it != end; it++)
126      {
127         boost::shared_ptr<CField> field = *it;
128         this->data_out->writeFieldGrid(field);
129      }
130         
131      for (it = this->enabledFields.begin() ;it != end; it++)
132      {
133         boost::shared_ptr<CField> field = *it;
134         this->data_out->writeField(field);
135      }
136         
137      this->data_out->definition_end();
138   }
139
140   void CFile::close(void)
141   {
142     this->data_out->closeFile();
143   }
144   //----------------------------------------------------------------
145
146   void CFile::parse(xml::CXMLNode & node)
147   {
148      SuperClass::parse(node);
149      if (node.goToChildElement() & this->hasId())
150      { // Si la définition du fichier intégre des champs et si le fichier est identifié.
151         node.goToParentElement();
152         this->setVirtualFieldGroup(this->getId());
153         this->getVirtualFieldGroup()->parse(node, false);
154      }
155   }
156   //----------------------------------------------------------------
157
158   StdString CFile::toString(void) const
159   {
160      StdOStringStream oss;
161
162      oss << "<" << CFile::GetName() << " ";
163      if (this->hasId())
164         oss << " id=\"" << this->getId() << "\" ";
165      oss << SuperClassAttribute::toString() << ">" << std::endl;
166      if (this->getVirtualFieldGroup().get() != NULL)
167         oss << *this->getVirtualFieldGroup() << std::endl;
168      oss << "</" << CFile::GetName() << " >";
169      return (oss.str());
170   }
171
172   //----------------------------------------------------------------
173   
174   void CFile::solveDescInheritance(const CAttributeMap * const parent)
175   {
176      SuperClassAttribute::setAttributes(parent);
177      this->getVirtualFieldGroup()->solveDescInheritance(NULL);
178   }
179
180   //----------------------------------------------------------------
181
182   void CFile::solveFieldRefInheritance(void)
183   {
184      // Résolution des héritages par référence de chacun des champs contenus dans le fichier.
185      std::vector<boost::shared_ptr<CField> > allF = this->getAllFields();
186      for (unsigned int i = 0; i < allF.size(); i++)
187         allF[i]->solveRefInheritance();
188   }
189
190   //----------------------------------------------------------------
191
192   void CFile::solveEFGridRef(void)
193   {
194      for (unsigned int i = 0; i < this->enabledFields.size(); i++)
195         this->enabledFields[i]->solveGridReference();
196   }
197
198   //----------------------------------------------------------------
199
200   void CFile::solveEFOperation(void)
201   {
202      for (unsigned int i = 0; i < this->enabledFields.size(); i++)
203         this->enabledFields[i]->solveOperation();
204   }
205   
206   //---------------------------------------------------------------
207   
208   void CFile::toBinary  (StdOStream & os) const
209   {
210      ENodeType genum = CFileGroup::GetType();
211      bool hasVFG = (this->getVirtualFieldGroup().get() != NULL);
212      SuperClass::toBinary(os);
213     
214      os.write (reinterpret_cast<const char*>(&genum) , sizeof(ENodeType));
215      os.write (reinterpret_cast<const char*>(&hasVFG) , sizeof(bool));
216     
217      if (hasVFG)this->getVirtualFieldGroup()->toBinary(os);
218         
219   }
220   
221   //----------------------------------------------------------------
222   
223   void CFile::fromBinary(StdIStream & is)
224   {
225      ENodeType renum = Unknown;
226      bool hasVFG = false;
227      SuperClass::fromBinary(is);
228     
229      is.read (reinterpret_cast<char*>(&renum), sizeof(ENodeType));
230      is.read (reinterpret_cast<char*>(&hasVFG), sizeof(bool));
231     
232      if (renum != CFileGroup::GetType())
233         ERROR("CFile::fromBinary(StdIStream & is)",
234               << "[ renum = " << renum << "] Bad type !");
235     
236      this->setVirtualFieldGroup(this->getId());
237      if (hasVFG)this->getVirtualFieldGroup()->fromBinary(is);
238     
239   }
240
241   ///---------------------------------------------------------------
242
243} // namespace tree
244} // namespace xmlioserver
Note: See TracBrowser for help on using the repository browser.