Jpp  17.3.2
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 &file_name, const std::string &symbol)
 Load function from shared library. More...
 
void load (const std::string &buffer)
 Load 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 &file_name, const std::string &symbol)
 Constructor. More...
 
 JFunctionAdaptorHelper (const JFunctionAdaptorHelper &helper)
 Copy constructor. 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.

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

237  :
238  handle (NULL),
239  function(NULL)
240  {}
template<class __pF__>
JEEP::JFunctionAdaptorHelper< __pF__ >::JFunctionAdaptorHelper ( __pF__  pf)
inlineprotected

Constructor.

Parameters
pfpointer to function

Definition at line 248 of file JFunctionAdaptor.hh.

248  :
249  handle (NULL),
250  function(pf)
251  {}
template<class __pF__>
JEEP::JFunctionAdaptorHelper< __pF__ >::JFunctionAdaptorHelper ( const std::string file_name,
const std::string symbol 
)
inlineprotected

Constructor.

Parameters
file_namefile name
symbolfunction name

Definition at line 260 of file JFunctionAdaptor.hh.

261  :
262  handle (NULL),
263  function(NULL)
264  {
265  this->load(file_name, symbol);
266  }
void load(const std::string &file_name, 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 274 of file JFunctionAdaptor.hh.

274  :
275  handle (helper.handle),
276  function(helper.function)
277  {
278  if (is_open()) {
279  attach(helper);
280  }
281  }
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  close();
83 
84  function = pf;
85  }
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:696
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:696
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 file_name,
const std::string symbol 
)
inline

Load function from shared library.

Parameters
file_namefile name
symbolfunction name

Definition at line 168 of file JFunctionAdaptor.hh.

169  {
170  open(file_name.c_str());
171 
172  get(symbol.c_str());
173  }
void open(const char *file_name)
Open file.
template<class __pF__>
void JEEP::JFunctionAdaptorHelper< __pF__ >::load ( const std::string buffer)
inline

Load function from shared library.

The input buffer should consist of <file name>SEPARATOR<symbol>.

Parameters
bufferinput

Definition at line 183 of file JFunctionAdaptor.hh.

184  {
185  using namespace std;
186 
187  const string::size_type pos = buffer.rfind(SEPARATOR);
188 
189  if (pos != string::npos) {
190 
191  load(buffer.substr(0,pos).c_str(), buffer.substr(pos+1).c_str());
192 
193  } else {
194 
195  THROW(JParseError, "Missing separator " << SEPARATOR << " in " << buffer);
196  }
197  }
static const char SEPARATOR
Separation character between library file name and function name.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
void load(const std::string &file_name, const std::string &symbol)
Load function from shared library.
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.

Parameters
ininput stream
objectfunction adaptor helper
Returns
input stream

Definition at line 207 of file JFunctionAdaptor.hh.

208  {
209  object.reset();
210 
211  std::string buffer;
212 
213  if (in >> buffer) {
214  object.load(buffer);
215  }
216 
217  return in;
218  }
then awk string
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:46
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 228 of file JFunctionAdaptor.hh.

229  {
230  return out;
231  }

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

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

Definition at line 284 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: