57 _ranges = copy._ranges;
69 if (_ranges.empty()) {
73 TYPENAME Ranges::const_iterator ri;
74 for (ri = _ranges.begin(); ri != _ranges.end(); ++ri) {
75 if (num >= (*ri)._min && num <= (*ri)._max) {
93 validate(Number num,
bool &range_error)
const {
94 if (!is_in_range(num)) {
108 return _ranges.size() == 1 && _ranges[0]._min == _ranges[0]._max;
120 nassertr(has_one_value(), 0);
121 return _ranges[0]._min;
132 if (!_ranges.empty()) {
133 hashgen.
add_int(_ranges.size());
134 TYPENAME Ranges::const_iterator ri;
135 for (ri = _ranges.begin(); ri != _ranges.end(); ++ri) {
138 hashgen.
add_int((
int)(*ri)._min);
139 hashgen.
add_int((
int)(*ri)._max);
151 output(ostream &out, Number divisor)
const {
152 if (!_ranges.empty()) {
153 TYPENAME Ranges::const_iterator ri;
154 ri = _ranges.begin();
155 output_minmax(out, divisor, *ri);
157 while (ri != _ranges.end()) {
159 output_minmax(out, divisor, *ri);
175 output(out, divisor);
178 if (!_ranges.empty()) {
179 TYPENAME Ranges::const_iterator ri;
180 ri = _ranges.begin();
181 output_minmax_char(out, *ri);
183 while (ri != _ranges.end()) {
185 output_minmax_char(out, *ri);
220 TYPENAME Ranges::const_iterator ri;
221 for (ri = _ranges.begin(); ri != _ranges.end(); ++ri) {
222 if ((min >= (*ri)._min && min <= (*ri)._max) ||
223 (max >= (*ri)._min && max <= (*ri)._max) ||
224 (min < (*ri)._min && max > (*ri)._max)) {
232 _ranges.push_back(minmax);
247 return _ranges.empty();
259 return _ranges.size();
270 nassertr(n >= 0 && n < (
int)_ranges.size(), 0);
271 return _ranges[n]._min;
282 nassertr(n >= 0 && n < (
int)_ranges.size(), 0);
283 return _ranges[n]._max;
293 output_minmax(ostream &out, Number divisor,
const MinMax &range)
const {
295 if (range._min == range._max) {
298 out << range._min <<
"-" << range._max;
301 if (range._min == range._max) {
302 out << (double)range._min / (
double)divisor;
304 out << (double)range._min / (
double)divisor
306 << (double)range._max / (
double)divisor;
319 if (range._min == range._max) {
void output_char(ostream &out, Number divisor=1) const
Outputs the range, formatting the numeric values as quoted ASCII characters.
void add_int(int num)
Adds another integer to the hash so far.
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.
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.
static void enquote_string(ostream &out, char quote_mark, const string &str)
Outputs the indicated string within quotation marks.
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.