OpendTect-6_4  6.4
manobjectset.h
Go to the documentation of this file.
1 #ifndef manobjectset_h
2 #define manobjectset_h
3 
4 /*+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: Bert
9  Date: Feb 2009
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 -*/
14 
15 #include "objectset.h"
16 
17 
22 template <class T>
23 mClass(Basic) ManagedObjectSet : public ObjectSet<T>
24 {
25 public:
26 
27  typedef int size_type;
28  typedef T object_type;
29 
30  inline ManagedObjectSet() {}
32  inline virtual ~ManagedObjectSet();
33  inline ManagedObjectSet<T>& operator =(const ObjectSet<T>&);
34  inline ManagedObjectSet<T>& operator =(const ManagedObjectSet<T>&);
35  virtual bool isManaged() const { return true; }
36 
37  inline virtual void erase() { deepErase( *this ); }
38  inline virtual void append(const ObjectSet<T>&);
39  inline virtual void removeRange(size_type,size_type);
40  inline virtual T* removeSingle( int idx, bool kporder=true );
42  inline virtual T* removeAndTake(int idx, bool kporder=true );
44  inline virtual T* replace(int idx, T*);
46  inline virtual ManagedObjectSet<T>& operator -=(T*);
47 
48 };
49 
50 
51 //ObjectSet implementation
52 
53 template <class T> inline
55  : ObjectSet<T>()
56 { *this = t; }
57 
58 template <class T> inline
60 { erase(); }
61 
62 
63 template <class T> inline
65 {
66  if ( &os != this )
67  { erase(); append( os ); }
68  return *this;
69 }
70 
71 
72 template <class T> inline
74 {
75  if ( ptr )
76  { this->vec_.erase( (void*)ptr ); delete ptr; }
77  return *this;
78 }
79 
80 
81 template <class T> inline
83  const ManagedObjectSet<T>& os )
84 {
85  if ( &os != this )
86  deepCopy( *this, os );
87  return *this;
88 }
89 
90 
91 template <class T> inline
93 {
94  const int sz = os.size();
95  this->vec_.setCapacity( this->size()+sz, true );
96  if ( !os.isManaged() )
98  else
99  for ( int idx=0; idx<sz; idx++ )
100  ObjectSet<T>::add( os[idx] ? new T( *os[idx] ) : 0 );
101 }
102 
103 
104 template <class T> inline
105 T* ManagedObjectSet<T>::removeSingle( int idx, bool kporder )
106 {
107  delete (*this)[idx];
108  ObjectSet<T>::removeSingle( idx, kporder );
109  return 0; //Don't give anyone a chance to play with the deleted object
110 }
111 
112 
113 template <class T> inline
114 T* ManagedObjectSet<T>::replace( int idx , T* ptr )
115 {
116  delete ObjectSet<T>::replace( idx, ptr );
117  return 0; //Don't give anyone a chance to play with the deleted object
118 }
119 
120 
121 template <class T> inline
123 {
124  for ( int idx=(int)i1; idx<=i2; idx++ )
125  delete (*this)[idx];
126  ObjectSet<T>::removeRange( i1, i2 );
127 }
128 
129 template <class T> inline
130 T* ManagedObjectSet<T>::removeAndTake(int idx, bool kporder )
131 {
132  return ObjectSet<T>::removeSingle( idx, kporder );
133 }
134 
135 
136 #endif
virtual void removeRange(size_type, size_type)
Definition: manobjectset.h:122
virtual void removeRange(size_type from, size_type to)
Definition: objectset.h:477
virtual void erase()
Definition: manobjectset.h:37
virtual T * replace(size_type idx, T *)
Definition: objectset.h:390
virtual T * replace(int idx, T *)
Definition: manobjectset.h:114
void erase()
Definition: vectoraccess.h:78
virtual T * removeSingle(size_type, bool keep_order=true)
Definition: objectset.h:460
size_type size() const
Definition: objectset.h:50
bool append(TypeSetBase< T, I > &to, const TypeSetBase< S, J > &from)
append allowing a different type to be merged into set
Definition: typeset.h:198
Set of pointers to objects.
Definition: commontypes.h:32
ManagedObjectSet()
Definition: manobjectset.h:30
virtual bool isManaged() const
Definition: objectset.h:46
int size_type
Definition: manobjectset.h:27
virtual ManagedObjectSet< T > & operator-=(T *)
Definition: manobjectset.h:73
virtual void append(const ObjectSet< T > &)
Definition: manobjectset.h:92
virtual bool isManaged() const
Definition: manobjectset.h:35
void deepCopy(ObjectSet< T > &to, const ObjectSet< S > &from)
fill an ObjectSet with copies of the objects in the other set.
Definition: objectset.h:147
void removeRange(ODSET &inst, size_type start, size_type stop)
Removes a range from the set.
Definition: odset.h:57
bool setCapacity(I sz, bool withmargin)
Definition: vectoraccess.h:155
T object_type
Definition: manobjectset.h:28
virtual T * removeAndTake(int idx, bool kporder=true)
Definition: manobjectset.h:130
virtual ~ManagedObjectSet()
Definition: manobjectset.h:59
VectorAccess< void *, size_type > vec_
Definition: objectset.h:93
#define mClass(module)
Definition: commondefs.h:164
ObjectSet where the objects contained are owned by this set.
Definition: manobjectset.h:23
ManagedObjectSet< T > & operator=(const ObjectSet< T > &)
Definition: manobjectset.h:64
virtual T * removeSingle(int idx, bool kporder=true)
Definition: manobjectset.h:105
void deepErase(ObjectSet< T > &os)
empty the ObjectSet deleting all objects pointed to.
Definition: objectset.h:118

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B. V. 2019