From 0892fb1c390bd99132861fc6e46af7d866622962 Mon Sep 17 00:00:00 2001 From: Sverre Rabbelier Date: Fri, 14 Mar 2008 21:26:42 +0100 Subject: [PATCH] Converted OLCEditor. --- UnsignedByte/Core/OLCEditor.cpp | 51 +++++++++++++++++++++------------- UnsignedByte/Core/OLCEditor.h | 25 ++++------------- UnsignedByte/Resource/Resource.project | 1 + 3 files changed, 38 insertions(+), 39 deletions(-) diff --git a/UnsignedByte/Core/OLCEditor.cpp b/UnsignedByte/Core/OLCEditor.cpp index a5ba75e..5c1ada8 100644 --- a/UnsignedByte/Core/OLCEditor.cpp +++ b/UnsignedByte/Core/OLCEditor.cpp @@ -23,38 +23,49 @@ #include "UBSocket.h" #include "StringUtilities.h" #include "Savable.h" +#include "Array.h" #include "EditorOLC.h" #include "Command.h" #include "Permission.h" #include "Account.h" // needed because we include UBSocket.h -OLCEditor::SavableCommand OLCEditor::m_listCommands("Commands", &OLCEditor::listCommands); -OLCEditor::SavableCommand OLCEditor::m_newSavable("New", &OLCEditor::newSavable); -OLCEditor::SavableCommand OLCEditor::m_deleteSavable("Delete", &OLCEditor::deleteSavable); -OLCEditor::SavableCommand OLCEditor::m_editSavable("Edit", &OLCEditor::editSavable); -OLCEditor::SavableCommand OLCEditor::m_quitEditor("Quit", &OLCEditor::quitEditor); -OLCEditor::SavableCommand OLCEditor::m_doneEditing("Done", &OLCEditor::doneEditing); -OLCEditor::SavableCommand OLCEditor::m_listSavable("List", &OLCEditor::listSavable); - -OLCEditor::GeneralInterpreter::GeneralInterpreter(void) +typedef OLCEditor E; +typedef CommandObject O; +typedef CommandBinding B; + +static O listCommands("Commands", &E::listCommands); +static O newSavable("New", &E::newSavable); +static O deleteSavable("Delete", &E::deleteSavable); +static O editSavable("Edit", &E::editSavable); +static O quitEditor("Quit", &E::quitEditor); +static O doneEditing("Done", &E::doneEditing); +static O listSavable("List", &E::listSavable); + +static const B commands[] = { + B("new", newSavable), + B("edit", editSavable), + B("list", listSavable), + B("commands", listCommands), + B("quit", quitEditor), + B("done", doneEditing), +}; + +OLCEditor::OLCEditor(UBSocket* sock) : +Editor(sock), +m_commands(commands, array_size(commands)) { - addWord("new", &m_newSavable); - addWord("edit", &m_editSavable); - addWord("list", &m_listSavable); - addWord("commands", &m_listCommands); - addWord("quit", &m_quitEditor); - addWord("done", &m_doneEditing); + } -OLCEditor::GeneralInterpreter::~GeneralInterpreter(void) +OLCEditor::~OLCEditor() { - + } std::string OLCEditor::lookup(const std::string& action) { - SavableCommand* act = GeneralInterpreter::Get()->translate(action); + const SavableCommand* act = m_commands.get_object(action); if(act) return act->getName(); @@ -63,7 +74,7 @@ std::string OLCEditor::lookup(const std::string& action) void OLCEditor::dispatch(const std::string& action, const std::string& argument) { - SavableCommand* act = GeneralInterpreter::Get()->translate(action); + const SavableCommand* act = m_commands.get_object(action); if(act) act->Run(this, argument); @@ -199,7 +210,7 @@ void OLCEditor::listSavable(const std::string& argument) void OLCEditor::listCommands(const std::string& argument) { - m_sock->Send(String::Get()->box(GeneralInterpreter::Get()->getWords(), name())); + m_sock->Send(String::Get()->box(m_commands.getCommandsVector(), name())); std::string name = this->name(); name.append("Editing"); m_sock->Send(String::Get()->box(getCommands(), name)); diff --git a/UnsignedByte/Core/OLCEditor.h b/UnsignedByte/Core/OLCEditor.h index 9ca1902..e7f248a 100644 --- a/UnsignedByte/Core/OLCEditor.h +++ b/UnsignedByte/Core/OLCEditor.h @@ -25,14 +25,15 @@ #include "Editor.h" #include "Interpreter.h" #include "CommandObject.h" +#include "CommandTable.h" class OLCEditor : public Editor { public: typedef CommandObject SavableCommand; - OLCEditor(UBSocket* sock) : Editor(sock) {}; - virtual ~OLCEditor(void) {}; + OLCEditor(UBSocket* sock); + virtual ~OLCEditor(void); virtual std::string lookup(const std::string& action); virtual void dispatch(const std::string& action, const std::string& argument); @@ -55,21 +56,7 @@ public: void listSavable(const std::string& argument); private: - OLCEditor(const OLCEditor& rhs) : Editor(rhs.m_sock) {}; - -protected: - class GeneralInterpreter : public Interpreter, public Singleton { - private: - GeneralInterpreter(void); - ~GeneralInterpreter(void); - friend class Singleton; - }; - - static SavableCommand m_listCommands; - static SavableCommand m_newSavable; - static SavableCommand m_deleteSavable; - static SavableCommand m_editSavable; - static SavableCommand m_quitEditor; - static SavableCommand m_doneEditing; - static SavableCommand m_listSavable; + CommandTable m_commands; + + OLCEditor(const OLCEditor& rhs); }; diff --git a/UnsignedByte/Resource/Resource.project b/UnsignedByte/Resource/Resource.project index 3157dc3..ce30631 100644 --- a/UnsignedByte/Resource/Resource.project +++ b/UnsignedByte/Resource/Resource.project @@ -64,6 +64,7 @@ + -- 2.11.4.GIT