|
VLink 2.0.0
A high-performance communication middleware
|
Loads a JSON remap file and translates VLink URL strings at runtime. 更多...
#include <url_remap.h>
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.
|
noexcept |
|
noexcept |
Destructor.
|
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:
is_valid() is false).| url | Input URL string. |
url if no rule matches.
|
inlinenodiscardnoexcept |
|
inlinenodiscardnoexcept |
Returns whether conversion logging is currently enabled.
true if logging is enabled.
|
inlinenodiscardnoexcept |
|
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_path | Absolute 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().
|
noexcept |
Unloads the current configuration and loads a new one atomically.
Equivalent to calling unload() followed by load(file_path).
| file_path | Path to the new JSON remap file. |
true if the new file was loaded successfully.
|
inlinenoexcept |
Enables or disables logging of each URL conversion.
Details
| enable_log | If true, each successful remap is logged at INFO level. |
|
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.