Import Geant4 10.6.0 source tree
This commit is contained in:
@@ -77,16 +77,17 @@ class buffer : public rbuf {
|
||||
#endif
|
||||
|
||||
public:
|
||||
buffer(std::ostream& a_out,bool a_byte_swap,
|
||||
uint32 a_size,char* a_buffer,uint32 a_klen,bool a_verbose)
|
||||
buffer(std::ostream& a_out,bool a_byte_swap,uint32 a_size,char* a_buffer,uint32 a_klen,bool a_verbose)
|
||||
:parent(a_out,a_byte_swap,a_buffer+a_size,m_pos)
|
||||
,m_byte_swap(a_byte_swap)
|
||||
,m_verbose(a_verbose)
|
||||
//,m_verbose(true)
|
||||
,m_size(a_size) //expect a not zero size.
|
||||
,m_buffer(a_buffer) //don't get ownership.
|
||||
,m_pos(a_buffer)
|
||||
,m_klen(a_klen) //to compute refs (used in read_class, read_object)
|
||||
,m_map_objs(false)
|
||||
//,m_map_objs(false)
|
||||
,m_map_objs(true)
|
||||
{
|
||||
#ifdef TOOLS_MEM
|
||||
mem::increment(s_class().c_str());
|
||||
@@ -283,6 +284,8 @@ public:
|
||||
a_obj = 0;
|
||||
a_created = false;
|
||||
|
||||
//m_out << "debug : tools::rroot::buffer::read_object : begin :" << std::endl;
|
||||
|
||||
// before reading object save start position
|
||||
uint32 startpos = (uint32)(m_pos-m_buffer);
|
||||
|
||||
@@ -298,24 +301,30 @@ public:
|
||||
|
||||
if(m_verbose) {
|
||||
m_out << "tools::rroot::buffer::read_object :"
|
||||
<< " class " << sout(sclass)
|
||||
<< " bcnt " << bcnt
|
||||
<< " class " << sout(sclass) << ", is_ref " << is_ref
|
||||
<< ", bcnt " << bcnt
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
if(is_ref) {
|
||||
//bcnt is the position toward an object or an object ref.
|
||||
//m_out << "tools::rroot::buffer::read_object :"
|
||||
// << " is_ref : bcnt " << bcnt
|
||||
// << std::endl;
|
||||
if(is_ref) { //bcnt is the position toward an object or an object ref.
|
||||
//m_out << "debug : tools::rroot::buffer::read_object : is_ref : bcnt " << bcnt << std::endl;
|
||||
|
||||
unsigned int obj_offset = bcnt;
|
||||
obj_offset -= kMapOffset();
|
||||
obj_offset -= m_klen;
|
||||
|
||||
if(!m_map_objs) {
|
||||
m_out << "tools::rroot::buffer::read_object : warning :"
|
||||
<< " class " << sout(sclass) << ", is_ref but map objs is not enabled on this buffer."
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
if(m_map_objs) {
|
||||
#ifdef TOOLS_RROOT_OBJ_MAP_HASH_TABLE
|
||||
if(m_objs.find(obj_offset,a_obj)) return true;
|
||||
if(m_objs.find(obj_offset,a_obj)) {
|
||||
//m_out << "debug : tools::rroot::buffer::read_object : found object in map." << bcnt << std::endl;
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
obj_map::const_iterator it = m_objs.find(obj_offset);
|
||||
if(it!=m_objs.end()) {
|
||||
@@ -332,10 +341,16 @@ public:
|
||||
m_pos = m_buffer + obj_offset;
|
||||
|
||||
uint32 first_int;
|
||||
if(!parent::read(first_int)) return false;
|
||||
if(!parent::read(first_int)) {
|
||||
m_out << "tools::rroot::buffer::read_object : parent::read(first_int) failed." << std::endl;
|
||||
return false;
|
||||
}
|
||||
if(first_int & kByteCountMask()) {
|
||||
std::string scls;
|
||||
if(!read_class_tag(scls)) return false;
|
||||
if(!read_class_tag(scls)) {
|
||||
m_out << "tools::rroot::buffer::read_object : read_class_tag() failed." << std::endl;
|
||||
return false;
|
||||
}
|
||||
if(scls.empty()) {
|
||||
m_out << "tools::rroot::buffer::read_object :"
|
||||
<< " read_class_tag did not find a class name."
|
||||
@@ -348,7 +363,11 @@ public:
|
||||
// << std::endl;
|
||||
|
||||
iro* obj = a_fac.create(scls,a_args);
|
||||
if(!obj) return false;
|
||||
if(!obj) {
|
||||
m_out << "tools::rroot::buffer::read_object : is_ref : creation of object"
|
||||
<< " of class " << sout(sclass) << " failed." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(m_map_objs) {
|
||||
//must be done before stream()
|
||||
@@ -369,7 +388,7 @@ public:
|
||||
<< std::endl;
|
||||
//restore a good buffer position :
|
||||
//m_pos = m_buffer+startpos+sizeof(unsigned int);
|
||||
a_fac.destroy(obj);
|
||||
delete obj;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -398,13 +417,12 @@ public:
|
||||
|
||||
} else {
|
||||
if(sclass.empty()) {
|
||||
//m_out << "tools::rroot::buffer::read_object :"
|
||||
// << " found empty class name."
|
||||
// << std::endl;
|
||||
//m_out << "debug : tools::rroot::buffer::read_object : found empty class name." << std::endl;
|
||||
|
||||
m_pos = m_buffer+startpos+bcnt+sizeof(unsigned int);
|
||||
|
||||
} else {
|
||||
//m_out << "debug : tools::rroot::buffer::read_object : not a ref, create object." << std::endl;
|
||||
|
||||
// Being not a ref, it must NOT be in the map.
|
||||
// We gain a lot by not doing the below find.
|
||||
@@ -425,7 +443,12 @@ public:
|
||||
*/
|
||||
|
||||
iro* obj = a_fac.create(sclass,a_args);
|
||||
if(!obj) return false;
|
||||
if(!obj) {
|
||||
m_out << "tools::rroot::buffer::read_object : creation of object"
|
||||
<< " of class " << sout(sclass) << " failed." << std::endl;
|
||||
return false;
|
||||
}
|
||||
//m_out << "debug : tools::rroot::buffer::read_object : object created." << std::endl;
|
||||
|
||||
if(m_map_objs) {
|
||||
//must be done before stream()
|
||||
@@ -444,9 +467,11 @@ public:
|
||||
|
||||
//NOTE : if class ref, "up there"-startpos = 8.
|
||||
if(!obj->stream(*this)) {
|
||||
m_out << "tools::rroot::buffer::read_object : object.stream() failed"
|
||||
<< " for object of class " << sout(sclass) << "." << std::endl;
|
||||
//restore a good buffer position :
|
||||
//m_pos = m_buffer+startpos+bcnt+sizeof(unsigned int);
|
||||
a_fac.destroy(obj);
|
||||
delete obj;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -458,7 +483,7 @@ public:
|
||||
<< " check_byte_count failed "
|
||||
<< "for object of class "
|
||||
<< sout(sclass) << "." << std::endl;
|
||||
a_fac.destroy(obj);
|
||||
delete obj;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -469,9 +494,7 @@ public:
|
||||
}
|
||||
|
||||
if(m_verbose) {
|
||||
m_out << "tools::rroot::buffer::read_object :"
|
||||
<< " end : "
|
||||
<< std::endl;
|
||||
m_out << "tools::rroot::buffer::read_object : end." << std::endl;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -542,9 +565,7 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
bool check_byte_count(uint32 a_start_pos,
|
||||
uint32 a_byte_count,
|
||||
const std::string& a_store_cls){
|
||||
bool check_byte_count(uint32 a_start_pos,uint32 a_byte_count,const std::string& a_store_cls){
|
||||
if(!a_byte_count) return true;
|
||||
|
||||
size_t len = a_start_pos + a_byte_count + sizeof(unsigned int);
|
||||
@@ -607,18 +628,15 @@ protected:
|
||||
obj_map m_objs;
|
||||
};
|
||||
|
||||
inline bool dummy_TXxx_pointer_stream(buffer& a_buffer,ifac& a_fac,bool a_del = true) {
|
||||
inline bool dummy_TXxx_pointer_stream(buffer& a_buffer,ifac& a_fac) {
|
||||
ifac::args args;
|
||||
iro* obj;
|
||||
bool created;
|
||||
bool status = a_buffer.read_object(a_fac,args,obj,created);
|
||||
if(obj && a_del) {
|
||||
if(obj) {
|
||||
if(created) {
|
||||
if(a_buffer.map_objs()) a_buffer.remove_in_map(obj);
|
||||
delete obj;
|
||||
} else {
|
||||
a_buffer.out() << "dummy_TXxx_pointer_stream : warning : ask to delete an object of class " << sout(obj->s_cls())
|
||||
<< " not created here." << std::endl;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
@@ -628,16 +646,17 @@ template <class T>
|
||||
inline bool pointer_stream(buffer& a_buffer,
|
||||
ifac& a_fac,ifac::args& a_args,
|
||||
const std::string& a_T_class,
|
||||
T*& a_obj){
|
||||
T*& a_obj,bool& a_created){
|
||||
iro* obj;
|
||||
bool created;
|
||||
if(!a_buffer.read_object(a_fac,a_args,obj,created)) {
|
||||
if(!a_buffer.read_object(a_fac,a_args,obj,a_created)) {
|
||||
a_buffer.out() << "tools::rroot::pointer_stream : read_object failed." << std::endl;
|
||||
a_obj = 0;
|
||||
a_created = false;
|
||||
return false;
|
||||
}
|
||||
if(!obj) {
|
||||
a_obj = 0;
|
||||
a_created = false;
|
||||
} else {
|
||||
a_obj = (T*)obj->cast(a_T_class);
|
||||
if(!a_obj) {
|
||||
@@ -645,6 +664,8 @@ inline bool pointer_stream(buffer& a_buffer,
|
||||
<< " inlib::cast to " << a_T_class << " failed."
|
||||
<< ". Object is a " << obj->s_cls() << "."
|
||||
<< std::endl;
|
||||
if(a_created) delete obj;
|
||||
a_created = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -655,16 +676,17 @@ template <class T>
|
||||
inline bool pointer_stream(buffer& a_buffer,
|
||||
ifac& a_fac,ifac::args& a_args,
|
||||
cid a_T_class,
|
||||
T*& a_obj){
|
||||
T*& a_obj,bool& a_created){
|
||||
iro* obj;
|
||||
bool created;
|
||||
if(!a_buffer.read_object(a_fac,a_args,obj,created)) {
|
||||
if(!a_buffer.read_object(a_fac,a_args,obj,a_created)) {
|
||||
a_buffer.out() << "tools::rroot::pointer_stream : read_object failed." << std::endl;
|
||||
a_obj = 0;
|
||||
a_created = false;
|
||||
return false;
|
||||
}
|
||||
if(!obj) {
|
||||
a_obj = 0;
|
||||
a_created = false;
|
||||
} else {
|
||||
a_obj = (T*)obj->cast(a_T_class);
|
||||
if(!a_obj) {
|
||||
@@ -672,6 +694,8 @@ inline bool pointer_stream(buffer& a_buffer,
|
||||
<< " inlib::cast to " << a_T_class << " failed."
|
||||
<< ". Object is a " << obj->s_cls() << "."
|
||||
<< std::endl;
|
||||
if(a_created) delete obj;
|
||||
a_created = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -679,10 +703,9 @@ inline bool pointer_stream(buffer& a_buffer,
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline bool pointer_stream(buffer& a_buffer,
|
||||
ifac& a_fac,ifac::args& a_args,T*& a_obj){
|
||||
//return pointer_stream(a_buffer,a_fac,a_args,T::s_class(),a_obj);
|
||||
return pointer_stream(a_buffer,a_fac,a_args,T::id_class(),a_obj);
|
||||
inline bool pointer_stream(buffer& a_buffer,ifac& a_fac,ifac::args& a_args,T*& a_obj,bool& a_created){
|
||||
//return pointer_stream(a_buffer,a_fac,a_args,T::s_class(),a_obj,a_created);
|
||||
return pointer_stream(a_buffer,a_fac,a_args,T::id_class(),a_obj,a_created);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
|
||||
Reference in New Issue
Block a user