/* * TI Voxel Lib component. * * Copyright (c) 2014 Texas Instruments Inc. */ #ifndef VOXEL_PTR_H #define VOXEL_PTR_H #include namespace Voxel { /** * \addtogroup Util * @{ */ template void deleter(T *data) { delete data; } /** * NOTE: This is a simple way to ensure that matching new/delete are used. * WARNING: * 1. DO NOT CREATE the pointer "data" in some other library (so/dll) context and pass it to Ptr<> created in another library (so/dll). * Always. create Ptr<> and allocate "data" in the same so/dll. * 2. DO NOT USE THIS CLASS FOR array data, that is, allocated with new[] */ template class Ptr: public std::shared_ptr { public: Ptr(T *data): std::shared_ptr(data, deleter) {} template Ptr(T *data, _Deleter d): std::shared_ptr(data, d) {} Ptr(): std::shared_ptr() {} Ptr(const std::shared_ptr &p): std::shared_ptr(p) {} #ifdef SWIG T *operator ->() { return this->std::shared_ptr::operator->(); } const T *operator ->() const { return this->std::shared_ptr::operator->(); } #endif virtual ~Ptr() {} }; /** * @} */ } #endif // VOXEL_PTR_H