Fawkes API Fawkes Development Version
mapper_factory.h
1
2/***************************************************************************
3 * mapper_factory.h - Factory for Player proxy to Fawkes interface mappers
4 *
5 * Created: Tue Sep 30 00:28:01 2008
6 * Copyright 2006-2008 Tim Niemueller [www.niemueller.de]
7 *
8 ****************************************************************************/
9
10/* This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Library General Public License for more details.
19 *
20 * Read the full text in the LICENSE.GPL file in the doc directory.
21 */
22
23#ifndef _PLUGINS_PLAYER_MAPPER_FACTORY_H_
24#define _PLUGINS_PLAYER_MAPPER_FACTORY_H_
25
26#include "mapper.h"
27
28namespace fawkes {
29class Interface;
30class ObjectPositionInterface;
31} // namespace fawkes
32
33namespace PlayerCc {
34class ClientProxy;
35class Position2dProxy;
36} // namespace PlayerCc
37
39{
40public:
42 create_mapper(std::string varname, fawkes::Interface *interface, PlayerCc::ClientProxy *proxy);
43
44private:
46 {
47 }
48
49 template <class FawkesInterfaceType, class PlayerProxyType, class MapperType>
51 try_create(std::string varname, fawkes::Interface *interface, PlayerCc::ClientProxy *proxy);
52};
53
54/** Try to create a mapper instance.
55 * Tries to dynamically cast the Fawkes interface and Player proxy to the
56 * desired types, and if that succeeds instantiates a new mapper of the given type
57 * giving the casted instances as parameters.
58 * @param varname variable name
59 * @param interface Fawkes interface instance
60 * @param proxy Player proxy instance
61 * @return NULL if a dynamic cast failed, a mapper instance for the given interface
62 * and proxy otherwise
63 */
64template <class FawkesInterfaceType, class PlayerProxyType, class MapperType>
66PlayerMapperFactory::try_create(std::string varname,
67 fawkes::Interface * interface,
68 PlayerCc::ClientProxy *proxy)
69{
70 FawkesInterfaceType *fi;
71 if ((fi = dynamic_cast<FawkesInterfaceType *>(interface)) != NULL) {
72 PlayerProxyType *pp;
73 if ((pp = dynamic_cast<PlayerProxyType *>(proxy)) != NULL) {
74 return new MapperType(varname, fi, pp);
75 } else {
76 return NULL;
77 }
78 } else {
79 return NULL;
80 }
81}
82
83#endif
Player Fawkes mapper factory.
static PlayerProxyFawkesInterfaceMapper * create_mapper(std::string varname, fawkes::Interface *interface, PlayerCc::ClientProxy *proxy)
Create a mapp instance.
Player proxy to Fawkes interface mapper interface.
Definition: mapper.h:29
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:80
Fawkes library namespace.