epoc32/include/baliba.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
parent 2 2fe1408b6811
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
williamr@2
     1
// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
williamr@2
     2
// All rights reserved.
williamr@2
     3
// This component and the accompanying materials are made available
williamr@4
     4
// under the terms of "Eclipse Public License v1.0"
williamr@2
     5
// which accompanies this distribution, and is available
williamr@4
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
williamr@2
     7
//
williamr@2
     8
// Initial Contributors:
williamr@2
     9
// Nokia Corporation - initial contribution.
williamr@2
    10
//
williamr@2
    11
// Contributors:
williamr@2
    12
//
williamr@2
    13
// Description:
williamr@2
    14
// Written by Brendan, Dec 1996
williamr@2
    15
// Library associated files for pluggable components
williamr@2
    16
// 
williamr@2
    17
//
williamr@2
    18
williamr@2
    19
#if !defined(__LIBASSOC_H__)
williamr@2
    20
#define __LIBASSOC_H__
williamr@2
    21
#if !defined(__F32FILE_H__)
williamr@2
    22
#include <f32file.h>
williamr@2
    23
#endif
williamr@2
    24
williamr@2
    25
williamr@2
    26
williamr@2
    27
williamr@2
    28
class TLibAssocBase
williamr@2
    29
/**
williamr@2
    30
@publishedAll
williamr@2
    31
@released
williamr@2
    32
williamr@2
    33
This is an implementation base class for TLibAssoc.
williamr@2
    34
*/
williamr@2
    35
	{
williamr@2
    36
protected:
williamr@2
    37
	inline TLibAssocBase();
williamr@2
    38
	IMPORT_C TLibAssocBase(const RLibrary& aLib,TAny* aPtr);
williamr@2
    39
	IMPORT_C void Set(const RLibrary& aLib,TAny* aPtr);
williamr@2
    40
	IMPORT_C static void DoUnload(TAny* aThis);
williamr@2
    41
public:
williamr@2
    42
	inline TBool IsNull() const;
williamr@2
    43
private:
williamr@2
    44
	RLibrary iLibrary;
williamr@2
    45
protected:
williamr@2
    46
williamr@2
    47
    /**
williamr@2
    48
    A Pointer to the class instance.
williamr@2
    49
    */
williamr@2
    50
	TAny* iPtr;
williamr@2
    51
	};
williamr@2
    52
williamr@2
    53
williamr@2
    54
williamr@2
    55
williamr@2
    56
//	class TLibAssoc inlines
williamr@2
    57
inline TLibAssocBase::TLibAssocBase()
williamr@2
    58
	: iPtr(NULL)
williamr@2
    59
/**
williamr@2
    60
Default constructor.
williamr@2
    61
williamr@2
    62
It sets the member TLibAssocBase::iPtr to NULL.
williamr@2
    63
*/	
williamr@2
    64
	{}
williamr@2
    65
williamr@2
    66
williamr@2
    67
williamr@2
    68
williamr@2
    69
inline TBool TLibAssocBase::IsNull() const
williamr@2
    70
/**
williamr@2
    71
Tests whether the pointer to the class instance is NULL.
williamr@2
    72
williamr@2
    73
@return ETrue, if the pointer is NULL; EFalse, otherwise.
williamr@2
    74
*/
williamr@2
    75
	{return iPtr==NULL;}
williamr@2
    76
williamr@2
    77
williamr@2
    78
//
williamr@2
    79
//	class TLibAssoc
williamr@2
    80
//
williamr@2
    81
template <class T>
williamr@2
    82
class TLibAssoc : public TLibAssocBase
williamr@2
    83
/**
williamr@2
    84
@publishedAll
williamr@2
    85
@released
williamr@2
    86
williamr@2
    87
Associates a dynamically loadable DLL and an instance of a class that,
williamr@2
    88
typically, will have been created using the ordinal 1 function of that DLL.
williamr@2
    89
williamr@2
    90
An object of this type is useful when cleanup behaviour requires that
williamr@2
    91
a class instance be deleted and the associated DLL be closed.
williamr@2
    92
williamr@2
    93
The DLL is expected to be already open when the TLibAssoc object is created.
williamr@2
    94
*/
williamr@2
    95
	{
williamr@2
    96
public:
williamr@2
    97
	inline TLibAssoc();
williamr@2
    98
	inline TLibAssoc(const RLibrary& aLib,T* aClass);
williamr@2
    99
	inline void Set(const RLibrary& aLib,T* aClass);
williamr@2
   100
	//
williamr@2
   101
	inline void Unload();
williamr@2
   102
	//
williamr@2
   103
	inline operator TCleanupItem();
williamr@2
   104
	operator TLibAssoc*(); // undefined, but here to prevent accidental delete(TLibAssoc)
williamr@2
   105
	//
williamr@2
   106
	inline T* Ptr();
williamr@2
   107
	inline const T* PtrC() const;
williamr@2
   108
	//
williamr@2
   109
	inline operator T*();
williamr@2
   110
	inline operator const T*() const;
williamr@2
   111
	//
williamr@2
   112
	inline T* operator->();
williamr@2
   113
	inline const T* operator->() const;
williamr@2
   114
private:
williamr@2
   115
	static void Cleanup(TAny* aThis); // for TCleanupOperation
williamr@2
   116
	};
williamr@2
   117
williamr@2
   118
williamr@2
   119
williamr@2
   120
williamr@2
   121
template <class T>
williamr@2
   122
inline TLibAssoc<T>::TLibAssoc()
williamr@2
   123
/**
williamr@2
   124
Default constructor.
williamr@2
   125
williamr@2
   126
An association between a DLL and a class instance can be made
williamr@2
   127
after construction using the Set() function.
williamr@2
   128
*/
williamr@2
   129
	{}
williamr@2
   130
williamr@2
   131
williamr@2
   132
williamr@2
   133
template <class T>
williamr@2
   134
inline TLibAssoc<T>::TLibAssoc(const RLibrary& aLib,T* aClass)
williamr@2
   135
	: TLibAssocBase(aLib,aClass)
williamr@2
   136
/**
williamr@2
   137
Constructs the object taking the specified DLL and an instance of
williamr@2
   138
the specified class.
williamr@2
   139
williamr@2
   140
@param aLib   A reference to a DLL that has already been opened.
williamr@2
   141
@param aClass A pointer to an object to be associated with the DLL.
williamr@2
   142
              Typically, this object will have been created using
williamr@2
   143
              the ordinal 1 function from that DLL.
williamr@2
   144
*/	
williamr@2
   145
	{}
williamr@2
   146
williamr@2
   147
williamr@2
   148
williamr@2
   149
williamr@2
   150
template <class T>
williamr@2
   151
inline void TLibAssoc<T>::Set(const RLibrary& aLib,T* aClass)
williamr@2
   152
/**
williamr@2
   153
Makes an association between the specified DLL and an instance of
williamr@2
   154
the specified class.
williamr@2
   155
williamr@2
   156
@param aLib   A reference to a DLL that has already been opened.
williamr@2
   157
@param aClass A pointer to an object to be associated with the DLL.
williamr@2
   158
              Typically, this object will have been created using
williamr@2
   159
              the ordinal 1 function from that DLL.
williamr@2
   160
*/
williamr@2
   161
	{TLibAssocBase::Set(aLib,aClass);}
williamr@2
   162
williamr@2
   163
williamr@2
   164
williamr@2
   165
williamr@2
   166
template <class T>
williamr@2
   167
inline T* TLibAssoc<T>::Ptr()
williamr@2
   168
/**
williamr@2
   169
Gets a pointer to the class instance.
williamr@2
   170
williamr@2
   171
@return A pointer to the class instance.
williamr@2
   172
*/
williamr@2
   173
	{return (T*)iPtr;}
williamr@2
   174
williamr@2
   175
williamr@2
   176
williamr@2
   177
williamr@2
   178
template <class T>
williamr@2
   179
inline const T* TLibAssoc<T>::PtrC() const
williamr@2
   180
/**
williamr@2
   181
Gets a pointer to the const class instance.
williamr@2
   182
williamr@2
   183
@return A pointer to the const class instance.
williamr@2
   184
*/
williamr@2
   185
	{return (const T*)iPtr;}
williamr@2
   186
williamr@2
   187
williamr@2
   188
williamr@2
   189
williamr@2
   190
template <class T>
williamr@2
   191
inline TLibAssoc<T>::operator T*()
williamr@2
   192
/**
williamr@2
   193
Conversion operator.
williamr@2
   194
williamr@2
   195
Invoked by the compiler when a TLibAssoc<T> type is passed to a function that
williamr@2
   196
is prototyped to take a T* type.
williamr@2
   197
*/
williamr@2
   198
	{return (T*)iPtr;}
williamr@2
   199
williamr@2
   200
williamr@2
   201
williamr@2
   202
williamr@2
   203
template <class T>
williamr@2
   204
inline TLibAssoc<T>::operator const T*() const
williamr@2
   205
/**
williamr@2
   206
Const conversion operator.
williamr@2
   207
williamr@2
   208
Invoked by the compiler when a TLibAssoc<T> type is passed to a function that
williamr@2
   209
is prototyped to take a const T* type.
williamr@2
   210
*/
williamr@2
   211
	{return (const T*)iPtr;}
williamr@2
   212
williamr@2
   213
williamr@2
   214
williamr@2
   215
williamr@2
   216
template <class T>
williamr@2
   217
inline T* TLibAssoc<T>::operator->()
williamr@2
   218
/**
williamr@2
   219
Dereferencing operator.
williamr@2
   220
williamr@2
   221
@return A pointer to the class instance.
williamr@2
   222
*/
williamr@2
   223
	{return (T*)iPtr;}
williamr@2
   224
williamr@2
   225
williamr@2
   226
williamr@2
   227
williamr@2
   228
template <class T>
williamr@2
   229
inline const T* TLibAssoc<T>::operator->() const
williamr@2
   230
/**
williamr@2
   231
Const dereferencing operator.
williamr@2
   232
williamr@2
   233
@return A pointer to the const class instance.
williamr@2
   234
*/
williamr@2
   235
	{return (const T*)iPtr;}
williamr@2
   236
williamr@2
   237
williamr@2
   238
williamr@2
   239
williamr@2
   240
template <class T>
williamr@2
   241
inline TLibAssoc<T>::operator TCleanupItem()
williamr@2
   242
/**
williamr@2
   243
The TCleanupItem conversion operator.
williamr@2
   244
williamr@2
   245
Invoked by the compiler when a TLibAssoc<T> type is passed to a function that
williamr@2
   246
is prototyped to take a TCleanupItem type.
williamr@2
   247
williamr@2
   248
The most common usage is to put a cleanup item onto the cleanup stack using
williamr@2
   249
CleanupStack::PushL(). The cleanup operation is represented by the private
williamr@2
   250
static function Cleanup().
williamr@2
   251
williamr@2
   252
For example, if we declare
williamr@2
   253
williamr@2
   254
@code
williamr@2
   255
TLibAssoc<A> a;
williamr@2
   256
@endcode 
williamr@2
   257
williamr@2
   258
then we can simply put a cleanup item onto the cleanup stack
williamr@2
   259
by calling
williamr@2
   260
williamr@2
   261
@code
williamr@2
   262
CleanupStack::PushL(a);
williamr@2
   263
@endcode
williamr@2
   264
williamr@2
   265
@see TCleanupItem
williamr@2
   266
@see CleanupStack::PushL
williamr@2
   267
*/
williamr@2
   268
	{return(TCleanupItem(Cleanup,this));}
williamr@2
   269
williamr@2
   270
williamr@2
   271
williamr@2
   272
williamr@2
   273
template <class T>
williamr@2
   274
inline void TLibAssoc<T>::Unload()
williamr@2
   275
/**
williamr@2
   276
Deletes the class instance and calls Close() on the associated DLL.
williamr@2
   277
williamr@2
   278
@see RLibrary::Close
williamr@2
   279
*/
williamr@2
   280
	{Cleanup(this);}
williamr@2
   281
williamr@2
   282
williamr@2
   283
williamr@2
   284
williamr@2
   285
template <class T>
williamr@2
   286
void TLibAssoc<T>::Cleanup(TAny* aThis)
williamr@2
   287
/**
williamr@2
   288
The cleanup operation.
williamr@2
   289
williamr@2
   290
The implementation deletes the class instance and calls Close() on
williamr@2
   291
the associated DLL.
williamr@2
   292
williamr@2
   293
Note that this function is internal and is not intended for use; it is documented
williamr@2
   294
for completeness.
williamr@2
   295
*/
williamr@2
   296
	{
williamr@2
   297
	delete (T*)(((TLibAssoc<T>*)aThis)->iPtr);
williamr@2
   298
	TLibAssocBase::DoUnload(aThis);
williamr@2
   299
	}
williamr@2
   300
williamr@2
   301
#endif