Panda3D
Loading...
Searching...
No Matches
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 */
25template <class NUM>
26class EXPCL_DIRECT_DCPARSER DCNumericRange {
27public:
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
46public:
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
55private:
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
72typedef DCNumericRange<int> DCIntRange;
73typedef DCNumericRange<unsigned int> DCUnsignedIntRange;
74typedef DCNumericRange<int64_t> DCInt64Range;
75typedef DCNumericRange<uint64_t> DCUnsignedInt64Range;
76typedef DCNumericRange<double> DCDoubleRange;
77
78#endif
Represents a range of legal integer or floating-point values.
bool add_range(Number min, Number max)
Adds a new minmax to the list of ranges.
bool has_one_value() const
Returns true if the numeric range specifies exactly one legal value, false if multiple values are leg...
Number get_max(int n) const
Returns the maximum value defined by the nth component.
Number get_min(int n) const
Returns the minimum value defined by the nth component.
int get_num_ranges() const
Returns the number of minmax components in the range description.
void output_char(std::ostream &out, Number divisor=1) const
Outputs the range, formatting the numeric values as quoted ASCII characters.
void validate(Number num, bool &range_error) const
Convenience function to validate the indicated number.
bool is_empty() const
Returns true if the range contains no elements (and thus allows all numbers), false if it contains at...
Number get_one_value() const
If has_one_value() returns true, this returns the one legal value accepted by the numeric range.
bool is_in_range(Number num) const
Returns true if the indicated number is within the specified range, false otherwise.
This class generates an arbitrary hash number from a sequence of ints.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.