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

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