AlterOffice
AlterOffice 3.4 SDK C/C++ API Reference
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dynload.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 
3 
4 #ifndef INCLUDED_SALHELPER_DYNLOAD_HXX
5 #define INCLUDED_SALHELPER_DYNLOAD_HXX
6 
7 #include "sal/types.h"
8 #include "rtl/ustring.hxx"
9 #include "osl/module.h"
11 
12 namespace salhelper
13 {
14 
18 {
19 public:
27  static ORealDynamicLoader* SAL_CALL newInstance(
28  ORealDynamicLoader ** ppSetToZeroInDestructor,
29  const ::rtl::OUString& strModuleName,
30  const ::rtl::OUString& strInitFunction );
31 
33  sal_uInt32 SAL_CALL acquire();
35  sal_uInt32 SAL_CALL release();
36 
38  void* SAL_CALL getApi() const;
39 
40 protected:
50  ORealDynamicLoader( ORealDynamicLoader ** ppSetToZeroInDestructor,
51  const ::rtl::OUString& strModuleName,
52  const ::rtl::OUString& strInitFunction,
53  void* pApi,
54  oslModule pModule );
55 
57  virtual ~ORealDynamicLoader();
58 
60  void* m_pApi;
62  sal_uInt32 m_refCount;
73 };
74 
75 
88 template<class API>
90 {
91 public:
94  {
95  m_pLoader = NULL;
96  }
97 
104  ODynamicLoader( const ::rtl::OUString& strModuleName,
105  const ::rtl::OUString& strInitFunction )
106  {
107  if (!m_pStaticLoader)
108  {
111  strModuleName,
112  strInitFunction);
113  }
114  else
115  {
117  }
118 
120  }
121 
124  {
125  m_pLoader = toCopy.m_pLoader;
126  if( m_pLoader )
127  m_pLoader->acquire();
128  }
129 
132  {
133  if( m_pLoader )
134  if (m_pLoader->release()==0)
135  m_pStaticLoader = NULL;
136  }
137 
140  {
141  if( m_pLoader != toAssign.m_pLoader )
142  {
143  if( toAssign.m_pLoader )
144  {
145  toAssign.m_pLoader->acquire();
146  }
147  if( m_pLoader )
148  {
149  m_pLoader->release();
150  }
151  m_pLoader = toAssign.m_pLoader;
152  }
153 
154  return (*this);
155  }
156 
158  API* SAL_CALL getApi() const
159  {
160  return static_cast<API*>(m_pLoader->getApi());
161  }
162 
164  API* SAL_CALL operator->() const
165  {
166  return static_cast<API*>(m_pLoader->getApi());
167  }
168 
170  bool SAL_CALL isLoaded() const
171  {
172  return (m_pLoader != NULL);
173  }
174 
175 protected:
179 };
180 
181 
182 template<class API>
184 
185 }
186 
187 #endif
188 
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ORealDynamicLoader ** ppSetToZeroInDestructor
stores a pointer to itself, which must be reset in the destructor to signal that the loader is invali...
Definition: dynload.hxx:72
sal_uInt32 acquire()
increase the reference count.
The ODynamicLoader provides a special load on call mechanism for dynamic libraries which support a C-...
Definition: dynload.hxx:89
This String class provides base functionality for C++ like Unicode character array handling...
Definition: ustring.hxx:182
void * getApi() const
returns a pointer to the initialized API function structure.
API * getApi() const
returns a pointer to the initialized API function structure.
Definition: dynload.hxx:158
ORealDynamicLoader * m_pLoader
Definition: dynload.hxx:178
::rtl::OUString m_strModuleName
stores the library name.
Definition: dynload.hxx:66
::rtl::OUString m_strInitFunction
stores the name of the initialization function.
Definition: dynload.hxx:68
ODynamicLoader()
Default constructor.
Definition: dynload.hxx:93
void * m_pApi
points to the structure with the initialized API function pointers.
Definition: dynload.hxx:60
~ODynamicLoader()
Destructor, decrease the reference count and unload the library if it is the last instance...
Definition: dynload.hxx:131
static ORealDynamicLoader * m_pStaticLoader
stores the real loader helper instance
Definition: dynload.hxx:177
static ORealDynamicLoader * newInstance(ORealDynamicLoader **ppSetToZeroInDestructor, const ::rtl::OUString &strModuleName, const ::rtl::OUString &strInitFunction)
initializes the loader, loads the library and call the initialization function.
oslModule m_pModule
stores the library handle.
Definition: dynload.hxx:64
ODynamicLoader(const ::rtl::OUString &strModuleName, const ::rtl::OUString &strInitFunction)
Constructor, loads the library if necessary otherwise the reference count will be increased...
Definition: dynload.hxx:104
ODynamicLoader< API > & operator=(const ODynamicLoader< API > &toAssign)
Assign operator.
Definition: dynload.hxx:139
API * operator->() const
cast operator, which cast to a pointer with the initialized API function structure.
Definition: dynload.hxx:164
void * oslModule
Definition: module.h:39
The ORealDynamicLoader is an implementation helper class for the template loader ODynamicLoader.
Definition: dynload.hxx:17
ODynamicLoader(const ODynamicLoader< API > &toCopy)
Copy constructor.
Definition: dynload.hxx:123
bool isLoaded() const
checks if the loader works on a loaded and initialized library.
Definition: dynload.hxx:170
#define SALHELPER_DLLPUBLIC
Definition: salhelperdllapi.h:12
sal_uInt32 m_refCount
stores the reference count.
Definition: dynload.hxx:62
sal_uInt32 release()
decrease the reference count and delete the last instance.