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

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