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