Loads a JSON remap file and translates VLink URL strings at runtime.
More...
#include <url_remap.h>
|
| | 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 |
◆ 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.
- Parameters
-
- Returns
- 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().
- Returns
- 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.
- Returns
true if logging is enabled.
◆ is_valid()
| bool vlink::UrlRemap::is_valid |
( |
| ) |
const |
|
inlinenodiscardnoexcept |
Returns whether a remap file has been successfully loaded.
- Returns
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).
- Parameters
-
| file_path | Absolute or relative path to the JSON file. |
- Returns
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).
- Parameters
-
| file_path | Path to the new JSON remap file. |
- Returns
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.
- Parameters
-
| enable_log | If 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.
- Returns
true if the table was cleared; false if already unloaded.
The documentation for this class was generated from the following file: