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 }
32 
33 namespace PlayerCc {
34  class ClientProxy;
35  class Position2dProxy;
36 }
37 
39 {
40  public:
41  static PlayerProxyFawkesInterfaceMapper *create_mapper(std::string varname,
42  fawkes::Interface *interface,
43  PlayerCc::ClientProxy *proxy);
44 
45 
46  private:
48 
49  template <class FawkesInterfaceType, class PlayerProxyType, class MapperType>
50  static PlayerProxyFawkesInterfaceMapper * try_create(std::string varname,
51  fawkes::Interface *interface,
52  PlayerCc::ClientProxy *proxy);
53 };
54 
55 /** Try to create a mapper instance.
56  * Tries to dynamically cast the Fawkes interface and Player proxy to the
57  * desired types, and if that succeeds instantiates a new mapper of the given type
58  * giving the casted instances as parameters.
59  * @param varname variable name
60  * @param interface Fawkes interface instance
61  * @param proxy Player proxy instance
62  * @return NULL if a dynamic cast failed, a mapper instance for the given interface
63  * and proxy otherwise
64  */
65 template <class FawkesInterfaceType, class PlayerProxyType, class MapperType>
67 PlayerMapperFactory::try_create(std::string varname,
68  fawkes::Interface *interface,
69  PlayerCc::ClientProxy *proxy)
70 {
71  FawkesInterfaceType *fi;
72  if ( (fi = dynamic_cast<FawkesInterfaceType *>(interface)) != NULL ) {
73  PlayerProxyType *pp;
74  if ( (pp = dynamic_cast<PlayerProxyType *>(proxy)) != NULL ) {
75  return new MapperType(varname, fi, pp);
76  } else {
77  return NULL;
78  }
79  } else {
80  return NULL;
81  }
82 }
83 
84 
85 #endif
Fawkes library namespace.
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:79
Player Fawkes mapper factory.
Player proxy to Fawkes interface mapper interface.
Definition: mapper.h:28