From: Michael Andreen Date: Sat, 26 Jan 2008 15:46:10 +0000 (+0100) Subject: documented action.h X-Git-Url: https://ruin.nu/git/?p=popboot.git;a=commitdiff_plain;h=39f1842c8e2e482ce110f2fda486c31750a0b85f documented action.h --- diff --git a/action.h b/action.h index 32fbcb9..32d9122 100644 --- a/action.h +++ b/action.h @@ -10,8 +10,8 @@ typedef std::vector Literals; typedef __gnu_cxx::hash_map Preconditions; typedef __gnu_cxx::hash_map EffectsMap; +// These are needed to be able to use std::string as key in a hash_map. namespace __gnu_cxx { - template< typename CharT, typename Traits, typename Alloc > struct hash< std::basic_string > { size_t operator()(const std::basic_string& s) const { @@ -36,21 +36,61 @@ namespace __gnu_cxx { }; }; + +/** + * This class holds the information associated with an action. + * This is the name, the preconditions, the executable and the effects. + */ class Action { public: + /** + * Creates an action. + * @param name The name given to this action. + * @param preconditions The preconditions needed before execution of this action. + * @param executable The executable which will be executed. + * @param effects The effects which will be achieved after execution. + */ Action(std::string name, const Preconditions& preconditions, std::string executable, const EffectsMap& effects); + + /** + * Creates a copy of the given action. + */ Action(const Action& action); + /** + * Creates an empty, non-functional, action. + */ Action(){}; + + /** + * Returns the effects which will be achived if the action returns + * the input value. + */ const Literals& effects(int value) const; + + /** + * Returns the preconditions needed before execution of this action. + */ const Preconditions& preconditions() const; + /** + * Returns the name of this action. + */ const std::string& name() const; + /** + * Executes this action. + * @return the returnvalue of the execution. Can be used to find out the effects achieved. + */ int execute() const; protected: + //! The name of the action. std::string _name; + //! The executable which can be executed. std::string _executable; + //! The preconditions needed before execution. Preconditions _preconditions; + //! The effects which can be achieved. EffectsMap _effects; + //! An empty list of effects which will be returned if the returnvalue was not found in _effects. static const Literals _empty; };