VLink 2.0.0
A high-performance communication middleware
载入中...
搜索中...
未找到
vlink::UrlRemap类 参考

Loads a JSON remap file and translates VLink URL strings at runtime. 更多...

#include <url_remap.h>

vlink::UrlRemap 的协作图:

Public 成员函数

 UrlRemap () noexcept
 Constructs an empty, invalid UrlRemap. No file is loaded.
 ~UrlRemap () noexcept
 Destructor.
bool load (const std::string &file_path) noexcept
 Loads and parses a JSON remap configuration from file_path.
bool unload () noexcept
 Clears the remap table and marks the instance as invalid.
bool reload (const std::string &file_path) noexcept
 Unloads the current configuration and loads a new one atomically.
const std::string & convert (const std::string &url) noexcept
 Translates url according to the loaded remap rules.
void set_enable_log (bool enable_log) noexcept
 Enables or disables logging of each URL conversion.
bool is_enable_log () const noexcept
 Returns whether conversion logging is currently enabled.
bool is_valid () const noexcept
 Returns whether a remap file has been successfully loaded.
const std::string & get_error_string () const noexcept
 Returns the human-readable error description from the last failed operation.

详细描述

Loads a JSON remap file and translates VLink URL strings at runtime.

Not thread-safe. All methods should be called from a single thread, or the caller must provide external synchronisation.

构造及析构函数说明

◆ UrlRemap()

vlink::UrlRemap::UrlRemap ( )
noexcept

Constructs an empty, invalid UrlRemap. No file is loaded.

这是这个函数的调用关系图:

◆ ~UrlRemap()

vlink::UrlRemap::~UrlRemap ( )
noexcept

Destructor.

函数调用图:

成员函数说明

◆ convert()

const std::string & vlink::UrlRemap::convert ( const std::string & url)
noexcept

Translates url according to the loaded remap rules.

Checks an internal cache first for O(1) repeated lookups. If not cached, iterates the ordered remap list and returns the first matching target. The result is cached before returning.

Returns url unchanged if:

  • The remap table is not loaded (is_valid() is false).
  • No rule matches.
参数
urlInput URL string.
返回
Remapped URL, or the original url if no rule matches.
函数调用图:
这是这个函数的调用关系图:

◆ get_error_string()

const std::string & vlink::UrlRemap::get_error_string ( ) const
inlinenodiscardnoexcept

Returns the human-readable error description from the last failed operation.

Populated by load() on failure. Cleared on unload() and on successful load().

返回
Error string, or an empty string if no error has occurred.
这是这个函数的调用关系图:

◆ is_enable_log()

bool vlink::UrlRemap::is_enable_log ( ) const
inlinenodiscardnoexcept

Returns whether conversion logging is currently enabled.

返回
true if logging is enabled.
这是这个函数的调用关系图:

◆ is_valid()

bool vlink::UrlRemap::is_valid ( ) const
inlinenodiscardnoexcept

Returns whether a remap file has been successfully loaded.

返回
true if load() or reload() succeeded.
这是这个函数的调用关系图:

◆ load()

bool vlink::UrlRemap::load ( const std::string & file_path)
noexcept

Loads and parses a JSON remap configuration from file_path.

The file must be a flat JSON object with string keys and string values. Calling load() on an already-loaded instance returns false without modifying state (call unload() or reload() first).

参数
file_pathAbsolute or relative path to the JSON file.
返回
true on success; false if the file is missing, unreadable, or contains invalid JSON. The error description is accessible via get_error_string().
函数调用图:
这是这个函数的调用关系图:

◆ reload()

bool vlink::UrlRemap::reload ( const std::string & file_path)
noexcept

Unloads the current configuration and loads a new one atomically.

Equivalent to calling unload() followed by load(file_path).

参数
file_pathPath to the new JSON remap file.
返回
true if the new file was loaded successfully.
函数调用图:
这是这个函数的调用关系图:

◆ set_enable_log()

void vlink::UrlRemap::set_enable_log ( bool enable_log)
inlinenoexcept

Enables or disables logging of each URL conversion.

Details

参数
enable_logIf true, each successful remap is logged at INFO level.
这是这个函数的调用关系图:

◆ unload()

bool vlink::UrlRemap::unload ( )
noexcept

Clears the remap table and marks the instance as invalid.

Also clears the conversion result cache. Does nothing and returns false if the instance is not currently loaded.

返回
true if the table was cleared; false if already unloaded.
函数调用图:
这是这个函数的调用关系图:

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