// evioUtil.hxx // Author: Elliott Wolin, JLab, 5-feb-2007 // must do: // update word doc // should do: // shared pointer // java version // would like to do: // cMsg channel // ET channel // not sure: // scheme for exception type codes? #ifndef _evioUtil_hxx #define _evioUtil_hxx #include #include #include #include #include #include #include #include #include #ifdef vxworks #include #else #include #include #endif #include #include #include #ifdef sun #define __FUNCTION__ "unknown" #endif /** @mainpage EVIO Event I/O Package. * @author Elliott Wolin. * @version 2.0. * @date 5-Feb-2007. * * @section intro Introduction * The EVIO package is an object-oriented extension of the original EVIO C event I/O utility. * * The base utility reads and writes EVIO format events in an event buffer to and from disk. * Events are blocked into standard block sizes, and endian swapping is performed if necessary. * * This package maps the event in the event buffer into an in-memory tree-like bank hierarchy. Event trees can be queried, modified, * or created from scratch. In-memory trees can be automatically serialized into a buffer and written to disk. * * @warning Internally EVIO uses only the unambiguous types int8_t, uint8_t, ... int64_t, uint64_t. * The long and long long data types are not supported, as their interpretion varies among different compilers * and architectures. The unambiguous types are compatible with char, short, and int wherever I have checked. * But only the 64-bit types int64_t and uint64_t work consistently across architectures. * * @warning The safest route, of course, is to use the unambiguous types exclusively. * But the example programs use char, short, int, and int64_t and so far work fine. No guarantees for the future, though... */ /** All evio symbols reside in the evio namespace.*/ namespace evio { using namespace std; using namespace evio; // evio classes: class evioStreamParserHandler; class evioStreamParser; class evioDOMTree; class evioDOMNode; class evioDOMContainerNode; template class evioDOMLeafNode; class evioSerializable; template class evioUtil; // plus a number of function object classes defined below template class counted_ptr { public: typedef X element_type; explicit counted_ptr(X* p = 0) // allocate a new counter : itsCounter(0) {if (p) itsCounter = new counter(p);} ~counted_ptr() {release();} counted_ptr(const counted_ptr& r) throw() {acquire(r.itsCounter);} counted_ptr& operator=(const counted_ptr& r) { if (this != &r) { release(); acquire(r.itsCounter); } return *this; } X& operator*() const throw() {return *itsCounter->ptr;} X* operator->() const throw() {return itsCounter->ptr;} X* get() const throw() {return itsCounter ? itsCounter->ptr : 0;} bool unique() const throw() {return (itsCounter ? itsCounter->count == 1 : true);} private: struct counter { counter(X* p = 0, unsigned c = 1) : ptr(p), count(c) {} X* ptr; unsigned count; }* itsCounter; void acquire(counter* c) throw() { // increment the count itsCounter = c; if (c) ++c->count; } void release() { // decrement the count, delete if it is 0 if (itsCounter) { if (--itsCounter->count == 0) { delete itsCounter->ptr; delete itsCounter; } itsCounter = 0; } } }; //----------------------------------------------------------------------------- //----------------------------- Typedefs -------------------------------------- //----------------------------------------------------------------------------- typedef evioDOMTree* evioDOMTreeP; /** evioDOMNodeP; /** evioDOMNodeList; /** evioDOMNodeListP; /** tagNum; /**