Elements  5.12.0
A C++ base framework for the Euclid Software.
DependencyConfiguration.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2020 Euclid Science Ground Segment
3  *
4  * This library is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU Lesser General Public License as published by the Free
6  * Software Foundation; either version 3.0 of the License, or (at your option)
7  * any later version.
8  *
9  * This library is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12  * details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include <fstream>
20 #include <string>
21 #include <map>
22 #include <vector>
23 
25 
26 namespace ElementsServices {
27 namespace DataSync {
28 
29 using std::string;
30 using std::vector;
31 
33  path distantRoot,
34  path localRoot,
35  path configFile) :
36  m_aliasSeparator('\t'),
37  m_distantRoot(distantRoot),
38  m_localRoot(localRoot),
39  m_fileMap() {
40  parseConfigurationFile(configFile);
41 }
42 
44  return m_fileMap;
45 }
46 
48  return m_fileMap.at(localFile); // @TODO error handling
49 }
50 
52  return m_fileMap.size();
53 }
54 
56  vector<path> distant_paths;
57  for (const auto& item : m_fileMap) {
58  distant_paths.emplace_back(item.second);
59  }
60  return distant_paths;
61 }
62 
64  vector<path> local_paths;
65  for (const auto& item : m_fileMap) {
66  local_paths.emplace_back(item.first);
67  }
68  return local_paths;
69 }
70 
72  path abs_path = confFilePath(filename);
73  std::ifstream inputStream(abs_path.c_str());
74  string line;
75  while (std::getline(inputStream, line)) {
77  }
78 }
79 
81  if (lineHasAlias(line)) {
82  parseLineWithAlias(line);
83  } else {
85  }
86 }
87 
89  return m_aliasSeparator;
90 }
91 
92 bool DependencyConfiguration::lineHasAlias(string line) const {
93  string::size_type offset = line.find(m_aliasSeparator);
94  return offset != string::npos;
95 }
96 
98  string::size_type offset = line.find(m_aliasSeparator);
99  const string distantFilename = line.substr(0, offset);
100  const string localFilename = line.substr(offset + 1);
101  const path distantPath = m_distantRoot / distantFilename;
102  const path localPath = m_localRoot / localFilename;
103  m_fileMap[localPath] = distantPath;
104 }
105 
107  const path distantPath = m_distantRoot / line;
108  const path localPath = m_localRoot / line;
109  m_fileMap[localPath] = distantPath;
110 }
111 
112 } // namespace DataSync
113 } // namespace ElementsServices
T at(T... args)
DependencyConfiguration(path distantRoot, path localRoot, path configFile)
T emplace_back(T... args)
T find(T... args)
T getline(T... args)
Elements::Path::Item path
Definition: DataSyncUtils.h:39
ELEMENTS_API path confFilePath(path filename)
T size(T... args)
T substr(T... args)