Click here to Skip to main content
15,885,757 members
Articles / Programming Languages / C++

RCF - Interprocess Communication for C++

Rate me:
Please Sign up or sign in to vote.
4.94/5 (147 votes)
25 Oct 2011CPOL20 min read 4.6M   8.4K   331  
A server/client IPC framework, using the C++ preprocessor as an IDL compiler.
#ifndef INCLUDE_SF_SERIALIZESTL_HPP
#define INCLUDE_SF_SERIALIZESTL_HPP

#include <SF/Archive.hpp>

namespace SF {

    class PushBackSemantics
    {
    public:
        template<typename Container, typename Value>
        void operator()(Container &container, const Value &value)
        {
            container.push_back(value);
        }
    };

    class InsertSemantics
    {
    public:
        template<typename Container, typename Value>
        void operator()(Container &container, const Value &value)
        {
            container.insert(value);
        }
    };

    template<typename AddSemantics, typename StlContainer>
    void serializeStlContainer(Archive &ar, StlContainer &t, const unsigned int)
    {

        typedef typename StlContainer::iterator Iterator;
        typedef typename StlContainer::value_type Value;

        if (ar.isRead())  
        {
            t.clear();
            unsigned int count = 0;
            ar & count;
            for (unsigned int i=0; i<count; i++)
            {
                Value value;
                ar & value;
                AddSemantics()(t, value);
            }
        }
        else if (ar.isWrite()) 
        {
            unsigned int count = static_cast<unsigned int>(t.size());
            ar & count;
            Iterator it = t.begin();
            for (unsigned int i=0; i<count; i++) 
            {
                ar & *it;
                it++;
            }
        }
    }

}

#endif // ! INCLUDE_SF_SERIALIZESTL_HPP

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Australia Australia
Software developer, from Sweden and now living in Canberra, Australia, working on distributed C++ applications. When he is not programming, Jarl enjoys skiing and playing table tennis. He derives immense satisfaction from referring to himself in third person.

Comments and Discussions