bintools/rcomp/src/INDEXTAB.CPP
changeset 0 044383f39525
equal deleted inserted replaced
-1:000000000000 0:044383f39525
       
     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 <stdlib.h>
       
    21 #include "ERRORHAN.H"
       
    22 #include "INDEXTAB.H"
       
    23 
       
    24 #if defined(__MSVCDOTNET__) || defined(__TOOLS2__)
       
    25 using std::hex;
       
    26 using std::dec;
       
    27 using std::endl;
       
    28 using std::ostream;
       
    29 #endif //__MSVCDOTNET__
       
    30 
       
    31 int IndexTable::iInUse = 0;
       
    32 
       
    33 IndexTableItem::IndexTableItem(ResourceHeader* aResource)
       
    34 	{
       
    35 	iResource=aResource;
       
    36 	iOffset[0] = '\0';
       
    37 	iOffset[1] = '\0';
       
    38 	}
       
    39 
       
    40 IndexTableItem::~IndexTableItem()
       
    41 	{
       
    42 	delete iResource;
       
    43 	}
       
    44 
       
    45 void IndexTableItem::SetOffset(unsigned long aOffsetToSet)
       
    46 	{
       
    47 	assert(aOffsetToSet <= 0xFFFF);
       
    48 	
       
    49 	iOffset[0] = char(aOffsetToSet & 0xFF);
       
    50 	iOffset[1] = char((aOffsetToSet & 0xFF00)>>8);
       
    51 	}
       
    52 
       
    53 RCBinaryStream & operator<< ( RCBinaryStream & os, const IndexTableItem & o)
       
    54 	{
       
    55 	os.Write( o.iOffset, 2);
       
    56 	return os;
       
    57 	}
       
    58 
       
    59 ostream & operator<< ( ostream & os, const IndexTableItem & o)
       
    60 	{
       
    61 	unsigned long offset = (o.iOffset[1]<<8)|o.iOffset[0];
       
    62 	os << "IndexTableItem " << hex << offset << dec << "\t" << o.iResource->iLabel << endl;
       
    63 	return os;
       
    64 	}
       
    65 
       
    66 IndexTable::IndexTable()
       
    67 	{
       
    68 	assert( !iInUse);
       
    69 	iInUse = 1;		// Only one instance can be created at a time. This is because the class
       
    70 	}				// manages a lump of memory which is freed on destruction.
       
    71 
       
    72 IndexTable::~IndexTable()
       
    73 	{
       
    74 	assert( iInUse);
       
    75 	DeleteAll();
       
    76 	iInUse = 0;
       
    77 	}
       
    78 
       
    79 void IndexTable::Add( ResourceHeader* aResource)
       
    80 	{
       
    81 	Array::Add( new IndexTableItem( aResource) );
       
    82 	}
       
    83 
       
    84 void IndexTable::SetIndexOffset(unsigned long aOffsetToSet)
       
    85 	{
       
    86 	assert(aOffsetToSet <= 0xFFFF);
       
    87 	
       
    88 	iOffset[0] = char(aOffsetToSet & 0xFF);
       
    89 	iOffset[1] = char((aOffsetToSet & 0xFF00)>>8);
       
    90 	}
       
    91 
       
    92 
       
    93 ostream & operator<< ( ostream & os, const IndexTable & o)
       
    94 	{
       
    95 	os << "IndexTable" << endl;
       
    96 	
       
    97 	if ( o.Size() == 0)
       
    98 		{
       
    99 		os << "<None>" << endl;
       
   100 		return os;
       
   101 		}
       
   102 		
       
   103 	IndexTableIterator next( o);
       
   104 	IndexTableItem * p;
       
   105 	
       
   106 	while( ( p = next() ) != NULL)
       
   107 		os << * p;
       
   108 
       
   109 	unsigned long offset = (o.iOffset[1]<<8)|o.iOffset[0];
       
   110 	os << "IndexTable     " << hex << offset << dec << endl;
       
   111 	return os;
       
   112 	}
       
   113 
       
   114 RCBinaryStream & operator<< ( RCBinaryStream & os, const IndexTable & o)
       
   115 	{
       
   116 	if ( o.Size() == 0)
       
   117 		return os;
       
   118 		
       
   119 	IndexTableIterator next( o);
       
   120 	IndexTableItem * p;
       
   121 	
       
   122 	while( ( p = next() ) != NULL)
       
   123 		os << * p;
       
   124 
       
   125 	os.Write( o.iOffset, 2);
       
   126 	return os;
       
   127 	}
       
   128 
       
   129 IndexTableIterator::IndexTableIterator(const IndexTable & a):
       
   130 	ArrayIterator(a)
       
   131 	{}
       
   132 
       
   133 IndexTableItem * IndexTableIterator::operator() ()
       
   134 	{
       
   135 	return (IndexTableItem *) ArrayIterator::operator() ();
       
   136 	}