TexGen
ObjectContainer.h
Go to the documentation of this file.
1/*=============================================================================
2TexGen: Geometric textile modeller.
3Copyright (C) 2006 Martin Sherburn
4
5This program is free software; you can redistribute it and/or
6modify it under the terms of the GNU General Public License
7as published by the Free Software Foundation; either version 2
8of the License, or (at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18=============================================================================*/
19
20#pragma once
21namespace TexGen
22{
24
37 template <typename T>
39 {
40 public:
43 {
44 *this = Object;
45 }
47 {
48 *this = CopyMe;
49 }
51 {
52 if(m_pObject) delete m_pObject;
53 }
55 {
56 if (m_pObject) delete m_pObject;
57 if (CopyMe.m_pObject)
58 m_pObject = dynamic_cast<T*>(CopyMe.m_pObject->Copy());
59 else
61 return *this;
62 }
63 CObjectContainer &operator = (const T &Object)
64 {
65 if (m_pObject) delete m_pObject;
66 m_pObject = dynamic_cast<T*>(Object.Copy());
67 return *this;
68 }
69 // Object should act as if it was a pointer of type T
71
76 operator T*() { return m_pObject; }
78 T* operator->() { return m_pObject; }
80 void Clear() { if(m_pObject) delete m_pObject; m_pObject = NULL; }
82 operator const T*() const { return m_pObject; }
84 const T* operator->() const { return m_pObject; }
85 private:
88 };
89
91 template <typename T>
92 struct LessPairDoubleObjectRef : public std::binary_function<std::pair<double, CObjectContainer<T> >, std::pair<double, CObjectContainer<T> >, bool>
93 {
94 bool operator()(std::pair<double, CObjectContainer<T> > x, std::pair<double, CObjectContainer<T> > y) { return x.first < y.first; }
95 };
96
97
98
100
106 template <typename T>
108 {
109 public:
111 // Don't copy the pointer when it is copied
114 {
115 m_pPointer = pPointer;
116 return *this;
117 }
118 // Object should act as if it was a pointer of type T
120
125 operator T*() { return m_pPointer; }
127 T* operator->() { return m_pPointer; }
129 operator const T*() const { return m_pPointer; }
131 const T* operator->() const { return m_pPointer; }
132 private:
135 };
136
137
138}; // namespace TexGen
139
140
141
142
143
#define NULL
Definition: ShinyConfig.h:50
Object container to help handle memory management issues.
CObjectContainer(const CObjectContainer< T > &CopyMe)
T * m_pObject
Object contained within the class.
T * operator->()
Pointer overload operator to act as a pointer of type T.
CObjectContainer(const T &Object)
const T * operator->() const
Pointer overload operator for the class when it is defined as const.
CObjectContainer & operator=(const CObjectContainer< T > &CopyMe)
void Clear()
Remove the object contained within the container class.
Weak pointer that acts as normal pointer except when copied.
const T * operator->() const
Pointer overload operator for the class when it is defined as const.
T * operator->()
Pointer overload operator to act as a pointer of type T.
CWeakPointer(const CWeakPointer< T > &CopyMe)
T * m_pPointer
Object contained within the class.
CWeakPointer & operator=(T *pPointer)
Namespace containing a series of customised math operations not found in the standard c++ library.
Used to sort double-objectref pairs.
bool operator()(std::pair< double, CObjectContainer< T > > x, std::pair< double, CObjectContainer< T > > y)