Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core7/src/libraries/network/NetworkFunctionIncludes.h @ 10465

Last change on this file since 10465 was 10465, checked in by landauf, 9 years ago

moved macro ans helperfunction from NetworkFunction.h to NetworkFunctionIncludes.h

File size: 3.3 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Oliver Scheuss
24 *   Co-authors:
25 *      Fabian 'x3n' Landau
26 *
27 */
28
29#ifndef _NetworkFunctionIncludes_H__
30#define _NetworkFunctionIncludes_H__
31
32#include "NetworkPrereqs.h"
33
34#include <boost/preprocessor/cat.hpp>
35#include <boost/static_assert.hpp>
36
37#include "NetworkFunction.h"
38
39namespace orxonox
40{
41    #define registerStaticNetworkFunction( functionPointer ) \
42        static void* BOOST_PP_CAT( NETWORK_FUNCTION_, __UNIQUE_NUMBER__ ) = registerStaticNetworkFunctionFct( functionPointer, #functionPointer );
43
44    #define registerMemberNetworkFunction( class, function ) \
45        static void* BOOST_PP_CAT( NETWORK_FUNCTION_##class, __UNIQUE_NUMBER__ ) = registerMemberNetworkFunctionFct<class>( &class::function, #class "_" #function);
46
47    // call it with functionPointer, clientID, args
48    #define callStaticNetworkFunction( functionPointer, ...) \
49        { \
50            NetworkFunctionPointer p1; \
51            copyPtr( functionPointer, p1 ); \
52            FunctionCallManager::addCallStatic(NetworkFunctionStatic::getFunction(p1)->getNetworkID(), __VA_ARGS__); \
53        }
54
55    // call it with class, function, objectID, clientID, args
56    #define callMemberNetworkFunction( class, function, objectID, ...) \
57        { \
58            NetworkFunctionPointer p1; \
59            copyPtr( &class::function, p1 ); \
60            FunctionCallManager::addCallMember(NetworkMemberFunctionBase::getFunction(p1)->getNetworkID(), objectID, __VA_ARGS__); \
61        }
62
63    template<class T> inline void* registerStaticNetworkFunctionFct( T ptr, const std::string& name )
64    {
65        BOOST_STATIC_ASSERT( sizeof(T)<=sizeof(NetworkFunctionPointer) ); // if this fails your compiler uses bigger pointers for static functions than defined above
66        NetworkFunctionPointer destptr;
67        copyPtr( ptr, destptr );
68        new NetworkFunctionStatic( createFunctor(ptr), name, destptr );
69        return 0;
70    }
71
72    template<class T, class PT> inline void* registerMemberNetworkFunctionFct( PT ptr, const std::string& name )
73    {
74        BOOST_STATIC_ASSERT( sizeof(PT)<=sizeof(NetworkFunctionPointer) ); // if this fails your compiler uses bigger pointers for a specific kind of member functions than defined above
75        NetworkFunctionPointer destptr;
76        copyPtr( ptr, destptr );
77        new NetworkMemberFunction<T>( createFunctor(ptr), name, destptr );
78        return 0;
79    }
80
81}
82
83#endif /* _NetworkFunctionIncludes_H__ */
Note: See TracBrowser for help on using the repository browser.