Managing pipelines in C++

posted in Computer food
Published January 19, 2011
Advertisement
A few days ago, I released version 0.4 of my little security library. This version allows the creation of function pipeline using a simple syntax. If R is the return type of the pipeline and A is its argument type, then


pipeline p = stage(f1) | f2 | f3 | ... | fn;


Will construct a pipeline containing n stages.

The implementation is based on a limited version of boost.function as well as on simple expression templates (because we basically construct a representation of the pipeline function without evaluating it). The first function in the pipeline must be stageified - all the subsequent ones are automatically stageified by using operator|(pipeline_stage, F).

Pipeline stages are a strange beast. The pipeline_stage class has two specialization: the base one, which accept two callable F1 and F2 (functors that inherit std::unary_function<> or function pointers) and the limited one where F2 is nulltype. Using these two specialization I'm able to build an arbitrarly complex pipeline_stage:


// ps == pipeline_stage
typeid(stage(f1)|f2|f3|f4)).name() == typeif(ps,F3>,F4>,F5>).name()


Some code has been added recently to deal with the reconstruction of pipeline stages (stage(f1) constructs ps, so stage(f1) | stage(f2) would naturally construct ps,ps > ; this has been modified so that this expression constructs a ps object).

Version 0.4 has some small issues (does not compiles on Windows ; next version will ; pipeline p = stage(f1) cannot be written, due to the lack of a constructor in pipeline), but it works quite well in practice. I added adapters for the cryptographers and the encoders to enable the construction of encryption/decryption pipelines).

You can download the zlib-licenced code -ekogen-v0.4"]from my French speaking blog (scroll to the bottom up to the "annexes" part).

And if you like reading C++, this library will please you - nothing too advanced, everything can be read easily, although I make heavy use of templates.

Enjoy !
0 likes 2 comments

Comments

DWN
Thank you, could be quite handy
January 20, 2011 03:55 AM
Emmanuel Deloget
You're welcome !

I just modified the code so that I can plug std::tr1::function<> instead of my own bits::function<>. This is even easier to use as it does not rely on something that is
potentially buggy (my own version of the function<> template is provided for systems that does not provide any implementation of the TR1 ; the CMake build system is designed to discover the TR1 support and use it when available (g++ 4.x, Visual C++ 2010).

The next version of the library (0.5.n) will work on many more systems than this version, as any TR1 dependencies will be stripped if not supported (on a per-functionnality basis ; if your compiler has tr1::function<> but not tr1::uint32_t then uin32_t will be rediscovered using other means and tr1::function<> will be used).

To be released next week (I guess).
January 20, 2011 04:43 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement
Advertisement