Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/core/EventIncludes.h @ 11460

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

merged branch cpp11_v3 back to trunk

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