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

Last change on this file since 125 was 125, checked in by hozdoba, 14 years ago
File size: 6.2 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(), output(NULL)
14         {/* Ne rien faire de plus */}
15         CFile(const string& _id) : ObjectTemplate<CFile>(_id), FileAttribut(), vfieldGroup(NULL), enabledFields(), output(NULL)
16         {/* Ne rien faire de plus */}
17
18         static string GetName(void) { return ("file"); }
19         static string GetDefName(void)  { return (CFile::GetName()); }
20
21         virtual void parse (XMLNode& _node)
22         {
23            string name = _node.getElementName();
24            THashAttributes attributes;
25
26            /// PARSING GESTION DES ATTRIBUTS ///
27            _node.getAttributes(attributes);
28            this->setAttributes(attributes);
29            attributes.clear();
30
31            /// PARSING POUR GESION DES ENFANTS ///
32            if (_node.goToChildElement() and hasId())
33            { // Si la définition du fichier intégre des champs et si le fichier est identifié.
34               _node.goToParentElement();
35               vfieldGroup = CreateInstanceAndParse<FieldGroup>(_node, getId().c_str(), false );
36            }
37         }
38
39         AbstractDataOutput* getDataOutput(void) const { return (output); }
40         void initializeDataOutput(AbstractDataOutput* _output)
41         {
42            if (_output != NULL) output = _output;
43            else throw XMLIOSERVER::XMLIOUndefinedValueException("Impossible d'initialiser la sortie de données pour le fichier nommé '"+ getId() +"'.") ;
44         }
45
46         void getAllFields(std::vector<CField*>& _allF) const {  if (vfieldGroup!=NULL) vfieldGroup->getAllChildren(_allF); }
47         const std::vector<CField*>& getEnabledFields(void) const { return (enabledFields); }
48
49         const std::set<const CGrid*> getEnabledGrids(void) const
50         {
51            std::set<const CGrid*> sgrid;
52            const std::vector<CField*> enabledFields = getEnabledFields();
53            std::vector<CField*>::const_iterator it;
54
55            for ( it = enabledFields.begin() ; it != enabledFields.end(); it++ )
56               sgrid.insert((*it)->getGrid());
57
58            return (sgrid);
59         }
60
61         const std::set<const CDomain*> getEnabledDomains(void) const
62         {
63            const std::set<const CGrid*> sgrid = getEnabledGrids();
64            std::set<const CDomain*> sdomain;
65
66            std::set<const CGrid*>::const_iterator it;
67
68            for ( it = sgrid.begin() ; it != sgrid.end(); it++ )
69               sdomain.insert((*it)->getRelDomain());
70
71            return (sdomain);
72         }
73
74         const std::set<const CAxis*> getEnabledAxis(void) const
75         {
76            const std::set<const CGrid*> sgrid = getEnabledGrids();
77            std::set<const CAxis*> saxis;
78
79            std::set<const CGrid*>::const_iterator it;
80
81            for ( it = sgrid.begin() ; it != sgrid.end(); it++ )
82               saxis.insert((*it)->getRelAxis());
83
84            return (saxis);
85         }
86
87         virtual bool hasChild(void) const { return (vfieldGroup != NULL); }
88         virtual void printChild(ostream& out) const { out << *vfieldGroup << std::endl; }
89
90         virtual void resolveDescInheritance(const AttributRegistrar* const _parent = 0)
91         { addAttributes(*_parent); if(vfieldGroup != NULL) vfieldGroup->resolveDescInheritance(); }
92
93         void resolveFieldRefInheritance(void)
94         { // Résolution des héritages par référence de chacun des champs contenus dans le fichier.
95            std::vector<CField*> allF; this->getAllFields(allF);
96            for (unsigned int i = 0; i < allF.size(); i++) allF[i]->resolveRefInheritance();
97         }
98
99         FieldGroup* getVirtualFieldGroup(void) const { return (vfieldGroup); }
100
101         void findEnabledFields(const Date& inidate, int default_outputlevel = 5, int default_level = 1, bool default_enabled = true )
102         {
103            const int _outputlevel = (output_level.hasValue()) ? (int)output_level : default_outputlevel;
104            std::vector<CField*>::iterator it;
105
106            this->getAllFields(enabledFields);
107
108            for ( it = enabledFields.begin() ; it != enabledFields.end(); it++ )
109            { // TODO Jeu avec les itérateurs un peu bizarre, à modifier.
110              // std::cout << (*it)->field_ref <<std::endl;
111               if ((*it)->enabled.hasValue()) // Si l'attribut 'enabled' est défini ...
112               {
113                  if (! ((*it)->enabled))
114                  { it--; enabledFields.erase(it+1); continue; }
115               }
116               else // Si l'attribut 'enabled' n'est pas défini ...
117               {
118                  if (!default_enabled)
119                  { it--; enabledFields.erase(it+1); continue; }
120               }
121
122               if ((*it)->level.hasValue()) // Si l'attribut 'level' est défini ...
123               {
124                  if ((*it)->level > _outputlevel)
125                  { it--; enabledFields.erase(it+1); continue; }
126               }
127               else // Si l'attribut 'level' n'est pas défini ...
128               {
129                  if (default_level > _outputlevel)
130                  { it--; enabledFields.erase(it+1); continue; }
131               }
132
133               // Le champ est finalement actif, on ajoute la référence au champ de base.
134               (*it)->getBaseObject()->addRefObject(*it);
135               (*it)->setRelFile(this);
136               (*it)->initLastStoredDate(inidate);
137            }
138         }
139
140         void solveEFGridRef(void)
141         {
142            for (unsigned int i = 0; i < enabledFields.size(); i++)
143               enabledFields[i]->solveGridRef();
144         }
145
146         virtual  ~CFile(void)
147         {
148            if(vfieldGroup != NULL) delete vfieldGroup;
149            if(output != NULL) delete output;
150         }
151
152      private :
153
154         FieldGroup* vfieldGroup; // FieldGroup "virtuel"
155         std::vector<CField*> enabledFields; // Liste des champs à sortie dans le fichier courant.
156
157         AbstractDataOutput* output; // Gestion de la sortie des données.
158
159   }; // class CFile
160
161} // namespace XMLIOSERVER
162
163DECLARE_GROUP(File)
164
165
166#endif // __CFILE__
Note: See TracBrowser for help on using the repository browser.