1 | #ifndef __FIELD__ |
---|
2 | #define __FIELD__ |
---|
3 | |
---|
4 | using XMLIOSERVER::XML::XMLNode; |
---|
5 | using XMLIOSERVER::XML::THashAttributes; |
---|
6 | |
---|
7 | namespace XMLIOSERVER |
---|
8 | { |
---|
9 | class CGrid; // CGRID = CDOMAINE + CAXIS |
---|
10 | class CFile; |
---|
11 | |
---|
12 | class CField : public ObjectTemplate<CField>, public FieldAttribut |
---|
13 | { |
---|
14 | public: |
---|
15 | |
---|
16 | CField(void) : ObjectTemplate<CField>(), FieldAttribut(), lastStored(NULL), grid(NULL), file(NULL) |
---|
17 | {/* Ne rien faire de plus */} |
---|
18 | CField(const string& _id) : ObjectTemplate<CField>(_id), FieldAttribut(), lastStored(NULL), grid(NULL), file(NULL) |
---|
19 | {/* Ne rien faire de plus */} |
---|
20 | |
---|
21 | inline void solveGridRef(void) ; |
---|
22 | |
---|
23 | const CGrid* getGrid(void) const { return (grid); } |
---|
24 | const Array<double, 1>& getData(void) const { return (data); } |
---|
25 | |
---|
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 | |
---|
47 | public: /* virtual */ |
---|
48 | |
---|
49 | virtual CField* getReference(void) const |
---|
50 | { |
---|
51 | if(!field_ref.hasValue()) return (NULL); |
---|
52 | if (!CField::HasObject(field_ref)) |
---|
53 | { WARNING("Référence invalide sur l'objet "+GetName()+" nommé \""+((string)field_ref)+"\""); return (NULL); } |
---|
54 | |
---|
55 | return (CField::GetObject(field_ref)); |
---|
56 | } |
---|
57 | |
---|
58 | virtual ~CField(void) |
---|
59 | { if(lastStored != NULL) delete lastStored; } |
---|
60 | |
---|
61 | public: /* static */ |
---|
62 | |
---|
63 | static string GetName(void) { return ("field"); } |
---|
64 | static string GetDefName(void) { return (CField::GetName()); } |
---|
65 | |
---|
66 | private : |
---|
67 | |
---|
68 | Date* lastStored; |
---|
69 | |
---|
70 | CGrid* grid ; |
---|
71 | CFile* file; |
---|
72 | |
---|
73 | Array<double, 1> data; |
---|
74 | |
---|
75 | }; // class CField |
---|
76 | |
---|
77 | } // namespace XMLIOSERVER |
---|
78 | |
---|
79 | DECLARE_GROUP(Field) |
---|
80 | |
---|
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 | |
---|
117 | #endif // __FIELD__ |
---|