Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ShBitSet.hpp

00001 // Sh: A GPU metaprogramming language.
00002 //
00003 // Copyright 2003-2005 Serious Hack Inc.
00004 // 
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 //
00010 // This library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
00018 // MA  02110-1301, USA
00020 #ifndef SHBITSET_HPP
00021 #define SHBITSET_HPP
00022 
00023 #include <cstddef>
00024 #include <iosfwd>
00025 #include "ShDllExport.hpp"
00026 
00027 namespace SH {
00028 
00029 /* A reference to a single bit in a set.
00030  * @see ShBitSet
00031  */
00032 class
00033 SH_DLLEXPORT ShBitRef {
00034 public:
00035   operator bool() const;
00036   ShBitRef& operator=(bool b);
00037 
00038 private:
00039   friend class ShBitSet;
00040   
00041   ShBitRef(unsigned int* byte, unsigned int mask);
00042 
00043   unsigned int* m_byte;
00044   unsigned int m_mask;
00045 
00046   ShBitRef(const ShBitRef& other);
00047   ShBitRef& operator=(const ShBitRef& other);
00048 };
00049 
00055 class
00056 SH_DLLEXPORT ShBitSet {
00057 public:
00062   ShBitSet();
00063   explicit ShBitSet(std::size_t size);
00064   ShBitSet(const ShBitSet& other);
00065   
00066   ~ShBitSet();
00067 
00068   ShBitSet& operator=(const ShBitSet& other);
00069   ShBitSet& operator&=(const ShBitSet& other);
00070   ShBitSet& operator|=(const ShBitSet& other);
00071   ShBitSet& operator^=(const ShBitSet& other);
00072 
00073   ShBitSet operator&(const ShBitSet& other) const;
00074   ShBitSet operator|(const ShBitSet& other) const;
00075   ShBitSet operator^(const ShBitSet& other) const;
00076   
00077   ShBitSet operator~() const;
00078 
00079   bool operator==(const ShBitSet& other) const;
00080   bool operator!=(const ShBitSet& other) const;
00081 
00082   // Return true iff all entries are 1
00083   bool full() const;
00084   // Return true iff all entries are 0
00085   bool empty() const;
00086   
00087   std::size_t size() const;
00088 
00089   bool operator[](std::size_t i) const;
00090   ShBitRef operator[](std::size_t i);
00091 
00092 private:
00093   std::size_t m_size;
00094   unsigned int* m_data;
00095 };
00096 
00097 SH_DLLEXPORT
00098 std::ostream& operator<<(std::ostream& out, const ShBitSet& bitset);
00099 
00100 }
00101 
00102 #endif

Generated on Thu Jul 28 17:33:01 2005 for Sh by  doxygen 1.4.3-20050530