inlib
1.2.0
|
Public Member Functions | |
buffer (std::ostream &a_out, bool a_byte_swap, uint32 a_size) | |
virtual | ~buffer () |
std::ostream & | out () const |
char * | buf () |
const char * | buf () const |
uint32 | length () const |
uint32 | size () const |
char *& | pos () |
char * | max_pos () const |
template<class T > | |
bool | write (T x) |
bool | write (bool x) |
bool | write (const std::string &x) |
bool | write_fast_array (const char *a_a, uint32 a_n) |
bool | write_cstring (const char *a_s) |
template<class T > | |
bool | write_fast_array (const T *a_a, uint32 a_n) |
template<class T > | |
bool | write_array (const T *a_a, uint32 a_n) |
bool | write_version (short a_version) |
bool | write_version (short a_version, uint32 &a_pos) |
bool | set_byte_count (uint32 a_pos) |
bool | write_object (const ibo &a_obj) |
bool | expand (uint32 a_new_size) |
unsigned int | to_displace () const |
bool | displace_mapped (unsigned int a_num) |
Protected Member Functions | |
buffer (const buffer &a_from) | |
buffer & | operator= (const buffer &) |
bool | write_class (const std::string &a_cls) |
bool | set_byte_count_obj (uint32 a_pos) |
Static Protected Member Functions | |
static short | kMaxVersion () |
static uint32 | kMaxMapCount () |
static short | kByteCountVMask () |
static uint32 | kNewClassTag () |
static int | kMapOffset () |
static unsigned int | kClassMask () |
static uint32 | kByteCountMask () |
static std::string | sout (const std::string &a_string) |
Protected Attributes | |
std::ostream & | m_out |
bool | m_byte_swap |
uint32 | m_size |
char * | m_buffer |
char * | m_max |
char * | m_pos |
wbuf | m_wb |
std::map< ibo *, uint32 > | m_objs |
std::vector< std::pair< uint32, uint32 > > | m_obj_mapped |
std::map< std::string, uint32 > | m_clss |
std::vector< std::pair< uint32, uint32 > > | m_cls_mapped |
inlib::wroot::buffer::buffer | ( | std::ostream & | a_out, |
bool | a_byte_swap, | ||
uint32 | a_size | ||
) | [inline] |
Definition at line 32 of file buffer.
:m_out(a_out) ,m_byte_swap(a_byte_swap) ,m_size(0) ,m_buffer(0) ,m_max(0) ,m_pos(0) ,m_wb(a_out,a_byte_swap,0,m_pos) //it holds a ref on m_pos. { #ifdef INLIB_MEM mem::increment(s_class().c_str()); #endif m_size = a_size; m_buffer = new char[m_size]; //if(!m_buffer) {} m_max = m_buffer+m_size; m_pos = m_buffer; m_wb.set_eob(m_max); }
virtual inlib::wroot::buffer::~buffer | ( | ) | [inline, virtual] |
Definition at line 54 of file buffer.
{ m_objs.clear(); m_obj_mapped.clear(); m_clss.clear(); m_cls_mapped.clear(); delete [] m_buffer; #ifdef INLIB_MEM mem::decrement(s_class().c_str()); #endif }
inlib::wroot::buffer::buffer | ( | const buffer & | a_from | ) | [inline, protected] |
char* inlib::wroot::buffer::buf | ( | ) | [inline] |
const char* inlib::wroot::buffer::buf | ( | ) | const [inline] |
bool inlib::wroot::buffer::displace_mapped | ( | unsigned int | a_num | ) | [inline] |
Definition at line 275 of file buffer.
{ char* opos = m_pos; //m_out << "inlib::wroot::buffer::displace_mapped :" // << " cls num " << m_cls_mapped.size() // << std::endl; {std::vector< std::pair<uint32,uint32> >::const_iterator it; for(it=m_cls_mapped.begin();it!=m_cls_mapped.end();++it) { unsigned int offset = (*it).first; unsigned int id = (*it).second; //m_out << "displace " << offset << " " << id << std::endl; m_pos = m_buffer+offset; unsigned int clIdx = id+a_num; if(!write(uint32(clIdx|kClassMask()))) {m_pos = opos;return false;} }} //m_out << "inlib::wroot::buffer::displace_mapped :" // << " obj num " << m_obj_mapped.size() // << std::endl; {std::vector< std::pair<uint32,uint32> >::const_iterator it; for(it=m_obj_mapped.begin();it!=m_obj_mapped.end();++it) { uint32 offset = (*it).first; uint32 id = (*it).second; //m_out << "displace at " << offset // << " the obj pos " << id // << " by " << a_num // << std::endl; m_pos = m_buffer+offset; unsigned int objIdx = id+a_num; if(!write(objIdx)) {m_pos = opos;return false;} }} m_pos = opos; return true; }
bool inlib::wroot::buffer::expand | ( | uint32 | a_new_size | ) | [inline] |
Definition at line 252 of file buffer.
{ unsigned long len = m_pos-m_buffer; if(!realloc<char>(m_buffer,a_new_size,m_size)) { m_out << "inlib::wroot::buffer::expand :" << " can't realloc " << a_new_size << " bytes." << std::endl; m_size = 0; m_max = 0; m_pos = 0; m_wb.set_eob(m_max); return false; } m_size = a_new_size; m_max = m_buffer + m_size; m_pos = m_buffer + len; m_wb.set_eob(m_max); return true; }
static uint32 inlib::wroot::buffer::kByteCountMask | ( | ) | [inline, static, protected] |
static short inlib::wroot::buffer::kByteCountVMask | ( | ) | [inline, static, protected] |
static unsigned int inlib::wroot::buffer::kClassMask | ( | ) | [inline, static, protected] |
static int inlib::wroot::buffer::kMapOffset | ( | ) | [inline, static, protected] |
static uint32 inlib::wroot::buffer::kMaxMapCount | ( | ) | [inline, static, protected] |
static short inlib::wroot::buffer::kMaxVersion | ( | ) | [inline, static, protected] |
static uint32 inlib::wroot::buffer::kNewClassTag | ( | ) | [inline, static, protected] |
uint32 inlib::wroot::buffer::length | ( | ) | const [inline] |
char* inlib::wroot::buffer::max_pos | ( | ) | const [inline] |
std::ostream& inlib::wroot::buffer::out | ( | ) | const [inline] |
char*& inlib::wroot::buffer::pos | ( | ) | [inline] |
bool inlib::wroot::buffer::set_byte_count | ( | uint32 | a_pos | ) | [inline] |
Definition at line 177 of file buffer.
{ uint32 cnt = (uint32)(m_pos-m_buffer) - a_pos - sizeof(unsigned int); if(cnt>=kMaxMapCount()) { m_out << "inlib::wroot::buffer::set_byte_count :" << " bytecount too large (more than " << kMaxMapCount() << ")." << std::endl; return false; } union { uint32 cnt; short vers[2]; } v; v.cnt = cnt; char* opos = m_pos; m_pos = (char*)(m_buffer+a_pos); if(m_byte_swap) { if(!m_wb.write(short(v.vers[1]|kByteCountVMask()))) {m_pos = opos;return false;} if(!m_wb.write(v.vers[0])) {m_pos = opos;return false;} } else { if(!m_wb.write(short(v.vers[0]|kByteCountVMask()))) {m_pos = opos;return false;} if(!m_wb.write(v.vers[1])) {m_pos = opos;return false;} } m_pos = opos; return true; }
bool inlib::wroot::buffer::set_byte_count_obj | ( | uint32 | a_pos | ) | [inline, protected] |
Definition at line 347 of file buffer.
{ uint32 cnt = (uint32)(m_pos-m_buffer) - a_pos - sizeof(unsigned int); if(cnt>=kMaxMapCount()) { m_out << "inlib::wroot::buffer::set_byte_count_obj :" << " bytecount too large (more than " << kMaxMapCount() << ")." << std::endl; return false; } char* opos = m_pos; m_pos = (char*)(m_buffer+a_pos); if(!m_wb.write(uint32(cnt|kByteCountMask()))) {m_pos = opos;return false;} m_pos = opos; return true; }
uint32 inlib::wroot::buffer::size | ( | ) | const [inline] |
static std::string inlib::wroot::buffer::sout | ( | const std::string & | a_string | ) | [inline, static, protected] |
unsigned int inlib::wroot::buffer::to_displace | ( | ) | const [inline] |
Definition at line 271 of file buffer.
{ return m_cls_mapped.size()+m_obj_mapped.size(); }
bool inlib::wroot::buffer::write | ( | T | x | ) | [inline] |
bool inlib::wroot::buffer::write | ( | bool | x | ) | [inline] |
bool inlib::wroot::buffer::write | ( | const std::string & | x | ) | [inline] |
bool inlib::wroot::buffer::write_array | ( | const T * | a_a, |
uint32 | a_n | ||
) | [inline] |
Definition at line 141 of file buffer.
{ if(!write(a_n)) return false; return write_fast_array(a_a,a_n); }
bool inlib::wroot::buffer::write_class | ( | const std::string & | a_cls | ) | [inline, protected] |
Definition at line 323 of file buffer.
{ std::map<std::string,uint32>::const_iterator it = m_clss.find(a_cls); if(it!=m_clss.end()) { uint32 clIdx = (*it).second; unsigned int offset = (unsigned int)(m_pos-m_buffer); // save index of already stored class if(!write(uint32(clIdx|kClassMask()))) return false; m_cls_mapped.push_back(std::pair<uint32,uint32>(offset,clIdx)); } else { unsigned int offset = (unsigned int)(m_pos-m_buffer); if(!write(kNewClassTag())) return false; if(!write_cstring(a_cls.c_str())) return false; m_clss[a_cls] = offset + kMapOffset(); } return true; }
bool inlib::wroot::buffer::write_cstring | ( | const char * | a_s | ) | [inline] |
Definition at line 126 of file buffer.
{ return write_fast_array(a_s,(::strlen(a_s)+1)*sizeof(char)); }
bool inlib::wroot::buffer::write_fast_array | ( | const char * | a_a, |
uint32 | a_n | ||
) | [inline] |
bool inlib::wroot::buffer::write_fast_array | ( | const T * | a_a, |
uint32 | a_n | ||
) | [inline] |
bool inlib::wroot::buffer::write_object | ( | const ibo & | a_obj | ) | [inline] |
Definition at line 209 of file buffer.
{ //GB : if adding a write map logic, think to have a displace_mapped() // in basket::write_on_file(). std::map<ibo*,uint32>::const_iterator it = m_objs.find((ibo*)&a_obj); if(it!=m_objs.end()) { uint32 objIdx = (*it).second; unsigned int offset = (unsigned int)(m_pos-m_buffer); // save index of already stored object if(!write(objIdx)) return false; m_obj_mapped.push_back(std::pair<uint32,uint32>(offset,objIdx)); } else { // reserve space for leading byte count uint32 cntpos = (unsigned int)(m_pos-m_buffer); //NOTE : the below test is lacking in CERN-ROOT ! if((m_pos+sizeof(unsigned int))>m_max) { if(!expand(m_size+sizeof(unsigned int))) return false; } m_pos += sizeof(unsigned int); // write class of object first if(!write_class(a_obj.store_cls())) return false; // add to map before writing rest of object (to handle self reference) // (+kMapOffset so it's != kNullTag) m_objs[(ibo*)&a_obj] = cntpos + kMapOffset(); // let the object write itself : if(!a_obj.stream(*this)) return false; // write byte count if(!set_byte_count_obj(cntpos)) return false; } return true; }
bool inlib::wroot::buffer::write_version | ( | short | a_version | ) | [inline] |
Definition at line 147 of file buffer.
{ if(a_version>kMaxVersion()) { m_out << "inlib::wroot::buffer::write_version :" << " version number " << a_version << " cannot be larger than " << kMaxVersion() << "." << std::endl; return false; } return write(a_version); }
bool inlib::wroot::buffer::write_version | ( | short | a_version, |
uint32 & | a_pos | ||
) | [inline] |
Definition at line 157 of file buffer.
{ // reserve space for leading byte count a_pos = (uint32)(m_pos-m_buffer); //NOTE : the below test is lacking in CERN-ROOT ! if((m_pos+sizeof(unsigned int))>m_max) { if(!expand(m_size+sizeof(unsigned int))) return false; } m_pos += sizeof(unsigned int); if(a_version>kMaxVersion()) { m_out << "inlib::wroot::buffer::write_version :" << " version number " << a_version << " cannot be larger than " << kMaxVersion() << "." << std::endl; return false; } return write(a_version); }
char* inlib::wroot::buffer::m_buffer [protected] |
bool inlib::wroot::buffer::m_byte_swap [protected] |
std::vector< std::pair<uint32,uint32> > inlib::wroot::buffer::m_cls_mapped [protected] |
std::map<std::string,uint32> inlib::wroot::buffer::m_clss [protected] |
char* inlib::wroot::buffer::m_max [protected] |
std::vector< std::pair<uint32,uint32> > inlib::wroot::buffer::m_obj_mapped [protected] |
std::map<ibo*,uint32> inlib::wroot::buffer::m_objs [protected] |
std::ostream& inlib::wroot::buffer::m_out [protected] |
char* inlib::wroot::buffer::m_pos [protected] |
uint32 inlib::wroot::buffer::m_size [protected] |
wbuf inlib::wroot::buffer::m_wb [protected] |