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

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

Commit pour sauvegarde - diverses corrections de bogues et améliorations du code.

File size: 6.0 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
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         AbstractDataOutput* getDataOutput(void) const { return (output); }
39         void initializeDataOutput(AbstractDataOutput* _output)
40         {
41            if (_output != NULL) output = _output;
42            else throw XMLIOSERVER::XMLIOUndefinedValueException("Impossible d'initialiser la sortie de données pour le fichier nommé '"+ getId() +"'.") ;
43         }
44
45         void getAllFields(std::vector<CField*>& _allF) const {  if (vfieldGroup!=NULL) vfieldGroup->getAllChildren(_allF); }
46         const std::vector<CField*>& getEnabledFields(void) const { return (enabledFields); }
47
48         const std::set<const CGrid*> getEnabledGrids(void) const
49         {
50            std::set<const CGrid*> sgrid;
51            const std::vector<CField*> enabledFields = getEnabledFields();
52            std::vector<CField*>::const_iterator it;
53
54            for ( it = enabledFields.begin() ; it != enabledFields.end(); it++ )
55               sgrid.insert((*it)->getGrid());
56
57            return (sgrid);
58         }
59
60         const std::set<const CDomain*> getEnabledDomains(void) const
61         {
62            const std::set<const CGrid*> sgrid = getEnabledGrids();
63            std::set<const CDomain*> sdomain;
64
65            std::set<const CGrid*>::const_iterator it;
66
67            for ( it = sgrid.begin() ; it != sgrid.end(); it++ )
68               sdomain.insert((*it)->getRelDomain());
69
70            return (sdomain);
71         }
72
73         const std::set<const CAxis*> getEnabledAxis(void) const
74         {
75            const std::set<const CGrid*> sgrid = getEnabledGrids();
76            std::set<const CAxis*> saxis;
77
78            std::set<const CGrid*>::const_iterator it;
79
80            for ( it = sgrid.begin() ; it != sgrid.end(); it++ )
81               saxis.insert((*it)->getRelAxis());
82
83            return (saxis);
84         }
85
86         virtual bool hasChild(void) const { return (vfieldGroup != NULL); }
87         virtual void printChild(ostream& out) const { out << *vfieldGroup << std::endl; }
88
89         virtual void resolveDescInheritance(const AttributRegistrar* const _parent = 0)
90         { addAttributes(*_parent); if(vfieldGroup != NULL) vfieldGroup->resolveDescInheritance(); }
91
92         void resolveFieldRefInheritance(void)
93         { // Résolution des héritages par référence de chacun des champs contenus dans le fichier.
94            std::vector<CField*> allF; getAllFields(allF);
95            for (unsigned int i = 0; i < allF.size(); i++) allF[i]->resolveRefInheritance();
96         }
97
98         FieldGroup* getVirtualFieldGroup(void) const { return (vfieldGroup); }
99
100         void findEnabledFields(const Date& inidate, int default_outputlevel = 5, int default_level = 1, bool default_enabled = true )
101         {
102            const int _outputlevel = (output_level.hasValue()) ? (int)output_level : default_outputlevel;
103            std::vector<CField*>::iterator it;
104
105            getAllFields(enabledFields);
106
107            for ( it = enabledFields.begin() ; it != enabledFields.end(); it++ )
108            {
109               if ((*it)->enabled.hasValue()) // Si l'attribut 'enabled' est défini ...
110               {
111                  if (! ((*it)->enabled))
112                  { enabledFields.erase(it); continue; }
113               }
114               else // Si l'attribut 'enabled' n'est pas défini ...
115               {
116                  if (!default_enabled)
117                  { enabledFields.erase(it); continue; }
118               }
119
120               if ((*it)->level.hasValue()) // Si l'attribut 'level' est défini ...
121               {
122                  if ((*it)->level > _outputlevel)
123                  { enabledFields.erase(it); continue; }
124               }
125               else // Si l'attribut 'level' n'est pas défini ...
126               {
127                  if (default_level > _outputlevel)
128                  { enabledFields.erase(it); continue; }
129               }
130
131               // Le champ est finalement actif, on ajoute la référence au champ de base.
132               (*it)->getBaseObject()->addRefObject(*it);
133               (*it)->setRelFile(this);
134               (*it)->initLastStoredDate(inidate);
135            }
136         }
137
138         void solveEFGridRef(void)
139         {
140            for (unsigned int i = 0; i < enabledFields.size(); i++)
141               enabledFields[i]->solveGridRef();
142         }
143
144         virtual  ~CFile(void)
145         {
146            if(vfieldGroup != NULL) delete vfieldGroup;
147            if(output != NULL) delete output;
148         }
149
150      private :
151
152         FieldGroup* vfieldGroup; // FieldGroup "virtuel"
153         std::vector<CField*> enabledFields; // Liste des champs à sortie dans le fichier courant.
154
155         AbstractDataOutput* output; // Gestion de la sortie des données.
156
157   }; // class CFile
158
159} // namespace XMLIOSERVER
160
161DECLARE_GROUP(File)
162
163
164#endif // __CFILE__
Note: See TracBrowser for help on using the repository browser.