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

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