Github   Telegram
Loading...
Searching...
No Matches
Classes | Enumerations | Functions | Variables
formats::common Namespace Reference

Common utilities for all the formats. More...

Classes

class  ItemsWrapper
 
class  Path
 Document/array element path storage. More...
 
class  TransferTag
 This tag class is used to move a ValueBuilder object without copying. More...
 

Enumerations

enum class  IteratorDirection {
  kForward = 1 ,
  kReverse = -1
}
 Helper to distinguish forward and reverse iterators for Value. More...
 
enum class  Type {
  kNull ,
  kArray ,
  kObject
}
 Common enum of types. More...
 

Functions

template<typename Value >
auto Items (Value &&value)
 
template<typename Value >
void Merge (typename Value::Builder &original, const Value &patch)
 Add to original new non-object elements from patch (overwriting the old ones, if any) and merge object elements recursively. More...
 
std::string GetIndexString (size_t index)
 Returns string of [idx], e.g. "[0]" or "[1025]".
 
void AppendPath (std::string &path, std::string_view key)
 
void AppendPath (std::string &path, std::size_t index)
 
std::string MakeChildPath (std::string_view parent, std::string_view key)
 
std::string MakeChildPath (std::string_view parent, std::size_t index)
 
template<typename Value >
std::enable_if_t< common::kIsFormatValue< Value >, Value > GetAtPath (Value parent, const std::vector< std::string > &path)
 Get the Value at path in parent. More...
 
template<typename ValueBuilder >
std::enable_if_t<!common::kIsFormatValue< ValueBuilder >, ValueBuilder > GetAtPath (ValueBuilder &parent, std::vector< std::string > &&path)
 Get the ValueBuilder at path in parent. More...
 
template<typename Value >
void SetAtPath (typename Value::Builder &parent, std::vector< std::string > &&path, Value new_value)
 Set the new_value along the path in the parent. More...
 
template<typename ValueBuilder >
void RemoveAtPath (ValueBuilder &parent, std::vector< std::string > &&path)
 Remove the element along the path in the parent. More...
 
std::vector< std::string > SplitPathString (std::string_view path)
 Split path to vector<std::string> by dots. More...
 

Variables

template<class Value >
constexpr bool kIsFormatValue
 
constexpr char kPathSeparator = '.'
 
constexpr char kPathRoot [] = "/"
 
constexpr char kPathPrefixSeparator [] = ":/"
 

Detailed Description

Common utilities for all the formats.

Enumeration Type Documentation

◆ IteratorDirection

Helper to distinguish forward and reverse iterators for Value.

Definition at line 8 of file iterator_direction.hpp.

◆ Type

enum class formats::common::Type
strong

Common enum of types.

Enumerator
kArray 

Value or ValueBuilder holds Null value.

kObject 

Value or ValueBuilder holds an Array.

Definition at line 12 of file type.hpp.

Function Documentation

◆ GetAtPath() [1/2]

template<typename Value >
std::enable_if_t< common::kIsFormatValue< Value >, Value > formats::common::GetAtPath ( Value  parent,
const std::vector< std::string > &  path 
)

Get the Value at path in parent.

Note
For empty path this function returns parent.
Exceptions
TypeMismatchExceptionif there is a non-object node in the middle of path

Definition at line 49 of file utils.hpp.

◆ GetAtPath() [2/2]

template<typename ValueBuilder >
std::enable_if_t<!common::kIsFormatValue< ValueBuilder >, ValueBuilder > formats::common::GetAtPath ( ValueBuilder &  parent,
std::vector< std::string > &&  path 
)

Get the ValueBuilder at path in parent.

Note
path must not be empty.
Exceptions
TypeMismatchExceptionif there is a non-object node in the middle of path

Definition at line 63 of file utils.hpp.

◆ Items()

template<typename Value >
auto formats::common::Items ( Value &&  value)
inline

Definition at line 68 of file items.hpp.

◆ Merge()

template<typename Value >
void formats::common::Merge ( typename Value::Builder &  original,
const Value &  patch 
)

Add to original new non-object elements from patch (overwriting the old ones, if any) and merge object elements recursively.

Note
For the missing patch, it does nothing with the original.
Arrays are not merged.

Definition at line 17 of file merge.hpp.

◆ RemoveAtPath()

template<typename ValueBuilder >
void formats::common::RemoveAtPath ( ValueBuilder &  parent,
std::vector< std::string > &&  path 
)

Remove the element along the path in the parent.

Note
If path is empty or there is no node at path, this function does nothing.
Exceptions
TypeMismatchExceptionif there is a non-object node in the middle of path

Definition at line 88 of file utils.hpp.

◆ SetAtPath()

template<typename Value >
void formats::common::SetAtPath ( typename Value::Builder &  parent,
std::vector< std::string > &&  path,
Value  new_value 
)

Set the new_value along the path in the parent.

Note
If path is empty it sets new_value to parent.
Exceptions
TypeMismatchExceptionif there is a non-object node in the middle of path

Definition at line 73 of file utils.hpp.

◆ SplitPathString()

std::vector< std::string > formats::common::SplitPathString ( std::string_view  path)

Split path to vector<std::string> by dots.

Note
If path has a double dot or a dot at the beginning or end, the result will contain an empty string.
Returns an empty vector if path is empty

Variable Documentation

◆ kIsFormatValue

template<class Value >
constexpr bool formats::common::kIsFormatValue
inlineconstexpr
Initial value:
=
meta::kIsDetected<impl::IsFormatValue, Value>

Used in Parse overloads that are templated on Value, avoids clashing with Parse from string

Definition at line 49 of file meta.hpp.

◆ kPathPrefixSeparator

constexpr char formats::common::kPathPrefixSeparator[] = ":/"
inlineconstexpr

Definition at line 15 of file path.hpp.

◆ kPathRoot

constexpr char formats::common::kPathRoot[] = "/"
inlineconstexpr

Definition at line 14 of file path.hpp.

◆ kPathSeparator

constexpr char formats::common::kPathSeparator = '.'
inlineconstexpr

Definition at line 13 of file path.hpp.