Main Page · Modules · All Classes · Class Hierarchy
MALegBehavior.hpp
1 /*
2  * This file is part of the AiBO+ project
3  *
4  * Copyright (C) 2005-2016 Csaba Kertész (csaba.kertesz@gmail.com)
5  *
6  * AiBO+ is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * AiBO+ is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
19  *
20  */
21 
22 #pragma once
23 
24 #include <boost/type_traits/is_base_of.hpp>
25 
26 #include <MCLog.hpp>
27 
28 #include "MABehavior.hpp"
29 
30 class MALegController;
31 class MALeg;
32 
38 #define MALEGBEHAVIOR_CREATE(_behavior, _leg_type, _master) \
39  MABEHAVIOR_CREATE_S(_behavior, _master, MALegBehavior::GetBehaviorSuffix(_leg_type), _leg_type)
40 
41 #define MALEGBEHAVIOR_EXISTS(_behavior, _leg_type) \
42  MABEHAVIOR_EXISTS_S(_behavior, MALegBehavior::GetBehaviorSuffix(_leg_type))
43 
44 #define MALEGBEHAVIOR_DELETE(_behavior, _leg_type) \
45  MABEHAVIOR_DELETE_S(_behavior, MALegBehavior::GetBehaviorSuffix(_leg_type))
46 
47 #define MALEGBEHAVIOR_IS_ACTIVATED(_behavior, _leg_type) \
48  (MABEHAVIOR_IS_ACTIVATED_S(_behavior, MALegBehavior::GetBehaviorSuffix(_leg_type)))
49 
50 #define MALEGBEHAVIOR_IS_FINISHED(_behavior, _leg_type) \
51  (MABEHAVIOR_IS_FINISHED_S(_behavior, MALegBehavior::GetBehaviorSuffix(_leg_type)))
52 
53 #define MALEGBEHAVIOR_IS_FAILED(_behavior, _leg_type) \
54  (MABEHAVIOR_IS_FAILED_S(_behavior, MALegBehavior::GetBehaviorSuffix(_leg_type)))
55 
59 class MALegBehavior : public MABehavior
60 {
61 public:
62  MALegBehavior(const std::string& behavior_name, MA::Leg::LegTypes leg_type, bool dynamic = true);
63 
64  static std::string GetBehaviorSuffix(MA::Leg::LegTypes leg_type);
65 
66 protected:
70  const MALeg& LegState;
71 };
72 
73 
74 template <typename T>
75 std::string MAGetLegBehaviorName(MA::Leg::LegTypes leg_type)
76 {
77  std::string ClassName = MCGetClassName<T>();
78 
79  if (!boost::is_base_of<MALegBehavior, T>::value)
80  {
81  MC_ERROR("The class %s is not derived from MALegBehavior", ClassName.c_str());
82  }
83  return ClassName+MALegBehavior::GetBehaviorSuffix(leg_type);
84 }
85 
MALegController * Controller
Leg controller.
Behavior base class.
Definition: MABehavior.hpp:157
Base class for leg behaviors.
#define MC_ERROR(...)
Error macro.
Definition: MCLog.hpp:45
Leg controller class.
const MALeg & LegState
Leg state.
A leg class.
Definition: MALeg.hpp:71