arg_router  1.4.0
C++ command line argument parsing and routing
arg_router::utility::dynamic_string_view Class Reference

#include <arg_router/utility/dynamic_string_view.hpp>

Public Types

using value_type = string::value_type
 ! Value type
 
using allocator_type = string::allocator_type
 ! Allocator type
 
using size_type = string::size_type
 ! Size type
 
using difference_type = string::difference_type
 ! Difference type
 
using const_reference = string::const_reference
 ! Reference type
 
using const_pointer = string::const_pointer
 ! Pointer type
 
using const_iterator = std::string_view::const_iterator
 ! Iterator type
 

Public Member Functions

 dynamic_string_view (std::string_view sv={}) noexcept
 
 dynamic_string_view (const char *str) noexcept
 
 dynamic_string_view (string &&str) noexcept
 
 dynamic_string_view (const dynamic_string_view &other)
 
 dynamic_string_view (dynamic_string_view &&other) noexcept
 
dynamic_string_viewoperator= (dynamic_string_view other)
 
void convert_to_internal_storage ()
 
 operator std::string_view () const noexcept
 
bool operator== (const dynamic_string_view &other) const noexcept
 
bool operator!= (const dynamic_string_view &other) const noexcept
 
template<typename T , typename = std::enable_if_t<!std::is_same_v<std::decay_t<T>, dynamic_string_view>>>
dynamic_string_viewoperator+= (T &&other)
 
size_type size () const noexcept
 
size_type internal_storage_size () const noexcept
 
bool empty () const noexcept
 
const_iterator begin () const noexcept
 
const_iterator end () const noexcept
 

Friends

void swap (dynamic_string_view &a, dynamic_string_view &b)
 

Detailed Description

A view that can own the memory pointed at by the view if required.

This is a view until the user needs to modify the string, at which point the string data is copied into internal storage.

Definition at line 19 of file dynamic_string_view.hpp.

Constructor & Destructor Documentation

◆ dynamic_string_view() [1/5]

arg_router::utility::dynamic_string_view::dynamic_string_view ( std::string_view  sv = {})
inlinenoexcept

Default constructor.

View is assigned from sv and internal storage is empty.

Parameters
svInitial view data, or empty

Definition at line 36 of file dynamic_string_view.hpp.

◆ dynamic_string_view() [2/5]

arg_router::utility::dynamic_string_view::dynamic_string_view ( const char *  str)
inlinenoexcept

String literal constructor.

View is assigned from str and internal storage is empty.

Parameters
strInitial view data, or empty

Definition at line 44 of file dynamic_string_view.hpp.

◆ dynamic_string_view() [3/5]

arg_router::utility::dynamic_string_view::dynamic_string_view ( string &&  str)
inlinenoexcept

String move constructor.

str is moved into internal storage. View is set to point to the internal storage.

Parameters
strInitial string data

Definition at line 52 of file dynamic_string_view.hpp.

◆ dynamic_string_view() [4/5]

arg_router::utility::dynamic_string_view::dynamic_string_view ( const dynamic_string_view other)
inline

Copy constructor.

If other is just a view, this instance will be duplicate. Otherwise the internal storage is copied too and the view updated to match

Parameters
otherInstance to copy from

Definition at line 60 of file dynamic_string_view.hpp.

◆ dynamic_string_view() [5/5]

arg_router::utility::dynamic_string_view::dynamic_string_view ( dynamic_string_view &&  other)
inlinenoexcept

Move constructor.

Parameters
otherInstance to move from

Definition at line 71 of file dynamic_string_view.hpp.

Member Function Documentation

◆ begin()

const_iterator arg_router::utility::dynamic_string_view::begin ( ) const
inlinenoexcept
Returns
Iterator to beginning of the view

Definition at line 160 of file dynamic_string_view.hpp.

◆ convert_to_internal_storage()

void arg_router::utility::dynamic_string_view::convert_to_internal_storage ( )
inline

Copy the view data into internal storage and update the view to match.

Does nothing if already in internal storage.

Definition at line 91 of file dynamic_string_view.hpp.

◆ empty()

bool arg_router::utility::dynamic_string_view::empty ( ) const
inlinenoexcept
Returns
True if the view is empty

Definition at line 157 of file dynamic_string_view.hpp.

◆ end()

const_iterator arg_router::utility::dynamic_string_view::end ( ) const
inlinenoexcept
Returns
Iterator to one-past-the-end of the view

Definition at line 162 of file dynamic_string_view.hpp.

◆ internal_storage_size()

size_type arg_router::utility::dynamic_string_view::internal_storage_size ( ) const
inlinenoexcept
Returns
Number of characters in internal storage

Definition at line 155 of file dynamic_string_view.hpp.

◆ operator std::string_view()

arg_router::utility::dynamic_string_view::operator std::string_view ( ) const
inlinenoexcept

Implicit conversion operator for std::string_view.

Returns
The view

Definition at line 104 of file dynamic_string_view.hpp.

◆ operator!=()

bool arg_router::utility::dynamic_string_view::operator!= ( const dynamic_string_view other) const
inlinenoexcept

Inequality operator.

Parameters
otherInstance to compare against
Returns
True if the same

Definition at line 121 of file dynamic_string_view.hpp.

◆ operator+=()

template<typename T , typename = std::enable_if_t<!std::is_same_v<std::decay_t<T>, dynamic_string_view>>>
dynamic_string_view& arg_router::utility::dynamic_string_view::operator+= ( T &&  other)
inline

In-place concatenation operator.

Template Parameters
TType of other
Parameters
otherString-like instance to append
Returns
Reference to this

Definition at line 134 of file dynamic_string_view.hpp.

◆ operator=()

dynamic_string_view& arg_router::utility::dynamic_string_view::operator= ( dynamic_string_view  other)
inline

Assignment operator.

Parameters
otherInstance to copy or move from
Returns
Reference to this

Definition at line 81 of file dynamic_string_view.hpp.

◆ operator==()

bool arg_router::utility::dynamic_string_view::operator== ( const dynamic_string_view other) const
inlinenoexcept

Equality operator.

Parameters
otherInstance to compare against
Returns
True if the same

Definition at line 111 of file dynamic_string_view.hpp.

◆ size()

size_type arg_router::utility::dynamic_string_view::size ( ) const
inlinenoexcept
Returns
Number of characters

Definition at line 153 of file dynamic_string_view.hpp.

Friends And Related Function Documentation

◆ swap

void swap ( dynamic_string_view a,
dynamic_string_view b 
)
friend

Swaps a and b.

Parameters
aFirst instance
bSecond instance

Definition at line 169 of file dynamic_string_view.hpp.


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