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

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