Click here to Skip to main content
15,897,315 members
Articles / Programming Languages / C++

RMI for C++

Rate me:
Please Sign up or sign in to vote.
4.87/5 (113 votes)
6 Aug 2009CPOL8 min read 843.6K   4.6K   153  
User-friendly remote method invocation in C++.
//*****************************************************************************
// RCF - Remote Call Framework
// Copyright (c) 2005, Jarl Lindrud.
// Contact: jlindrud@hotmail.com .
//
// Distributed under the so-called MIT license, see accompanying file license.txt.
//*****************************************************************************

#ifndef _RCF_TOOLS_HPP_
#define _RCF_TOOLS_HPP_

// Various utilities

#include <deque>
#include <iostream>
#include <iterator>
#include <stdexcept>
#include <typeinfo>
#include <vector>

#include <boost/current_function.hpp>
#include <boost/noncopyable.hpp>
#include <boost/static_assert.hpp>
#include <boost/type_traits.hpp>

#include <RCF/Exception.hpp>
#include <RCF/ScopeGuard.h>
#include <RCF/ThreadLibrary.hpp>
#include <RCF/util/Meta.hpp>

#ifdef _MSC_VER
#pragma warning( disable : 4355 )  // warning C4355: 'this' : used in base member initializer list
#endif

// Assertion mechanism
#include <RCF/util/Assert.hpp>
#define RCF_ASSERT(x) UTIL_ASSERT(x, RCF::AssertionFailureException)

// Trace mechanism
#include <RCF/util/Trace.hpp>
#define RCF_TRACE(x) UTIL_TRACE(x, ::RCF::getRcfTraceChannel())
//#define RCF_TRACE(x) DUMMY_VARIABLE_ARG_MACRO()
namespace RCF {
    util::TraceChannel &getRcfTraceChannel();
}

// Throw mechanism
#include <RCF/util/Throw.hpp>
#define RCF_THROW UTIL_THROW

// Eliminate unused variable warnings, eg for scoped lock objects
#define RCF_UNUSED_VARIABLE(x) ((void) x)

#ifndef __BORLANDC__
namespace std {
#endif

    // Trace std::vector
    template<typename T>
    std::ostream &operator<<(std::ostream &os, const std::vector<T> &v)
    {
        os << "(";
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(os, ", "));
        os << ")";
        return os;
    }

    // Trace std::deque
    template<typename T>
    std::ostream &operator<<(std::ostream &os, const std::deque<T> &d)
    {
        os << "(";
        std::copy(d.begin(), d.end(), std::ostream_iterator<T>(os, ", "));
        os << ")";
        return os;
    }


    // Trace type_info
    inline std::ostream &operator<<(std::ostream &os, const std::type_info &ti) 
    { 
        return os << ti.name(); 
    }
    
    // Trace exception
    inline std::ostream &operator<<(std::ostream &os, const std::exception &e) 
    { 
        return os << "Type: " << typeid(e).name() << ", What: " << e.what(); 
    }

#ifndef __BORLANDC__
} // namespace std
#endif

#endif // ! _RCF_TOOLS_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