[98] | 1 | #ifndef __FIELD__ |
---|
| 2 | #define __FIELD__ |
---|
[79] | 3 | |
---|
[98] | 4 | using XMLIOSERVER::XML::XMLNode; |
---|
| 5 | using XMLIOSERVER::XML::THashAttributes; |
---|
[79] | 6 | |
---|
[98] | 7 | namespace XMLIOSERVER |
---|
[79] | 8 | { |
---|
[120] | 9 | class CGrid; // CGRID = CDOMAINE + CAXIS |
---|
[124] | 10 | class CFile; |
---|
[120] | 11 | |
---|
[106] | 12 | class CField : public ObjectTemplate<CField>, public FieldAttribut |
---|
[98] | 13 | { |
---|
| 14 | public: |
---|
[107] | 15 | |
---|
[124] | 16 | CField(void) : ObjectTemplate<CField>(), FieldAttribut(), lastStored(NULL), grid(NULL), file(NULL) |
---|
[107] | 17 | {/* Ne rien faire de plus */} |
---|
[124] | 18 | CField(const string& _id) : ObjectTemplate<CField>(_id), FieldAttribut(), lastStored(NULL), grid(NULL), file(NULL) |
---|
[107] | 19 | {/* Ne rien faire de plus */} |
---|
| 20 | |
---|
[124] | 21 | inline void solveGridRef(void) ; |
---|
[120] | 22 | |
---|
[122] | 23 | const CGrid* getGrid(void) const { return (grid); } |
---|
[123] | 24 | const Array<double, 1>& getData(void) const { return (data); } |
---|
[120] | 25 | |
---|
[124] | 26 | void initLastStoredDate(const Date& _newlastStored) |
---|
| 27 | { if(lastStored == NULL) lastStored = new Date(_newlastStored); }; |
---|
| 28 | |
---|
| 29 | bool isStorable(const Date& currDate) |
---|
| 30 | { |
---|
| 31 | if (lastStored == NULL) return (false); |
---|
| 32 | if (freq_op.hasValue()) |
---|
| 33 | return (currDate >= (*lastStored + (Duration)freq_op)); |
---|
| 34 | return (true); |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | void storeData(const Array<double, 1> & arr, const Date& currDate) |
---|
| 38 | { |
---|
| 39 | *lastStored = currDate; |
---|
| 40 | data.resize(shape(arr.size())) ; |
---|
| 41 | data = arr; |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | const CFile* getRelFile(void) const { return (file); } |
---|
| 45 | void setRelFile(CFile* _file) { file = _file; } |
---|
| 46 | |
---|
[128] | 47 | public: /* virtual */ |
---|
| 48 | |
---|
[108] | 49 | virtual CField* getReference(void) const |
---|
| 50 | { |
---|
[120] | 51 | if(!field_ref.hasValue()) return (NULL); |
---|
[109] | 52 | if (!CField::HasObject(field_ref)) |
---|
[123] | 53 | { WARNING("Référence invalide sur l'objet "+GetName()+" nommé \""+((string)field_ref)+"\""); return (NULL); } |
---|
[108] | 54 | |
---|
[120] | 55 | return (CField::GetObject(field_ref)); |
---|
[108] | 56 | } |
---|
| 57 | |
---|
[113] | 58 | virtual ~CField(void) |
---|
[124] | 59 | { if(lastStored != NULL) delete lastStored; } |
---|
[107] | 60 | |
---|
[128] | 61 | public: /* static */ |
---|
| 62 | |
---|
| 63 | static string GetName(void) { return ("field"); } |
---|
| 64 | static string GetDefName(void) { return (CField::GetName()); } |
---|
| 65 | |
---|
[120] | 66 | private : |
---|
| 67 | |
---|
[124] | 68 | Date* lastStored; |
---|
| 69 | |
---|
[120] | 70 | CGrid* grid ; |
---|
[124] | 71 | CFile* file; |
---|
[120] | 72 | |
---|
[124] | 73 | Array<double, 1> data; |
---|
| 74 | |
---|
[110] | 75 | }; // class CField |
---|
[107] | 76 | |
---|
[114] | 77 | } // namespace XMLIOSERVER |
---|
[107] | 78 | |
---|
[114] | 79 | DECLARE_GROUP(Field) |
---|
[112] | 80 | |
---|
[128] | 81 | /* Pour la gestion des références aux groupes de champs */ |
---|
| 82 | namespace XMLIOSERVER |
---|
| 83 | { |
---|
| 84 | template <> |
---|
| 85 | CField& GroupTemplate<CField, FieldAttribut>::createChildRef(const CField* const _ori) |
---|
| 86 | { |
---|
| 87 | if (!_ori->hasId()) |
---|
| 88 | throw (new XMLIOUndefinedValueException("Impossible de créer une référence à un élément sans identifiant !")); |
---|
| 89 | |
---|
| 90 | CField& obj = *ObjectTemplate<CField>::CreateObject(); |
---|
| 91 | obj.field_ref = _ori->getId(); |
---|
| 92 | childList.addObject(&obj); |
---|
| 93 | return (obj); |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | template <> |
---|
| 97 | void GroupTemplate<CField, FieldAttribut>::solveRefInheritance (void) |
---|
| 98 | { |
---|
| 99 | std::vector<CField*> _allf ; |
---|
| 100 | |
---|
| 101 | if(!group_ref.hasValue() || (GetName().compare("field_group") != 0)) return; |
---|
| 102 | if (!GroupTemplate<CField, FieldAttribut>::HasObject(group_ref)) |
---|
| 103 | { WARNING("Référence invalide sur l'objet "+GetName()+" nommé \""+((string)group_ref)+"\""); return; } |
---|
| 104 | |
---|
| 105 | const GroupTemplate<CField, FieldAttribut>* const gref |
---|
| 106 | = GroupTemplate<CField, FieldAttribut>::GetObject(group_ref); |
---|
| 107 | |
---|
| 108 | gref->getAllChildren(_allf); |
---|
| 109 | std::vector<CField*>::iterator it ; |
---|
| 110 | for ( it = _allf.begin() ; it != _allf.end(); it++ ) |
---|
| 111 | this->createChildRef(*it); |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | |
---|
| 115 | } // namespace XMLIOSERVER |
---|
| 116 | |
---|
[98] | 117 | #endif // __FIELD__ |
---|