Orxonox  0.0.5 Codename: Arcturus
NetworkFunction.h
Go to the documentation of this file.
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  * ...
26  *
27  */
28 
29 #ifndef _NetworkFunction_H__
30 #define _NetworkFunction_H__
31 
32 #include "NetworkPrereqs.h"
33 
34 #include <cassert>
35 #include <cstring>
36 #include <map>
37 #include <string>
38 
39 #include "core/command/Functor.h"
40 #include "FunctionCallManager.h"
42 
43 namespace orxonox
44 {
45 
46 #if defined(ORXONOX_COMPILER_GCC) && defined(ORXONOX_ARCH_32)
47 static constexpr unsigned int MAX_FUNCTION_POINTER_SIZE = 8;
48 #else
49 static constexpr unsigned int MAX_FUNCTION_POINTER_SIZE = 16;
50 #endif //ORXONOX_COMPILER_GCC
51 static constexpr unsigned int MAX_FUNCTION_POINTER_INTS = (MAX_FUNCTION_POINTER_SIZE-1)/4+1;
52 
54  uint32_t pointer[MAX_FUNCTION_POINTER_INTS];
55  bool operator<(const NetworkFunctionPointer& b) const
56  {
57 #if defined(ORXONOX_COMPILER_GCC) && defined(ORXONOX_ARCH_32)
58  if (pointer[0] != b.pointer[0])
59  return pointer[0] < b.pointer[0];
60  else if (pointer[1] != b.pointer[1])
61  return pointer[1] < b.pointer[1];
62  else
63  return false;
64 #else
65  if (pointer[0] != b.pointer[0])
66  return pointer[0] < b.pointer[0];
67  else if (pointer[1] != b.pointer[1])
68  return pointer[1] < b.pointer[1];
69  else if (pointer[2] != b.pointer[2])
70  return pointer[2] < b.pointer[2];
71  else if (pointer[3] != b.pointer[3])
72  return pointer[3] < b.pointer[3];
73  else
74  return false;
75 #endif
76  }
77 };
78 
79 
80 
81 
82 
84  public:
85  NetworkFunctionBase(const std::string& name, const NetworkFunctionPointer& pointer);
86  virtual ~NetworkFunctionBase() {}
87 
88  void setNetworkID(uint32_t id);
89  inline uint32_t getNetworkID() const { return this->networkID_; }
90  inline const std::string& getName() const { return this->name_; }
91  inline const NetworkFunctionPointer& getPointer() const { return this->pointer_; }
92 
93  virtual bool call(uint32_t objectID)=0;
94  virtual bool call(uint32_t objectID, const MultiType& mt1)=0;
95  virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2)=0;
96  virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3)=0;
97  virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)=0;
98  virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5)=0;
99 
100  private:
101  uint32_t networkID_;
104 
105 };
106 
107 
109  public:
111  : NetworkFunctionBase(name, p)
112  , functor_(functor)
113  { }
114 
115  // ignore the objectID because its a static function
116  virtual bool call(uint32_t objectID) override{ (*this->functor_)(); return true; }
117  virtual bool call(uint32_t objectID, const MultiType& mt1) override{ (*this->functor_)(mt1); return true; }
118  virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2) override{ (*this->functor_)(mt1, mt2); return true; }
119  virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3) override{ (*this->functor_)(mt1, mt2, mt3); return true; }
120  virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4) override{ (*this->functor_)(mt1, mt2, mt3, mt4); return true; }
121  virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5) override{ (*this->functor_)(mt1, mt2, mt3, mt4, mt5); return true; }
122 
123  private:
125 
126 };
127 
128 
130  public:
132  : NetworkFunctionBase(name, p)
133  { }
134 };
135 
136 
137 template <class T> class NetworkMemberFunction: public NetworkMemberFunctionBase {
138  public:
140  : NetworkMemberFunctionBase(name, p)
141  , functor_(functor)
142  { }
143 
144  virtual inline bool call(uint32_t objectID) override
145  {
146  if ( Synchronisable::getSynchronisable(objectID)!=nullptr )
147  {
148  (*this->functor_)(orxonox_cast<T*>(Synchronisable::getSynchronisable(objectID)));
149  return true;
150  }
151  else
152  return false;
153  }
154  virtual inline bool call(uint32_t objectID, const MultiType& mt1) override
155  {
156  if ( Synchronisable::getSynchronisable(objectID)!=nullptr )
157  {
158  (*this->functor_)(orxonox_cast<T*>(Synchronisable::getSynchronisable(objectID)), mt1);
159  return true;
160  }
161  else
162  return false;
163  }
164  virtual inline bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2) override
165  {
166  if ( Synchronisable::getSynchronisable(objectID)!=nullptr )
167  {
168  (*this->functor_)(orxonox_cast<T*>(Synchronisable::getSynchronisable(objectID)), mt1, mt2);
169  return true;
170  }
171  else
172  return false;
173  }
174  virtual inline bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3) override
175  {
176  if ( Synchronisable::getSynchronisable(objectID)!=nullptr )
177  {
178  (*this->functor_)(orxonox_cast<T*>(Synchronisable::getSynchronisable(objectID)), mt1, mt2, mt3);
179  return true;
180  }
181  else
182  return false;
183  }
184  virtual inline bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4) override
185  {
186  if ( Synchronisable::getSynchronisable(objectID)!=nullptr )
187  {
188  (*this->functor_)(orxonox_cast<T*>(Synchronisable::getSynchronisable(objectID)), mt1, mt2, mt3, mt4);
189  return true;
190  }
191  else
192  return false;
193  }
194  virtual inline bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5) override
195  {
196  if ( Synchronisable::getSynchronisable(objectID)!=nullptr )
197  {
198  (*this->functor_)(orxonox_cast<T*>(Synchronisable::getSynchronisable(objectID)), mt1, mt2, mt3, mt4, mt5);
199  return true;
200  }
201  else
202  return false;
203  }
204 
205  private:
207 };
208 
209 }
210 
211 #endif /* _NetworkFunction_H__ */
Definition: NetworkFunction.h:83
virtual bool call(uint32_t objectID, const MultiType &mt1) override
Definition: NetworkFunction.h:154
const NetworkFunctionPointer & getPointer() const
Definition: NetworkFunction.h:91
virtual bool call(uint32_t objectID, const MultiType &mt1, const MultiType &mt2) override
Definition: NetworkFunction.h:118
Shared library macros, enums, constants and forward declarations for the network library ...
uint32_t pointer[MAX_FUNCTION_POINTER_INTS]
Definition: NetworkFunction.h:54
static Synchronisable * getSynchronisable(uint32_t objectID_)
This function looks up the objectID_ in the objectMap_ and returns a pointer to the right Synchronisa...
Definition: Synchronisable.cc:218
virtual bool call(uint32_t objectID, const MultiType &mt1, const MultiType &mt2, const MultiType &mt3, const MultiType &mt4, const MultiType &mt5) override
Definition: NetworkFunction.h:194
std::string name_
Definition: NetworkFunction.h:102
Definition of orxonox::Functor and its specialized subclasses, as well as the createFunctor() functio...
NetworkFunctionStatic(const FunctorStaticPtr &functor, const std::string &name, const NetworkFunctionPointer &p)
Definition: NetworkFunction.h:110
NetworkMemberFunctionBase(const std::string &name, const NetworkFunctionPointer &p)
Definition: NetworkFunction.h:131
Definition: NetworkFunction.h:53
::std::string string
Definition: gtest-port.h:756
virtual bool call(uint32_t objectID, const MultiType &mt1) override
Definition: NetworkFunction.h:117
virtual bool call(uint32_t objectID, const MultiType &mt1, const MultiType &mt2, const MultiType &mt3, const MultiType &mt4) override
Definition: NetworkFunction.h:120
virtual bool call(uint32_t objectID) override
Definition: NetworkFunction.h:144
virtual bool call(uint32_t objectID, const MultiType &mt1, const MultiType &mt2, const MultiType &mt3) override
Definition: NetworkFunction.h:119
NetworkFunctionPointer pointer_
Definition: NetworkFunction.h:103
uint32_t getNetworkID() const
Definition: NetworkFunction.h:89
virtual bool call(uint32_t objectID, const MultiType &mt1, const MultiType &mt2, const MultiType &mt3, const MultiType &mt4, const MultiType &mt5) override
Definition: NetworkFunction.h:121
virtual bool call(uint32_t objectID) override
Definition: NetworkFunction.h:116
bool operator<(const NetworkFunctionPointer &b) const
Definition: NetworkFunction.h:55
Definition: NetworkFunction.h:108
virtual bool call(uint32_t objectID, const MultiType &mt1, const MultiType &mt2, const MultiType &mt3, const MultiType &mt4) override
Definition: NetworkFunction.h:184
static constexpr unsigned int MAX_FUNCTION_POINTER_SIZE
Definition: NetworkFunction.h:49
const std::string & getName() const
Definition: NetworkFunction.h:90
uint32_t networkID_
Definition: NetworkFunction.h:101
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
#define _NetworkExport
Definition: NetworkPrereqs.h:59
FunctorMemberPtr< T > functor_
Definition: NetworkFunction.h:206
virtual ~NetworkFunctionBase()
Definition: NetworkFunction.h:86
The MultiType can hold a value of many possible types and convert them to other types.
Definition: MultiType.h:130
virtual bool call(uint32_t objectID, const MultiType &mt1, const MultiType &mt2, const MultiType &mt3) override
Definition: NetworkFunction.h:174
Definition: NetworkFunction.h:129
std::shared_ptr< FunctorMember< void >> FunctorStaticPtr
Definition: FunctorPtr.h:60
std::shared_ptr< FunctorMember< T >> FunctorMemberPtr
Definition: FunctorPtr.h:59
virtual bool call(uint32_t objectID, const MultiType &mt1, const MultiType &mt2) override
Definition: NetworkFunction.h:164
static constexpr unsigned int MAX_FUNCTION_POINTER_INTS
Definition: NetworkFunction.h:51
NetworkMemberFunction(const FunctorMemberPtr< T > &functor, const std::string &name, const NetworkFunctionPointer &p)
Definition: NetworkFunction.h:139
Definition: NetworkFunction.h:137
internal::String name_
Definition: gtest.cc:2289
FunctorStaticPtr functor_
Definition: NetworkFunction.h:124