]> ruin.nu Git - popboot.git/blob - action.h
simple hash
[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
8 typedef std::vector<std::string> Literals;
9 typedef __gnu_cxx::hash_map<std::string,bool> Preconditions;
10 typedef __gnu_cxx::hash_map<int,Literals> EffectsMap;
11
12 namespace __gnu_cxx {
13
14         template< typename CharT, typename Traits, typename Alloc >
15                 struct hash< std::basic_string<CharT, Traits, Alloc> > {
16                         size_t operator()(const std::basic_string<CharT, Traits, Alloc>& s) const {
17
18                                 size_t hash = 0;
19                                 for (unsigned int i = 0; i < s.size(); ++i)
20                                         hash += static_cast<size_t>(s[i]);
21                                 return hash + 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                                 size_t hash = 0;
33                                 for (unsigned int i = 0; i < s.size(); ++i)
34                                         hash += static_cast<size_t>(s[i]);
35                                 return hash + s.size();
36                         }
37
38                 };
39 };
40 class Action {
41         public:
42                 Action(std::string name, const Preconditions& preconditions, std::string executable, const EffectsMap& effects);
43                 Action(const Action& action);
44                 Action(){};
45                 const Literals& effects(int value) const;
46                 const Preconditions& preconditions() const;
47                 const std::string& name() const;
48                 int execute() const;
49
50         protected:
51                 std::string _name;
52                 std::string _executable;
53                 Preconditions _preconditions;
54                 EffectsMap _effects;
55                 static const Literals _empty;
56 };
57
58
59 #endif