Spicy
Classes | Typedefs | Enumerations | Functions
hilti::rt Namespace Reference

Classes

class  Address
 
class  Backtrace
 
class  Bool
 
class  Bytes
 
struct  Configuration
 
struct  Context
 
class  DeferredExpression
 
class  Exception
 
class  FormattingError
 
class  Interval
 
class  IntrusivePtr
 
struct  is_tuple
 
struct  is_tuple< std::tuple< T... > >
 
class  Library
 
class  Map
 
class  Network
 
struct  Nothing
 
struct  Null
 
class  Port
 
class  RegExp
 
struct  ResourceUsage
 
class  Result
 
class  Resumable
 
class  Set
 
class  Stream
 
class  StrongReference
 
class  StrongReferenceGeneric
 
class  TemporaryDirectory
 
class  Time
 
struct  TypeInfo
 
class  Union
 
class  ValueReference
 
class  Vector
 
class  WeakReference
 
class  WouldBlock
 

Typedefs

template<typename T >
using Controllable = std::enable_shared_from_this< T >
 

Enumerations

enum  AddressFamily : int64_t { Undef, IPv4, IPv6 }
 
enum  Protocol : int64_t { Undef = 0, TCP, UDP, ICMP }
 
enum  ByteOrder : int64_t {
  Little, Big, Network, Host,
  Undef = -1
}
 

Functions

bool operator== (const Backtrace &a, const Backtrace &b)
 
std::string demangle (const std::string &symbol)
 
template<typename Result >
std::string to_string_for_print (const DeferredExpression< Result > &x)
 
template<typename Result >
std::ostream & operator<< (std::ostream &out, const DeferredExpression< Result > &x)
 
std::ostream & operator<< (std::ostream &stream, const Exception &e)
 
 HILTI_EXCEPTION (InvalidArgument, RuntimeError)
 
 HILTI_EXCEPTION (InvalidValue, RuntimeError)
 
 HILTI_EXCEPTION (MissingData, RecoverableFailure)
 
template<typename T >
std::string to_string (T &&x)
 
template<typename T >
std::string to_string_for_print (const T &x)
 
template<typename... Args>
std::string fmt (const char *fmt, const Args &... args)
 
template<typename... Args>
std::string fmt (const std::string &s, const Args &... args)
 
template<typename T >
void print (const T &t, bool newline=true)
 
template<typename T , typename std::enable_if_t< is_tuple< T >::value > * = nullptr>
void printValues (const T &t, bool newline=true)
 
void __does_not_exist ()
 
void init ()
 
void done ()
 
bool isInitialized ()
 
template<class T , class U >
IntrusivePtr< T > cast_intrusive (IntrusivePtr< U > p) noexcept
 
template<typename T >
auto range (const T &t)
 
void fatalError (const std::string &msg) __attribute__((noreturn))
 
void warning (const std::string &msg)
 
bool operator== (const Nothing &, const Nothing &)
 
bool operator!= (const Nothing &, const Nothing &)
 
std::ostream & operator<< (std::ostream &out, const Address &x)
 
std::ostream & operator<< (std::ostream &out, const AddressFamily &family)
 
std::ostream & operator<< (std::ostream &out, const Bytes &x)
 
std::ostream & operator<< (std::ostream &out, const Interval &x)
 
template<typename K , typename V >
std::ostream & operator<< (std::ostream &out, const Map< K, V > &x)
 
template<typename K , typename V >
std::ostream & operator<< (std::ostream &out, const std::pair< K, V > &x)
 
std::ostream & operator<< (std::ostream &out, const map::Empty &x)
 
std::ostream & operator<< (std::ostream &out, const Network &x)
 
std::ostream & operator<< (std::ostream &out, const Null &x)
 
template<>
std::string detail::to_string_for_print< std::optional< std::string > > (const std::optional< std::string > &x)
 
template<>
std::string detail::to_string_for_print< std::optional< std::string_view > > (const std::optional< std::string_view > &x)
 
std::ostream & operator<< (std::ostream &out, const Protocol &x)
 
std::ostream & operator<< (std::ostream &out, const Port &x)
 
template<>
std::string detail::to_string_for_print< StrongReference< std::string > > (const StrongReference< std::string > &x)
 
template<>
std::string detail::to_string_for_print< WeakReference< std::string > > (const WeakReference< std::string > &x)
 
template<>
std::string detail::to_string_for_print< ValueReference< std::string > > (const ValueReference< std::string > &x)
 
template<typename T >
std::ostream & operator<< (std::ostream &out, const StrongReference< T > &x)
 
template<typename T >
std::ostream & operator<< (std::ostream &out, const ValueReference< T > &x)
 
template<typename T >
std::ostream & operator<< (std::ostream &out, const WeakReference< T > &x)
 
std::ostream & operator<< (std::ostream &out, const RegExp &x)
 
template<>
std::string detail::to_string_for_print< Result< std::string > > (const Result< std::string > &x)
 
template<>
std::string detail::to_string_for_print< Result< std::string_view > > (const Result< std::string_view > &x)
 
template<typename T >
std::ostream & operator<< (std::ostream &out, const Set< T > &x)
 
std::ostream & operator<< (std::ostream &out, const set::Empty &x)
 
template<>
std::string detail::to_string_for_print< stream::View > (const stream::View &x)
 
std::ostream & operator<< (std::ostream &out, const Stream &x)
 
template<>
std::string detail::to_string_for_print< std::string > (const std::string &x)
 
template<>
std::string detail::to_string_for_print< std::string_view > (const std::string_view &x)
 
std::ostream & operator<< (std::ostream &out, const Time &x)
 
template<typename T , typename Allocator >
std::ostream & operator<< (std::ostream &out, const Vector< T, Allocator > &x)
 
std::ostream & operator<< (std::ostream &out, const vector::Empty &x)
 
template<typename T , typename Allocator >
bool operator!= (const Vector< T, Allocator > &a, const Vector< T, Allocator > &b)
 
void internalError (const std::string &msg) __attribute__((noreturn))
 
std::string version ()
 
void abort_with_backtrace () __attribute__((noreturn))
 
std::string linker_scope ()
 
void cannot_be_reached () __attribute__((noreturn))
 
ResourceUsage resource_usage ()
 
std::optional< std::string > getenv (const std::string &name)
 
hilti::rt::Result< hilti::rt::filesystem::path > createTemporaryFile (const std::string &prefix="")
 
hilti::rt::filesystem::path normalizePath (const hilti::rt::filesystem::path &p)
 
std::string_view rtrim (std::string_view s, const std::string &chars) noexcept
 
std::string_view ltrim (std::string_view s, const std::string &chars) noexcept
 
std::string_view trim (std::string_view s, const std::string &chars) noexcept
 
std::string_view rtrim (std::string_view s) noexcept
 
std::string_view ltrim (std::string_view s) noexcept
 
std::string_view trim (std::string_view s) noexcept
 
std::vector< std::string_view > split (std::string_view s, std::string_view delim)
 
std::vector< std::string_view > split (std::string_view s)
 
std::pair< std::string, std::string > split1 (std::string s)
 
std::pair< std::string, std::string > rsplit1 (std::string s)
 
std::pair< std::string, std::string > split1 (std::string s, const std::string &delim)
 
std::pair< std::string, std::string > rsplit1 (std::string s, const std::string &delim)
 
std::string replace (std::string s, std::string_view o, std::string_view n)
 
bool startsWith (const std::string &s, const std::string &prefix)
 
template<typename T , typename TIter = decltype(std::begin(std::declval<T>())), typename = decltype(std::end(std::declval<T>()))>
constexpr auto enumerate (T &&iterable)
 
std::string expandEscapes (std::string s)
 
std::string escapeBytes (std::string_view s, bool escape_quotes=false, bool use_octal=false)
 
std::string escapeUTF8 (std::string_view s, bool escape_quotes=false, bool escape_control=true, bool keep_hex=false)
 
template<typename T >
std::string join (const T &l, const std::string &delim="")
 
template<typename C , typename F >
auto transform (const C &x, F f)
 
template<class Iter , typename Result >
Iter atoi_n (Iter s, Iter e, uint8_t base, Result *result)
 
template<typename I1 , typename I2 >
I1 pow (I1 base, I2 exp)
 
template<typename F , std::size_t I = 0, typename... Ts>
void tuple_for_each (const std::tuple< Ts... > &tup, F func)
 
template<typename T , typename F , std::size_t TupSize = std::tuple_size_v<std::decay_t<T>>>
constexpr auto map_tuple (T &&tup, F f)
 
template<typename T , std::size_t TupSize = std::tuple_size_v<std::decay_t<T>>>
auto join_tuple (T &&tup)
 
template<typename T , std::size_t TupSize = std::tuple_size_v<std::decay_t<T>>>
auto join_tuple_for_print (T &&tup)
 
ByteOrder systemByteOrder ()
 
std::string strftime (const std::string &format, const Time &time)
 
Time strptime (const std::string &buf, const std::string &format)
 
template<typename... Hashes>
constexpr std::size_t hashCombine (std::size_t hash1, std::size_t hash2, Hashes... hashes)
 

Detailed Description

This header defines functions that are made available to HILTI programs inside the hilti::* namespace.

A map that mostly builds on std::map, but adds a couple of things:

- We add safe HILTI-side iterators become detectably invalid when the main
  containers gets destroyed.

- [Future] Automatic element expiration.

A set that mostly builds on std::set, but adds a couple of things:

- We add safe HILTI-side iterators become detectably invalid when the main
  containers gets destroyed.

- [Future] Automatic element expiration.

A vector that for large part built on std::vector, but adds a couple of things:

- We record if an element has been set at all.
- We add safe HILTIs-side iterators become detectably invalid when the main
  containers gets destroyed.
- We add auto-growth on assign.
- We track which elements are set at all.

Typedef Documentation

◆ Controllable

template<typename T >
using hilti::rt::Controllable = typedef std::enable_shared_from_this<T>

Base for classes that ValueReference::self can receive.

Enumeration Type Documentation

◆ ByteOrder

enum hilti::rt::ByteOrder : int64_t
strong

Available byte orders.

◆ Protocol

enum hilti::rt::Protocol : int64_t
strong

Protocols that can be associated with a Port.

Function Documentation

◆ abort_with_backtrace()

void hilti::rt::abort_with_backtrace ( )

Dumps a backtrack to stderr and then aborts execution.

◆ atoi_n()

template<class Iter , typename Result >
Iter hilti::rt::atoi_n ( Iter  s,
Iter  e,
uint8_t  base,
Result result 
)
inline

Parses a numerical value from a character sequence into an integer. Character sequences can start with + or - to denote the sign.

Users should check the returned iterator to detect how many characters were extracted. If the returned iterator is different from s the extracted numerical value was stored in the memory pointed to by result; otherwise result remains unchanged.

Precondition
The input sequence must not be empty, i.e., we require s != e.
Base must be in the inclusive range [2, 36].
s beginning of the input range.
e end of the input range.
base base of the input range.
result address of the memory location to used for storing
a possible parsed result.
Returns
iterator to the first character not used in value extraction.

◆ cannot_be_reached()

void hilti::rt::cannot_be_reached ( )

Aborts with an internal error saying we should not be where we are.

◆ cast_intrusive()

template<class T , class U >
IntrusivePtr<T> hilti::rt::cast_intrusive ( IntrusivePtr< U >  p)
noexcept

Casts an IntrusivePtr object to another by way of static_cast on the underlying pointer.

Parameters
pThe pointer of type U to cast to another type, T.
Returns
The pointer, as cast to type T.

◆ createTemporaryFile()

hilti::rt::Result< hilti::rt::filesystem::path > hilti::rt::createTemporaryFile ( const std::string &  prefix = "")

Creates a temporary file in the system temporary directory.

Parameters
prefixprefix to use for the file's basename
Returns
a valid path or an error

◆ demangle()

std::string hilti::rt::demangle ( const std::string &  symbol)
inline

Wrapper around the ABI's C++ demangle function.

◆ done()

void hilti::rt::done ( )

Shuts down the run-time library, freeing all resources. Once executed, no libhilti functionality can be used anymore.

◆ enumerate()

template<typename T , typename TIter = decltype(std::begin(std::declval<T>())), typename = decltype(std::end(std::declval<T>()))>
constexpr auto hilti::rt::enumerate ( T &&  iterable)

Python-style enumerate() that returns an iterable yielding pairs (index, val). From http://reedbeta.com/blog/python-like-enumerate-in-cpp17/.

◆ fatalError()

void hilti::rt::fatalError ( const std::string &  msg)
inline

Reports an internal error and aborts execution. Reports a fatal error and immediately aborts execution. This skips all cleanup and should be used only for catastrophic library issues; not for anything that can happen during "normal" operation (which is almost everything).

Reports an fatal error and aborts execution.

Note
This forwards to the corresponding HILTI runtime function.

◆ fmt() [1/2]

template<typename... Args>
std::string hilti::rt::fmt ( const char *  fmt,
const Args &...  args 
)

sprintf-style string formatting.

◆ fmt() [2/2]

template<typename... Args>
std::string hilti::rt::fmt ( const std::string &  s,
const Args &...  args 
)

sprintf-style string formatting.

◆ getenv()

std::optional< std::string > hilti::rt::getenv ( const std::string &  name)

Returns the value of an environment variable, if set.

◆ HILTI_EXCEPTION() [1/3]

hilti::rt::HILTI_EXCEPTION ( InvalidArgument  ,
RuntimeError   
)

Base class for exceptions thrown by the runtime system. Base class for exceptions created by HILTI programs. Base class for exceptions which can be recovered. Thrown when an assert statement fails. Exception triggered when a division by zero is attempted.Thrown for trouble encountered while managing the runtime environment. Exception indicating access to an already expired weak reference. Exception reflecting an attempt to modify a stream object that's been frozen.Exception indicating an undefined use of a reference type. Thrown when an invalid container index is accessed. Exception flagging invalid arguments passed to a function.

◆ HILTI_EXCEPTION() [2/3]

hilti::rt::HILTI_EXCEPTION ( InvalidValue  ,
RuntimeError   
)

Exception flagging access to an iterator that not, or no longer, valid. Exception flagging incorrect use of type-info values.

◆ HILTI_EXCEPTION() [3/3]

hilti::rt::HILTI_EXCEPTION ( MissingData  ,
RecoverableFailure   
)

Exception indicating illegal reuse of MatchState. Exception indicating that the request data is missing.

◆ init()

void hilti::rt::init ( )

Initializes the HILTI run-time library. This must be called once at startup before any other libhilti functionality can be used.

◆ internalError()

void hilti::rt::internalError ( const std::string &  msg)
inline

Reports an internal error and aborts execution.

Note
This forwards to the corresponding HILTI runtime function.

◆ isInitialized()

bool hilti::rt::isInitialized ( )

Returns true if init() has already been called.

◆ join()

template<typename T >
std::string hilti::rt::join ( const T &  l,
const std::string &  delim = "" 
)

Joins elements of a container into a string, using a specified delimiter to separate them.

◆ join_tuple()

template<typename T , std::size_t TupSize = std::tuple_size_v<std::decay_t<T>>>
auto hilti::rt::join_tuple ( T &&  tup)

Converts a tuple's elements into string representations and then concatenates those with separating commas. This version converts the tuple elements into strings using HILTI's standard rendering (which, e.g., means that strings will be surrounded by quotes).

◆ join_tuple_for_print()

template<typename T , std::size_t TupSize = std::tuple_size_v<std::decay_t<T>>>
auto hilti::rt::join_tuple_for_print ( T &&  tup)

Converts a tuple's elements into string representations and then concatenates those with separating commas. This version converts the tuple elements into strings as if they were given to a HILTI print statements (which, e.g., means that top-level strings won't be surrounded by quotes).

◆ linker_scope()

std::string hilti::rt::linker_scope ( )
inline

Returns the unique scope of the current HLTO module.

◆ ltrim() [1/2]

std::string_view hilti::rt::ltrim ( std::string_view  s,
const std::string &  chars 
)
inlinenoexcept

Returns a string view with all leading characters of a given set removed.

Note
This function is not UTF8-aware.

◆ ltrim() [2/2]

std::string_view hilti::rt::ltrim ( std::string_view  s)
inlinenoexcept

Returns a string view with all leading white space removed.

Note
This function is not UTF8-aware.

◆ map_tuple()

template<typename T , typename F , std::size_t TupSize = std::tuple_size_v<std::decay_t<T>>>
constexpr auto hilti::rt::map_tuple ( T &&  tup,
f 
)

Applies a transformation function to each element of a tuple, returning a new tuple.

◆ normalizePath()

hilti::rt::filesystem::path hilti::rt::normalizePath ( const hilti::rt::filesystem::path &  p)

Turns a path into an absolute path with all dots removed.

◆ pow()

template<typename I1 , typename I2 >
I1 hilti::rt::pow ( I1  base,
I2  exp 
)
inline

Computes integer powers

◆ print()

template<typename T >
void hilti::rt::print ( const T &  t,
bool  newline = true 
)

Corresponds to hilti::print.

◆ printValues()

template<typename T , typename std::enable_if_t< is_tuple< T >::value > * = nullptr>
void hilti::rt::printValues ( const T &  t,
bool  newline = true 
)

Corresponds to hilti::printValues.

◆ range()

template<typename T >
auto hilti::rt::range ( const T &  t)

Wrapper that returns an object suitable to operate range-based for loop on to iterator over a sequence.

◆ replace()

std::string hilti::rt::replace ( std::string  s,
std::string_view  o,
std::string_view  n 
)

Replaces all occurrences of one string with another.

Note
This function is not UTF8-aware.

◆ resource_usage()

hilti::rt::ResourceUsage hilti::rt::resource_usage ( )

Returns statistics about the current resource uage.

◆ rsplit1() [1/2]

std::pair< std::string, std::string > hilti::rt::rsplit1 ( std::string  s)

Splits a string once at the last occurrence of successive whitespace. Leaves the 2nd element of the result pair unset if whitespace does not occur.

Note
This function is not UTF8-aware.

◆ rsplit1() [2/2]

std::pair< std::string, std::string > hilti::rt::rsplit1 ( std::string  s,
const std::string &  delim 
)

Splits a string once at the last occurrence of a delimiter. Leaves the 1st element of the result pair unset if the delimiter does not occur.

Note
This function is not UTF8-aware.

◆ rtrim() [1/2]

std::string_view hilti::rt::rtrim ( std::string_view  s,
const std::string &  chars 
)
inlinenoexcept

Returns a string view with all trailing characters of a given set removed.

Note
This function is not UTF8-aware.

◆ rtrim() [2/2]

std::string_view hilti::rt::rtrim ( std::string_view  s)
inlinenoexcept

Returns a string view with all trailing white space removed.

Note
This function is not UTF8-aware.

◆ split() [1/2]

std::vector< std::string_view > hilti::rt::split ( std::string_view  s,
std::string_view  delim 
)

Splits a string at all occurrences of a delimiter. Successive occurrences of the delimiter will be split into multiple pieces.

Note
This function is not UTF8-aware.

◆ split() [2/2]

std::vector< std::string_view > hilti::rt::split ( std::string_view  s)

Splits a string at all occurrences of successive white space.

Note
This function is not UTF8-aware.

◆ split1() [1/2]

std::pair< std::string, std::string > hilti::rt::split1 ( std::string  s)

Splits a string once at the 1st occurrence of successive whitespace. Leaves the 2nd element of the result pair unset if whitespace does not occur.

Note
This function is not UTF8-aware.

◆ split1() [2/2]

std::pair< std::string, std::string > hilti::rt::split1 ( std::string  s,
const std::string &  delim 
)

Splits a string once at the 1st occurrence of a delimiter. Leaves the 2nd element of the result pair unset if the delimiter does not occur.

Note
This function is not UTF8-aware.

◆ startsWith()

bool hilti::rt::startsWith ( const std::string &  s,
const std::string &  prefix 
)
inline

Returns true if a string begins with another.

Note
This function is not UTF8-aware.

Returns true if a string begins with another.

◆ strftime()

std::string hilti::rt::strftime ( const std::string &  format,
const Time time 
)

Formats a time according to user-specified format string.

This function uses the currently active locale and timezone to format values. Formatted strings cannot exceed 128 bytes.

Parameters
formata POSIX-conformant format string, see https://pubs.opengroup.org/onlinepubs/009695399/functions/strftime.html for the available format specifiers
timetimestamp to format
Returns
formatted timestamp
Exceptions
<tt>InvalidArgument</tt>if the timestamp could not be formatted

◆ strptime()

hilti::rt::Time hilti::rt::strptime ( const std::string &  buf,
const std::string &  format 
)

Parse time from string.

This function uses the currently active locale and timezone to parse values.

Parameters
bufstring to parse
formatformat string dictating how to interpret buf, see https://pubs.opengroup.org/onlinepubs/009695399/functions/strptime.html for the available format specifiers.
Returns
parsed time value
Exceptions
<tt>InvalidArgument</tt>if the time value could not be parsed OutOfRange if the parse time value cannot be represented

◆ systemByteOrder()

hilti::rt::ByteOrder hilti::rt::systemByteOrder ( )

Returns the byte order of the system we're running on. The result is either ByteOrder::Little or ByteOrder::Big.

◆ to_string()

template<typename T >
std::string hilti::rt::to_string ( T &&  x)

Converts a HILTI runtime type into a string representation.

◆ to_string_for_print()

template<typename T >
std::string hilti::rt::to_string_for_print ( const T &  x)
inline

Converts a HILTI runtime type into the string representation that hilti::print() outputs. This representation is slightly different from the standard one (e.g., it doesn't enclose top-level strings in quotation marks).

◆ transform()

template<typename C , typename F >
auto hilti::rt::transform ( const C &  x,
f 
)

Applies a function to each element of container.

◆ trim() [1/2]

std::string_view hilti::rt::trim ( std::string_view  s,
const std::string &  chars 
)
inlinenoexcept

Returns a string view with all leading & trailing characters of a given set removed.

Note
This function is not UTF8-aware.

◆ trim() [2/2]

std::string_view hilti::rt::trim ( std::string_view  s)
inlinenoexcept

Returns a string view with all leading & trailing white space removed.

Note
This function is not UTF8-aware.

◆ tuple_for_each()

template<typename F , std::size_t I = 0, typename... Ts>
void hilti::rt::tuple_for_each ( const std::tuple< Ts... > &  tup,
func 
)

Generic tuple for-each that runs a callback for each element.

◆ version()

std::string hilti::rt::version ( )

Returns a string identifying the version of the runtime library.

◆ warning()

void hilti::rt::warning ( const std::string &  msg)

Reports a warning.