X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcreaDevManagerLib%2FmodelCDMBlackBox.cpp;fp=lib%2FcreaDevManagerLib%2FmodelCDMBlackBox.cpp;h=d177c88250b810f0cda829dddc451e124082363e;hb=2c45094f8403883f8fb52c1801f1d96a35a471bf;hp=5ea4a26cbfae621fd360a674a0044f096b5b17f5;hpb=2b6788596bc21c7942df4b0d6917eaf5b5d72277;p=crea.git diff --git a/lib/creaDevManagerLib/modelCDMBlackBox.cpp b/lib/creaDevManagerLib/modelCDMBlackBox.cpp index 5ea4a26..d177c88 100644 --- a/lib/creaDevManagerLib/modelCDMBlackBox.cpp +++ b/lib/creaDevManagerLib/modelCDMBlackBox.cpp @@ -34,19 +34,69 @@ #include "modelCDMBlackBox.h" +#include + +#include "CDMUtilities.h" + #include #include"wx/dir.h" modelCDMBlackBox::modelCDMBlackBox() { + this->source = NULL; + this->header = NULL; } modelCDMBlackBox::modelCDMBlackBox(const std::string& hName, const std::string& path, const int& level) { - this->name = this->nameBlackBox = hName.substr(2, hName.size()-4); + this->name = hName.substr(2, hName.size()-4); this->path = path; this->level = level; this->type = wxDIR_DIRS; + this->source = NULL; + this->header = NULL; + + std::string pathHeader = path + "/" + "bb" + this->name + ".h"; + + std::ifstream confFile; + confFile.open((pathHeader).c_str()); + std::string word; + while(confFile.is_open() && !confFile.eof()) + { + //get BBTK's + std::getline(confFile,word,'('); + std::vector wordBits; + CDMUtilities::splitter::split(wordBits,word," \n",CDMUtilities::splitter::no_empties); + + if(wordBits[wordBits.size()-1] == "BBTK_NAME") + { + std::getline(confFile,word,'"'); + std::getline(confFile,word,'"'); + this->nameBlackBox = word; + } + else if(wordBits[wordBits.size()-1] == "BBTK_AUTHOR") + { + std::getline(confFile,word,'"'); + std::getline(confFile,word,'"'); + this->authors = word; + } + else if(wordBits[wordBits.size()-1] == "BBTK_DESCRIPTION") + { + std::getline(confFile,word,'"'); + std::getline(confFile,word,'"'); + this->description = word; + } + else if(wordBits[wordBits.size()-1] == "BBTK_CATEGORY") + { + std::getline(confFile,word,'"'); + std::getline(confFile,word,'"'); + this->categories = word; + if (this->categories == "") + this->categories = "empty"; + } + } + confFile.close(); + } modelCDMBlackBox::~modelCDMBlackBox() @@ -63,11 +113,6 @@ const std::string& modelCDMBlackBox::GetAuthors() const return this->authors; } -const std::string& modelCDMBlackBox::GetAuthorsEmail() const -{ - return this->authorsEmail; -} - const std::string& modelCDMBlackBox::GetCategories() const { return this->categories; @@ -78,33 +123,120 @@ const std::string& modelCDMBlackBox::GetDescription() const return this->description; } -const std::string& modelCDMBlackBox::GetVersion() const -{ - return this->version; -} - bool modelCDMBlackBox::SetAuthors(const std::string& authors, std::string*& result) { - //TODO: implement method - return true; -} + std::vector words; + CDMUtilities::splitter::split(words, authors, ",\"\n", CDMUtilities::splitter::no_empties); + std::string authorsReal = words[0]; + for (int i = 1; i < words.size(); i++) + { + authorsReal += "/" + words[i]; + } -bool modelCDMBlackBox::SetAuthorsEmail( - const std::string& email, - std::string*& result -) -{ - //TODO: implement method + //opening original header + std::string pathHeader = this->header->GetPath(); + std::ifstream in(pathHeader.c_str()); + if( !in.is_open()) + { + result = new std::string(pathHeader + " file failed to open."); + return false; + } + //opening temporal header + std::ofstream out((pathHeader + ".tmp").c_str()); + if( !out.is_open()) + { + result = new std::string(pathHeader + ".tmp file failed to open."); + return false; + } + //copying contents from original to temporal and making changes + std::string reading; + while (getline(in, reading, '(')) + { + CDMUtilities::splitter::split(words, reading, "\n ", CDMUtilities::splitter::no_empties); + if(words[words.size() - 1] == "BBTK_AUTHOR") + { + out << reading << "(\"" << authorsReal << "\")"; + getline(in, reading, ')'); + } + else + { + out << reading; + if (!in.eof()) + out << "("; + } + } + in.close(); + out.close(); + //delete old file and rename new file + std::string renameCommand = "mv " + pathHeader + ".tmp " + pathHeader; + if(system(renameCommand.c_str())) + { + result = new std::string("An error occurred while running '" + renameCommand + "'."); + return false; + } + + this->authors = authorsReal; return true; + } bool modelCDMBlackBox::SetCategories( - const std::string& version, + const std::string& categories, std::string*& result ) { - //TODO: implement method - return true; + std::vector words; + CDMUtilities::splitter::split(words, categories, "\"", CDMUtilities::splitter::no_empties); + std::string catsReal = words[0]; + for (int i = 1; i < words.size(); i++) + { + catsReal += "-" + words[i]; + } + + //opening original header + std::string pathHeader = this->header->GetPath(); + std::ifstream in(pathHeader.c_str()); + if( !in.is_open()) + { + result = new std::string(pathHeader + " file failed to open."); + return false; + } + //opening temporal header + std::ofstream out((pathHeader + ".tmp").c_str()); + if( !out.is_open()) + { + result = new std::string(pathHeader + ".tmp file failed to open."); + return false; + } + //copying contents from original to temporal and making changes + std::string reading; + while (getline(in, reading, '(')) + { + CDMUtilities::splitter::split(words, reading, "\n ", CDMUtilities::splitter::no_empties); + if(words[words.size() - 1] == "BBTK_CATEGORY") + { + out << reading << "(\"" << catsReal << "\")"; + getline(in, reading, ')'); + } + else + { + out << reading; + if (!in.eof()) + out << "("; + } + } + in.close(); + out.close(); + //delete old file and rename new file + std::string renameCommand = "mv " + pathHeader + ".tmp " + pathHeader; + if(system(renameCommand.c_str())) + { + result = new std::string("An error occurred while running '" + renameCommand + "'."); + return false; + } + + this->categories = catsReal; + return true; } bool modelCDMBlackBox::SetDescription( @@ -112,26 +244,88 @@ bool modelCDMBlackBox::SetDescription( std::string*& result ) { - //TODO: implement method + std::vector words; + CDMUtilities::splitter::split(words, description, "\"", CDMUtilities::splitter::no_empties); + std::string descReal = words[0]; + for (int i = 1; i < words.size(); i++) + { + descReal += "\\\"" + words[i]; + } + + //opening original header + std::string pathHeader = this->header->GetPath(); + std::ifstream in(pathHeader.c_str()); + if( !in.is_open()) + { + result = new std::string(pathHeader + " file failed to open."); + return false; + } + //opening temporal header + std::ofstream out((pathHeader + ".tmp").c_str()); + if( !out.is_open()) + { + result = new std::string(pathHeader + ".tmp file failed to open."); + return false; + } + //copying contents from original to temporal and making changes + std::string reading; + while (getline(in, reading, '(')) + { + CDMUtilities::splitter::split(words, reading, "\n ", CDMUtilities::splitter::no_empties); + if(words[words.size() - 1] == "BBTK_DESCRIPTION") + { + out << reading << "(\"" << descReal << "\")"; + getline(in, reading, ')'); + } + else + { + out << reading; + if (!in.eof()) + out << "("; + } + } + in.close(); + out.close(); + //delete old file and rename new file + std::string renameCommand = "mv " + pathHeader + ".tmp " + pathHeader; + if(system(renameCommand.c_str())) + { + result = new std::string("An error occurred while running '" + renameCommand + "'."); + return false; + } + + this->description = descReal; return true; } -bool modelCDMBlackBox::SetVersion(const std::string& version, std::string*& result) +void modelCDMBlackBox::SetHeaderFile(modelCDMFile* file) { - //TODO: implement method - return true; + this->header = file; +} + +void modelCDMBlackBox::SetSourceFile(modelCDMFile* file) +{ + this->source = file; } bool modelCDMBlackBox::OpenCxx(std::string*& result) { - //TODO: implement method - return true; + return !CDMUtilities::openTextEditor(this->source->GetPath()); } bool modelCDMBlackBox::OpenHxx(std::string*& result) { - //TODO: implement method - return true; + return !CDMUtilities::openTextEditor(this->header->GetPath()); +} + +modelCDMFile* modelCDMBlackBox::GetHeaderFile() const +{ + return this->header; +} + +modelCDMFile* modelCDMBlackBox::GetSourceFile() const +{ + return this->source; } const bool modelCDMBlackBox::Refresh(std::string*& result)