epoc32/include/s32strm.h
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
child 4 837f303aceeb
equal deleted inserted replaced
1:666f914201fb 2:2fe1408b6811
     1 s32strm.h
     1 // Copyright (c) 1998-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 //
       
    15 
       
    16 #if !defined(__S32STRM_H__)
       
    17 #define __S32STRM_H__
       
    18 #if !defined(__E32BASE_H__)
       
    19 #include <e32base.h>
       
    20 #endif
       
    21 
       
    22 /** The largest integer value which can be stored as a TCardinality type. */
       
    23 const TInt KMaxCardinality=0x1fffffff;
       
    24 //
       
    25 class MStreamBuf;
       
    26 class RWriteStream;
       
    27 
       
    28 /**
       
    29  * @publishedAll 
       
    30  * @released
       
    31  * The read stream interface. The process of internalising from a stream is 
       
    32 achieved through a reference to an object of this type.
       
    33 
       
    34 A store aware class defines an implements an InternalizeL() member function 
       
    35 which is used to internalise that object and takes a reference to an 
       
    36 RReadStream as the interface to the read stream. 
       
    37 */
       
    38 class RReadStream
       
    39 	{
       
    40 public:
       
    41 	inline RReadStream();
       
    42 	inline RReadStream(MStreamBuf* aSource);
       
    43 	inline MStreamBuf* Source();
       
    44 	inline void Close();
       
    45 	IMPORT_C void Release();
       
    46 //
       
    47 	IMPORT_C void PushL();
       
    48 	inline void Pop();
       
    49 //
       
    50 	IMPORT_C void ReadL(TDes8& aDes);
       
    51 	IMPORT_C void ReadL(TDes8& aDes,TInt aLength);
       
    52 	IMPORT_C void ReadL(TDes8& aDes,TChar aDelim);
       
    53 	IMPORT_C void ReadL(TUint8* aPtr,TInt aLength);
       
    54 	IMPORT_C void ReadL(TInt aLength);
       
    55 	inline void ReadL(RWriteStream& aStream);
       
    56 	inline void ReadL(RWriteStream& aStream,TInt aLength);
       
    57 //
       
    58 	IMPORT_C void ReadL(TDes16& aDes);
       
    59 	IMPORT_C void ReadL(TDes16& aDes,TInt aLength);
       
    60 	IMPORT_C void ReadL(TDes16& aDes,TChar aDelim);
       
    61 	IMPORT_C void ReadL(TUint16* aPtr,TInt aLength);
       
    62 //
       
    63 	IMPORT_C TInt8 ReadInt8L();
       
    64 	IMPORT_C TInt16 ReadInt16L();
       
    65 	IMPORT_C TInt32 ReadInt32L();
       
    66 	IMPORT_C TUint8 ReadUint8L();
       
    67 	IMPORT_C TUint16 ReadUint16L();
       
    68 	IMPORT_C TUint32 ReadUint32L();
       
    69 	IMPORT_C TReal32 ReadReal32L() __SOFTFP;
       
    70 	IMPORT_C TReal64 ReadReal64L() __SOFTFP;
       
    71 protected:
       
    72 	inline void Attach(MStreamBuf* aSource);
       
    73 	inline void Detach();
       
    74 private:
       
    75 	MStreamBuf* iSrc;
       
    76 private:
       
    77 	friend class RWriteStream;
       
    78 	};
       
    79 template <class T>
       
    80 class MExternalizer;
       
    81 class TStreamRef;
       
    82 
       
    83 /**
       
    84  * @publishedAll 
       
    85  * @released
       
    86  * The write stream interface. The process of externalising to a stream is 
       
    87 achieved through a reference to an object of this type.
       
    88 
       
    89 A store aware class defines and implements an ExternalizeL() member function 
       
    90 which is used to externalise that object and takes a reference to an 
       
    91 RWriteStream as the interface to the write stream. 
       
    92 */
       
    93 class RWriteStream
       
    94 	{
       
    95 public:
       
    96 	inline RWriteStream();
       
    97 	inline RWriteStream(const MExternalizer<TStreamRef>& anExter);
       
    98 	inline RWriteStream(MStreamBuf* aSink);
       
    99 	inline MStreamBuf* Sink();
       
   100 	IMPORT_C void Close();
       
   101 	IMPORT_C void Release();
       
   102 	IMPORT_C void CommitL();
       
   103 //
       
   104 	IMPORT_C void PushL();
       
   105 	inline void Pop();
       
   106 //
       
   107 	IMPORT_C void WriteL(const TDesC8& aDes);
       
   108 	IMPORT_C void WriteL(const TDesC8& aDes,TInt aLength);
       
   109 	IMPORT_C void WriteL(const TUint8* aPtr,TInt aLength);
       
   110 	IMPORT_C void WriteL(RReadStream& aStream);
       
   111 	IMPORT_C void WriteL(RReadStream& aStream,TInt aLength);
       
   112 //
       
   113 	IMPORT_C void WriteL(const TDesC16& aDes);
       
   114 	IMPORT_C void WriteL(const TDesC16& aDes,TInt aLength);
       
   115 	IMPORT_C void WriteL(const TUint16* aPtr,TInt aLength);
       
   116 //
       
   117 	IMPORT_C void WriteInt8L(TInt aValue);
       
   118 	IMPORT_C void WriteInt16L(TInt aValue);
       
   119 	IMPORT_C void WriteInt32L(TInt32 aValue);
       
   120 	IMPORT_C void WriteUint8L(TUint aValue);
       
   121 	IMPORT_C void WriteUint16L(TUint aValue);
       
   122 	IMPORT_C void WriteUint32L(TUint32 aValue);
       
   123 	IMPORT_C void WriteReal32L(TReal aValue) __SOFTFP;
       
   124 	IMPORT_C void WriteReal64L(TReal64 aValue) __SOFTFP;
       
   125 protected:
       
   126 	inline void Attach(MStreamBuf* aSink);
       
   127 	inline void Detach();
       
   128 private:
       
   129 	IMPORT_C void WriteRefL(TStreamRef aRef);
       
   130 private:
       
   131 	MStreamBuf* iSnk;
       
   132 	const MExternalizer<TStreamRef>* iExterL;
       
   133 private:
       
   134 	friend class TStreamRef;
       
   135 	};
       
   136 //
       
   137 template <class T>
       
   138 inline RWriteStream& operator<<(RWriteStream& aStream,const T& anObject);
       
   139 template <class T>
       
   140 inline RReadStream& operator>>(RReadStream& aStream,T& anObject);
       
   141 
       
   142 /**
       
   143  * @publishedAll 
       
   144  * @released
       
   145  * Compact stream format for positive integer values in the range 0 to 
       
   146 536,870,911 ((2^29)-1). Values in the range 0-127 are stored in a single byte, 
       
   147 128-16383 in two bytes and other values in 4 bytes.
       
   148 
       
   149 The class provides conversion to and from TInt, and both externalization and 
       
   150 internalization functions. It is used to significant effect within Symbian 
       
   151 code. 
       
   152 */
       
   153 class TCardinality
       
   154 	{
       
   155 public:
       
   156 	TCardinality() {}
       
   157 	inline TCardinality(TInt aCount);
       
   158 	inline operator TInt() const;
       
   159 //
       
   160 	IMPORT_C void ExternalizeL(RWriteStream& aStream) const;
       
   161 	IMPORT_C void InternalizeL(RReadStream& aStream);
       
   162 private:
       
   163 	TInt iCount;
       
   164 private:
       
   165 	IMPORT_C static void __DbgChkRange(TInt aCount);
       
   166 	};
       
   167 //
       
   168 /** Defines a function type for a function returned by TExternalizer::Function() 
       
   169 and TStreamRef. */
       
   170 typedef void (*TExternalizeFunction)(const TAny* aPtr,RWriteStream& aStream);
       
   171 /** Defines a function type for a function returned by TInternalizer::Function(). */
       
   172 typedef void (*TInternalizeFunction)(TAny* aPtr,RReadStream& aStream);
       
   173 
       
   174 /**
       
   175  * @publishedAll 
       
   176  * @released
       
   177  * A family of classes whose instances can be used to perform externalisation 
       
   178 on behalf of other objects.
       
   179 
       
   180 @see TStreamRef  
       
   181 */
       
   182 template <class T>
       
   183 class TExternalizer
       
   184 	{
       
   185 public:
       
   186 	inline void operator()(const T& anObject,RWriteStream& aStream) const;
       
   187 	inline static TExternalizeFunction Function();
       
   188 private:
       
   189 	static void ExternalizeAsL(const TAny* aPtr,RWriteStream& aStream);
       
   190 	};
       
   191 
       
   192 /**
       
   193  * @publishedAll 
       
   194  * @released
       
   195  * A specific instantiation of the family of TExternalizer<class T> classes whose 
       
   196 instances can be used to perform externalisation on behalf of other untyped 
       
   197 objects. 
       
   198 */
       
   199 TEMPLATE_SPECIALIZATION class TExternalizer<TAny>
       
   200 	{
       
   201 public:
       
   202 	/** Default constructor. */
       
   203 	TExternalizer() {}
       
   204 	
       
   205 	/** Constructs the externaliser with the specified externalisation function.
       
   206 	
       
   207 	@param aFunction The externalisation function. */
       
   208 	inline TExternalizer(TExternalizeFunction aFunction);
       
   209 	inline void operator()(const TAny* aPtr,RWriteStream& aStream) const;
       
   210 	
       
   211 	/** Gets a pointer to the function to be used to perform externalisation.
       
   212 	
       
   213 	@return The externalisation function. */
       
   214 	inline TExternalizeFunction Function() const;
       
   215 private:
       
   216 	TExternalizeFunction iFunc;
       
   217 	};
       
   218 
       
   219 /**
       
   220  * @publishedAll 
       
   221  * @released
       
   222  * A family of classes whose instances can be used to perform internalisation 
       
   223 on behalf of other objects. 
       
   224 */
       
   225 template <class T>
       
   226 class TInternalizer
       
   227 	{
       
   228 public:
       
   229 	inline void operator()(T& anObject,RReadStream& aStream) const;
       
   230 	inline static TInternalizeFunction Function();
       
   231 private:
       
   232 	static void InternalizeAsL(TAny* aPtr,RReadStream& aStream);
       
   233 	};
       
   234 
       
   235 /**
       
   236  * @publishedAll 
       
   237  * @released
       
   238  * A specific instantiation of the family of TInternalizer<class T> classes whose 
       
   239 instances can be used to perform internalisation on behalf of other objects. 
       
   240 */
       
   241 TEMPLATE_SPECIALIZATION class TInternalizer<TAny>
       
   242 	{
       
   243 public:
       
   244 	/** Default constructor. */
       
   245 	TInternalizer() {}
       
   246 	
       
   247 	/** Constructs the internaliser with the specified internalisation function.
       
   248 	
       
   249 	@param aFunction The internalisation function. */
       
   250 	inline TInternalizer(TInternalizeFunction aFunction);
       
   251 	inline void operator()(TAny* aPtr,RReadStream& aStream) const;
       
   252 	
       
   253 	/** Gets a pointer to the function to be used to perform internalisation.
       
   254 	
       
   255 	@return The internalisation function. */
       
   256 	inline TInternalizeFunction Function() const;
       
   257 private:
       
   258 	TInternalizeFunction iFunc;
       
   259 	};
       
   260 
       
   261 /**
       
   262  * @publishedAll 
       
   263  * @released
       
   264  * A family of classes defining an interface that can be implemented by classes 
       
   265 that need to perform externalisation on behalf of others.
       
   266 
       
   267 @see CStoreMap 
       
   268 */
       
   269 template <class T>
       
   270 class MExternalizer
       
   271 	{
       
   272 public:
       
   273 	inline void operator()(const T& anObject,RWriteStream& aStream) const;
       
   274 private:
       
   275 	/** Performs externalisation.
       
   276 	
       
   277 	The function is called by operator().
       
   278 	
       
   279 	@param anObject The object to be externalised.
       
   280 	@param aStream The write stream. */
       
   281 	virtual void ExternalizeL(const T& anObject,RWriteStream& aStream) const=0;
       
   282 	};
       
   283 
       
   284 /**
       
   285  * @publishedAll 
       
   286  * @released
       
   287  * A family of classes defining an interface that can be implemented by classes 
       
   288 that need to perform internalisation on behalf of others.
       
   289 
       
   290 @see CStoreMap 
       
   291 */
       
   292 template <class T>
       
   293 class MInternalizer
       
   294 	{
       
   295 public:
       
   296 	inline void operator()(T& anObject,RReadStream& aStream) const;
       
   297 private:
       
   298 	/** Performs internalisation.
       
   299 	
       
   300 	The function is called by operator().
       
   301 	
       
   302 	@param anObject The object to be the target of the internalisation process.
       
   303 	@param aStream The read stream. */
       
   304 	virtual void InternalizeL(T& anObject,RReadStream& aStream) const=0;
       
   305 	};
       
   306 
       
   307 /**
       
   308  * @publishedAll 
       
   309  * @released
       
   310  * A proxy for perfoming externalisation for classes that do not have an 
       
   311 externalisation member. 
       
   312 */
       
   313 class TStreamRef
       
   314 	{
       
   315 public:
       
   316 	inline TStreamRef(const TAny* aPtr,TExternalizeFunction aFunction);
       
   317 	inline const TAny* Ptr() const;
       
   318 	inline TExternalizeFunction Function() const;
       
   319 //
       
   320 	inline void ExternalizeL(RWriteStream& aStream) const;
       
   321 private:
       
   322 	const TAny* iPtr;
       
   323 	TExternalizeFunction iFunc;
       
   324 	};
       
   325 
       
   326 /**
       
   327  * @publishedAll 
       
   328  * @released
       
   329  * A class whose members are used to distinguish between the two variants of 
       
   330 the Symbian OS internal function DoExternalizeL(). 
       
   331 */
       
   332 class Externalize
       
   333 	{
       
   334 public:
       
   335 	/** Indicates that an object will be externalized by calling its 
       
   336 	ExternalizeL() member. */
       
   337 	class Member {};
       
   338 
       
   339 	/** Indicates that an object will be externalized by calling a global 
       
   340 	ExternalizeL() function. */
       
   341 	class Function {};
       
   342 	};
       
   343 
       
   344 /**
       
   345  * @publishedAll 
       
   346  * @released
       
   347  * A class whose members are used to distinguish between the two variants of 
       
   348 the Symbian OS internal function DoInternalizeL(). 
       
   349 */
       
   350 class Internalize
       
   351 	{
       
   352 public:
       
   353 	/** Indicates that an object will be internalized by calling its 
       
   354 	InternalizeL() member. */
       
   355 	class Member {};
       
   356 
       
   357 	/** Indicates that an object will be internalized by calling a global 
       
   358 	InternalizeL() function. */
       
   359 	class Function {};
       
   360 	};
       
   361 
       
   362 #include <s32strm.inl>
       
   363 #endif