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 software is provided 'as-is', without any express or implied
00006 // warranty. In no event will the authors be held liable for any damages
00007 // arising from the use of this software.
00008 // 
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it
00011 // freely, subject to the following restrictions:
00012 // 
00013 // 1. The origin of this software must not be misrepresented; you must
00014 // not claim that you wrote the original software. If you use this
00015 // software in a product, an acknowledgment in the product documentation
00016 // would be appreciated but is not required.
00017 // 
00018 // 2. Altered source versions must be plainly marked as such, and must
00019 // not be misrepresented as being the original software.
00020 // 
00021 // 3. This notice may not be removed or altered from any source
00022 // distribution.
00024 #ifndef SHBITSET_HPP
00025 #define SHBITSET_HPP
00026 
00027 #include <cstddef>
00028 #include <iosfwd>
00029 #include "ShDllExport.hpp"
00030 
00031 namespace SH {
00032 
00033 /* A reference to a single bit in a set.
00034  * @see ShBitSet
00035  */
00036 class
00037 SH_DLLEXPORT ShBitRef {
00038 public:
00039   operator bool() const;
00040   ShBitRef& operator=(bool b);
00041 
00042 private:
00043   friend class ShBitSet;
00044   
00045   ShBitRef(unsigned int* byte, unsigned int mask);
00046 
00047   unsigned int* m_byte;
00048   unsigned int m_mask;
00049 
00050   ShBitRef(const ShBitRef& other);
00051   ShBitRef& operator=(const ShBitRef& other);
00052 };
00053 
00059 class
00060 SH_DLLEXPORT ShBitSet {
00061 public:
00066   ShBitSet();
00067   explicit ShBitSet(std::size_t size);
00068   ShBitSet(const ShBitSet& other);
00069   
00070   ~ShBitSet();
00071 
00072   ShBitSet& operator=(const ShBitSet& other);
00073   ShBitSet& operator&=(const ShBitSet& other);
00074   ShBitSet& operator|=(const ShBitSet& other);
00075   ShBitSet& operator^=(const ShBitSet& other);
00076 
00077   ShBitSet operator&(const ShBitSet& other) const;
00078   ShBitSet operator|(const ShBitSet& other) const;
00079   ShBitSet operator^(const ShBitSet& other) const;
00080   
00081   ShBitSet operator~() const;
00082 
00083   bool operator==(const ShBitSet& other) const;
00084   bool operator!=(const ShBitSet& other) const;
00085 
00086   // Return true iff all entries are 1
00087   bool full() const;
00088   // Return true iff all entries are 0
00089   bool empty() const;
00090   
00091   std::size_t size() const;
00092 
00093   bool operator[](std::size_t i) const;
00094   ShBitRef operator[](std::size_t i);
00095 
00096 private:
00097   std::size_t m_size;
00098   unsigned int* m_data;
00099 };
00100 
00101 SH_DLLEXPORT
00102 std::ostream& operator<<(std::ostream& out, const ShBitSet& bitset);
00103 
00104 }
00105 
00106 #endif

Generated on Wed Jun 15 18:12:38 2005 for Sh by  doxygen 1.4.3-20050530