1 | #ifndef __DOMAIN__ |
---|
2 | #define __DOMAIN__ |
---|
3 | |
---|
4 | using XMLIOSERVER::XML::XMLNode; |
---|
5 | using XMLIOSERVER::XML::THashAttributes; |
---|
6 | |
---|
7 | namespace XMLIOSERVER |
---|
8 | { |
---|
9 | class CDomain : public ObjectTemplate<CDomain>, public DomainAttribut |
---|
10 | { |
---|
11 | public: |
---|
12 | |
---|
13 | CDomain(void) : ObjectTemplate<CDomain>(), DomainAttribut() |
---|
14 | { /* Ne rien faire de plus */ } |
---|
15 | CDomain(const string& _id) : ObjectTemplate<CDomain>(_id), DomainAttribut() |
---|
16 | { /* Ne rien faire de plus */ } |
---|
17 | |
---|
18 | static string GetName(void) {return ("domain"); } |
---|
19 | static string GetDefName(void) { return (CDomain::GetName()); } |
---|
20 | |
---|
21 | inline void check(void) ; |
---|
22 | |
---|
23 | ~CDomain(void) { /* Ne rien faire de plus */ } |
---|
24 | |
---|
25 | }; // class Domain |
---|
26 | |
---|
27 | void CDomain::check(void) |
---|
28 | { |
---|
29 | //static bool isChecked = false ; |
---|
30 | |
---|
31 | //if (isChecked) return; // Si la vérification a été faite, on arrête tout. |
---|
32 | |
---|
33 | // domaine global |
---|
34 | if (!ni_glo.hasValue() || ni_glo<=0 ) throw XMLIOSERVER::XMLIOUndefinedValueException("domaine global mal defini") ; |
---|
35 | if (!nj_glo.hasValue() || nj_glo<=0 ) throw XMLIOSERVER::XMLIOUndefinedValueException("domaine global mal defini") ; |
---|
36 | |
---|
37 | //domaine local en i |
---|
38 | if ( ni.hasValue() && ibegin.hasValue()) |
---|
39 | { |
---|
40 | if (iend.hasValue() && iend!=ibegin+ni-1) throw XMLIOSERVER::XMLIOUndefinedValueException("domain local mal défini 1") ; |
---|
41 | iend = ibegin + ni - 1 ; |
---|
42 | } |
---|
43 | else if (ni.hasValue() && iend.hasValue()) |
---|
44 | { |
---|
45 | if (ibegin != ni-iend+1) throw XMLIOSERVER::XMLIOUndefinedValueException("domain local mal défini 2") ; |
---|
46 | ibegin = ni - iend + 1 ; |
---|
47 | } |
---|
48 | else if (ibegin.hasValue() && iend.hasValue()) |
---|
49 | { |
---|
50 | if (ni!=iend-ibegin-1) throw XMLIOSERVER::XMLIOUndefinedValueException("domain local mal défini 3") ; |
---|
51 | ni = iend - ibegin - 1 ; |
---|
52 | } |
---|
53 | else throw XMLIOSERVER::XMLIOUndefinedValueException("domain local non défini 4") ; |
---|
54 | |
---|
55 | if (ni<0 || ibegin>iend || ibegin<1 || iend>ni_glo) throw XMLIOSERVER::XMLIOUndefinedValueException("domain local mal défini 5") ; |
---|
56 | |
---|
57 | //domaine local en j |
---|
58 | if ( nj.hasValue() && jbegin.hasValue()) |
---|
59 | { |
---|
60 | if (jend.hasValue() && jend!=jbegin+nj-1) throw XMLIOSERVER::XMLIOUndefinedValueException("domain local mal défini 6") ; |
---|
61 | jend = jbegin + nj - 1 ; |
---|
62 | } |
---|
63 | else if (nj.hasValue() && jend.hasValue()) |
---|
64 | { |
---|
65 | if (jbegin!=nj-jend+1) throw XMLIOSERVER::XMLIOUndefinedValueException("domain local mal défini 7") ; |
---|
66 | jbegin = nj - jend + 1 ; |
---|
67 | } |
---|
68 | else if (jbegin.hasValue() && jend.hasValue()) |
---|
69 | { |
---|
70 | if (nj!=jend-jbegin-1) throw XMLIOSERVER::XMLIOUndefinedValueException("domain local mal défini 8") ; |
---|
71 | nj = jend - jbegin - 1 ; |
---|
72 | } |
---|
73 | else throw XMLIOSERVER::XMLIOUndefinedValueException("domain local non défini 9") ; |
---|
74 | |
---|
75 | if (nj<0 || jbegin>jend || jbegin<1 || jend>nj_glo) throw XMLIOSERVER::XMLIOUndefinedValueException("domain local mal défini 10") ; |
---|
76 | |
---|
77 | //cout<<"mask ni "<<mask->extent(0)<<" nj "<<mask->extent(1)<<" "<<mask<<endl ; |
---|
78 | if (mask.hasValue()) |
---|
79 | if (mask->extent(0) != ni || mask->extent(1) != nj) |
---|
80 | throw XMLIOSERVER::XMLIOUndefinedValueException("le champ mask n'a pas la même taille que le domaine local") ; |
---|
81 | |
---|
82 | if (data_dim.hasValue()) |
---|
83 | { |
---|
84 | if (!(data_dim==1 || data_dim==2)) throw XMLIOSERVER::XMLIOUndefinedValueException("dimension non comptatible (doit être 1 ou 2)") ; |
---|
85 | } |
---|
86 | else throw XMLIOSERVER::XMLIOUndefinedValueException("Dimension des donnée non définie") ; |
---|
87 | |
---|
88 | if (data_ni.hasValue()) |
---|
89 | { |
---|
90 | if (data_ni<=0) throw XMLIOSERVER::XMLIOUndefinedValueException("Dimension des données négative") ; |
---|
91 | } |
---|
92 | else |
---|
93 | { |
---|
94 | if (data_dim==1) data_ni=ni*nj ; |
---|
95 | else data_ni=(int) ni ; |
---|
96 | } |
---|
97 | |
---|
98 | if (!data_ibegin.hasValue()) data_ibegin=0 ; |
---|
99 | |
---|
100 | if (data_nj.hasValue()) |
---|
101 | { |
---|
102 | if (data_nj<=0) throw XMLIOSERVER::XMLIOUndefinedValueException("Dimension des données négative") ; |
---|
103 | } |
---|
104 | else data_nj=(int) nj ; |
---|
105 | |
---|
106 | if (!data_jbegin.hasValue()) data_jbegin=0 ; |
---|
107 | |
---|
108 | if (!mask.hasValue()) |
---|
109 | { // Si aucun masque n'est défini, on en crée un nouveau qui valide l'intégralité du domaine. |
---|
110 | mask->resize(shape(ni,nj)) ; |
---|
111 | *mask=true ; |
---|
112 | } |
---|
113 | |
---|
114 | // Gestion de la compression |
---|
115 | |
---|
116 | if (data_i_index.hasValue()) |
---|
117 | { |
---|
118 | if (data_n_index.hasValue()) |
---|
119 | { |
---|
120 | if (data_n_index!=data_i_index->extent(0)) |
---|
121 | throw XMLIOSERVER::XMLIOUndefinedValueException("Dimension data_i_index incompatible avec data_n_index") ; |
---|
122 | } |
---|
123 | else data_n_index=data_i_index->extent(0) ; |
---|
124 | |
---|
125 | if (data_dim==2) |
---|
126 | { |
---|
127 | if (data_j_index.hasValue()) |
---|
128 | { |
---|
129 | if (data_j_index->extent(0)!=data_i_index->extent(0)) |
---|
130 | throw XMLIOSERVER::XMLIOUndefinedValueException("Dimension data_j_index incompatible avec data_i_index") ; |
---|
131 | } |
---|
132 | else throw XMLIOSERVER::XMLIOUndefinedValueException("data_j_index non défini") ; |
---|
133 | } |
---|
134 | } |
---|
135 | else |
---|
136 | { |
---|
137 | if (data_n_index.hasValue() || (data_dim==2 && data_j_index.hasValue())) |
---|
138 | throw XMLIOSERVER::XMLIOUndefinedValueException("data_i_index non défini") ; |
---|
139 | } |
---|
140 | //cout<<"data_n_index.hasValue() "<<data_n_index.hasValue()<<endl ; |
---|
141 | if (!data_n_index.hasValue()) |
---|
142 | { |
---|
143 | if (data_dim==1) |
---|
144 | { |
---|
145 | int i ; |
---|
146 | data_n_index=*data_ni ; |
---|
147 | //cout <<"data_n_index "<<data_n_index<<" "<<data_ni<<" "<<data_nj<<endl ; |
---|
148 | |
---|
149 | data_i_index->resize(data_n_index) ; |
---|
150 | |
---|
151 | for (i=0;i<data_ni;i++) (*data_i_index)(i)=i ; |
---|
152 | //cout <<"data_i_index "<<*data_i_index<<endl ; |
---|
153 | } |
---|
154 | else // data_dim=2 |
---|
155 | { |
---|
156 | int i ; |
---|
157 | int j ; |
---|
158 | int count ; |
---|
159 | |
---|
160 | data_n_index = data_ni * data_nj ; |
---|
161 | data_i_index -> resize(data_n_index) ; |
---|
162 | data_j_index -> resize(data_n_index) ; |
---|
163 | for(count=0,i=0; i<data_ni;i++) |
---|
164 | for(j=0; j<data_nj;j++) |
---|
165 | { |
---|
166 | (*data_i_index)(count)=i ; |
---|
167 | // cout<<count<<" "<<(*data_i_index)(count)<<endl ; |
---|
168 | (*data_j_index)(count)=j ; |
---|
169 | //cout<<count<<" "<<(*data_j_index)(count)<<endl ; |
---|
170 | count++ ; |
---|
171 | } |
---|
172 | //cout<<data_ni<<" "<<data_nj<<" "<<data_n_index<<" "<<*data_i_index<<" "<<*data_j_index<<endl ; |
---|
173 | } |
---|
174 | } |
---|
175 | |
---|
176 | //isChecked = true ; |
---|
177 | } |
---|
178 | |
---|
179 | } // namespace XMLIOSERVER |
---|
180 | |
---|
181 | DECLARE_GROUP(Domain) |
---|
182 | |
---|
183 | #endif // __FIELD__ |
---|