inlib
1.2.0
|
Public Member Functions | |
virtual bool | read (uchar &a_x) |
virtual bool | read (char &a_x) |
virtual bool | read (uint16 &a_x) |
virtual bool | read (int16 &a_x) |
virtual bool | read (uint32 &a_x) |
virtual bool | read (int32 &a_x) |
virtual bool | read (uint64 &a_x) |
virtual bool | read (int64 &a_x) |
virtual bool | read (bool &a_v) |
virtual bool | read (float &a_v) |
virtual bool | read (double &a_v) |
virtual bool | read_cstr (char *&a_cstr) |
virtual bool | read_vec (uint32 &a_n, uchar *&a_x) |
virtual bool | read_vec (uint32 &a_n, char *&a_x) |
virtual bool | read_vec (uint32 &a_n, uint16 *&a_x) |
virtual bool | read_vec (uint32 &a_n, int16 *&a_x) |
virtual bool | read_vec (uint32 &a_n, uint32 *&a_x) |
virtual bool | read_vec (uint32 &a_n, int32 *&a_x) |
virtual bool | read_vec (uint32 &a_n, uint64 *&a_x) |
virtual bool | read_vec (uint32 &a_n, int64 *&a_x) |
virtual bool | read_vec (uint32 &a_n, float *&a_x) |
virtual bool | read_vec (uint32 &a_n, double *&a_x) |
virtual bool | read_vec (uint32 &a_n, bool *&a_x) |
virtual bool | read_vec (std::vector< std::string > &a_a) |
virtual bool | read_std_vec_vec (std_vec_vec_uint_t &a_vv) |
virtual bool | read_std_vec_vec (std_vec_vec_float_t &a_vv) |
virtual bool | read_std_vec_vec (std_vec_vec_string_t &a_vv) |
xrbuf (std::ostream &a_out, uint32 a_size=1014) | |
virtual | ~xrbuf () |
bool | copy (uint32 a_size, const char *a_buffer) |
Protected Member Functions | |
xrbuf (const xrbuf &a_from) | |
xrbuf & | operator= (const xrbuf &) |
template<class ta_type > | |
bool | _read_strtol (ta_type &a_v) |
template<class ta_type , class ta_ret_type > | |
bool | _read (ta_type &a_v, inlib::s2int64_func a_func) |
template<class ta_type > | |
bool | _read_array (uint32 &a_n, ta_type *&a_a) |
template<class T > | |
bool | _read_std_vec_vec (std::vector< std::vector< T > > &a_vv) |
uint32 | _remaining () const |
Protected Attributes | |
std::ostream & | m_out |
uint32 | m_size |
char * | m_buffer |
char * | m_max |
char * | m_pos |
inlib::io::xrbuf::xrbuf | ( | std::ostream & | a_out, |
uint32 | a_size = 1014 |
||
) | [inline] |
virtual inlib::io::xrbuf::~xrbuf | ( | ) | [inline, virtual] |
inlib::io::xrbuf::xrbuf | ( | const xrbuf & | a_from | ) | [inline, protected] |
bool inlib::io::xrbuf::_read | ( | ta_type & | a_v, |
inlib::s2int64_func | a_func | ||
) | [inline, protected] |
bool inlib::io::xrbuf::_read_array | ( | uint32 & | a_n, |
ta_type *& | a_a | ||
) | [inline, protected] |
Definition at line 280 of file xrbuf.
{ // assume that the whole remaining buffer containes {xxx0}. // a_a is allocated by this method. a_n = 0; uint32 a_size = 100; a_a = new ta_type[a_size]; if(!a_a) return false; char* pos = m_pos; char* begin = m_pos; uint32 sz = _remaining(); if(sz==1) {a_n = 0;return true;} for(uint32 index=0;index<sz;index++,pos++) { if( ((*pos)==' ') || ((*pos)=='\0') ){ m_pos = begin; ta_type v; if(!read(v)) { delete [] a_a; a_a = 0; a_n = 0; return false; } if((a_n+1)>a_size) { uint32 new_a_size = 2*a_size; if(!realloc<ta_type>(a_a,new_a_size,a_size)) {a_n=0;return false;} a_size = new_a_size; } a_a[a_n] = v; a_n++; begin = pos+1; if((*pos)=='\0') return true; } } //FIXME : return false if not ending with null char. return true; }
bool inlib::io::xrbuf::_read_std_vec_vec | ( | std::vector< std::vector< T > > & | a_vv | ) | [inline, protected] |
Definition at line 319 of file xrbuf.
{ // <num> <num> <num>\n<num> <num> <num>\n...\n<num> <num>0 a_vv.clear(); char* pos = m_pos; char* begin = m_pos; uint32 sz = _remaining(); for(uint32 index=0;index<sz;index++,pos++) { if((*pos)=='\0') { m_pos = begin; uint32 n; T* v; if(!_read_array<T>(n,v)) { //v is allocated with new T[]. a_vv.clear(); return false; } if(n) { std::vector<T> sv(n); for(unsigned int i=0;i<n;i++) sv[i] = v[i]; a_vv.push_back(sv); } delete [] v; return true; } else if( ((*pos)=='\\') && ((pos+1)<=m_max) && ((*(pos+1))=='n') ){ m_pos = begin; char old_char = *pos; *pos = '\0'; uint32 n; T* v; if(!_read_array<T>(n,v)) { //v is allocated with new T[]. *pos = old_char; a_vv.clear(); return false; } *pos = old_char; if(n) { std::vector<T> sv(n); for(unsigned int i=0;i<n;i++) sv[i] = v[i]; a_vv.push_back(sv); } delete [] v; begin = pos+2; } } return true; }
bool inlib::io::xrbuf::_read_strtol | ( | ta_type & | a_v | ) | [inline, protected] |
uint32 inlib::io::xrbuf::_remaining | ( | ) | const [inline, protected] |
bool inlib::io::xrbuf::copy | ( | uint32 | a_size, |
const char * | a_buffer | ||
) | [inline] |
virtual bool inlib::io::xrbuf::read | ( | uchar & | a_x | ) | [inline, virtual] |
Implements inlib::io::irbuf.
Definition at line 30 of file xrbuf.
{return _read_strtol<uchar>(a_x);}
virtual bool inlib::io::xrbuf::read | ( | char & | a_x | ) | [inline, virtual] |
virtual bool inlib::io::xrbuf::read | ( | uint16 & | a_x | ) | [inline, virtual] |
Implements inlib::io::irbuf.
Definition at line 32 of file xrbuf.
{return _read_strtol<uint16>(a_x);}
virtual bool inlib::io::xrbuf::read | ( | int16 & | a_x | ) | [inline, virtual] |
Implements inlib::io::irbuf.
Definition at line 33 of file xrbuf.
{return _read_strtol<int16>(a_x);}
virtual bool inlib::io::xrbuf::read | ( | uint32 & | a_x | ) | [inline, virtual] |
Implements inlib::io::irbuf.
Definition at line 34 of file xrbuf.
{return _read_strtol<uint32>(a_x);}
virtual bool inlib::io::xrbuf::read | ( | int32 & | a_x | ) | [inline, virtual] |
Implements inlib::io::irbuf.
Definition at line 35 of file xrbuf.
{return _read_strtol<int32>(a_x);}
virtual bool inlib::io::xrbuf::read | ( | uint64 & | a_x | ) | [inline, virtual] |
Implements inlib::io::irbuf.
Definition at line 37 of file xrbuf.
{ return _read<uint64,int64>(a_x,inlib::s2int64); }
virtual bool inlib::io::xrbuf::read | ( | int64 & | a_x | ) | [inline, virtual] |
Implements inlib::io::irbuf.
Definition at line 40 of file xrbuf.
{ return _read<int64,int64>(a_x,inlib::s2int64); }
virtual bool inlib::io::xrbuf::read | ( | bool & | a_v | ) | [inline, virtual] |
Implements inlib::io::irbuf.
virtual bool inlib::io::xrbuf::read | ( | float & | a_v | ) | [inline, virtual] |
virtual bool inlib::io::xrbuf::read | ( | double & | a_v | ) | [inline, virtual] |
virtual bool inlib::io::xrbuf::read_cstr | ( | char *& | a_cstr | ) | [inline, virtual] |
Implements inlib::io::irbuf.
Definition at line 73 of file xrbuf.
{ char* pos = m_pos; char* begin = m_pos; uint32 sz = _remaining(); for(uint32 index=0;index<sz;index++,pos++) { if((*pos)=='\0') { diff_pointer_t l = pos-begin; a_cstr = str_new(l); ::memcpy(a_cstr,begin,l); begin = pos+1; m_pos = begin; return true; //stop at first string found. } } a_cstr = 0; return false; }
virtual bool inlib::io::xrbuf::read_std_vec_vec | ( | std_vec_vec_uint_t & | a_vv | ) | [inline, virtual] |
Implements inlib::io::irbuf.
Definition at line 165 of file xrbuf.
{
return _read_std_vec_vec<unsigned int>(a_vv);
}
virtual bool inlib::io::xrbuf::read_std_vec_vec | ( | std_vec_vec_float_t & | a_vv | ) | [inline, virtual] |
Implements inlib::io::irbuf.
Definition at line 168 of file xrbuf.
{
return _read_std_vec_vec<float>(a_vv);
}
virtual bool inlib::io::xrbuf::read_std_vec_vec | ( | std_vec_vec_string_t & | a_vv | ) | [inline, virtual] |
Implements inlib::io::irbuf.
Definition at line 171 of file xrbuf.
{ // <str>\n<str>\n<num>\t<str>\n<str>\n<str>\t...\t<str>\n<str>0 a_vv.clear(); char* pos = m_pos; char* begin = m_pos; uint32 sz = _remaining(); for(uint32 index=0;index<sz;index++,pos++) { if((*pos)=='\0') { m_pos = begin; std::vector<std::string> v; if(!read_vec(v)) { a_vv.clear(); return false; } a_vv.push_back(v); return true; } else if( ((*pos)=='\\') && ((pos+1)<=m_max) && ((*(pos+1))=='t') ){ m_pos = begin; char old_char = *pos; *pos = '\0'; std::vector<std::string> v; if(!read_vec(v)) { *pos = old_char; a_vv.clear(); return false; } *pos = old_char; a_vv.push_back(v); begin = pos+2; } } return true; }
Implements inlib::io::irbuf.
Definition at line 91 of file xrbuf.
{
return _read_array<uchar>(a_n,a_x);
}
virtual bool inlib::io::xrbuf::read_vec | ( | uint32 & | a_n, |
char *& | a_x | ||
) | [inline, virtual] |
Implements inlib::io::irbuf.
Definition at line 94 of file xrbuf.
{
return _read_array<char>(a_n,a_x);
}
Implements inlib::io::irbuf.
Definition at line 97 of file xrbuf.
{
return _read_array<uint16>(a_n,a_x);
}
Implements inlib::io::irbuf.
Definition at line 100 of file xrbuf.
{
return _read_array<int16>(a_n,a_x);
}
Implements inlib::io::irbuf.
Definition at line 103 of file xrbuf.
{
return _read_array<uint32>(a_n,a_x);
}
Implements inlib::io::irbuf.
Definition at line 106 of file xrbuf.
{
return _read_array<int32>(a_n,a_x);
}
Implements inlib::io::irbuf.
Definition at line 109 of file xrbuf.
{
return _read_array<uint64>(a_n,a_x);
}
Implements inlib::io::irbuf.
Definition at line 112 of file xrbuf.
{
return _read_array<int64>(a_n,a_x);
}
virtual bool inlib::io::xrbuf::read_vec | ( | uint32 & | a_n, |
float *& | a_x | ||
) | [inline, virtual] |
Implements inlib::io::irbuf.
Definition at line 115 of file xrbuf.
{
return _read_array<float>(a_n,a_x);
}
virtual bool inlib::io::xrbuf::read_vec | ( | uint32 & | a_n, |
double *& | a_x | ||
) | [inline, virtual] |
Implements inlib::io::irbuf.
Definition at line 118 of file xrbuf.
{
return _read_array<double>(a_n,a_x);
}
virtual bool inlib::io::xrbuf::read_vec | ( | uint32 & | a_n, |
bool *& | a_x | ||
) | [inline, virtual] |
Implements inlib::io::irbuf.
Definition at line 121 of file xrbuf.
{
return _read_array<bool>(a_n,a_x);
}
virtual bool inlib::io::xrbuf::read_vec | ( | std::vector< std::string > & | a_a | ) | [inline, virtual] |
Implements inlib::io::irbuf.
Definition at line 125 of file xrbuf.
{ // <chars>\n<chars>\n<chars>0 a_a.clear(); typedef cstr_t ta_type; char* pos = m_pos; char* begin = m_pos; uint32 sz = _remaining(); for(uint32 index=0;index<sz;index++,pos++) { if((*pos)=='\0') { m_pos = begin; ta_type v; if(!read_cstr(v)) { //v is allocated with str_new. a_a.clear(); return false; } if(v) a_a.push_back(v); begin = pos+1; return true; } else if( ((*pos)=='\\') && ((pos+1)<=m_max) && ((*(pos+1))=='n') ){ m_pos = begin; char old_char = *pos; *pos = '\0'; ta_type v; if(!read_cstr(v)) { //v is allocated with str_new. *pos = old_char; a_a.clear(); return false; } *pos = old_char; if(v) a_a.push_back(v); begin = pos+2; } } //FIXME : return false if not ending with null char. return true; }
char* inlib::io::xrbuf::m_buffer [protected] |
char* inlib::io::xrbuf::m_max [protected] |
std::ostream& inlib::io::xrbuf::m_out [protected] |
char* inlib::io::xrbuf::m_pos [protected] |
uint32 inlib::io::xrbuf::m_size [protected] |