00001 /*--License:
00002 Kyra Sprite Engine
00003 Copyright Lee Thomason (Grinning Lizard Software) 2001-2002
00004 www.grinninglizard.com/kyra
00005 www.sourceforge.net/projects/kyra
00006
00007 This program is free software; you can redistribute it and/or
00008 modify it under the terms of the GNU General Public License
00009 as published by the Free Software Foundation; either version 2
00010 of the License, or (at your option) any later version.
00011
00012 This program is distributed in the hope that it will be useful,
00013 but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00015 GNU General Public License for more details.
00016
00017 You should have received a copy of the GNU General Public License
00018 along with this program; if not, write to the Free Software
00019 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00020
00021 The full text of the license can be found in license.txt
00022 */
00023
00024 #ifndef GLNAMEFIELD_INCLUDED
00025 #define GLNAMEFIELD_INCLUDED
00026
00027 #pragma warning( disable : 4530 )
00028 #pragma warning( disable : 4786 )
00029 #include <string>
00030
00031 #include "../util/gltypes.h"
00032 #include "../util/gllist.h"
00033 #include "SDL_endian.h"
00034
00035
00036
00037
00038 // A strange data type. Given names (strings) with dot seperators,
00039 // these are mapped to integers, so that the names can be OR'd together
00040 // with unique values.
00041 //
00042 // for example:
00043 // woman.walking.ne
00044 // woman.walking.se
00045 //
00046 // may get mapped to:
00047 // woman 1 ( 1 << 0 )
00048 // walking 2 ( 1 << 1 )
00049 // ne 4 ( 1 << 2 )
00050 // se 8 ( 2 << 2 )
00051
00052
00053 class GlNameField
00054 {
00055 public:
00056
00057 GlNameField();
00058 ~GlNameField() {}
00059
00060 // Add woman.walking.ne
00061 void Add( const std::string& sentance );
00062
00063 // Adds complete, calculate the values.
00064 void Calc();
00065
00066 // Get a value; can only be called after calc
00067 bool Get( const std::string& sentance, U32* value ) const;
00068
00069 // Horrible hack...that needs to be fixed to make this a "Gl" class
00070 void WriteHeader( FILE* text, const char* prefix );
00071
00072 private:
00073 enum
00074 {
00075 MAX_BUCKET = 32
00076 };
00077
00078 bool calcComplete;
00079 int numBucket;
00080 int bitWidth[ MAX_BUCKET ]; // bit width of a bucket
00081 int shift[ MAX_BUCKET ]; // shift to get to a bucket
00082
00083 GlSList< std::string > bucket[ MAX_BUCKET ];
00084 };
00085
00086
00087 class KrCachedWrite
00088 {
00089 public:
00090
00091 KrCachedWrite( SDL_RWops* _stream ) { stream = _stream; }
00092 ~KrCachedWrite() {}
00093
00094 // Writes a dummy value to the stream, but remembers the location.
00095 // Flush will write the data.
00096 void Write( const std::string& value );
00097
00098 // Goes back and writes all the values; needs the name field to look them up.
00099 void Flush();
00100
00101 // Write all the cached names to the header file. Call after a Flush.
00102 void WriteHeader( FILE* text, const char* prefix );
00103
00104 private:
00105 struct Data
00106 {
00107 U32 pos;
00108 std::string value;
00109
00110 bool operator==( const Data& rhs ) { return value == rhs.value && pos == rhs.pos; }
00111 };
00112 GlNameField nameField;
00113 GlSList< Data > list;
00114 SDL_RWops* stream;
00115 };
00116
00117
00118 #endif
00119
1.2.11.1 written by Dimitri van Heesch,
© 1997-2001