VLink  2.0.0
A high-performance communication middleware
vlink::UrlRemap Class Reference

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

#include <url_remap.h>

Collaboration diagram for vlink::UrlRemap:

Public Member Functions

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

Detailed Description

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.

Constructor & Destructor Documentation

◆ UrlRemap()

vlink::UrlRemap::UrlRemap ( )
noexcept

Constructs an empty, unloaded instance.

◆ ~UrlRemap()

vlink::UrlRemap::~UrlRemap ( )
noexcept

Destroys the instance and clears caches.

Member Function Documentation

◆ convert()

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

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

Parameters
urlInput URL to rewrite.
Returns
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.

Returns
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.

Returns
true when logging is currently enabled.

◆ is_valid()

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

Reports whether a rewrite table has been successfully loaded.

Returns
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.

Parameters
file_pathAbsolute or relative path to a flat JSON object of string pairs.
Returns
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.

Parameters
file_pathPath of the replacement JSON file.
Returns
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.

Parameters
enable_logtrue emits one log line per successful rewrite.

◆ unload()

bool vlink::UrlRemap::unload ( )
noexcept

Clears the rewrite table and the result cache.

Returns
true when the table was cleared; false when no table was loaded.

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