Git Product home page Git Product logo

rsm's Introduction

rsm

rsm is a utility library that contains different utilities for different purposes. It`s basically different tools I tend to reprogram with every project that I decided to centralise in a library. It is programmed in C++ and requires C++11.

Build Status

Master: Build Status Build Status

Features

  • Any
    • Type-erasure class for generic storage
    • Easy to use(copyable, movable)
  • Config
    • Allow you to read from a configuration file
    • Default Configuration type is a Key=Value type
    • Allow declaration of custom configuration type
  • Logger
    • Easy to use logger
    • Two provided log device:
      • To stdout
      • To file
  • Matrix
    • Matrix class for easier usage of matrix
    • Safe and easy to use with operator()
  • Message Dispatcher
    • Lightweight Message class to ship any kind of message
    • Virtual Message Handler to handle messages using a key=> message type association
    • Async Message Dispatcher to dispatch messages in a asynchronous way
    • Or monothread Message Dispatcher to dispatch the messages when you want
  • Timer
    • Timer that can trigger a callback when timed out
    • Can also trigger a callback when interrupted

Code Samples

Any

rsm::Any obj(std::vector<int>{0, 1, 2});

if(obj.isValid()) {
	auto val = obj.get<std::vector<int>>();
    
    for(const auto i : val) {
    	//...
    }
}

Config

rsm::Config config;
config.load("myConfig.txt");

if(config.hasConfig("key")) {
	auto value = config.get("key");
}

config.set("newKey", 42);

config.save("newConfig.txt");

Logging

rsm::Logger::addLogDevice(std::make_unique<rsm::FileLogDevice>(myLogFile.txt));
rsm::Logger::info() << "A Info Log";

MyStreambleObject myObject; 
rsm::Logger::debug() << myObject; // Assuming myStreableObject overloads operator<<

Matrix

rsm::Matrix<int> matrix(5, 10, 3); // Creates a 5x10 matrix filled with 3

matrix(2, 4) = 5; //Set value 5 to entry at row 2 and column 4
auto value = matrix(1, 3); //Return the value at row 1 and column 3

Message Dispatcher (Async)

class MyHandler : public rsm::MessageHandler {
	void onMessage(const std::string& key, const rsm::Message& message) override {
    	//...
    }
};

rsm::MessageDispatcher dispatcher;
MyHandler handler;

rsm::AsyncMessageDispatcher asyncDispatcher;
asyncDispatcher.registerHandler("asyncKey", handler);
asyncDispatcher.startDispatching(); //Start thread for automatic dispatching of pushed message
asyncDispatcher.pushMessage("asyncKey", "asyncMessage"); //Push message and dispatch
asyncDispatcher.stopDispatching(); //Stop dispatching and the dispatching thread

Message Dispatcher (Synchronous)

class MyHandler : public rsm::MessageHandler {
	void onMessage(const std::string& key, const rsm::Message& message) override {
    	//...
    }
};

rsm::MessageDispatcher dispatcher;
MyHandler handler;

dispatcher.registerHandler("syncKey", handler); //Register handler to a specific key
dispatcher.pushMessage("syncKey", "syncMessage"); //Push a message in the dispatching queue
dispatcher.dispatch(); //Required to dispatch all message previsouly pushed

Timer

rsm::Timer<void(), void()> timer;
timer.setTimeoutFunction([]() {
	rsm::Logger::info() << "The timer timed out";
});

timer.setInterruptFunction([]() {
	rsm::Logger::info() << "The timer has been interrupted";
});

timer.start(std::chrono::milliseconds(1000)); //Call the timeout function after 1seconds

timer.interrupt(); //Call the interrupt function and stop the timer

License

The library is distributed under the zlib/png license. This basically means you can use rsm in any project(commercial or not, proprietary or open-source) for free. There is no restriction to the use. You don't even need to mention rsm or me, though it would be appreciated.

Written by Jean-Sébastien Fauteux

rsm's People

Contributors

rosme avatar therocode avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

therocode

rsm's Issues

Change typedef to using

Replace where possible all typedef to using. Thus code like
typedef std::string Key;
will become
using Key = std::string;

This is the proper usage in C++11 and it doesn't change the way to use those types.

Add logging level filtering

Have the logger allow for a maximum level to be shown. (e.g. Debug for debug builds, but Warning for Release builds).

The lowest the level set, the more it shows:

Debug -> everything (Debug, Info, Warning, Critical, Error)
Info -> Info, Warning, Critical, Error
Warning -> Warning, Critical, Error
Critical -> Critical, Error
Error -> Error

Command line argument parser

The goal is to have a class that you can pass the argc and argv to be parsed, and you can query if certain arguments are present.

You can also specify the scheme you want and that if an argument is supposed to have a parameter and it's missing, the parsing will fail.

e.g. -myArgument . If is missing, the parsing returns false and you can show an error to the end user.

Modify logger to offer a stream

Currently, the code require to pass something to the logging function:
rsm::Logger::debug("ToLog")

This prevent chaining easily. It could be interesting to offer a stream somehow so this could be done:
rsm::Logger::debug() << "ToLog" << "Other Data"

Add time to logging

It could be interesting to add the time to the logging for better tracking.

Add time to logging

Currently, the logging just output, but there is no time information.

It would be nice to have this information, something like this:

[7h54m12s][Debug]: This is a debug line

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.