Add copied_ptr.h to the repository too.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7732 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2003-09-10 23:06:18 +00:00
parent d273b0b94c
commit d55d4b9c1c
3 changed files with 110 additions and 0 deletions

View File

@ -1,3 +1,8 @@
2003-09-11 Angus Leeming <leeming@lyx.org>
* cow_ptr.h:
* copied_ptr.h: added to the repository. Maybe temporarily.
2003-09-09 Lars Gullik Bjønnes <larsbj@lyx.org>
* Makefile.am (libsupport_la_SOURCES): remove LAssert.C and LAssert.h

View File

@ -32,6 +32,8 @@ libsupport_la_SOURCES = \
boost-inst.C \
chdir.C \
copy.C \
copied_ptr.h \
cow_ptr.h \
filename.C \
filename.h \
filetools.C \

103
src/support/copied_ptr.h Normal file
View File

@ -0,0 +1,103 @@
// -*- C++ -*-
/**
* \file copied_ptr.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Yonat Sharon http://ootips.org/yonat/
*
* simple copy-on-create/assign pointer.
*
* Note: If the actual object pointed to belongs to a derived class,
* then copied_ptr will not create a copy of the derived class object,
* but a new base class object.
* If you want to use a polymorphic copy-on-assign pointer, use
* cloned_ptr.
*/
#ifndef COPIED_PTR_H
#define COPIED_PTR_H
namespace lyx {
namespace support {
template <typename T>
class copied_ptr {
public:
explicit copied_ptr(T * = 0);
~copied_ptr();
copied_ptr(copied_ptr const &);
copied_ptr & operator=(copied_ptr const &);
T & operator*() const;
T * operator->() const;
T * get() const;
private:
T * ptr_;
void copy(copied_ptr const &);
};
template <typename T>
copied_ptr<T>::copied_ptr(T * p)
: ptr_(p)
{}
template <typename T>
copied_ptr<T>::~copied_ptr()
{
delete ptr_;
}
template <typename T>
copied_ptr<T>::copied_ptr(copied_ptr const & other)
{
copy(other.get());
}
template <typename T>
copied_ptr<T> & copied_ptr<T>::operator=(copied_ptr const & other)
{
if (&other != this) {
delete ptr_;
copy(other);
}
return *this;
}
template <typename T>
T & copied_ptr<T>::operator*() const
{
return *ptr_;
}
template <typename T>
T * copied_ptr<T>::operator->() const
{
return ptr_;
}
template <typename T>
T * copied_ptr<T>::get() const
{
return ptr_;
}
template <typename T>
void copied_ptr<T>::copy(copied_ptr const & other)
{
ptr_ = other.ptr_ ? new T(*other.ptr_) : 0;
}
} // namespace support
} // namespace lyx
#endif // NOT COPIED_PTR_H