Util

pimpl

Container for an unknown object. It stores a pointer to an object and its destructor. Pimpl can be used to hide includes from the main model to speed up compile time.
Nameabmt::util::pimpl
Header#include <abmt/util/pimpl.h>

Attributes

void* p
std::function<void()> destruct
std::size_t tid

Methods

pimpl()=default
pimpl(T* instance)
pimpl(const pimpl& p)=delete
void set(T* instance)Sets a new pointer with a new type. When it was set before the old object is deleted.
T& get()
bool is_type()template function
bool is_set()
T& get2()when you know what you are doing and what your past me has done... (returns cast without type-check)
~pimpl()

default_ptr < typename T >

A std::shared_ptr with default initialization of T.
Nameabmt::default_ptr
Header#include <abmt/util/default_ptr.h>

Methods

default_ptr()
default_ptr(T* p)
default_ptr(T2* p)
default_ptr(const std::shared_ptr< T2 >& p)

str_utils

#ifndef SHARED_ABMT_STR_UTILS_H_
#define SHARED_ABMT_STR_UTILS_H_

#include <abmt/time.h>

#include <string>
#include <vector>

namespace abmt{
namespace util{

std::string str_to_upper(std::string s);
std::string str_to_lower(std::string s);

std::string str_replace(std::string str,std::string search, std::string replace);

/// Removes leading and tailing " \n\r\t"
std::string str_trim(std::string s);
std::vector<std::string> str_split(std::string target, std::string token = ",");
std::vector<std::string> str_split_and_trim(std::string target, std::string token = ",");

/// Replaces #Y #y #M #D #h #m #s #s.s in str with date (#Y -> 2020, #y -> 20).
std::string str_replace_date(std::string str = "#Y-#M-#D #h:#m:#s", abmt::date d = abmt::time::now());

/// "format" can contain #Y #y #M #D #h #m #s. For seconds can have subseconds.
abmt::date str_read_date(std::string str,std::string format);

/// Tries to guess the format of str. Returns date.is_zero() on parse fail.
abmt::date str_read_date(std::string str);

} //namespace util
} //namespace abmt

#endif
Impressum