// edm_handle.h #ifndef INCLUDED_EDM_HANDLE #define INCLUDED_EDM_HANDLE // PURPOSE // Provide a basic handle to hold data chunks. // // CLASSES // edm_Handle: Hold and give access to data chunks. // // DESCRIPTION // This component implements a very basic parameterizable handle class for // chunk types. Unlike auto_ptr, this handle class is not responsible for // the memory of the object it points to. The purpose of the handle type is // to eliminate the need for user casts and to simplify the retrieval of // chunk objects from the event repository. // // The handle can be used to hold both const and non-const chunk objects: // // edm_Handle ch; // "const" handle // edm_Handle h; // "non-const" handle // // A typical usage would be: // // edm_Handle h; // event->getChunk(edm_SomeKey(&h)); // // now use h as a pointer to a Bar chunk // ================ // CLASS edm_Handle // ================ template class edm_Handle { Chunk *d_chunk_p; public: // CREATORS edm_Handle() : d_chunk_p(0) {} // Create an null handle. edm_Handle(Chunk *chunk) : d_chunk_p(chunk) {} // Create a handle that holds the specified chunk. edm_Handle(const edm_Handle& handle) : d_chunk_p(handle.d_chunk_p) {} // Create a handle that points to the same chunk as the specified // handle. ~edm_Handle() {} // Destroy this handle but NOT the chunk data being held. // MANIPULATORS edm_Handle& operator=(const edm_Handle& handle) { d_chunk_p = handle.d_chunk_p; } // Make this handle point to the same chunk as the specified handle. void load(Chunk *chunk) { d_chunk_p = chunk; } // Release currently held chunk, if any, and set this handle to hold // the specified chunk. // ACCESSORS Chunk* operator->() const { return d_chunk_p; } // Return a pointer to the chunk being held by this handle. Chunk& operator*() const { return *d_chunk_p; } // Return a reference to the chunk being held by this handle. operator Chunk*() const { return d_chunk_p; } // Convert this handle to a pointer to the chunk being held by this // handle. }; #endif