X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FUtils%2Fpimpl_ptr.cti;fp=senf%2FUtils%2Fpimpl_ptr.cti;h=4ae797a7ec50e269f9c0069225944b5458d24dcb;hb=7c7bdbf90e2ff5a93f6e92b3c2f3e62cba74ac24;hp=0000000000000000000000000000000000000000;hpb=aa4bfb511acb198a278caafc193ac67a9c322a13;p=senf.git diff --git a/senf/Utils/pimpl_ptr.cti b/senf/Utils/pimpl_ptr.cti new file mode 100644 index 0000000..4ae797a --- /dev/null +++ b/senf/Utils/pimpl_ptr.cti @@ -0,0 +1,159 @@ +// $Id$ +// +// Copyright (C) 2010 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY +// Stefan Bund +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +/** \file + \brief pimpl_ptr inline template implementation */ + +//#include "pimpl_ptr.ih" + +// Custom includes +#include "IgnoreValue.hh" + +#define prefix_ inline +///////////////////////////////cti.p/////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////// +// senf::pimpl_ptr + +template +prefix_ senf::pimpl_ptr::pimpl_ptr(T* pointee) + : p (pointee) +{ + // Is it fair to assume pointer assignment to be atomic on multi-threaded platforms ? + doCopy_ = &myCopyFn; + doDelete_ = &myDeleteFn; +} + +template +prefix_ senf::pimpl_ptr::pimpl_ptr(const pimpl_ptr & rhs) + : p (doCopy_(rhs.p)) +{} + +template +prefix_ senf::pimpl_ptr::~pimpl_ptr() + throw() +{ + doDelete_(p); +} + +template +prefix_ const T* senf::pimpl_ptr::get() + const throw() +{ + return p; +} + +template +prefix_ T* senf::pimpl_ptr::get() + throw() +{ + return p; +} + +template +prefix_ const T* senf::pimpl_ptr::operator->() + const throw() +{ + return p; +} + +template +prefix_ T* senf::pimpl_ptr::operator->() + throw() +{ + return p; +} + +template +prefix_ const T& senf::pimpl_ptr::operator*() + const throw() +{ + return *p; +} + +template +prefix_ T& senf::pimpl_ptr::operator*() + throw() +{ + return *p; +} + +template +prefix_ void senf::pimpl_ptr::swap(pimpl_ptr & with) + throw() +{ + std::swap(p, with.p); +} + +template +prefix_ senf::pimpl_ptr & +senf::pimpl_ptr::operator=(const pimpl_ptr & rhs) +{ + T* pp = doCopy_(rhs.p); + doDelete_(p); + p = pp; + return *this; +} + +template +prefix_ void senf::pimpl_ptr::myDeleteFn(T* p) +{ + return CloneAllocator::deallocate_clone(p); +} + +template +prefix_ T* senf::pimpl_ptr::myCopyFn(const T* p) +{ + return CloneAllocator::allocate_clone(*p); +} + +/////////////////////////////////////////////////////////////////////////// + +template +prefix_ void std::swap(senf::pimpl_ptr & lhs, + senf::pimpl_ptr & rhs) + throw() +{ + lhs.swap(rhs); +} + +template +typename senf::pimpl_ptr::Copier + senf::pimpl_ptr::doCopy_ (0); + +template +typename senf::pimpl_ptr::Deleter + senf::pimpl_ptr::doDelete_ (0); + +///////////////////////////////cti.e/////////////////////////////////////// +#undef prefix_ + + +// Local Variables: +// mode: c++ +// fill-column: 100 +// comment-column: 40 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// End: