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

Last change on this file since 130 was 130, checked in by hozdoba, 14 years ago
File size: 4.4 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) : 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         void solveOperation(void)
45         {
46            FieldOperation*   fope = this->operation.getValue();
47            Duration      *  ffope = this->freq_op.getValue();
48
49            if (fope != NULL)
50            { // Si une opération sur le champ est définie ...
51               if (fope->getId().compare("once") == 0)
52                  this->freq_op.setValue(NoneDu);
53            }
54            else
55            { // Si aucune opération sur le champ n'est définie ...
56               FieldOperation ope("inst");
57               this->operation.setValue(ope);
58            }
59
60            // Si la fréquence d'opération n'est pas définie, on l'initialise à 0s.
61            // Une fréquence à 0s signifie que l'opération se fera à chaque écriture de données depuis la simulation.
62            if (ffope == NULL)
63               this->freq_op.setValue(NoneDu);
64
65            this->operation.getValue()->setFreqOp(this->freq_op);
66         }
67
68         const CFile* getRelFile(void) const { return (file); }
69         void setRelFile(CFile* _file) { file = _file; }
70
71      public: /* virtual */
72
73         virtual CField* getReference(void) const
74         {
75            if(!field_ref.hasValue()) return (NULL);
76            if (!CField::HasObject(field_ref))
77            { WARNING("Référence invalide sur l'objet "+GetName()+" nommé \""+((string)field_ref)+"\""); return (NULL); }
78
79            return (CField::GetObject(field_ref));
80         }
81
82         virtual ~CField(void)
83         { if(lastStored !=  NULL) delete lastStored; }
84
85      public: /* static */
86
87         static string GetName(void) { return ("field"); }
88         static string GetDefName(void)  { return (CField::GetName()); }
89
90      private :
91
92         Date* lastStored;
93
94         CGrid* grid ;
95         CFile* file;
96
97         Array<double, 1>  data;
98
99   }; // class CField
100
101} // namespace XMLIOSERVER
102
103DECLARE_GROUP(Field)
104
105/* Pour la gestion des références aux groupes de champs */
106namespace XMLIOSERVER
107{
108   template <>
109      CField& GroupTemplate<CField, FieldAttribut>::createChildRef(const CField* const _ori)
110   {
111      if (!_ori->hasId())
112         throw (new XMLIOUndefinedValueException("Impossible de créer une référence à un élément sans identifiant !"));
113
114      CField& obj = *ObjectTemplate<CField>::CreateObject();
115      obj.field_ref = _ori->getId();
116      childList.addObject(&obj);
117      return (obj);
118   }
119
120   template <>
121      void GroupTemplate<CField, FieldAttribut>::solveRefInheritance (void)
122   {
123      std::vector<CField*> _allf ;
124
125      if(!group_ref.hasValue() || (GetName().compare("field_group") != 0)) return;
126      if (!GroupTemplate<CField, FieldAttribut>::HasObject(group_ref))
127      { WARNING("Référence invalide sur l'objet "+GetName()+" nommé \""+((string)group_ref)+"\""); return; }
128
129      const GroupTemplate<CField, FieldAttribut>* const gref
130               = GroupTemplate<CField, FieldAttribut>::GetObject(group_ref);
131
132      gref->getAllChildren(_allf);
133      std::vector<CField*>::iterator it ;
134      for ( it = _allf.begin() ; it != _allf.end(); it++ )
135         this->createChildRef(*it);
136   }
137
138
139} // namespace XMLIOSERVER
140
141#endif // __FIELD__
Note: See TracBrowser for help on using the repository browser.