Giter Club home page Giter Club logo

coolercppidiom's Introduction

CoolerCppIdiom

Codacy Badge

Collection of useful c++ tools / common idioms you might not found elsewhere, provide with clean code and easy to use api, mose of then are just one file with minimal dependency.

How to

Just include the corresponding file.

Useful kits

A cooler version of promise pattern, we can create our own dispatcher to dispatch task to threads(ui,pool,io,http,etc) just like using std::async and future::then.

This specific implementation uses ppltask, but we can implement it on any primise-like library for c++.

using namespace concurrency_;

auto t = delayed(1000)
| ui([] {
    std::cout << "running on ui" << std::endl;
})
| io([] {
    std::cout << "running on io" << std::endl;
    return std::this_thread::get_id();
})
| delay<std::thread::id>(100)
| pool([](std::thread::id id) {
    std::cout << "running on pool" << std::endl;
    std::cout << "received thread_id" << id  << std::endl;
});

Make json serialization easier for your life.

With nlohmann's JSON for Modern C++ plus a helper file, we can do this now

struct Person{
    std::string name;
    std::optional<std::uint32_t> age;
    std::optional<std::vector<Person>> friends;
};

JSON_AUTO(Person, name, age, friends)

void func()
{
    Person p;
    p.name = "John";
    json obj = p;
    Person op = obj;
}

A simple yet powerful event delegate implementation, support trackable listener, provide an alternate bind to std::bind which support bind to smart pointer.

Event<void(const std::string&, std::string&&)> signal1;

auto func1 = Storm::lambda([&, nocopy]() {
    signal1("123", "123");
});

auto conn1 = signal1.add([&slot1](const std::string& v, std::string&& str){
    slot1 = true;
    std::cout << "\nslot 1: " << v << ", " << std::string(std::move(str)) << std::endl;
});

Connection conn2 = signal1.add([&slot2, &conn2](const std::string& v, std::string&& str) {
    slot2 = true;
    std::cout << "\nslot 2: " << v << ", " << str << std::endl;
    conn2.disconnect();
});


func1();

An async call adapter for Qt which enables user to post async lambda to Qt's UI thread.

A easy to use c++11 thread pool.

Snowflake uuid generator in c++.

A simple throttle control.

Object leak trace, perf timer and extras.

Timetick, Datetime, FpsTimer.

Windows Com ptr implementation with clean and safe interface.

Object tree is a useful way to manage object in c++.

Generica Qt metacall which enables user to call QObject's method with name and QVariantList packed arguments.

...
const QString& object;
const QString& method; 
const QVariantList& args;
//get meta method from method name
QMetaMethod metaMethod;
Qx::metaCall(object, metaMethod, args);

Generica Qt signal map which enables user to connect QObject's signal with name and QVariantList packed arguments.

GenericSignalMapper* mapper1 = new GenericSignalMapper(method, this);
connect(object, qFlagLocation(signature.toUtf8().constData()), mapper1, SLOT(mapSlot()));
connect(mapper1, SIGNAL(mapped(QObject*, QMetaMethod, QVariantList)), this, SLOT(onGenericSignal(QObject*, QMetaMethod, QVariantList)));

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.