datahandle.h 2.63 KB
 schultezub committed Jul 06, 2012 1 2 3 4 ``````#ifndef datahandle_h__ #define datahandle_h__ namespace TUMVis { `````` schultezub committed Jul 25, 2012 5 `````` class AbstractData; `````` schultezub committed Jul 06, 2012 6 7 8 `````` /** * A DataHandle is responsible to manage the lifetime of an AbstractData instance. `````` schultezub committed Jul 25, 2012 9 `````` * Therefore, it implements a reference counting technique in cooperation with AbstractData. `````` schultezub committed Jul 06, 2012 10 `````` * `````` schultezub committed Jul 25, 2012 11 12 13 14 15 16 `````` * \note For clarity: An AbstractData instance can be referenced by multiple DataHandles. As soon * as it is afterwards reference by 0 DataHandles the AbstractData instance will be destroyed. * Also remember that a DataHandle takes ownership of the given AbstractData instance. So do * not delete it once it has been assigned to a DataHandle (respectively DataContainer) or mess * with its reference counting! * \note Reference counting implementation inspired from Scott Meyers: More Effective C++, Item 29 `````` schultezub committed Jul 06, 2012 17 `````` * `````` schultezub committed Jul 25, 2012 18 `````` * \todo Check for thread-safety `````` schultezub committed Jul 06, 2012 19 20 21 22 `````` */ class DataHandle { public: /** `````` schultezub committed Jul 25, 2012 23 24 25 26 `````` * Creates a new DataHandle for the given data. * \note By passing the data to DataHandle you will transfer its ownership to the reference * counting mechanism. Make sure not to interfere with it or delete \a data yourself! * \param data Data for the DataHandle `````` schultezub committed Jul 06, 2012 27 `````` */ `````` schultezub committed Jul 25, 2012 28 `````` DataHandle(AbstractData* data); `````` schultezub committed Jul 06, 2012 29 30 `````` /** `````` schultezub committed Jul 25, 2012 31 32 33 `````` * Copy-constructor * \note If \a rhs is not shareable, this implies a copy of the data! * \param rhs Source DataHandle `````` schultezub committed Jul 06, 2012 34 `````` */ `````` schultezub committed Jul 25, 2012 35 `````` DataHandle(const DataHandle& rhs); `````` schultezub committed Jul 06, 2012 36 37 `````` /** `````` schultezub committed Jul 25, 2012 38 39 40 41 `````` * Assignment operator * \note If \a rhs is not shareable, this implies a copy of the data! * \param rhs source DataHandle * \return *this `````` schultezub committed Jul 06, 2012 42 `````` */ `````` schultezub committed Jul 25, 2012 43 `````` DataHandle& operator=(const DataHandle& rhs); `````` schultezub committed Jul 12, 2012 44 `````` `````` schultezub committed Jul 06, 2012 45 `````` /** `````` schultezub committed Jul 25, 2012 46 `````` * Destructor, will delete the managed AbstractData. `````` schultezub committed Jul 06, 2012 47 `````` */ `````` schultezub committed Jul 25, 2012 48 `````` virtual ~DataHandle(); `````` schultezub committed Jul 06, 2012 49 50 `````` /** `````` schultezub committed Jul 25, 2012 51 52 `````` * Grants const access to the managed AbstractData instance. * \return _data; `````` schultezub committed Jul 06, 2012 53 `````` */ `````` schultezub committed Jul 25, 2012 54 `````` const AbstractData* getData() const; `````` schultezub committed Jul 06, 2012 55 56 `````` /** `````` schultezub committed Jul 25, 2012 57 58 59 `````` * Grants access to the managed AbstractData instance. * \note If the data is referenced by more than one object, this implies a copy of the data! * \return A modifyable version of the held data. `````` schultezub committed Jul 06, 2012 60 `````` */ `````` schultezub committed Jul 25, 2012 61 `````` AbstractData* getData(); `````` schultezub committed Jul 06, 2012 62 63 `````` `````` schultezub committed Jul 25, 2012 64 `````` private: `````` schultezub committed Jul 06, 2012 65 `````` /** `````` schultezub committed Jul 25, 2012 66 `````` * Initializes the reference counting for the data. `````` schultezub committed Jul 06, 2012 67 `````` */ `````` schultezub committed Jul 25, 2012 68 `````` void init(); `````` schultezub committed Jul 06, 2012 69 `````` `````` schultezub committed Jul 25, 2012 70 `````` AbstractData* _data; ///< managed data `````` schultezub committed Jul 06, 2012 71 72 73 74 75 `````` }; } #endif // datahandle_h__``````