bit/bstream.h

00001 /***************************************************************************
00002  *   Copyright (C) 2001 by Rick L. Vinyard, Jr.                            *
00003  *   rvinyard@cs.nmsu.edu                                                  *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation version 2.1.                *
00008  *                                                                         *
00009  *   This program is distributed in the hope that it will be useful,       *
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00012  *   GNU General Public License for more details.                          *
00013  *                                                                         *
00014  *   You should have received a copy of the GNU Lesser General Public      *
00015  *   License along with this library; if not, write to the                 *
00016  *   Free Software Foundation, Inc.,                                       *
00017  *   51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA              *
00018  ***************************************************************************/
00019 #ifndef BSTREAM_H
00020 #define BSTREAM_H
00021 
00022 #include <stdexcept>
00023 
00029 namespace bit {
00030 
00038 class bstream {
00039 public:
00040     bstream();
00041 
00042     virtual ~bstream();
00043 
00044     //bool is_big_endian()                 { return m_big_endian; }
00045     //bool is_little_endian()              { return !m_big_endian; }
00046     bool is_host_big_endian()            {
00047         return m_host_big_endian;
00048     }
00049     bool is_host_little_endian()         {
00050         return !m_host_big_endian;
00051     }
00052 
00053     //void big_endian(bool b=true)         { m_big_endian = b; }
00054     //void little_endian(bool b=true)      { m_big_endian = !b; }
00055     void host_big_endian(bool b=true)    {
00056         m_host_big_endian = b;
00057     }
00058     void host_little_endian(bool b=true) {
00059         m_host_big_endian = !b;
00060     }
00061 
00062     typedef enum State {WHOLE, BITS, OCTETS} State;
00063 
00064   protected:
00065     //bool m_big_endian;
00066     bool m_host_big_endian;
00067     unsigned char m_leftoverbits;
00068     size_t  m_numleftoverbits;
00069     static const int m_masks[8];
00070 
00071     State m_state;
00072     size_t m_stateval;
00073 
00074 
00075 };
00076 
00077 class bits {
00078   public:
00079     bits(size_t n): val(n) { }
00080     int val;
00081 };
00082 
00083 class octets {
00084   public:
00085     octets(size_t n): val(n) { }
00086     int val;
00087 };
00088 
00089 class whole {
00090   public:
00091     whole() { }
00092 };
00093 
00094 }; // namespace bit
00095 
00096 #endif

Generated on Tue Mar 13 20:00:01 2007 by  doxygen 1.5.1