]> ruin.nu Git - popboot.git/blobdiff - action.h
simple hash
[popboot.git] / action.h
index 9b3c9276a105ab8366324c63839ffde92d34d70f..a0a1173e4cc0ce9ff6507f615e8c911ed529bb7c 100644 (file)
--- a/action.h
+++ b/action.h
@@ -3,23 +3,57 @@
 
 #include <vector>
 #include <string>
+#include <ext/hash_map>
 
-typedef std::vector<std::string> literals;
+typedef std::vector<std::string> Literals;
+typedef __gnu_cxx::hash_map<std::string,bool> Preconditions;
+typedef __gnu_cxx::hash_map<int,Literals> EffectsMap;
 
+namespace __gnu_cxx {
+
+       template< typename CharT, typename Traits, typename Alloc >
+               struct hash< std::basic_string<CharT, Traits, Alloc> > {
+                       size_t operator()(const std::basic_string<CharT, Traits, Alloc>& s) const {
+
+                               size_t hash = 0;
+                               for (unsigned int i = 0; i < s.size(); ++i)
+                                       hash += static_cast<size_t>(s[i]);
+                               return hash + s.size();
+
+                       }
+
+               };
+
+       template< typename CharT, typename Traits, typename Alloc >
+               struct hash< const std::basic_string<CharT, Traits, Alloc> > { //yes you need this version aswell!
+
+                       size_t operator()(const std::basic_string<CharT, Traits, Alloc>& s) const {
+
+                               size_t hash = 0;
+                               for (unsigned int i = 0; i < s.size(); ++i)
+                                       hash += static_cast<size_t>(s[i]);
+                               return hash + s.size();
+                       }
+
+               };
+};
 class Action {
        public:
-               Action(std::string executable, literals preconditions, literals effects);
+               Action(std::string name, const Preconditions& preconditions, std::string executable, const EffectsMap& effects);
                Action(const Action& action);
                Action(){};
-               const literals& effects() const;
-               const literals& preconditions() const;
-               const std::string& executable() const;
+               const Literals& effects(int value) const;
+               const Preconditions& preconditions() const;
+               const std::string& name() const;
                int execute() const;
 
        protected:
+               std::string _name;
                std::string _executable;
-               literals _preconditions;
-               literals _effects;
+               Preconditions _preconditions;
+               EffectsMap _effects;
+               static const Literals _empty;
 };
 
+
 #endif