os/persistentdata/persistentstorage/store/INC/S32STD.H
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/store/INC/S32STD.H	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,387 @@
     1.4 +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#if !defined(__S32STD_H__)
    1.20 +#define __S32STD_H__
    1.21 +#if !defined(__S32STRM_H__)
    1.22 +#include <s32strm.h>
    1.23 +#endif
    1.24 +
    1.25 +/** The value of the null stream ID. */
    1.26 +const TUint32 KNullStreamIdValue=0;
    1.27 +const TUint32 KMaxStreamIdValue=0xfffffff;
    1.28 +const TUint32 KMaskStreamIdValue=0xfffffff;
    1.29 +const TInt KShiftStreamIdValue=28;
    1.30 +
    1.31 +/**
    1.32 + * @publishedAll 
    1.33 + * @released
    1.34 + * Provides unique identification for stream within a store.
    1.35 +
    1.36 +A store always assigns a new id and constructs and returns an associated TStreamId 
    1.37 +object when a new stream is created.
    1.38 +
    1.39 +@see RStoreWriteStream::CreateL()
    1.40 +@see RStoreWriteStream::CreateLC()  
    1.41 +*/
    1.42 +class TStreamId
    1.43 +	{
    1.44 +public:
    1.45 +	/** Constructs an uninitialised object. It is necessary because there are also 
    1.46 +	non-default constructors in this class. */
    1.47 +	TStreamId() {}
    1.48 +	inline TStreamId(TUint32 aValue);
    1.49 +//
    1.50 +	inline TBool operator==(TStreamId anId) const;
    1.51 +	inline TBool operator!=(TStreamId anId) const;
    1.52 +//
    1.53 +	inline void ExternalizeL(RWriteStream& aStream) const;
    1.54 +	IMPORT_C void InternalizeL(RReadStream& aStream);
    1.55 +//
    1.56 +	inline TUint32 Value() const;
    1.57 +private:
    1.58 +	TUint32 iVal;
    1.59 +private:
    1.60 +	IMPORT_C static void __DbgChkRange(TUint32 aValue);
    1.61 +	};
    1.62 +#if defined(__NO_CLASS_CONSTS__)
    1.63 +#define KNullStreamId TStreamId(KNullStreamIdValue)
    1.64 +#else
    1.65 +/** The null stream ID; this is a stream ID which is guaranteed not to exist. */
    1.66 +const TStreamId KNullStreamId=TStreamId(KNullStreamIdValue);
    1.67 +#endif
    1.68 +//
    1.69 +class CStreamStore;
    1.70 +
    1.71 +/**
    1.72 + * @publishedAll 
    1.73 + * @released
    1.74 + * Supports the opening and manipulation of an existing stream in a store.  
    1.75 +*/
    1.76 +class RStoreReadStream : public RReadStream
    1.77 +	{
    1.78 +public:
    1.79 +	IMPORT_C void OpenL(const CStreamStore& aStore,TStreamId anId);
    1.80 +	IMPORT_C void OpenLC(const CStreamStore& aStore,TStreamId anId);
    1.81 +	};
    1.82 +
    1.83 +/**
    1.84 + * @publishedAll 
    1.85 + * @released
    1.86 + * Supports the writing of a stream to a store.
    1.87 +
    1.88 +The class allows:
    1.89 +
    1.90 +creation of a new stream
    1.91 +
    1.92 +overwriting of an existing stream
    1.93 +
    1.94 +replacement of an existing stream
    1.95 +
    1.96 +appending to an existing stream 
    1.97 +*/
    1.98 +class RStoreWriteStream : public RWriteStream
    1.99 +	{
   1.100 +public:
   1.101 +	/** Constructs an uninitialised object. It is necessary because there are also 
   1.102 +	non-default constructors in this class. */
   1.103 +	RStoreWriteStream() {}
   1.104 +	inline RStoreWriteStream(const MExternalizer<TStreamRef>& anExter);
   1.105 +	IMPORT_C TStreamId CreateL(CStreamStore& aStore);
   1.106 +	IMPORT_C TStreamId CreateLC(CStreamStore& aStore);
   1.107 +	IMPORT_C void OpenL(CStreamStore& aStore,TStreamId anId);
   1.108 +	IMPORT_C void OpenLC(CStreamStore& aStore,TStreamId anId);
   1.109 +	IMPORT_C void ReplaceL(CStreamStore& aStore,TStreamId anId);
   1.110 +	IMPORT_C void ReplaceLC(CStreamStore& aStore,TStreamId anId);
   1.111 +	IMPORT_C void AppendL(CStreamStore& aStore,TStreamId anId);
   1.112 +	IMPORT_C void AppendLC(CStreamStore& aStore,TStreamId anId);
   1.113 +	};
   1.114 +
   1.115 +/**
   1.116 + * @publishedAll 
   1.117 + * @released
   1.118 + * Base class for swizzles.
   1.119 +
   1.120 +A swizzle maintains a dual representation for an object:
   1.121 +
   1.122 +by stream id, if the object is not in memory (the stream contains the external 
   1.123 +representation of that object).
   1.124 +
   1.125 +by pointer, if the object is in memory.
   1.126 +
   1.127 +The class is not intended for instantiation. 
   1.128 +*/
   1.129 +class TSwizzleCBase
   1.130 +	{
   1.131 +public:
   1.132 +	inline TBool operator==(const TSwizzleCBase& aSwizzle) const;
   1.133 +	inline TBool operator==(const TAny* aPtr) const;
   1.134 +	inline TBool operator!=(const TSwizzleCBase& aSwizzle) const;
   1.135 +	inline TBool operator!=(const TAny* aPtr) const;
   1.136 +//
   1.137 +	inline TBool IsPtr() const;
   1.138 +	inline TBool IsId() const;
   1.139 +	IMPORT_C TStreamId AsId() const;
   1.140 +	IMPORT_C void InternalizeL(RReadStream& aStream);
   1.141 +protected:
   1.142 +	TSwizzleCBase() {}
   1.143 +	inline TSwizzleCBase(const TAny* aPtr);
   1.144 +	IMPORT_C TSwizzleCBase(TStreamId anId);
   1.145 +	inline TSwizzleCBase(TStreamRef aRef);
   1.146 +	inline const TAny* Ptr() const;
   1.147 +	IMPORT_C void DoExternalizeL(RWriteStream& aStream,TExternalizer<TAny> anExter) const;
   1.148 +private:
   1.149 +	IMPORT_C static TBool IsPtrRep(const TAny* aPtr);
   1.150 +	IMPORT_C static TBool IsIdRep(const TAny* aPtr);
   1.151 +private:
   1.152 +	const TAny* iPtr;
   1.153 +private:
   1.154 +	IMPORT_C static void __DbgChkPtr(const TAny* aPtr);
   1.155 +	IMPORT_C static void __DbgChkRef(TStreamRef aRef);
   1.156 +	};
   1.157 +inline TBool operator==(const TAny* aPtr,const TSwizzleCBase& aSwizzle);
   1.158 +inline TBool operator!=(const TAny* aPtr,const TSwizzleCBase& aSwizzle);
   1.159 +
   1.160 +/**
   1.161 + * @publishedAll 
   1.162 + * @released
   1.163 + * Implementation class for swizzles.
   1.164 +
   1.165 +Although part of the class hierarchy, no function or data members in this 
   1.166 +class form part of the public application programming interface.
   1.167 +
   1.168 +The class is not intended for instantiation.
   1.169 +
   1.170 +@see TSwizzle  
   1.171 +*/
   1.172 +class TSwizzleBase : public TSwizzleCBase
   1.173 +	{
   1.174 +protected:
   1.175 +	TSwizzleBase() {}
   1.176 +	inline TSwizzleBase(TAny* aPtr);
   1.177 +	inline TSwizzleBase(TStreamId anId);
   1.178 +	inline TAny* Ptr() const;
   1.179 +	};
   1.180 +
   1.181 +/**
   1.182 + * @publishedAll 
   1.183 + * @released
   1.184 + * Maintains a dual representation for an object. The representation is:
   1.185 +
   1.186 +by stream id, if the object is not in memory (the stream contains the external 
   1.187 +representation of that object).
   1.188 +
   1.189 +by pointer, if the object is in memory.
   1.190 +
   1.191 +The template class defines the type of object for which the swizzle is a representation. 
   1.192 +Full access to the represented object is available through the swizzle.
   1.193 +
   1.194 +Maintaining a dual representation for an object allows the loading of objects 
   1.195 +into memory from a store to be deferred; this is particularly important in 
   1.196 +complex applications. 
   1.197 +*/
   1.198 +template <class T>
   1.199 +class TSwizzle : public TSwizzleBase
   1.200 +	{
   1.201 +public:
   1.202 +	/** Constructs an uninitialised swizzle. It is necessary because there are also 
   1.203 +	non-default constructors in this class. */
   1.204 +	TSwizzle() {}
   1.205 +	inline TSwizzle(T* aPtr);
   1.206 +	inline TSwizzle(TStreamId anId);
   1.207 +	inline TSwizzle<T>& operator=(T* aPtr);
   1.208 +	inline T* AsPtr() const;
   1.209 +	inline operator T*() const;
   1.210 +	inline T& operator*() const;
   1.211 +	inline T* operator->() const;
   1.212 +	inline void ExternalizeL(RWriteStream& aStream) const;
   1.213 +	};
   1.214 +
   1.215 +/**
   1.216 + * @publishedAll 
   1.217 + * @released
   1.218 + * A specific instantiation of the family of TSwizzle<class T> classes that maintains 
   1.219 +the representation of an untyped object as a non-const pointer or as a stream 
   1.220 +id.  
   1.221 +*/
   1.222 +TEMPLATE_SPECIALIZATION class TSwizzle<TAny> : public TSwizzleBase
   1.223 +	{
   1.224 +public:
   1.225 +	/** Default constructor.
   1.226 +	
   1.227 +	Constructs an uninitialised swizzle. */
   1.228 +	TSwizzle() {}
   1.229 +	inline TSwizzle(TAny* aPtr);
   1.230 +	inline TSwizzle(TStreamId anId);
   1.231 +	inline TSwizzle(const TSwizzleBase& aSwizzle);
   1.232 +	inline TSwizzle<TAny>& operator=(TAny* aPtr);
   1.233 +	inline TSwizzle<TAny>& operator=(const TSwizzleBase& aSwizzle);
   1.234 +	inline TAny* AsPtr() const;
   1.235 +	inline operator TAny*() const;
   1.236 +	};
   1.237 +
   1.238 +/**
   1.239 + * @publishedAll 
   1.240 + * @released
   1.241 + * Maintains a dual representation for a constant object. The representation is:
   1.242 +
   1.243 +by stream id, if the object is not in memory (the stream contains the external 
   1.244 +representation of that object).
   1.245 +
   1.246 +by pointer, if the object is in memory.
   1.247 +
   1.248 +The template class defines the type of object for which the swizzle is a representation. 
   1.249 +Access to the to the represented object is available through the swizzle, 
   1.250 +but is limited. The represented object cannot be changed.
   1.251 +
   1.252 +Maintaining a dual representation for an object allows the loading of objects 
   1.253 +into memory from a store to be deferred; this is particularly important in 
   1.254 +complex applications.  
   1.255 +*/
   1.256 +template <class T>
   1.257 +class TSwizzleC : public TSwizzleCBase
   1.258 +	{
   1.259 +public:
   1.260 +	/** Constructs an uninitialised swizzle. It is necessary because there are also 
   1.261 +	non-default constructors in this class. */
   1.262 +	TSwizzleC() {}
   1.263 +	inline TSwizzleC(const T* aPtr);
   1.264 +	inline TSwizzleC(TStreamId anId);
   1.265 +	inline TSwizzleC(TSwizzle<T> aSwizzle);
   1.266 +	inline TSwizzleC<T>& operator=(const T* aPtr);
   1.267 +	inline const T* AsPtr() const;
   1.268 +	inline operator const T*() const;
   1.269 +	inline const T& operator*() const;
   1.270 +	inline const T* operator->() const;
   1.271 +	inline void ExternalizeL(RWriteStream& aStream) const;
   1.272 +	};
   1.273 +
   1.274 +/**
   1.275 + * @publishedAll 
   1.276 + * @released
   1.277 + * A specific instantiation of the family of TSwizzleC<class T> classes that maintains 
   1.278 +the representation of an untyped object as a const pointer or as a stream id. 
   1.279 +*/
   1.280 +TEMPLATE_SPECIALIZATION class TSwizzleC<TAny> : public TSwizzleCBase
   1.281 +	{
   1.282 +public:
   1.283 +	/** Default constructor.
   1.284 +	
   1.285 +	Constructs an uninitialised swizzle. */
   1.286 +	TSwizzleC() {}
   1.287 +	inline TSwizzleC(const TAny* aPtr);
   1.288 +	inline TSwizzleC(TStreamId anId);
   1.289 +	inline TSwizzleC(const TSwizzleCBase& aSwizzle);
   1.290 +	inline TSwizzleC(TStreamRef aRef);
   1.291 +	inline TSwizzleC<TAny>& operator=(const TAny* aPtr);
   1.292 +	inline TSwizzleC<TAny>& operator=(const TSwizzleCBase& aSwizzle);
   1.293 +	inline const TAny* AsPtr() const;
   1.294 +	inline operator const TAny*() const;
   1.295 +	};
   1.296 +
   1.297 +/**
   1.298 + * @publishedAll 
   1.299 + * @released
   1.300 + * Store map used when externalising swizzled in-memory objects. 
   1.301 +
   1.302 +It has three main characteristics:
   1.303 +
   1.304 +it acts as an in-memory repository of stream ids and associated swizzles 
   1.305 +
   1.306 +it acts as an externaliser for swizzles 
   1.307 +
   1.308 +it offers cleanup support  
   1.309 +*/
   1.310 +class CStoreMap : public CBase,public MExternalizer<TStreamRef>
   1.311 +	{
   1.312 +public:
   1.313 +	/**
   1.314 +	 * @publishedAll 
   1.315 +	 * @released
   1.316 +	 */
   1.317 +	struct TEntry {TSwizzleC<TAny> swizzle;TStreamId id;};
   1.318 +	typedef const TEntry* TIterator;
   1.319 +public:
   1.320 +	IMPORT_C static CStoreMap* NewL(CStreamStore& aStore);
   1.321 +	IMPORT_C static CStoreMap* NewLC(CStreamStore& aStore);
   1.322 +	IMPORT_C CStoreMap(CStreamStore& aStore);
   1.323 +	IMPORT_C ~CStoreMap();
   1.324 +//
   1.325 +	IMPORT_C void BindL(TSwizzleC<TAny> aSwizzle,TStreamId anId);
   1.326 +	IMPORT_C void Unbind(TSwizzleC<TAny> aSwizzle);
   1.327 +	IMPORT_C void Forget(TStreamId anId);
   1.328 +	IMPORT_C void Reset();
   1.329 +	IMPORT_C void ResetAndDestroy();
   1.330 +//
   1.331 +	IMPORT_C TStreamId At(TSwizzleC<TAny> aSwizzle) const;
   1.332 +	IMPORT_C TSwizzleC<TAny> Label(TStreamId anId) const;
   1.333 +	IMPORT_C TIterator Begin() const;
   1.334 +	IMPORT_C TIterator End() const;
   1.335 +private:
   1.336 +	void ExternalizeL(const TStreamRef& aRef,RWriteStream& aStream) const;
   1.337 +private:
   1.338 +	CArrayFixFlat<TEntry> iArray;
   1.339 +	TStreamId iFree;
   1.340 +	CStreamStore* iStore;
   1.341 +	};
   1.342 +
   1.343 +/**
   1.344 + * @publishedAll 
   1.345 + * @released
   1.346 + * Maintains two way associations between a UID (a TUid type) and a stream id 
   1.347 +(a TStreamId type) .
   1.348 +
   1.349 +Each UID and stream id pair forms an entry in an array. The class provides 
   1.350 +member functions to manage these entries, for example, to add a new entry 
   1.351 +or to change the stream id associated with a UID.
   1.352 +
   1.353 +@see TUid
   1.354 +@see TStreamId
   1.355 +@see CDictionaryStore 
   1.356 + */
   1.357 +class CStreamDictionary : public CBase
   1.358 +	{
   1.359 +public:
   1.360 +	IMPORT_C static CStreamDictionary* NewL();
   1.361 +	IMPORT_C static CStreamDictionary* NewLC();
   1.362 +	IMPORT_C CStreamDictionary();
   1.363 +	IMPORT_C ~CStreamDictionary();
   1.364 +//
   1.365 +	IMPORT_C void AssignL(TUid aUid,TStreamId anId);
   1.366 +	IMPORT_C void Remove(TUid aUid);
   1.367 +	IMPORT_C TStreamId At(TUid aUid) const;
   1.368 +	IMPORT_C TBool IsNull() const;
   1.369 +	//
   1.370 +	IMPORT_C void ExternalizeL(RWriteStream& aStream) const;
   1.371 +	IMPORT_C void InternalizeL(RReadStream& aStream);
   1.372 +private:
   1.373 +	
   1.374 +	class TEntry
   1.375 +		{
   1.376 +	public:
   1.377 +		TEntry() {}
   1.378 +		inline TEntry(TUid aUid,TStreamId anId);
   1.379 +		void ExternalizeL(RWriteStream& aStream) const;
   1.380 +		void InternalizeL(RReadStream& aStream);
   1.381 +	public:
   1.382 +		TUid iUid;
   1.383 +		TStreamId iId;
   1.384 +		};
   1.385 +private:
   1.386 +	CArrayFixSeg<TEntry> iArray;
   1.387 +	};
   1.388 +
   1.389 +#include <s32std.inl>
   1.390 +#endif