Skip to content

nyacpp/nya

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NYA Library

C++ header only library with a bunch of tricks.

Usage

#include <nya.hpp>
//
    uint x;   // unsigned int
    llong y;  // long long
	    
    u_p<MyClass> myObject;    // std::unique_ptr
    s_p<MyClass> myObject;    // std::shared_ptr

    int sum = std::accumulate(nya_all(v), 0);  // begin, end

Additional C++ Fun

#include <nya/api.hpp>
  • enum with conversion to and from string
#define MyEnumDef(K, V)                 \
    K(One)                              \
    V(Two, 20)                          \
    K(Three)    /* It's the third */    \
    V(Four, 40) /* It's the fourth */
nya_enum(MyEnum, MyEnumDef);

MyEnum e1 = MyEnum::One;
const char* s = e1.c_str();  // to string
MyEnum e2 = "Two";           // from string
switch (e2)                  // switch
{
    case MyEnum::One: cout << "-> 1\n"; break;
    case MyEnum::Two: cout << "-> 2\n"; break;
}
void bar(int y) { x1 = y; }

{
    nya::event_loop eventLoop;
    eventLoop.post(bar, 1);    // will be called in the following thread

    thread th([&eventLoop] { eventLoop.run(); });
    th.join();
}
nya_throw << "File %s is not found"s % fileName;
  • format — boost::format wrapper
cout << "Alpha %s Gamma"s % "Beta"; // "Alpha Beta Gamma"
template<typename F> using sig = boost::signals2::signal<F>;
sig<void(int)> foo;                // signal
void bar(int y) { x1 = y; }        // slot 1
auto baz = [](int y) { x2 = y; };  // slot 2

{
    nya::event_loop eventLoop;
    nya::invoke_in(eventLoop, bar, 1);      // async function invocation with parameter
    nya::connect_in(eventLoop, foo, baz);   // async connect to lambda  
    foo(2);                                 // slot will be called in the following thread

    thread th([&eventLoop] { eventLoop.run(); });
    th.join();
}
  • io notes
cout << SomeClass(); // any class with string cast operator
cout << std::variant<int, float>(1); // variant streaming is not in std yet
error_log << "Number %d shouldn't be here"s % 5;

Additional CMake Fun

  • submodule — automatic submodule update (copy the file, if nya is submodule itself)
include(nya/cmake/submodule.cmake)
nya_submodule(deps/my_module)
include(nya/cmake/fetch_content.cmake)
nya_fetch_content(https://github.com/catchorg/Catch2.git master)

About

C++ shortenings like llong, umap, u_p etc.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published