]> ruin.nu Git - popboot.git/blob - action.h
including iterator
[popboot.git] / action.h
1 #ifndef __ACTION_H__
2 #define __ACTION_H__
3
4 #include <vector>
5 #include <string>
6 #include <ext/hash_map>
7 #include <locale>
8
9 typedef std::vector<std::string> Literals;
10 typedef __gnu_cxx::hash_map<std::string,bool> Preconditions;
11 typedef __gnu_cxx::hash_map<int,Literals> EffectsMap;
12
13 namespace __gnu_cxx {
14
15         template< typename CharT, typename Traits, typename Alloc >
16                 struct hash< std::basic_string<CharT, Traits, Alloc> > {
17                         size_t operator()(const std::basic_string<CharT, Traits, Alloc>& s) const {
18
19                                 const std::collate<CharT>& c = std::use_facet< std::collate<CharT> >(std::locale());
20
21                                 return c.hash(s.c_str(), s.c_str() + s.size());
22
23                         }
24
25                 };
26
27         template< typename CharT, typename Traits, typename Alloc >
28                 struct hash< const std::basic_string<CharT, Traits, Alloc> > { //yes you need this version aswell!
29
30                         size_t operator()(const std::basic_string<CharT, Traits, Alloc>& s) const {
31
32                                 const std::collate<CharT>& c = std::use_facet< std::collate<CharT> >(std::locale());
33
34                                 return c.hash(s.c_str(), s.c_str() + s.size());
35                         }
36
37                 };
38 };
39 class Action {
40         public:
41                 Action(std::string name, const Preconditions& preconditions, std::string executable, const EffectsMap& effects);
42                 Action(const Action& action);
43                 Action(){};
44                 const Literals& effects(int value) const;
45                 const Preconditions& preconditions() const;
46                 const std::string& name() const;
47                 int execute() const;
48
49         protected:
50                 std::string _name;
51                 std::string _executable;
52                 Preconditions _preconditions;
53                 EffectsMap _effects;
54                 static const Literals _empty;
55 };
56
57
58 #endif