source: XMLIO_V2/dev/dev_rv/src/XMLIO/file.hpp @ 120

Last change on this file since 120 was 120, checked in by hozdoba, 14 years ago

Mise à jour intermédiaire ...
A venir : commit d'une version stable intégrant l'écriture de fichiers NetCDF4.
(en cours de finalisation actuellement)

File size: 3.9 KB
Line 
1#ifndef __CFILE__
2#define __CFILE__
3
4using XMLIOSERVER::XML::XMLNode;
5using XMLIOSERVER::XML::THashAttributes;
6
7namespace XMLIOSERVER
8{
9   class CFile : public ObjectTemplate<CFile>, public FileAttribut
10   {
11      public:
12
13         CFile(void) : ObjectTemplate<CFile>(), FileAttribut(), vfieldGroup(NULL), enabledFields()
14         {/* Ne rien faire de plus */}
15         CFile(const string& _id) : ObjectTemplate<CFile>(_id), FileAttribut(), vfieldGroup(NULL), enabledFields()
16         {/* Ne rien faire de plus */}
17
18         static string GetName(void) { return ("file"); }
19
20         virtual void parse (XMLNode& _node)
21         {
22            string name = _node.getElementName();
23            THashAttributes attributes;
24
25            /// PARSING GESTION DES ATTRIBUTS ///
26            _node.getAttributes(attributes);
27            this->setAttributes(attributes);
28            attributes.clear();
29
30            /// PARSING POUR GESION DES ENFANTS ///
31            if (_node.goToChildElement() and hasId())
32            { // Si la définition du fichier intégre des champs et si le fichier est identifié.
33               _node.goToParentElement();
34               vfieldGroup = CreateInstanceAndParse<FieldGroup>(_node, getId().c_str(), false );
35            }
36         }
37
38         void getAllFields(std::vector<CField*>& _allF) const {  if (vfieldGroup!=NULL) vfieldGroup->getAllChildren(_allF); }
39
40         virtual bool hasChild(void) const { return (vfieldGroup != NULL); }
41
42         virtual void printChild(ostream& out) const { out << *vfieldGroup << std::endl; }
43         /*{ // Sortie sans affichage des groupes.
44            std::vector<CField*> allF; getAllFields(allF);
45            for (unsigned int i = 0; i < allF.size(); i++)
46               out << *(allF[i]) << std::endl;
47         }*/
48
49         virtual void resolveDescInheritance(const AttributRegistrar* _parent = 0)
50         { addAttributes(*_parent); if(vfieldGroup != NULL) vfieldGroup->resolveDescInheritance(); }
51
52         void resolveFieldRefInheritance(void)
53         { // Résolution des héritages par référence de chacun des champs contenus dans le fichier.
54            std::vector<CField*> allF; getAllFields(allF);
55            for (unsigned int i = 0; i < allF.size(); i++) allF[i]->resolveRefInheritance();
56         }
57
58         FieldGroup* getVirtualFieldGroup(void) { return (vfieldGroup); }
59
60         void findEnabledFields(int default_outputlevel = 5, int default_level = 1, bool default_enabled = true )
61         {
62            const int _outputlevel = (output_level.hasValue()) ? (int)output_level : default_outputlevel;
63            std::vector<CField*>::iterator it;
64
65            getAllFields(enabledFields);
66
67            for ( it = enabledFields.begin() ; it < enabledFields.end(); it++ )
68            {
69               if ((*it)->enabled.hasValue()) // Si l'attribut 'enabled' est défini ...
70               {
71                  if (! ((*it)->enabled))
72                  { enabledFields.erase(it); continue; }
73               }
74               else // Si l'attribut 'enabled' n'est pas défini ...
75               {
76                  if (!default_enabled)
77                  { enabledFields.erase(it); continue; }
78               }
79
80               if ((*it)->level.hasValue()) // Si l'attribut 'level' est défini ...
81               {
82                  if ((*it)->level > _outputlevel)
83                  { enabledFields.erase(it); continue; }
84               }
85               else // Si l'attribut 'level' n'est pas défini ...
86               {
87                  if (default_level > _outputlevel)
88                  { enabledFields.erase(it); continue; }
89               }
90
91            }
92         }
93
94         virtual  ~CFile(void)
95         { if(vfieldGroup != NULL) delete vfieldGroup; }
96
97      private :
98
99         FieldGroup* vfieldGroup; // FieldGroup "virtuel"
100         std::vector<CField*> enabledFields;
101
102   }; // class CFile
103
104} // namespace XMLIOSERVER
105
106DECLARE_GROUP(File)
107
108
109#endif // __CFILE__
Note: See TracBrowser for help on using the repository browser.