diff --git a/doomsday/engine/api/stringpool.h b/doomsday/engine/api/stringpool.h index fa77d6266e..23fafb88e8 100644 --- a/doomsday/engine/api/stringpool.h +++ b/doomsday/engine/api/stringpool.h @@ -5,8 +5,11 @@ * Data structure for storing a set of unique case-insensitive strings. When * multiple strings with the same case-insensitive contents are added to the * pool, only one copy of the string is kept in memory. If there is variation - * in the letter cases, the version added last is used. In other words, the - * letter cases of the earlier duplicate strings may change. + * in the letter cases, the version added first is used. In other words, the + * letter cases of the later duplicate strings is ignored. + * + * @todo Add serialization. + * @todo Add case-sensitive mode. * * @authors Copyright © 2010-2012 Daniel Swanson * diff --git a/doomsday/engine/engine.pro b/doomsday/engine/engine.pro index 869055e687..8265141e9f 100644 --- a/doomsday/engine/engine.pro +++ b/doomsday/engine/engine.pro @@ -270,7 +270,7 @@ DENG_HEADERS = \ portable/include/r_things.h \ portable/include/r_util.h \ portable/include/r_world.h \ - portable/include/strarray.h \ + portable/include/stringarray.h \ portable/include/sv_def.h \ portable/include/sv_frame.h \ portable/include/sv_infine.h \ @@ -530,7 +530,7 @@ SOURCES += \ portable/src/s_sfx.c \ portable/src/s_wav.c \ portable/src/size.c \ - portable/src/strarray.cpp \ + portable/src/stringarray.cpp \ portable/src/sv_frame.c \ portable/src/sv_infine.c \ portable/src/sv_main.c \ diff --git a/doomsday/engine/portable/include/de_misc.h b/doomsday/engine/portable/include/de_misc.h index 81e13a14e5..5bf2bae8c8 100644 --- a/doomsday/engine/portable/include/de_misc.h +++ b/doomsday/engine/portable/include/de_misc.h @@ -42,6 +42,6 @@ #include "m_gridmap.h" #include "m_decomp64.h" #include "smoother.h" -#include "strarray.h" +#include "stringarray.h" #endif /* LIBDENG_MISC_H */ diff --git a/doomsday/engine/portable/include/def_main.h b/doomsday/engine/portable/include/def_main.h index 36d3b83aa0..2ffc105a46 100644 --- a/doomsday/engine/portable/include/def_main.h +++ b/doomsday/engine/portable/include/def_main.h @@ -24,7 +24,7 @@ #define LIBDENG_DEFINITIONS_MAIN_H #include "def_data.h" -#include "strarray.h" +#include "stringarray.h" typedef struct sfxinfo_s { void* data; /// Pointer to sound data. @@ -108,17 +108,17 @@ boolean Def_SameStateSequence(state_t* snew, state_t* sold); * Compiles a list of all the defined mobj types. Indices in this list * match those in the @c mobjInfo array. * - * @return StrArray instance. Caller gets ownership. + * @return StringArray instance. Caller gets ownership. */ -StrArray* Def_ListMobjTypeIDs(void); +StringArray* Def_ListMobjTypeIDs(void); /** * Compiles a list of all the defined mobj states. Indices in this list * match those in the @c states array. * - * @return StrArray instance. Caller gets ownership. + * @return StringArray instance. Caller gets ownership. */ -StrArray* Def_ListStateIDs(void); +StringArray* Def_ListStateIDs(void); D_CMD(ListMobjs); diff --git a/doomsday/engine/portable/include/strarray.h b/doomsday/engine/portable/include/stringarray.h similarity index 61% rename from doomsday/engine/portable/include/strarray.h rename to doomsday/engine/portable/include/stringarray.h index 89ec9b5e9a..a7fe03b046 100644 --- a/doomsday/engine/portable/include/strarray.h +++ b/doomsday/engine/portable/include/stringarray.h @@ -1,10 +1,10 @@ /** - * @file strarray.h + * @file stringarray.h * Array of text strings. @ingroup base * * Dynamic, indexable array of text strings. * - * @see stringpool.h for case-insensitive strings + * @todo Use StringPool internally for effecient storage, searches * * @authors Copyright © 2012 Jaakko Keränen * @@ -23,158 +23,158 @@ * 02110-1301 USA */ -#ifndef LIBDENG_STR_ARRAY_H -#define LIBDENG_STR_ARRAY_H +#ifndef LIBDENG_STRING_ARRAY_H +#define LIBDENG_STRING_ARRAY_H #include "dd_types.h" -struct strarray_s; // opaque +struct stringarray_s; // opaque /** - * StrArray instance. Construct with StrArray_New(). + * StringArray instance. Construct with StringArray_New(). */ -typedef struct strarray_s StrArray; +typedef struct stringarray_s StringArray; /** * Constructs an empty string array. * - * @return StrArray instance. Must be deleted with StrArray_Delete(). + * @return StringArray instance. Must be deleted with StringArray_Delete(). */ -StrArray* StrArray_New(void); +StringArray* StringArray_New(void); /** * Creates a new sub-array that contains copies of a subset of the * array's strings. - * @param ar StrArray instance whose strings to copy. + * @param ar StringArray instance whose strings to copy. * @param fromIndex Start of range of copied strings. * @param count Number of strings in the range. Use -1 to extend to range * to the end of the array. * - * @return A newly created StrArray instance with copies of the strings. + * @return A newly created StringArray instance with copies of the strings. * The returned array will contain @a count strings and - * must be deleted with StrArray_Delete(). + * must be deleted with StringArray_Delete(). */ -StrArray* StrArray_NewSub(const StrArray* ar, int fromIndex, int count); +StringArray* StringArray_NewSub(const StringArray* ar, int fromIndex, int count); /** * Destructs the string array @a ar. - * @param ar StrArray instance. + * @param ar StringArray instance. */ -void StrArray_Delete(StrArray* ar); +void StringArray_Delete(StringArray* ar); /** * Empties the contents of string array @a ar. - * @param ar StrArray instance. + * @param ar StringArray instance. */ -void StrArray_Clear(StrArray* ar); +void StringArray_Clear(StringArray* ar); /** * Returns the number of strings in the array. - * @param ar StrArray instance. + * @param ar StringArray instance. */ -int StrArray_Size(const StrArray* ar); +int StringArray_Size(const StringArray* ar); /** * Appends a string at the end of the array. - * @param ar StrArray instance. + * @param ar StringArray instance. * @param str Text string to append. A copy is made of the contents. */ -void StrArray_Append(StrArray* ar, const char* str); +void StringArray_Append(StringArray* ar, const char* str); /** * Appends an array of text strings at the end of the array. - * @param ar StrArray instance. - * @param other Another StrArray instance whose strings will be appended + * @param ar StringArray instance. + * @param other Another StringArray instance whose strings will be appended * to the end of @a ar. */ -void StrArray_AppendArray(StrArray* ar, const StrArray* other); +void StringArray_AppendArray(StringArray* ar, const StringArray* other); /** * Inserts a string to the start of the array. - * @param ar StrArray instance. + * @param ar StringArray instance. * @param str Text string to prepend. A copy is made of the contents. */ -void StrArray_Prepend(StrArray* ar, const char* str); +void StringArray_Prepend(StringArray* ar, const char* str); /** * Inserts a string to the array. - * @param ar StrArray instance. + * @param ar StringArray instance. * @param str Text string to prepend. A copy is made of the contents. * @param atIndex Position where @a str will appear after the operation * is complete. When inserting at position @em n, strings at positions * n+1..last will be pushed to positions n+2..last+1. */ -void StrArray_Insert(StrArray* ar, const char* str, int atIndex); +void StringArray_Insert(StringArray* ar, const char* str, int atIndex); /** * Removes the string at position @a index. - * @param ar StrArray instance. + * @param ar StringArray instance. * @param atIndex Position to remove. When removing position @em n, strings * at positions n+1..last will be pulled to positions n..last-1. */ -void StrArray_Remove(StrArray* ar, int index); +void StringArray_Remove(StringArray* ar, int index); /** * Removes a range of strings from the array. - * @param ar StrArray instance. + * @param ar StringArray instance. * @param fromIndex Beginning of the range of positions to remove. * @param count Length of the removed range. Use -1 to extend to range * to the end of the array. */ -void StrArray_RemoveRange(StrArray* ar, int fromIndex, int count); +void StringArray_RemoveRange(StringArray* ar, int fromIndex, int count); /** * Finds string @a str in the array (case sensitive) and returns its position. - * @param ar StrArray instance. + * @param ar StringArray instance. * @param str Text string to find. * * @return Position of the string, or -1 if not found. * * @note Search operation performance is O(n). */ -int StrArray_IndexOf(const StrArray* ar, const char* str); +int StringArray_IndexOf(const StringArray* ar, const char* str); /** * Returns a non-modifiable string at position @a index. - * @param ar StrArray instance. + * @param ar StringArray instance. * @param index Position in the array. * * @return Text string. */ -const char* StrArray_At(const StrArray* ar, int index); +const char* StringArray_At(const StringArray* ar, int index); /** * Returns a modifiable string at position @a index. - * @param ar StrArray instance. + * @param ar StringArray instance. * @param index Position in the array. * * @return ddstring_t instance that can be modified. */ -ddstring_t* StrArray_StringAt(StrArray* ar, int index); +ddstring_t* StringArray_StringAt(StringArray* ar, int index); /** * Checks if the array contains a string (case sensitive). - * @param ar StrArray instance. + * @param ar StringArray instance. * @param str Text string to check for. * * @return @c true, if the string is in the array; otherwise @c false. * * @note Performance is O(n). */ -boolean StrArray_Contains(const StrArray* ar, const char* str); +boolean StringArray_Contains(const StringArray* ar, const char* str); /** * Serializes the array of strings using @a writer. - * @param ar StrArray instance. + * @param ar StringArray instance. * @param writer Writer instance. */ -void StrArray_Write(const StrArray* ar, Writer* writer); +void StringArray_Write(const StringArray* ar, Writer* writer); /** * Deserializes the array of strings from @a reader. - * @param ar StrArray instance. + * @param ar StringArray instance. * @param reader Reader instance. */ -void StrArray_Read(StrArray* ar, Reader* reader); +void StringArray_Read(StringArray* ar, Reader* reader); -#endif // LIBDENG_STR_ARRAY_H +#endif // LIBDENG_STRING_ARRAY_H diff --git a/doomsday/engine/portable/src/cl_world.c b/doomsday/engine/portable/src/cl_world.c index c6c2a7a674..88fb94c09f 100644 --- a/doomsday/engine/portable/src/cl_world.c +++ b/doomsday/engine/portable/src/cl_world.c @@ -104,47 +104,47 @@ static void setTableSize(indextranstable_t* table, int size) void Cl_ReadServerMobjTypeIDs(void) { int i; - StrArray* ar = StrArray_New(); - StrArray_Read(ar, msgReader); + StringArray* ar = StringArray_New(); + StringArray_Read(ar, msgReader); #ifdef _DEBUG - Con_Message("Cl_ReadServerMobjTypeIDs: Received %i mobj type IDs.\n", StrArray_Size(ar)); + Con_Message("Cl_ReadServerMobjTypeIDs: Received %i mobj type IDs.\n", StringArray_Size(ar)); #endif - setTableSize(&xlatMobjType, StrArray_Size(ar)); + setTableSize(&xlatMobjType, StringArray_Size(ar)); // Translate the type IDs to local. - for(i = 0; i < StrArray_Size(ar); ++i) + for(i = 0; i < StringArray_Size(ar); ++i) { - xlatMobjType.serverToLocal[i] = Def_GetMobjNumForName(StrArray_At(ar, i)); + xlatMobjType.serverToLocal[i] = Def_GetMobjNumForName(StringArray_At(ar, i)); #ifdef _DEBUG Con_Message("Server mobj %i => local %i\n", i, xlatMobjType.serverToLocal[i]); #endif } - StrArray_Delete(ar); + StringArray_Delete(ar); } void Cl_ReadServerMobjStateIDs(void) { int i; - StrArray* ar = StrArray_New(); - StrArray_Read(ar, msgReader); + StringArray* ar = StringArray_New(); + StringArray_Read(ar, msgReader); #ifdef _DEBUG - Con_Message("Cl_ReadServerMobjStateIDs: Received %i mobj state IDs.\n", StrArray_Size(ar)); + Con_Message("Cl_ReadServerMobjStateIDs: Received %i mobj state IDs.\n", StringArray_Size(ar)); #endif - setTableSize(&xlatMobjState, StrArray_Size(ar)); + setTableSize(&xlatMobjState, StringArray_Size(ar)); // Translate the type IDs to local. - for(i = 0; i < StrArray_Size(ar); ++i) + for(i = 0; i < StringArray_Size(ar); ++i) { - xlatMobjState.serverToLocal[i] = Def_GetStateNum(StrArray_At(ar, i)); + xlatMobjState.serverToLocal[i] = Def_GetStateNum(StringArray_At(ar, i)); #ifdef _DEBUG Con_Message("Server state %i => local %i\n", i, xlatMobjState.serverToLocal[i]); #endif } - StrArray_Delete(ar); + StringArray_Delete(ar); } static material_t* Cl_FindLocalMaterial(materialarchive_serialid_t archId) diff --git a/doomsday/engine/portable/src/def_main.c b/doomsday/engine/portable/src/def_main.c index 2019fe505c..f70aff4fdb 100644 --- a/doomsday/engine/portable/src/def_main.c +++ b/doomsday/engine/portable/src/def_main.c @@ -1957,24 +1957,24 @@ int Def_Set(int type, int index, int value, const void* ptr) return true; } -StrArray* Def_ListMobjTypeIDs(void) +StringArray* Def_ListMobjTypeIDs(void) { - StrArray* array = StrArray_New(); + StringArray* array = StringArray_New(); int i; for(i = 0; i < defs.count.mobjs.num; ++i) { - StrArray_Append(array, defs.mobjs[i].id); + StringArray_Append(array, defs.mobjs[i].id); } return array; } -StrArray* Def_ListStateIDs(void) +StringArray* Def_ListStateIDs(void) { - StrArray* array = StrArray_New(); + StringArray* array = StringArray_New(); int i; for(i = 0; i < defs.count.states.num; ++i) { - StrArray_Append(array, defs.states[i].id); + StringArray_Append(array, defs.states[i].id); } return array; } diff --git a/doomsday/engine/portable/src/strarray.cpp b/doomsday/engine/portable/src/stringarray.cpp similarity index 66% rename from doomsday/engine/portable/src/strarray.cpp rename to doomsday/engine/portable/src/stringarray.cpp index 2fffd90327..1e60bb75cd 100644 --- a/doomsday/engine/portable/src/strarray.cpp +++ b/doomsday/engine/portable/src/stringarray.cpp @@ -1,6 +1,6 @@ /** - * @file strarray.cpp - * Array of text strings. @ingroup base + * @file stringarray.cpp + * Array of text strings implementation. @ingroup base * * @authors Copyright © 2012 Jaakko Keränen * @@ -19,7 +19,7 @@ * 02110-1301 USA */ -#include "strarray.h" +#include "stringarray.h" #include #include #include @@ -52,7 +52,7 @@ class Str { } // namespace de -struct strarray_s { +struct stringarray_s { typedef std::vector Strings; Strings array; @@ -75,13 +75,13 @@ struct strarray_s { } }; -StrArray* StrArray_New(void) +StringArray* StringArray_New(void) { - StrArray* ar = new StrArray; + StringArray* ar = new StringArray; return ar; } -StrArray* StrArray_NewSub(const StrArray *ar, int fromIndex, int count) +StringArray* StringArray_NewSub(const StringArray *ar, int fromIndex, int count) { assert(ar); if(count < 0) @@ -90,65 +90,65 @@ StrArray* StrArray_NewSub(const StrArray *ar, int fromIndex, int count) } ar->assertValidRange(fromIndex, count); - StrArray* sub = StrArray_New(); + StringArray* sub = StringArray_New(); for(int i = 0; i < count; ++i) { - StrArray_Append(sub, StrArray_At(ar, fromIndex + i)); + StringArray_Append(sub, StringArray_At(ar, fromIndex + i)); } return sub; } -void StrArray_Delete(StrArray* ar) +void StringArray_Delete(StringArray* ar) { if(ar) delete ar; } -void StrArray_Clear(StrArray* ar) +void StringArray_Clear(StringArray* ar) { assert(ar); - for(StrArray::Strings::iterator i = ar->array.begin(); i != ar->array.end(); ++i) + for(StringArray::Strings::iterator i = ar->array.begin(); i != ar->array.end(); ++i) { delete *i; } ar->array.clear(); } -int StrArray_Size(const StrArray *ar) +int StringArray_Size(const StringArray *ar) { assert(ar); return ar->array.size(); } -void StrArray_Append(StrArray* ar, const char* str) +void StringArray_Append(StringArray* ar, const char* str) { assert(ar); ar->array.push_back(new de::Str(str)); } -void StrArray_AppendArray(StrArray* ar, const StrArray* other) +void StringArray_AppendArray(StringArray* ar, const StringArray* other) { assert(ar); assert(other); assert(ar != other); - for(StrArray::Strings::const_iterator i = other->array.begin(); i != other->array.end(); ++i) + for(StringArray::Strings::const_iterator i = other->array.begin(); i != other->array.end(); ++i) { - StrArray_Append(ar, Str_Text(**i)); + StringArray_Append(ar, Str_Text(**i)); } } -void StrArray_Prepend(StrArray* ar, const char* str) +void StringArray_Prepend(StringArray* ar, const char* str) { - StrArray_Insert(ar, str, 0); + StringArray_Insert(ar, str, 0); } -void StrArray_Insert(StrArray* ar, const char* str, int atIndex) +void StringArray_Insert(StringArray* ar, const char* str, int atIndex) { assert(ar); ar->assertValidIndex(atIndex); ar->array.insert(ar->array.begin() + atIndex, new de::Str(str)); } -void StrArray_Remove(StrArray* ar, int index) +void StringArray_Remove(StringArray* ar, int index) { assert(ar); ar->assertValidIndex(index); @@ -156,7 +156,7 @@ void StrArray_Remove(StrArray* ar, int index) ar->array.erase(ar->array.begin() + index); } -void StrArray_RemoveRange(StrArray* ar, int fromIndex, int count) +void StringArray_RemoveRange(StringArray* ar, int fromIndex, int count) { if(count < 0) { @@ -164,11 +164,11 @@ void StrArray_RemoveRange(StrArray* ar, int fromIndex, int count) } for(int i = 0; i < count; ++i) { - StrArray_Remove(ar, fromIndex); + StringArray_Remove(ar, fromIndex); } } -int StrArray_IndexOf(const StrArray *ar, const char* str) +int StringArray_IndexOf(const StringArray *ar, const char* str) { assert(ar); for(uint i = 0; i < ar->array.size(); ++i) @@ -179,39 +179,39 @@ int StrArray_IndexOf(const StrArray *ar, const char* str) return -1; } -const char* StrArray_At(const StrArray *ar, int index) +const char* StringArray_At(const StringArray *ar, int index) { assert(ar); ar->assertValidIndex(index); return Str_Text(*ar->array[index]); } -ddstring_t* StrArray_StringAt(StrArray* ar, int index) +ddstring_t* StringArray_StringAt(StringArray* ar, int index) { assert(ar); ar->assertValidIndex(index); return *ar->array[index]; } -boolean StrArray_Contains(const StrArray* ar, const char* str) +boolean StringArray_Contains(const StringArray* ar, const char* str) { - return StrArray_IndexOf(ar, str) >= 0; + return StringArray_IndexOf(ar, str) >= 0; } -void StrArray_Write(const StrArray *ar, Writer* writer) +void StringArray_Write(const StringArray *ar, Writer* writer) { assert(ar); Writer_WriteUInt32(writer, ar->array.size()); // Write each of the strings. - for(StrArray::Strings::const_iterator i = ar->array.begin(); i != ar->array.end(); ++i) + for(StringArray::Strings::const_iterator i = ar->array.begin(); i != ar->array.end(); ++i) { Str_Write(**i, writer); } } -void StrArray_Read(StrArray* ar, Reader* reader) +void StringArray_Read(StringArray* ar, Reader* reader) { - StrArray_Clear(ar); + StringArray_Clear(ar); uint count = Reader_ReadUInt32(reader); for(uint i = 0; i < count; ++i) diff --git a/doomsday/engine/portable/src/sv_main.c b/doomsday/engine/portable/src/sv_main.c index 1c509156de..45b3d7e846 100644 --- a/doomsday/engine/portable/src/sv_main.c +++ b/doomsday/engine/portable/src/sv_main.c @@ -805,7 +805,7 @@ void Sv_PlayerLeaves(unsigned int nodeID) */ void Sv_Handshake(int plrNum, boolean newPlayer) { - StrArray* ar; + StringArray* ar; int i; uint playersInGame = 0; @@ -834,18 +834,18 @@ void Sv_Handshake(int plrNum, boolean newPlayer) // Include the list of thing Ids. ar = Def_ListMobjTypeIDs(); Msg_Begin(PSV_MOBJ_TYPE_ID_LIST); - StrArray_Write(ar, msgWriter); + StringArray_Write(ar, msgWriter); Msg_End(); Net_SendBuffer(plrNum, 0); - StrArray_Delete(ar); + StringArray_Delete(ar); // Include the list of state Ids. ar = Def_ListStateIDs(); Msg_Begin(PSV_MOBJ_STATE_ID_LIST); - StrArray_Write(ar, msgWriter); + StringArray_Write(ar, msgWriter); Msg_End(); Net_SendBuffer(plrNum, 0); - StrArray_Delete(ar); + StringArray_Delete(ar); if(newPlayer) {