ATLAS Offline Software
SealSharedLib.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
15 #ifndef CXXUTILS_SEAL_SHAREDLIB_H // wlav SEAL_BASE_SHARED_LIBRARY_H
16 #define CXXUTILS_SEAL_SHAREDLIB_H // wlav SEAL_BASE_SHARED_LIBRARY_H
17 
18 
20 //# include "SealBase/SharedLibraryError.h" wlav
21 //# include "SealBase/Callback.h" wlav
22 # include <string>
23 # include <list>
24 # include <exception> // wlav
25 
26 //namespace seal { wlav
27 namespace Athena { // wlav
28 
29 
30 
31 // wlav from SealBase/Callback.h
32 template <class T1>
34 {
35 public:
36  Callback1Rep (void) : m_refs (0) { }
37  virtual ~Callback1Rep (void) { }
38 
39  virtual void call (T1) = 0;
40  virtual bool equal (const Callback1Rep *x) const = 0;
41 
42  void ref (void) { ++m_refs; }
43  void unref (void) { if (--m_refs == 0) delete this; }
44 
45 private:
46  int m_refs;
47 };
48 
49 template <class T1>
50 class Callback1
51 {
52 public:
54  Callback1 (const Callback1 &x);
55  ~Callback1 (void);
56  Callback1 & operator= (const Callback1 &x);
57 
58  bool operator== (const Callback1 &x) const;
59  operator bool (void) const;
60  void operator() (T1);
61 
62 private:
64 };
65 
66 template <class T1, class T2>
67 class CallbackImpF11 : public Callback1Rep<T1>
68 {
69  typedef CallbackImpF11 self;
70 public:
71  CallbackImpF11 (void (*function) (T1, T2),
72  const T2 &fill_2)
73  : m_function (function),
74  m_fill_2 (fill_2)
75  { }
76 
77  virtual void call (T1 a)
78  { (*m_function) (a, m_fill_2); }
79 
80  virtual bool equal (const Callback1Rep<T1> *other) const
81  { const self *x = dynamic_cast<const self *> (other);
82  return x && x->m_function == m_function && x->m_fill_2 == m_fill_2; }
83 
84 private:
85  void (*m_function) (T1, T2);
87 };
88 
89 template <class T1>
90 inline
92  : m_rep (implementation)
93 { if (m_rep) m_rep->ref (); }
94 
95 template <class T1>
96 inline
98  : m_rep (x.m_rep)
99 { if (m_rep) m_rep->ref (); }
100 
101 template <class T1>
102 inline
104 { if (m_rep) m_rep->unref (); }
105 
106 template <class T1>
107 inline Callback1<T1> &
109 {
110  if (m_rep != x.m_rep)
111  {
112  if (m_rep) m_rep->unref ();
113  m_rep = x.m_rep;
114  if (m_rep) m_rep->ref ();
115  }
116  return *this;
117 }
118 
119 template <class T1>
120 inline bool
122 { return m_rep == x.m_rep || (m_rep && x.m_rep && m_rep->equal (x.m_rep)); }
123 
124 template <class T1>
125 inline
127 { return m_rep ? true : false; } // FIXME: for Sun CC 4.2 (no bool)
128 
129 template <class T1>
130 inline void
132 { m_rep->call (a); }
133 
134 template <class T1, class T2>
135 inline Callback1Rep<T1> *
136 CreateCallback (void (*function) (T1, T2),
137  const T2 &fill_2)
138 { return new CallbackImpF11<T1,T2> (function, fill_2); }
139 
140 
141 // wlav modified from SealBase/SharedLibraryError.h
144 {
145 public:
146  SharedLibraryError( const std::string& context, const std::string& cause );
147  virtual ~SharedLibraryError() throw() {}
148 
149  virtual const char* what() const throw();
150 
151 private:
152  std::string m_message;
153 };
154 
155 
158 {
159 public:
160  typedef void * Data;
161  typedef void (*Function) (void);
162 
164  struct LibraryInfo
165  {
166  unsigned long m_text_start; //< Start of text segment
167  unsigned long m_text_end; //< End of text segment
168  unsigned long m_data_start; //< Start of data segment
169  unsigned long m_data_end; //< End of data segment
170  unsigned long m_bss_start; //< Start of common
171  unsigned long m_bss_end; //< End of common
172  const char *m_filename; //< Filename
173  };
174 
176 
177  static std::string path (void);
178  static void path ATLAS_NOT_THREAD_SAFE (const std::string &path);
179  static std::string libname (const std::string &name);
180  static std::string symname (const std::string &name);
181 
182  static SharedLibrary * self (void);
183  static SharedLibrary * load (const std::string &name);
184  static void loaded (InfoHandler &handler);
185 
186  void release (void);
187  void abandon (void);
188 
189  Data data (const std::string &name, bool mangle = true) const;
190  Function function (const std::string &name, bool mangle = true) const;
191 
192 protected:
193  SharedLibrary (void *handle);
194  ~SharedLibrary (void);
195 
196 private:
197  void *m_handle;
198 
199  // undefined semantics
201  SharedLibrary &operator= (const SharedLibrary &);
202 };
203 
204 //<<<<<< INLINE PUBLIC FUNCTIONS >>>>>>
205 //<<<<<< INLINE MEMBER FUNCTIONS >>>>>>
206 
207 //} // namespace seal wlav
208 } // namespace Athena wlav
209 #endif // CXXUTILS_SEAL_SHAREDLIB_H wlav SEAL_BASE_SHARED_LIBRARY_H
Athena::SharedLibrary::LibraryInfo::m_data_start
unsigned long m_data_start
Definition: SealSharedLib.h:168
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
Athena::SharedLibrary::Data
void * Data
Definition: SealSharedLib.h:160
Athena::Callback1::operator()
void operator()(T1)
Definition: SealSharedLib.h:131
Athena::SharedLibrary::LibraryInfo::m_text_start
unsigned long m_text_start
Definition: SealSharedLib.h:166
athena.path
path
python interpreter configuration --------------------------------------—
Definition: athena.py:128
Athena::Callback1Rep
Definition: SealSharedLib.h:34
Athena::SharedLibrary::InfoHandler
Callback1< const LibraryInfo & > InfoHandler
Definition: SealSharedLib.h:175
Athena::CallbackImpF11::call
virtual void call(T1 a)
Definition: SealSharedLib.h:77
Athena::Callback1::~Callback1
~Callback1(void)
Definition: SealSharedLib.h:103
Athena::CallbackImpF11::m_fill_2
T2 m_fill_2
Definition: SealSharedLib.h:86
Athena::SharedLibrary::LibraryInfo::m_data_end
unsigned long m_data_end
Definition: SealSharedLib.h:169
x
#define x
Athena::SharedLibraryError
Error in a shared library operation.
Definition: SealSharedLib.h:144
Athena::CallbackImpF11
Definition: SealSharedLib.h:68
Athena::Callback1Rep::call
virtual void call(T1)=0
Athena::SharedLibrary::LibraryInfo::m_bss_end
unsigned long m_bss_end
Definition: SealSharedLib.h:171
handler
void handler(int sig)
signal handler
Definition: rmain.cxx:98
Athena::SharedLibraryError::m_message
std::string m_message
Definition: SealSharedLib.h:152
Athena::Callback1::operator==
bool operator==(const Callback1 &x) const
Definition: SealSharedLib.h:121
Athena::Callback1Rep::equal
virtual bool equal(const Callback1Rep *x) const =0
Athena::SharedLibrary::LibraryInfo::m_bss_start
unsigned long m_bss_start
Definition: SealSharedLib.h:170
Athena
Some weak symbol referencing magic...
Definition: AthLegacySequence.h:21
calibdata.exception
exception
Definition: calibdata.py:496
Athena::SharedLibrary::LibraryInfo::m_filename
const char * m_filename
Definition: SealSharedLib.h:172
Athena::Callback1Rep::m_refs
int m_refs
Definition: SealSharedLib.h:46
Athena::SharedLibrary::LibraryInfo::m_text_end
unsigned long m_text_end
Definition: SealSharedLib.h:167
Athena::Callback1::m_rep
Callback1Rep< T1 > * m_rep
Definition: SealSharedLib.h:63
Athena::CallbackImpF11::m_function
void(* m_function)(T1, T2)
Definition: SealSharedLib.h:85
Athena::Callback1Rep::~Callback1Rep
virtual ~Callback1Rep(void)
Definition: SealSharedLib.h:37
python.EventInfoMgtInit.release
release
Definition: EventInfoMgtInit.py:24
private
#define private
Definition: DetDescrConditionsDict_dict_fixes.cxx:13
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
Athena::SharedLibraryError::~SharedLibraryError
virtual ~SharedLibraryError()
Definition: SealSharedLib.h:147
Athena::Callback1Rep::unref
void unref(void)
Definition: SealSharedLib.h:43
Athena::SharedLibraryError::what
virtual const char * what() const
Definition: SealSharedLib.cxx:103
Athena::SharedLibrary::LibraryInfo
Information about a currently loaded shared library.
Definition: SealSharedLib.h:165
Athena::SharedLibrary
Shared library services.
Definition: SealSharedLib.h:158
Athena::Callback1
Definition: SealSharedLib.h:51
Athena::SharedLibrary::m_handle
void * m_handle
Definition: SealSharedLib.h:197
Athena::Callback1Rep::Callback1Rep
Callback1Rep(void)
Definition: SealSharedLib.h:36
a
TList * a
Definition: liststreamerinfos.cxx:10
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
Athena::SharedLibrary::SharedLibrary
SharedLibrary(const SharedLibrary &)
Athena::CallbackImpF11::equal
virtual bool equal(const Callback1Rep< T1 > *other) const
Definition: SealSharedLib.h:80
Athena::Callback1::Callback1
Callback1(Callback1Rep< T1 > *implementation=0)
Definition: SealSharedLib.h:91
calibdata.implementation
implementation
Definition: calibdata.py:43
Athena::SharedLibraryError::SharedLibraryError
SharedLibraryError(const std::string &context, const std::string &cause)
Definition: SealSharedLib.cxx:83
Athena::SharedLibrary::ATLAS_NOT_THREAD_SAFE
static void path ATLAS_NOT_THREAD_SAFE(const std::string &path)
python.root_pickle.load
def load(f, use_proxy=1, key=None)
Definition: root_pickle.py:476
checker_macros.h
Define macros for attributes used to control the static checker.
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60
Athena::CallbackImpF11::CallbackImpF11
CallbackImpF11(void(*function)(T1, T2), const T2 &fill_2)
Definition: SealSharedLib.h:71
Athena::Callback1Rep::ref
void ref(void)
Definition: SealSharedLib.h:42
Athena::CreateCallback
Callback1Rep< T1 > * CreateCallback(void(*function)(T1, T2), const T2 &fill_2)
Definition: SealSharedLib.h:136
Athena::Callback1::operator=
Callback1 & operator=(const Callback1 &x)
Definition: SealSharedLib.h:108