Created
January 3, 2011 21:25
-
-
Save chtitux/763993 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Processor.cpp | |
* | |
* Created on: 9 déc. 2010 | |
* Author: chtitux | |
*/ | |
#include <vector> | |
#include <algorithm> | |
#include <string> | |
#include <fstream> | |
#include <iostream> | |
#include "Processor.h" | |
#include "Exception.h" | |
#include "CommandDefaultAbout.h" | |
#include "CommandDisplay.h" | |
#include "CommandDisplayDlls.h" | |
#include "CommandList.h" | |
#include "CommandLoadDll.h" | |
#include "CommandRemoveDll.h" | |
#include "CommandPrompt.h" | |
#include "CommandQuit.h" | |
#include "CommandRead.h" | |
Processor::Processor(Io *_io): | |
System(_io) | |
{ | |
// Ajout de la CommandDefaultAbout | |
this->AddCde(new CommandDefaultAbout("about")); | |
this->AddCde(new CommandDisplay("display")); | |
this->AddCde(new CommandDisplayDlls("display_dlls")); | |
this->AddCde(new CommandList("list")); | |
this->AddCde(new CommandLoadDll("load_dll")); | |
this->AddCde(new CommandRemoveDll("remove_dll")); | |
this->AddCde(new CommandPrompt("prompt")); | |
this->AddCde(new CommandQuit("quit")); | |
this->AddCde(new CommandRead("read")); | |
} | |
Processor::~Processor() { | |
// TODO Auto-generated destructor stub | |
} | |
void Processor::AddCde(Command* command) | |
{ | |
commands.insert(value_type((*command).GetName(), command)); | |
} | |
void Processor::AddCdes(Package* package) | |
{ | |
Package::const_iterator it = (*package).begin(); | |
for(; it != (*package).end(); it++) | |
{ | |
AddCde((*it)); | |
} | |
} | |
/** | |
* Enlève une commande d'un Processor | |
*/ | |
void Processor::RemoveCde(Command* command) | |
{ | |
commands.erase((*command).GetName()); | |
} | |
void Processor::RemoveCdes(Package* package) | |
{ | |
Package::iterator it = (*package).begin(); | |
for(; it != (*package).end(); it++) | |
{ | |
RemoveCde(*it); | |
} | |
} | |
void Processor::AddSystem(System* system) | |
{ | |
systems.push_back(system); | |
} | |
void Processor::RemoveSystem(const string& name) | |
{ | |
Systems::iterator it = systems.begin(); | |
System sys; | |
for(;it != systems.end(); it++) | |
{ | |
// Si le nom est matché, on supprime toutes les occurences du system | |
if((**it).getSystemType() == name) | |
{ | |
systems.erase(std::remove(systems.begin(), systems.end(), *it), systems.end()); | |
break; | |
} | |
} | |
// | |
} | |
void Processor::ExecuteCde(const string& command) | |
{ | |
cout << command << endl; | |
if(command == "quit") | |
Terminate(); // FIXME : enlever le check cde == "string" | |
Command* cde = commands.find(command)->second; | |
if(cde) | |
cde->Execute(*this); | |
else | |
io->getOut() << "Command not found !"; | |
} | |
string Processor::FetchCde() | |
{ | |
std::string ligne; // variable contenant chaque ligne lue | |
std::getline( (*io).getIn() , ligne ); | |
return ligne; | |
} | |
void Processor::Run() | |
{ | |
ExecuteCde(FetchCde()); | |
} | |
void Processor::Start() | |
{ | |
} | |
void Processor::Terminate() | |
{ | |
terminated = true; | |
} | |
bool Processor::IsTerminated() | |
{ | |
return terminated; | |
} | |
ostream& Processor::PrintOn(ostream& ostream) const | |
{ | |
return ostream << "Processor : "; | |
} | |
void Processor::CheckConsistency() | |
{ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment