Browse Source

Updated to use ReadableString. getHelp() now takes paremeters.

release/0.19
JustinAJ 11 years ago
parent
commit
e608ee4a3f
  1. 26
      Jupiter/Command.cpp
  2. 11
      Jupiter/Command.h

26
Jupiter/Command.cpp

@ -19,11 +19,12 @@
#include "ArrayList.h" #include "ArrayList.h"
#include "Functions.h" #include "Functions.h"
#include "Command.h" #include "Command.h"
#include "String.h"
struct Jupiter::Command::Data struct Jupiter::Command::Data
{ {
public: public:
Jupiter::ArrayList<Jupiter::CString_Strict<char>> triggers; Jupiter::ArrayList<Jupiter::StringS> triggers;
}; };
Jupiter::Command::Command() Jupiter::Command::Command()
@ -34,26 +35,21 @@ Jupiter::Command::Command()
Jupiter::Command::Command(const Command &command) Jupiter::Command::Command(const Command &command)
{ {
Jupiter::Command::data_ = new Jupiter::Command::Data(); Jupiter::Command::data_ = new Jupiter::Command::Data();
Jupiter::CStringS *trigger; for (size_t i = 0; i != Jupiter::Command::data_->triggers.size(); i++)
for (int i = command.data_->triggers.size() - 1; i >= 0; i--) Jupiter::Command::data_->triggers.add(new Jupiter::StringS(*command.data_->triggers.get(i)));
{
trigger = new Jupiter::CStringS(*command.data_->triggers.get(i));
Jupiter::Command::data_->triggers.add(trigger);
}
} }
Jupiter::Command::~Command() Jupiter::Command::~Command()
{ {
for (int i = Jupiter::Command::data_->triggers.size() - 1; i >= 0; i--) delete Jupiter::Command::data_->triggers.remove(i); Jupiter::Command::data_->triggers.emptyAndDelete();
delete Jupiter::Command::data_; delete Jupiter::Command::data_;
} }
// Command Functions // Command Functions
void Jupiter::Command::addTrigger(const char *trigger) void Jupiter::Command::addTrigger(const Jupiter::ReadableString &trigger)
{ {
Jupiter::CStringS *aTrigger = new Jupiter::CStringS(trigger); Jupiter::Command::data_->triggers.add(new Jupiter::StringS(trigger));
Jupiter::Command::data_->triggers.add(aTrigger);
} }
const char *Jupiter::Command::getTrigger(short index) const const char *Jupiter::Command::getTrigger(short index) const
@ -61,14 +57,14 @@ const char *Jupiter::Command::getTrigger(short index) const
return Jupiter::Command::data_->triggers.get(index)->c_str(); return Jupiter::Command::data_->triggers.get(index)->c_str();
} }
unsigned int Jupiter::Command::getTriggerCount() const size_t Jupiter::Command::getTriggerCount() const
{ {
return Jupiter::Command::data_->triggers.size(); return Jupiter::Command::data_->triggers.size();
} }
bool Jupiter::Command::matches(const char *trigger) const bool Jupiter::Command::matches(const Jupiter::ReadableString &trigger) const
{ {
unsigned int size = Jupiter::Command::data_->triggers.size(); for (size_t i = 0; i != Jupiter::Command::data_->triggers.size(); i++)
for (unsigned int i = 0; i < size; i++) if (Jupiter::Command::data_->triggers.get(i)->equalsi(trigger)) return true; if (Jupiter::Command::data_->triggers.get(i)->equalsi(trigger)) return true;
return false; return false;
} }

11
Jupiter/Command.h

@ -25,7 +25,7 @@
#include "Jupiter.h" #include "Jupiter.h"
#include "ArrayList.h" #include "ArrayList.h"
#include "CString.h" #include "Reference_String.h"
namespace Jupiter namespace Jupiter
{ {
@ -41,7 +41,7 @@ namespace Jupiter
* *
* @param trigger Trigger to add to the command. * @param trigger Trigger to add to the command.
*/ */
void addTrigger(const char *trigger); void addTrigger(const Jupiter::ReadableString &trigger);
/** /**
* @brief Fetches a command's specified trigger. * @brief Fetches a command's specified trigger.
@ -56,7 +56,7 @@ namespace Jupiter
* *
* @return Number of triggers the command accepts. * @return Number of triggers the command accepts.
*/ */
unsigned int getTriggerCount() const; size_t getTriggerCount() const;
/** /**
* @brief Checks if a specified trigger matches one of the stored triggers. * @brief Checks if a specified trigger matches one of the stored triggers.
@ -65,14 +65,15 @@ namespace Jupiter
* @param trigger Trigger to check against the trigger list. * @param trigger Trigger to check against the trigger list.
* @return True if a match was found, false otherwise. * @return True if a match was found, false otherwise.
*/ */
bool matches(const char *trigger) const; bool matches(const Jupiter::ReadableString &trigger) const;
/** /**
* @brief Returns a brief explanation and syntax description about a command. * @brief Returns a brief explanation and syntax description about a command.
* *
* @param parameters Optional string containing any data to be passed to the help command.
* @return Brief description of command and syntax. * @return Brief description of command and syntax.
*/ */
virtual const char *getHelp() = 0; virtual const Jupiter::ReadableString &getHelp(const Jupiter::ReadableString &parameters = Jupiter::ReferenceString::empty) = 0;
/** /**
* @brief Default constructor for command class. * @brief Default constructor for command class.

Loading…
Cancel
Save