00001 /* 00002 FALCON - The Falcon Programming Language. 00003 FILE: strtable.h 00004 00005 String table used in modules 00006 ------------------------------------------------------------------- 00007 Author: Giancarlo Niccolai 00008 Begin: Mon Feb 14 2005 00009 00010 ------------------------------------------------------------------- 00011 (C) Copyright 2004: the FALCON developers (see list in AUTHORS file) 00012 00013 See LICENSE file for licensing details. 00014 */ 00015 00020 #ifndef flc_strtable_H 00021 #define flc_strtable_H 00022 00023 #include <falcon/types.h> 00024 #include <falcon/string.h> 00025 #include <falcon/genericvector.h> 00026 #include <falcon/genericmap.h> 00027 #include <falcon/basealloc.h> 00028 00029 namespace Falcon { 00030 00031 class Stream; 00032 class ModuleLoader; 00033 00034 class FALCON_DYN_CLASS StringTable: public BaseAlloc 00035 { 00036 GenericVector m_vector; 00037 Map m_map; 00038 Map m_intMap; 00039 char *m_tableStorage; 00040 uint32 m_internatCount; 00041 00042 friend class ModuleLoader; 00043 00044 // Non-const version of get is private 00045 String *getNonConst( uint32 id ) 00046 { 00047 if ( id < m_vector.size() ) 00048 return *(String **) m_vector.at( id ); 00049 return 0; 00050 } 00051 00052 public: 00053 StringTable(); 00054 StringTable( const StringTable &other ); 00055 ~StringTable(); 00056 00057 void reserve( int32 size ) { 00058 m_vector.reserve( size ); 00059 } 00060 00061 int32 add( String *str ); 00062 int32 findId( const String &str ) const; 00063 String *find( const String &source ) const; 00064 00070 bool skip( Stream *in ) const; 00071 00072 const String *get( uint32 id ) const 00073 { 00074 if ( id < m_vector.size() ) 00075 return *(String **) m_vector.at( id ); 00076 return 0; 00077 } 00078 00079 const String *operator[]( int32 id ) { 00080 return *(String **) m_vector.at( id );; 00081 } 00082 00083 int32 size() const { return m_vector.size(); } 00084 00113 bool save( Stream *out ) const; 00114 00121 bool load( Stream *in ); 00122 00140 bool saveTemplate( Stream *out, const String &modName, const String &origLangCode ) const; 00141 00152 void build( char **table, bool bInternational ); 00153 00164 void build( wchar_t **table, bool bInternational ); 00165 00170 uint32 internatCount() const { return m_internatCount; } 00171 }; 00172 00173 } 00174 00175 #endif 00176 00177 /* end of strtable.h */