VLink  2.0.0
A high-performance communication middleware
vlink::UrlParser Class Referencefinal

Immutable URL decomposition used by the VLink transport router. More...

#include <url_parser.h>

Collaboration diagram for vlink::UrlParser:

Public Types

enum class  Category : uint8_t { kHierarchical = 0 , kNonHierarchical = 1 }
 Distinguishes hierarchical and non-hierarchical URI forms. More...
 
enum class  Component : uint8_t {
  kTransport = 0 , kContent = 1 , kUsername = 2 , kPassword = 3 ,
  kHost = 4 , kPort = 5 , kPath = 6 , kQuery = 7 ,
  kFragment = 8
}
 Component identifiers accepted by the explicit-components constructor. More...
 
enum class  Separator : uint8_t { kAmpersand = 0 , kSemicolon = 1 }
 Selectable separator used to break the query string into key/value pairs. More...
 

Public Member Functions

 UrlParser (const char *str, Category category=Category::kHierarchical, Separator separator=Separator::kAmpersand)
 Parses str as a null-terminated URL string. More...
 
 UrlParser (const std::string &str, Category category=Category::kHierarchical, Separator separator=Separator::kAmpersand)
 Parses str as an std::string URL. More...
 
 UrlParser (const std::map< Component, std::string > &components, Category category, bool rooted, Separator separator=Separator::kAmpersand)
 Builds a parser directly from an explicit component map. More...
 
 UrlParser (const UrlParser &other, const std::map< Component, std::string > &replacements)
 Builds a parser by copying other and overriding selected components. More...
 
const std::string & get_transport () const
 Returns the parsed transport string (e.g. "dds" or "intra"). More...
 
Category get_category () const
 Returns the URL category supplied at construction time. More...
 
const std::string & get_content () const
 Returns the full content portion of a non-hierarchical URL. More...
 
const std::string & get_username () const
 Returns the authentication username component. More...
 
const std::string & get_password () const
 Returns the authentication password component. More...
 
const std::string & get_host () const
 Returns the host component (hostname or IP address). More...
 
int64_t get_port () const
 Returns the port number, or 0 when no port was specified. More...
 
const std::string & get_path () const
 Returns the path component of the URL. More...
 
const std::string & get_query () const
 Returns the raw query string (without the leading ?). More...
 
const std::map< std::string, std::string > & get_query_dictionary () const
 Returns the parsed query string as a key/value dictionary. More...
 
const std::string & get_fragment () const
 Returns the fragment identifier (without the leading #). More...
 
std::string to_string () const
 Reconstructs the URL string from the parsed components. More...
 

Detailed Description

Immutable URL decomposition used by the VLink transport router.

Parses the input URL once at construction and exposes each component through const accessors. For hierarchical URLs the stored path drops the leading / marker; the rootedness flag is preserved separately so to_string() can reconstruct an equivalent representation.

Member Enumeration Documentation

◆ Category

enum vlink::UrlParser::Category : uint8_t
strong

Distinguishes hierarchical and non-hierarchical URI forms.

Enumerator
kHierarchical 

Standard scheme://authority/path layout (most VLink transports).

kNonHierarchical 

Opaque scheme:content layout (e.g. mailto:).

◆ Component

enum vlink::UrlParser::Component : uint8_t
strong

Component identifiers accepted by the explicit-components constructor.

Enumerator
kTransport 

URI scheme / VLink transport prefix.

kContent 

Full content string after the scheme separator.

kUsername 

Optional authentication username.

kPassword 

Optional authentication password.

kHost 

Hostname or IP address.

kPort 

Port number (stored as string in the components map).

kPath 

Resource path (e.g. /vehicle/speed).

kQuery 

Raw query string (without the leading ?).

kFragment 

Fragment identifier (without the leading #).

◆ Separator

enum vlink::UrlParser::Separator : uint8_t
strong

Selectable separator used to break the query string into key/value pairs.

Enumerator
kAmpersand 

& separator (default; key=val&key2=val2).

kSemicolon 

; separator (alternative; key=val;key2=val2).

Constructor & Destructor Documentation

◆ UrlParser() [1/4]

vlink::UrlParser::UrlParser ( const char *  str,
Category  category = Category::kHierarchical,
Separator  separator = Separator::kAmpersand 
)
explicit

Parses str as a null-terminated URL string.

Parameters
strURL string to parse.
categoryHierarchical or non-hierarchical layout; default hierarchical.
separatorQuery-pair separator; default &.

◆ UrlParser() [2/4]

vlink::UrlParser::UrlParser ( const std::string &  str,
Category  category = Category::kHierarchical,
Separator  separator = Separator::kAmpersand 
)
explicit

Parses str as an std::string URL.

Parameters
strURL string to parse.
categoryHierarchical or non-hierarchical layout; default hierarchical.
separatorQuery-pair separator; default &.

◆ UrlParser() [3/4]

vlink::UrlParser::UrlParser ( const std::map< Component, std::string > &  components,
Category  category,
bool  rooted,
Separator  separator = Separator::kAmpersand 
)
explicit

Builds a parser directly from an explicit component map.

Useful for constructing a URL from a previously decomposed set of fields instead of parsing a raw string.

Parameters
componentsMap of Component to value for every present component.
categoryHierarchical or non-hierarchical layout.
rootedtrue when the path starts with / (hierarchical URLs).
separatorQuery-pair separator; default &.
Exceptions
Exception::RuntimeErrorwhen category is Category::kHierarchical and Component::kPath is missing, or when category is Category::kNonHierarchical and Component::kContent is missing.

◆ UrlParser() [4/4]

vlink::UrlParser::UrlParser ( const UrlParser other,
const std::map< Component, std::string > &  replacements 
)
explicit

Builds a parser by copying other and overriding selected components.

Equivalent to producing a modified copy of an existing URL.

Parameters
otherSource parser.
replacementsComponents that override the corresponding entries in other.

Member Function Documentation

◆ get_category()

Category vlink::UrlParser::get_category ( ) const

Returns the URL category supplied at construction time.

Returns
Either Category::kHierarchical or Category::kNonHierarchical.

◆ get_content()

const std::string& vlink::UrlParser::get_content ( ) const

Returns the full content portion of a non-hierarchical URL.

Calling this method on a hierarchical URL throws Exception::RuntimeError.

Returns
Reference to the content string.

◆ get_fragment()

const std::string& vlink::UrlParser::get_fragment ( ) const

Returns the fragment identifier (without the leading #).

Returns
Reference to the fragment; empty when absent.

◆ get_host()

const std::string& vlink::UrlParser::get_host ( ) const

Returns the host component (hostname or IP address).

Valid only for hierarchical URLs; otherwise throws Exception::RuntimeError.

Returns
Reference to the host string; empty when absent.

◆ get_password()

const std::string& vlink::UrlParser::get_password ( ) const

Returns the authentication password component.

Valid only for hierarchical URLs; otherwise throws Exception::RuntimeError.

Returns
Reference to the password; empty when absent.

◆ get_path()

const std::string& vlink::UrlParser::get_path ( ) const

Returns the path component of the URL.

Valid only for hierarchical URLs; otherwise throws Exception::RuntimeError. The returned string omits the leading / for rooted hierarchical URLs; the rootedness flag is retained internally and emitted again by to_string().

Returns
Reference to the path; empty when absent.

◆ get_port()

int64_t vlink::UrlParser::get_port ( ) const

Returns the port number, or 0 when no port was specified.

Valid only for hierarchical URLs; otherwise throws Exception::RuntimeError.

Returns
Parsed port as int64_t; 0 when absent.

◆ get_query()

const std::string& vlink::UrlParser::get_query ( ) const

Returns the raw query string (without the leading ?).

Returns
Reference to the raw query; empty when no query was present.

◆ get_query_dictionary()

const std::map<std::string, std::string>& vlink::UrlParser::get_query_dictionary ( ) const

Returns the parsed query string as a key/value dictionary.

Built by splitting the raw query on the configured Separator and then splitting each token on the first = character. Keys without a value appear with an empty string.

Returns
Reference to the query dictionary.

◆ get_transport()

const std::string& vlink::UrlParser::get_transport ( ) const

Returns the parsed transport string (e.g. "dds" or "intra").

Returns
Reference to the transport component; empty when absent.

◆ get_username()

const std::string& vlink::UrlParser::get_username ( ) const

Returns the authentication username component.

Valid only for hierarchical URLs; otherwise throws Exception::RuntimeError.

Returns
Reference to the username; empty when absent.

◆ to_string()

std::string vlink::UrlParser::to_string ( ) const

Reconstructs the URL string from the parsed components.

Hierarchical URLs are reassembled as scheme://authority/path?query::fragment when an authority is present; non-hierarchical URLs as scheme:content?query::fragment. The output may differ from the original input when equivalent components were originally written differently.

Returns
Reconstructed URL string.

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