/////////////////////////////////////////////////////////////////////////////////////////////////// // OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net) /////////////////////////////////////////////////////////////////////////////////////////////////// // Created : 2008-12-19 // Updated : 2005-06-13 // Licence : This source is under MIT License // File : gli/shared_array.inl /////////////////////////////////////////////////////////////////////////////////////////////////// namespace gli { template shared_array::shared_array() : Counter(0), Pointer(0) {} template shared_array::shared_array ( shared_array const & SharedArray ) { this->Counter = SharedArray.Counter; this->Pointer = SharedArray.Pointer; (*this->Counter)++; } template shared_array::shared_array ( T * Pointer ) { this->reset(Pointer); } template shared_array::~shared_array() { this->reset(); } template void shared_array::reset() { if(this->Pointer) { (*this->Counter)--; if(*this->Counter <= 0) { delete this->Counter; this->Counter = 0; delete[] this->Pointer; this->Pointer = 0; } } } template void shared_array::reset(T * Pointer) { this->Counter = new int; this->Pointer = Pointer; *this->Counter = 1; } template shared_array& shared_array::operator= ( shared_array const & SharedArray ) { this->reset(); this->Counter = SharedArray.Counter; this->Pointer = SharedArray.Pointer; (*this->Counter)++; return *this; } //template //shared_array & shared_array::operator=(T * Pointer) //{ // if(this->Pointer) // { // (*this->Counter)--; // if(*this->Counter <= 0) // { // delete this->Counter; // delete[] this->Pointer; // } // } // this->Counter = new int; // this->Pointer = this->Pointer; // (*this->Counter) = 1; // return *this; //} template bool shared_array::operator==(shared_array const & SharedArray) const { return this->Pointer == SharedArray.Pointer; } template bool shared_array::operator!=(shared_array const & SharedArray) const { return this->Pointer != SharedArray.Pointer; } template T & shared_array::operator*() { return *this->Pointer; } template T * shared_array::operator->() { return this->Pointer; } template T const & shared_array::operator*() const { return * this->Pointer; } template T const * const shared_array::operator->() const { return this->Pointer; } template T * shared_array::get() { return this->Pointer; } template T const * const shared_array::get() const { return this->Pointer; } }//namespace gli