Panda3D
dcNumericRange.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file dcNumericRange.h
10  * @author drose
11  * @date 2004-06-21
12  */
13 
14 #ifndef DCNUMERICRANGE_H
15 #define DCNUMERICRANGE_H
16 
17 #include "dcbase.h"
18 #include "hashGenerator.h"
19 #include "dcPacker.h"
20 
21 /**
22  * Represents a range of legal integer or floating-point values. This is used
23  * to constrain simple numeric types, as well as array sizes.
24  */
25 template <class NUM>
26 class EXPCL_DIRECT_DCPARSER DCNumericRange {
27 public:
28  typedef NUM Number;
29 
30  INLINE DCNumericRange();
31  INLINE DCNumericRange(Number min, Number max);
32  INLINE DCNumericRange(const DCNumericRange &copy);
33  INLINE void operator = (const DCNumericRange &copy);
34 
35  INLINE bool is_in_range(Number num) const;
36  INLINE void validate(Number num, bool &range_error) const;
37 
38  INLINE bool has_one_value() const;
39  INLINE Number get_one_value() const;
40 
41  INLINE void generate_hash(HashGenerator &hashgen) const;
42 
43  INLINE void output(std::ostream &out, Number divisor = 1) const;
44  INLINE void output_char(std::ostream &out, Number divisor = 1) const;
45 
46 public:
47  INLINE void clear();
48  INLINE bool add_range(Number min, Number max);
49 
50  INLINE bool is_empty() const;
51  INLINE int get_num_ranges() const;
52  INLINE Number get_min(int n) const;
53  INLINE Number get_max(int n) const;
54 
55 private:
56  class MinMax {
57  public:
58  INLINE bool operator < (const MinMax &other) const;
59 
60  Number _min;
61  Number _max;
62  };
63  INLINE void output_minmax(std::ostream &out, Number divisor, const MinMax &range) const;
64  INLINE void output_minmax_char(std::ostream &out, const MinMax &range) const;
65 
66  typedef pvector<MinMax> Ranges;
67  Ranges _ranges;
68 };
69 
70 #include "dcNumericRange.I"
71 
77 
78 #endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Represents a range of legal integer or floating-point values.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:42
This class generates an arbitrary hash number from a sequence of ints.
Definition: hashGenerator.h:24
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.