author | marvin shi <marvin.shi@nokia.com> |
Wed, 17 Nov 2010 16:47:55 +0800 | |
changeset 696 | 30aa553e9465 |
parent 695 | 46ca13b54f56 |
permissions | -rw-r--r-- |
695
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
1 |
/* |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
2 |
* Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies). |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
3 |
* All rights reserved. |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
4 |
* This component and the accompanying materials are made available |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
5 |
* under the terms of the License "Eclipse Public License v1.0" |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
6 |
* which accompanies this distribution, and is available |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
8 |
* |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
9 |
* Initial Contributors: |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
10 |
* Nokia Corporation - initial contribution. |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
11 |
* |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
12 |
* Contributors: |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
13 |
* |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
14 |
* Description: |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
15 |
* |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
16 |
*/ |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
17 |
|
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
18 |
#include "bsymutil.h" |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
19 |
#include <stdio.h> |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
20 |
|
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
21 |
|
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
22 |
MemoryWriter::MemoryWriter() |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
23 |
{ |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
24 |
iChar = new char[4*MaxSize]; |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
25 |
iOffset = 0; |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
26 |
iTotalSize = 4*MaxSize; |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
27 |
iStringTableStart = 0; |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
28 |
} |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
29 |
MemoryWriter::~MemoryWriter() |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
30 |
{ |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
31 |
delete[] iChar; |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
32 |
} |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
33 |
int MemoryWriter::WriteBytes(const char* pChar, int size) |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
34 |
{ |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
35 |
while(iOffset + size > iTotalSize) |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
36 |
{ |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
37 |
ExtendMemory(); |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
38 |
} |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
39 |
memcpy(iChar + iOffset, pChar, size); |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
40 |
iOffset += size; |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
41 |
return size; |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
42 |
} |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
43 |
TUint32 MemoryWriter::GetOffset() |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
44 |
{ |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
45 |
return iOffset; |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
46 |
} |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
47 |
char* MemoryWriter::GetDataPointer() |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
48 |
{ |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
49 |
return iChar; |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
50 |
} |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
51 |
bool MemoryWriter::ExtendMemory() |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
52 |
{ |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
53 |
char* pTmp = new char[iTotalSize + MaxSize]; |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
54 |
memcpy(pTmp, iChar, iOffset); |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
55 |
delete[] iChar; |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
56 |
iChar = pTmp; |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
57 |
iTotalSize += MaxSize; |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
58 |
return true; |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
59 |
} |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
60 |
bool MemoryWriter::SetOffset(TUint32 aOffset) |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
61 |
{ |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
62 |
while(aOffset > iTotalSize) |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
63 |
{ |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
64 |
ExtendMemory(); |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
65 |
} |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
66 |
iOffset = aOffset; |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
67 |
return true; |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
68 |
} |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
69 |
void MemoryWriter::AddEmptyString() |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
70 |
{ |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
71 |
unsigned char len = 0; |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
72 |
WriteBytes((char *)&len, 1); |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
73 |
} |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
74 |
TUint32 MemoryWriter::AddString(const string& aStr) |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
75 |
{ |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
76 |
TUint32 result = 0; |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
77 |
if(aStr.empty()) |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
78 |
return result; |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
79 |
result = iOffset - iStringTableStart; |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
80 |
int len = aStr.length(); |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
81 |
if(len >= 255) |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
82 |
{ |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
83 |
TUint16 wlen = len; |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
84 |
unsigned char mark = 0xff; |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
85 |
WriteBytes((char*)&mark, 1); |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
86 |
WriteBytes((char*)&wlen, 2); |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
87 |
WriteBytes(aStr.c_str(), len); |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
88 |
} |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
89 |
else |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
90 |
{ |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
91 |
unsigned char clen = len; |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
92 |
WriteBytes((char *)&clen, 1); |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
93 |
WriteBytes(aStr.c_str(), len); |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
94 |
} |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
95 |
return result; |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
96 |
} |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
97 |
TUint32 MemoryWriter::AddScopeName(const string& aStr) |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
98 |
{ |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
99 |
TUint32 result = 0; |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
100 |
if(aStr.empty()) |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
101 |
return result; |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
102 |
if(aStr == iLastScopeName) |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
103 |
{ |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
104 |
return iLastScopeNameOffset; |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
105 |
} |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
106 |
else |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
107 |
{ |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
108 |
iLastScopeName = aStr; |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
109 |
iLastScopeNameOffset = AddString(aStr); |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
110 |
} |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
111 |
return iLastScopeNameOffset; |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
112 |
} |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
113 |
void MemoryWriter::SetStringTableStart(TUint32 aOffset) |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
114 |
{ |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
115 |
iStringTableStart = aOffset; |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
116 |
} |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
117 |
TUint32 MemoryWriter::GetStringTableStart() |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
118 |
{ |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
119 |
return iStringTableStart; |
46ca13b54f56
features: bsym for rofsbuild and log input support for rombuild
marvin shi <marvin.shi@nokia.com>
parents:
diff
changeset
|
120 |
} |