ALib C++ Library
Library Version: 2412 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
TStringVector< TChar, TAllocator > Class Template Reference

Description:

template<typename TChar, typename TAllocator>
class alib::strings::util::TStringVector< TChar, TAllocator >

This is a simple type that publicly inherits container type std::vector to store a list of ALib strings, using an ALib {lang;Allocator}.

The (current) design of this class could be named "open" or "weak". This is due to the fact that a) The interface of the std::vector is public by inheritance, and b) Only a few additional interface methods have been added.

As a consequence, it is up to the user of the type to care about proper allocation and deallocation of string data: If a string is added using method Add, its content is copied to memory allocated with the allocator provided with construction. However, any other string may be added by using the interface of the std::vector.

The typical use case is with class TMonoAllocator or TLocalAllocator provided with module ALib Monomem:

  • Create a Mono- or LocalAllocator
  • Create a StringVectorMA, passing the allocator.
  • Gather some string data (copied or otherwise referenced).
  • Pass it over to a function or otherwise use the vector.
  • Destruct the objects.
Attention
With other use cases, especially when using type StringVectorPA in combination with class PoolAllocator, it has to be well thought how this type is used in respect to the need of freeing memory, especially when strings got allocated with method Add.
Template Parameters
TAllocatorThe allocator type, as prototyped with Allocator.

Definition at line 48 of file strings/util/stringvector.hpp.

#include <stringvector.hpp>

Inheritance diagram for TStringVector< TChar, TAllocator >:
[legend]
Collaboration diagram for TStringVector< TChar, TAllocator >:
[legend]

Public Type Index:

using AllocatorType = TAllocator
 The allocator type that TAllocator specifies.
 
using CharType = TChar
 Type definition of the given template parameter TChar.
 
using StringType = strings::TString<TChar>
 Type definition of the stored strings.
 

Public Method Index:

 TStringVector (AllocatorType &pAllocator)
 
 ~TStringVector ()=default
 Destructor.
 
integer Add (const strings::TString< TChar > &src)
 
AllocatorTypeGetAllocator () noexcept
 
integer Size () const noexcept
 
String TryGet (integer idx)
 

Protected Type Index:

using vectorBase
 The vector type that TAllocator specifies.
 

Type Definition Details:

◆ AllocatorType

template<typename TChar , typename TAllocator >
using AllocatorType = TAllocator

The allocator type that TAllocator specifies.

Definition at line 60 of file strings/util/stringvector.hpp.

◆ CharType

template<typename TChar , typename TAllocator >
using CharType = TChar

Type definition of the given template parameter TChar.

Definition at line 54 of file strings/util/stringvector.hpp.

◆ StringType

template<typename TChar , typename TAllocator >
using StringType = strings::TString<TChar>

Type definition of the stored strings.

Definition at line 57 of file strings/util/stringvector.hpp.

◆ vectorBase

template<typename TChar , typename TAllocator >
using vectorBase
protected
Initial value:
std::vector< StringType,
lang::StdContainerAllocator<StringType, TAllocator>>
strings::TString< TChar > StringType
Type definition of the stored strings.

The vector type that TAllocator specifies.

Definition at line 64 of file strings/util/stringvector.hpp.

Constructor(s) / Destructor Details:

◆ TStringVector()

template<typename TChar , typename TAllocator >
TStringVector ( AllocatorType & pAllocator)
inline

Constructor.

Parameters
pAllocatorThe allocator to use.

Definition at line 71 of file strings/util/stringvector.hpp.

Method Details:

◆ Add()

template<typename TChar , typename TAllocator >
integer Add ( const strings::TString< TChar > & src)
inline

Adds a string to the end of the list of strings.

Parameters
srcSource string to be copied.
Returns
The index of the created string in this vector.

Definition at line 93 of file strings/util/stringvector.hpp.

Here is the call graph for this function:

◆ GetAllocator()

template<typename TChar , typename TAllocator >
AllocatorType & GetAllocator ( )
inlinenoexcept

Returns the allocator provided with construction. If this was nulled, then this method can be used to set an external (or new) allocator using the assignment operator. Has to be set before the first insertion of data.

Returns
A reference to the internal allocator.

Definition at line 82 of file strings/util/stringvector.hpp.

◆ Size()

template<typename TChar , typename TAllocator >
integer Size ( ) const
inlinenoexcept

Returns the size of this vector as integer.

Returns
The number of strings stored.

Definition at line 87 of file strings/util/stringvector.hpp.

◆ TryGet()

template<typename TChar , typename TAllocator >
String TryGet ( integer idx)
inline

Receives the string at a valid idx. If the index is out of bounds, a nulled string is returned.

Parameters
idxThe index to try.
Returns
The string stored at idx, if available.

Definition at line 103 of file strings/util/stringvector.hpp.

Here is the call graph for this function:

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