nstd - C ++ library - “gentleman's set” of useful classes


    I always wanted to have at hand a certain “gentleman's set” of library classes, with little dependence, which could be easily combined with other libraries and frameworks and easily transferred to other projects. As they say - turned on and forgot. And most importantly - “don’t pay for what you don’t use” (C) C ++



    nstd ::


    I like libraries consisting only of header files. Moreover, the modules are coming in C ++! :) Immediately make a reservation, the nstd library in no way claims to be the place of the great and powerful libraries and frameworks like boost, Qt, POCO, etc. etc. Rather, it is a complement to them.

    My library uses the capabilities of C ++ 17 and consists of several functionally weakly dependent on each other classes. I’ll immediately warn you that the library is actively supplementing and changing, and, perhaps, at the time you read this article, it has already changed so much that it’s better to refer to the source codes here for the latest information .

    The library contains several examples on the use of classes. For them, I have included CodeBlocks projects (for Windows). However, the examples also contain the GENie configuration file for generating other types of projects. For example, you can easily generate a Makefile for these purposes. C ++ 17 is supported by GCC 7.1 and the latest versions of Clang. Unfortunately, Visual Studio 2017 does not yet support all the features of the new standard, in particular, inline for data members and the simplified way to declare nested namespaces are not supported. Therefore, in principle, you can generate a project for VS 2017 through GENie, but it has not yet been compiled. Although, if you really need to, you can correct the sources for compilation in VS 2017 yourself, it’s not difficult there.

    If you don’t have CodeBlocks or don’t want to install it, then, using the MinGW-w64 GCC 7.1 for Windows example, I will describe how to quickly generate and compile examples using GENie and Makefiles.

    1. Download MinGW-w64 with GCC 7.1, for example from here . Unpack it into a folder convenient for you and write the path to the MinGW / bin folder into the PATH variable.
    2. Download the executable file GENie for Windows (there is also for other OS) from here .
    3. Copy genie.exe to the folder with examples where the genie.lua file is located.
    4. To generate Makefiles, run the command from the examples folder: “genie.exe gmake”
    5. In the folder with examples, the main Makefile and sub-makefiles for each project will appear.
    6. For example, to collect all the examples in the Release configuration, run the same there: "mingw32-make.exe config = release". If you want to collect only one of the examples, then you just need to add the name of the example, for example: "mingw32-make.exe config = release relinx_example".

    The nstd library is distributed under the MIT license and contains not only the classes of my development, but also third-party developments. In the description of the project on Github, I indicate which third-party classes I included in the project. In the repository, they are in a separate external folder .

    Briefly about the current contents of nstd: I already presented the Relinx

    class on Habrahabr here . Simply put, this is LINQ for C ++. Lazy computing is supported and almost all .NET LINQ methods are implemented. I decided to enable Relinx in nstd. Good is not lost :). signal_slot

    classes are convenient in that they allow signals and slots to automatically disconnect from each other when the connection between them is broken. Each slot connection with a signal of any type is represented by the connection class, upon destruction of which the signal-slot bundle breaks. The important thing is that connection, unlike signals and slots, is not a template, which allows you to save it in any container, regardless of the type of signal and slot. Accordingly, if this container is destroyed, all communications with the signals will be broken. This is convenient when the object containing this container is destroyed, and you do not need to specifically disconnect from the signals - this will happen automatically.

    live_propertybuilt on the basis of signal_slot classes. This is a binding over types, which allows you to track changes over them and, if desired, you can control the behavior: change the value or not.

    expiry_cache is a template container that stores data only for a certain time and notifies with a signal about the expiration of the data. It works in two modes: prolongs the life of the data if it was accessed during the storage time, and the mode without extending the life of the data. Also, there is an automatic cleaning mode in the background through a separate stream (auto vacuum).

    json is a third-party library for working with the JSON data format.

    asio is a third-party library for working with network connections. Perhaps it will soon enter the C ++ standard.

    urdl- a third-party library from the author asio, but forked and developed by other developers. It allows you to conveniently download data from the network.

    sqlite is a third-party wrapper over sqlite3. Very interesting implementation.

    quantum random number provider is a random number generator class using the free QRNG service (http://qrng.anu.edu.au), which returns random numbers generated on quantum equipment.

    For examples of using these classes (and some others that I haven't mentioned here), check out the Github repository here . If you have questions or have good suggestions - please contact!

    I am actively trying to complement the nstd library with useful classes. I invite everyone to take part in the development of the nstd library. If there are good and useful classes, then send me. I will try to adapt and include in the library.

    /// TODO:

    In the near future I want to implement remote signals that work through a TCP or UDP connection. I want to use these signals for communication between processes and communication over the network.

    There is still an idea to implement GUI classes based on Blend2D or AGG and using its implementation of signals slots. I have not yet decided which of the graphic libraries to take as a basis. I will be glad to hear your opinion on this matter.

    Also popular now: