ODIN
ldrnumbers.h
1 /***************************************************************************
2  ldrnumbers.h - description
3  -------------------
4  begin : Mon Jul 12 2004
5  copyright : (C) 2000-2021 by Thies H. Jochimsen
6  email : thies@jochimsen.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef LDRNUMBERS_H
19 #define LDRNUMBERS_H
20 
21 
22 #include <odinpara/ldrbase.h>
23 #include <tjutils/tjtypes.h>
24 
25 
31 
36 template<class T>
37 class LDRnumber : public virtual LDRbase {
38 
39  public:
40 
44  LDRnumber() {common_init();}
45 
51  LDRnumber(T v, const STD_string& name="");
52 
53 
58 
62  LDRnumber<T>& operator = (T v) {val=v; return *this;}
63 
68 
69  // code to make the number appear like a built-in number
70  operator T () const {return val;}
71  T operator += (T rhsval) {val+=rhsval; return *this;}
72  T operator -= (T rhsval) {val-=rhsval; return *this;}
73  T operator *= (T rhsval) {val*=rhsval; return *this;}
74  T operator /= (T rhsval) {val/=rhsval; return *this;}
75  T operator ++ () {val=val+(T)1; return val;} // prefix
76  T operator ++ (int) {T tmp=val; val=val+(T)1; return tmp;} // postfix
77  T operator -- () {val=val-(T)1; return val;} // prefix
78  T operator -- (int) {T tmp=val; val=val-(T)1; return tmp;} // postfix
79 
84  LDRnumber<T>& set_minmaxval(double min,double max) {minval=min; maxval=max; return *this;}
85 
86  // overwriting virtual functions from LDRbase
87  STD_string printvalstring(const LDRserBase* ser=0) const;
88  bool parsevalstring(const STD_string& parstring, const LDRserBase* ser=0);
89  STD_string get_parx_code(parxCodeType type) const;
90  double get_minval() const {return minval;}
91  double get_maxval() const {return maxval;}
92  STD_string get_typeInfo(bool parx_equivtype=false) const {return TypeTraits::type2label(val);}
93  LDRbase* create_copy() const {return new LDRnumber<T>(*this);}
94  T* cast(T*) {return &val;}
95 
96  private:
97 
98  void common_init();
99 
100  T val;
101  double minval,maxval;
102 };
103 
105 //
106 // Aliases:
107 
112 
117 
122 
127 
128 
132 #endif
133 
LDRbase * create_copy() const
Definition: ldrnumbers.h:93
bool parsevalstring(const STD_string &parstring, const LDRserBase *ser=0)
LDRnumber< T > & set_minmaxval(double min, double max)
Definition: ldrnumbers.h:84
STD_string printvalstring(const LDRserBase *ser=0) const
STD_string get_typeInfo(bool parx_equivtype=false) const
Definition: ldrnumbers.h:92
LDRnumber< T > & operator=(T v)
Definition: ldrnumbers.h:62
STD_string get_parx_code(parxCodeType type) const
double get_maxval() const
Definition: ldrnumbers.h:91
LDRnumber(T v, const STD_string &name="")
double get_minval() const
Definition: ldrnumbers.h:90
LDRnumber(const LDRnumber< T > &bi)
Definition: ldrnumbers.h:57
LDRnumber< int > LDRint
Definition: ldrnumbers.h:111
LDRnumber< float > LDRfloat
Definition: ldrnumbers.h:116
LDRnumber< STD_complex > LDRcomplex
Definition: ldrnumbers.h:126
LDRnumber< double > LDRdouble
Definition: ldrnumbers.h:121
parxCodeType
Definition: ldrbase.h:216