# PStringArray Class Reference

This is an array collection class of `PString` objects. More...

`#include <pstring.h>`

Inheritance diagram for PStringArray:

List of all members.

## Construction

| PStringArray (PINDEX count, char const *const *strarr, PBoolean caseless=false)
| Create a PStringArray from the array of C strings.
| PStringArray (const PString &str)
| Create a PStringArray of length one from the single string.
| PStringArray (const PStringList &list)
| Create a PStringArray from the list of strings.
| PStringArray (const PSortedStringList &list)
| Create a PStringArray from the sorted list strings.
| PStringArray (const std::vector< PString > &vec)
| Create a PStringArray from a vector of PStrings.
| PStringArray (const std::vector< std::string > &vec)
| Create a PStringArray from a vector of std::string.
template<typename stlContainer>
static PStringArray | container (const stlContainer &vec)
| Create a PStringArray from an STL container.

## Public Member Functions

Overrides from class PObject
virtual void | ReadFrom (istream &strm)
| Input the contents of the object from the stream.
New functions for class
PINDEX | GetStringsIndex (const PString &str) const
| As for `GetValuesIndex()` but takes a PString argument so that literals will be automatically converted.
PString | operator[] (PINDEX index) const
| Retrieve a reference to the object in the array.
PString & | operator[] (PINDEX index)
| Retrieve a reference to the object in the array.
PINDEX | AppendString (const PString &str)
| Append a string to the array.
PStringArray & | operator+= (const PStringArray &array)
| Concatenate a PString or PStringArray to the array.
PStringArray & | operator+= (const PString &str)
PStringArray | operator+ (const PStringArray &array)
| Create a new PStringArray, and add PString or PStringArray to it a new PStringArray.
PStringArray | operator+ (const PString &str)
char ** | ToCharArray (PCharArray *storage=NULL) const
| Create an array of C strings.

## Detailed Description

This is an array collection class of `PString` objects.

It has all the usual functions for a collection, with the object types set to `PString` pointers.

In addition some addition functions are added that take a const `PString` reference instead of a pointer as most standard collection functions do. This is more convenient for when string expressions are used as parameters to function in the collection.

See the `PAbstractArray` and `PArray` classes and `PDECLARE_ARRAY` macro for more information.

## Constructor & Destructor Documentation

PStringArray::PStringArray | ( | PINDEX | count,
|  | char const *const * | strarr,
|  | PBoolean | caseless = `false` |
| ) |  |  |

Create a PStringArray from the array of C strings.

If count is P_MAX_INDEX then strarr is assumed to point to an array of strings where the last pointer is NULL.

Parameters:

  count | Count of strings in array
  strarr | Array of C strings
  caseless | New strings are to be PCaselessStrings

PStringArray::PStringArray | ( | const PString & | str | ) |

Create a PStringArray of length one from the single string.

Parameters:

  str | Single string to convert to an array of one.

PStringArray::PStringArray | ( | const PStringList & | list | ) |

Create a PStringArray from the list of strings.

Parameters:

  list | List of strings to convert to array.

PStringArray::PStringArray | ( | const PSortedStringList & | list | ) |

Create a PStringArray from the sorted list strings.

Parameters:

  list | List of strings to convert to array.

PStringArray::PStringArray | ( | const std::vector< PString > & | vec | ) | `[inline]`

Create a PStringArray from a vector of PStrings.

PStringArray::PStringArray | ( | const std::vector< std::string > & | vec | ) | `[inline]`

Create a PStringArray from a vector of std::string.

## Member Function Documentation

PINDEX PStringArray::AppendString | ( | const PString & | str | ) |

Append a string to the array.

Parameters:

  str | String to append.

template<typename stlContainer>

static PStringArray PStringArray::container | ( | const stlContainer & | vec | ) | `[inline, static]`

Create a PStringArray from an STL container.

PINDEX PStringArray::GetStringsIndex | ( | const PString & | str | ) | const

As for `GetValuesIndex()` but takes a PString argument so that literals will be automatically converted.

Returns:
  Index of string in array or P_MAX_INDEX if not found.

Parameters:

  str | String to search for index of

PStringArray PStringArray::operator+ | ( | const PString & | str | ) |

PStringArray PStringArray::operator+ | ( | const PStringArray & | array | ) |

Create a new PStringArray, and add PString or PStringArray to it a new PStringArray.

Returns:
  A new PStringArray with the additional elements(s)

PStringArray& PStringArray::operator+= | ( | const PString & | str | ) |

PStringArray& PStringArray::operator+= | ( | const PStringArray & | array | ) |

Concatenate a PString or PStringArray to the array.

Returns:
  The PStringArray with the new items appended

PString& PStringArray::operator[] | ( | PINDEX | index | ) |

Retrieve a reference to the object in the array.

If there was not an object at that ordinal position or the index was beyond the size of the array then the function will create a new one.

Returns:
  reference to the object at `index` position.

Parameters:

  index | Index position in the collection of the object.

PString PStringArray::operator[] | ( | PINDEX | index | ) | const

Retrieve a reference to the object in the array.

If there was not an object at that ordinal position or the index was beyond the size of the array then the function asserts.

Returns:
  Reference to the object at `index` position.

Parameters:

  index | Index position in the collection of the object.

Reimplemented from PArray< T >.

virtual void PStringArray::ReadFrom | ( | istream & | strm | ) | `[virtual]`

Input the contents of the object from the stream.

This is primarily used by the standard `operator>>` function.

The default behaviour reads '\n' separated strings until `!strm.good()`.

Reimplemented from PObject.

char** PStringArray::ToCharArray | ( | PCharArray * | storage = `NULL` | ) | const

Create an array of C strings.

If storage is NULL then this returns a single pointer that must be disposed of using free(). Note that each of the strings are part of the same memory allocation so only one free() is required.

If storage is not null then that is used to allocate the memory.

The documentation for this class was generated from the following file:

- pstring.h