Click here to Skip to main content
15,868,016 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 805.9K   4.6K   153  
User-friendly remote method invocation in C++.
//*****************************************************************************
// Copyright (c) 2003. All rights reserved.
// Developed by Jarl Lindrud.
// Contact: jlindrud@hotmail.com .
//*****************************************************************************

#ifndef _UTIL_THROW_HPP_
#define _UTIL_THROW_HPP_

#include <exception>

#include <boost/current_function.hpp>

#include "VariableArgMacro.hpp"

namespace util {
    
    template<typename E> 
    struct ThrowFunctor : public VariableArgMacroFunctor
    {
        ~ThrowFunctor() 
        { 
            if (!std::uncaught_exception()) 
            {
                throw E( (header.str() + args.str()).c_str() );
            }
        }
    };


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

#ifdef NDEBUG

    #define UTIL_THROW(E, msg)                throw E(msg); DUMMY_VARIABLE_ARG_MACRO()
    
#else 

    DECLARE_VARIABLE_ARG_MACRO_T1( UTIL_THROW, ThrowFunctor );
    #define UTIL_THROW(E, msg)                while (true) util::VariableArgMacro<util::ThrowFunctor< E > >().init( "THROW : " #E ": ", msg, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION ).cast( (util::VariableArgMacro<util::ThrowFunctor< E > > *) NULL ).UTIL_THROW_A
    #define UTIL_THROW_A(x)                   UTIL_THROW_OP(x, B)
    #define UTIL_THROW_B(x)                   UTIL_THROW_OP(x, A)
    #define UTIL_THROW_OP(x, next)            UTIL_THROW_A.notify_((x), #x).UTIL_THROW_ ## next

#endif

#ifdef _MSC_VER
#pragma warning( pop )
#endif

} // namespace util

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