1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
/*************************************************************************
DOC++, a C++ (and C) documentation system for LaTeX and HTML
Copyright (C) 1996 Roland Wunderling,
Malte Zoeckler
DOC++ is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation. This program
is distributed WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
If you intend to use DOC++ commercially on a regular basis you
must contact the authors for an appropriate donation.
*************************************************************************/
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <iostream.h>
#include "nametable.hh"
#include "McString.h"
//@ ----------------------------------------------------------------------------
int hashFunction( const NameTable::Name* n )
{
unsigned int res = 0;
const char* sptr = n->name;
while (*sptr)
{
res *= 65 ;
res += *sptr++ - int('0') ;
res %= 0x0fffffff ;
}
return res ;
}
void NameTable::add( int num, const char* name )
{
int n = strlen(name) + 1 ;
int i = names.size() ;
char* start = names ;
names.append( n, name ) ;
int delta = start - (char*)names ;
if( delta )
{
for( table.first() ; table.current() ; table.next() )
((Name*)table.current())->name -= delta ;
}
Name newName( &names[i] ) ;
table.add( newName, num ) ;
}
void NameTable::clear()
{
table.clear() ;
names.clear() ;
}
ostream& operator<<(ostream& out, const NameTable& nt)
{
for( nt.first() ; nt.current() ; nt.next() )
{
out << nt[nt.current()] << ':' ;
out << nt.current() << char(6) << endl ;
}
return out ;
}
istream& operator>>(istream& in, NameTable& nt)
{
int num ;
char c ;
McString string ;
nt.clear() ;
while( in )
{
in >> num ;
in.get(c) ;
if( c != ':' )
break ;
string.clear() ;
do {
in.get(c) ;
if( c == char(6) )
{
nt.add( num, string ) ;
break ;
}
string += c ;
} while( in ) ;
}
return in ;
}
int NameTable::isConsistent() const
{
return names.isConsistent() && table.isConsistent() ;
}
NameTable::NameTable()
: table( hashFunction )
, names( 1000 )
{
}
|