Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/putil/bitMask.h

Go to the documentation of this file.
00001 // Filename: bitMask.h
00002 // Created by:  drose (08Jun00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef BITMASK_H
00020 #define BITMASK_H
00021 
00022 #include <pandabase.h>
00023 
00024 #include "numeric_types.h"
00025 #include "typedObject.h"
00026 #include "indent.h"
00027 
00028 #include <checksumHashGenerator.h>
00029 
00030 
00031 ////////////////////////////////////////////////////////////////////
00032 //       Class : BitMask
00033 // Description : A general bitmask class.  This stores an array of
00034 //               bits of some length that must fit within a given word
00035 //               of the indicated type.  See also BitArray.
00036 ////////////////////////////////////////////////////////////////////
00037 template<class WordType, int num_bits>
00038 class BitMask {
00039 PUBLISHED:
00040   INLINE BitMask();
00041   INLINE BitMask(WordType init_value);
00042   INLINE BitMask(const BitMask<WordType, num_bits> &copy);
00043   INLINE void operator = (const BitMask<WordType, num_bits> &copy);
00044 
00045   INLINE static BitMask<WordType, num_bits> all_on();
00046   INLINE static BitMask<WordType, num_bits> all_off();
00047   INLINE static BitMask<WordType, num_bits> lower_on(int on_bits);
00048   INLINE static BitMask<WordType, num_bits> bit(int index);
00049 
00050   INLINE ~BitMask();
00051 
00052   INLINE int get_num_bits() const;
00053   INLINE bool get_bit(int index) const;
00054   INLINE void set_bit(int index);
00055   INLINE void clear_bit(int index);
00056   INLINE void set_bit_to(int index, bool value);
00057   INLINE bool is_zero() const;
00058 
00059   INLINE WordType extract(int low_bit, int size) const;
00060   INLINE void store(WordType value, int low_bit, int size);
00061   INLINE WordType get_word() const;
00062   INLINE void set_word(WordType value);
00063 
00064   INLINE void invert_in_place();
00065   INLINE void clear();
00066 
00067   void output(ostream &out) const;
00068   void output_binary(ostream &out, int spaces_every = 4) const;
00069   void output_hex(ostream &out, int spaces_every = 4) const;
00070   void write(ostream &out, int indent_level = 0) const;
00071 
00072   INLINE bool operator == (const BitMask<WordType, num_bits> &other) const;
00073   INLINE bool operator != (const BitMask<WordType, num_bits> &other) const;
00074   INLINE bool operator < (const BitMask<WordType, num_bits> &other) const;
00075   INLINE int compare_to(const BitMask<WordType, num_bits> &other) const;
00076 
00077   INLINE BitMask<WordType, num_bits>
00078   operator & (const BitMask<WordType, num_bits> &other) const;
00079 
00080   INLINE BitMask<WordType, num_bits>
00081   operator | (const BitMask<WordType, num_bits> &other) const;
00082 
00083   INLINE BitMask<WordType, num_bits>
00084   operator ^ (const BitMask<WordType, num_bits> &other) const;
00085 
00086   INLINE BitMask<WordType, num_bits>
00087   operator ~ () const;
00088 
00089   INLINE BitMask<WordType, num_bits>
00090   operator << (int shift) const;
00091 
00092   INLINE BitMask<WordType, num_bits>
00093   operator >> (int shift) const;
00094 
00095   INLINE void operator &= (const BitMask<WordType, num_bits> &other);
00096   INLINE void operator |= (const BitMask<WordType, num_bits> &other);
00097   INLINE void operator ^= (const BitMask<WordType, num_bits> &other);
00098   INLINE void operator <<= (int shift);
00099   INLINE void operator >>= (int shift);
00100 
00101 public:
00102   INLINE void generate_hash(ChecksumHashGenerator &hashgen) const;
00103 
00104 private:
00105   WordType _word;
00106 
00107 public:
00108   static TypeHandle get_class_type() {
00109     return _type_handle;
00110   }
00111   static void init_type();
00112 
00113 private:
00114   static TypeHandle _type_handle;
00115 };
00116 
00117 #include "bitMask.I"
00118 
00119 template<class WordType, int num_bits>
00120 INLINE ostream &operator << (ostream &out, const BitMask<WordType, num_bits> &bitmask) {
00121   bitmask.output(out);
00122   return out;
00123 }
00124 
00125 // We need to define this temporary macro so we can pass a parameter
00126 // containing a comma through the macro.
00127 #define BITMASK32_DEF BitMask<PN_uint32, 32>
00128 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, BITMASK32_DEF);
00129 
00130 typedef BitMask<PN_uint32, 32> BitMask32;
00131 
00132 // Tell GCC that we'll take care of the instantiation explicitly here.
00133 #ifdef __GNUC__
00134 #pragma interface
00135 #endif
00136 
00137 #endif

Generated on Fri May 2 00:43:31 2003 for Panda by doxygen1.3