Go to the documentation of this file.00001 #ifndef actasp_AspFluent_h__guard
00002 #define actasp_AspFluent_h__guard
00003
00004 #include <string>
00005 #include <vector>
00006 #include <stdexcept>
00007 #include <set>
00008 #include <functional>
00009
00010 namespace actasp {
00011
00012 class ActionComparator;
00013 class ActionEquality;
00014
00015 class AspFluent {
00016 public:
00017
00018 AspFluent(const std::string& formula) throw (std::invalid_argument);
00019 AspFluent(const std::string &name, const std::vector<std::string> &variables, unsigned int timeStep = 0) throw ();
00020
00021 unsigned int arity() const throw ();
00022
00023 void setTimeStep(unsigned int timeStep) throw();
00024 unsigned int getTimeStep() const throw();
00025
00026 std::string getName() const throw();
00027 std::vector<std::string> getParameters() const throw();
00028
00029 bool operator<(const AspFluent& other) const throw();
00030 bool operator==(const AspFluent& other) const throw();
00031
00032 std::string toString() const throw();
00033 std::string toString(unsigned int timeStep) const throw();
00034 std::string toString(const std::string& timeStepVar) const throw();
00035
00036 operator std::string() const { return this->toString(); }
00037
00038 private:
00039 unsigned int timeStep;
00040 std::string cachedBase;
00041
00042 friend class ActionComparator;
00043 friend class ActionEquality;
00044
00045 };
00046
00047 struct ActionComparator : public std::binary_function<const AspFluent&, const AspFluent&, bool>{
00048 bool operator()(const AspFluent& first, const AspFluent& second) const {
00049 return first.cachedBase < second.cachedBase;
00050 }
00051 };
00052
00053 struct ActionEquality : public std::binary_function<const AspFluent&, const AspFluent&, bool>{
00054 bool operator()(const AspFluent& first, const AspFluent& second) const {
00055 return first.cachedBase == second.cachedBase;
00056 }
00057 };
00058
00059 struct TimeStepComparator : public std::binary_function<const AspFluent&, const AspFluent&, bool>{
00060 bool operator()(const AspFluent& first, const AspFluent& second) const {
00061 return first.getTimeStep() < second.getTimeStep();
00062 }
00063 };
00064
00065 typedef std::set<AspFluent, ActionComparator> ActionSet;
00066
00067 struct AspFluentRef {
00068
00069 AspFluentRef(const AspFluent &inobj) : const_obj(&inobj) {}
00070
00071 operator const AspFluent&() const {
00072 return *const_obj;
00073 }
00074
00075 bool operator<(const AspFluent& other) const throw() {
00076 return *const_obj < other;
00077 }
00078 bool operator==(const AspFluent& other) const throw() {
00079 return *const_obj == other;
00080 }
00081
00082 operator std::string() const { return const_obj->toString(); }
00083
00084 const AspFluent *const_obj;
00085 };
00086
00087 }
00088 #endif