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 "Functions.h"
#include "Command.h"
#include "String.h"
struct Jupiter::Command::Data
{
public:
Jupiter::ArrayList<Jupiter::CString_Strict<char>> triggers;
Jupiter::ArrayList<Jupiter::StringS> triggers;
};
Jupiter::Command::Command()
@ -34,26 +35,21 @@ Jupiter::Command::Command()
Jupiter::Command::Command(const Command &command)
{
Jupiter::Command::data_ = new Jupiter::Command::Data();
Jupiter::CStringS *trigger;
for (int i = command.data_->triggers.size() - 1; i >= 0; i--)
{
trigger = new Jupiter::CStringS(*command.data_->triggers.get(i));
Jupiter::Command::data_->triggers.add(trigger);
}
for (size_t i = 0; i != Jupiter::Command::data_->triggers.size(); i++)
Jupiter::Command::data_->triggers.add(new Jupiter::StringS(*command.data_->triggers.get(i)));
}
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_;
}
// 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(aTrigger);
Jupiter::Command::data_->triggers.add(new Jupiter::StringS(trigger));
}
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();
}
unsigned int Jupiter::Command::getTriggerCount() const
size_t Jupiter::Command::getTriggerCount() const
{
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 (unsigned int i = 0; i < size; i++) if (Jupiter::Command::data_->triggers.get(i)->equalsi(trigger)) return true;
for (size_t i = 0; i != Jupiter::Command::data_->triggers.size(); i++)
if (Jupiter::Command::data_->triggers.get(i)->equalsi(trigger)) return true;
return false;
}

11
Jupiter/Command.h

@ -25,7 +25,7 @@
#include "Jupiter.h"
#include "ArrayList.h"
#include "CString.h"
#include "Reference_String.h"
namespace Jupiter
{
@ -41,7 +41,7 @@ namespace Jupiter
*
* @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.
@ -56,7 +56,7 @@ namespace Jupiter
*
* @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.
@ -65,14 +65,15 @@ namespace Jupiter
* @param trigger Trigger to check against the trigger list.
* @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.
*
* @param parameters Optional string containing any data to be passed to the help command.
* @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.

Loading…
Cancel
Save