X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcreaDevManagerLib%2FmodelCDMBlackBox.cpp;fp=lib%2FcreaDevManagerLib%2FmodelCDMBlackBox.cpp;h=4d834927d61e08d6e3609d4b889ec595e5c732fe;hb=cfa883d25e73975f73c20fefc1ec2c947d827938;hp=d177c88250b810f0cda829dddc451e124082363e;hpb=2c45094f8403883f8fb52c1801f1d96a35a471bf;p=crea.git diff --git a/lib/creaDevManagerLib/modelCDMBlackBox.cpp b/lib/creaDevManagerLib/modelCDMBlackBox.cpp index d177c88..4d83492 100644 --- a/lib/creaDevManagerLib/modelCDMBlackBox.cpp +++ b/lib/creaDevManagerLib/modelCDMBlackBox.cpp @@ -47,16 +47,16 @@ modelCDMBlackBox::modelCDMBlackBox() this->header = NULL; } -modelCDMBlackBox::modelCDMBlackBox(const std::string& hName, const std::string& path, const int& level) +modelCDMBlackBox::modelCDMBlackBox(const std::string& path, const std::string& name, const int& level) { - this->name = hName.substr(2, hName.size()-4); + this->name = name; 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::string pathHeader = path + CDMUtilities::SLASH + "bb" + this->name + ".h"; std::ifstream confFile; confFile.open((pathHeader).c_str()); @@ -101,6 +101,8 @@ modelCDMBlackBox::modelCDMBlackBox(const std::string& hName, const std::string& modelCDMBlackBox::~modelCDMBlackBox() { + this->header = NULL; + this->source = NULL; } const std::string& modelCDMBlackBox::GetNameBlackBox() const @@ -126,11 +128,11 @@ const std::string& modelCDMBlackBox::GetDescription() const bool modelCDMBlackBox::SetAuthors(const std::string& authors, std::string*& result) { std::vector words; - CDMUtilities::splitter::split(words, authors, ",\"\n", CDMUtilities::splitter::no_empties); + 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]; + authorsReal += "," + words[i]; } //opening original header @@ -168,7 +170,7 @@ bool modelCDMBlackBox::SetAuthors(const std::string& authors, std::string*& resu in.close(); out.close(); //delete old file and rename new file - std::string renameCommand = "mv " + pathHeader + ".tmp " + pathHeader; + std::string renameCommand = "mv \"" + pathHeader + ".tmp\" \"" + pathHeader + "\""; if(system(renameCommand.c_str())) { result = new std::string("An error occurred while running '" + renameCommand + "'."); @@ -186,57 +188,57 @@ bool modelCDMBlackBox::SetCategories( ) { 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; + 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( @@ -245,11 +247,11 @@ bool modelCDMBlackBox::SetDescription( ) { std::vector words; - CDMUtilities::splitter::split(words, description, "\"", CDMUtilities::splitter::no_empties); + CDMUtilities::splitter::split(words, description, "\"\n\\/", CDMUtilities::splitter::no_empties); std::string descReal = words[0]; for (int i = 1; i < words.size(); i++) { - descReal += "\\\"" + words[i]; + descReal += "-" + words[i]; } //opening original header @@ -287,7 +289,7 @@ bool modelCDMBlackBox::SetDescription( in.close(); out.close(); //delete old file and rename new file - std::string renameCommand = "mv " + pathHeader + ".tmp " + pathHeader; + std::string renameCommand = "mv \"" + pathHeader + ".tmp\" \"" + pathHeader + "\""; if(system(renameCommand.c_str())) { result = new std::string("An error occurred while running '" + renameCommand + "'."); @@ -330,6 +332,49 @@ modelCDMFile* modelCDMBlackBox::GetSourceFile() const const bool modelCDMBlackBox::Refresh(std::string*& result) { - //TODO: implement method + std::string pathHeader = path + CDMUtilities::SLASH + "bb" + this->name + ".h"; + + std::ifstream confFile; + confFile.open((pathHeader).c_str()); + std::string word; + + if(!confFile.is_open()) + return false; + + 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(); return true; }