Mass++ Common Libraries v2.7.5
 All Classes Namespaces Files Functions Variables Enumerations Macros
Public Member Functions | Protected Attributes | List of all members
kome::core::NumberRestriction Class Reference

the restriction of number class More...

#include <NumberRestriction.h>

Public Member Functions

 NumberRestriction ()
 constructor
 
virtual ~NumberRestriction ()
 destructor
 
void reset ()
 resets restriction
 
void setInclusiveMinValue (const double value)
 sets inclusive min value More...
 
bool hasInclusiveMinValue ()
 judges whether this argument inclusive min value. More...
 
double getInclusiveMinValue (const double dfValue=0.0)
 gets min inclusive value More...
 
void setInclusiveMaxValue (const double value)
 sets inclusive max value More...
 
bool hasInclusiveMaxValue ()
 judges whether this argument inclusive max value. More...
 
double getInclusiveMaxValue (const double dfValue=0.0)
 gets max inclusive value More...
 
void setExclusiveMinValue (const double value)
 sets exclusive min value More...
 
bool hasExclusiveMinValue ()
 judges whether this argument exclusive min value. More...
 
double getExclusiveMinValue (const double dfValue=0.0)
 gets min exclusive value More...
 
void setExclusiveMaxValue (const double value)
 sets exclusive max value More...
 
bool hasExclusiveMaxValue ()
 judges whether this argument exclusive max value. More...
 
double getExclusiveMaxValue (const double dfValue=0.0)
 gets max exclusive value More...
 
double getLowerBound (const double dfValue=0.0)
 gets lower bound value More...
 
double getUpperBound (const double dfValue=0.0)
 gets upper bound value More...
 
bool checkDoubleValue (const double value)
 checks real number value is in the specified range More...
 
bool checkIntValue (const int value)
 checks integer value is in the specified range More...
 
std::string getRangeStr (const char *name)
 gets character string that means value range More...
 

Protected Attributes

boost::optional< double > m_minInclusive
 
boost::optional< double > m_maxInclusive
 
boost::optional< double > m_minExclusive
 
boost::optional< double > m_maxExclusive
 

Detailed Description

the restriction of number class

Definition at line 26 of file NumberRestriction.h.

Member Function Documentation

bool kome::core::NumberRestriction::checkDoubleValue ( const double  value)

checks real number value is in the specified range

Parameters
[in]valuevalue to be checked
Returns
If value is in the specified range, this method returns true.

Definition at line 169 of file NumberRestriction.cpp.

169  {
170  // min inclusive
171  if( m_minInclusive ) {
172  if( value < m_minInclusive.get() ) {
173  return false;
174  }
175  }
176 
177  // max inclusive
178  if( m_maxInclusive ) {
179  if( value > m_maxInclusive.get() ) {
180  return false;
181  }
182  }
183 
184  // min exclusive
185  if( m_minExclusive ) {
186  if( value <= m_minExclusive.get() ) {
187  return false;
188  }
189  }
190 
191  // max exclusive
192  if( m_maxExclusive ) {
193  if( value >= m_maxExclusive.get() ) {
194  return false;
195  }
196  }
197 
198  return true;
199 }
boost::optional< double > m_maxInclusive
boost::optional< double > m_maxExclusive
boost::optional< double > m_minExclusive
boost::optional< double > m_minInclusive
bool kome::core::NumberRestriction::checkIntValue ( const int  value)

checks integer value is in the specified range

Parameters
[in]valuevalue to be checked
Returns
If value is in the specified range, this method returns true.

Definition at line 202 of file NumberRestriction.cpp.

202  {
203  // min inclusive
204  if( m_minInclusive ) {
205  if( value < roundnum( m_minInclusive.get() ) ) {
206  return false;
207  }
208  }
209 
210  // max inclusive
211  if( m_maxInclusive ) {
212  if( value > roundnum( m_maxInclusive.get() ) ) {
213  return false;
214  }
215  }
216 
217  // min exclusive
218  if( m_minExclusive ) {
219  if( value <= roundnum( m_minExclusive.get() ) ) {
220  return false;
221  }
222  }
223 
224  // max exclusive
225  if( m_maxExclusive ) {
226  if( value >= roundnum( m_maxExclusive.get() ) ) {
227  return false;
228  }
229  }
230 
231  return true;
232 }
int roundnum(const double v)
gets the closest integer to the argument
boost::optional< double > m_maxInclusive
boost::optional< double > m_maxExclusive
boost::optional< double > m_minExclusive
boost::optional< double > m_minInclusive

Here is the call graph for this function:

double kome::core::NumberRestriction::getExclusiveMaxValue ( const double  dfValue = 0.0)

gets max exclusive value

Parameters
[in]dfValuedefault value
Returns
If this argument has exclusive max value, this method returns it, otherwise returns default value.

Definition at line 119 of file NumberRestriction.cpp.

119  {
120  if( m_maxExclusive ) {
121  return m_maxExclusive.get();
122  }
123  return dfValue;
124 }
boost::optional< double > m_maxExclusive
double kome::core::NumberRestriction::getExclusiveMinValue ( const double  dfValue = 0.0)

gets min exclusive value

Parameters
[in]dfValuedefault value
Returns
If this argument has exclusive min value, this method returns it, otherwise returns default value.

Definition at line 98 of file NumberRestriction.cpp.

98  {
99  if( m_minExclusive ) {
100  return m_minExclusive.get();
101  }
102  return dfValue;
103 }
boost::optional< double > m_minExclusive
double kome::core::NumberRestriction::getInclusiveMaxValue ( const double  dfValue = 0.0)

gets max inclusive value

Parameters
[in]dfValuedefault value
Returns
If this argument has inclusive max value, this method returns it, otherwise returns default value.

Definition at line 77 of file NumberRestriction.cpp.

77  {
78  if( m_maxInclusive ) {
79  return m_maxInclusive.get();
80  }
81  return dfValue;
82 }
boost::optional< double > m_maxInclusive
double kome::core::NumberRestriction::getInclusiveMinValue ( const double  dfValue = 0.0)

gets min inclusive value

Parameters
[in]dfValuedefault value
Returns
If this argument has inclusive min value, this method returns it, otherwise returns default value.

Definition at line 56 of file NumberRestriction.cpp.

56  {
57  if( m_minInclusive ) {
58  return m_minInclusive.get();
59  }
60  return dfValue;
61 }
boost::optional< double > m_minInclusive
double kome::core::NumberRestriction::getLowerBound ( const double  dfValue = 0.0)

gets lower bound value

Parameters
[in]dfValuedefault value
Returns
If this argument has lower bound value, this method returns it, otherwise returns default value.

Definition at line 127 of file NumberRestriction.cpp.

127  {
128  if( m_minInclusive ) {
129  double v0 = m_minInclusive.get();
130  if( m_minExclusive ) {
131  double v1 = m_minExclusive.get();
132 
133  // compare
134  return MAX( v0, v1 );
135  }
136  return v0;
137  }
138  else if( m_minExclusive ) {
139  double v1 = m_minExclusive.get();
140  return v1;
141  }
142 
143  // default value
144  return dfValue;
145 }
#define MAX(x, y)
Definition: CoreMacros.h:27
boost::optional< double > m_minExclusive
boost::optional< double > m_minInclusive
std::string kome::core::NumberRestriction::getRangeStr ( const char *  name)

gets character string that means value range

Parameters
[in]namenumber value name
Returns
character string that means value range

Definition at line 235 of file NumberRestriction.cpp.

235  {
236  // string
237  std::string range;
238 
239  // variables
240  boost::optional< double > v;
241  bool inclusive = false;
242 
243  // get min value
244  if( m_minExclusive ) {
245  v = m_minExclusive.get();
246  }
247  if( m_minInclusive ) {
248  if( !v || m_minInclusive.get() > v.get() ) {
249  v = m_minInclusive.get();
250  inclusive = true;
251  }
252  }
253 
254  // min value
255  if( v ) {
256 
258  {
259  range = FMT( "%g <", v.get() );
260  if( inclusive ) {
261  range.append( "=" );
262  }
263  range.append( " " );
264  range.append( NVL( name, "" ) );
265  }
266  else
267  {
268  // In the case where no maximum value is going to be expressed
269  // in the range string, it is better to put the name first.
270  range.append( NVL( name, "" ) );
271  range.append( " " );
272  if( inclusive ) {
273  range += FMT( ">= %g", v.get() );
274  }
275  else
276  {
277  range += FMT( "> %g", v.get() );
278  }
279  }
280  }
281 
282  // get max value
283  v.reset();
284  inclusive = false;
285 
286  if( m_maxExclusive ) {
287  v = m_maxExclusive.get();
288  }
289  if( m_maxInclusive ) {
290  if( !v || m_maxInclusive.get() < v.get() ) {
291  v = m_maxInclusive.get();
292  inclusive = true;
293  }
294  }
295 
296  // print maxvalue
297  if( v ) {
298  if( range.empty() ) {
299  range = NVL( name, "" );
300  }
301  range.append( " <" );
302  if( inclusive ) {
303  range.append( "=" );
304  }
305  range.append( FMT( " %g", v.get() ) );
306  }
307 
308  return range;
309 }
#define NVL(checkVal, replaceVal)
Definition: CoreMacros.h:99
boost::optional< double > m_maxInclusive
boost::optional< double > m_maxExclusive
boost::optional< double > m_minExclusive
boost::optional< double > m_minInclusive
double kome::core::NumberRestriction::getUpperBound ( const double  dfValue = 0.0)

gets upper bound value

Parameters
[in]dfValuedefault value
Returns
If this argument has upper bound value, this method returns it, otherwise returns default value.

Definition at line 148 of file NumberRestriction.cpp.

148  {
149  if( m_maxInclusive ) {
150  double v0 = m_maxInclusive.get();
151  if( m_maxExclusive ) {
152  double v1 = m_maxExclusive.get();
153 
154  // compare
155  return MIN( v0, v1 );
156  }
157  return v0;
158  }
159  else if( m_maxExclusive ) {
160  double v1 = m_maxExclusive.get();
161  return v1;
162  }
163 
164  // default value
165  return dfValue;
166 }
#define MIN(x, y)
Definition: CoreMacros.h:30
boost::optional< double > m_maxInclusive
boost::optional< double > m_maxExclusive
bool kome::core::NumberRestriction::hasExclusiveMaxValue ( )

judges whether this argument exclusive max value.

Returns
If this argument has exclusive max value, this method returns true.

Definition at line 111 of file NumberRestriction.cpp.

111  {
112  if( m_maxExclusive ) {
113  return true;
114  }
115  return false;
116 }
boost::optional< double > m_maxExclusive
bool kome::core::NumberRestriction::hasExclusiveMinValue ( )

judges whether this argument exclusive min value.

Returns
If this argument has exclusive min value, this method returns true.

Definition at line 90 of file NumberRestriction.cpp.

90  {
91  if( m_minExclusive ) {
92  return true;
93  }
94  return false;
95 }
boost::optional< double > m_minExclusive
bool kome::core::NumberRestriction::hasInclusiveMaxValue ( )

judges whether this argument inclusive max value.

Returns
If this argument has inclusive max value, this method returns true.

Definition at line 69 of file NumberRestriction.cpp.

69  {
70  if( m_maxInclusive ) {
71  return true;
72  }
73  return false;
74 }
boost::optional< double > m_maxInclusive
bool kome::core::NumberRestriction::hasInclusiveMinValue ( )

judges whether this argument inclusive min value.

Returns
If this argument has inclusive min value, this method returns true.

Definition at line 48 of file NumberRestriction.cpp.

48  {
49  if( m_minInclusive ) {
50  return true;
51  }
52  return false;
53 }
boost::optional< double > m_minInclusive
void kome::core::NumberRestriction::setExclusiveMaxValue ( const double  value)

sets exclusive max value

Parameters
[in]valueexclusive max value

Definition at line 106 of file NumberRestriction.cpp.

106  {
107  m_maxExclusive = value;
108 }
boost::optional< double > m_maxExclusive
void kome::core::NumberRestriction::setExclusiveMinValue ( const double  value)

sets exclusive min value

Parameters
[in]valueexclusive min value

Definition at line 85 of file NumberRestriction.cpp.

85  {
86  m_minExclusive = value;
87 }
boost::optional< double > m_minExclusive
void kome::core::NumberRestriction::setInclusiveMaxValue ( const double  value)

sets inclusive max value

Parameters
[in]valueinclusive max value

Definition at line 64 of file NumberRestriction.cpp.

64  {
65  m_maxInclusive = value;
66 }
boost::optional< double > m_maxInclusive
void kome::core::NumberRestriction::setInclusiveMinValue ( const double  value)

sets inclusive min value

Parameters
[in]valueinclusive min value

Definition at line 43 of file NumberRestriction.cpp.

43  {
44  m_minInclusive = value;
45 }
boost::optional< double > m_minInclusive

Member Data Documentation

boost::optional< double > kome::core::NumberRestriction::m_maxExclusive
protected

exclusive maximum value

Definition at line 48 of file NumberRestriction.h.

boost::optional< double > kome::core::NumberRestriction::m_maxInclusive
protected

inclusive maximum value

Definition at line 44 of file NumberRestriction.h.

boost::optional< double > kome::core::NumberRestriction::m_minExclusive
protected

exclusive minimum value

Definition at line 46 of file NumberRestriction.h.

boost::optional< double > kome::core::NumberRestriction::m_minInclusive
protected

inclusive minimum value

Definition at line 42 of file NumberRestriction.h.


The documentation for this class was generated from the following files: