OpendTect-6_4  6.4
attribparamgroup.h
Go to the documentation of this file.
1 #ifndef attribparamgroup_h
2 #define attribparamgroup_h
3 
4 /*+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: Kristofer Tingdahl
9  Date: 10-12-1999
10  RCS: $Id$
11 ________________________________________________________________________
12 */
13 
14 #include "attribparam.h"
15 #include "datainpspec.h"
16 #include "bufstringset.h"
17 
18 namespace Attrib
19 {
20 
40 template <class PT>
41 mClass(AttributeEngine) ParamGroup : public Param
42 {
43 public:
44 
45  ParamGroup( int startsz, const char* prefix,
46  const PT& templ);
47  ParamGroup(const ParamGroup&);
48  ~ParamGroup();
49 
50  ParamGroup<PT>* clone() const;
51  bool isOK() const;
52  const char* errMsg() const;
53  bool setValues(BufferStringSet&);
54  bool getCompositeValue(BufferString&) const;
55  void fillDefStr(BufferString&) const;
56 
57  Param& operator[]( int idx ) { return *params_[idx];}
58  const Param& operator[]( int idx ) const { return *params_[idx];}
59 
60  void setSize(int);
61  int size() const { return sz_; }
62  int isEmpty() const { return sz_==0; }
63  const char* getPrefix() const { return prefix_.buf();}
64 
65 protected:
66  int getSize() const;
67  bool isEqual(const Param&) const;
68 
69  int sz_;
70 
72  PT templ_;
74 
76 
77 };
78 
79 
80 #define mDescGetParamGroup(PT,ret,desc,key) \
81 ParamGroup<PT>* ret; \
82 { \
83  Param* param = desc.getParam( key ); \
84  mDynamicCastGet(ParamGroup<PT>*,tmp,param) \
85  ret = tmp; \
86 }
87 
88 #define mDescGetConstParamGroup(PT,ret,desc,key) \
89 const ParamGroup<PT>* ret; \
90 {\
91  const Param* param = desc.getParam( key ); \
92  mDynamicCastGet(const ParamGroup<PT>*,tmp,param)\
93  ret = tmp; \
94 }
95 
96 
97 /*
98 template <class PT>
99 inline const ParamGroup<PT>* getParamGroup( const Desc& desc, const char* key )
100 {
101  return getParamGroup( const_cast<Desc&>( desc ), key );
102 }
103 */
104 
105 template <class PT> inline
106 bool ParamGroup<PT>::isEqual(const Param& b) const
107 {
108  mDynamicCastGet(ParamGroup<PT>*,pgr,&const_cast<Param&>(b));
109  if ( !pgr || pgr->size() != sz_ )
110  return false;
111  if ( prefix_ != pgr->getPrefix() )
112  return false;
113 
114  for ( int idx=0; idx<sz_; idx++ )
115  {
116  if ( params_[idx]->getSpec()->nElems()
117  != pgr->params_[idx]->getSpec()->nElems() )
118  return false;
119 
120  for ( int idy=0;
121  idy<params_[idx]->getSpec()->nElems(); idy++ )
122  {
123  const BufferString txt( params_[idx]->getSpec()->text(idx) );
124  if ( txt != pgr->params_[idx]->getSpec()->text(idx) )
125  return false;
126  }
127  }
128  return true;
129 }
130 
131 
132 template <class PT> inline
134 {
135  if ( !enabled_ ) return true;
136  if ( !sz_ ) return false;
137 
138  for ( int idx=0; idx<sz_; idx++ )
139  {
140  if ( !params_[idx]->isOK() )
141  {
142  BufferString& err = const_cast<ParamGroup*>(this)-> errmsg_;
143  err = "cannot parse parameter "; err += idx;
144  err += " of the group "; err += prefix_;
145  return false;
146  }
147  }
148 
149  return true;
150 }
151 
152 
153 template <class PT> inline
155 {
156  setSize( vals.size() );
157  for ( int idx=0; idx<sz_; idx++ )
158  {
159  if ( !params_[idx]->setCompositeValue(vals.get(idx) ) )
160  return false;
161  }
162 
163  return isOK();
164 }
165 
166 
167 template <class PT> inline
169 {
170  return new ParamGroup<PT>(*this);
171 }
172 
173 
174 template <class PT> inline
175 const char* ParamGroup<PT>::errMsg() const
176 { return errmsg_.str(); }
177 
178 
179 template <class PT> inline
180 ParamGroup<PT>::ParamGroup( int startsz, const char* prefix, const PT& templ )
181  : Param( prefix )
182  , templ_( templ )
183  , prefix_( prefix )
184 {
185  isgroup_ = true;
186  setSize( startsz );
187 }
188 
189 
190 template <class PT> inline
192  : Param( a )
193  , prefix_( a.prefix_ )
194  , templ_( a.templ_ )
195  , sz_( a.sz_ )
196 {
197  for ( int idx=0; idx<a.params_.size(); idx++ )
198  {
199  PT* np = new PT( (PT&)a[idx] );
200  np->setKey( BufferString(prefix_,idx) );
201  params_ += np;
202  }
203 }
204 
205 template <class PT> inline
207 {
208  deepErase( params_ );
209 }
210 
211 
212 template <class PT> inline
214 {
215  return sz_;
216 }
217 
218 
219 template <class PT> inline
220 void ParamGroup<PT>::setSize( int nsz )
221 {
222  while ( nsz > params_.size() )
223  {
224  PT* newpara = new PT(templ_);
225  newpara->setKey( BufferString(prefix_,params_.size()) );
226  params_ += newpara;
227  }
228 
229  sz_ = nsz;
230 }
231 
232 template <class PT> inline
234 {
235  for ( int idx=0; idx<sz_; idx++ )
236  {
237  BufferString parstr;
238  if ( !params_[idx]->getCompositeValue(parstr) )
239  return false;
240  res.add( parstr ).add( " " );
241  }
242  return true;
243 }
244 
245 
246 template <class PT> inline
248 {
249  for ( int idx=0; idx<sz_; idx++ )
250  {
251  res.add( params_[idx]->getKey() ).add( "=" );
252  BufferString val;
253  if ( !params_[idx]->isRequired()
254  || !params_[idx]->getCompositeValue(val))
255  val = params_[idx]->getDefaultValue();
256  res.add( val ).add( " " );
257  }
258 }
259 
260 
261 #define mAttribSpecSet(sizegiver,sizetaker) \
262  public: \
263  bool update() \
264  { \
265  if ( sizegiver == sizetaker.size() ) \
266  return false; \
267  \
268  sizetaker.setSize( sizegiver ); \
269  \
270  return true; \
271  }
272 
273 
274 }//namespace
275 
276 #endif
bool setValues(BufferStringSet &)
Definition: attribparamgroup.h:154
bool isEqual(const Param &) const
Definition: attribparamgroup.h:106
const char * str() const
Definition: odstring.h:48
const char * errMsg() const
Definition: attribparamgroup.h:175
Set of BufferString objects.
Definition: bufstringset.h:28
bool isRequired() const
Definition: attribparambase.h:54
ParamGroup(int startsz, const char *prefix, const PT &templ)
Definition: attribparamgroup.h:180
ObjectSet< PT > params_
Definition: attribparamgroup.h:73
FixedString getKey() const
Definition: attribparambase.h:58
size_type size() const
Definition: objectset.h:50
BufferString errmsg_
Definition: attribparamgroup.h:75
bool getCompositeValue(BufferString &) const
Definition: attribparamgroup.h:233
int getSize() const
Definition: attribparamgroup.h:213
~ParamGroup()
Definition: attribparamgroup.h:206
const BufferString prefix_
Definition: attribparamgroup.h:71
A parameter that is used by an attribute.
Definition: attribparambase.h:36
const char * getPrefix() const
Definition: attribparamgroup.h:63
int size() const
Definition: attribparamgroup.h:61
#define mDynamicCastGet(typ, out, in)
Definition: commondefs.h:131
OD::String with its own variable length buffer. The buffer has a guaranteed minimum size...
Definition: bufstring.h:40
BufferString errmsg_
Definition: horizontracker.h:119
int isEmpty() const
Definition: attribparamgroup.h:62
ParamGroup< PT > * clone() const
Definition: attribparamgroup.h:168
bool isgroup_
Definition: attribparambase.h:77
BufferString & add(char)
bool isOK() const
Definition: attribparamgroup.h:133
BufferString & get(int idx)
Definition: bufstringset.h:36
const char * errMsg() const
Definition: horizontracker.h:61
#define mClass(module)
Definition: commondefs.h:164
void setSize(int)
Definition: attribparamgroup.h:220
Attrib::Param that contains many (a set) Attrib::Param of one kind.
Definition: attribparamgroup.h:41
void fillDefStr(BufferString &) const
Definition: attribparamgroup.h:247
Param & operator[](int idx)
Definition: attribparamgroup.h:57
Semblance Attribute.
Definition: attribdataholder.h:25
void deepErase(ObjectSet< T > &os)
empty the ObjectSet deleting all objects pointed to.
Definition: objectset.h:118
int sz_
Definition: attribparamgroup.h:69
PT templ_
Definition: attribparamgroup.h:72
const Param & operator[](int idx) const
Definition: attribparamgroup.h:58

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B. V. 2019