OpendTect  6.3
integerid.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
8  Date: June 2016
9 ________________________________________________________________________
10 
11 -*/
12 
13 #include "undefval.h"
14 template <class T> class TypeSet;
15 
16 
46 template <class IntType>
48 {
49 public:
50 
51  typedef IntType IDType;
52 
53  inline IntegerID() : nr_(-1) {}
54  static inline IntegerID get( IntType i )
55  { return IntegerID(i); }
56 
57  inline IntType getI() const { return nr_; }
58  inline void setI( IntType i ) { nr_ = i; }
59 
60  inline bool operator ==( const IntegerID& oth ) const
61  { return nr_ == oth.nr_;};
62  inline bool operator !=( const IntegerID& oth ) const
63  { return nr_ != oth.nr_;};
64  // Do not add '>' or similar!
65 
66  inline bool isInvalid() const { return nr_ < 0; }
67  inline bool isValid() const { return !isInvalid(); }
68  inline void setInvalid() { nr_ = -1; }
69  static inline IntegerID getInvalid() { return IntegerID(-1); }
70 
71 protected:
72 
73  IntType nr_;
74 
75  inline IntegerID( IntType i )
76  : nr_(i) { /* keep this constructor private! */ }
77 
78  friend class TypeSet<IntType>;
79 
80 };
81 
82 
83 #define mDefIntegerIDType(IntType,classname) \
84  \
85 class classname : public IntegerID<IntType> \
86 { \
87 public: \
88  \
89  inline classname() {} \
90  \
91  static inline classname get( IntType i ) \
92  { return classname(i); } \
93  \
94  inline bool operator ==( const classname& oth ) const \
95  { return IntegerID<IntType>::operator ==(oth); } \
96  inline bool operator !=( const classname& oth ) const \
97  { return IntegerID<IntType>::operator !=(oth); } \
98  \
99  static inline classname getInvalid() { return classname(-1); } \
100  \
101 protected: \
102  \
103  inline classname( IntType i ) \
104  : IntegerID<IntType>(i) {} \
105  \
106  friend class TypeSet<classname>; \
107  \
108 }
IntType IDType
Definition: integerid.h:51
bool operator==(const ArrayNDInfo &a1, const ArrayNDInfo &a2)
Definition: arrayndinfo.h:51
bool isValid() const
Definition: integerid.h:67
void setI(IntType i)
Definition: integerid.h:58
IntType getI() const
Definition: integerid.h:57
single integer ID with comparison but no automatic conversion. Note that you will want to make a subc...
Definition: integerid.h:47
IntegerID(IntType i)
Definition: integerid.h:75
void setInvalid()
Definition: integerid.h:68
Set of (small) copyable elements.
Definition: commontypes.h:26
bool operator!=(const ArrayNDInfo &a1, const ArrayNDInfo &a2)
Definition: arrayndinfo.h:60
IntegerID()
Definition: integerid.h:53
bool isInvalid() const
Definition: integerid.h:66
IntType nr_
Definition: integerid.h:73
static IntegerID getInvalid()
Definition: integerid.h:69
#define mClass(module)
Definition: commondefs.h:161

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