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

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

mise à jour

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