Jpp 21.0.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JTOOLS::JAutoPointer< JDerived_t, JBase_t > Class Template Reference

Template class for loading and storing of objects. More...

#include <JSelector.hh>

Inheritance diagram for JTOOLS::JAutoPointer< JDerived_t, JBase_t >:
JTOOLS::JAbstractAutoPointer< JBase_t > JTOOLS::JDriver< JDerived_t > JLANG::JStreamInput JLANG::JStreamOutput

Public Member Functions

 JAutoPointer ()
 Default constructor.
 
 JAutoPointer (JDerived_t *p)
 Constructor.
 
virtual std::istream & read (std::istream &in) override
 Stream input.
 
virtual std::ostream & write (std::ostream &out) const override
 Stream output.
 

Static Private Member Functions

static JDerived_t * load (std::false_type option)
 Load object without input.
 
static JDerived_t * load (std::istream &in, std::false_type option)
 Load object without input.
 
static JDerived_t * load (std::istream &in, std::true_type option)
 Load object with input.
 
static JDerived_t * load ()
 Load object.
 
static JDerived_t * load (std::istream &in)
 Load object.
 
static void store (std::ostream &out, const JDerived_t *p, std::false_type option)
 Store object without output.
 
static void store (std::ostream &out, const JDerived_t *p, std::true_type option)
 Store object with output.
 
static void store (std::ostream &out, const T *p)
 Store object.
 

Detailed Description

template<class JDerived_t, class JBase_t>
class JTOOLS::JAutoPointer< JDerived_t, JBase_t >

Template class for loading and storing of objects.

This class implements the JAbstractAutoPointer interface.

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

Constructor & Destructor Documentation

◆ JAutoPointer() [1/2]

template<class JDerived_t , class JBase_t >
JTOOLS::JAutoPointer< JDerived_t, JBase_t >::JAutoPointer ( )
inline

Default constructor.

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

66 :
68 {}
JAbstractAutoPointer()
Default constructor.

◆ JAutoPointer() [2/2]

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

Constructor.

This class owns the pointer.

Parameters
ppointer to object

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

77 :
79 {
80 this->reset(p);
81 }
void reset(T &value)
Reset value.

Member Function Documentation

◆ read()

template<class JDerived_t , class JBase_t >
virtual std::istream & JTOOLS::JAutoPointer< JDerived_t, JBase_t >::read ( std::istream & in)
inlineoverridevirtual

Stream input.

This method creates a new object and read the corresponding input data if the redirect operator >>(isteam&) is defined for this data type.

Parameters
ininput stream
Returns
input stream

Implements JLANG::JStreamInput.

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

93 {
94 JDerived_t* p = this->load(in);
95
96 if (p != NULL) {
97 this->reset(p);
98 }
99
100 return in;
101 }
static JDerived_t * load()
Definition JDriver.hh:110

◆ write()

template<class JDerived_t , class JBase_t >
virtual std::ostream & JTOOLS::JAutoPointer< JDerived_t, JBase_t >::write ( std::ostream & out) const
inlineoverridevirtual

Stream output.

This method writes the corresponding data if the redirect operator <<(osteam&) is defined for this data type.

Parameters
outoutput stream
Returns
output stream

Implements JLANG::JStreamOutput.

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

113 {
114 this->store(out, this->get());
115
116 return out;
117 }
static void store(std::ostream &out, const JDerived_t *p, std::false_type option)
Definition JDriver.hh:85

◆ load() [1/5]

static JDerived_t * JTOOLS::JDriver< JDerived_t >::load ( std::false_type option)
inlinestaticprivateinherited

Load object without input.

Parameters
optionI/O option
Returns
pointer to newly loaded object

Definition at line 34 of file JDriver.hh.

35 {
36 return new JClass_t();
37 }

◆ load() [2/5]

static JDerived_t * JTOOLS::JDriver< JDerived_t >::load ( std::istream & in,
std::false_type option )
inlinestaticprivateinherited

Load object without input.

Parameters
ininput stream
optionI/O option
Returns
pointer to newly loaded object

Definition at line 47 of file JDriver.hh.

48 {
49 return load(option);
50 }

◆ load() [3/5]

static JDerived_t * JTOOLS::JDriver< JDerived_t >::load ( std::istream & in,
std::true_type option )
inlinestaticprivateinherited

Load object with input.

Parameters
ininput stream
optionI/O option
Returns
pointer to newly loaded object

Definition at line 60 of file JDriver.hh.

61 {
62 JClass_t* p = load(std::false_type());
63
64 in >> *p;
65
66 if (in.fail()) {
67
68 delete p;
69
70 p = NULL;
71 }
72
73 return p;
74 }

◆ load() [4/5]

static JDerived_t * JTOOLS::JDriver< JDerived_t >::load ( )
inlinestaticinherited

Load object.

Returns
pointer to newly loaded object

Definition at line 110 of file JDriver.hh.

111 {
112 return load(std::bool_constant<JStreamAvailable<JClass_t>::has_istream>());
113 }
Test availability of stream operators.

◆ load() [5/5]

static JDerived_t * JTOOLS::JDriver< JDerived_t >::load ( std::istream & in)
inlinestaticinherited

Load object.

Parameters
ininput stream
Returns
pointer to newly loaded object

Definition at line 122 of file JDriver.hh.

123 {
124 return load(in, std::bool_constant<JStreamAvailable<JClass_t>::has_istream>());
125 }

◆ store() [1/3]

static void JTOOLS::JDriver< JDerived_t >::store ( std::ostream & out,
const JDerived_t * p,
std::false_type option )
inlinestaticprivateinherited

Store object without output.

This implementation doesn't do anything.

Parameters
outoutput stream
optionI/O option
ppointer to object

Definition at line 85 of file JDriver.hh.

86 {}

◆ store() [2/3]

static void JTOOLS::JDriver< JDerived_t >::store ( std::ostream & out,
const JDerived_t * p,
std::true_type option )
inlinestaticprivateinherited

Store object with output.

Parameters
outoutput stream
optionI/O option
ppointer object

Definition at line 96 of file JDriver.hh.

97 {
98 if (p != NULL) {
99 out << *p;
100 }
101 }

◆ store() [3/3]

static void JTOOLS::JDriver< JDerived_t >::store ( std::ostream & out,
const T * p )
inlinestaticinherited

Store object.

Parameters
outoutput stream
ppointer to object

Definition at line 135 of file JDriver.hh.

136 {
137 store(out, dynamic_cast<const JClass_t*>(p), std::bool_constant<JStreamAvailable<JClass_t>::has_ostream>());
138 }

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