|
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 #include <assert.h> |
|
20 #include "LINKARRA.H" |
|
21 #include "NAMEIDMA.H" |
|
22 #include "RCBINSTR.H" |
|
23 #include "TOKENS.H" |
|
24 #include "MEM.H" |
|
25 #include "ERRORHAN.H" |
|
26 #include "RCBINSTR.H" |
|
27 |
|
28 #if defined(__MSVCDOTNET__) || defined(__TOOLS2__) |
|
29 using std::cout; |
|
30 using std::cerr; |
|
31 using std::endl; |
|
32 #endif //__MSVCDOTNET__ |
|
33 |
|
34 extern NameIdMap* pResourceNameIds; |
|
35 extern int verbose; |
|
36 extern RCTypeArray gTypes; |
|
37 |
|
38 int LinkArray::iInUse = 0; |
|
39 |
|
40 LinkArray::LinkArray() |
|
41 { |
|
42 assert(!iInUse); |
|
43 iInUse = 1; |
|
44 } |
|
45 |
|
46 LinkArray::~LinkArray() |
|
47 { |
|
48 assert(iInUse); |
|
49 DeleteAll(); |
|
50 } |
|
51 |
|
52 void LinkArray::Add( LinkItem * pNewItem) |
|
53 { |
|
54 Array::Add( pNewItem); |
|
55 } |
|
56 |
|
57 void LinkArray::OverwriteLinks ( RCBinaryStream & os ) const |
|
58 { |
|
59 if ( verbose) { MOFF; cout << "Writing in correct links." << endl; MON;} |
|
60 LinkArrayIterator next( *this); |
|
61 LinkItem * p; |
|
62 while ( ( p = next() ) != NULL) |
|
63 p->OverwriteLink( os); |
|
64 } |
|
65 |
|
66 LinkItem::LinkItem(ResourceDataStream& aStream,const String& aResourceName,const String& aFileName,int aLineNumber): |
|
67 iStreamPosition(0xeebbeebb), // garbage initialization |
|
68 iResourceName(aResourceName), |
|
69 iFileName(aFileName), |
|
70 iLineNumber(aLineNumber) |
|
71 { |
|
72 aStream.EnquireStreamPositionWhenKnown(iStreamPosition); // causes iStream to be correctly set at some point later |
|
73 } |
|
74 |
|
75 int WordLink::NumberOfBytesOccupiesInStream() |
|
76 { // static |
|
77 return gTypes.GetSize(L_WORD); |
|
78 } |
|
79 |
|
80 int LongLink::NumberOfBytesOccupiesInStream() |
|
81 { // static |
|
82 return gTypes.GetSize(L_LONG); |
|
83 } |
|
84 |
|
85 void WordLink::OverwriteLink( RCBinaryStream & os ) const |
|
86 { |
|
87 if ( verbose) { MOFF; cout << "Writing WORD link: " << iResourceName << "\t" << iStreamPosition << endl; MON;} |
|
88 os.SetPosition(iStreamPosition); |
|
89 ErrorHandler::Register(iFileName,iLineNumber); |
|
90 os << NumericValue(pResourceNameIds->FindId(iResourceName),L_WORD); |
|
91 } |
|
92 |
|
93 void LongLink::OverwriteLink( RCBinaryStream & os ) const |
|
94 { |
|
95 if ( verbose) { MOFF; cout << "Writing LONG link: " << iResourceName << "\t" << iStreamPosition << endl; MON;} |
|
96 os.SetPosition(iStreamPosition); |
|
97 ErrorHandler::Register(iFileName,iLineNumber); |
|
98 os << NumericValue(pResourceNameIds->FindId(iResourceName),L_LONG); |
|
99 } |
|
100 |
|
101 LinkArrayIterator::LinkArrayIterator(const LinkArray& c): |
|
102 ArrayIterator(c) |
|
103 {} |
|
104 |
|
105 LinkItem * LinkArrayIterator::operator() () |
|
106 { |
|
107 return (LinkItem *) ArrayIterator::operator() (); |
|
108 } |
|
109 |
|
110 WordLink::WordLink(ResourceDataStream& aStream,const String& aResourceName,const String& aFileName,int aLineNumber): |
|
111 LinkItem(aStream,aResourceName,aFileName,aLineNumber) |
|
112 {} |
|
113 |
|
114 LongLink::LongLink(ResourceDataStream& aStream,const String& aResourceName,const String& aFileName,int aLineNumber): |
|
115 LinkItem(aStream,aResourceName,aFileName,aLineNumber) |
|
116 {} |
|
117 |
|
118 ostream & WordLink::StreamOut ( ostream & os) |
|
119 { |
|
120 os << "WordLink: " << iStreamPosition << "\t" << iResourceName << endl; |
|
121 |
|
122 return os; |
|
123 } |
|
124 |
|
125 ostream & LongLink::StreamOut( ostream & os) |
|
126 { |
|
127 os << "LongLink: " << iStreamPosition << "\t" << iResourceName << endl; |
|
128 |
|
129 return os; |
|
130 } |
|
131 |
|
132 ostream & operator<< ( ostream & os, LinkArray & o) |
|
133 { |
|
134 os << "LinkArray *******" << endl; |
|
135 |
|
136 LinkArrayIterator next( o); |
|
137 LinkItem * p; |
|
138 |
|
139 while( ( p = next() ) != NULL) |
|
140 p->StreamOut( os); |
|
141 |
|
142 return os; |
|
143 } |