Main Page | Data Structures | File List | Data Fields | Globals

stringArray.c File Reference

Fault-tolerant structure to store one or more strings. More...

Go to the source code of this file.

Data Structures

struct  StringArray

Defines

#define STRINGARRAY_VERSION   "1.3.1"
#define STRINGARRAY_DATE   "19-Dec-2003"
#define STRINGARRAY_STARTSIZEOFARRAY   50
 This value sets the size of arrayOfStrings if a new structure StringArray is created.


Typedefs

typedef StringArrayStringArray_Ptr
 A pointer to structure StringArray is assigned the name StringArrayPtr.


Functions

StringArray_Ptr StringArray_create (void)
 Creates a StringArray structure.

StringArray_Ptr StringArray_createWithSpecifiedArraySize (const int sizeOfArray)
 Creates a StringArray structure.

void StringArray_destroy (StringArray_Ptr sAPtr)
 Destroys a structure StringArray.

void StringArray_extend (const StringArray_Ptr sAPtr)
 Extends the array size of a structure StringArray.

void StringArray_display (StringArray_Ptr sAPtr, FILE *outputStream)
 Displays a structure StringArray.

StringArray_Ptr StringArray_copy (const StringArray_Ptr sAPtr)
 A deepcopy of sAPtr is returned.

void StringArray_concatenate (const StringArray_Ptr sAPtrTarget, const StringArray_Ptr sAPtrSource)
 A copy of each string in sAPtrSource is added to sAPtrTarget.

void StringArray_mapConcatenate (const StringArray_Ptr sAPtr, const char *source)
 source is added to each element (char*) of sAPtr.

int StringArray_getNumberOfElements (const StringArray_Ptr sAPtr)
 Returns the number of elements of a structure StringArray.

int StringArray_getSizeOfArray (const StringArray_Ptr sAPtr)
 Returns the size of the array arrayOfStrings of a structure StringArray.

void StringArray_addElement (const StringArray_Ptr sAPtr, char *string)
 A char* is added to the structure StringArray.

char * StringArray_getElement (const StringArray_Ptr sAPtr, const int index)
 The char* of the element with index index of structure StringArray is returned.

int StringArray_removeElement (StringArray_Ptr sAPtr, const char *string)
 All elements of sAPtr that are identical to string are removed.


Detailed Description

Fault-tolerant structure to store one or more strings.

This structure provides a fault-tolerant way to store several strings. Strings are stored in sequential order with the function StringArray_addElement. The individual elements are accessed via their index starting from zero. Therefore, the index of the element with the highest index number is one less than numberOfElements.

The structure is created with StringArray_create, destroyed with StringArray_destroy and displayed with StringArray_display. The number of elements of a structure is returned by the function StringArray_getNumberOfElements, the size of the array arrayOfStrings is returned by the function StringArray_getSizeOfArray. Strings are added by StringArray_addElement and the value of an element is obtained by StringArray_getElement. Elements that are identical to a given string can be removed with StringArray_removeElement.

If an element is accessed via StringArray_getElement and the index is higher than numberOfElements - 1 (number of elements of this structure) the define IndexOutOfBoundsError is called and the program aborts.

The size of arrayOfStrings can grow during the lifetime of a structure StringArray. When a structure StringArray is created with StringArray_create the initial size of arrayOfStrings is set to STRINGARRAY_STARTSIZEOFARRAY. StringArray_addElement checks if numberOfElements exceeds sizeOfArray and, if necessary, resizes the string array automatically via StringArray_extend. As there is currently no function to remove elements arrayOfStrings can not shrink during the lifetime of an instance of StringArray!

Attention:
Function StringArray_addElement just links the given char* to arrayOfStrings. The char* is not copied and therefore must not be freed after the assignment! If StringArray_destroy is called the memory of all elements in arrayOfStrings is freed automatically.
Description of the members:

arrayOfStrings - array of char*
numberOfElements - number of elements in the structure
sizeOfArray - size of the array arrayOfStrings

Author:
Uli Fechner
Version:
01/09/2003 - v1.0.0 - Uli Fechner - initial release

02/09/2003 - v1.1.0 - Uli Fechner - major change: the size of the string array (arrayOfStrings) can now grow during the lifetime of a structure StringArray; this is handled automatically by StringArray_addElement if numberOfElements exceeds sizeOfArray; added STRINGARRAY_STARTSIZEOFARRAY, StringArray_createWithSpecifiedArraySize and StringArray_extend; changes in StringArray_create and StringArray_addElement

08/09/2003 - v1.1.1 - Uli Fechner - small modification in the output format of StringArray_display

08/09/2003 - v1.2.0 - Uli Fechner - bugfix related to the extension of the array (StringArray_addElement and StringArray_extend); modified the headers of both functions

15/10/2003 - v1.2.1 - Uli Fechner - changed the define STRINGARRAY_STARTSIZEOFARRAY

10/12/2003 - v1.2.2 - Uli Fechner - added function StringArray_concatenate

17/12/2003 - v1.3.0 - Uli Fechner - added function StringArray_copy and StringArray_mapConcatenate

19/12/2003 - v1.3.1 - Uli Fechner - added function StringArray_removeElement \code

Definition in file stringArray.c.


Define Documentation

#define STRINGARRAY_DATE   "19-Dec-2003"
 

Definition at line 3 of file stringArray.c.

#define STRINGARRAY_STARTSIZEOFARRAY   50
 

This value sets the size of arrayOfStrings if a new structure StringArray is created.

Author:
Uli Fechner
Version:
02/09/2003 - Uli Fechner - initial release

Definition at line 81 of file stringArray.c.

Referenced by StringArray_create().

#define STRINGARRAY_VERSION   "1.3.1"
 

Definition at line 2 of file stringArray.c.


Typedef Documentation

typedef StringArray* StringArray_Ptr
 

A pointer to structure StringArray is assigned the name StringArrayPtr.

Definition at line 71 of file stringArray.c.

Referenced by readDataFromStream(), SmilesCompound_getStringArrayOfNames(), StringArray_copy(), StringArray_create(), StringArray_createWithSpecifiedArraySize(), and StringArray_removeElement().


Function Documentation

void StringArray_addElement const StringArray_Ptr  sAPtr,
char *  string
 

A char* is added to the structure StringArray.

The char* is added to the array arrayOfStrings of structure StringArray. If the array arrayOfStrings is already full (i.e. numberOfElements >= sizeOfArray) it is extended by calling the function StringArray_extend.

Parameters:
sAPtr pointer on the structure StringArray the char* is added to
string char* that is added to StringArray
Author:
Uli Fechner
Version:
01/09/2003 - Uli Fechner - initial release

02/09/2003 - Uli Fechner - added the capability to extend arrayOfStrings if necessary; therefore, const of sAPtr had to be removed

08/09/2003 - Uli Fechner - fixed a bug related to the function call StringArray_extend; function header modified (const added)

Definition at line 404 of file stringArray.c.

References StringArray::arrayOfStrings, StringArray::numberOfElements, StringArray::sizeOfArray, and StringArray_extend().

Referenced by readDataFromStream(), SmilesCompound_addName(), SmilesCompound_create(), SmilesCompound_setName(), StringArray_concatenate(), and StringArray_copy().

void StringArray_concatenate const StringArray_Ptr  sAPtrTarget,
const StringArray_Ptr  sAPtrSource
 

A copy of each string in sAPtrSource is added to sAPtrTarget.

Attention:
Empty strings (NULL) are not copied. The number of elements that are added to sAPtrTarget may therefore be less than the number of elements that are added to sAPtrSource.
Parameters:
sAPtrTarget copies of the strings of sAPtrSource are added to this structure StringArray
sAPtrSource copies of the strings of this structure StringArray are added to sAPtrSource
Author:
Uli Fechner
Version:
10/12/2003 - Uli Fechner - initial release

Definition at line 310 of file stringArray.c.

References MemoryError, StringArray::numberOfElements, StringArray_addElement(), and StringArray_getElement().

Referenced by SmilesCompound_identical().

StringArray_Ptr StringArray_copy const StringArray_Ptr  sAPtr  ) 
 

A deepcopy of sAPtr is returned.

Attention:
Empty strings (NULL) are not copied. The number of elements of the copy of sAPtr may therefore be less than the number of elements of sAPtr.
Parameters:
sAPtr a deepcopy of the strings of sAPtr is returned
Return values:
StringArray_Ptr deepcopy of sAPtr
Author:
Uli Fechner
Version:
17/12/2003 - Uli Fechner - initial release

Definition at line 276 of file stringArray.c.

References MemoryError, StringArray::numberOfElements, StringArray_addElement(), StringArray_create(), StringArray_getElement(), and StringArray_Ptr.

Referenced by SmilesCompound_copy(), and StringArray_removeElement().

StringArray_Ptr StringArray_create void   ) 
 

Creates a StringArray structure.

A StringArray structure is created. The size of the array arrayOfStrings of the structure is STRINGARRAY_STARTSIZEOFARRAY and is dynamically adjusted during the lifetime of the structure.

Attention:
This function is only a wrapper for StringArray_createWithSpecifiedArraySize
Return values:
StringArray_Ptr pointer on the newly created structure StringArray
Author:
Uli Fechner
Version:
01/09/2003 - Uli Fechner - initial release

02/09/2003 - Uli Fechner - major change: now, this function is a wrapper for StringArray_createWithSpecifiedArraySize; therefore, all instructions moved to StringArray_createWithSpecifiedArraySize

Definition at line 129 of file stringArray.c.

References StringArray_createWithSpecifiedArraySize(), StringArray_Ptr, and STRINGARRAY_STARTSIZEOFARRAY.

Referenced by readDataFromStream(), SmilesCompound_addName(), SmilesCompound_create(), SmilesCompound_setName(), and StringArray_copy().

StringArray_Ptr StringArray_createWithSpecifiedArraySize const int  sizeOfArray  ) 
 

Creates a StringArray structure.

A StringArray structure is created. The size of the array arrayOfStrings of the structure is given as an argument.

Parameters:
sizeOfArray the size of the array arrayOfStrings of the newly created structure
Return values:
StringArray_Ptr pointer on the newly created structure StringArray
Author:
Uli Fechner
Version:
02/09/2003 - Uli Fechner - initial release

Definition at line 144 of file stringArray.c.

References StringArray::arrayOfStrings, MemoryError, StringArray::numberOfElements, StringArray::sizeOfArray, and StringArray_Ptr.

Referenced by StringArray_create().

void StringArray_destroy StringArray_Ptr  sAPtr  ) 
 

Destroys a structure StringArray.

The structure StringArray the pointer sAPtr refers to is destroyed. All allocated memory of the structure is automatically freed; this includes the memory of the char* of arrayOfStrings.

Parameters:
sAPtr pointer on the structure StringArray that should be destroyed
Author:
Uli Fechner
Version:
01/09/2003 - Uli Fechner - initial release

Definition at line 175 of file stringArray.c.

References AbortProgram, StringArray::arrayOfStrings, and StringArray::numberOfElements.

Referenced by readDataFromStream(), SmilesCompound_create(), SmilesCompound_destroy(), SmilesCompound_setName(), SmilesCompound_setSmiles(), and StringArray_removeElement().

void StringArray_display StringArray_Ptr  sAPtr,
FILE *  outputStream
 

Displays a structure StringArray.

The structure StringArray the pointer sAPtr refers to is displayed on the FILE* outputStream.

Parameters:
sAPtr pointer on the structure StringArray that is displayed
outputStream FILE* on the stream the output is sent to
Author:
Uli Fechner
Version:
01/09/2003 - Uli Fechner - initial release

08/09/2003 - Uli Fechner - small modifications in the output format

Definition at line 244 of file stringArray.c.

References StringArray::arrayOfStrings, and StringArray::numberOfElements.

Referenced by readDataFromStream(), and SmilesCompound_display().

void StringArray_extend const StringArray_Ptr  sAPtr  ) 
 

Extends the array size of a structure StringArray.

The array size of the structure StringArray is enlarged (more exactly: its size is doubled). This function is automatically called by StringArray_addElement if numberOfElements exceeds sizeOfArray.

Parameters:
sAPtr pointer on the structure StringArray containing the array that is extended
Author:
Uli Fechner
Version:
02/09/2003 - Uli Fechner - initial release

08/09/2003 - Uli Fechner - function rewritten from scratch; function header modified

Definition at line 212 of file stringArray.c.

References StringArray::arrayOfStrings, MemoryError, StringArray::numberOfElements, and StringArray::sizeOfArray.

Referenced by StringArray_addElement().

char * StringArray_getElement const StringArray_Ptr  sAPtr,
const int  index
 

The char* of the element with index index of structure StringArray is returned.

The value of the element with index index of the structure StringArray sAPtr points on is returned. If the index index is greater than (numberOfElements - 1 ), the program aborts with the call of the define IndexOutOfBoundsError.

Parameters:
sAPtr pointer on the structure StringArray that contains the char*
index index of the char* that is returned
Return values:
char* the char* with index index
Author:
Uli Fechner
Version:
01/09/2003 - Uli Fechner - initial release

Definition at line 425 of file stringArray.c.

References StringArray::arrayOfStrings, IndexOutOfBoundsError, and StringArray::numberOfElements.

Referenced by main(), StringArray_concatenate(), StringArray_copy(), and StringArray_mapConcatenate().

int StringArray_getNumberOfElements const StringArray_Ptr  sAPtr  ) 
 

Returns the number of elements of a structure StringArray.

The number of elements of the structure StringArray the pointer sAPtr refers to is returned.

Parameters:
sAPtr pointer on the structure StringArray of which the number of elements is returned
Return values:
int number of elements of the structure StringArray
Author:
Uli Fechner
Version:
01/09/2003 - Uli Fechner - initial release

Definition at line 370 of file stringArray.c.

References StringArray::numberOfElements.

Referenced by readDataFromStream(), and SmilesCompound_display().

int StringArray_getSizeOfArray const StringArray_Ptr  sAPtr  ) 
 

Returns the size of the array arrayOfStrings of a structure StringArray.

The size of the array arrayOfStrings of the structure StringArray is returned.

Parameters:
sAPtr pointer on the structure StringArray of which the size of the array is returned
Return values:
int size of the array arrayOfStrings of the structure StringArray
Author:
Uli Fechner
Version:
01/09/2003 - Uli Fechner - initial release

Definition at line 384 of file stringArray.c.

References StringArray::sizeOfArray.

void StringArray_mapConcatenate const StringArray_Ptr  sAPtr,
const char *  source
 

source is added to each element (char*) of sAPtr.

Attention:
Notrhing is added to empty strings (NULL).
Parameters:
sAPtr each element of sAPtr is modified
source this char* is concatenated to each element of sAPtr
Author:
Uli Fechner
Version:
17/12/2003 - Uli Fechner - initial release

Definition at line 339 of file stringArray.c.

References StringArray::arrayOfStrings, MemoryError, StringArray::numberOfElements, and StringArray_getElement().

Referenced by enqueueMolecules().

int StringArray_removeElement StringArray_Ptr  sAPtr,
const char *  string
 

All elements of sAPtr that are identical to string are removed.

Elements that are identical to string are removed from sAPtr. The return value is the number of times string is found in sAPtr.

Parameters:
sAPtr string is removed from the structure StringArray that is referred to by sAPtr
string all occurrences of string are removed from sAPtr
Return values:
int number of times string was removed from sAPtr
Author:
Uli Fechner
Version:
19/12/2003 - Uli Fechner - initial release

Definition at line 444 of file stringArray.c.

References StringArray::arrayOfStrings, StringArray::numberOfElements, StringArray_copy(), StringArray_destroy(), and StringArray_Ptr.

Referenced by SmilesCompound_removeFromArrayOfNames().


Generated on Tue Nov 9 16:27:12 2004 for retroflux by doxygen 1.3.6