Consolix
Loading...
Searching...
No Matches
consolix Namespace Reference

< Utility modules and helpers. More...

Classes

class  AppComponentManager
 Manages a collection of application components with lifecycle support. More...
 
class  BaseLoopComponent
 Abstract base class for application components with looping functionality. More...
 
class  ColorManipulator
 A utility class for managing text color in streams. More...
 
class  ConsoleApplication
 Singleton class to manage the lifecycle of a console application. More...
 
class  IAppComponent
 Interface for defining application components. More...
 
class  IShutdownable
 Interface for components supporting shutdown logic. More...
 
class  LoggerComponent
 Fallback LoggerComponent when LogIt is disabled. More...
 
class  LogoComponent
 Component responsible for displaying a customizable ASCII logo. More...
 
class  LoopComponent
 Component for managing a customizable execution loop. More...
 
class  MultiStream
 A class for handling multi-target log streams. More...
 
class  ServiceLocator
 A universal service locator for managing shared resources. More...
 
class  TitleComponent
 Handles setting and retrieving the console window title. More...
 

Enumerations

enum class  TextColor {
  Black , DarkRed , DarkGreen , DarkYellow ,
  DarkBlue , DarkMagenta , DarkCyan , LightGray ,
  DarkGray , Red , Green , Yellow ,
  Blue , Magenta , Cyan , White
}
 Represents text colors for console output. More...
 

Functions

void init ()
 Initializes the application. This function prepares the application and service locator for use.
 
template<typename InitAction>
void init (InitAction init_action)
 Initializes the application with a custom action. This function prepares the application and service locator, and executes a custom action during initialization.
 
template<typename Component, typename... Args>
std::shared_ptr< Component > add (Args &&... args)
 Adds a new component to the application. Creates a new instance of the specified component type and adds it to the application.
 
void add (std::shared_ptr< IAppComponent > component)
 Adds an existing component to the application. Registers a pre-existing component with the application.
 
void run ()
 Runs the application. Processes all components in the application's main loop.
 
template<typename IterationAction>
void run (IterationAction iteration_action)
 Runs the application with a custom loop action.
 
void stop ()
 Stops the application. Stops the application's main loop and begins the shutdown process.
 
template<typename T>
void register_service (std::function< std::shared_ptr< T >()> creator)
 Registers a resource or service globally. Registers a resource or service with the ServiceLocator using the provided creator function.
 
template<typename T>
void register_service ()
 Registers a resource with default construction globally. Registers a resource or service using default construction.
 
template<typename T>
T & get_service ()
 Retrieves a resource globally. Retrieves a reference to a globally registered resource from the ServiceLocator.
 
template<typename T>
bool has_service ()
 Checks if a resource is registered globally.
 
void clear_all ()
 Clears all registered resources globally. Clears all resources and services registered in the ServiceLocator
 
ColorManipulator color (TextColor color)
 Creates a color manipulator for use in output streams.
 
std::ostream & operator<< (std::ostream &os, const ColorManipulator &manip)
 Overloads the stream operator to apply text color.
 
const char * to_c_str (const TextColor &color)
 Converts a TextColor to an ANSI escape code string.
 
bool check_escaped (const std::string &json_string, size_t quote_position)
 Checks if a character in a JSON string is escaped.
 
*The resulting JSON string may optionally retain whitespace or newlines *where the comments were removed **param json_string The JSON string to process *param with_whitespace If comments are replaced with equivalent whitespace *If comments are removed without leaving whitespace *param preserve_newlines If true and with_whitespace is newline characters *in comments are preserved all characters in the *comments are replaced with whitespace *return A JSON string with comments removed *std::string strip_json_comments (const std::string &json_string, bool with_whitespace=false, bool preserve_newlines=true)
 
std::string get_exec_path ()
 Retrieves the full path of the executable.
 
std::string get_exec_dir ()
 Retrieves the directory of the executable file.
 
std::string get_file_name (const std::string &file_path)
 Extracts the file name from a full file path.
 
std::string make_relative (const std::string &file_path, const std::string &base_path)
 Computes the relative path from base_path to file_path.
 
void create_directories (const std::string &path)
 Creates directories recursively for the given path.
 

Variables

*The resulting JSON string may optionally retain whitespace or newlines *where the comments were removed **param json_string The JSON string to process *param with_whitespace If true
 Removes comments from a JSON string.
 
*The resulting JSON string may optionally retain whitespace or newlines *where the comments were removed **param json_string The JSON string to process *param with_whitespace If comments are replaced with equivalent whitespace *If false
 
*The resulting JSON string may optionally retain whitespace or newlines *where the comments were removed **param json_string The JSON string to process *param with_whitespace If comments are replaced with equivalent whitespace *If comments are removed without leaving whitespace *param preserve_newlines If true and with_whitespace is enabled
 
*The resulting JSON string may optionally retain whitespace or newlines *where the comments were removed **param json_string The JSON string to process *param with_whitespace If comments are replaced with equivalent whitespace *If comments are removed without leaving whitespace *param preserve_newlines If true and with_whitespace is newline characters *in comments are preserved Otherwise
 

Detailed Description

< Utility modules and helpers.

< Global configuration macros for Consolix. < Core functionalities of Consolix. < Aggregated components of Consolix.

Main namespace for the Consolix framework.

The consolix namespace contains all classes, functions, and utilities provided by the Consolix framework. It is the primary namespace used for building structured and flexible console applications.

Enumeration Type Documentation

◆ TextColor

enum class consolix::TextColor
strong

Represents text colors for console output.

The enumeration defines a set of standard text colors compatible with both ANSI escape codes (Linux/macOS) and Windows API (Windows).

Enumerator
Black 
DarkRed 
DarkGreen 
DarkYellow 
DarkBlue 
DarkMagenta 
DarkCyan 
LightGray 
DarkGray 
Red 
Green 
Yellow 
Blue 
Magenta 
Cyan 
White 

Definition at line 17 of file enums.hpp.

Function Documentation

◆ add() [1/2]

template<typename Component, typename... Args>
std::shared_ptr< Component > consolix::add ( Args &&... args)
inline

Adds a new component to the application. Creates a new instance of the specified component type and adds it to the application.

Template Parameters
ComponentThe type of the component to add.
ArgsThe types of the arguments to pass to the component's constructor.
Parameters
argsArguments to construct the component.
Returns
A std::shared_ptr to the added component.
Examples
example_application_main_loop.cpp.

Definition at line 50 of file application_utils.hpp.

◆ add() [2/2]

void consolix::add ( std::shared_ptr< IAppComponent > component)
inline

Adds an existing component to the application. Registers a pre-existing component with the application.

Parameters
componentA std::shared_ptr to the component to add.

Definition at line 57 of file application_utils.hpp.

◆ check_escaped()

bool consolix::check_escaped ( const std::string & json_string,
size_t quote_position )
inline

Checks if a character in a JSON string is escaped.

Parameters
json_stringThe JSON string.
quote_positionThe position of the character to check.
Returns
true if the character is escaped, false otherwise.

Definition at line 17 of file json_utils.hpp.

◆ clear_all()

void consolix::clear_all ( )
inline

Clears all registered resources globally. Clears all resources and services registered in the ServiceLocator

Definition at line 65 of file service_utils.hpp.

◆ color()

ColorManipulator consolix::color ( TextColor color)
inline

Creates a color manipulator for use in output streams.

Parameters
colorThe desired text color.
Returns
A ColorManipulator object for stream manipulation.
Examples
example_application_main_loop.cpp.

Definition at line 52 of file ColorManipulator.hpp.

◆ create_directories()

void consolix::create_directories ( const std::string & path)

Creates directories recursively for the given path.

Parameters
pathThe directory path to create.
Exceptions
std::runtime_errorif the directories cannot be created.

Definition at line 185 of file path_utils.hpp.

◆ get_exec_dir()

std::string consolix::get_exec_dir ( )

Retrieves the directory of the executable file.

Returns
A string containing the directory path of the executable.

Definition at line 56 of file path_utils.hpp.

◆ get_exec_path()

std::string consolix::get_exec_path ( )

Retrieves the full path of the executable.

Returns
A string containing the full path of the executable.

Definition at line 17 of file path_utils.hpp.

◆ get_file_name()

std::string consolix::get_file_name ( const std::string & file_path)

Extracts the file name from a full file path.

Parameters
file_pathThe full file path as a string.
Returns
The extracted file name, or the full string if no directory separator is found.

Definition at line 147 of file path_utils.hpp.

◆ get_service()

template<typename T>
T & consolix::get_service ( )
inline

Retrieves a resource globally. Retrieves a reference to a globally registered resource from the ServiceLocator.

Template Parameters
TThe type of the resource.
Returns
Reference to the resource.
Examples
example_application_main_loop.cpp.

Definition at line 51 of file service_utils.hpp.

◆ has_service()

template<typename T>
bool consolix::has_service ( )
inline

Checks if a resource is registered globally.

Template Parameters
TThe type of the resource.
Returns
true if the resource is registered, false otherwise.

Definition at line 59 of file service_utils.hpp.

◆ init() [1/2]

void consolix::init ( )

Initializes the application. This function prepares the application and service locator for use.

Definition at line 28 of file application_utils.hpp.

◆ init() [2/2]

template<typename InitAction>
void consolix::init ( InitAction init_action)

Initializes the application with a custom action. This function prepares the application and service locator, and executes a custom action during initialization.

Template Parameters
InitActionA callable type for the custom initialization action.
Parameters
init_actionThe action to execute during initialization.

Definition at line 38 of file application_utils.hpp.

◆ make_relative()

std::string consolix::make_relative ( const std::string & file_path,
const std::string & base_path )
inline

Computes the relative path from base_path to file_path.

Parameters
file_pathThe target file path.
base_pathThe base path from which to compute the relative path.
Returns
A string representing the relative path from base_path to file_path.

Definition at line 156 of file path_utils.hpp.

◆ operator<<()

std::ostream & consolix::operator<< ( std::ostream & os,
const ColorManipulator & manip )
inline

Overloads the stream operator to apply text color.

Parameters
osThe output stream.
manipThe ColorManipulator controlling the text color.
Returns
The modified output stream.

Definition at line 60 of file ColorManipulator.hpp.

◆ register_service() [1/2]

template<typename T>
void consolix::register_service ( )
inline

Registers a resource with default construction globally. Registers a resource or service using default construction.

Template Parameters
TThe type of the resource.

Definition at line 42 of file service_utils.hpp.

◆ register_service() [2/2]

template<typename T>
void consolix::register_service ( std::function< std::shared_ptr< T >()> creator)
inline

Registers a resource or service globally. Registers a resource or service with the ServiceLocator using the provided creator function.

Template Parameters
TThe type of the resource.
Parameters
creatorA function to create the resource (optional).

Definition at line 34 of file service_utils.hpp.

◆ run() [1/2]

void consolix::run ( )
inline

Runs the application. Processes all components in the application's main loop.

Examples
example_application_main_loop.cpp.

Definition at line 63 of file application_utils.hpp.

◆ run() [2/2]

template<typename IterationAction>
void consolix::run ( IterationAction iteration_action)
inline

Runs the application with a custom loop action.

Executes a custom action during each iteration of the application's main loop.

Template Parameters
IterationActionA callable type for the custom loop action.
Parameters
iteration_actionThe action to execute in the main loop.

Definition at line 73 of file application_utils.hpp.

◆ stop()

void consolix::stop ( )
inline

Stops the application. Stops the application's main loop and begins the shutdown process.

Definition at line 79 of file application_utils.hpp.

◆ strip_json_comments()

*The resulting JSON string may optionally retain whitespace or newlines *where the comments were removed **param json_string The JSON string to process *param with_whitespace If comments are replaced with equivalent whitespace *If comments are removed without leaving whitespace *param preserve_newlines If true and with_whitespace is newline characters *in comments are preserved all characters in the *comments are replaced with whitespace *return A JSON string with comments removed *std::string consolix::strip_json_comments ( const std::string & json_string,
bool with_whitespace = false,
bool preserve_newlines = true )

Definition at line 39 of file json_utils.hpp.

◆ to_c_str()

const char * consolix::to_c_str ( const TextColor & color)
inline

Converts a TextColor to an ANSI escape code string.

Parameters
colorThe text color to convert.
Returns
A C-style string representing the ANSI escape code for the color.

Definition at line 39 of file enums.hpp.

Variable Documentation

◆ enabled

* The resulting JSON string may optionally retain whitespace or newlines* where the comments were removed* * param json_string The JSON string to process* param with_whitespace If comments are replaced with equivalent whitespace* If comments are removed without leaving whitespace* param preserve_newlines If true and with_whitespace is consolix::enabled

Definition at line 35 of file json_utils.hpp.

◆ false

* The resulting JSON string may optionally retain whitespace or newlines* where the comments were removed* * param json_string The JSON string to process* param with_whitespace If comments are replaced with equivalent whitespace* If consolix::false

Definition at line 34 of file json_utils.hpp.

◆ Otherwise

* The resulting JSON string may optionally retain whitespace or newlines* where the comments were removed* * param json_string The JSON string to process* param with_whitespace If comments are replaced with equivalent whitespace* If comments are removed without leaving whitespace* param preserve_newlines If true and with_whitespace is newline characters* in comments are preserved consolix::Otherwise

Definition at line 36 of file json_utils.hpp.

◆ true

* The resulting JSON string may optionally retain whitespace or newlines* where the comments were removed* * param json_string The JSON string to process* param with_whitespace If consolix::true

Removes comments from a JSON string.

This function processes a JSON string and removes comments, including single-line comments (e.g., // or #) and multi-line comments (e.g., `/* ...

Definition at line 33 of file json_utils.hpp.