2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------
29 * modelCDMBlackBox.cpp
31 * Created on: Nov 23, 2012
32 * Author: Daniel Felipe Gonzalez Obando
35 #include "modelCDMBlackBox.h"
39 #include "CDMUtilities.h"
44 modelCDMBlackBox::modelCDMBlackBox()
50 modelCDMBlackBox::modelCDMBlackBox(const std::string& hName, const std::string& path, const int& level)
52 this->name = hName.substr(2, hName.size()-4);
55 this->type = wxDIR_DIRS;
59 std::string pathHeader = path + "/" + "bb" + this->name + ".h";
61 std::ifstream confFile;
62 confFile.open((pathHeader).c_str());
64 while(confFile.is_open() && !confFile.eof())
67 std::getline(confFile,word,'(');
68 std::vector<std::string> wordBits;
69 CDMUtilities::splitter::split(wordBits,word," \n",CDMUtilities::splitter::no_empties);
71 if(wordBits[wordBits.size()-1] == "BBTK_NAME")
73 std::getline(confFile,word,'"');
74 std::getline(confFile,word,'"');
75 this->nameBlackBox = word;
77 else if(wordBits[wordBits.size()-1] == "BBTK_AUTHOR")
79 std::getline(confFile,word,'"');
80 std::getline(confFile,word,'"');
83 else if(wordBits[wordBits.size()-1] == "BBTK_DESCRIPTION")
85 std::getline(confFile,word,'"');
86 std::getline(confFile,word,'"');
87 this->description = word;
89 else if(wordBits[wordBits.size()-1] == "BBTK_CATEGORY")
91 std::getline(confFile,word,'"');
92 std::getline(confFile,word,'"');
93 this->categories = word;
94 if (this->categories == "")
95 this->categories = "empty";
102 modelCDMBlackBox::~modelCDMBlackBox()
106 const std::string& modelCDMBlackBox::GetNameBlackBox() const
108 return this->nameBlackBox;
111 const std::string& modelCDMBlackBox::GetAuthors() const
113 return this->authors;
116 const std::string& modelCDMBlackBox::GetCategories() const
118 return this->categories;
121 const std::string& modelCDMBlackBox::GetDescription() const
123 return this->description;
126 bool modelCDMBlackBox::SetAuthors(const std::string& authors, std::string*& result)
128 std::vector<std::string> words;
129 CDMUtilities::splitter::split(words, authors, ",\"\n", CDMUtilities::splitter::no_empties);
130 std::string authorsReal = words[0];
131 for (int i = 1; i < words.size(); i++)
133 authorsReal += "/" + words[i];
136 //opening original header
137 std::string pathHeader = this->header->GetPath();
138 std::ifstream in(pathHeader.c_str());
141 result = new std::string(pathHeader + " file failed to open.");
144 //opening temporal header
145 std::ofstream out((pathHeader + ".tmp").c_str());
148 result = new std::string(pathHeader + ".tmp file failed to open.");
151 //copying contents from original to temporal and making changes
153 while (getline(in, reading, '('))
155 CDMUtilities::splitter::split(words, reading, "\n ", CDMUtilities::splitter::no_empties);
156 if(words[words.size() - 1] == "BBTK_AUTHOR")
158 out << reading << "(\"" << authorsReal << "\")";
159 getline(in, reading, ')');
170 //delete old file and rename new file
171 std::string renameCommand = "mv " + pathHeader + ".tmp " + pathHeader;
172 if(system(renameCommand.c_str()))
174 result = new std::string("An error occurred while running '" + renameCommand + "'.");
178 this->authors = authorsReal;
183 bool modelCDMBlackBox::SetCategories(
184 const std::string& categories,
188 std::vector<std::string> words;
189 CDMUtilities::splitter::split(words, categories, "\"", CDMUtilities::splitter::no_empties);
190 std::string catsReal = words[0];
191 for (int i = 1; i < words.size(); i++)
193 catsReal += "-" + words[i];
196 //opening original header
197 std::string pathHeader = this->header->GetPath();
198 std::ifstream in(pathHeader.c_str());
201 result = new std::string(pathHeader + " file failed to open.");
204 //opening temporal header
205 std::ofstream out((pathHeader + ".tmp").c_str());
208 result = new std::string(pathHeader + ".tmp file failed to open.");
211 //copying contents from original to temporal and making changes
213 while (getline(in, reading, '('))
215 CDMUtilities::splitter::split(words, reading, "\n ", CDMUtilities::splitter::no_empties);
216 if(words[words.size() - 1] == "BBTK_CATEGORY")
218 out << reading << "(\"" << catsReal << "\")";
219 getline(in, reading, ')');
230 //delete old file and rename new file
231 std::string renameCommand = "mv " + pathHeader + ".tmp " + pathHeader;
232 if(system(renameCommand.c_str()))
234 result = new std::string("An error occurred while running '" + renameCommand + "'.");
238 this->categories = catsReal;
242 bool modelCDMBlackBox::SetDescription(
243 const std::string& description,
247 std::vector<std::string> words;
248 CDMUtilities::splitter::split(words, description, "\"", CDMUtilities::splitter::no_empties);
249 std::string descReal = words[0];
250 for (int i = 1; i < words.size(); i++)
252 descReal += "\\\"" + words[i];
255 //opening original header
256 std::string pathHeader = this->header->GetPath();
257 std::ifstream in(pathHeader.c_str());
260 result = new std::string(pathHeader + " file failed to open.");
263 //opening temporal header
264 std::ofstream out((pathHeader + ".tmp").c_str());
267 result = new std::string(pathHeader + ".tmp file failed to open.");
270 //copying contents from original to temporal and making changes
272 while (getline(in, reading, '('))
274 CDMUtilities::splitter::split(words, reading, "\n ", CDMUtilities::splitter::no_empties);
275 if(words[words.size() - 1] == "BBTK_DESCRIPTION")
277 out << reading << "(\"" << descReal << "\")";
278 getline(in, reading, ')');
289 //delete old file and rename new file
290 std::string renameCommand = "mv " + pathHeader + ".tmp " + pathHeader;
291 if(system(renameCommand.c_str()))
293 result = new std::string("An error occurred while running '" + renameCommand + "'.");
297 this->description = descReal;
301 void modelCDMBlackBox::SetHeaderFile(modelCDMFile* file)
306 void modelCDMBlackBox::SetSourceFile(modelCDMFile* file)
311 bool modelCDMBlackBox::OpenCxx(std::string*& result)
313 return !CDMUtilities::openTextEditor(this->source->GetPath());
316 bool modelCDMBlackBox::OpenHxx(std::string*& result)
318 return !CDMUtilities::openTextEditor(this->header->GetPath());
321 modelCDMFile* modelCDMBlackBox::GetHeaderFile() const
326 modelCDMFile* modelCDMBlackBox::GetSourceFile() const
331 const bool modelCDMBlackBox::Refresh(std::string*& result)
333 //TODO: implement method