Jpp  18.0.0-rc.3
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
JLANG::JObjectWriter< T > Struct Template Referenceabstract

Auxiliary class for object writing to a named device. More...

#include <JObjectWriter.hh>

Inheritance diagram for JLANG::JObjectWriter< T >:
JLANG::JObjectOutput< T > JLANG::JAbstractObjectWriter< T > JLANG::JSharedPointer< JObjectOutput< T > > JLANG::JObjectOutput< T > JLANG::JSharedCounter JLANG::JStorage< JObjectOutput< T >, JNew > JLANG::JPointer< JObjectOutput< T > > JLANG::JNew< JObjectOutput< T > > JLANG::JAbstractPointer< JObjectOutput< T > > JLANG::JEquals< JAbstractPointer< JObjectOutput< T > > > JLANG::JSTDObjectWriter< T > JLANG::JAssignSequence< T > JLANG::JAssignSequence< T >::JCSV

Public Types

typedef JSharedPointer
< JObjectOutput< T > > 
helper_type
 
typedef JPointer
< JObjectOutput< T > > 
pointer_type
 
typedef JStorage
< JObjectOutput< T >, JNew
storage_type
 
typedef JNew< JObjectOutput< T > > memory_type
 

Public Member Functions

 JObjectWriter ()
 Default constructor. More...
 
virtual JObjectOutput< T > * getHelper () const override
 Get helper. More...
 
virtual bool put (const T &object)=0
 Object output. More...
 
virtual bool put (const T &object) override
 Object output. More...
 
const JSharedPointergetSharedPointer () const
 Get shared pointer. More...
 
JSharedPointergetSharedPointer ()
 Get shared pointer. More...
 
void setSharedPointer (const JSharedPointer &object)
 Set shared pointer. More...
 
virtual void reset () override
 Reset pointer. More...
 
void reset (const JPointer< T > &pointer)
 Reset pointer. More...
 
void reset (JObjectOutput< T > *p)
 Reset pointer. More...
 
void set (const JPointer< T > &pointer)
 Set pointer. More...
 
void initialise ()
 Initialise counter. More...
 
void attach (const JSharedCounter &object)
 Attach this counter to given shared counter object. More...
 
bool detach ()
 Detach. More...
 
const int getCount ()
 Get count. More...
 
void recreate ()
 Recreate object in memory. More...
 
void create ()
 Create object in memory. More...
 
void create (const unsigned int size)
 Create array of objects in memory. More...
 
virtual JObjectOutput< T > * get () const override
 Get pointer. More...
 
JObjectOutput< T > *const & getReference () const
 Get rereference to internal pointer. More...
 
JObjectOutput< T > *& getReference ()
 Get rereference to internal pointer. More...
 
virtual bool equals (const JAbstractPointer &object) const
 Equals. More...
 
bool is_valid () const
 Check validity of pointer. More...
 
JObjectOutput< T > * operator-> () const
 Smart pointer operator. More...
 
 operator JObjectOutput< T > * () const
 Type conversion operator. More...
 

Static Public Member Functions

static void release (JObjectOutput< T > *p)
 Release memory. More...
 

Protected Member Functions

void set (const JSharedPointer &object)
 Set pointer. More...
 
virtual void set (JObjectOutput< T > *p) override
 Set pointer. More...
 
void release ()
 Release memory. More...
 

Protected Attributes

int * counter
 
JObjectOutput< T > * __p
 pointer to object More...
 

Detailed Description

template<class T>
struct JLANG::JObjectWriter< T >

Auxiliary class for object writing to a named device.

This class implements the JAbstractObjectWriter interface.

Definition at line 25 of file JObjectWriter.hh.

Member Typedef Documentation

template<class T>
typedef JSharedPointer< JObjectOutput<T> > JLANG::JObjectWriter< T >::helper_type

Definition at line 31 of file JObjectWriter.hh.

Definition at line 34 of file JSharedPointer.hh.

Definition at line 35 of file JSharedPointer.hh.

typedef JNew <JObjectOutput< T > > JLANG::JStorage< JObjectOutput< T > , JNew >::memory_type
inherited

Definition at line 33 of file JStorage.hh.

Constructor & Destructor Documentation

template<class T>
JLANG::JObjectWriter< T >::JObjectWriter ( )
inline

Default constructor.

Definition at line 36 of file JObjectWriter.hh.

37  {}

Member Function Documentation

template<class T>
virtual JObjectOutput<T>* JLANG::JObjectWriter< T >::getHelper ( ) const
inlineoverridevirtual

Get helper.

Returns
helper

Implements JLANG::JAbstractObjectWriter< T >.

Definition at line 45 of file JObjectWriter.hh.

46  {
47  return this->get();
48  }
template<class T>
virtual bool JLANG::JObjectOutput< T >::put ( const T object)
pure virtualinherited
template<class T>
virtual bool JLANG::JAbstractObjectWriter< T >::put ( const T object)
inlineoverridevirtualinherited

Object output.

Parameters
objectobject
Returns
true if OK; else false

Implements JLANG::JObjectOutput< T >.

Definition at line 43 of file JAbstractObjectWriter.hh.

44  {
45  return (this->getHelper() != NULL && this->getHelper()->put(object));
46  }
virtual JObjectOutput< T > * getHelper() const =0
Get helper.
virtual bool put(const T &object) override
Object output.
const JSharedPointer& JLANG::JSharedPointer< JObjectOutput< T > , JNew >::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  }
The template JSharedPointer class can be used to share a pointer to an object.
JSharedPointer& JLANG::JSharedPointer< JObjectOutput< T > , JNew >::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  }
The template JSharedPointer class can be used to share a pointer to an object.
void JLANG::JSharedPointer< JObjectOutput< T > , JNew >::setSharedPointer ( const JSharedPointer< JObjectOutput< 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  }
void set(const JSharedPointer &object)
Set pointer.
bool is_valid() const
Check validity of pointer.
virtual void reset() override
Reset pointer.
virtual void JLANG::JSharedPointer< JObjectOutput< T > , JNew >::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< JObjectOutput< T >, JNew >.

Definition at line 171 of file JSharedPointer.hh.

172  {
173  if (this->detach()) {
175  }
176 
178  }
void reset(T &value)
Reset value.
bool detach()
Detach.
void JLANG::JPointer< JObjectOutput< T > >::reset ( const JPointer< T > &  pointer)
inlineinherited

Reset pointer.

Parameters
pointerpointer to object

Definition at line 108 of file JPointer.hh.

109  {
110  this->reset(pointer.get());
111  }
virtual JClass_t * get() const override
Get pointer.
Definition: JPointer.hh:64
virtual void reset() override
Reset pointer.
Definition: JPointer.hh:84
void JLANG::JAbstractPointer< JObjectOutput< T > >::reset ( JObjectOutput< 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 reset()=0
Reset pointer.
virtual void set(JObjectOutput< T > *p)=0
Set pointer.
void JLANG::JSharedPointer< JObjectOutput< T > , JNew >::set ( const JSharedPointer< JObjectOutput< 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  }
void attach(const JSharedCounter &object)
Attach this counter to given shared counter object.
virtual void JLANG::JSharedPointer< JObjectOutput< T > , JNew >::set ( JObjectOutput< 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< JObjectOutput< T > >.

Definition at line 202 of file JSharedPointer.hh.

203  {
204  pointer_type::set(p);
205 
206  this->initialise();
207  }
void initialise()
Initialise counter.
void JLANG::JPointer< JObjectOutput< 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  }
virtual void set(JObjectOutput< T > *p) override
Set pointer.
Definition: JPointer.hh:75
virtual JClass_t * get() const override
Get pointer.
Definition: JPointer.hh:64
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  }
bool detach()
Detach.
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  }
bool detach()
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  }
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  }
void JLANG::JStorage< JObjectOutput< 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  }
bool is_valid() const
Check validity of pointer.
virtual void set(JObjectOutput< T > *p) override
Set pointer.
Definition: JPointer.hh:75
void JLANG::JStorage< JObjectOutput< 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  {
71  this->reset(memory_type::create());
72  }
virtual void reset() override
Reset pointer.
Definition: JStorage.hh:42
void JLANG::JStorage< JObjectOutput< 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  }
virtual void reset() override
Reset pointer.
Definition: JStorage.hh:42
void JLANG::JStorage< JObjectOutput< T > , JNew >::release ( )
inlineprotectedinherited

Release memory.

Definition at line 91 of file JStorage.hh.

92  {
93  memory_type::release(this->get());
94  }
static void JLANG::JNew< JObjectOutput< T > >::release ( JObjectOutput< T > *  p)
inlinestaticinherited

Release memory.

Parameters
ppointer to data

Definition at line 41 of file JMemory.hh.

42  {
43  delete p;
44  }
virtual JObjectOutput< T > * JLANG::JPointer< JObjectOutput< T > >::get ( ) const
inlineoverridevirtualinherited

Get pointer.

Returns
pointer to object

Implements JLANG::JAbstractPointer< JObjectOutput< T > >.

Definition at line 64 of file JPointer.hh.

65  {
66  return this->__p;
67  }
JObjectOutput< T > * __p
pointer to object
Definition: JPointer.hh:136
JObjectOutput< T > * const& JLANG::JPointer< JObjectOutput< 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  }
JObjectOutput< T > * __p
pointer to object
Definition: JPointer.hh:136
JObjectOutput< T > * & JLANG::JPointer< JObjectOutput< 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  }
JObjectOutput< T > * __p
pointer to object
Definition: JPointer.hh:136
virtual bool JLANG::JAbstractPointer< JObjectOutput< T > >::equals ( const JAbstractPointer< JObjectOutput< 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  }
bool JLANG::JAbstractPointer< JObjectOutput< 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  }
JObjectOutput< T > * JLANG::JAbstractPointer< JObjectOutput< 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.
Definition: JException.hh:696
bool is_valid() const
Check validity of pointer.
Exception for null pointer operation.
Definition: JException.hh:216
JLANG::JAbstractPointer< JObjectOutput< T > >::operator JObjectOutput< T > * ( ) const
inlineinherited

Type conversion operator.

Returns
pointer to object

Definition at line 126 of file JAbstractPointer.hh.

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

Member Data Documentation

int* JLANG::JSharedCounter::counter
protectedinherited

Definition at line 94 of file JSharedCounter.hh.

JObjectOutput< T > * JLANG::JPointer< JObjectOutput< T > >::__p
protectedinherited

pointer to object

Definition at line 136 of file JPointer.hh.


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