Jpp
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
JEEP::JFunctionAdaptorHelper< pF > Struct Template Reference

Auxiliary base class for function adaptor. More...

#include <JFunctionAdaptor.hh>

Inheritance diagram for JEEP::JFunctionAdaptorHelper< pF >:
JLANG::JSharedCounter

Public Member Functions

virtual ~JFunctionAdaptorHelper ()
 Virtual destructor. More...
 
bool is_valid () const
 Check validity. More...
 
void reset ()
 Reset function adaptor helper. More...
 
void set (pF pf)
 Set function. More...
 
void open (const char *file_name)
 Open file. More...
 
void close ()
 Close file. More...
 
void initialise ()
 Initialise counter. More...
 
void attach (const JSharedCounter &object)
 Attach this counter to given shared counter object. More...
 
bool detach ()
 Detach. More...
 

Protected Member Functions

 JFunctionAdaptorHelper ()
 Default constructor. More...
 
 JFunctionAdaptorHelper (const JFunctionAdaptorHelper &helper)
 Copy constructor. More...
 
 JFunctionAdaptorHelper (pF pf)
 Constructor. More...
 
 JFunctionAdaptorHelper (const char *file_name, const char *function_name)
 Constructor. More...
 
void get (const char *function_name)
 Get function with given name according to specific protocol. More...
 

Protected Attributes

void * handle
 
pF function
 
int * counter
 

Friends

std::istream & operator>> (std::istream &in, JFunctionAdaptorHelper &object)
 Read function adaptor helper from input stream. More...
 
std::ostream & operator<< (std::ostream &out, const JFunctionAdaptorHelper &object)
 Write function adaptor helper to output stream. More...
 

Detailed Description

template<class pF>
struct JEEP::JFunctionAdaptorHelper< pF >

Auxiliary base class for function adaptor.

Definition at line 33 of file JFunctionAdaptor.hh.

Constructor & Destructor Documentation

◆ ~JFunctionAdaptorHelper()

template<class pF>
virtual JEEP::JFunctionAdaptorHelper< pF >::~JFunctionAdaptorHelper ( )
inlinevirtual

Virtual destructor.

Definition at line 39 of file JFunctionAdaptor.hh.

40  {
41  if (detach()) {
42  close();
43  }
44  }

◆ JFunctionAdaptorHelper() [1/4]

template<class pF>
JEEP::JFunctionAdaptorHelper< pF >::JFunctionAdaptorHelper ( )
inlineprotected

Default constructor.

Definition at line 160 of file JFunctionAdaptor.hh.

160  :
161  handle (NULL),
162  function(NULL)
163  {}

◆ JFunctionAdaptorHelper() [2/4]

template<class pF>
JEEP::JFunctionAdaptorHelper< pF >::JFunctionAdaptorHelper ( const JFunctionAdaptorHelper< pF > &  helper)
inlineprotected

Copy constructor.

Parameters
helperhelper

Definition at line 171 of file JFunctionAdaptor.hh.

171  :
172  handle (helper.handle),
173  function(helper.function)
174  {
175  attach(helper);
176  }

◆ JFunctionAdaptorHelper() [3/4]

template<class pF>
JEEP::JFunctionAdaptorHelper< pF >::JFunctionAdaptorHelper ( pF  pf)
inlineprotected

Constructor.

Parameters
pfpointer to function

Definition at line 184 of file JFunctionAdaptor.hh.

184  :
185  handle (NULL),
186  function(pf)
187  {}

◆ JFunctionAdaptorHelper() [4/4]

template<class pF>
JEEP::JFunctionAdaptorHelper< pF >::JFunctionAdaptorHelper ( const char *  file_name,
const char *  function_name 
)
inlineprotected

Constructor.

Parameters
file_namefile name
function_namefunction name

Definition at line 196 of file JFunctionAdaptor.hh.

197  :
198  handle (NULL),
199  function(NULL)
200  {
201  this->open(file_name);
202 
203  this->get(function_name);
204  }

Member Function Documentation

◆ is_valid()

template<class pF>
bool JEEP::JFunctionAdaptorHelper< pF >::is_valid ( ) const
inline

Check validity.

Returns
true if valid function; else false

Definition at line 52 of file JFunctionAdaptor.hh.

53  {
54  return (function != NULL);
55  }

◆ reset()

template<class pF>
void JEEP::JFunctionAdaptorHelper< pF >::reset ( )
inline

Reset function adaptor helper.

Definition at line 61 of file JFunctionAdaptor.hh.

62  {
63  if (detach()) {
64  close();
65  }
66 
67  function = NULL;
68  }

◆ set()

template<class pF>
void JEEP::JFunctionAdaptorHelper< pF >::set ( pF  pf)
inline

Set function.

Parameters
pfpointer to function

Definition at line 76 of file JFunctionAdaptor.hh.

77  {
78  reset();
79 
80  function = pf;
81  }

◆ open()

template<class pF>
void JEEP::JFunctionAdaptorHelper< pF >::open ( const char *  file_name)
inline

Open file.

Parameters
file_namefile name

Definition at line 89 of file JFunctionAdaptor.hh.

90  {
91  reset();
92 
93  handle = dlopen(file_name, RTLD_LAZY);
94 
95  if (!handle) {
96  THROW(JLANG::JFileOpenException, dlerror());
97  }
98 
99  initialise();
100  }

◆ close()

template<class pF>
void JEEP::JFunctionAdaptorHelper< pF >::close ( )
inline

Close file.

Note that the file should remain open as long as the library method is used.

Definition at line 108 of file JFunctionAdaptor.hh.

109  {
110  if (handle != NULL) {
111  dlclose(handle);
112  }
113 
114  handle = NULL;
115  }

◆ get()

template<class pF>
void JEEP::JFunctionAdaptorHelper< pF >::get ( const char *  function_name)
inlineprotected

Get function with given name according to specific protocol.

Parameters
function_namefunction name

Definition at line 212 of file JFunctionAdaptor.hh.

213  {
214  function = NULL;
215 
216  if (handle != NULL) {
217 
218  dlerror(); // reset errors
219 
220  function = (pF) dlsym(handle, function_name);
221 
222  const char* error = dlerror();
223 
224  if (error != NULL) {
226  }
227 
228  } else {
229 
230  THROW(JLANG::JFileReadException, "Invalid handle.");
231  }
232  }

◆ 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  }

Friends And Related Function Documentation

◆ operator>>

template<class pF>
std::istream& operator>> ( std::istream &  in,
JFunctionAdaptorHelper< pF > &  object 
)
friend

Read function adaptor helper from input stream.

Parameters
ininput stream
objectfunction adaptor helper
Returns
input stream

Definition at line 125 of file JFunctionAdaptor.hh.

126  {
127  using namespace std;
128 
129  object.reset();
130 
131  string file_name, function_name;
132 
133  if (in >> file_name >> function_name) {
134 
135  object.open(file_name.c_str());
136 
137  object.get(function_name.c_str());
138  }
139 
140  return in;
141  }

◆ operator<<

template<class pF>
std::ostream& operator<< ( std::ostream &  out,
const JFunctionAdaptorHelper< pF > &  object 
)
friend

Write function adaptor helper to output stream.

Parameters
outoutput stream
objectfunction adaptor helper
Returns
output stream

Definition at line 151 of file JFunctionAdaptor.hh.

152  {
153  return out;
154  }

Member Data Documentation

◆ handle

template<class pF>
void* JEEP::JFunctionAdaptorHelper< pF >::handle
protected

Definition at line 234 of file JFunctionAdaptor.hh.

◆ function

template<class pF>
pF JEEP::JFunctionAdaptorHelper< pF >::function
protected

Definition at line 235 of file JFunctionAdaptor.hh.

◆ counter

int* JLANG::JSharedCounter::counter
protectedinherited

Definition at line 83 of file JSharedCounter.hh.


The documentation for this struct was generated from the following file:
JLANG::JSharedCounter::detach
bool detach()
Detach.
Definition: JSharedCounter.hh:63
JLANG::JFileReadException
Exception for reading of file.
Definition: JException.hh:360
JLANG::JFileOpenException
Exception for opening of file.
Definition: JException.hh:342
JLANG::JSharedCounter::counter
int * counter
Definition: JSharedCounter.hh:83
JEEP::JFunctionAdaptorHelper::open
void open(const char *file_name)
Open file.
Definition: JFunctionAdaptor.hh:89
JEEP::JFunctionAdaptorHelper::get
void get(const char *function_name)
Get function with given name according to specific protocol.
Definition: JFunctionAdaptor.hh:212
JEEP::JFunctionAdaptorHelper::reset
void reset()
Reset function adaptor helper.
Definition: JFunctionAdaptor.hh:61
JLANG::JSharedCounter::attach
void attach(const JSharedCounter &object)
Attach this counter to given shared counter object.
Definition: JSharedCounter.hh:46
JEEP::JFunctionAdaptorHelper::close
void close()
Close file.
Definition: JFunctionAdaptor.hh:108
THROW
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
JLANG::JSharedCounter::initialise
void initialise()
Initialise counter.
Definition: JSharedCounter.hh:33
JEEP::JFunctionAdaptorHelper::handle
void * handle
Definition: JFunctionAdaptor.hh:234
JEEP::JFunctionAdaptorHelper::function
pF function
Definition: JFunctionAdaptor.hh:235
std
Definition: jaanetDictionary.h:36