Setting SSH and LEMP on a bare-bones Debian server
So you got yourself access to a Debian server (or virtual private server) and have logged into it by one way or the other. In this tutorial, we will learn how to...
So you got yourself access to a Debian server (or virtual private server) and have logged into it by one way or the other. In this tutorial, we will learn how to...
A generic factory is a factory that can register any class type. It is very easy to write because we are allowed to use void pointers.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#include <functional> class Factory { public: Factory() {} ~Factory() {} void Register(const std::string _key, const std::function<void *()> _creator) { m_creators[_key] = _creator; } template<typename ClassType> ClassType* Get(const std::string _key) const { return static_cast<ClassType *>(m_creators.at(_key)()); } private: std::map<std::string, std::function<void *()> > m_creators; }; |
Usage:
1 2 3 4 5 6 7 8 9 |
int main() { Factory f; f.Register("Derived1", &BaseClass<Derived1>::CreateInterface); f.Register("Derived2", &BaseClass<Derived2>::CreateInterface); Derived1 *d1 = f.Get<Derived1>("Derived1"); Derived2 *d2 = f.Get<Derived2>("Derived2"); Derived1 *d2 = f.Get<Derived1>("Derived2"); // This also compiles!!! } |
As we are...
Problem statement: Find the largest sum that is possible in an array. I.e., find the maximum sub-array. Solution: From the very first this problem looks complicated because of how it is framed....
This is based on this Visual Studio 2013 for QtCreator along with my own changes. On Windows: Put the XML file in %APPDATA%/QtProject/qtcreator/styles On Linux/Unix: Put the XML file in $HOME/.config/QtProject/qtcreator/styles You...
‘C++ Traits’ is an idiom that allows a great level of abstraction at compile time which is normally possible only by a combination of inheritance and composition. It allows an algorithm to...
In my previous post, I gave the rather simple steps to install MSYS2/Mingw-w64. Now I will tell you how to install a custom library, specifically log4cxx. Before starting, lets acknowledge that there...
Okay… first of all… There are multiple packages and tutorials available to get one or the other working on Windows 10. This tutorial focuses on how to create a comfortable maintainable compiler...
Imagine you have been given the job of installing AC vent ducts in a house. Great. So you begin your work, starting from the basement for some reason. And there in the...
Okay, I have started working on the long demanded (for and by me) time management software. I got this idea a really long time ago and have seen nobody working on it...
Abstract This tutorial provides a quick introduction to the Unified Modeling Language. The heart of object-oriented problem solving is the construction of a model. The model abstracts the essential details of the...