Thoth
A functional, expressive, asynchronous C++26 webdev library
Loading...
Searching...
No Matches
Thoth::Http::QueryParams Struct Reference

#include <QueryParams.hpp>

Public Types

using QueryKey = std::string
 
using QueryKeyRef = std::string_view
 
using QueryValue = std::string
 
using QueryValueRef = std::string_view
 
using QueryValues = std::vector< QueryValue >
 
using QueryPair = std::pair< QueryKey, QueryValues >
 
using MapType = Dsa::LinearMap< QueryKey, QueryValues >
 
using IterType = decltype(MapType().begin())
 
using CIterType = decltype(MapType().cbegin())
 

Public Member Functions

 QueryParams (const MapType &initAs)
 Create with an existing map.
 
 QueryParams (std::initializer_list< QueryPair > init)
 
bool Exists (QueryKeyRef key) const
 check if a key exists.
 
bool ValExists (QueryKeyRef key, QueryValueRef val) const
 check if a key=val exists.
 
void Add (QueryKeyRef key, QueryValue val)
 Add a value with the specified key.
 
bool Remove (QueryKeyRef key, QueryValueRef val)
 Remove a value with the specified key.
 
bool RemoveKey (QueryKeyRef key)
 Remove a key and all values associated.
 
bool SetIfNull (QueryKeyRef key, QueryValueRef value)
 If key not exists, set it to value.
 
std::optional< QueryValues * > Get (QueryKeyRef key)
 Get the reference of a key but don't create if it not exists.
 
IterType begin ()
 
IterType end ()
 
CIterType begin () const
 
CIterType end () const
 
void Clear ()
 Clear all keys.
 
size_t Size () const
 
bool Empty () const
 
QueryValuesoperator[] (QueryKeyRef key)
 
bool operator== (const QueryParams &other) const
 

Static Public Member Functions

static QueryParams Parse (std::string_view paramsStr)
 Parse the query as it is.
 
static std::expected< QueryParams, RequestErrorParseDecodified (std::string_view str)
 Tries to decode and then parse.
 

Friends

struct std::formatter< QueryParams >
 
struct std::hash< QueryParams >
 

Member Typedef Documentation

◆ CIterType

using Thoth::Http::QueryParams::CIterType = decltype(MapType().cbegin())

◆ IterType

◆ MapType

◆ QueryKey

◆ QueryKeyRef

using Thoth::Http::QueryParams::QueryKeyRef = std::string_view

◆ QueryPair

◆ QueryValue

◆ QueryValueRef

using Thoth::Http::QueryParams::QueryValueRef = std::string_view

◆ QueryValues

Constructor & Destructor Documentation

◆ QueryParams() [1/2]

Thoth::Http::QueryParams::QueryParams ( const MapType initAs)
explicit

Create with an existing map.

◆ QueryParams() [2/2]

Thoth::Http::QueryParams::QueryParams ( std::initializer_list< QueryPair init)

Member Function Documentation

◆ Add()

void Thoth::Http::QueryParams::Add ( QueryKeyRef  key,
QueryValue  val 
)

Add a value with the specified key.

Parameters
keyThe key where it will be added.
valThe value to be added.

◆ begin() [1/2]

IterType Thoth::Http::QueryParams::begin ( )

◆ begin() [2/2]

CIterType Thoth::Http::QueryParams::begin ( ) const

◆ Clear()

void Thoth::Http::QueryParams::Clear ( )

Clear all keys.

◆ Empty()

bool Thoth::Http::QueryParams::Empty ( ) const
Returns
True if Size() is 0.

◆ end() [1/2]

IterType Thoth::Http::QueryParams::end ( )

◆ end() [2/2]

CIterType Thoth::Http::QueryParams::end ( ) const

◆ Exists()

bool Thoth::Http::QueryParams::Exists ( QueryKeyRef  key) const

check if a key exists.

Parameters
keyThe key to be checked.
Returns
True if the key exists, false otherwise.

◆ Get()

std::optional< QueryValues * > Thoth::Http::QueryParams::Get ( QueryKeyRef  key)

Get the reference of a key but don't create if it not exists.

Parameters
keyThe key.
Returns
QueryValues* if the key exists, std::nullopt otherwise.

◆ operator==()

bool Thoth::Http::QueryParams::operator== ( const QueryParams other) const
Returns
True if both queries match.

◆ operator[]()

QueryValues & Thoth::Http::QueryParams::operator[] ( QueryKeyRef  key)
Returns
The QueryValues& associated with a key. Create if it not exists. STL containers has many problems so it must be QueryKey.

◆ Parse()

static QueryParams Thoth::Http::QueryParams::Parse ( std::string_view  paramsStr)
static

Parse the query as it is.

◆ ParseDecodified()

static std::expected< QueryParams, RequestError > Thoth::Http::QueryParams::ParseDecodified ( std::string_view  str)
static

Tries to decode and then parse.

◆ Remove()

bool Thoth::Http::QueryParams::Remove ( QueryKeyRef  key,
QueryValueRef  val 
)

Remove a value with the specified key.

Parameters
keyThe key where it will be removed.
valThe value to be removed.
Returns
True if the key exists, false otherwise.

◆ RemoveKey()

bool Thoth::Http::QueryParams::RemoveKey ( QueryKeyRef  key)

Remove a key and all values associated.

Parameters
keyThe key that it will be removed.
Returns
True if the key exists, false otherwise.

◆ SetIfNull()

bool Thoth::Http::QueryParams::SetIfNull ( QueryKeyRef  key,
QueryValueRef  value 
)

If key not exists, set it to value.

Parameters
keyThe key.
valueThe value to be added.
Returns
True if the key not exists, false otherwise.

◆ Size()

size_t Thoth::Http::QueryParams::Size ( ) const
Returns
The count of keys.

◆ ValExists()

bool Thoth::Http::QueryParams::ValExists ( QueryKeyRef  key,
QueryValueRef  val 
) const

check if a key=val exists.

Parameters
keyThe key to be checked.
valThe key to be checked.
Returns
True if the key exists, false otherwise.

Friends And Related Symbol Documentation

◆ std::formatter< QueryParams >

friend struct std::formatter< QueryParams >
friend

◆ std::hash< QueryParams >

friend struct std::hash< QueryParams >
friend

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