/*! * @file state.h * @brief Contains a base class for a state (in meowpp, most of all the return * value of a function (or to say, an "operation") will be a state). * * @author cathook */ #ifndef __MEOWPP_UTILITY_STATE_H__ #define __MEOWPP_UTILITY_STATE_H__ #include "object.h" namespace meow { /*! * @brief The base class for state. * * Some example code: * @code{.cpp} * #include * #include * * using namespace meow; * * class Func1State : public State { * public: * static const int SAME = 0; * static const int DIFF = 1; * }; * * State Func1(int a, int b) { * if (a == b) { * return Func1State::SAME; * } else { * return Func1State::DIFF; * } * } * * int main() { * if (Func1(3, 5) == Func1State::SAME) { * printf("same!\n"); * } else { * printf("diff\n"); * } * return 0; * } * @endcode */ class State : public Object { private: int value_; //!< Stores the current state. public: /*! * @brief Default constructor. */ State() {} /*! * @brief Copy constructor. */ State(State const& arg_another_state) : State(arg_another_state.value_) {} /*! * @brief Constructor. */ State(int arg_init_value) : value_(arg_init_value) {} /*! * @brief Virtual destructor. */ virtual ~State() {} /*! * @brief Gets the integer value of the state. */ operator int() const { return value_; } /*! * @brief Sets the integer value of the state. */ State& operator=(State const& arg_new_state) { value_ = arg_new_state.value_; return *this; } Object* Copy() const { return new State(value_); } Object* CopyFrom(Object const* another_state) { value_ = dynamic_cast(another_state)->value_; return this; } bool Equals(Object const* another_state) { return (value_ == dynamic_cast(another_state)->value_); } }; } // meow #endif // __MEOWPP_UTILITY_STATE_H__