uvw  1.9.0
Classes | Static Public Member Functions | List of all members
uvw::Utilities Struct Reference

Miscellaneous utilities. More...

#include <util.hpp>

Classes

struct  OS
 OS dedicated utilities. More...
 

Static Public Member Functions

static HandleType guessHandle (HandleCategory category) noexcept
 Gets the type of the handle given a category. More...
 
static HandleType guessHandle (FileHandle file) noexcept
 Gets the type of the stream to be used with the given descriptor. More...
 
static std::vector< CPUInfocpuInfo () noexcept
 Gets information about the CPUs on the system. More...
 
static std::vector< InterfaceAddressinterfaceAddresses () noexcept
 Gets a set of descriptors of all the available interfaces. More...
 
static std::string indexToName (unsigned int index) noexcept
 IPv6-capable implementation of if_indextoname. More...
 
static std::string indexToIid (unsigned int index) noexcept
 Retrieves a network interface identifier. More...
 
static bool replaceAllocator (MallocFuncType mallocFunc, ReallocFuncType reallocFunc, CallocFuncType callocFunc, FreeFuncType freeFunc) noexcept
 Override the use of some standard library’s functions. More...
 
static std::array< double, 3 > loadAverage () noexcept
 Gets the load average. More...
 
static char ** setupArgs (int argc, char **argv)
 Store the program arguments. More...
 
static std::string processTitle ()
 Gets the title of the current process. More...
 
static bool processTitle (std::string title)
 Sets the current process title. More...
 
static uint64_t totalMemory () noexcept
 Gets memory information (in bytes). More...
 
static double uptime () noexcept
 Gets the current system uptime. More...
 
static RUsage rusage () noexcept
 Gets the resource usage measures for the current process. More...
 
static uint64_t hrtime () noexcept
 Gets the current high-resolution real time. More...
 
static std::string path () noexcept
 Gets the executable path. More...
 
static std::string cwd () noexcept
 Gets the current working directory. More...
 
static bool chdir (const std::string &dir) noexcept
 Changes the current working directory. More...
 

Detailed Description

Miscellaneous utilities.

Miscellaneous functions that don’t really belong to any other class.

Definition at line 431 of file util.hpp.

Member Function Documentation

◆ chdir()

static bool uvw::Utilities::chdir ( const std::string &  dir)
inlinestaticnoexcept

Changes the current working directory.

Parameters
dirThe working directory to be set.
Returns
True in case of success, false otherwise.

Definition at line 850 of file util.hpp.

◆ cpuInfo()

static std::vector<CPUInfo> uvw::Utilities::cpuInfo ( )
inlinestaticnoexcept

Gets information about the CPUs on the system.

This function can be used to query the underlying system and get a set of descriptors of all the available CPUs.

Returns
A set of descriptors of all the available CPUs.

Definition at line 624 of file util.hpp.

◆ cwd()

static std::string uvw::Utilities::cwd ( )
inlinestaticnoexcept

Gets the current working directory.

Returns
The current working directory, an empty string in case of errors.

Definition at line 841 of file util.hpp.

◆ guessHandle() [1/2]

static HandleType uvw::Utilities::guessHandle ( HandleCategory  category)
inlinestaticnoexcept

Gets the type of the handle given a category.

Parameters
categoryA properly initialized handle category.
Returns
The actual type of the handle as defined by HandleType

Definition at line 552 of file util.hpp.

◆ guessHandle() [2/2]

static HandleType uvw::Utilities::guessHandle ( FileHandle  file)
inlinestaticnoexcept

Gets the type of the stream to be used with the given descriptor.

Returns the type of stream that should be used with a given file descriptor.
Usually this will be used during initialization to guess the type of the stdio streams.

Parameters
fileA valid descriptor.
Returns
One of the following types:
  • HandleType::UNKNOWN
  • HandleType::PIPE
  • HandleType::TCP
  • HandleType::TTY
  • HandleType::UDP
  • HandleType::FILE

Definition at line 611 of file util.hpp.

◆ hrtime()

static uint64_t uvw::Utilities::hrtime ( )
inlinestaticnoexcept

Gets the current high-resolution real time.

The time is expressed in nanoseconds. It is relative to an arbitrary time in the past. It is not related to the time of the day and therefore not subject to clock drift. The primary use is for measuring performance between interval.

Returns
The current high-resolution real time.

Definition at line 825 of file util.hpp.

◆ indexToIid()

static std::string uvw::Utilities::indexToIid ( unsigned int  index)
inlinestaticnoexcept

Retrieves a network interface identifier.

See the official documentation for further details.

Parameters
indexNetwork interface index.
Returns
Network interface identifier.

Definition at line 707 of file util.hpp.

◆ indexToName()

static std::string uvw::Utilities::indexToName ( unsigned int  index)
inlinestaticnoexcept

IPv6-capable implementation of if_indextoname.

Mapping between network interface names and indexes.

See the official documentation for further details.

Parameters
indexNetwork interface index.
Returns
Network interface name.

Definition at line 693 of file util.hpp.

◆ interfaceAddresses()

static std::vector<InterfaceAddress> uvw::Utilities::interfaceAddresses ( )
inlinestaticnoexcept

Gets a set of descriptors of all the available interfaces.

This function can be used to query the underlying system and get a set of descriptors of all the available interfaces, either internal or not.

Returns
A set of descriptors of all the available interfaces.

Definition at line 649 of file util.hpp.

◆ loadAverage()

static std::array<double, 3> uvw::Utilities::loadAverage ( )
inlinestaticnoexcept

Gets the load average.

Returns
[0,0,0] on Windows (not available), the load average otherwise.

Definition at line 741 of file util.hpp.

◆ path()

static std::string uvw::Utilities::path ( )
inlinestaticnoexcept

Gets the executable path.

Returns
The executable path, an empty string in case of errors.

Definition at line 833 of file util.hpp.

◆ processTitle() [1/2]

static std::string uvw::Utilities::processTitle ( )
inlinestatic

Gets the title of the current process.

Returns
The process title.

Definition at line 762 of file util.hpp.

◆ processTitle() [2/2]

static bool uvw::Utilities::processTitle ( std::string  title)
inlinestatic

Sets the current process title.

Parameters
titleThe process title to be set.
Returns
True in case of success, false otherwise.

Definition at line 779 of file util.hpp.

◆ replaceAllocator()

static bool uvw::Utilities::replaceAllocator ( MallocFuncType  mallocFunc,
ReallocFuncType  reallocFunc,
CallocFuncType  callocFunc,
FreeFuncType  freeFunc 
)
inlinestaticnoexcept

Override the use of some standard library’s functions.

Override the use of the standard library’s memory allocation functions.
This method must be invoked before any other uvw function is called or after all resources have been freed and thus the underlying library doesn’t reference any allocated memory chunk.

If any of the function pointers is null, the invokation will fail.

Note: there is no protection against changing the allocator multiple times. If the user changes it they are responsible for making sure the allocator is changed while no memory was allocated with the previous allocator, or that they are compatible.

Parameters
mallocFuncReplacement function for malloc.
reallocFuncReplacement function for realloc.
callocFuncReplacement function for calloc.
freeFuncReplacement function for free.
Returns
True in case of success, false otherwise.

Definition at line 733 of file util.hpp.

◆ rusage()

static RUsage uvw::Utilities::rusage ( )
inlinestaticnoexcept

Gets the resource usage measures for the current process.

Returns
Resource usage measures, zeroes-filled object in case of errors.

Definition at line 809 of file util.hpp.

◆ setupArgs()

static char** uvw::Utilities::setupArgs ( int  argc,
char **  argv 
)
inlinestatic

Store the program arguments.

Required for getting / setting the process title.

Returns
Arguments that haven't been consumed internally.

Definition at line 754 of file util.hpp.

◆ totalMemory()

static uint64_t uvw::Utilities::totalMemory ( )
inlinestaticnoexcept

Gets memory information (in bytes).

Returns
Memory information.

Definition at line 787 of file util.hpp.

◆ uptime()

static double uvw::Utilities::uptime ( )
inlinestaticnoexcept

Gets the current system uptime.

Returns
The current system uptime or 0 in case of errors.

Definition at line 795 of file util.hpp.


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