SourcePP
Several modern C++20 libraries for sanely parsing Valve's formats.
Loading...
Searching...
No Matches
kvpp::KV1ElementWritable< S > Class Template Reference

#include <KV1Writer.h>

Collaboration diagram for kvpp::KV1ElementWritable< S >:

Public Types

using iterator = std::vector<KV1ElementWritable>::iterator
using const_iterator = std::vector<KV1ElementWritable>::const_iterator

Public Member Functions

std::string_view getKey () const
 Get the key associated with the element.
void setKey (std::string_view key_)
 Set the key associated with the element.
std::string_view getValue () const
 Get the value associated with the element.
template<KV1ValueType V>
V getValue () const
 Get the value associated with the element as the given type.
template<KV1ValueType V>
void setValue (V value_)
 Set the value associated with the element.
template<KV1ValueType V>
KV1ElementWritable & operator= (V value_)
 Set the value associated with the element.
std::string_view getConditional () const
 Get the conditional associated with the element.
void setConditional (std::string_view conditional_)
 Set the conditional associated with the element.
bool hasChild (std::string_view childKey) const
 Check if the element has one or more children with the given key.
template<KV1ValueType V = std::string_view>
KV1ElementWritable & addChild (std::string_view key_, V value_={}, std::string_view conditional_="")
uint64_t getChildCount () const
 Get the number of child elements.
uint64_t getChildCount (std::string_view childKey) const
 Get the number of child elements with the given key.
const std::vector< KV1ElementWritable > & getChildren () const
 Get the child elements of the element.
std::vector< KV1ElementWritable > & getChildren ()
 Get the child elements of the element.
constexpr iterator begin ()
constexpr iterator end ()
constexpr const_iterator begin () const
constexpr const_iterator end () const
constexpr const_iterator cbegin () const
constexpr const_iterator cend () const
const KV1ElementWritable & operator[] (unsigned int n) const
 Get the child element of the element at the given index.
KV1ElementWritable & operator[] (unsigned int n)
 Get the child element of the element at the given index.
const KV1ElementWritable & operator[] (std::string_view childKey) const
 Get the first child element of the element with the given key.
KV1ElementWritable & operator[] (std::string_view childKey)
 Get the first child element of the element with the given key, or create a new element if it doesn't exist.
const KV1ElementWritable & operator() (std::string_view childKey) const
 Get the first child element of the element with the given key.
KV1ElementWritable & operator() (std::string_view childKey)
 Get the first child element of the element with the given key, or create a new element if it doesn't exist.
const KV1ElementWritable & operator() (std::string_view childKey, unsigned int n) const
 Get the nth child element of the element with the given key.
KV1ElementWritable & operator() (std::string_view childKey, unsigned int n)
 Get the nth child element of the element with the given key, or create a new element if it doesn't exist.
void removeChild (unsigned int n)
 Remove a child element from the element.
void removeChild (std::string_view childKey, int n=-1)
 Remove a child element from the element with the given key. -1 means all children with the given key.
bool isInvalid () const
 Check if the given element is invalid.
 operator bool () const

Static Public Member Functions

static const KV1ElementWritable & getInvalid ()

Protected Member Functions

 KV1ElementWritable ()=default

Static Protected Member Functions

static void read (BufferStreamReadOnly &stream, std::vector< KV1ElementWritable > &elements, const sourcepp::parser::text::EscapeSequenceMap &escapeSequences)
static void write (BufferStream &stream, const std::vector< KV1ElementWritable > &elements, unsigned short indentLevel, const sourcepp::parser::text::EscapeSequenceMap &escapeSequences)

Protected Attributes

S key = ""
S value = ""
S conditional = ""
std::vector< KV1ElementWritable > children

Detailed Description

template<typename S = std::string>
requires std::convertible_to<S, std::string>
class kvpp::KV1ElementWritable< S >

Definition at line 13 of file KV1Writer.h.

Member Typedef Documentation

◆ const_iterator

template<typename S = std::string>
using kvpp::KV1ElementWritable< S >::const_iterator = std::vector<KV1ElementWritable>::const_iterator

Definition at line 134 of file KV1Writer.h.

◆ iterator

template<typename S = std::string>
using kvpp::KV1ElementWritable< S >::iterator = std::vector<KV1ElementWritable>::iterator

Definition at line 124 of file KV1Writer.h.

Constructor & Destructor Documentation

◆ KV1ElementWritable()

template<typename S = std::string>
kvpp::KV1ElementWritable< S >::KV1ElementWritable ( )
protecteddefault

Member Function Documentation

◆ addChild()

template<typename S = std::string>
template<KV1ValueType V = std::string_view>
KV1ElementWritable & kvpp::KV1ElementWritable< S >::addChild ( std::string_view key_,
V value_ = {},
std::string_view conditional_ = "" )
inline

Definition at line 89 of file KV1Writer.h.

◆ begin() [1/2]

template<typename S = std::string>
iterator kvpp::KV1ElementWritable< S >::begin ( )
inlinenodiscardconstexpr

Definition at line 126 of file KV1Writer.h.

◆ begin() [2/2]

template<typename S = std::string>
const_iterator kvpp::KV1ElementWritable< S >::begin ( ) const
inlinenodiscardconstexpr

Definition at line 136 of file KV1Writer.h.

◆ cbegin()

template<typename S = std::string>
const_iterator kvpp::KV1ElementWritable< S >::cbegin ( ) const
inlinenodiscardconstexpr

Definition at line 144 of file KV1Writer.h.

◆ cend()

template<typename S = std::string>
const_iterator kvpp::KV1ElementWritable< S >::cend ( ) const
inlinenodiscardconstexpr

Definition at line 148 of file KV1Writer.h.

◆ end() [1/2]

template<typename S = std::string>
iterator kvpp::KV1ElementWritable< S >::end ( )
inlinenodiscardconstexpr

Definition at line 130 of file KV1Writer.h.

◆ end() [2/2]

template<typename S = std::string>
const_iterator kvpp::KV1ElementWritable< S >::end ( ) const
inlinenodiscardconstexpr

Definition at line 140 of file KV1Writer.h.

◆ getChildCount() [1/2]

template<typename S = std::string>
uint64_t kvpp::KV1ElementWritable< S >::getChildCount ( ) const
inlinenodiscard

Get the number of child elements.

Definition at line 99 of file KV1Writer.h.

◆ getChildCount() [2/2]

template<typename S = std::string>
uint64_t kvpp::KV1ElementWritable< S >::getChildCount ( std::string_view childKey) const
inlinenodiscard

Get the number of child elements with the given key.

Definition at line 104 of file KV1Writer.h.

◆ getChildren() [1/2]

template<typename S = std::string>
std::vector< KV1ElementWritable > & kvpp::KV1ElementWritable< S >::getChildren ( )
inlinenodiscard

Get the child elements of the element.

Definition at line 120 of file KV1Writer.h.

◆ getChildren() [2/2]

template<typename S = std::string>
const std::vector< KV1ElementWritable > & kvpp::KV1ElementWritable< S >::getChildren ( ) const
inlinenodiscard

Get the child elements of the element.

Definition at line 115 of file KV1Writer.h.

◆ getConditional()

template<typename S = std::string>
std::string_view kvpp::KV1ElementWritable< S >::getConditional ( ) const
inlinenodiscard

Get the conditional associated with the element.

Definition at line 73 of file KV1Writer.h.

◆ getInvalid()

template<typename S = std::string>
const KV1ElementWritable & kvpp::KV1ElementWritable< S >::getInvalid ( )
inlinestatic

Definition at line 252 of file KV1Writer.h.

◆ getKey()

template<typename S = std::string>
std::string_view kvpp::KV1ElementWritable< S >::getKey ( ) const
inlinenodiscard

Get the key associated with the element.

Definition at line 16 of file KV1Writer.h.

◆ getValue() [1/2]

template<typename S = std::string>
template<KV1ValueType V>
V kvpp::KV1ElementWritable< S >::getValue ( ) const
inlinenodiscard

Get the value associated with the element as the given type.

Definition at line 32 of file KV1Writer.h.

◆ getValue() [2/2]

template<typename S = std::string>
std::string_view kvpp::KV1ElementWritable< S >::getValue ( ) const
inlinenodiscard

Get the value associated with the element.

Definition at line 26 of file KV1Writer.h.

◆ hasChild()

template<typename S = std::string>
bool kvpp::KV1ElementWritable< S >::hasChild ( std::string_view childKey) const
inlinenodiscard

Check if the element has one or more children with the given key.

Definition at line 83 of file KV1Writer.h.

◆ isInvalid()

template<typename S = std::string>
bool kvpp::KV1ElementWritable< S >::isInvalid ( ) const
inlinenodiscard

Check if the given element is invalid.

Definition at line 248 of file KV1Writer.h.

◆ operator bool()

template<typename S = std::string>
kvpp::KV1ElementWritable< S >::operator bool ( ) const
inlineexplicitnodiscard

Definition at line 257 of file KV1Writer.h.

◆ operator()() [1/4]

template<typename S = std::string>
KV1ElementWritable & kvpp::KV1ElementWritable< S >::operator() ( std::string_view childKey)
inlinenodiscard

Get the first child element of the element with the given key, or create a new element if it doesn't exist.

Definition at line 183 of file KV1Writer.h.

◆ operator()() [2/4]

template<typename S = std::string>
const KV1ElementWritable & kvpp::KV1ElementWritable< S >::operator() ( std::string_view childKey) const
inlinenodiscard

Get the first child element of the element with the given key.

Definition at line 173 of file KV1Writer.h.

◆ operator()() [3/4]

template<typename S = std::string>
KV1ElementWritable & kvpp::KV1ElementWritable< S >::operator() ( std::string_view childKey,
unsigned int n )
inlinenodiscard

Get the nth child element of the element with the given key, or create a new element if it doesn't exist.

Definition at line 209 of file KV1Writer.h.

◆ operator()() [4/4]

template<typename S = std::string>
const KV1ElementWritable & kvpp::KV1ElementWritable< S >::operator() ( std::string_view childKey,
unsigned int n ) const
inlinenodiscard

Get the nth child element of the element with the given key.

Definition at line 193 of file KV1Writer.h.

◆ operator=()

template<typename S = std::string>
template<KV1ValueType V>
KV1ElementWritable & kvpp::KV1ElementWritable< S >::operator= ( V value_)
inline

Set the value associated with the element.

Definition at line 67 of file KV1Writer.h.

◆ operator[]() [1/4]

template<typename S = std::string>
KV1ElementWritable & kvpp::KV1ElementWritable< S >::operator[] ( std::string_view childKey)
inlinenodiscard

Get the first child element of the element with the given key, or create a new element if it doesn't exist.

Definition at line 168 of file KV1Writer.h.

◆ operator[]() [2/4]

template<typename S = std::string>
const KV1ElementWritable & kvpp::KV1ElementWritable< S >::operator[] ( std::string_view childKey) const
inlinenodiscard

Get the first child element of the element with the given key.

Definition at line 163 of file KV1Writer.h.

◆ operator[]() [3/4]

template<typename S = std::string>
KV1ElementWritable & kvpp::KV1ElementWritable< S >::operator[] ( unsigned int n)
inlinenodiscard

Get the child element of the element at the given index.

Definition at line 158 of file KV1Writer.h.

◆ operator[]() [4/4]

template<typename S = std::string>
const KV1ElementWritable & kvpp::KV1ElementWritable< S >::operator[] ( unsigned int n) const
inlinenodiscard

Get the child element of the element at the given index.

Definition at line 153 of file KV1Writer.h.

◆ read()

template<typename S = std::string>
void kvpp::KV1ElementWritable< S >::read ( BufferStreamReadOnly & stream,
std::vector< KV1ElementWritable< S > > & elements,
const sourcepp::parser::text::EscapeSequenceMap & escapeSequences )
inlinestaticprotected

Definition at line 264 of file KV1Writer.h.

◆ removeChild() [1/2]

template<typename S = std::string>
void kvpp::KV1ElementWritable< S >::removeChild ( std::string_view childKey,
int n = -1 )
inline

Remove a child element from the element with the given key. -1 means all children with the given key.

Definition at line 232 of file KV1Writer.h.

◆ removeChild() [2/2]

template<typename S = std::string>
void kvpp::KV1ElementWritable< S >::removeChild ( unsigned int n)
inline

Remove a child element from the element.

Definition at line 225 of file KV1Writer.h.

◆ setConditional()

template<typename S = std::string>
void kvpp::KV1ElementWritable< S >::setConditional ( std::string_view conditional_)
inline

Set the conditional associated with the element.

Definition at line 78 of file KV1Writer.h.

◆ setKey()

template<typename S = std::string>
void kvpp::KV1ElementWritable< S >::setKey ( std::string_view key_)
inline

Set the key associated with the element.

Definition at line 21 of file KV1Writer.h.

◆ setValue()

template<typename S = std::string>
template<KV1ValueType V>
void kvpp::KV1ElementWritable< S >::setValue ( V value_)
inline

Set the value associated with the element.

Definition at line 55 of file KV1Writer.h.

◆ write()

template<typename S = std::string>
void kvpp::KV1ElementWritable< S >::write ( BufferStream & stream,
const std::vector< KV1ElementWritable< S > > & elements,
unsigned short indentLevel,
const sourcepp::parser::text::EscapeSequenceMap & escapeSequences )
inlinestaticprotected

Definition at line 302 of file KV1Writer.h.

Member Data Documentation

◆ children

template<typename S = std::string>
std::vector<KV1ElementWritable> kvpp::KV1ElementWritable< S >::children
protected

Definition at line 342 of file KV1Writer.h.

◆ conditional

template<typename S = std::string>
S kvpp::KV1ElementWritable< S >::conditional = ""
protected

Definition at line 341 of file KV1Writer.h.

◆ key

template<typename S = std::string>
S kvpp::KV1ElementWritable< S >::key = ""
protected

Definition at line 339 of file KV1Writer.h.

◆ value

template<typename S = std::string>
S kvpp::KV1ElementWritable< S >::value = ""
protected

Definition at line 340 of file KV1Writer.h.


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