TEC
A lightweight C++ library enabling safe, efficient execution in multithreaded and concurrent systems.
Loading...
Searching...
No Matches
tec_utils.hpp File Reference

Provides time-related utilities and system information functions for the tec namespace. More...

#include <chrono>
#include <cstdio>
#include <string>
#include "tec/tec_def.hpp"
#include <unistd.h>
#include <pwd.h>
#include <linux/limits.h>

Go to the source code of this file.

Classes

class  tec::Timer< Duration >
 A simple timer for measuring elapsed time. More...
 

Functions

System Utilities

Functions for retrieving system information (non-Windows platforms).

Provides utilities for retrieving the computer name and username on non-Windows platforms. Windows-specific utilities are defined in tec/mswin/tec_win_utils.hpp.

std::string tec::getcomputername ()
 Retrieves the computer hostname.
 
std::string tec::getusername ()
 Retrieves the logged-in username.
 

Time Utilities

Type aliases and functions for time-related operations.

Provides utilities for measuring time intervals using a monotonic clock, along with type aliases for common time durations and time points.

using tec::Clock = std::chrono::steady_clock
 Type alias for a monotonic clock suitable for measuring intervals.
 
using tec::Seconds = std::chrono::seconds
 Type alias for seconds duration.
 
using tec::TimePointSec = std::chrono::time_point< Clock, Seconds >
 Type alias for a time point in seconds.
 
using tec::MilliSec = std::chrono::milliseconds
 Type alias for milliseconds duration.
 
using tec::TimePointMs = std::chrono::time_point< Clock, MilliSec >
 Type alias for a time point in milliseconds.
 
using tec::MicroSec = std::chrono::microseconds
 Type alias for microseconds duration.
 
using tec::TimePointMu = std::chrono::time_point< Clock, MicroSec >
 Type alias for a time point in microseconds.
 
template<typename Duration >
Duration tec::now ()
 Returns the current time as a duration since the epoch.
 
template<typename Duration >
Duration tec::since (Duration start)
 Returns the duration since a specified start time.
 
constexpr const chartec::time_unit (Seconds)
 Returns the unit string for a duration type.
 
constexpr const chartec::time_unit (MilliSec)
 
constexpr const chartec::time_unit (MicroSec)
 
constexpr Seconds tec::one_hour ()
 Returns a constant duration of one hour.
 
constexpr Seconds tec::one_day ()
 Returns a constant duration of one day.
 

Detailed Description

Provides time-related utilities and system information functions for the tec namespace.

Author
The Emacs Cat
Date
2025-09-17

Typedef Documentation

◆ Clock

using tec::Clock = typedef std::chrono::steady_clock

Type alias for a monotonic clock suitable for measuring intervals.

Uses std::chrono::steady_clock for consistent interval measurements.

Function Documentation

◆ getcomputername()

std::string tec::getcomputername ( )
inline

Retrieves the computer hostname.

Returns the hostname of the current system using UTF-8 encoding. Returns an empty string on failure.

Returns
std::string The hostname or an empty string if the operation fails.

◆ getusername()

std::string tec::getusername ( )
inline

Retrieves the logged-in username.

Returns the username of the current user using UTF-8 encoding. Returns an empty string on failure.

Returns
std::string The username or an empty string if the operation fails.

◆ now()

template<typename Duration >
Duration tec::now ( )

Returns the current time as a duration since the epoch.

Measures the time elapsed since the clock's epoch, cast to the specified duration type.

Template Parameters
DurationThe duration type (e.g., Seconds, MilliSec, MicroSec).
Returns
Duration The current time as a duration since the epoch.

◆ one_day()

constexpr Seconds tec::one_day ( )
constexpr

Returns a constant duration of one day.

Provides a constant representing one day in seconds.

Returns
Seconds A duration of one day (86400 seconds).

◆ one_hour()

constexpr Seconds tec::one_hour ( )
constexpr

Returns a constant duration of one hour.

Provides a constant representing one hour in seconds.

Returns
Seconds A duration of one hour (3600 seconds).

◆ since()

template<typename Duration >
Duration tec::since ( Duration  start)

Returns the duration since a specified start time.

Calculates the time elapsed since the given start time, using the specified duration type.

Template Parameters
DurationThe duration type (e.g., Seconds, MilliSec, MicroSec).
Parameters
startThe start time as a duration since the epoch.
Returns
Duration The time elapsed since the start time.

◆ time_unit()

constexpr const char * tec::time_unit ( Seconds  )
constexpr

Returns the unit string for a duration type.

Provides a human-readable string representing the unit of the specified duration type.

Parameters
durationThe duration type (e.g., Seconds, MilliSec, MicroSec).
Returns
const char* The unit string ("s" for seconds, "ms" for milliseconds, "mu" for microseconds).