w_bitmap.h

00001 /*<std-header orig-src='shore' incl-file-exclusion='W_BITMAP_H'>
00002 
00003  $Id: w_bitmap.h,v 1.13 2010/05/26 01:20:23 nhall Exp $
00004 
00005 SHORE -- Scalable Heterogeneous Object REpository
00006 
00007 Copyright (c) 1994-99 Computer Sciences Department, University of
00008                       Wisconsin -- Madison
00009 All Rights Reserved.
00010 
00011 Permission to use, copy, modify and distribute this software and its
00012 documentation is hereby granted, provided that both the copyright
00013 notice and this permission notice appear in all copies of the
00014 software, derivative works or modified versions, and any portions
00015 thereof, and that both notices appear in supporting documentation.
00016 
00017 THE AUTHORS AND THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY
00018 OF WISCONSIN - MADISON ALLOW FREE USE OF THIS SOFTWARE IN ITS
00019 "AS IS" CONDITION, AND THEY DISCLAIM ANY LIABILITY OF ANY KIND
00020 FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
00021 
00022 This software was developed with support by the Advanced Research
00023 Project Agency, ARPA order number 018 (formerly 8230), monitored by
00024 the U.S. Army Research Laboratory under contract DAAB07-91-C-Q518.
00025 Further funding for this work was provided by DARPA through
00026 Rome Research Laboratory Contract No. F30602-97-2-0247.
00027 
00028 */
00029 
00030 #ifndef W_BITMAP_H
00031 #define W_BITMAP_H
00032 
00033 #include "w_defines.h"
00034 
00035 /*  -- do not edit anything above this line --   </std-header>*/
00036 
00037 #include <w_base.h>
00038 
00039 #ifdef __GNUG__
00040 #pragma interface
00041 #endif
00042 
00043 /** \brief Bitmaps of arbitrary sizes (in bits).  NOT USED by the storage manager.
00044  *\ingroup UNUSED 
00045  */
00046 class w_bitmap_t : public w_base_t {
00047 public:
00048     /// construct for \e size bits
00049     NORET            w_bitmap_t(uint4_t size);
00050     /// construct for \e size bits, using given pointer to storage 
00051     NORET            w_bitmap_t(uint1_t* p, uint4_t size);
00052 
00053     NORET            ~w_bitmap_t();
00054 
00055     /// clear all bits
00056     void            zero();
00057     /// set all bits
00058     void            fill();
00059 
00060     void            resetPtr(uint1_t* p, uint4_t size);
00061     /// set bit at offset
00062     void            set(uint4_t offset);
00063     /// return first set bit after bit at start
00064     int4_t            first_set(uint4_t start) const;
00065     /// return # bits set
00066     uint4_t            num_set() const;
00067     /// return true iff bit at offset is set
00068     bool            is_set(uint4_t offset) const;
00069 
00070     /// clear bit at offset
00071     void            clr(uint4_t offset);
00072     /// return first clear bit after bit at start
00073     int4_t            first_clr(uint4_t start) const;
00074     /// return # bits clear
00075     uint4_t            num_clr() const;
00076     /// return true iff bit at offset is clear
00077     bool            is_clr(uint4_t offset) const;
00078 
00079     /// return size in bits
00080     uint4_t            size() const;        // # bits
00081 
00082     /// return size in bytes needed for numBits
00083     static int        bytesForBits(uint4_t numBits);
00084 
00085     /// return pointer to the storage area
00086     uint1_t*            addr();
00087     /// return const pointer to the storage area
00088     const uint1_t*        addr() const;
00089 
00090     friend ostream&        operator<<(ostream&, const w_bitmap_t&);
00091 private:
00092     uint1_t*             ptr;
00093     uint4_t            sz; // # bits
00094     bool            mem_alloc;
00095 
00096 };
00097 
00098 inline NORET
00099 w_bitmap_t::w_bitmap_t(uint1_t* p, uint4_t size)
00100     : ptr(p), sz(size), mem_alloc(false)
00101 {
00102 }
00103 
00104 inline NORET
00105 w_bitmap_t::~w_bitmap_t()
00106 {
00107    if (mem_alloc) delete [] ptr ; 
00108 }
00109 
00110 inline void 
00111 w_bitmap_t::resetPtr(uint1_t* p, uint4_t size)
00112 {
00113    w_assert9(!mem_alloc);
00114    sz = size;
00115    ptr = p;
00116 }
00117 
00118 inline bool
00119 w_bitmap_t::is_clr(uint4_t offset) const
00120 {
00121     return !is_set(offset);
00122 }
00123 
00124 inline w_base_t::uint4_t
00125 w_bitmap_t::size() const
00126 {
00127     return sz ;
00128 }
00129 
00130 inline w_base_t::uint4_t
00131 w_bitmap_t::num_clr() const
00132 {
00133     return sz - num_set();
00134 }
00135 
00136 inline w_base_t::uint1_t*
00137 w_bitmap_t::addr() 
00138 {
00139     return ptr;
00140 }
00141 
00142 inline const w_base_t::uint1_t*
00143 w_bitmap_t::addr() const
00144 {
00145     return ptr;
00146 }
00147 
00148 
00149 /*<std-footer incl-file-exclusion='W_BITMAP_H'>  -- do not edit anything below this line -- */
00150 
00151 #endif          /*</std-footer>*/

Generated on Wed Jul 7 17:22:32 2010 for Shore Storage Manager by  doxygen 1.4.7