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 
28 namespace fawkes {
29 class Interface;
30 class ObjectPositionInterface;
31 } // namespace fawkes
32 
33 namespace PlayerCc {
34 class ClientProxy;
35 class Position2dProxy;
36 } // namespace PlayerCc
37 
39 {
40 public:
42  create_mapper(std::string varname, fawkes::Interface *interface, PlayerCc::ClientProxy *proxy);
43 
44 private:
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  */
64 template <class FawkesInterfaceType, class PlayerProxyType, class MapperType>
66 PlayerMapperFactory::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
PlayerMapperFactory
Definition: mapper_factory.h:38
PlayerMapperFactory::create_mapper
static PlayerProxyFawkesInterfaceMapper * create_mapper(std::string varname, fawkes::Interface *interface, PlayerCc::ClientProxy *proxy)
Create a mapp instance.
Definition: mapper_factory.cpp:54
fawkes
fawkes::Interface
Definition: interface.h:78
PlayerProxyFawkesInterfaceMapper
Definition: mapper.h:28