Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JTOOLS::JAutoElement< JBase_t > Class Template Reference

Handler class for automatic pointer. More...

#include <JSelector.hh>

Inheritance diagram for JTOOLS::JAutoElement< JBase_t >:
JLANG::JSharedPointer< JClass_t, JMemory_t > JLANG::JSharedCounter JLANG::JStorage< JClass_t, JNew > JLANG::JPointer< JClass_t > JLANG::JNew< JClass_t > JLANG::JAbstractPointer< JClass_t > JLANG::JEquals< JAbstractPointer< JClass_t > >

Public Types

typedef JPointer< JClass_t > pointer_type
 
typedef JStorage< JClass_t, JMemory_t > storage_type
 
typedef JNew< JClass_t > memory_type
 

Public Member Functions

 JAutoElement ()
 Default constructor.
 
template<class JDerived_t >
 JAutoElement (JType< JDerived_t > type)
 Constructor.
 
template<class JDerived_t >
 JAutoElement (JDerived_t *p)
 Constructor.
 
template<class JDerived_t >
void set ()
 Set the automatic pointer to the given data type.
 
template<class JDerived_t >
void set (JType< JDerived_t > type)
 Set the automatic pointer to the given data type.
 
template<class JDerived_t >
void set (JDerived_t *p)
 Set the automatic pointer to the given data type.
 
template<class JDerived_t >
JAutoElementoperator= (JType< JDerived_t > type)
 Assign given data type to the automatic pointer.
 
template<class JDerived_t >
JAutoElementoperator= (JDerived_t *p)
 Assign given data type to the automatic pointer.
 
const JSharedPointergetSharedPointer () const
 Get shared pointer.
 
JSharedPointergetSharedPointer ()
 Get shared pointer.
 
void setSharedPointer (const JSharedPointer &object)
 Set shared pointer.
 
virtual void reset () override
 Reset pointer.
 
void reset (const JPointer< T > &pointer)
 Reset pointer.
 
void reset (JClass_t *p)
 Reset pointer.
 
template<class T >
void set (const JPointer< T > &pointer)
 Set pointer.
 
void initialise ()
 Initialise counter.
 
void attach (const JSharedCounter &object)
 Attach this counter to given shared counter object.
 
bool detach ()
 Detach.
 
const int getCount ()
 Get count.
 
void recreate ()
 Recreate object in memory.
 
void create ()
 Create object in memory.
 
void create (const unsigned int size)
 Create array of objects in memory.
 
virtual JClass_t * get () const override
 Get pointer.
 
JClass_t *const & getReference () const
 Get rereference to internal pointer.
 
JClass_t *& getReference ()
 Get rereference to internal pointer.
 
virtual bool equals (const JAbstractPointer &object) const
 Equals.
 
bool is_valid () const
 Check validity of pointer.
 
JClass_t * operator-> () const
 Smart pointer operator.
 
 operator JClass_t * () const
 Type conversion operator.
 

Static Public Member Functions

static void release (JClass_t *p)
 Release memory.
 

Protected Member Functions

void set (const JSharedPointer &object)
 Set pointer.
 
virtual void set (JClass_t *p) override
 Set pointer.
 
void release ()
 Release memory.
 

Protected Attributes

int * counter
 
JClass_t * __p
 pointer to object
 

Private Types

typedef JAbstractAutoPointer< JBase_t > JAbstractAutoPointer_t
 
typedef JSharedPointer< JAbstractAutoPointer_tJSharedPointer_t
 
typedef JAutoElement< JBase_t > JAutoElement_t
 

Friends

std::istream & operator>> (std::istream &in, JAutoElement_t &element)
 Stream input.
 
std::ostream & operator<< (std::ostream &out, const JAutoElement_t &element)
 Stream output.
 

Detailed Description

template<class JBase_t>
class JTOOLS::JAutoElement< JBase_t >

Handler class for automatic pointer.

Definition at line 128 of file JTools/JSelector.hh.

Member Typedef Documentation

◆ JAbstractAutoPointer_t

template<class JBase_t >
JAbstractAutoPointer<JBase_t> JTOOLS::JAutoElement< JBase_t >::JAbstractAutoPointer_t
private

Definition at line 132 of file JTools/JSelector.hh.

◆ JSharedPointer_t

template<class JBase_t >
JSharedPointer<JAbstractAutoPointer_t> JTOOLS::JAutoElement< JBase_t >::JSharedPointer_t
private

Definition at line 133 of file JTools/JSelector.hh.

◆ JAutoElement_t

template<class JBase_t >
JAutoElement<JBase_t> JTOOLS::JAutoElement< JBase_t >::JAutoElement_t
private

Definition at line 134 of file JTools/JSelector.hh.

◆ pointer_type

template<class JClass_t , template< class > class JMemory_t = JNew>
JPointer<JClass_t> JLANG::JSharedPointer< JClass_t, JMemory_t >::pointer_type
inherited

Definition at line 34 of file JSharedPointer.hh.

◆ storage_type

template<class JClass_t , template< class > class JMemory_t = JNew>
JStorage<JClass_t, JMemory_t> JLANG::JSharedPointer< JClass_t, JMemory_t >::storage_type
inherited

Definition at line 35 of file JSharedPointer.hh.

◆ memory_type

JNew<JClass_t> JLANG::JStorage< JClass_t, JNew >::memory_type
inherited

Definition at line 33 of file JStorage.hh.

Constructor & Destructor Documentation

◆ JAutoElement() [1/3]

template<class JBase_t >
JTOOLS::JAutoElement< JBase_t >::JAutoElement ( )
inline

Default constructor.

Definition at line 140 of file JTools/JSelector.hh.

140 :
142 {}
JSharedPointer< JAbstractAutoPointer_t > JSharedPointer_t

◆ JAutoElement() [2/3]

template<class JBase_t >
template<class JDerived_t >
JTOOLS::JAutoElement< JBase_t >::JAutoElement ( JType< JDerived_t > type)
inline

Constructor.

Parameters
typedata type

Definition at line 151 of file JTools/JSelector.hh.

151 :
153 {
154 this->set(type);
155 }
void set()
Set the automatic pointer to the given data type.

◆ JAutoElement() [3/3]

template<class JBase_t >
template<class JDerived_t >
JTOOLS::JAutoElement< JBase_t >::JAutoElement ( JDerived_t * p)
inline

Constructor.

This class owns the pointer.

Parameters
ppointer to object

Definition at line 165 of file JTools/JSelector.hh.

165 :
167 {
168 this->set(p);
169 }

Member Function Documentation

◆ set() [1/6]

template<class JBase_t >
template<class JDerived_t >
void JTOOLS::JAutoElement< JBase_t >::set ( )
inline

Set the automatic pointer to the given data type.

Definition at line 176 of file JTools/JSelector.hh.

177 {
178 this->set(JType<JDerived_t>());
179 }

◆ set() [2/6]

template<class JBase_t >
template<class JDerived_t >
void JTOOLS::JAutoElement< JBase_t >::set ( JType< JDerived_t > type)
inline

Set the automatic pointer to the given data type.

Parameters
typedata type

Definition at line 188 of file JTools/JSelector.hh.

189 {
190 this->reset(new JAutoPointer<JDerived_t, JBase_t>());
191 }
virtual void reset() override
Reset pointer.

◆ set() [3/6]

template<class JBase_t >
template<class JDerived_t >
void JTOOLS::JAutoElement< JBase_t >::set ( JDerived_t * p)
inline

Set the automatic pointer to the given data type.

Parameters
ppointer to object

Definition at line 200 of file JTools/JSelector.hh.

201 {
202 this->reset(new JAutoPointer<JDerived_t, JBase_t>(p));
203 }

◆ operator=() [1/2]

template<class JBase_t >
template<class JDerived_t >
JAutoElement & JTOOLS::JAutoElement< JBase_t >::operator= ( JType< JDerived_t > type)
inline

Assign given data type to the automatic pointer.

Parameters
typedata type
Returns
this JAutoElement

Definition at line 213 of file JTools/JSelector.hh.

214 {
215 set(type);
216
217 return *this;
218 }

◆ operator=() [2/2]

template<class JBase_t >
template<class JDerived_t >
JAutoElement & JTOOLS::JAutoElement< JBase_t >::operator= ( JDerived_t * p)
inline

Assign given data type to the automatic pointer.

Parameters
ppointer to object
Returns
this JAutoElement

Definition at line 228 of file JTools/JSelector.hh.

229 {
230 set(p);
231
232 return *this;
233 }

◆ getSharedPointer() [1/2]

template<class JClass_t , template< class > class JMemory_t = JNew>
const JSharedPointer & JLANG::JSharedPointer< JClass_t, JMemory_t >::getSharedPointer ( ) const
inlineinherited

Get shared pointer.

Returns
this shared pointer

Definition at line 95 of file JSharedPointer.hh.

96 {
97 return static_cast<const JSharedPointer&>(*this);
98 }
JSharedPointer()
Default constructor.

◆ getSharedPointer() [2/2]

template<class JClass_t , template< class > class JMemory_t = JNew>
JSharedPointer & JLANG::JSharedPointer< JClass_t, JMemory_t >::getSharedPointer ( )
inlineinherited

Get shared pointer.

Returns
this shared pointer

Definition at line 106 of file JSharedPointer.hh.

107 {
108 return static_cast<JSharedPointer&>(*this);
109 }

◆ setSharedPointer()

template<class JClass_t , template< class > class JMemory_t = JNew>
void JLANG::JSharedPointer< JClass_t, JMemory_t >::setSharedPointer ( const JSharedPointer< JClass_t, JMemory_t > & object)
inlineinherited

Set shared pointer.

Parameters
objectshared pointer

Definition at line 117 of file JSharedPointer.hh.

118 {
119 if (this->get() != object.get()) {
120
121 this->reset();
122
123 if (object.is_valid()) {
124 this->set(object);
125 }
126 }
127 }
bool is_valid() const
Check validity of pointer.
virtual JClass_t * get() const override
Get pointer.
Definition JPointer.hh:64
void set(const JSharedPointer &object)
Set pointer.

◆ reset() [1/3]

template<class JClass_t , template< class > class JMemory_t = JNew>
virtual void JLANG::JSharedPointer< JClass_t, JMemory_t >::reset ( )
inlineoverridevirtualinherited

Reset pointer.

The reference counter is decremented by one and the object pointed to previously is deleted when its reference counter is zero.

Reimplemented from JLANG::JStorage< JClass_t, JNew >.

Definition at line 171 of file JSharedPointer.hh.

172 {
173 if (this->detach()) {
175 }
176
178 }
virtual void reset() override
Reset pointer.
Definition JPointer.hh:84
virtual void reset() override
Reset pointer.
Definition JStorage.hh:42

◆ reset() [2/3]

void JLANG::JPointer< JClass_t >::reset ( const JPointer< T > & pointer)
inlineinherited

Reset pointer.

Parameters
pointerpointer to object

Definition at line 35 of file JPointer.hh.

109 {
110 this->reset(pointer.get());
111 }

◆ reset() [3/3]

template<class JClass_t >
void JLANG::JAbstractPointer< JClass_t >::reset ( JClass_t * p)
inlineinherited

Reset pointer.

Parameters
ppointer to object

Definition at line 94 of file JAbstractPointer.hh.

95 {
96 if (this->get() != p) {
97
98 this->reset();
99
100 if (p != NULL) {
101 this->set(p);
102 }
103 }
104 }
virtual void set(JClass_t *p)=0
Set pointer.
virtual JClass_t * get() const =0
Get pointer.
virtual void reset()=0
Reset pointer.

◆ set() [4/6]

template<class JClass_t , template< class > class JMemory_t = JNew>
void JLANG::JSharedPointer< JClass_t, JMemory_t >::set ( const JSharedPointer< JClass_t, JMemory_t > & object)
inlineprotectedinherited

Set pointer.

The reference counter of the shared object pointed to is incremented by one.

Parameters
objectshared pointer

Definition at line 188 of file JSharedPointer.hh.

189 {
190 pointer_type::set(object.get());
191
192 this->attach(object);
193 }
virtual void set(JClass_t *p) override
Set pointer.
Definition JPointer.hh:75
void attach(const JSharedCounter &object)
Attach this counter to given shared counter object.

◆ set() [5/6]

template<class JClass_t , template< class > class JMemory_t = JNew>
virtual void JLANG::JSharedPointer< JClass_t, JMemory_t >::set ( JClass_t * p)
inlineoverrideprotectedvirtualinherited

Set pointer.

The reference counter of the shared object pointed to is initialised to one.

Parameters
ppointer to derived class object

Reimplemented from JLANG::JPointer< JClass_t >.

Definition at line 202 of file JSharedPointer.hh.

203 {
205
206 this->initialise();
207 }
void initialise()
Initialise counter.

◆ set() [6/6]

template<class JClass_t >
template<class T >
void JLANG::JPointer< JClass_t >::set ( const JPointer< T > & pointer)
inlineinherited

Set pointer.

Parameters
pointerpointer to object

Definition at line 96 of file JPointer.hh.

97 {
98 this->set(pointer.get());
99 }

◆ initialise()

void JLANG::JSharedCounter::initialise ( )
inlineinherited

Initialise counter.

Definition at line 33 of file JSharedCounter.hh.

34 {
35 detach();
36
37 counter = new int(1);
38 }

◆ attach()

void JLANG::JSharedCounter::attach ( const JSharedCounter & object)
inlineinherited

Attach this counter to given shared counter object.

Parameters
objectshared counter

Definition at line 46 of file JSharedCounter.hh.

47 {
48 detach();
49
50 counter = object.counter;
51
52 if (counter != NULL) {
53 ++(*counter);
54 }
55 }

◆ detach()

bool JLANG::JSharedCounter::detach ( )
inlineinherited

Detach.

Returns
true if counter at zero; else false

Definition at line 63 of file JSharedCounter.hh.

64 {
65 if (counter != NULL) {
66
67 if (--(*counter) == 0) {
68
69 delete counter;
70
71 counter = NULL;
72
73 return true;
74 }
75
76 counter = NULL;
77 }
78
79 return false;
80 }

◆ getCount()

const int JLANG::JSharedCounter::getCount ( )
inlineinherited

Get count.

Returns
count

Definition at line 88 of file JSharedCounter.hh.

89 {
90 return (counter != NULL ? *counter : 0);
91 }

◆ recreate()

void JLANG::JStorage< JClass_t, JNew >::recreate ( )
inlineinherited

Recreate object in memory.

A new object is created if no memory is allocated yet, else the previously created object is maintained.

Definition at line 57 of file JStorage.hh.

58 {
59 if (!this->is_valid()) {
60 this->set(memory_type::create());
61 }
62 }
static JClass_t * create()
Create object in memory.
Definition JMemory.hh:30

◆ create() [1/2]

void JLANG::JStorage< JClass_t, JNew >::create ( )
inlineinherited

Create object in memory.

The memory allocated by a previously created object will be released.

Definition at line 69 of file JStorage.hh.

70 {
72 }

◆ create() [2/2]

void JLANG::JStorage< JClass_t, JNew >::create ( const unsigned int size)
inlineinherited

Create array of objects in memory.

The memory allocated by previously created objects will be released.

Parameters
sizenumber of elements

Definition at line 81 of file JStorage.hh.

82 {
83 this->reset(memory_type::create(size));
84 }

◆ release() [1/2]

void JLANG::JStorage< JClass_t, JNew >::release ( )
inlineprotectedinherited

Release memory.

Definition at line 91 of file JStorage.hh.

92 {
93 memory_type::release(this->get());
94 }
static void release(JClass_t *p)
Release memory.
Definition JMemory.hh:41

◆ release() [2/2]

template<class JClass_t >
static void JLANG::JNew< JClass_t >::release ( JClass_t * p)
inlinestaticinherited

Release memory.

Parameters
ppointer to data

Definition at line 41 of file JMemory.hh.

42 {
43 delete p;
44 }

◆ get()

template<class JClass_t >
virtual JClass_t * JLANG::JPointer< JClass_t >::get ( ) const
inlineoverridevirtualinherited

◆ getReference() [1/2]

template<class JClass_t >
JClass_t *const & JLANG::JPointer< JClass_t >::getReference ( ) const
inlineinherited

Get rereference to internal pointer.

Returns
reference to internal pointer

Definition at line 119 of file JPointer.hh.

120 {
121 return __p;
122 }

◆ getReference() [2/2]

template<class JClass_t >
JClass_t *& JLANG::JPointer< JClass_t >::getReference ( )
inlineinherited

Get rereference to internal pointer.

Returns
reference to internal pointer

Definition at line 130 of file JPointer.hh.

131 {
132 return __p;
133 }

◆ equals()

template<class JClass_t >
virtual bool JLANG::JAbstractPointer< JClass_t >::equals ( const JAbstractPointer< JClass_t > & object) const
inlinevirtualinherited

Equals.

The equality is evaluated by comparison of the internal pointers.

Parameters
objectabstract pointer
Returns
true if equals; else false

Definition at line 50 of file JAbstractPointer.hh.

51 {
52 return this->get() == object.get();
53 }

◆ is_valid()

template<class JClass_t >
bool JLANG::JAbstractPointer< JClass_t >::is_valid ( ) const
inlineinherited

Check validity of pointer.

Returns
true if pointer not null; else false

Definition at line 83 of file JAbstractPointer.hh.

84 {
85 return this->get() != NULL;
86 }

◆ operator->()

template<class JClass_t >
JClass_t * JLANG::JAbstractPointer< JClass_t >::operator-> ( ) const
inlineinherited

Smart pointer operator.

Returns
pointer to object

Definition at line 112 of file JAbstractPointer.hh.

113 {
114 if (!is_valid())
115 THROW(JNullPointerException, "JAbstractPointer::operator->()");
116 else
117 return this->get();
118 }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.

◆ operator JClass_t *()

template<class JClass_t >
JLANG::JAbstractPointer< JClass_t >::operator JClass_t * ( ) const
inlineinherited

Type conversion operator.

Returns
pointer to object

Definition at line 126 of file JAbstractPointer.hh.

127 {
128 return this->get();
129 }

Friends And Related Symbol Documentation

◆ operator>>

template<class JBase_t >
std::istream & operator>> ( std::istream & in,
JAutoElement_t & element )
friend

Stream input.

Parameters
ininput stream
elementelement
Returns
input stream

Definition at line 243 of file JTools/JSelector.hh.

244 {
245 if (element.is_valid())
246 return element.get()->read(in);
247 else
248 return in;
249 }

◆ operator<<

template<class JBase_t >
std::ostream & operator<< ( std::ostream & out,
const JAutoElement_t & element )
friend

Stream output.

Parameters
outoutput stream
elementelement
Returns
output stream

Definition at line 259 of file JTools/JSelector.hh.

260 {
261 if (element.is_valid())
262 return element.get()->write(out);
263 else
264 return out;
265 }

Member Data Documentation

◆ counter

int* JLANG::JSharedCounter::counter
protectedinherited

Definition at line 94 of file JSharedCounter.hh.

◆ __p

template<class JClass_t >
JClass_t* JLANG::JPointer< JClass_t >::__p
protectedinherited

pointer to object

Definition at line 136 of file JPointer.hh.


The documentation for this class was generated from the following file: