diff --git a/Action.cpp b/Action.cpp new file mode 100644 index 0000000..ee5828a --- /dev/null +++ b/Action.cpp @@ -0,0 +1,42 @@ +#include "Action.h" +using namespace mmm; + +Action::Action() { + parameters.clear(); + parametersIterator = -1; + parametersEndIndicator = true; +} + +Action::~Action() { + parameters.clear(); + parametersIterator = -1; + parametersEndIndicator = true; +} + +void Action::insertParameter(std::string param) { + parameters.push_back(param); + if(parametersEndIndicator) { + parametersEndIndicator = false; + } +} + +std::string Action::getNextParameter() { + if(parametersIterator+1 < parameters.size()) { + parametersIterator++; + return parameters[parametersIterator]; + } else { + parametersEndIndicator = true; + return ""; + } +} + +void Action::resetParametersIterator() { + parametersIterator = -1; + if(parametersEndIndicator) { + parametersEndIndicator = false; + } +} + +bool Action::parametersEnd() { + return parametersEndIndicator; +} diff --git a/Action.h b/Action.h new file mode 100644 index 0000000..1725be1 --- /dev/null +++ b/Action.h @@ -0,0 +1,34 @@ +#ifndef _ACTION_H +#define _ACTION_H +#include +#include +/// \file Action.h +/// \brief A base class for 3m actions. +/// \author Phitherek_ +/// \date 2013 +/// \version 0.1-pre + +/// \namespace mmm +/// \brief A global namespace for 3m. +namespace mmm { +/// \class Action +/// \brief A base class for 3m actions. +class Action { +protected: + std::vector parameters; ///< Action parameters. + int parametersIterator; ///< Parameter list iterator. + bool parametersEndIndicator; ///< Indicates if the parameter list iterator has reached end of the list. +public: + Action(); ///< A constructor. + ~Action(); ///< A destructor. + void insertParameter(std::string param); ///< \brief A function that inserts parameter to action' s parameter list. + ///< \param param Parameter to insert. + std::string getNextParameter(); ///< \brief A function that gets next parameter from the parameter list. + ///< \return Next parameter from the parameter list. + void resetParametersIterator(); ///< A function that resets iterator of parameter list. + bool parametersEnd(); ///< \brief A function that returns if parameter list iterator is at the end of the list. + ///< \return True if parameter list iterator is at the end of the list, false otherwise. + virtual void run() {} ///< A virtual function that executes the action. +}; +} +#endif diff --git a/OBJECTS b/OBJECTS index b31f6d2..7c2a6f1 100644 --- a/OBJECTS +++ b/OBJECTS @@ -9,7 +9,7 @@ ModListDescription: name, server, modlistPath x ModInfoDescription: name, server, modinfoPath x ModInfo: ModInfoDescription, vector x ParameterParser: actionList, argc, argv -Action: +Action: x SyncAction InstallAction UpdateAction