OpendTect-6_4  6.4
property.h
Go to the documentation of this file.
1 #ifndef property_h
2 #define property_h
3 
4 /*+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: Bert Bril
9  Date: Dec 2003
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 
14 -*/
15 
16 #include "generalmod.h"
17 #include "propertyref.h"
18 #include "factory.h"
19 
20 class PropertySet;
21 
22 
32 { mODTextTranslationClass(Property);
33 public:
34 
35  Property( const PropertyRef& pr )
36  : ref_(pr), lastval_(mUdf(float)) {}
37  virtual Property* clone() const = 0;
38  static Property* get(const IOPar&);
39  virtual ~Property() {}
40  bool isEqualTo(const Property&) const;
41  virtual bool isValue() const { return false; }
42 
43  inline const PropertyRef& ref() const { return ref_; }
44  const char* name() const;
45 
46  virtual void reset() { lastval_ = mUdf(float); }
47  virtual bool init(const PropertySet&) const;
49  virtual uiString errMsg() const {
50  return uiString::emptyString();
51  }
52 
53  virtual bool isUdf() const = 0;
54  virtual bool dependsOn(const Property&) const { return false; }
55 
56  virtual const char* type() const = 0;
57  virtual const char* def() const = 0;
58  virtual void setDef(const char*) = 0;
59 
60  void fillPar(IOPar&) const;
61  void usePar(const IOPar&);
62 
63  mDefineFactory1ParamInClass(Property,const PropertyRef&,factory);
64 
66  {
67  public:
68 
69  enum ValOpt { New, Prev, Avg };
70 
71  EvalOpts( ValOpt vo=New, float relpos=0.5 )
72  : valopt_(vo)
73  , relpos_(relpos)
74  , absz_(0.f)
75  , relz_(0.f) {}
77  float relpos_;
78  float absz_, relz_;
79 
80  inline bool isAvg() const { return valopt_==Avg; }
81  inline bool isPrev() const { return valopt_==Prev;}
82 # define mPropertyEvalAvg Property::EvalOpts(Property::EvalOpts::Avg)
83 # define mPropertyEvalPrev Property::EvalOpts(Property::EvalOpts::Prev)
84 # define mPropertyEvalNew(pos) \
85  Property::EvalOpts(Property::EvalOpts::New,pos)
86 
87  };
88 
89  float value( EvalOpts eo=EvalOpts() ) const
90  {
91  return eo.isPrev() || !mIsUdf(lastval_) ? lastval_
92  : (lastval_ = gtVal(eo));
93  }
94 
95 protected:
96 
97  const PropertyRef& ref_;
98  mutable float lastval_;
99 
100  virtual float gtVal(EvalOpts) const = 0;
101 
102 };
103 
104 
106 {
107 public:
108 
112  PropertySet( const PropertySet& ps )
113  { *this = ps; }
114  virtual ~PropertySet() { erase(); }
115  PropertySet& operator =(const PropertySet&);
116 
117  inline int size() const { return props_.size(); }
118  inline bool isEmpty() const { return props_.isEmpty(); }
119  int indexOf(const char*,bool matchaliases=false) const;
120  inline bool isPresent( const char* nm, bool ma=false ) const
121  { return indexOf(nm,ma) >= 0; }
122  Property& get( int idx ) { return *props_[idx]; }
123  const Property& get( int idx ) const { return *props_[idx]; }
124  inline const Property* find( const char* nm, bool ma=false ) const
125  { return fnd(nm,ma); }
126  inline Property* find( const char* nm, bool ma=false )
127  { return fnd(nm,ma); }
128  int indexOf( const Property& p ) const
129  { return props_.indexOf(&p); }
130  int indexOf( const PropertyRef& pr ) const
131  { return indexOf(pr.name()); }
132  int indexOf(PropertyRef::StdType,int occ=0) const;
134  ObjectSet<Property>&) const;
135 
136  bool add(Property*);
137  int set(Property*);
138  void remove(int);
139  void replace(int,Property*);
140  void erase() { deepErase(props_); }
141 
142  bool prepareUsage() const;
143  void resetMemory();
144  inline uiString errMsg() const { return errmsg_; }
145 
146 
147 protected:
148 
150  mutable uiString errmsg_;
151 
152  Property* fnd(const char*,bool) const;
153 
154 };
155 
156 
157 // For impl of Property subclasses. gtVal and the last three must be provided.
158 #define mDefPropertyFns(clss,typstr) \
159 protected: \
160  virtual float gtVal(EvalOpts) const; \
161 public: \
162  static const char* typeStr() { return typstr; } \
163  virtual const char* type() const { return typeStr(); } \
164  virtual const char* factoryKeyword() const { return type(); } \
165  static Property* create( const PropertyRef& r ) { return new clss(r); } \
166  virtual clss* clone() const { return new clss( *this ); }\
167  static void initClass() { factory().addCreator(create,typeStr());} \
168  virtual const char* def() const; \
169  virtual void setDef(const char*); \
170  virtual bool isUdf() const
171 
172 
173 
176 mExpClass(General) ValueProperty : public Property
177 {
178 public:
179 
181  : Property(pr)
182  , val_(pr.disp_.range_.center()) {}
183  ValueProperty( const PropertyRef& pr, float v )
184  : Property(pr)
185  , val_(v) {}
186  virtual bool isValue() const { return true; }
187 
188  float val_;
189 
191  void setValue( float v ) { val_ = v; }
192 
193 };
194 
197 mExpClass(General) RangeProperty : public Property
198 {
199 public:
200 
202  : Property(pr)
203  , rg_(pr.disp_.range_) {}
205  Interval<float> rg )
206  : Property(pr)
207  , rg_(rg) {}
208 
210 
212 
213 protected:
214 
215  float gtAvgVal() const;
216 };
217 
218 #endif
Property * find(const char *nm, bool ma=false)
Definition: property.h:126
Property(const PropertyRef &pr)
Definition: property.h:35
#define mExpClass(module)
Definition: commondefs.h:160
#define mIsUdf(val)
Use mIsUdf to check for undefinedness of simple types.
Definition: undefval.h:287
Definition: propertyref.h:176
ObjectSet< Property > props_
Definition: property.h:149
float relpos_
Definition: property.h:77
float lastval_
Definition: property.h:98
Definition: property.h:105
void erase()
Definition: property.h:140
#define mODTextTranslationClass(clss)
Definition: uistring.h:38
int indexOf(const PropertyRef &pr) const
Definition: property.h:130
virtual uiString errMsg() const
Definition: property.h:49
float relz_
Definition: property.h:78
void usePar(const IOPar &iop, ODPolygon< T > &poly, const char *inpkey)
Definition: polygon.h:188
bool isPrev() const
Definition: property.h:81
Ref Data for a (usually petrophysical) property.
Definition: propertyref.h:42
bool init()
uiString errmsg_
Definition: property.h:150
bool isPresent(const char *nm, bool ma=false) const
Definition: property.h:120
virtual bool dependsOn(const Property &) const
Definition: property.h:54
uiString errMsg() const
Definition: property.h:144
static const uiString & emptyString()
Definition: uistring.h:109
Definition: uistring.h:89
bool isEmpty() const
Definition: odset.h:45
ObjectSet< T >::size_type indexOf(const ObjectSet< T > &os, const S &val)
Locate object in set.
Definition: objectset.h:169
PropertySet(const PropertySet &ps)
Definition: property.h:112
bool isAvg() const
Definition: property.h:80
ValueProperty(const PropertyRef &pr, float v)
Definition: property.h:183
RangeProperty(const PropertyRef &pr)
Definition: property.h:201
ValueProperty(const PropertyRef &pr)
Definition: property.h:180
#define mDefineFactory1ParamInClass(T, P, funcname)
Definition: factory.h:447
ValOpt
Definition: property.h:69
size_type size() const
Definition: objectset.h:50
void resetMemory()
Range of values. pos_ is usually in [0,1].
Definition: property.h:197
const PropertyRef & ref() const
Definition: property.h:43
Generalized set of parameters of the keyword-value type.
Definition: iopar.h:47
EvalOpts(ValOpt vo=New, float relpos=0.5)
Definition: property.h:71
const Property * find(const char *nm, bool ma=false) const
Definition: property.h:124
bool prepareUsage() const
init()&#39;s all Properties
#define mUdf(type)
Use this macro to get the undefined for simple types.
Definition: undefval.h:272
bool isEmpty() const
Definition: property.h:118
const PropertyRef & ref_
Definition: property.h:97
virtual ~Property()
Definition: property.h:39
void fillPar(IOPar &iop, const ODPolygon< T > &poly, const char *inpkey)
Definition: polygon.h:175
virtual ~PropertySet()
Definition: property.h:114
#define mDefPropertyFns(clss, typstr)
Definition: property.h:158
Property * fnd(const char *, bool) const
BufferString errmsg_
Definition: horizontracker.h:119
PropertySet & operator=(const PropertySet &)
int size() const
Definition: property.h:117
Interval< float > rg_
Definition: property.h:209
Simple, single-value property.
Definition: property.h:176
A (usually petrophysical) property of some object.
Definition: property.h:31
ValOpt valopt_
Definition: property.h:76
float value(EvalOpts eo=EvalOpts()) const
Definition: property.h:89
void getPropertiesOfRefType(PropertyRef::StdType, ObjectSet< Property > &) const
PropertySet()
Definition: property.h:109
RangeProperty(const PropertyRef &pr, Interval< float > rg)
Definition: property.h:204
StdType
Definition: propertyref.h:46
bool add(Property *)
refuses to add with identical name
virtual bool isValue() const
Definition: property.h:186
Definition: property.h:65
void setValue(float v)
Definition: property.h:191
bool isUdf(const T &t)
Definition: undefval.h:243
virtual const OD::String & name() const
Definition: namedobj.h:47
float val_
Definition: property.h:188
virtual bool isValue() const
Definition: property.h:41
virtual void reset()
Definition: property.h:46
virtual size_type indexOf(const T *) const
Definition: objectset.h:337
int indexOf(const Property &p) const
Definition: property.h:128
void replace(int, Property *)
void deepErase(ObjectSet< T > &os)
empty the ObjectSet deleting all objects pointed to.
Definition: objectset.h:118

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