LIPH's C++ Codes
liph Namespace Reference

Namespaces

namespace  io
 
namespace  noncopyable_
 
namespace  requests
 

Classes

class  avl
 
struct  base64
 
class  big_integer
 
class  blocking_queue
 
class  csv
 
class  double_buffer
 
class  double_buffer_with_shared_ptr
 
class  final_action
 
class  flags
 
class  hierarchical_mutex
 
class  json
 
class  log_message
 
class  logger
 
class  no_destructor
 
class  prepared_statement
 
class  prime_sieve
 
class  rand
 
struct  random
 
struct  rgb
 
class  scoped_thread
 
struct  singleton
 
class  skip_list
 
class  spinlock
 
class  sqlite
 
class  thread_guard
 
class  threadpool
 
class  timer
 
class  unique_unlock
 

Concepts

concept  Printable
 

Typedefs

using file_ptr = std::unique_ptr< FILE, decltype([](FILE *f) { if(f) fclose(f)
 
typedef noncopyable_::noncopyable noncopyable
 

Enumerations

enum class  color256 : uint8_t {
  Black = 0 , Maroon = 1 , Green = 2 , Olive = 3 ,
  Navy = 4 , Purple = 5 , Teal = 6 , Silver = 7 ,
  Grey = 8 , Red = 9 , Lime = 10 , Yellow = 11 ,
  Blue = 12 , Fuchsia = 13 , Aqua = 14 , White = 15 ,
  NavyBlue = 17 , DarkBlue = 18 , DarkGreen = 22 , DarkCyan = 36 ,
  LightSeaGreen = 37 , DarkTurquoise = 44 , MediumSpringGreen = 49 , DarkRed = 52 ,
  BlueViolet = 57 , SteelBlue = 67 , CornflowerBlue = 69 , CadetBlue = 72 ,
  MediumTurquoise = 80 , DarkMagenta = 90 , DarkViolet = 92 , LightSlateGrey = 103 ,
  MediumPurple = 104 , LightSlateBlue = 105 , DarkSeaGreen = 108 , LightGreen = 119 ,
  MediumVioletRed = 126 , IndianRed = 131 , MediumOrchid = 134 , DarkGoldenrod = 136 ,
  RosyBrown = 138 , DarkKhaki = 143 , LightSteelBlue = 147 , GreenYellow = 154 ,
  Orchid = 170 , Violet = 177 , Tan = 180 , HotPink = 205 ,
  DarkOrange = 208 , LightCoral = 210 , SandyBrown = 215
}
 

Functions

template<class T >
void erase (std::vector< T > &v, const std::set< size_t > &idx)
 Erases the specified elements from v, according to index in idx. More...
 
template<class T >
std::vector< T > topk (const std::vector< T > &data, size_t k)
 
template<class T >
find_kth (const std::vector< T > &data, size_t k)
 
template<class T >
int binary_search (T a[], int n, T val)
 
void sleeps (int n)
 
void sleepms (int n)
 
std::string MD5 (const std::string &msg)
 
std::string md5 (const std::string &msg)
 
bool read_file (const std::filesystem::path &pathname, std::string &output)
 read all from pathname, append to output More...
 
bool write_file (const std::filesystem::path &pathname, const std::string &str)
 write all to pathname More...
 
bool path_exists (const std::string &pathname)
 check path(file or directory) exists More...
 
std::vector< std::string > list_files (const std::string &pathname)
 list all files(including directories) in pathname recursively and sort by names More...
 
file_ptr fopen (const char *filename, char const *mode)
 
bool mkdir (const std::filesystem::path &path)
 
bool mkdirp (const std::filesystem::path &path)
 
unsigned bkdr_hash (const char *str)
 
uint64_t bkdr_hash64 (const char *str)
 
template<typename To , typename From >
To implicit_cast (const From &f)
 
template<typename To , typename From >
To down_cast (From *f)
 
template<typename To , typename From >
To down_cast (From &f)
 
template<typename To , typename From >
To bit_cast (const From &from)
 
template<class T >
std::string demangle ()
 
template<class T >
std::string demangle (const T &t)
 
template<class F >
auto finally (F &&f) noexcept
 
template<class T >
make_default ()
 
template<class T1 , class T2 >
std::ostream & operator<< (std::ostream &o, const std::pair< T1, T2 > &p)
 
std::ostream & operator<< (std::ostream &o, const std::vector< bool > &vb)
 
std::ostream & operator<< (std::ostream &o, const char *s)
 
std::ostream & operator<< (std::ostream &o, const std::string &s)
 
std::ostream & operator<< (std::ostream &o, std::string_view s)
 
template<std::ranges::input_range Range>
std::ostream & operator<< (std::ostream &o, const Range &range)
 
template<class K , class V >
std::ostream & operator<< (std::ostream &o, const std::map< K, V > &map)
 
template<class K , class V >
std::ostream & operator<< (std::ostream &o, const std::unordered_map< K, V > &map)
 
void println ()
 
void print (bool b)
 
template<Printable T>
void print (T &&t)
 
template<Printable T, Printable... Args>
void print (T &&head, Args &&...args)
 
template<Printable... Args>
void print (bool head, Args &&...args)
 
void err_exit (const char *str=nullptr)
 
void err_exit (const std::string &str)
 
void err_exit_if (bool error)
 
void bzero (void *p, size_t n)
 
int become_daemon (int flags)
 
bool single_proc (const char *lock_file_path, bool exit)
 
template<class RandomIt , class Compare = std::less<typename std::iterator_traits<RandomIt>::value_type>>
void bubble_sort (RandomIt first, RandomIt last, Compare comp=Compare())
 
template<class RandomIt , class Compare = std::less<typename std::iterator_traits<RandomIt>::value_type>>
void selection_sort (RandomIt first, RandomIt last, Compare comp=Compare())
 
template<class RandomIt , class Compare = std::less<typename std::iterator_traits<RandomIt>::value_type>>
RandomIt partition (RandomIt first, RandomIt last, const Compare &comp=Compare())
 
template<class RandomIt , class Compare = std::less<typename std::iterator_traits<RandomIt>::value_type>>
void quick_sort (RandomIt first, RandomIt last, Compare comp=Compare())
 
template<class RandomIt , class Compare = std::less<typename std::iterator_traits<RandomIt>::value_type>>
void merge (RandomIt first, RandomIt mid, RandomIt last, Compare comp=Compare())
 将有序的[first, mid) 和 [mid, last) 合并为有序的 [first, last) More...
 
template<class RandomIt , class Compare = std::less<typename std::iterator_traits<RandomIt>::value_type>>
void merge_sort (RandomIt first, RandomIt last, Compare comp=Compare())
 
template<class RandomIt , class Compare = std::less<typename std::iterator_traits<RandomIt>::value_type>>
void insert_sort (RandomIt first, RandomIt last, Compare comp=Compare())
 
template<class RandomIt , class Distance , class Compare = std::less<typename std::iterator_traits<RandomIt>::value_type>>
void shell_insert (RandomIt first, RandomIt last, Distance dk, Compare comp=Compare())
 
template<class RandomIt , class Compare = std::less<typename std::iterator_traits<RandomIt>::value_type>>
void shell_sort (RandomIt first, RandomIt last, Compare comp=Compare())
 
void counting_sort (int A[], int n, int max)
 
void radix_sort (int A[], int n, int d)
 
void bucket_sort (int A[], int n, int min, int max, int m)
 
std::string_view ltrim (std::string_view s, std::string_view charset)
 
std::string_view rtrim (std::string_view s, std::string_view charset)
 
std::string_view trim (std::string_view s, std::string_view charset)
 
void split (std::vector< std::string > &tokens, const std::string &s, const std::string &delimiters=" ")
 Split @s to tokens by @delimiters and append to @tokens. More...
 
std::vector< std::string > split (const std::string &s, const std::string &delimiters=" ")
 Split @s to tokens by @delimiters and return. More...
 
std::string basename (std::string_view path)
 Return basename of @path. More...
 
std::string dirname (std::string_view path)
 Return dirname of @path. More...
 
void skip_whitespace (std::string_view &sv)
 @sv skips leading whitespace characters and be the substr More...
 
bool eat_symbol (std::string_view &sv, std::string_view symbol)
 
std::optional< int > to_int (std::string_view str)
 Convert @str to int. More...
 
std::string replace (std::string_view str, std::string_view old, std::string_view New)
 Replace all @old in @str with @New. More...
 
constexpr bool startswith (std::string_view s, std::string_view t) noexcept
 
constexpr bool endswith (std::string_view s, std::string_view t) noexcept
 
template<typename Target = std::string, typename Source = std::string>
Target to (const Source &s)
 Convert source to target. More...
 
template<std::ranges::input_range Range>
std::string join (const Range &range, const std::string &sep=" ")
 Join all items in @range into a string, using @sep as separator. More...
 
std::string color256fg (unsigned char n)
 
std::string color256bg (unsigned char n)
 
std::string color_reset ()
 
bool stdin_echo_on ()
 
bool stdin_echo_off ()
 
bool stdin_buffering_on ()
 
bool stdin_buffering_off ()
 
void clear_screen ()
 
void clear_scrollback_buffer ()
 
void reset_screen ()
 
std::string color256fg (uint8_t)
 
std::string color256bg (uint8_t)
 
std::string color256fg (color256 c)
 
std::string color256bg (color256 c)
 
std::string text_bold ()
 
std::string text_faint ()
 
std::string text_italic ()
 
std::string text_underline ()
 
std::string text_blink ()
 
std::string text_rapid_blink ()
 
std::string text_reverse ()
 
std::string text_conceal ()
 
std::string text_strikethrough ()
 
int julianday (int year, int month, int day)
 
int day_of_the_week (int y, int m, int d)
 

Typedef Documentation

◆ file_ptr

using liph::file_ptr = typedef std::unique_ptr<FILE, decltype([](FILE *f) { if (f) fclose(f)

◆ noncopyable

Enumeration Type Documentation

◆ color256

enum class liph::color256 : uint8_t
strong
Enumerator
Black 
Maroon 
Green 
Olive 
Navy 
Purple 
Teal 
Silver 
Grey 
Red 
Lime 
Yellow 
Blue 
Fuchsia 
Aqua 
White 
NavyBlue 
DarkBlue 
DarkGreen 
DarkCyan 
LightSeaGreen 
DarkTurquoise 
MediumSpringGreen 
DarkRed 
BlueViolet 
SteelBlue 
CornflowerBlue 
CadetBlue 
MediumTurquoise 
DarkMagenta 
DarkViolet 
LightSlateGrey 
MediumPurple 
LightSlateBlue 
DarkSeaGreen 
LightGreen 
MediumVioletRed 
IndianRed 
MediumOrchid 
DarkGoldenrod 
RosyBrown 
DarkKhaki 
LightSteelBlue 
GreenYellow 
Orchid 
Violet 
Tan 
HotPink 
DarkOrange 
LightCoral 
SandyBrown 

Function Documentation

◆ basename()

std::string liph::basename ( std::string_view  path)

Return basename of @path.

◆ become_daemon()

int liph::become_daemon ( int  flags)

◆ binary_search()

template<class T >
int liph::binary_search ( a[],
int  n,
val 
)

◆ bit_cast()

template<typename To , typename From >
To liph::bit_cast ( const From &  from)
inline

◆ bkdr_hash()

unsigned liph::bkdr_hash ( const char *  str)
inline

◆ bkdr_hash64()

uint64_t liph::bkdr_hash64 ( const char *  str)
inline

◆ bubble_sort()

template<class RandomIt , class Compare = std::less<typename std::iterator_traits<RandomIt>::value_type>>
void liph::bubble_sort ( RandomIt  first,
RandomIt  last,
Compare  comp = Compare() 
)

◆ bucket_sort()

void liph::bucket_sort ( int  A[],
int  n,
int  min,
int  max,
int  m 
)

◆ bzero()

void liph::bzero ( void *  p,
size_t  n 
)
inline

◆ clear_screen()

void liph::clear_screen ( )

◆ clear_scrollback_buffer()

void liph::clear_scrollback_buffer ( )

◆ color256bg() [1/3]

std::string liph::color256bg ( color256  c)
inline

◆ color256bg() [2/3]

std::string liph::color256bg ( uint8_t  )

◆ color256bg() [3/3]

std::string liph::color256bg ( unsigned char  n)

◆ color256fg() [1/3]

std::string liph::color256fg ( color256  c)
inline

◆ color256fg() [2/3]

std::string liph::color256fg ( uint8_t  )

◆ color256fg() [3/3]

std::string liph::color256fg ( unsigned char  n)

◆ color_reset()

std::string liph::color_reset ( )

◆ counting_sort()

void liph::counting_sort ( int  A[],
int  n,
int  max 
)

◆ day_of_the_week()

int liph::day_of_the_week ( int  y,
int  m,
int  d 
)
inline

◆ demangle() [1/2]

template<class T >
std::string liph::demangle ( )

◆ demangle() [2/2]

template<class T >
std::string liph::demangle ( const T &  t)

◆ dirname()

std::string liph::dirname ( std::string_view  path)

Return dirname of @path.

◆ down_cast() [1/2]

template<typename To , typename From >
To liph::down_cast ( From &  f)
inline

◆ down_cast() [2/2]

template<typename To , typename From >
To liph::down_cast ( From *  f)
inline

◆ eat_symbol()

bool liph::eat_symbol ( std::string_view &  sv,
std::string_view  symbol 
)

@sv skips leading @symbol and be the substr

Returns
true if @sv start swith @symbol

◆ endswith()

constexpr bool liph::endswith ( std::string_view  s,
std::string_view  t 
)
constexprnoexcept
Returns
true if s ends with t

◆ erase()

template<class T >
void liph::erase ( std::vector< T > &  v,
const std::set< size_t > &  idx 
)

Erases the specified elements from v, according to index in idx.

◆ err_exit() [1/2]

void liph::err_exit ( const char *  str = nullptr)
inline

◆ err_exit() [2/2]

void liph::err_exit ( const std::string &  str)
inline

◆ err_exit_if()

void liph::err_exit_if ( bool  error)
inline

◆ finally()

template<class F >
auto liph::finally ( F &&  f)
noexcept

◆ find_kth()

template<class T >
T liph::find_kth ( const std::vector< T > &  data,
size_t  k 
)

◆ fopen()

file_ptr liph::fopen ( const char *  filename,
char const *  mode 
)
inline

◆ implicit_cast()

template<typename To , typename From >
To liph::implicit_cast ( const From &  f)
inline

◆ insert_sort()

template<class RandomIt , class Compare = std::less<typename std::iterator_traits<RandomIt>::value_type>>
void liph::insert_sort ( RandomIt  first,
RandomIt  last,
Compare  comp = Compare() 
)

◆ join()

template<std::ranges::input_range Range>
std::string liph::join ( const Range &  range,
const std::string &  sep = " " 
)

Join all items in @range into a string, using @sep as separator.

◆ julianday()

int liph::julianday ( int  year,
int  month,
int  day 
)
inline

◆ list_files()

std::vector< std::string > liph::list_files ( const std::string &  pathname)

list all files(including directories) in pathname recursively and sort by names

◆ ltrim()

std::string_view liph::ltrim ( std::string_view  s,
std::string_view  charset = " \n\r\t\f\v" 
)

Remove whitespace characters to the left of s

Parameters
charsetdefault: whitespace(" \n\r\t\f\v")
Returns
sub string_view of s

◆ make_default()

template<class T >
T liph::make_default ( )

◆ MD5()

std::string liph::MD5 ( const std::string &  msg)

◆ md5()

std::string liph::md5 ( const std::string &  msg)

◆ merge()

template<class RandomIt , class Compare = std::less<typename std::iterator_traits<RandomIt>::value_type>>
void liph::merge ( RandomIt  first,
RandomIt  mid,
RandomIt  last,
Compare  comp = Compare() 
)

将有序的[first, mid) 和 [mid, last) 合并为有序的 [first, last)

◆ merge_sort()

template<class RandomIt , class Compare = std::less<typename std::iterator_traits<RandomIt>::value_type>>
void liph::merge_sort ( RandomIt  first,
RandomIt  last,
Compare  comp = Compare() 
)

◆ mkdir()

bool liph::mkdir ( const std::filesystem::path &  path)
inline

mkdir

Returns
true if directory exists finally

◆ mkdirp()

bool liph::mkdirp ( const std::filesystem::path &  path)
inline

mkdir -p

Returns
true if directory exists finally

◆ operator<<() [1/8]

std::ostream & liph::operator<< ( std::ostream &  o,
const char *  s 
)
inline

◆ operator<<() [2/8]

template<std::ranges::input_range Range>
std::ostream & liph::operator<< ( std::ostream &  o,
const Range &  range 
)

◆ operator<<() [3/8]

template<class K , class V >
std::ostream & liph::operator<< ( std::ostream &  o,
const std::map< K, V > &  map 
)

◆ operator<<() [4/8]

template<class T1 , class T2 >
std::ostream & liph::operator<< ( std::ostream &  o,
const std::pair< T1, T2 > &  p 
)

◆ operator<<() [5/8]

std::ostream & liph::operator<< ( std::ostream &  o,
const std::string &  s 
)
inline

◆ operator<<() [6/8]

template<class K , class V >
std::ostream & liph::operator<< ( std::ostream &  o,
const std::unordered_map< K, V > &  map 
)

◆ operator<<() [7/8]

std::ostream & liph::operator<< ( std::ostream &  o,
const std::vector< bool > &  vb 
)
inline

◆ operator<<() [8/8]

std::ostream & liph::operator<< ( std::ostream &  o,
std::string_view  s 
)
inline

◆ partition()

template<class RandomIt , class Compare = std::less<typename std::iterator_traits<RandomIt>::value_type>>
RandomIt liph::partition ( RandomIt  first,
RandomIt  last,
const Compare &  comp = Compare() 
)

◆ path_exists()

bool liph::path_exists ( const std::string &  pathname)

check path(file or directory) exists

◆ print() [1/4]

void liph::print ( bool  b)
inline

◆ print() [2/4]

template<Printable... Args>
void liph::print ( bool  head,
Args &&...  args 
)

◆ print() [3/4]

template<Printable T, Printable... Args>
void liph::print ( T &&  head,
Args &&...  args 
)

◆ print() [4/4]

template<Printable T>
void liph::print ( T &&  t)

◆ println()

void liph::println ( )
inline

◆ quick_sort()

template<class RandomIt , class Compare = std::less<typename std::iterator_traits<RandomIt>::value_type>>
void liph::quick_sort ( RandomIt  first,
RandomIt  last,
Compare  comp = Compare() 
)

◆ radix_sort()

void liph::radix_sort ( int  A[],
int  n,
int  d 
)

◆ read_file()

bool liph::read_file ( const std::filesystem::path &  pathname,
std::string &  output 
)

read all from pathname, append to output

◆ replace()

std::string liph::replace ( std::string_view  str,
std::string_view  s,
std::string_view  t 
)

Replace all @old in @str with @New.

◆ reset_screen()

void liph::reset_screen ( )

◆ rtrim()

std::string_view liph::rtrim ( std::string_view  s,
std::string_view  charset = " \n\r\t\f\v" 
)

Remove whitespace characters to the right of s

See also
ltrim

◆ selection_sort()

template<class RandomIt , class Compare = std::less<typename std::iterator_traits<RandomIt>::value_type>>
void liph::selection_sort ( RandomIt  first,
RandomIt  last,
Compare  comp = Compare() 
)

◆ shell_insert()

template<class RandomIt , class Distance , class Compare = std::less<typename std::iterator_traits<RandomIt>::value_type>>
void liph::shell_insert ( RandomIt  first,
RandomIt  last,
Distance  dk,
Compare  comp = Compare() 
)

增量为 dk 的插入排序 dk = 1 => insert_sort

◆ shell_sort()

template<class RandomIt , class Compare = std::less<typename std::iterator_traits<RandomIt>::value_type>>
void liph::shell_sort ( RandomIt  first,
RandomIt  last,
Compare  comp = Compare() 
)

◆ single_proc()

bool liph::single_proc ( const char *  lock_file_path,
bool  exit 
)

◆ skip_whitespace()

void liph::skip_whitespace ( std::string_view &  sv)

@sv skips leading whitespace characters and be the substr

◆ sleepms()

void liph::sleepms ( int  n)
inline

◆ sleeps()

void liph::sleeps ( int  n)
inline

◆ split() [1/2]

std::vector< std::string > liph::split ( const std::string &  s,
const std::string &  delimiters 
)

Split @s to tokens by @delimiters and return.

◆ split() [2/2]

void liph::split ( std::vector< std::string > &  tokens,
const std::string &  s,
const std::string &  delimiters 
)

Split @s to tokens by @delimiters and append to @tokens.

◆ startswith()

constexpr bool liph::startswith ( std::string_view  s,
std::string_view  t 
)
constexprnoexcept
Returns
true if s starts with t

◆ stdin_buffering_off()

bool liph::stdin_buffering_off ( )

◆ stdin_buffering_on()

bool liph::stdin_buffering_on ( )

◆ stdin_echo_off()

bool liph::stdin_echo_off ( )

◆ stdin_echo_on()

bool liph::stdin_echo_on ( )

◆ text_blink()

std::string liph::text_blink ( )
inline

◆ text_bold()

std::string liph::text_bold ( )
inline

◆ text_conceal()

std::string liph::text_conceal ( )
inline

◆ text_faint()

std::string liph::text_faint ( )
inline

◆ text_italic()

std::string liph::text_italic ( )
inline

◆ text_rapid_blink()

std::string liph::text_rapid_blink ( )
inline

◆ text_reverse()

std::string liph::text_reverse ( )
inline

◆ text_strikethrough()

std::string liph::text_strikethrough ( )
inline

◆ text_underline()

std::string liph::text_underline ( )
inline

◆ to()

template<typename Target = std::string, typename Source = std::string>
Target liph::to ( const Source &  s)

Convert source to target.

◆ to_int()

std::optional< int > liph::to_int ( std::string_view  s)

Convert @str to int.

◆ topk()

template<class T >
std::vector< T > liph::topk ( const std::vector< T > &  data,
size_t  k 
)

◆ trim()

std::string_view liph::trim ( std::string_view  s,
std::string_view  charset = " \n\r\t\f\v" 
)

Remove whitespace characters to the left and right of s

See also
ltrim

◆ write_file()

bool liph::write_file ( const std::filesystem::path &  pathname,
const std::string &  str 
)

write all to pathname