[106] | 1 | #ifndef __CFILE__ |
---|
| 2 | #define __CFILE__ |
---|
| 3 | |
---|
| 4 | using XMLIOSERVER::XML::XMLNode; |
---|
| 5 | using XMLIOSERVER::XML::THashAttributes; |
---|
| 6 | |
---|
| 7 | namespace XMLIOSERVER |
---|
[107] | 8 | { |
---|
[106] | 9 | class CFile : public ObjectTemplate<CFile>, public FileAttribut |
---|
| 10 | { |
---|
| 11 | public: |
---|
[107] | 12 | |
---|
[122] | 13 | CFile(void) : ObjectTemplate<CFile>(), FileAttribut(), vfieldGroup(NULL), enabledFields(), output(NULL) |
---|
[107] | 14 | {/* Ne rien faire de plus */} |
---|
[122] | 15 | CFile(const string& _id) : ObjectTemplate<CFile>(_id), FileAttribut(), vfieldGroup(NULL), enabledFields(), output(NULL) |
---|
[107] | 16 | {/* Ne rien faire de plus */} |
---|
| 17 | |
---|
| 18 | static string GetName(void) { return ("file"); } |
---|
[125] | 19 | static string GetDefName(void) { return (CFile::GetName()); } |
---|
[107] | 20 | |
---|
[110] | 21 | virtual void parse (XMLNode& _node) |
---|
[106] | 22 | { |
---|
[107] | 23 | string name = _node.getElementName(); |
---|
| 24 | THashAttributes attributes; |
---|
[106] | 25 | |
---|
| 26 | /// PARSING GESTION DES ATTRIBUTS /// |
---|
[107] | 27 | _node.getAttributes(attributes); |
---|
[106] | 28 | this->setAttributes(attributes); |
---|
| 29 | attributes.clear(); |
---|
[107] | 30 | |
---|
| 31 | /// PARSING POUR GESION DES ENFANTS /// |
---|
[106] | 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(); |
---|
[114] | 35 | vfieldGroup = CreateInstanceAndParse<FieldGroup>(_node, getId().c_str(), false ); |
---|
[107] | 36 | } |
---|
[106] | 37 | } |
---|
[107] | 38 | |
---|
[124] | 39 | AbstractDataOutput* getDataOutput(void) const { return (output); } |
---|
[122] | 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 | |
---|
[108] | 46 | void getAllFields(std::vector<CField*>& _allF) const { if (vfieldGroup!=NULL) vfieldGroup->getAllChildren(_allF); } |
---|
[122] | 47 | const std::vector<CField*>& getEnabledFields(void) const { return (enabledFields); } |
---|
[120] | 48 | |
---|
[122] | 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 | |
---|
[107] | 87 | virtual bool hasChild(void) const { return (vfieldGroup != NULL); } |
---|
| 88 | virtual void printChild(ostream& out) const { out << *vfieldGroup << std::endl; } |
---|
[120] | 89 | |
---|
[122] | 90 | virtual void resolveDescInheritance(const AttributRegistrar* const _parent = 0) |
---|
[107] | 91 | { addAttributes(*_parent); if(vfieldGroup != NULL) vfieldGroup->resolveDescInheritance(); } |
---|
| 92 | |
---|
[108] | 93 | void resolveFieldRefInheritance(void) |
---|
[109] | 94 | { // Résolution des héritages par référence de chacun des champs contenus dans le fichier. |
---|
[125] | 95 | std::vector<CField*> allF; this->getAllFields(allF); |
---|
[108] | 96 | for (unsigned int i = 0; i < allF.size(); i++) allF[i]->resolveRefInheritance(); |
---|
| 97 | } |
---|
| 98 | |
---|
[124] | 99 | FieldGroup* getVirtualFieldGroup(void) const { return (vfieldGroup); } |
---|
[107] | 100 | |
---|
[124] | 101 | void findEnabledFields(const Date& inidate, int default_outputlevel = 5, int default_level = 1, bool default_enabled = true ) |
---|
[120] | 102 | { |
---|
| 103 | const int _outputlevel = (output_level.hasValue()) ? (int)output_level : default_outputlevel; |
---|
| 104 | std::vector<CField*>::iterator it; |
---|
| 105 | |
---|
[125] | 106 | this->getAllFields(enabledFields); |
---|
[120] | 107 | |
---|
[122] | 108 | for ( it = enabledFields.begin() ; it != enabledFields.end(); it++ ) |
---|
[125] | 109 | { // TODO Jeu avec les itérateurs un peu bizarre, à modifier. |
---|
| 110 | // std::cout << (*it)->field_ref <<std::endl; |
---|
[120] | 111 | if ((*it)->enabled.hasValue()) // Si l'attribut 'enabled' est défini ... |
---|
| 112 | { |
---|
| 113 | if (! ((*it)->enabled)) |
---|
[125] | 114 | { it--; enabledFields.erase(it+1); continue; } |
---|
[120] | 115 | } |
---|
| 116 | else // Si l'attribut 'enabled' n'est pas défini ... |
---|
| 117 | { |
---|
| 118 | if (!default_enabled) |
---|
[125] | 119 | { it--; enabledFields.erase(it+1); continue; } |
---|
[120] | 120 | } |
---|
| 121 | |
---|
| 122 | if ((*it)->level.hasValue()) // Si l'attribut 'level' est défini ... |
---|
| 123 | { |
---|
| 124 | if ((*it)->level > _outputlevel) |
---|
[125] | 125 | { it--; enabledFields.erase(it+1); continue; } |
---|
[120] | 126 | } |
---|
| 127 | else // Si l'attribut 'level' n'est pas défini ... |
---|
| 128 | { |
---|
| 129 | if (default_level > _outputlevel) |
---|
[125] | 130 | { it--; enabledFields.erase(it+1); continue; } |
---|
[120] | 131 | } |
---|
[124] | 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); |
---|
[120] | 137 | } |
---|
| 138 | } |
---|
| 139 | |
---|
[122] | 140 | void solveEFGridRef(void) |
---|
| 141 | { |
---|
| 142 | for (unsigned int i = 0; i < enabledFields.size(); i++) |
---|
[124] | 143 | enabledFields[i]->solveGridRef(); |
---|
[122] | 144 | } |
---|
| 145 | |
---|
[113] | 146 | virtual ~CFile(void) |
---|
[122] | 147 | { |
---|
| 148 | if(vfieldGroup != NULL) delete vfieldGroup; |
---|
| 149 | if(output != NULL) delete output; |
---|
| 150 | } |
---|
[107] | 151 | |
---|
[106] | 152 | private : |
---|
[107] | 153 | |
---|
[106] | 154 | FieldGroup* vfieldGroup; // FieldGroup "virtuel" |
---|
[122] | 155 | std::vector<CField*> enabledFields; // Liste des champs à sortie dans le fichier courant. |
---|
[124] | 156 | |
---|
[122] | 157 | AbstractDataOutput* output; // Gestion de la sortie des données. |
---|
[107] | 158 | |
---|
| 159 | }; // class CFile |
---|
| 160 | |
---|
[114] | 161 | } // namespace XMLIOSERVER |
---|
[107] | 162 | |
---|
[114] | 163 | DECLARE_GROUP(File) |
---|
[112] | 164 | |
---|
| 165 | |
---|
[106] | 166 | #endif // __CFILE__ |
---|