VLink  2.0.0
A high-performance communication middleware
vlink::UrlParser类 参考final

Immutable URL decomposition used by the VLink transport router. 更多...

#include <url_parser.h>

vlink::UrlParser 的协作图:

Public 类型

enum class  Category : uint8_t { kHierarchical = 0 , kNonHierarchical = 1 }
 Distinguishes hierarchical and non-hierarchical URI forms. 更多...
 
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. 更多...
 
enum class  Separator : uint8_t { kAmpersand = 0 , kSemicolon = 1 }
 Selectable separator used to break the query string into key/value pairs. 更多...
 

Public 成员函数

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

详细描述

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.

成员枚举类型说明

◆ Category

enum vlink::UrlParser::Category : uint8_t
strong

Distinguishes hierarchical and non-hierarchical URI forms.

枚举值
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.

枚举值
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.

枚举值
kAmpersand 

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

kSemicolon 

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

构造及析构函数说明

◆ 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.

参数
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.

参数
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.

参数
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 &.
异常
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.

参数
otherSource parser.
replacementsComponents that override the corresponding entries in other.

成员函数说明

◆ get_category()

Category vlink::UrlParser::get_category ( ) const

Returns the URL category supplied at construction time.

返回
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.

返回
Reference to the content string.

◆ get_fragment()

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

Returns the fragment identifier (without the leading #).

返回
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.

返回
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.

返回
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().

返回
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.

返回
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 ?).

返回
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.

返回
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").

返回
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.

返回
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.

返回
Reconstructed URL string.

该类的文档由以下文件生成: