Click here to Skip to main content
11,409,097 members (67,245 online)
Click here to Skip to main content
Add your own
alternative version

RMI for C++

, 6 Aug 2009 CPOL
User-friendly remote method invocation in C++.
rcf.zip
RCF
demo
vs2003
RCF
Client
Server
doc
include
RCF
Connection.inl
Marshal.inl
Multiplexer.inl
RCF.inl
RcfServer.inl
ServerStub.inl
Protocol
util
Platform
Compiler
bcc55
cw80
gcc32
icl70
msvc71
Library
bcc55
cw80
gcc32
msvc60
msvc71
Machine
SPARC
x86
OS
Cygwin
Unix
Windows
System
NonWindows
Windows
Threads
SF
src
RCF
Protocol
util
SF
test
Jamfile
Jamrules
borland
Jamfile
Jamrules
vs2003
RCF
RCF
RCFTest
//*****************************************************************************
// Copyright (c) 2003. All rights reserved.
// Developed by Jarl Lindrud.
// Contact: jlindrud@hotmail.com .
//*****************************************************************************

#ifndef _UTIL_VARIABLEARGMACRO_HPP_
#define _UTIL_VARIABLEARGMACRO_HPP_

#include <sys/types.h>
#include <sys/timeb.h>

#include <sstream>
#include <typeinfo>

#include "Platform/Platform.hpp"

namespace util {

    class VariableArgMacroFunctor 
    {
    public:
        virtual ~VariableArgMacroFunctor() {}
        VariableArgMacroFunctor &init(const std::string &label, const std::string &msg, const char *file, int line, const char *func) 
        { 
            struct timeb tp;
            ftime(&tp);
            int timestamp = static_cast<int>( (tp.time % 60) * 1000 + tp.millitm );
            int threadid = Platform::OS::GetCurrentThreadId();
            header << file << "(" << line << "): " << func << ": " << ": Thread-id=" << threadid << " : Timestamp(ms)=" << timestamp << ": " << label << msg << ": " ; 
            return *this;
        }
        void deinit() { args << "\n"; Platform::OS::OutputDebugString( (header.str() + args.str()).c_str() ); }
        template<typename T> void notify(const T &t, const char *name) { args << name << "=" << t << ", "; }
        template<typename T> T &cast() { return dynamic_cast<T &>(*this); }
        template<typename T> T &cast(T *) { return dynamic_cast<T &>(*this); }
        std::ostringstream header;
        std::ostringstream args;
    };

    class DummyVariableArgMacroObject
    {
    public:
        template<typename T> 
        DummyVariableArgMacroObject &operator()(const T &) 
        { 
            return *this; 
        }
    };

    #define DUMMY_VARIABLE_ARG_MACRO() if (false) ::util::DummyVariableArgMacroObject()

} // namespace util


#define DECLARE_VARIABLE_ARG_MACRO( macro_name, functor ) DECLARE_VARIABLE_ARG_MACRO_(macro_name, macro_name##_A, macro_name##_B, functor)
#define DECLARE_VARIABLE_ARG_MACRO_( macro_name, macro_name_A, macro_name_B, functor)                                    \
    template<typename Functor> class VariableArgMacro;                                                                    \
    template<> class VariableArgMacro< functor > : public functor {                                                        \
    public:                                                                                                                \
        VariableArgMacro() : macro_name_A(*this), macro_name_B(*this) {}                                                \
        template<typename T1> VariableArgMacro(const T1 &t1) : functor(t1), macro_name_A(*this), macro_name_B(*this) {}    \
        template<typename T1, typename T2> VariableArgMacro(const T1 &t1, const T2 &t2) : functor(t1,t2), macro_name_A(*this), macro_name_B(*this) {}            \
        ~VariableArgMacro() { functor::deinit(); }                                                                                \
        VariableArgMacro &macro_name_A;                                                                                    \
        VariableArgMacro &macro_name_B;                                                                                    \
        template<typename T> VariableArgMacro< functor > &notify_(const T &t, const char *name) { notify(t,name); return *this; }    \
    }

#define DECLARE_VARIABLE_ARG_MACRO_T1( macro_name, functor ) DECLARE_VARIABLE_ARG_MACRO_T1_(macro_name, macro_name##_A, macro_name##_B, functor)
#define DECLARE_VARIABLE_ARG_MACRO_T1_( macro_name, macro_name_A, macro_name_B, functor)                                \
    template<typename Functor> class VariableArgMacro;                                                                    \
    template<typename U> class VariableArgMacro< functor<U> > : public functor<U> {                                        \
    public:                                                                                                                \
        VariableArgMacro() : macro_name_A(*this), macro_name_B(*this) {}                                                \
        template<typename T1> VariableArgMacro(const T1 &t1) : functor<U>(t1), macro_name_A(*this), macro_name_B(*this) {}                                            \
        template<typename T1, typename T2> VariableArgMacro(const T1 &t1, const T2 &t2) : functor<U>(t1,t2), macro_name_A(*this), macro_name_B(*this) {}            \
        ~VariableArgMacro() { functor<U>::deinit(); }                                                                                \
        VariableArgMacro &macro_name_A;                                                                                    \
        VariableArgMacro &macro_name_B;                                                                                    \
        template<typename T> VariableArgMacro< functor<U> > &notify_(const T &t, const char *name) { notify(t,name); return *this; }    \
    }

#define DECLARE_VARIABLE_ARG_MACRO_T2( macro_name, functor ) DECLARE_VARIABLE_ARG_MACRO_T2_(macro_name, macro_name##_A, macro_name##_B, functor)
#define DECLARE_VARIABLE_ARG_MACRO_T2_( macro_name, macro_name_A, macro_name_B, functor)                                \
    template<typename Functor> class VariableArgMacro;                                                                    \
    template<typename U, typename V> class VariableArgMacro< functor<U,V> > : public functor<U,V> {                        \
    public:                                                                                                                \
        VariableArgMacro() : macro_name_A(*this), macro_name_B(*this) {}                                                \
        template<typename T1> VariableArgMacro(const T1 &t1) : functor<U,V>(t1), macro_name_A(*this), macro_name_B(*this) {}                                        \
        template<typename T1, typename T2> VariableArgMacro(const T1 &t1, const T2 &t2) : functor<U,V>(t1,t2), macro_name_A(*this), macro_name_B(*this) {}            \
        ~VariableArgMacro() { functor<U>::deinit(); }                                                                                \
        VariableArgMacro &macro_name_A;                                                                                    \
        VariableArgMacro &macro_name_B;                                                                                    \
        template<typename T> VariableArgMacro< functor<U,V> > &notify_(const T &t, const char *name) { notify(t,name); return *this; }    \
    }

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

Share

About the Author

Jarl Lindrud

Australia Australia
Software developer, ex-resident of Sweden and now living in Canberra, Australia, working on distributed C++ applications. Jarl enjoys programming, but prefers skiing and playing table tennis. He derives immense satisfaction from referring to himself in third person.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150414.5 | Last Updated 6 Aug 2009
Article Copyright 2005 by Jarl Lindrud
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid