RestLink 2.2.0
Powerfull Rest Client for Qt
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
RestLink::Parameter Class Reference

Represents a generic parameter, which could be a path, query, or header parameter, with support for special values and flags. More...

#include <parameter.h>

Inherited by RestLink::Header, RestLink::PathParameter, and RestLink::QueryParameter.

Public Types

enum  Flag { NoFlag = 0x0 , Authentication = 0x1 , Secret = 0x2 , Locale = 0x64 }
 Defines flags used to specify special attributes for a parameter. More...
 
enum  Type { BaseType , PathParameterType , QueryParameterType , HeaderType }
 Defines the possible types of parameters. More...
 

Public Member Functions

 Parameter ()
 Default constructor for Parameter class.
 
 Parameter (const Parameter &other)
 Copy constructor for Parameter class.
 
 Parameter (Parameter &&other)
 Move constructor for Parameter class.
 
 ~Parameter ()
 Destructor for Parameter class.
 
Parameteroperator= (const Parameter &other)
 Copy assignment operator for Parameter class.
 
Parameteroperator= (Parameter &&other)
 Move assignment operator for Parameter class.
 
QString name () const
 Retrieves the name of the parameter.
 
void setName (const QString &name)
 Sets the name of the parameter.
 
QVariant value () const
 Retrieves the value of the parameter.
 
void setValue (const QVariant &value)
 Sets the value of the parameter.
 
QVariant specialValue (Api *api) const
 Returns a special value for the parameter, based on the provided API.
 
QVariantList specialValues (Api *api) const
 Returns a list of special values for the parameter, based on the provided API.
 
bool hasValue (const QVariant &value) const
 Checks if the parameter contains a specific value.
 
void addValue (const QVariant &value)
 Adds a value to the parameter.
 
void removeValue (const QVariant &value)
 Removes a value from the parameter.
 
QList< QVariant > values () const
 Returns a list of all values associated with the parameter.
 
void setValues (const QList< QVariant > &values)
 Sets a list of values for the parameter.
 
bool hasFlag (Flag flag) const
 Checks if a specific flag is set for the parameter.
 
Flags flags () const
 Retrieves all flags set for the parameter.
 
void setFlag (Flag flag, bool on=true)
 Sets or clears a specific flag for the parameter.
 
void setFlags (const Flags &flags)
 Sets multiple flags for the parameter.
 
Type type () const
 Returns the type of the parameter.
 
bool isValid () const
 Checks if the parameter is valid.
 
PathParameter toPathParameter () const
 
QueryParameter toQueryParameter () const
 
Header toHeader () const
 
QJsonObject toJsonObject () const
 Converts the parameter to a QJsonObject.
 
bool operator== (const Parameter &other) const
 Equality operator for Parameter class.
 
bool operator!= (const Parameter &other) const
 Inequality operator for Parameter class.
 

Static Public Member Functions

static Parameter fromJsonObject (const QJsonObject &object, Type type)
 Loads parameter information from a JSON object.
 
static Parameter merge (const Parameter &p1, const Parameter &p2)
 Merges two Parameter objects into a single parameter.
 

Protected Member Functions

 Parameter (ParameterData *d)
 
 Parameter (const QSharedDataPointer< ParameterData > &data)
 

Static Protected Member Functions

static void dataFromJsonObject (ParameterData *data, const QJsonObject &object)
 

Protected Attributes

QSharedDataPointer< ParameterData > d_ptr
 

Detailed Description

Represents a generic parameter, which could be a path, query, or header parameter, with support for special values and flags.

This class provides a flexible structure to define parameters in various contexts, supporting operations such as adding/removing values, flagging special attributes, and converting to/from JSON format. Parameters can represent different types, including path parameters, query parameters, and headers.

Member Enumeration Documentation

◆ Flag

Defines flags used to specify special attributes for a parameter.

Flags can be used to indicate attributes like authentication, secrecy, and locale.

Enumerator
NoFlag 

No flags are set. This is the default state.

Authentication 

Indicates that the parameter is used for authentication purposes.

Secret 

Indicates that the parameter holds secret or sensitive information.

Locale 

Indicates that the parameter is related to the locale or language settings.

◆ Type

Defines the possible types of parameters.

Parameters can be classified into different types, including base type, path parameter type, query parameter type, and header type.

Enumerator
BaseType 

Represents the base type of the parameter, typically a general or default type.

PathParameterType 

Represents parameters that are embedded in the URL path, usually used for resource identifiers.

QueryParameterType 

Represents parameters that are passed as part of the query string in the URL.

HeaderType 

Represents parameters that are used as HTTP headers.

Constructor & Destructor Documentation

◆ Parameter() [1/5]

RestLink::Parameter::Parameter ( )

Default constructor for Parameter class.

Initializes a new parameter instance with default values.

◆ Parameter() [2/5]

RestLink::Parameter::Parameter ( const Parameter other)

Copy constructor for Parameter class.

Creates a new Parameter instance as a copy of the provided parameter.

Parameters
otherThe parameter to copy.

◆ Parameter() [3/5]

RestLink::Parameter::Parameter ( Parameter &&  other)

Move constructor for Parameter class.

Transfers ownership of the resources from the provided parameter to the new instance.

Parameters
otherThe parameter to move.

◆ ~Parameter()

RestLink::Parameter::~Parameter ( )

Destructor for Parameter class.

Cleans up the resources held by the parameter.

◆ Parameter() [4/5]

RestLink::Parameter::Parameter ( ParameterData *  d)
protected

◆ Parameter() [5/5]

RestLink::Parameter::Parameter ( const QSharedDataPointer< ParameterData > &  data)
protected

Member Function Documentation

◆ operator=() [1/2]

Parameter & RestLink::Parameter::operator= ( const Parameter other)

Copy assignment operator for Parameter class.

Copies the contents of one Parameter instance to another.

Parameters
otherThe parameter to copy from.
Returns
A reference to the current instance.

◆ operator=() [2/2]

Parameter & RestLink::Parameter::operator= ( Parameter &&  other)

Move assignment operator for Parameter class.

Transfers ownership of the resources from the provided parameter to the current instance.

Parameters
otherThe parameter to move from.
Returns
A reference to the current instance.

◆ name()

QString RestLink::Parameter::name ( ) const

Retrieves the name of the parameter.

Returns
The parameter name as a QString.

◆ setName()

void RestLink::Parameter::setName ( const QString &  name)

Sets the name of the parameter.

Parameters
nameThe name to set for the parameter.

◆ value()

QVariant RestLink::Parameter::value ( ) const

Retrieves the value of the parameter.

Returns
The parameter value as a QVariant.

◆ setValue()

void RestLink::Parameter::setValue ( const QVariant &  value)

Sets the value of the parameter.

Parameters
valueThe value to set for the parameter.

◆ specialValue()

QVariant RestLink::Parameter::specialValue ( Api api) const

Returns a special value for the parameter, based on the provided API.

This method may return a specific value depending on the context of the API.

Parameters
apiThe API used to determine the special value.
Returns
A QVariant representing the special value.

◆ specialValues()

QVariantList RestLink::Parameter::specialValues ( Api api) const

Returns a list of special values for the parameter, based on the provided API.

This method may return multiple special values depending on the context of the API.

Parameters
apiThe API used to determine the special values.
Returns
A list of special values as QVariantList.

◆ hasValue()

bool RestLink::Parameter::hasValue ( const QVariant &  value) const

Checks if the parameter contains a specific value.

Parameters
valueThe value to check.
Returns
True if the value exists in the parameter, false otherwise.

◆ addValue()

void RestLink::Parameter::addValue ( const QVariant &  value)

Adds a value to the parameter.

Parameters
valueThe value to add.

◆ removeValue()

void RestLink::Parameter::removeValue ( const QVariant &  value)

Removes a value from the parameter.

Parameters
valueThe value to remove.

◆ values()

QVariantList RestLink::Parameter::values ( ) const

Returns a list of all values associated with the parameter.

Returns
A list of values as QList<QVariant>.

◆ setValues()

void RestLink::Parameter::setValues ( const QList< QVariant > &  values)

Sets a list of values for the parameter.

Parameters
valuesThe new list of values to assign.

◆ hasFlag()

bool RestLink::Parameter::hasFlag ( Flag  flag) const

Checks if a specific flag is set for the parameter.

Parameters
flagThe ParameterFlag to check.
Returns
true if the flag is set, otherwise false.

◆ flags()

Parameter::Flags RestLink::Parameter::flags ( ) const

Retrieves all flags set for the parameter.

Returns
The flags as a ParameterFlags bitmask.

◆ setFlag()

void RestLink::Parameter::setFlag ( Flag  flag,
bool  on = true 
)

Sets or clears a specific flag for the parameter.

Parameters
flagThe ParameterFlag to modify.
ontrue to set the flag, false to clear it.

◆ setFlags()

void RestLink::Parameter::setFlags ( const Flags &  flags)

Sets multiple flags for the parameter.

Parameters
flagsThe ParameterFlags bitmask to set.

◆ type()

Parameter::Type RestLink::Parameter::type ( ) const

Returns the type of the parameter.

Returns
The parameter's type.

◆ isValid()

bool RestLink::Parameter::isValid ( ) const

Checks if the parameter is valid.

Returns
true if the parameter is valid, otherwise false.

A parameter is considered valid if it has a non-empty name and a not null value.

◆ toPathParameter()

PathParameter RestLink::Parameter::toPathParameter ( ) const

◆ toQueryParameter()

QueryParameter RestLink::Parameter::toQueryParameter ( ) const

Converts the current Parameter instance to a QueryParameter. If the type of the parameter is QueryParameterType, it returns a valid QueryParameter. Otherwise, it returns an invalid QueryParameter instance.

Returns
QueryParameter - A converted QueryParameter instance or an invalid one.

◆ toHeader()

Header RestLink::Parameter::toHeader ( ) const

Converts the current Parameter instance to a Header. If the type of the parameter is HeaderType, it returns a valid Header. Otherwise, it returns an invalid Header instance.

Returns
Header - A converted Header instance or an invalid one.

◆ toJsonObject()

QJsonObject RestLink::Parameter::toJsonObject ( ) const

Converts the parameter to a QJsonObject.

Returns
The parameter represented as a QJsonObject.

◆ fromJsonObject()

Parameter RestLink::Parameter::fromJsonObject ( const QJsonObject &  object,
Type  type 
)
static

Loads parameter information from a JSON object.

Parameters
objectThe QJsonObject containing the parameter data.

◆ merge()

Parameter RestLink::Parameter::merge ( const Parameter r1,
const Parameter r2 
)
static

Merges two Parameter objects into a single parameter.

Parameters
p1The first Parameter to merge.
p2The second Parameter to merge.
Returns
A new Parameter containing merged properties.

◆ operator==()

bool RestLink::Parameter::operator== ( const Parameter other) const

Equality operator for Parameter class.

Two parameters are considered equal if they have the same name, value, and flags.

Parameters
otherThe parameter to compare with.
Returns
True if the parameters are equal, false otherwise.

◆ operator!=()

bool RestLink::Parameter::operator!= ( const Parameter other) const

Inequality operator for Parameter class.

Two parameters are considered unequal if they differ in name, value, or flags.

Parameters
otherThe parameter to compare with.
Returns
True if the parameters are unequal, false otherwise.

◆ dataFromJsonObject()

void RestLink::Parameter::dataFromJsonObject ( ParameterData *  data,
const QJsonObject &  object 
)
staticprotected

Member Data Documentation

◆ d_ptr

QSharedDataPointer<ParameterData> RestLink::Parameter::d_ptr
protected