- C++17 or later required
- no external dependencies
- string manipulation
- random number generation
- ini (config) file reading/writing
- simplistic logging
- file system
Documented
- Usage examples see below
- All functions are documented in their headers
Unit Tested
- in
./test/
using the awesome doctest header-only library - tests also provide more usage examples
- Git clone or copy folder
libnada
to the same directory yourCMakeLists.txt
is in. - Add these 3 lines to your
CMakeLists.txt
...
add_subdirectory(libnada)
...
include_directories(libnada/include)
...
target_link_libraries(PROJECT_NAME PRIVATE nada)
...
bool b1 = nada::random::b(100); // always true
bool b2 = nada::random::b(50); // is true 50% of the time
bool b3 = nada::random::b(25); // is true 25% of the time
bool b4 = nada::random::b(0); // always false
int i1 = nada::random::i(1,6); // like a dice: gives 1, 2, 3, 4, 5 or 6
float f1 = nada::random::f(0,1); // gives a random float between 0 and 1,
// i.e. 0.6621, 0.1551 or 0.99101 or something
double d1 = nada::random::d(1, 1000); // gives a random double between 1 and 1000
// i.e. 551.07, 0.1987 or 851.29 or so
std::string s1 = "hello world";
// Remove whitespace
nada::str::remove_whitespace(s1); // "helloworld"
// Remove all chars
nada::str::remove(s1, 'o'); // "hellwrld"
// Get text between tags or other delimiters
std::string tagged1 = "oh that is so <tacky> isn't it?";
std::string tag1 = nada::str::get_between(tagged1, '<', '>'); // "tacky"
std::string tagged2 = "oh that is so 'tacky' isn't it?";
std::string tag2 = nada::str::get_between(tagged2, '\'', '\''); // "tacky"
// Tokenize Strings
std::string s2 = "hello world, how are you?";
std::vector<std::string> v2 = nada::str::tokenize(s2, ' '); // ["hello", "world,", "how", "are", "you?"]
std::string s3 = "0.1,0.2,0.3,0.4";
std::vector<std::string> v3 = nada::str::tokenize(s3, ','); // ["0.1", "0.2", "0.3", "0.4"]
Given subfolder/some_ini_file.ini
# contents of example ini file
first=1
second=2.5
third=4
fourth=some value
// Read values like this
nada::Ini ini("subfolder/some_ini_file.ini");
if (ini.good()) {
int i = ini.get_int<int>("first"); // 1
double d = ini.get_float<double>("second"); // 2.5
std::string s = ini.get("fourth"); // "some value"
}
// sleep + a simple millis() clock
unsigned long long m1 = nada::time::millis(); // 1669025747307
nada::time::sleep(100); // sleeps 100 ms
unsigned long long m1 = nada::time::millis(); // 1669025747407
// Sum elements using multi-threading if available
std::vector<unsigned> v = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
unsigned sum = NADA_SUM(v, std::plus()); // sum == 10
// if you got a folder structure like this for example
// .
// └── subfolder
// ├── file1.xml
// ├── file2.jpg
// ├── file3.png
// ├── file4.jpg
// └── subsubfolder
// ├── file5.txt
// └── file6.xml
std::vector<std::string> files = nada::fs::all_files("subfolder");
// => subfolder/file1.xml, subfolder/file2.jpg, subfolder/file3.png subfolder/file4.jpg
std::vector<std::string> files = nada::fs::all_files("subfolder", "jpg");
// => subfolder/file2.jpg, subfolder/file4.jpg
std::vector<std::string> files = nada::fs::all_files_recursive("subfolder", "xml");
// => subfolder/file1.xml, subfolder/subsubfolder/file6.xml