source: XMLIO_V2/dev/dev_rv/src/XMLIO/field.hpp @ 131

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

Début Interface c<->fortran

File size: 4.3 KB
Line 
1#ifndef __FIELD__
2#define __FIELD__
3
4using XMLIOSERVER::XML::XMLNode;
5using XMLIOSERVER::XML::THashAttributes;
6
7namespace 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)
17            : ObjectTemplate<CField>(), FieldAttribut(),
18              lastStored(NULL), grid(NULL), file(NULL)
19         { /* Ne rien faire de plus */ }
20
21         CField(const string& _id)
22            : ObjectTemplate<CField>(_id), FieldAttribut(),
23              lastStored(NULL), grid(NULL), file(NULL)
24         { /* Ne rien faire de plus */ }
25
26         inline void solveGridRef(void) ;
27
28         const CGrid* getGrid   (void) const { return (grid); }
29         const CFile* getRelFile(void) const { return (file); }
30         const Array<double, 1>& getData(void) const { return (data); }
31         void setRelFile(CFile* const _file) { file = _file; }
32
33         void initLastStoredDate(const Date& _newlastStored)
34         {
35            if(lastStored == NULL)
36               lastStored = new Date(_newlastStored);
37         };
38
39         bool isStorable(const Date& currDate)
40         {
41            if (lastStored == NULL) return (false);
42            if (freq_op.hasValue())
43               return (currDate >= (*lastStored + (Duration)freq_op));
44            return (true);
45         }
46
47         void storeData(const Array<double, 1> & arr, const Date& currDate)
48         {
49            *lastStored = currDate;
50            data.resize(shape(arr.size())) ;
51            data = arr;
52         }
53
54         void solveOperation(void)
55         {
56            FieldOperation* const  fope = this->operation.getValue();
57            Duration      * const ffope = this->freq_op.getValue();
58
59            if (fope != NULL)
60            { // Si une opération sur le champ est définie ...
61               if (fope->getId().compare("once") == 0)
62                  this->freq_op.setValue(NoneDu);
63            }
64            else
65            { // Si aucune opération sur le champ n'est définie ...
66               FieldOperation ope("inst");
67               this->operation.setValue(ope);
68            }
69
70            if (ffope == NULL)
71               this->freq_op.setValue(NoneDu);
72            this->operation.getValue()->setFreqOp(this->freq_op);
73         }
74
75      public: /* virtual */
76
77         virtual CField* getReference(void) const
78         {
79            if(!field_ref.hasValue()) return (NULL);
80            if (!CField::HasObject(field_ref))
81            { WARNING("Référence invalide sur l'objet "+GetName()+" nommé \""+((string)field_ref)+"\""); return (NULL); }
82
83            return (CField::GetObject(field_ref));
84         }
85
86         virtual ~CField(void)
87         { if(lastStored !=  NULL) delete lastStored; }
88
89      public: /* static */
90
91         static string GetName   (void) { return ("field"); }
92         static string GetDefName(void) { return (CField::GetName()); }
93
94      private :
95
96         Date* lastStored;
97         CGrid* grid ;
98         CFile* file;
99         Array<double, 1> data;
100
101   }; // class CField
102
103} // namespace XMLIOSERVER
104
105DECLARE_GROUP(Field)
106
107/* Pour la gestion des références aux groupes de champs */
108namespace XMLIOSERVER
109{
110   template <>
111      CField& GroupTemplate<CField, FieldAttribut>::createChildRef(const CField* const _ori)
112   {
113      if (!_ori->hasId())
114         throw (new XMLIOUndefinedValueException
115            ("Impossible de créer une référence à un élément sans identifiant !"));
116
117      CField& obj = *ObjectTemplate<CField>::CreateObject();
118      obj.field_ref = _ori->getId();
119      childList.addObject(&obj);
120      return (obj);
121   }
122
123   template <>
124      void GroupTemplate<CField, FieldAttribut>::solveRefInheritance (void)
125   {
126      std::vector<CField*> _allf ;
127
128      if(!group_ref.hasValue() || (GetName().compare("field_group") != 0)) return;
129      if (!GroupTemplate<CField, FieldAttribut>::HasObject(group_ref))
130      { WARNING("Référence invalide sur l'objet "+GetName()+" nommé \""+((string)group_ref)+"\""); return; }
131
132      const GroupTemplate<CField, FieldAttribut>* const gref
133               = GroupTemplate<CField, FieldAttribut>::GetObject(group_ref);
134
135      gref->getAllChildren(_allf);
136      std::vector<CField*>::iterator it ;
137      for ( it = _allf.begin() ; it != _allf.end(); it++ )
138         this->createChildRef(*it);
139   }
140
141
142} // namespace XMLIOSERVER
143
144#endif // __FIELD__
Note: See TracBrowser for help on using the repository browser.