inlib  1.2.0
Public Member Functions | Protected Member Functions | Protected Attributes
inlib::rroot::rbuf Class Reference
Inheritance diagram for inlib::rroot::rbuf:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 rbuf (std::ostream &a_out, bool a_byte_swap, const char *a_eob, char *&a_pos)
virtual ~rbuf ()
std::ostream & out () const
void skip (unsigned int a_num)
void set_eob (const char *a_eob)
char *& pos ()
const char * eob () const
bool read (unsigned char &a_x)
bool read (unsigned short &a_x)
bool read (unsigned int &a_x)
bool read (uint64 &a_x)
bool read (float &a_x)
bool read (double &a_x)
bool read (char &a_x)
bool read (short &a_x)
bool read (int &a_x)
bool read (int64 &a_x)
bool read (std::string &a_x)
bool read (bool &x)
bool read (std::vector< std::string > &a_a)
bool read_fast_array (bool *b, uint32 n)
bool read_fast_array (char *c, uint32 n)
bool read_fast_array (unsigned char *c, uint32 n)
template<class T >
bool read_fast_array (T *a_a, uint32 a_n)
template<class T >
bool read_array (uint32 a_sz, T *&a_a, uint32 &a_n)
bool check_eob (uint32 n)

Protected Member Functions

 rbuf (const rbuf &a_from)
rbufoperator= (const rbuf &)
template<class T >
bool _check_eob (T &a_x)

Protected Attributes

std::ostream & m_out
bool m_byte_swap
const char * m_eob
char *& m_pos
r_2_func m_r_2_func
r_4_func m_r_4_func
r_8_func m_r_8_func

Detailed Description

Definition at line 20 of file rbuf.


Constructor & Destructor Documentation

inlib::rroot::rbuf::rbuf ( std::ostream &  a_out,
bool  a_byte_swap,
const char *  a_eob,
char *&  a_pos 
) [inline]

Definition at line 78 of file rbuf.

  :m_out(a_out)
  ,m_byte_swap(a_byte_swap)
  ,m_eob(a_eob)
  ,m_pos(a_pos)

  ,m_r_2_func(0)
  ,m_r_4_func(0)
  ,m_r_8_func(0)
  {
#ifdef INLIB_MEM
    mem::increment(s_class().c_str());
#endif
    if(m_byte_swap) {
      m_r_2_func = read_swap_2;
      m_r_4_func = read_swap_4;
      m_r_8_func = read_swap_8;
    } else {
      m_r_2_func = read_nswp_2;
      m_r_4_func = read_nswp_4;
      m_r_8_func = read_nswp_8;
    }
  }
virtual inlib::rroot::rbuf::~rbuf ( ) [inline, virtual]

Definition at line 102 of file rbuf.

                 {
#ifdef INLIB_MEM
    mem::decrement(s_class().c_str());
#endif
  }
inlib::rroot::rbuf::rbuf ( const rbuf a_from) [inline, protected]

Definition at line 108 of file rbuf.

  :m_out(a_from.m_out),m_eob(a_from.m_eob),m_pos(a_from.m_pos){
#ifdef INLIB_MEM
    mem::increment(s_class().c_str());
#endif
  }

Member Function Documentation

template<class T >
bool inlib::rroot::rbuf::_check_eob ( T &  a_x) [inline, protected]

Definition at line 345 of file rbuf.

                         {
    if((m_pos+sizeof(T))>m_eob) {
      a_x = T();
      m_out << s_class() << " : " << stype(T()) << " : "
           << " try to access out of buffer " << long2s(sizeof(T)) << " bytes"
           << " (pos=" << char_p2s(m_pos)
           << ", eob=" << char_p2s(m_eob) << ")." << std::endl;
      return false;
    }
    return true;
  }
bool inlib::rroot::rbuf::check_eob ( uint32  n) [inline]

Definition at line 333 of file rbuf.

                          {
    if((m_pos+n)>m_eob) {
      m_out << "inlib::rroot::rbuf::check_eob :"
            << " try to access out of buffer " << n << " bytes."
            << std::endl;
      return false;
    }
    return true;
  }
const char* inlib::rroot::rbuf::eob ( ) const [inline]

Definition at line 122 of file rbuf.

{return m_eob;}
rbuf& inlib::rroot::rbuf::operator= ( const rbuf ) [inline, protected]

Definition at line 114 of file rbuf.

{return *this;}
std::ostream& inlib::rroot::rbuf::out ( ) const [inline]

Definition at line 116 of file rbuf.

{return m_out;}
char*& inlib::rroot::rbuf::pos ( ) [inline]

Definition at line 121 of file rbuf.

{return m_pos;}
bool inlib::rroot::rbuf::read ( unsigned char &  a_x) [inline]

Definition at line 125 of file rbuf.

                                {
    if(!_check_eob<unsigned char>(a_x)) return false;
    a_x = *m_pos++;
    return true;
  }
bool inlib::rroot::rbuf::read ( unsigned short &  a_x) [inline]

Definition at line 130 of file rbuf.

                                 {
    if(!_check_eob<unsigned short>(a_x)) return false;
    m_r_2_func(m_pos,(char*)&a_x);
    m_pos += sizeof(unsigned short);
    return true;
  }
bool inlib::rroot::rbuf::read ( unsigned int &  a_x) [inline]

Definition at line 137 of file rbuf.

                               {
    if(!_check_eob<unsigned int>(a_x)) return false;
    m_r_4_func(m_pos,(char*)&a_x);
    m_pos += sizeof(unsigned int);
    return true;
  }
bool inlib::rroot::rbuf::read ( uint64 a_x) [inline]

Definition at line 144 of file rbuf.

                        {
    if(!_check_eob<uint64>(a_x)) return false;
    m_r_8_func(m_pos,(char*)&a_x);
    m_pos += 8;
    return true;
  }
bool inlib::rroot::rbuf::read ( float &  a_x) [inline]

Definition at line 151 of file rbuf.

                        {
    if(!_check_eob<float>(a_x)) return false;
    m_r_4_func(m_pos,(char*)&a_x);
    m_pos += sizeof(float);
    return true;
  }
bool inlib::rroot::rbuf::read ( double &  a_x) [inline]

Definition at line 158 of file rbuf.

                         {
    if(!_check_eob<double>(a_x)) return false;
    m_r_8_func(m_pos,(char*)&a_x);
    m_pos += sizeof(double);
    return true;
  }
bool inlib::rroot::rbuf::read ( char &  a_x) [inline]

Definition at line 165 of file rbuf.

                       {
    if(!_check_eob<char>(a_x)) return false;
    a_x = *m_pos++;
    return true;
  }
bool inlib::rroot::rbuf::read ( short &  a_x) [inline]

Definition at line 170 of file rbuf.

                        {
    if(!_check_eob<short>(a_x)) return false;
    m_r_2_func(m_pos,(char*)&a_x);
    m_pos += sizeof(short);
    return true;
  }
bool inlib::rroot::rbuf::read ( int &  a_x) [inline]

Definition at line 177 of file rbuf.

                      {
    if(!_check_eob<int>(a_x)) return false;
    m_r_4_func(m_pos,(char*)&a_x);
    m_pos += sizeof(int);
    return true;
  }
bool inlib::rroot::rbuf::read ( int64 a_x) [inline]

Definition at line 184 of file rbuf.

                       {
    if(!_check_eob<int64>(a_x)) return false;
    m_r_8_func(m_pos,(char*)&a_x);
    m_pos += 8;
    return true;
  }
bool inlib::rroot::rbuf::read ( std::string &  a_x) [inline]

Definition at line 191 of file rbuf.

                            {
    unsigned char nwh;
    if(!read(nwh)) {a_x.clear();return false;}
    int nchars;
    if(nwh == 255) {
      if(!read(nchars)) {a_x.clear();return false;}
    } else {
      nchars = nwh;
    }
    if(nchars<0) {
      m_out << s_class() << "::read(string) :"
            << " negative char number " << nchars << "." << std::endl;
      a_x.clear();
      return false;
    }
    if((m_pos+nchars)>m_eob) {
      m_out << s_class() << "::read(string) :"
            << " try to access out of buffer " << long2s(nchars) << " bytes "
            << " (pos=" << char_p2s(m_pos)
            << ", eob=" << char_p2s(m_eob) << ")." << std::endl;
      a_x.clear();
      return false;
    }
    a_x.resize(nchars);  
    ::memcpy((char*)a_x.c_str(),m_pos,nchars);
    m_pos += nchars;
    return true;
  }
bool inlib::rroot::rbuf::read ( bool &  x) [inline]

Definition at line 220 of file rbuf.

                    { 
    unsigned char uc = 0;
    bool status = read(uc); 
    x = uc?true:false;
    return status;
  }
bool inlib::rroot::rbuf::read ( std::vector< std::string > &  a_a) [inline]

Definition at line 226 of file rbuf.

                                       {
    int n;
    if(!read(n)) {a_a.clear();return false;}
    for(int index=0;index<n;index++) {
      std::string s;
      if(!read(s)) {a_a.clear();return false;}
      a_a.push_back(s);
    }
    return true;
  }
template<class T >
bool inlib::rroot::rbuf::read_array ( uint32  a_sz,
T *&  a_a,
uint32 a_n 
) [inline]

Definition at line 297 of file rbuf.

                                                   {
    a_n = 0;
   {int n;
    if(!read(n)) {a_n = 0;return false;}
    a_n = n;}

    if(!a_n) return true;
  
    uint32 l = a_n * sizeof(T);
    if(!check_eob(l)) return false;

    bool owner = false;
    if(!a_a) {
      //ignore a_sz
      a_a = new T[a_n];
      if(!a_a) {a_n=0;return false;}
      owner = true;
    } else {
      if(a_n>a_sz) return false;
    }

    if(m_byte_swap) {
      for(uint32 i=0;i<a_n;i++) {     
        if(!read(*(a_a+i))) {
          if(owner) {delete [] a_a;a_a = 0;}
          a_n = 0;
          return false;
        }
      }
    } else {
      ::memcpy(a_a,m_pos,l);
      m_pos += l;
    }
    return true;
  }
bool inlib::rroot::rbuf::read_fast_array ( bool *  b,
uint32  n 
) [inline]

Definition at line 240 of file rbuf.

                                        {
    // Read array of n characters from the I/O buffer.
    if(!n) return true;
    uint32 l = n * sizeof(unsigned char);
    if(!check_eob(l)) return false;
    for(uint32 i = 0; i < n; i++) {
      unsigned char uc;
      if(!read(uc)) return false;
      b[i] = uc?true:false;
    }
    return true;
  }
bool inlib::rroot::rbuf::read_fast_array ( char *  c,
uint32  n 
) [inline]

Definition at line 252 of file rbuf.

                                        {
    // Read array of n characters from the I/O buffer.
    if(!n) return true;
    uint32 l = n * sizeof(char);
    if(!check_eob(l)) return false;
    ::memcpy(c,m_pos,l);
    m_pos += l;
    return true;
  }
bool inlib::rroot::rbuf::read_fast_array ( unsigned char *  c,
uint32  n 
) [inline]

Definition at line 261 of file rbuf.

                                                 {
    // Read array of n characters from the I/O buffer.
    if(!n) return true;
    uint32 l = n * sizeof(unsigned char);
    if(!check_eob(l)) return false;
    ::memcpy(c, m_pos, l);
    m_pos += l;
    return true;
  }
template<class T >
bool inlib::rroot::rbuf::read_fast_array ( T *  a_a,
uint32  a_n 
) [inline]

Definition at line 272 of file rbuf.

                                         {
    // Read array of n ints from the I/O buffer.
    if(!a_n) return true;

    uint32 l = a_n * sizeof(T);
    if(!check_eob(l)) {
      m_out << s_class() << "::read_fast_array :"
            << " try to access out of buffer " << long2s(l) << " bytes "
            << " (pos=" << char_p2s(m_pos)
            << ", eob=" << char_p2s(m_eob) << ")." << std::endl;
      return false;
    }

    if(m_byte_swap) {
      for(uint32 i=0;i<a_n;i++) {
        if(!read(*(a_a+i))) return false;
      }
    } else {
      ::memcpy(a_a,m_pos,l);
      m_pos += l;
    }
    return true;
  }
void inlib::rroot::rbuf::set_eob ( const char *  a_eob) [inline]

Definition at line 120 of file rbuf.

{m_eob = a_eob;}
void inlib::rroot::rbuf::skip ( unsigned int  a_num) [inline]

Definition at line 118 of file rbuf.

{m_pos += a_num;}

Member Data Documentation

Reimplemented in inlib::rroot::buffer.

Definition at line 358 of file rbuf.

const char* inlib::rroot::rbuf::m_eob [protected]

Definition at line 359 of file rbuf.

std::ostream& inlib::rroot::rbuf::m_out [protected]

Definition at line 357 of file rbuf.

char*& inlib::rroot::rbuf::m_pos [protected]

Reimplemented in inlib::rroot::buffer.

Definition at line 360 of file rbuf.

r_2_func inlib::rroot::rbuf::m_r_2_func [protected]

Definition at line 362 of file rbuf.

r_4_func inlib::rroot::rbuf::m_r_4_func [protected]

Definition at line 363 of file rbuf.

r_8_func inlib::rroot::rbuf::m_r_8_func [protected]

Definition at line 364 of file rbuf.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines