1.1 --- a/epoc32/include/baliba.h Tue Nov 24 13:55:44 2009 +0000
1.2 +++ b/epoc32/include/baliba.h Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -1,1 +1,301 @@
1.4 -baliba.h
1.5 +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +// All rights reserved.
1.7 +// This component and the accompanying materials are made available
1.8 +// 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
1.9 +// which accompanies this distribution, and is available
1.10 +// at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
1.11 +//
1.12 +// Initial Contributors:
1.13 +// Nokia Corporation - initial contribution.
1.14 +//
1.15 +// Contributors:
1.16 +//
1.17 +// Description:
1.18 +// Written by Brendan, Dec 1996
1.19 +// Library associated files for pluggable components
1.20 +//
1.21 +//
1.22 +
1.23 +#if !defined(__LIBASSOC_H__)
1.24 +#define __LIBASSOC_H__
1.25 +#if !defined(__F32FILE_H__)
1.26 +#include <f32file.h>
1.27 +#endif
1.28 +
1.29 +
1.30 +
1.31 +
1.32 +class TLibAssocBase
1.33 +/**
1.34 +@publishedAll
1.35 +@released
1.36 +
1.37 +This is an implementation base class for TLibAssoc.
1.38 +*/
1.39 + {
1.40 +protected:
1.41 + inline TLibAssocBase();
1.42 + IMPORT_C TLibAssocBase(const RLibrary& aLib,TAny* aPtr);
1.43 + IMPORT_C void Set(const RLibrary& aLib,TAny* aPtr);
1.44 + IMPORT_C static void DoUnload(TAny* aThis);
1.45 +public:
1.46 + inline TBool IsNull() const;
1.47 +private:
1.48 + RLibrary iLibrary;
1.49 +protected:
1.50 +
1.51 + /**
1.52 + A Pointer to the class instance.
1.53 + */
1.54 + TAny* iPtr;
1.55 + };
1.56 +
1.57 +
1.58 +
1.59 +
1.60 +// class TLibAssoc inlines
1.61 +inline TLibAssocBase::TLibAssocBase()
1.62 + : iPtr(NULL)
1.63 +/**
1.64 +Default constructor.
1.65 +
1.66 +It sets the member TLibAssocBase::iPtr to NULL.
1.67 +*/
1.68 + {}
1.69 +
1.70 +
1.71 +
1.72 +
1.73 +inline TBool TLibAssocBase::IsNull() const
1.74 +/**
1.75 +Tests whether the pointer to the class instance is NULL.
1.76 +
1.77 +@return ETrue, if the pointer is NULL; EFalse, otherwise.
1.78 +*/
1.79 + {return iPtr==NULL;}
1.80 +
1.81 +
1.82 +//
1.83 +// class TLibAssoc
1.84 +//
1.85 +template <class T>
1.86 +class TLibAssoc : public TLibAssocBase
1.87 +/**
1.88 +@publishedAll
1.89 +@released
1.90 +
1.91 +Associates a dynamically loadable DLL and an instance of a class that,
1.92 +typically, will have been created using the ordinal 1 function of that DLL.
1.93 +
1.94 +An object of this type is useful when cleanup behaviour requires that
1.95 +a class instance be deleted and the associated DLL be closed.
1.96 +
1.97 +The DLL is expected to be already open when the TLibAssoc object is created.
1.98 +*/
1.99 + {
1.100 +public:
1.101 + inline TLibAssoc();
1.102 + inline TLibAssoc(const RLibrary& aLib,T* aClass);
1.103 + inline void Set(const RLibrary& aLib,T* aClass);
1.104 + //
1.105 + inline void Unload();
1.106 + //
1.107 + inline operator TCleanupItem();
1.108 + operator TLibAssoc*(); // undefined, but here to prevent accidental delete(TLibAssoc)
1.109 + //
1.110 + inline T* Ptr();
1.111 + inline const T* PtrC() const;
1.112 + //
1.113 + inline operator T*();
1.114 + inline operator const T*() const;
1.115 + //
1.116 + inline T* operator->();
1.117 + inline const T* operator->() const;
1.118 +private:
1.119 + static void Cleanup(TAny* aThis); // for TCleanupOperation
1.120 + };
1.121 +
1.122 +
1.123 +
1.124 +
1.125 +template <class T>
1.126 +inline TLibAssoc<T>::TLibAssoc()
1.127 +/**
1.128 +Default constructor.
1.129 +
1.130 +An association between a DLL and a class instance can be made
1.131 +after construction using the Set() function.
1.132 +*/
1.133 + {}
1.134 +
1.135 +
1.136 +
1.137 +template <class T>
1.138 +inline TLibAssoc<T>::TLibAssoc(const RLibrary& aLib,T* aClass)
1.139 + : TLibAssocBase(aLib,aClass)
1.140 +/**
1.141 +Constructs the object taking the specified DLL and an instance of
1.142 +the specified class.
1.143 +
1.144 +@param aLib A reference to a DLL that has already been opened.
1.145 +@param aClass A pointer to an object to be associated with the DLL.
1.146 + Typically, this object will have been created using
1.147 + the ordinal 1 function from that DLL.
1.148 +*/
1.149 + {}
1.150 +
1.151 +
1.152 +
1.153 +
1.154 +template <class T>
1.155 +inline void TLibAssoc<T>::Set(const RLibrary& aLib,T* aClass)
1.156 +/**
1.157 +Makes an association between the specified DLL and an instance of
1.158 +the specified class.
1.159 +
1.160 +@param aLib A reference to a DLL that has already been opened.
1.161 +@param aClass A pointer to an object to be associated with the DLL.
1.162 + Typically, this object will have been created using
1.163 + the ordinal 1 function from that DLL.
1.164 +*/
1.165 + {TLibAssocBase::Set(aLib,aClass);}
1.166 +
1.167 +
1.168 +
1.169 +
1.170 +template <class T>
1.171 +inline T* TLibAssoc<T>::Ptr()
1.172 +/**
1.173 +Gets a pointer to the class instance.
1.174 +
1.175 +@return A pointer to the class instance.
1.176 +*/
1.177 + {return (T*)iPtr;}
1.178 +
1.179 +
1.180 +
1.181 +
1.182 +template <class T>
1.183 +inline const T* TLibAssoc<T>::PtrC() const
1.184 +/**
1.185 +Gets a pointer to the const class instance.
1.186 +
1.187 +@return A pointer to the const class instance.
1.188 +*/
1.189 + {return (const T*)iPtr;}
1.190 +
1.191 +
1.192 +
1.193 +
1.194 +template <class T>
1.195 +inline TLibAssoc<T>::operator T*()
1.196 +/**
1.197 +Conversion operator.
1.198 +
1.199 +Invoked by the compiler when a TLibAssoc<T> type is passed to a function that
1.200 +is prototyped to take a T* type.
1.201 +*/
1.202 + {return (T*)iPtr;}
1.203 +
1.204 +
1.205 +
1.206 +
1.207 +template <class T>
1.208 +inline TLibAssoc<T>::operator const T*() const
1.209 +/**
1.210 +Const conversion operator.
1.211 +
1.212 +Invoked by the compiler when a TLibAssoc<T> type is passed to a function that
1.213 +is prototyped to take a const T* type.
1.214 +*/
1.215 + {return (const T*)iPtr;}
1.216 +
1.217 +
1.218 +
1.219 +
1.220 +template <class T>
1.221 +inline T* TLibAssoc<T>::operator->()
1.222 +/**
1.223 +Dereferencing operator.
1.224 +
1.225 +@return A pointer to the class instance.
1.226 +*/
1.227 + {return (T*)iPtr;}
1.228 +
1.229 +
1.230 +
1.231 +
1.232 +template <class T>
1.233 +inline const T* TLibAssoc<T>::operator->() const
1.234 +/**
1.235 +Const dereferencing operator.
1.236 +
1.237 +@return A pointer to the const class instance.
1.238 +*/
1.239 + {return (const T*)iPtr;}
1.240 +
1.241 +
1.242 +
1.243 +
1.244 +template <class T>
1.245 +inline TLibAssoc<T>::operator TCleanupItem()
1.246 +/**
1.247 +The TCleanupItem conversion operator.
1.248 +
1.249 +Invoked by the compiler when a TLibAssoc<T> type is passed to a function that
1.250 +is prototyped to take a TCleanupItem type.
1.251 +
1.252 +The most common usage is to put a cleanup item onto the cleanup stack using
1.253 +CleanupStack::PushL(). The cleanup operation is represented by the private
1.254 +static function Cleanup().
1.255 +
1.256 +For example, if we declare
1.257 +
1.258 +@code
1.259 +TLibAssoc<A> a;
1.260 +@endcode
1.261 +
1.262 +then we can simply put a cleanup item onto the cleanup stack
1.263 +by calling
1.264 +
1.265 +@code
1.266 +CleanupStack::PushL(a);
1.267 +@endcode
1.268 +
1.269 +@see TCleanupItem
1.270 +@see CleanupStack::PushL
1.271 +*/
1.272 + {return(TCleanupItem(Cleanup,this));}
1.273 +
1.274 +
1.275 +
1.276 +
1.277 +template <class T>
1.278 +inline void TLibAssoc<T>::Unload()
1.279 +/**
1.280 +Deletes the class instance and calls Close() on the associated DLL.
1.281 +
1.282 +@see RLibrary::Close
1.283 +*/
1.284 + {Cleanup(this);}
1.285 +
1.286 +
1.287 +
1.288 +
1.289 +template <class T>
1.290 +void TLibAssoc<T>::Cleanup(TAny* aThis)
1.291 +/**
1.292 +The cleanup operation.
1.293 +
1.294 +The implementation deletes the class instance and calls Close() on
1.295 +the associated DLL.
1.296 +
1.297 +Note that this function is internal and is not intended for use; it is documented
1.298 +for completeness.
1.299 +*/
1.300 + {
1.301 + delete (T*)(((TLibAssoc<T>*)aThis)->iPtr);
1.302 + TLibAssocBase::DoUnload(aThis);
1.303 + }
1.304 +
1.305 +#endif