Giter VIP home page Giter VIP logo

ssvutils's Introduction

SSVUtils Build Status

C++14 multi-purpose utility library that only depends on the STL.

The code examples below are currently outdated.


CommandLine

--

Delegates

int result{0};
ssvu::Delegate<void(int)> onSomething;
onSomething += [&](int mValue){ result += mValue; };
onSomething += [&](int mValue){ result += mValue * 2; };
onSomething(2);
assert(result == 6);

Encoding

string source{"encode me!"};
auto encoded = ssvu::Encoding::encode<Encoding::Type::Base64>(source);
auto decoded = ssvu::Encoding::decode<Encoding::Type::Base64>(encoded);
assert(source == decoded);

FileSystem

string myPath{"/home/folder"};
ssvu::FileSystem::normalizePath(myPath);
assert(myPath == "/home/folder/");

if(!ssvu::FileSystem::exists(myPath)) ssvu::FileSystem::createFolder(myPath);

ssvu::FileSystem::removeFile(myPath + "garbage_file");

string homePath{ssvu::FileSystem::getParentPath(myPath)};
assert(homePath == "/home/");

for(const auto& filePath : ssvu::FileSystem::getScan<Mode::Recurse, Type::File>(myPath))
	// Iterate on all file paths (recursively)

for(const auto& subFolderPath : ssvu::FileSystem::getScan<Mode::Recurse, Type::Folder>(myPath))
	// Iterate on all sub folder paths (recursively)

// and more...

Global

// std::unique_ptr is verbose
using namespace ssvu;

Uptr<int> test{new int};
Uptr<int, SomeCustomDeleter>{new int};

Log

using namespace ssvu;

lo << lt("Testing log") << "Hello!" << endl;
// Prints to console: "[Testing log]	Hello!"

saveLogToFile("log.txt");
// Saves everything that was logged to "log.txt"

MemoryManager

--

PreAlloc

--

String

string test{"abcdef"};

assert(ssvu::beginsWith(test, "abc"));
assert(ssvu::endsWith(test, "def"));

string test2{"ABCDEF"};
assert(ssvu::toLower(test2) == test);

ssvu::replaceAll(test, "abc", "ABC");
assert(ssvu::beginsWith(test, "ABC"));

test += ssvu::toStr(100);
assert(test == "ABCdef100");

// and more...

TemplateSystem

// Example 1
using namespace ssvu::TemplateSystem;
Dictionary dict{{"key1", "value1"}, {"key2", "value2"}};
string toExpand{".{{key1}}.{{key2}}."};
assert(dict.getExpanded(toExpand) == ".value1.value2.");

// Example 2
using namespace ssvu::TemplateSystem;
Dictionary dict;
Dictionary subdict1{{"key", "value1"}};
Dictionary subdict2{{"key", "value2"}};
dict += {"section", subdict1};
dict += {"section", subdict2};
string toExpand{"{{#section}}.{{key}}.{{/section}}"};
assert(dict.getExpanded(toExpand) == ".value1..value2.");

Timeline

--

Utils

auto i = ssvu::getRnd(0, 5); // get random int [0, 5)
auto f = ssvu::getRndF(0.f, 5.f); // get random float [0.f, 5.f)

auto x = ssvu::getRnd(0, 100);
auto clamped = ssvu::getClamped(x, 40, 60); // gets x clamped between 40 and 60

auto rr = ssvu::toRadians(720.f);
auto dd = ssvu::toDegrees(rr);
assert(ssvu::wrapDegrees(dd) == 360.f);

std::vector<int> container{0, 5, 10, 15};
ssvu::eraseRemove(container, 10);
// container is now = {0, 5, 15}

ssvu::eraseRemoveIf(container, [&](const int& mValue){ return mValue > 0; });
// container is now = {0}

assert(ssvu::contains(container, 0));
assert(!ssvu::contains(container, 5));
assert(!ssvu::containsAny(container, {10, 15}));

// and more...

ssvutils's People

Contributors

vittorioromeo avatar j4cobgarby avatar leokolln avatar tsjost avatar

Stargazers

Jung-Hyun Ian Byun avatar M. Galib Uludag avatar fl avatar ryank231231 avatar  avatar Alex avatar YYY avatar  avatar Bara C. Tudor avatar  avatar Jonathan Ragan-Kelley avatar Evan Moran avatar  avatar  avatar Andrey avatar Trung Pham avatar abdul dakkak avatar  avatar  avatar  avatar Bill Quith avatar Sergey Lyubimov avatar Jacopo Santoni avatar Isaac Wycoff avatar H avatar Aurelio avatar Ethan Smith avatar  avatar Jacob Paul Adkins avatar D. M. avatar  avatar  avatar  avatar наб avatar  avatar Albert Tavares de Almeida avatar Glocke avatar  avatar  avatar Karim Ahmed avatar  avatar  avatar Dhi Aurrahman avatar Ben Hymers avatar Luis Panadero Guardeño avatar Mario Link avatar Violet Giraffe avatar Eric Hebert avatar Gordon McShane avatar O. Libre avatar Ariel Malka avatar Oscar avatar Dimitri Diakopoulos avatar Brad Svercl avatar x avatar Gopalakrishna Palem avatar ugo avatar  avatar Denis avatar Daniel Jour avatar  avatar

Watchers

 avatar ugo avatar  avatar  avatar  avatar наб avatar  avatar  avatar

ssvutils's Issues

Filesystem is C++ 14?

Hi,

I want use only the filesystem in c++11, it is possible?

Or i can extract the source of filesystem only to use in c++11?

Thanks.

thread_local on OS X

OS X (or more precisely, Apple's version of Clang) doesn't support thread_local storage, and so trying to compile this on OS X results in the following error:

error: thread-local storage is not supported for the current target

everywhere where thread_local is used.

More info on StackOverflow: Why does Apple clang disallow C++11 thread_local when 'official' clang supports it

Some possible ways to work around this:

proper definitions checking

in file https://github.com/SuperV1234/SSVUtils/blob/master/include/SSVUtils/Core/Detection/Detection.hpp
you are checking various expressions, eg.: #if (__linux || __unix || __posix || __LINUX__ || __linux__)
If you want to check existence of these expressions, it sould be #if defined(__linux) || defined(__unix) || defined(__posix) || defined(__LINUX__) || defined(__linux__) and so on.
If you want to check for non zero value, then you should ensure, that expressions are defined with some implicit value. In this case current code remains, but code must precede something like this:

#ifndef __posix
    #define __posix 0
#endif

Make CMake including less convoluted

I appreciate the CMake, as it simplifies inclusion in other CMake based projects. However, the requirement to depend on an extra submodule SSVCMake, and all the convoluted functions within it, make it rather hard to figure out when something doesn't work. Like, where is the ssvu target ? What targets should I depend on ? etc. etc. ?

Is there any decent documentation?

The readme says that the examples there are outdated, and generating documentation with Doxygen is hard to read.

I'm particularly looking at the filesystem module.

Don't call Base64 encryption

There's no key involved there, so it's not encryption. It's Base64 encoding and decoding. Similarly with MD5. Also with obfuscation.

These seem to be trivial issues, but next time you'll see someone using Base64 to encode and then they'll send confidential data over the wire: you'll cringe.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.