]> git.lyx.org Git - features.git/commitdiff
Add copied_ptr.h to the repository too.
authorAngus Leeming <leeming@lyx.org>
Wed, 10 Sep 2003 23:06:18 +0000 (23:06 +0000)
committerAngus Leeming <leeming@lyx.org>
Wed, 10 Sep 2003 23:06:18 +0000 (23:06 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7732 a592a061-630c-0410-9148-cb99ea01b6c8

src/support/ChangeLog
src/support/Makefile.am
src/support/copied_ptr.h [new file with mode: 0644]

index ce82f3f96e72b975ee0bf8a23a4b85eb9436c817..634cd5555ed87e98b53ad469d6a57c051ea73c90 100644 (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
index 9d7c22a366cc9cb4c36bf9d8c688242950105b89..6813f2c129e67254c0d12817f9a85d76f3af0822 100644 (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 \
diff --git a/src/support/copied_ptr.h b/src/support/copied_ptr.h
new file mode 100644 (file)
index 0000000..0683158
--- /dev/null
@@ -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