Panda3D
 All Classes Functions Variables Enumerations
dcNumericRange.h
00001 // Filename: dcNumericRange.h
00002 // Created by:  drose (21Jun04)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef DCNUMERICRANGE_H
00016 #define DCNUMERICRANGE_H
00017 
00018 #include "dcbase.h"
00019 #include "hashGenerator.h"
00020 #include "dcPacker.h"
00021 
00022 ////////////////////////////////////////////////////////////////////
00023 //       Class : DCNumericRange
00024 // Description : Represents a range of legal integer or floating-point
00025 //               values.  This is used to constrain simple numeric
00026 //               types, as well as array sizes.
00027 ////////////////////////////////////////////////////////////////////
00028 template <class NUM>
00029 class DCNumericRange {
00030 public:
00031   typedef NUM Number;
00032 
00033   INLINE DCNumericRange();
00034   INLINE DCNumericRange(Number min, Number max);
00035   INLINE DCNumericRange(const DCNumericRange &copy);
00036   INLINE void operator = (const DCNumericRange &copy);
00037 
00038   bool is_in_range(Number num) const;
00039   INLINE void validate(Number num, bool &range_error) const;
00040 
00041   INLINE bool has_one_value() const;
00042   INLINE Number get_one_value() const;
00043 
00044   void generate_hash(HashGenerator &hashgen) const;
00045 
00046   void output(ostream &out, Number divisor = 1) const;
00047   void output_char(ostream &out, Number divisor = 1) const;
00048 
00049 public:
00050   INLINE void clear();
00051   bool add_range(Number min, Number max);
00052 
00053   INLINE bool is_empty() const;
00054   INLINE int get_num_ranges() const;
00055   INLINE Number get_min(int n) const;
00056   INLINE Number get_max(int n) const;
00057 
00058 private:
00059   class MinMax {
00060   public:
00061     INLINE bool operator < (const MinMax &other) const;
00062 
00063     Number _min;
00064     Number _max;
00065   };
00066   INLINE void output_minmax(ostream &out, Number divisor, const MinMax &range) const;
00067   INLINE void output_minmax_char(ostream &out, const MinMax &range) const;
00068 
00069   typedef pvector<MinMax> Ranges;
00070   Ranges _ranges;
00071 };
00072 
00073 #include "dcNumericRange.I"
00074 
00075 typedef DCNumericRange<int> DCIntRange;
00076 typedef DCNumericRange<unsigned int> DCUnsignedIntRange;
00077 typedef DCNumericRange<PN_int64> DCInt64Range;
00078 typedef DCNumericRange<PN_uint64> DCUnsignedInt64Range;
00079 typedef DCNumericRange<double> DCDoubleRange;
00080 
00081 #endif
 All Classes Functions Variables Enumerations