Xmipp  v3.23.11-Nereus
userSettings.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: David Strelak (davidstrelak@gmail.com)
4  *
5  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20  * 02111-1307 USA
21  *
22  * All comments concerning this program package may be sent to the
23  * e-mail address 'xmipp@cnb.csic.es'
24  ***************************************************************************/
25 
26 #include "userSettings.h"
27 #include <iostream>
28 
29 std::list<UserSettings> UserSettings::storages;
30 
32  std::ofstream output(path);
33  if (output) {
34  for (const auto& rec : data) {
35  output << rec.first << delim << rec.second << "\n";
36  }
37  output.close();
38  return true;
39  }
40 
41  std::cerr<<"Error opening output file "<< path << std::endl;
42  return false;
43 }
44 
46  std::ifstream file(path);
47  std::string line;
48 
49  if (!file) {
50  std::cerr<<"File "<< path << " does NOT exist yet or cannot be read."
51  << std::endl;
52  return false;
53  }
54  while (std::getline(file, line))
55  {
56  std::stringstream ss(line);
57  std::string key, value;
58  std::getline(ss, key, delim);
59  std::getline(ss, value);
60  data[key] = value;
61  }
62  file.close();
63  return true;
64 }