Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
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.
 
bool is_valid () const
 Check validity of function.
 
void reset ()
 Reset function adaptor helper.
 
void set (__pF__ pf)
 Set function.
 
void get (const char *symbol)
 Get function with given name according to specific protocol.
 
bool is_open () const
 Check if shared library file is open.
 
void open (const char *file_name)
 Open file.
 
void close ()
 Close file.
 
void load (const std::string &libso, const std::string &symbol)
 Load function from shared library.
 
void reload ()
 Reload function from shared library.
 
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.
 

Static Public Attributes

static const char SEPARATOR = ':'
 Separation character between library file name and function name.
 

Protected Member Functions

 JFunctionAdaptorHelper ()
 Default constructor.
 
 JFunctionAdaptorHelper (__pF__ pf)
 Constructor.
 
 JFunctionAdaptorHelper (const std::string &libso, const std::string &symbol)
 Constructor.
 
 JFunctionAdaptorHelper (const JFunctionAdaptorHelper &helper)
 Copy constructor.
 

Protected Attributes

void * handle
 
__pF__ function
 
std::string libso
 
std::string symbol
 
int * counter
 

Friends

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

Detailed Description

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

Auxiliary base class for function adaptor.

Note that the dynamic load library internally maintains link counts for the file handles.

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 45 of file JFunctionAdaptor.hh.

46 {
47 reset();
48 }
void reset()
Reset function adaptor helper.

◆ JFunctionAdaptorHelper() [1/4]

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

Default constructor.

Definition at line 242 of file JFunctionAdaptor.hh.

242 :
243 handle (NULL),
244 function(NULL)
245 {}

◆ JFunctionAdaptorHelper() [2/4]

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

Constructor.

Parameters
pfpointer to function

Definition at line 253 of file JFunctionAdaptor.hh.

253 :
254 handle (NULL),
255 function(pf)
256 {}

◆ JFunctionAdaptorHelper() [3/4]

template<class __pF__ >
JEEP::JFunctionAdaptorHelper< __pF__ >::JFunctionAdaptorHelper ( const std::string & libso,
const std::string & symbol )
inlineprotected

Constructor.

Parameters
libsofile name
symbolfunction name

Definition at line 265 of file JFunctionAdaptor.hh.

266 :
267 handle (NULL),
268 function(NULL)
269 {
270 this->load(libso, symbol);
271 }
void load(const std::string &libso, const std::string &symbol)
Load function from shared library.

◆ JFunctionAdaptorHelper() [4/4]

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

Copy constructor.

Parameters
helperhelper

Definition at line 279 of file JFunctionAdaptor.hh.

279 :
280 handle (helper.handle),
281 function(helper.function),
282 libso (helper.libso),
283 symbol (helper.symbol)
284 {
285 if (is_open()) {
286 attach(helper);
287 }
288 }
void attach(const JSharedCounter &object)
Attach this counter to given shared counter object.
bool is_open() const
Check if shared library file is open.

Member Function Documentation

◆ is_valid()

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

Check validity of function.

Returns
true if valid function; else false

Definition at line 56 of file JFunctionAdaptor.hh.

57 {
58 return (function != NULL);
59 }

◆ reset()

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

Reset function adaptor helper.

Definition at line 65 of file JFunctionAdaptor.hh.

66 {
67 if (detach()) {
68 close();
69 }
70
71 function = NULL;
72 }

◆ set()

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

Set function.

Parameters
pfpointer to function

Definition at line 80 of file JFunctionAdaptor.hh.

81 {
82 reset();
83
84 function = pf;
85 }

◆ get()

template<class __pF__ >
void JEEP::JFunctionAdaptorHelper< __pF__ >::get ( const char * symbol)
inline

Get function with given name according to specific protocol.

Parameters
symbolfunction name

Definition at line 93 of file JFunctionAdaptor.hh.

94 {
95 function = NULL;
96
97 if (handle != NULL) {
98
99 dlerror(); // reset errors
100
101 function = (__pF__) dlsym(handle, symbol);
102
103 const char* error = dlerror();
104
105 if (error != NULL) {
106 THROW(JFileReadException, error);
107 }
108
109 } else {
110
111 THROW(JFileReadException, "Invalid handle.");
112 }
113 }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.

◆ is_open()

template<class __pF__ >
bool JEEP::JFunctionAdaptorHelper< __pF__ >::is_open ( ) const
inline

Check if shared library file is open.

Returns
true if open; else false

Definition at line 121 of file JFunctionAdaptor.hh.

122 {
123 return (handle != NULL);
124 }

◆ open()

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

Open file.

Parameters
file_namefile name

Definition at line 132 of file JFunctionAdaptor.hh.

133 {
134 reset();
135
136 handle = dlopen(file_name, RTLD_LOCAL | RTLD_LAZY);
137
138 if (!handle) {
139 THROW(JFileOpenException, dlerror());
140 }
141
142 initialise();
143 }
void initialise()
Initialise counter.

◆ close()

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

Close file.

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

Definition at line 151 of file JFunctionAdaptor.hh.

152 {
153 if (handle != NULL) {
154 dlclose(handle);
155 dlclose(handle);
156 }
157
158 handle = NULL;
159 }

◆ load()

template<class __pF__ >
void JEEP::JFunctionAdaptorHelper< __pF__ >::load ( const std::string & libso,
const std::string & symbol )
inline

Load function from shared library.

Parameters
libsofile name
symbolfunction name

Definition at line 168 of file JFunctionAdaptor.hh.

169 {
170 this->libso = libso;
171 this->symbol = symbol;
172
173 reload();
174 }
void reload()
Reload function from shared library.

◆ reload()

template<class __pF__ >
void JEEP::JFunctionAdaptorHelper< __pF__ >::reload ( )
inline

Reload function from shared library.

Definition at line 180 of file JFunctionAdaptor.hh.

181 {
182 open(libso.c_str());
183
184 get(symbol.c_str());
185 }
void get(const char *symbol)
Get function with given name according to specific protocol.
void open(const char *file_name)
Open file.

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

Friends And Related Symbol Documentation

◆ operator>>

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

Read function adaptor helper from input stream.

The input format should be conform <file name>[SEPARATOR<symbol>].

Parameters
ininput stream
objectfunction adaptor helper
Returns
input stream

Definition at line 197 of file JFunctionAdaptor.hh.

198 {
199 using namespace std;
200
201 object.reset();
202
203 string buffer;
204
205 if (in >> buffer) {
206
207 const string::size_type pos = buffer.rfind(SEPARATOR);
208
209 if (pos != string::npos) {
210
211 object.libso = buffer.substr(0,pos);
212 object.symbol = buffer.substr(pos+1);
213
214 } else {
215
216 object.libso = buffer;
217 }
218
219 object.reload();
220 }
221
222 return in;
223 }
static const char SEPARATOR
Separation character between library file name and function name.

◆ 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 233 of file JFunctionAdaptor.hh.

234 {
235 return out;
236 }

Member Data Documentation

◆ SEPARATOR

template<class __pF__ >
const char JEEP::JFunctionAdaptorHelper< __pF__ >::SEPARATOR = ':'
static

Separation character between library file name and function name.

Definition at line 39 of file JFunctionAdaptor.hh.

◆ handle

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

Definition at line 290 of file JFunctionAdaptor.hh.

◆ function

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

Definition at line 291 of file JFunctionAdaptor.hh.

◆ libso

template<class __pF__ >
std::string JEEP::JFunctionAdaptorHelper< __pF__ >::libso
protected

Definition at line 292 of file JFunctionAdaptor.hh.

◆ symbol

template<class __pF__ >
std::string JEEP::JFunctionAdaptorHelper< __pF__ >::symbol
protected

Definition at line 293 of file JFunctionAdaptor.hh.

◆ counter

int* JLANG::JSharedCounter::counter
protectedinherited

Definition at line 94 of file JSharedCounter.hh.


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