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

Loads a JSON rewrite table and substitutes VLink URLs at runtime. 更多...

#include <url_remap.h>

vlink::UrlRemap 的协作图:

Public 成员函数

 UrlRemap () noexcept
 Constructs an empty, unloaded instance. 更多...
 
 ~UrlRemap () noexcept
 Destroys the instance and clears caches. 更多...
 
bool load (const std::string &file_path) noexcept
 Parses file_path and installs the rewrite table. 更多...
 
bool unload () noexcept
 Clears the rewrite table and the result cache. 更多...
 
bool reload (const std::string &file_path) noexcept
 Atomically unloads the current table and loads file_path. 更多...
 
const std::string & convert (const std::string &url) noexcept
 Translates url using the loaded rules; returns url unchanged on miss. 更多...
 
void set_enable_log (bool enable_log) noexcept
 Toggles per-conversion INFO logging. 更多...
 
bool is_enable_log () const noexcept
 Reports whether per-conversion logging is enabled. 更多...
 
bool is_valid () const noexcept
 Reports whether a rewrite table has been successfully loaded. 更多...
 
const std::string & get_error_string () const noexcept
 Returns the diagnostic message produced by the last failure. 更多...
 

详细描述

Loads a JSON rewrite table and substitutes VLink URLs at runtime.

Each instance holds an ordered rewrite list, a result cache, and a status string used for diagnostics. Copy and assignment are disabled.

构造及析构函数说明

◆ UrlRemap()

vlink::UrlRemap::UrlRemap ( )
noexcept

Constructs an empty, unloaded instance.

◆ ~UrlRemap()

vlink::UrlRemap::~UrlRemap ( )
noexcept

Destroys the instance and clears caches.

成员函数说明

◆ convert()

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

Translates url using the loaded rules; returns url unchanged on miss.

参数
urlInput URL to rewrite.
返回
Reference to the rewritten URL on a hit, or to url itself on a miss. The referent's lifetime depends on the path taken (the input url, the internal remap table, or the cache); copy it if you need to retain it.

◆ get_error_string()

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

Returns the diagnostic message produced by the last failure.

返回
Error string or empty when no failure has occurred since the last successful load.

◆ is_enable_log()

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

Reports whether per-conversion logging is enabled.

返回
true when logging is currently enabled.

◆ is_valid()

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

Reports whether a rewrite table has been successfully loaded.

返回
true after a successful load() or reload() and before the next unload().

◆ load()

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

Parses file_path and installs the rewrite table.

参数
file_pathAbsolute or relative path to a flat JSON object of string pairs.
返回
true on success; false when already loaded, the file is missing, unreadable, or contains invalid JSON. Errors are surfaced via get_error_string().

◆ reload()

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

Atomically unloads the current table and loads file_path.

参数
file_pathPath of the replacement JSON file.
返回
true when the new file loaded successfully.

◆ set_enable_log()

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

Toggles per-conversion INFO logging.

Details

参数
enable_logtrue emits one log line per successful rewrite.

◆ unload()

bool vlink::UrlRemap::unload ( )
noexcept

Clears the rewrite table and the result cache.

返回
true when the table was cleared; false when no table was loaded.

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