VLink 2.0.0
A high-performance communication middleware
Loading...
Searching...
No Matches
vlink::UrlRemap Class Reference

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

#include <url_remap.h>

Collaboration diagram for vlink::UrlRemap:

Public Member Functions

 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.

Detailed Description

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.

Constructor & Destructor Documentation

◆ UrlRemap()

vlink::UrlRemap::UrlRemap ( )
noexcept

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

Here is the caller graph for this function:

◆ ~UrlRemap()

vlink::UrlRemap::~UrlRemap ( )
noexcept

Destructor.

Here is the call graph for this function:

Member Function Documentation

◆ 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
urlInput URL string.
Returns
Remapped URL, or the original url if no rule matches.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.
Here is the caller graph for this function:

◆ is_enable_log()

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

Returns whether conversion logging is currently enabled.

Returns
true if logging is enabled.
Here is the caller graph for this function:

◆ 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.
Here is the caller graph for this function:

◆ 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_pathAbsolute 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().
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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_pathPath to the new JSON remap file.
Returns
true if the new file was loaded successfully.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_enable_log()

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

Enables or disables logging of each URL conversion.

Details.

Parameters
enable_logIf true, each successful remap is logged at INFO level.
Here is the caller graph for this function:

◆ 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.
Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following file: