47 _ranges = copy._ranges;
57 if (_ranges.empty()) {
61 typename Ranges::const_iterator ri;
62 for (ri = _ranges.begin(); ri != _ranges.end(); ++ri) {
63 if (num >= (*ri)._min && num <= (*ri)._max) {
78 validate(Number num,
bool &range_error)
const {
79 if (!is_in_range(num)) {
91 return _ranges.size() == 1 && _ranges[0]._min == _ranges[0]._max;
101 nassertr(has_one_value(), 0);
102 return _ranges[0]._min;
111 if (!_ranges.empty()) {
112 hashgen.
add_int(_ranges.size());
113 typename Ranges::const_iterator ri;
114 for (ri = _ranges.begin(); ri != _ranges.end(); ++ri) {
117 hashgen.
add_int((
int)(*ri)._min);
118 hashgen.
add_int((
int)(*ri)._max);
128 output(std::ostream &out, Number divisor)
const {
129 if (!_ranges.empty()) {
130 typename Ranges::const_iterator ri;
131 ri = _ranges.begin();
132 output_minmax(out, divisor, *ri);
134 while (ri != _ranges.end()) {
136 output_minmax(out, divisor, *ri);
150 output(out, divisor);
153 if (!_ranges.empty()) {
154 typename Ranges::const_iterator ri;
155 ri = _ranges.begin();
156 output_minmax_char(out, *ri);
158 while (ri != _ranges.end()) {
160 output_minmax_char(out, *ri);
190 typename Ranges::const_iterator ri;
191 for (ri = _ranges.begin(); ri != _ranges.end(); ++ri) {
192 if ((min >= (*ri)._min && min <= (*ri)._max) ||
193 (max >= (*ri)._min && max <= (*ri)._max) ||
194 (min < (*ri)._min && max > (*ri)._max)) {
202 _ranges.push_back(minmax);
214 return _ranges.empty();
223 return _ranges.size();
232 nassertr(n >= 0 && n < (
int)_ranges.size(), 0);
233 return _ranges[n]._min;
242 nassertr(n >= 0 && n < (
int)_ranges.size(), 0);
243 return _ranges[n]._max;
251 output_minmax(std::ostream &out, Number divisor,
const MinMax &range)
const {
253 if (range._min == range._max) {
256 out << range._min <<
"-" << range._max;
259 if (range._min == range._max) {
260 out << (double)range._min / (
double)divisor;
262 out << (double)range._min / (
double)divisor
264 << (double)range._max / (
double)divisor;
275 if (range._min == range._max) {
void add_int(int num)
Adds another integer to the hash so far.
void validate(Number num, bool &range_error) const
Convenience function to validate the indicated number.
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...
Represents a range of legal integer or floating-point values.
int get_num_ranges() const
Returns the number of minmax components in the range description.
Number get_max(int n) const
Returns the maximum value defined by the nth component.
Number get_one_value() const
If has_one_value() returns true, this returns the one legal value accepted by the numeric range.
Number get_min(int n) const
Returns the minimum value defined by the nth component.
static void enquote_string(std::ostream &out, char quote_mark, const std::string &str)
Outputs the indicated string within quotation marks.
This class generates an arbitrary hash number from a sequence of ints.
void output_char(std::ostream &out, Number divisor=1) const
Outputs the range, formatting the numeric values as quoted ASCII characters.
bool is_empty() const
Returns true if the range contains no elements (and thus allows all numbers), false if it contains at...
bool is_in_range(Number num) const
Returns true if the indicated number is within the specified range, false otherwise.