ALib C++ Library
Library Version: 2510 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
alib::strings::util::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 54 of file ALib.Strings.Vector.H.

#include <ALib.Strings.Vector.H>

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

Public Type Index:

using AllocatorType = TAllocator
 The allocator type that TAllocator specifies.
 

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 alib::strings::util::TStringVector< TChar, TAllocator >::AllocatorType = TAllocator

The allocator type that TAllocator specifies.

Definition at line 59 of file ALib.Strings.Vector.H.

◆ vectorBase

template<typename TChar, typename TAllocator>
using alib::strings::util::TStringVector< TChar, TAllocator >::vectorBase
protected
Initial value:

The vector type that TAllocator specifies.

Definition at line 63 of file ALib.Strings.Vector.H.

Constructor(s) / Destructor Details:

◆ TStringVector()

template<typename TChar, typename TAllocator>
alib::strings::util::TStringVector< TChar, TAllocator >::TStringVector ( AllocatorType & pAllocator)
inline

Constructor.

Parameters
pAllocatorThe allocator to use.

Definition at line 70 of file ALib.Strings.Vector.H.

Method Details:

◆ Add()

template<typename TChar, typename TAllocator>
integer alib::strings::util::TStringVector< TChar, TAllocator >::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 92 of file ALib.Strings.Vector.H.

◆ GetAllocator()

template<typename TChar, typename TAllocator>
AllocatorType & alib::strings::util::TStringVector< TChar, TAllocator >::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 81 of file ALib.Strings.Vector.H.

◆ Size()

template<typename TChar, typename TAllocator>
integer alib::strings::util::TStringVector< TChar, TAllocator >::Size ( ) const
inlinenoexcept

Returns the size of this vector as integer.

Returns
The number of strings stored.

Definition at line 86 of file ALib.Strings.Vector.H.

◆ TryGet()

template<typename TChar, typename TAllocator>
String alib::strings::util::TStringVector< TChar, TAllocator >::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 102 of file ALib.Strings.Vector.H.


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