|
1 /* |
|
2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef __RCOFSTRM_H__ |
|
20 #define __RCOFSTRM_H__ |
|
21 |
|
22 #if defined(__VC32__) && !defined(__MSVCDOTNET__) |
|
23 #pragma warning( disable : 4710 ) // function not inlined |
|
24 #endif |
|
25 |
|
26 #if defined(__MSVCDOTNET__) || defined(__TOOLS2__) |
|
27 #include <fstream> |
|
28 using std::ofstream; |
|
29 #else //!__MSVCDOTNET__ |
|
30 #include <fstream.h> |
|
31 #endif //__MSVCDOTNET__ |
|
32 |
|
33 #include "ASTRING.H" |
|
34 #include "NUMVAL.H" |
|
35 #include "ARRAY.H" |
|
36 |
|
37 class RCBinaryStream |
|
38 { |
|
39 public: |
|
40 RCBinaryStream(); |
|
41 ~RCBinaryStream(); |
|
42 void OpenForAppend(const String& aFileName); |
|
43 int IsOpen(); |
|
44 RCBinaryStream& operator<<(char aChar); |
|
45 RCBinaryStream& operator<<(char* aCharPtr); |
|
46 static int SizeOfCompressedInteger(unsigned int aInteger); |
|
47 void WriteCompressedInteger(unsigned int aInteger); |
|
48 void Write(const unsigned char* aCharPtr, unsigned long aCount); |
|
49 unsigned long GetPosition(); |
|
50 void SetPosition(unsigned long NewPosition); |
|
51 private: |
|
52 ofstream iOs; |
|
53 }; |
|
54 |
|
55 class ResourceDataStream // this class knows about resources that contain compressed Unicode - i.e. that each run of alternating compressed-Unicode and other-stuff needs to be preceded by a 1-2 byte run-length |
|
56 { |
|
57 public: |
|
58 ResourceDataStream(); |
|
59 ~ResourceDataStream(); |
|
60 void StartOfBlockWithSizePrefix(DataType aDataTypeOfSizePrefix); // StartOfBlockWithSizePrefix/EndOfBlockWithSizePrefix blocks can be nested |
|
61 void EndOfBlockWithSizePrefix(); |
|
62 void StartOfCompressedUnicodeRun(int aUncompressedUnicodeSizeInBytes, const unsigned char* aUncompressedUnicodeBuffer); // StartOfCompressedUnicodeRun/EndOfCompressedUnicodeRun runs *cannot* be nested |
|
63 void EndOfCompressedUnicodeRun(); |
|
64 void TwoByteAlignmentPoint(); |
|
65 void EnquireStreamPositionWhenKnown(unsigned long& aStreamPosition); |
|
66 void StreamIn(const unsigned char* aBuffer, int aNumberOfBytes); |
|
67 void MakePlaceHolder(int aNumberOfBytes); |
|
68 bool StreamOutReturningWhetherContainsCompressedUnicode(RCBinaryStream& aStream, int& aSizeWhenUncompressed); |
|
69 void Dump(const char* aDumpFile) const; |
|
70 private: |
|
71 enum MarkType |
|
72 { |
|
73 EMarkType_StartOfBlockWithSizePrefix, // uses iOtherData to store the address of the NumericValue of the size-prefix |
|
74 EMarkType_EndOfBlockWithSizePrefix, |
|
75 EMarkType_StartOfCompressedUnicodeRun, // uses iOtherData to store a BinaryBuffer which contains the uncompressed Unicode - a EMarkType_StartOfCompressedUnicodeRun mark is always followed in ResourceDataStream's iArrayOfMarks by a EMarkType_EndOfCompressedUnicodeRun |
|
76 EMarkType_EndOfCompressedUnicodeRun, // uses iOtherData to store the combined size of the run taking into account any extra bytes caused by other marks, e.g. a padding byte caused by a EMarkType_TwoByteAlignmentPoint |
|
77 EMarkType_TwoByteAlignmentPoint, // uses iOtherData to store whether a padding byte is required or not (iOtherData is set to non-zero if it is and zero if it isn't) |
|
78 EMarkType_EnquireStreamPositionWhenKnown // uses iOtherData to store the address of the unsigned long to write the stream-position to |
|
79 }; |
|
80 class BinaryBuffer |
|
81 { |
|
82 public: |
|
83 static BinaryBuffer* New(int aNumberOfBytes, const unsigned char* aBuffer); |
|
84 void Destroy(); |
|
85 inline int NumberOfBytes() const {return iNumberOfBytes;} |
|
86 inline const unsigned char* Buffer() const {return iBuffer;} |
|
87 private: |
|
88 BinaryBuffer(); // defined (as private) but not declared to prevent anyone instantiating this class apart from the static New function |
|
89 private: |
|
90 int iNumberOfBytes; |
|
91 unsigned char iBuffer[1]; |
|
92 }; |
|
93 class Mark : public ArrayItem |
|
94 { |
|
95 public: |
|
96 inline Mark(int aBufferPosition, MarkType aMarkType, unsigned int aOtherData) :iBufferPosition(aBufferPosition), iMarkType(aMarkType), iOtherData(aOtherData) {} |
|
97 public: |
|
98 int iBufferPosition; |
|
99 MarkType iMarkType; |
|
100 unsigned int iOtherData; |
|
101 }; |
|
102 class ArrayOfMarks : public Array |
|
103 { |
|
104 public: |
|
105 inline ArrayOfMarks() {} |
|
106 inline void AppendMark(int aBufferPosition, MarkType aMarkType, unsigned int aOtherData=0xbebebebe) {Add(new Mark(aBufferPosition, aMarkType, aOtherData));} |
|
107 inline void InsertMark(int aIndex, int aBufferPosition, MarkType aMarkType, unsigned int aOtherData=0xbebebebe) {Add(aIndex, new Mark(aBufferPosition, aMarkType, aOtherData));} |
|
108 inline void RemoveMark(int aIndex) {Discard(aIndex);} |
|
109 inline Mark& MarkAt(int aIndex) const {return *(Mark*)(*this)[aIndex];} |
|
110 }; |
|
111 private: |
|
112 void EnsureEnoughSpareBytes(int aNumberOfBytes); |
|
113 int NumberOfBytesToNextMark(int aMarkIndex) const; |
|
114 void ConvertCompressedRunToUncompressed(int aIndexOfStartOfCompressedUnicodeRun); // aIndexOfStartOfCompressedUnicodeRun is an index into iArrayOfMarks |
|
115 private: |
|
116 unsigned char* iBuffer; |
|
117 int iNumberOfBytesAllocated; |
|
118 int iNumberOfBytesUsed; |
|
119 ArrayOfMarks iArrayOfMarks; |
|
120 bool iContainsCompressedUnicode; |
|
121 }; |
|
122 |
|
123 #endif |