Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/doc/src/libraries/core/EventIncludes.h @ 7363

Last change on this file since 7363 was 7363, checked in by landauf, 14 years ago

assigned a group to each header file in the core library

  • Property svn:eol-style set to native
File size: 5.0 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 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30    @file
31    @ingroup Event
32*/
33
34#ifndef _EventIncludes_H__
35#define _EventIncludes_H__
36
37#include "CorePrereqs.h"
38#include "XMLPort.h"
39#include "command/Executor.h"
40
41/**
42    @brief Defines a new event state (a state of the object which can be changed by events).
43
44    @param classname    The name of this class
45    @param subclassname Usually BaseObject - if different, only instances of this class can send events to this object
46    @param statename    The name (string) of this state
47    @param function     The function which should be used to set the state
48    @param xmlelement   Argument for XMLPort
49    @param mode         Argument for XMLPort
50*/
51#define XMLPortEventState(classname, subclassname, statename, function, xmlelement, mode) \
52    orxonox::EventState* containername##function = this->getEventState(statename); \
53    if (!containername##function) \
54    { \
55        containername##function = new orxonox::EventState(orxonox::createFunctor(&classname::function, this), orxonox::ClassIdentifier<subclassname>::getIdentifier()); \
56        this->addEventState(statename, containername##function); \
57    } \
58    XMLPortEventStateIntern(xmlportevent##function, classname, statename, xmlelement, mode)
59
60#define XMLPortEventSink(classname, subclassname, statename, function, xmlelement, mode) \
61    orxonox::EventState* containername##function = this->getEventState(statename); \
62    if (!containername##function) \
63    { \
64        containername##function = new orxonox::EventState(orxonox::createFunctor(&classname::function, this), orxonox::ClassIdentifier<subclassname>::getIdentifier(), true); \
65        this->addEventState(statename, containername##function); \
66    } \
67    XMLPortEventStateIntern(xmlportevent##function, classname, statename, xmlelement, mode)
68
69/**
70    @brief Like XMLPortEventState but creates an event sink instead of an event state.
71           The most important destinction between an EventState and an EventSink is, that an EventState only processes event which change the state of the EventState, where as an EventSink is an EventState that processes any Event that reaches it.
72*/
73#define XMLPortEventStateTemplate(classname, subclassname, statename, function, xmlelement, mode, ...) \
74    orxonox::EventState* containername##function = this->getEventState(statename); \
75    if (!containername##function) \
76    { \
77        containername##function = new orxonox::EventState(orxonox::createFunctor<classname, __VA_ARGS__ >(&classname::function, this), orxonox::ClassIdentifier<subclassname>::getIdentifier()); \
78        this->addEventState(statename, containername##function); \
79    } \
80    XMLPortEventStateIntern(xmlportevent##function, classname, statename, xmlelement, mode)
81
82#define XMLPortEventStateIntern(name, classname, statename, xmlelement, mode) \
83    static orxonox::ExecutorMemberPtr<classname> xmlsetfunctor##name = orxonox::createExecutor(orxonox::createFunctor(&classname::addEventSource), std::string( #classname ) + "::" + "addEventSource" + '(' + statename + ')').cast<orxonox::ExecutorMember<classname> >(); \
84    static orxonox::ExecutorMemberPtr<classname> xmlgetfunctor##name = orxonox::createExecutor(orxonox::createFunctor(&classname::getEventSource), std::string( #classname ) + "::" + "getEventSource" + '(' + statename + ')').cast<orxonox::ExecutorMember<classname> >(); \
85    xmlsetfunctor##name->setDefaultValue(1, statename); \
86    xmlgetfunctor##name->setDefaultValue(1, statename); \
87    XMLPortObjectGeneric(xmlport##name, classname, orxonox::BaseObject, statename, xmlsetfunctor##name, xmlgetfunctor##name, xmlelement, mode, false, true)
88
89
90/**
91    @brief Defines a new event name for a class. Named events can only have names which were defined with this macro.
92
93    @param classname The name of the class
94    @param name      The name of the event
95*/
96#define CreateEventName(classname, name) \
97    static std::string eventname##classname##name = #name
98
99/**
100    @brief This macro is needed to fire an event with this name. The event name must previously be declared with @ref CreateEventName.
101*/
102#define FireEventName(classname, name) \
103    eventname##classname##name
104
105#endif /* _EventIncludes_H__ */
Note: See TracBrowser for help on using the repository browser.