OpendTect  6.6
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  RCS: $Id$
10 ________________________________________________________________________
11 
12 
13 -*/
14 
15 #include "generalmod.h"
16 #include "propertyref.h"
17 #include "mnemonics.h"
18 #include "factory.h"
19 
20 class PropertySet;
21 class Mnemonic;
22 
23 
34 public:
35  Property( const PropertyRef& pr );
36  virtual Property* clone() const = 0;
37  static Property* get(const IOPar&);
38  virtual ~Property() {}
39 
40  bool isEqualTo(const Property&) const;
41  virtual bool isValue() const { return false; }
42 
43  inline const PropertyRef& ref() const { return ref_; }
44  inline const Mnemonic* mnem() const { return mn_; }
45  const char* name() const;
46 
47  virtual void reset() { lastval_ = mUdf(float); }
48  virtual bool init(const PropertySet&) const;
50  virtual uiString errMsg() const {
51  return uiString::emptyString();
52  }
53 
54  virtual bool isUdf() const = 0;
55  virtual bool dependsOn(const Property&) const { return false; }
56 
57  virtual const char* type() const = 0;
58  virtual const char* def() const = 0;
59  virtual void setDef(const char*) = 0;
60 
61  void fillPar(IOPar&) const;
62  void usePar(const IOPar&);
63 
65 
67  {
68  public:
69 
70  enum ValOpt { New, Prev, Avg };
71 
72  EvalOpts( ValOpt vo=New, float relpos=0.5 )
73  : valopt_(vo)
74  , relpos_(relpos)
75  , absz_(0.f)
76  , relz_(0.f) {}
78  float relpos_;
79  float absz_, relz_;
80 
81  inline bool isAvg() const { return valopt_==Avg; }
82  inline bool isPrev() const { return valopt_==Prev;}
83 # define mPropertyEvalAvg Property::EvalOpts(Property::EvalOpts::Avg)
84 # define mPropertyEvalPrev Property::EvalOpts(Property::EvalOpts::Prev)
85 # define mPropertyEvalNew(pos) \
86  Property::EvalOpts(Property::EvalOpts::New,pos)
87 
88  };
89 
90  float value( EvalOpts eo=EvalOpts() ) const
91  {
92  return eo.isPrev() || !mIsUdf(lastval_) ? lastval_
93  : (lastval_ = gtVal(eo));
94  }
95 
96 protected:
97 
98  const PropertyRef& ref_;
99  const Mnemonic* mn_;
100  mutable float lastval_;
101 
102  virtual float gtVal(EvalOpts) const = 0;
103 
104 };
105 
106 
108 {
109 public:
114  { *this = ps; }
115  virtual ~PropertySet() { erase(); }
117 
118  inline int size() const { return props_.size(); }
119  inline bool isEmpty() const { return props_.isEmpty(); }
120  int indexOf(const char*,bool matchaliases=false) const;
121  inline bool isPresent( const char* nm, bool ma=false ) const
122  { return indexOf(nm,ma) >= 0; }
123  Property& get( int idx ) { return *props_[idx]; }
124  const Property& get( int idx ) const { return *props_[idx]; }
125  inline const Property* find( const char* nm, bool ma=false ) const
126  { return fnd(nm,ma); }
127  inline Property* find( const char* nm, bool ma=false )
128  { return fnd(nm,ma); }
129  int indexOf( const Property& p ) const
130  { return props_.indexOf(&p); }
131  int indexOf( const PropertyRef& pr ) const
132  { return indexOf(pr.name()); }
133  int indexOf(PropertyRef::StdType,int occ=0) const;
135  ObjectSet<Property>&) const;
136 
137  bool add(Property*);
138  int set(Property*);
139  void remove(int);
140  void replace(int,Property*);
141  void erase() { deepErase(props_); }
142 
143  bool prepareUsage() const;
144  void resetMemory();
145  inline uiString errMsg() const { return errmsg_; }
146 
147 
148 protected:
149 
151  mutable uiString errmsg_;
152 
153  Property* fnd(const char*,bool) const;
154 
155 };
156 
157 
158 // For impl of Property subclasses. gtVal and the last three must be provided.
159 #define mDefPropertyFns(clss,typstr) \
160 protected: \
161  virtual float gtVal(EvalOpts) const; \
162 public: \
163  static const char* typeStr() { return typstr; } \
164  virtual const char* type() const { return typeStr(); } \
165  virtual const char* factoryKeyword() const { return type(); } \
166  static Property* create( const PropertyRef& r ) { return new clss(r); } \
167  virtual clss* clone() const { return new clss( *this ); }\
168  static void initClass() { factory().addCreator(create,typeStr());} \
169  virtual const char* def() const; \
170  virtual void setDef(const char*); \
171  virtual bool isUdf() const
172 
173 
174 
178 {
179 public:
181  : Property(pr)
182  , val_(mnem()?mnem()->disp_.typicalrange_.center()
183  :mUdf(float)) {}
184  ValueProperty( const PropertyRef& pr, float v )
185  : Property(pr)
186  , val_(v) {}
187  virtual bool isValue() const { return true; }
188 
189  float val_;
190 
192  void setValue( float v ) { val_ = v; }
193 
194 };
195 
199 {
200 public:
202  : Property(pr)
203  , rg_(mnem()?mnem()->disp_.range_
204  :Interval<float>::udf()) {}
206  Interval<float> rg )
207  : Property(pr)
208  , rg_(rg) {}
209 
211 
213 
214 protected:
215 
216  float gtAvgVal() const;
217 };
Property::ref
const PropertyRef & ref() const
Definition: property.h:43
Property::init
virtual bool init(const PropertySet &) const
clears 'memory' and makes property usable
ValueProperty::setValue
void setValue(float v)
Definition: property.h:192
PropertySet::props_
ObjectSet< Property > props_
Definition: property.h:150
ValueProperty::val_
float val_
Definition: property.h:189
Property::mn_
const Mnemonic * mn_
Definition: property.h:99
PropertySet::errmsg_
uiString errmsg_
Definition: property.h:151
Property::gtVal
virtual float gtVal(EvalOpts) const =0
Mnemonic::disp_
DispDefs disp_
Definition: mnemonics.h:58
factory.h
Property::reset
virtual void reset()
Definition: property.h:47
PropertySet::fnd
Property * fnd(const char *, bool) const
PropertySet::replace
void replace(int, Property *)
Property::mDefineFactory1ParamInClass
mDefineFactory1ParamInClass(Property, const PropertyRef &, factory)
ObjectSet< Property >
Property::EvalOpts::relz_
float relz_
Definition: property.h:79
PropertySet::find
Property * find(const char *nm, bool ma=false)
Definition: property.h:127
Property::isValue
virtual bool isValue() const
Definition: property.h:41
mIsUdf
#define mIsUdf(val)
Use mIsUdf to check for undefinedness of simple types.
Definition: undefval.h:289
Property::def
virtual const char * def() const =0
PropertySet::indexOf
int indexOf(const char *, bool matchaliases=false) const
ValueProperty::ValueProperty
ValueProperty(const PropertyRef &pr)
Definition: property.h:180
mExpClass
#define mExpClass(module)
Definition: commondefs.h:177
PropertySet::set
int set(Property *)
add or change into. returns index.
Property::isUdf
virtual bool isUdf() const =0
Property::EvalOpts::isAvg
bool isAvg() const
Definition: property.h:81
Property::~Property
virtual ~Property()
Definition: property.h:38
Property::EvalOpts::ValOpt
ValOpt
Definition: property.h:70
Property::value
float value(EvalOpts eo=EvalOpts()) const
Definition: property.h:90
PropertySet::isPresent
bool isPresent(const char *nm, bool ma=false) const
Definition: property.h:121
PropertySet::size
int size() const
Definition: property.h:118
ValueProperty
Simple, single-value property.
Definition: property.h:178
Property
A (usually petrophysical) property of some object.
Definition: property.h:33
Mnemonic
Definition: mnemonics.h:26
Property::type
virtual const char * type() const =0
Property::EvalOpts
Definition: property.h:67
Property::lastval_
float lastval_
Definition: property.h:100
PropertySet::getPropertiesOfRefType
void getPropertiesOfRefType(PropertyRef::StdType, ObjectSet< Property > &) const
Property::dependsOn
virtual bool dependsOn(const Property &) const
Definition: property.h:55
NamedObject::name
virtual const name_type & name() const
Definition: namedobj.h:54
PropertyRefSelection
Definition: propertyref.h:166
RangeProperty::RangeProperty
RangeProperty(const PropertyRef &pr, Interval< float > rg)
Definition: property.h:205
PropertySet::PropertySet
PropertySet(const PropertySet &ps)
Definition: property.h:113
ValueProperty::ValueProperty
ValueProperty(const PropertyRef &pr, float v)
Definition: property.h:184
PropertySet::~PropertySet
virtual ~PropertySet()
Definition: property.h:115
indexOf
BufferStringSet::idx_type indexOf(const BufferStringSet &, const char *)
Property::isEqualTo
bool isEqualTo(const Property &) const
Property::EvalOpts::isPrev
bool isPrev() const
Definition: property.h:82
Property::clone
virtual Property * clone() const =0
PropertySet::isEmpty
bool isEmpty() const
Definition: property.h:119
PropertySet::prepareUsage
bool prepareUsage() const
init()'s all Properties
Property::Property
Property(const PropertyRef &pr)
Property::get
static Property * get(const IOPar &)
PropertySet::resetMemory
void resetMemory()
Property::usePar
void usePar(const IOPar &)
mnemonics.h
PropertySet::find
const Property * find(const char *nm, bool ma=false) const
Definition: property.h:125
Property::name
const char * name() const
Property::fillPar
void fillPar(IOPar &) const
RangeProperty::rg_
Interval< float > rg_
Definition: property.h:210
PropertySet
Definition: property.h:108
ValueProperty::isValue
virtual bool isValue() const
Definition: property.h:187
propertyref.h
PropertySet::get
Property & get(int idx)
Definition: property.h:123
PropertyRef
Ref Data for a (usually petrophysical) property.
Definition: propertyref.h:43
PropertySet::remove
void remove(int)
PropertySet::add
bool add(Property *)
refuses to add with identical name
deepErase
void deepErase(BufferStringSet &)
Mnemonic::operator=
Mnemonic & operator=(const Mnemonic &)
Property::EvalOpts::EvalOpts
EvalOpts(ValOpt vo=New, float relpos=0.5)
Definition: property.h:72
uiString
String that is able to hold international (UTF-8) strings for the user interface.
Definition: uistring.h:121
uiString::emptyString
static const uiString & emptyString()
Definition: uistring.h:300
Property::EvalOpts::relpos_
float relpos_
Definition: property.h:78
MPE::errmsg_
BufferString errmsg_
Definition: horizontracker.h:118
Property::ref_
const PropertyRef & ref_
Definition: property.h:98
PropertyRef::StdType
StdType
Definition: propertyref.h:46
PropertySet::get
const Property & get(int idx) const
Definition: property.h:124
Property::setDef
virtual void setDef(const char *)=0
mUdf
#define mUdf(type)
Use this macro to get the undefined for simple types.
Definition: undefval.h:274
PropertySet::indexOf
int indexOf(const PropertyRef &pr) const
Definition: property.h:131
Property::EvalOpts::valopt_
ValOpt valopt_
Definition: property.h:77
PropertySet::errMsg
uiString errMsg() const
Definition: property.h:145
Property::mnem
const Mnemonic * mnem() const
Definition: property.h:44
Property::mODTextTranslationClass
mODTextTranslationClass(Property)
Interval
Interval of values.
Definition: commontypes.h:30
PropertySet::PropertySet
PropertySet(const PropertyRefSelection &)
Creates ValueProperty's.
RangeProperty::RangeProperty
RangeProperty(const PropertyRef &pr)
Definition: property.h:201
PropertySet::indexOf
int indexOf(PropertyRef::StdType, int occ=0) const
PropertySet::indexOf
int indexOf(const Property &p) const
Definition: property.h:129
PropertySet::PropertySet
PropertySet()
Definition: property.h:110
IOPar
Generalized set of parameters of the keyword-value type.
Definition: iopar.h:55
Property::errMsg
virtual uiString errMsg() const
Definition: property.h:50
mDefPropertyFns
#define mDefPropertyFns(clss, typstr)
Definition: property.h:159
RangeProperty::gtAvgVal
float gtAvgVal() const
PropertySet::erase
void erase()
Definition: property.h:141
RangeProperty
Range of values. pos_ is usually in [0,1].
Definition: property.h:199

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