Jpp  18.3.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Attributes | 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 of function. More...
 
void reset ()
 Reset function adaptor helper. More...
 
void set (__pF__ pf)
 Set function. More...
 
void get (const char *symbol)
 Get function with given name according to specific protocol. More...
 
bool is_open () const
 Check if shared library file is open. More...
 
void open (const char *file_name)
 Open file. More...
 
void close ()
 Close file. More...
 
void load (const std::string &libso, const std::string &symbol)
 Load function from shared library. More...
 
void reload ()
 Reload function from shared library. 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...
 

Static Public Attributes

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

Protected Member Functions

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

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. 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.

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

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.
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  {}
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  {}
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.
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

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  }
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  }
bool detach()
Detach.
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  }
void reset()
Reset function adaptor helper.
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.
Definition: JException.hh:712
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  }
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  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
void initialise()
Initialise counter.
void reset()
Reset function adaptor helper.
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  }
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.
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 open(const char *file_name)
Open file.
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  }

Friends And Related Function Documentation

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.
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:48
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

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.

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

Definition at line 290 of file JFunctionAdaptor.hh.

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

Definition at line 291 of file JFunctionAdaptor.hh.

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

Definition at line 292 of file JFunctionAdaptor.hh.

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

Definition at line 293 of file JFunctionAdaptor.hh.

int* JLANG::JSharedCounter::counter
protectedinherited

Definition at line 94 of file JSharedCounter.hh.


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