6 #include <ext/hash_map>
9 //! A list of strings, each string representing an effect.
10 typedef std::vector<std::string> Literals;
11 //! A map, but really a list of pairs, the precondition as a string, and a bool, true if it's a hard precondition, otherwise false.
12 typedef __gnu_cxx::hash_map<std::string,bool> Preconditions;
13 //! A map from returnvalue of the execution to the effects achieved.
14 typedef __gnu_cxx::hash_map<int,Literals> EffectsMap;
16 // These are needed to be able to use std::string as key in a hash_map.
18 template< typename CharT, typename Traits, typename Alloc >
19 struct hash< std::basic_string<CharT, Traits, Alloc> > {
20 size_t operator()(const std::basic_string<CharT, Traits, Alloc>& s) const {
22 const std::collate<CharT>& c = std::use_facet< std::collate<CharT> >(std::locale());
24 return c.hash(s.c_str(), s.c_str() + s.size());
30 template< typename CharT, typename Traits, typename Alloc >
31 struct hash< const std::basic_string<CharT, Traits, Alloc> > { //yes you need this version aswell!
33 size_t operator()(const std::basic_string<CharT, Traits, Alloc>& s) const {
35 const std::collate<CharT>& c = std::use_facet< std::collate<CharT> >(std::locale());
37 return c.hash(s.c_str(), s.c_str() + s.size());
44 * This class holds the information associated with an action.
45 * This is the name, the preconditions, the executable and the effects.
51 * @param name The name given to this action.
52 * @param preconditions The preconditions needed before execution of this action.
53 * @param executable The executable which will be executed.
54 * @param effects The effects which will be achieved after execution.
56 Action(std::string name, const Preconditions& preconditions, std::string executable, const EffectsMap& effects);
59 * Creates a copy of the given action.
61 Action(const Action& action);
63 * Creates an empty, non-functional, action.
68 * Returns the effects which will be achived if the action returns
71 const Literals& effects(int value) const;
74 * Returns the preconditions needed before execution of this action.
76 const Preconditions& preconditions() const;
78 * Returns the name of this action.
80 const std::string& name() const;
82 * Executes this action.
83 * @return the returnvalue of the execution. Can be used to find out the effects achieved.
88 //! The name of the action.
90 //! The executable which can be executed.
91 std::string _executable;
92 //! The preconditions needed before execution.
93 Preconditions _preconditions;
94 //! The effects which can be achieved.
96 //! An empty list of effects which will be returned if the returnvalue was not found in _effects.
97 static const Literals _empty;