Skip to content

Commit

Permalink
Refactor: Renamed StrArray to StringArray
Browse files Browse the repository at this point in the history
More consistent with existing naming conventions.
  • Loading branch information
skyjake committed Jan 18, 2012
1 parent 34b745d commit add61e8
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 112 deletions.
7 changes: 5 additions & 2 deletions doomsday/engine/api/stringpool.h
Expand Up @@ -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 <danij@dengine.net>
*
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/engine.pro
Expand Up @@ -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 \
Expand Down Expand Up @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/include/de_misc.h
Expand Up @@ -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 */
10 changes: 5 additions & 5 deletions doomsday/engine/portable/include/def_main.h
Expand Up @@ -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.
Expand Down Expand Up @@ -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);

Expand Down
@@ -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 <jaakko.keranen@iki.fi>
*
Expand All @@ -23,158 +23,158 @@
* 02110-1301 USA</small>
*/

#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
* <i>n+1..last</i> will be pushed to positions <i>n+2..last+1</i>.
*/
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 <i>n+1..last</i> will be pulled to positions <i>n..last-1</i>.
*/
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
28 changes: 14 additions & 14 deletions doomsday/engine/portable/src/cl_world.c
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions doomsday/engine/portable/src/def_main.c
Expand Up @@ -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;
}
Expand Down

0 comments on commit add61e8

Please sign in to comment.