Panda3D
 All Classes Functions Variables Enumerations
dcNumericRange.h
1 // Filename: dcNumericRange.h
2 // Created by: drose (21Jun04)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef DCNUMERICRANGE_H
16 #define DCNUMERICRANGE_H
17 
18 #include "dcbase.h"
19 #include "hashGenerator.h"
20 #include "dcPacker.h"
21 
22 ////////////////////////////////////////////////////////////////////
23 // Class : DCNumericRange
24 // Description : Represents a range of legal integer or floating-point
25 // values. This is used to constrain simple numeric
26 // types, as well as array sizes.
27 ////////////////////////////////////////////////////////////////////
28 template <class NUM>
30 public:
31  typedef NUM Number;
32 
33  INLINE DCNumericRange();
34  INLINE DCNumericRange(Number min, Number max);
35  INLINE DCNumericRange(const DCNumericRange &copy);
36  INLINE void operator = (const DCNumericRange &copy);
37 
38  bool is_in_range(Number num) const;
39  INLINE void validate(Number num, bool &range_error) const;
40 
41  INLINE bool has_one_value() const;
42  INLINE Number get_one_value() const;
43 
44  void generate_hash(HashGenerator &hashgen) const;
45 
46  void output(ostream &out, Number divisor = 1) const;
47  void output_char(ostream &out, Number divisor = 1) const;
48 
49 public:
50  INLINE void clear();
51  bool add_range(Number min, Number max);
52 
53  INLINE bool is_empty() const;
54  INLINE int get_num_ranges() const;
55  INLINE Number get_min(int n) const;
56  INLINE Number get_max(int n) const;
57 
58 private:
59  class MinMax {
60  public:
61  INLINE bool operator < (const MinMax &other) const;
62 
63  Number _min;
64  Number _max;
65  };
66  INLINE void output_minmax(ostream &out, Number divisor, const MinMax &range) const;
67  INLINE void output_minmax_char(ostream &out, const MinMax &range) const;
68 
69  typedef pvector<MinMax> Ranges;
70  Ranges _ranges;
71 };
72 
73 #include "dcNumericRange.I"
74 
80 
81 #endif
void output_char(ostream &out, Number divisor=1) const
Outputs the range, formatting the numeric values as quoted ASCII characters.
bool add_range(Number min, Number max)
Adds a new minmax to the list of ranges.
bool is_empty() const
Returns true if the range contains no elements (and thus allows all numbers), false if it contains at...
Represents a range of legal integer or floating-point values.
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:39
Number get_min(int n) const
Returns the minimum value defined by the nth component.
This class generates an arbitrary hash number from a sequence of ints.
Definition: hashGenerator.h:26
void validate(Number num, bool &range_error) const
Convenience function to validate the indicated number.
Number get_max(int n) const
Returns the maximum value defined by the nth component.
bool is_in_range(Number num) const
Returns true if the indicated number is within the specified range, false otherwise.
Number get_one_value() const
If has_one_value() returns true, this returns the one legal value accepted by the numeric range...
bool has_one_value() const
Returns true if the numeric range specifies exactly one legal value, false if multiple values are leg...
int get_num_ranges() const
Returns the number of minmax components in the range description.