Skip to content

Calling function via void* pointer with arguments contained in std::container in a C++03 way

Recently I posted a technique that can be used to call functions, passed as raw void* pointers with arguments contained in an std::vector, so that the arguments are correctly transformed from container to normal C/C++–style arguments list. The method proposed was quite generalized and pretty type–safe. But it had one limitation: it required C++0x compiler supporting variadic templates.
So I decided to solve the original problem using C++03 compiler (which are mostly used in production today).

Continue reading ‘Calling function via void* pointer with arguments contained in std::container in a C++03 way’ »

Calling function via void* pointer with arguments contained in std::container

Today I passed by a question posted to accu-general mailing list of Accu organization, which raised my interest. The guy was asking if it is possible to call a function, previously casted to void* pointer, passing to it a number of homogeneous arguments, with their unknown exact quantity at compile–time, that are contained in a container, e.g. vector. Simply saying, expressed in pseudo-code, he wanted something like:

    template <class TParameterType>
    void call_function(void *pFunction, std::vector<tparametertype> pars)
    {
        pFunction(pars.begin(), pars.end());
    }

Easy to imagine — tricky to implement! :)

Continue reading ‘Calling function via void* pointer with arguments contained in std::container’ »

RCF 1.2 + OpenSSL

Being asked about code snippet showing real working example of using RCF together with OpenSSL, I decided to create such a refined self–contained example.
I tried to make it as close to available docs and samples as possible, still keeping it compilable and working.

Continue reading ‘RCF 1.2 + OpenSSL’ »

SSL certificates as easy as 1,2,.. 3!

These days I yet again faced the problem of establishing of secure connection between my client and server applications. Although this time the task by itself was quite small and simple and (so a hand–made solution would definitely suffice) I’d decided to go via standard approach, i.e. using something that has already been invented, tested and proved to be useful.

When we’re talking about transport–level security that’s undisputidly what is called a Secure Sockets Layer, or SSL. There is a number of free libraries out there implementing SSL, like popular OpenSSL or less popular Ajisai (based on cryptographic C++ library Botan). In my case I had to stick to OpenSSL as I also was about to use RCF for my client–server communication and RCF had already got support for OpenSSL integration to secure it’s transport channels.

OpenSSL uses certificates to make secured interactions work. So we immediately face a problem of getting these certificates. Searching the Internet would not give immediate understanding of what kind of certificate to we need and where to get the required one. so I’ve put all the pieces of information together and am sharing that knowledge with you :)

Continue reading ‘SSL certificates as easy as 1,2,.. 3!’ »

C++ Delayed Constructor 2: multi–level approach

Few days ago I described a mechanism which allows bind–like operations for constructors. In other words it gives opportunity for us to define object construction details once (e.g. all parameters required for object construction) and later to create this object, but without the need to specify these parameters at the place of creation, i.e. we first bind constructor’s parameters to some helper object and later we just ask this helper object to create our original object, whilst the helper cares about all construction parameters for our obj.

I decided to develop this idea a bit further to allow “multi–level” delayed construction of objects.

Continue reading ‘C++ Delayed Constructor 2: multi–level approach’ »

Converting Variadic Template Arguments Pack to Boost Mpl Sequence

Most existing articles describing variadic templates today address just some basic things, giving few encouraging examples, starting with recursive implementation of count<T...> method and usually finishing with type–safe printf, which by the way is very nice! :)

I’d like to add to these starter–oriented hints yet another one. The question risen usually when one first meets variadic templates is “a… is it possible to find out which types exactly were passed, like enumerate them and all sorts of such things?…” Usual answer refers to mentioned above count<T...> implementation only, saying that there could be little done with regards to the rest of problems. While it is true to some extent it is not actually.

Continue reading ‘Converting Variadic Template Arguments Pack to Boost Mpl Sequence’ »

C++ Delayed Constructor

Messing recently with a multiple–dispatch solution in C++ / Boost / Loki environment I faced a number of challenges one of which was to implement a “delayed constructor” mechanism. Basically, this is a somehow known problem of binding values to constructors which isn’t solvable by boost::bind as there is no way to get an address of the constructor, but for which a solutions exists in boost::lambda::bind. Honestly, I didn’t look into there in deep. Instead I went for a short [maybe elegant] solution, compilable by any compiler supporting variadic templates (spirit of c++0x is already within our codes):

Continue reading ‘C++ Delayed Constructor’ »