Elements  6.2
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 <map>
21 #include <string>
22 #include <vector>
23 
25 
26 namespace Elements {
27 inline namespace Services {
28 namespace DataSync {
29 
30 using std::string;
31 using std::vector;
32 
34  : m_aliasSeparator('\t'), m_distantRoot(distantRoot), m_localRoot(localRoot), m_fileMap() {
35  parseConfigurationFile(configFile);
36 }
37 
39  return m_fileMap;
40 }
41 
43  return m_fileMap.at(localFile); // @TODO error handling
44 }
45 
47  return m_fileMap.size();
48 }
49 
51  vector<path> distant_paths;
52  for (const auto& item : m_fileMap) {
53  distant_paths.emplace_back(item.second);
54  }
55  return distant_paths;
56 }
57 
59  vector<path> local_paths;
60  for (const auto& item : m_fileMap) {
61  local_paths.emplace_back(item.first);
62  }
63  return local_paths;
64 }
65 
67  path abs_path = confFilePath(filename);
68  std::ifstream inputStream(abs_path.c_str());
69  string line;
70  while (std::getline(inputStream, line)) {
72  }
73 }
74 
76  if (lineHasAlias(line)) {
77  parseLineWithAlias(line);
78  } else {
80  }
81 }
82 
84  return m_aliasSeparator;
85 }
86 
87 bool DependencyConfiguration::lineHasAlias(string line) const {
88  string::size_type offset = line.find(m_aliasSeparator);
89  return offset != string::npos;
90 }
91 
93  string::size_type offset = line.find(m_aliasSeparator);
94  const string distantFilename = line.substr(0, offset);
95  const string localFilename = line.substr(offset + 1);
96  const path distantPath = m_distantRoot / distantFilename;
97  const path localPath = m_localRoot / localFilename;
98  m_fileMap[localPath] = distantPath;
99 }
100 
102  const path distantPath = m_distantRoot / line;
103  const path localPath = m_localRoot / line;
104  m_fileMap[localPath] = distantPath;
105 }
106 
107 } // namespace DataSync
108 } // namespace Services
109 } // namespace Elements
Elements::Services::DataSync::DependencyConfiguration::parseLineWithoutAlias
void parseLineWithoutAlias(std::string line)
Definition: DependencyConfiguration.cpp:101
Elements::Services::DataSync::DependencyConfiguration::dependencyCount
size_t dependencyCount() const
Definition: DependencyConfiguration.cpp:46
std::string
STL class.
Elements::Services::DataSync::DependencyConfiguration::distantPaths
std::vector< path > distantPaths() const
Definition: DependencyConfiguration.cpp:50
Elements::Services::DataSync::DependencyConfiguration::distantPathOf
path distantPathOf(path localFile) const
Definition: DependencyConfiguration.cpp:42
Elements::Services::DataSync::DependencyConfiguration::DependencyConfiguration
DependencyConfiguration(path distantRoot, path localRoot, path configFile)
Definition: DependencyConfiguration.cpp:33
Elements::Services::DataSync::DependencyConfiguration::fileMap
std::map< path, path > fileMap() const
Definition: DependencyConfiguration.cpp:38
std::vector
STL class.
std::string::find
T find(T... args)
std::map::size
T size(T... args)
Elements::Services::DataSync::DependencyConfiguration::lineHasAlias
bool lineHasAlias(std::string line) const
Definition: DependencyConfiguration.cpp:87
Elements::Services::DataSync::DependencyConfiguration::m_aliasSeparator
char m_aliasSeparator
Definition: DependencyConfiguration.h:76
Elements::Services::DataSync::DependencyConfiguration::aliasSeparator
char aliasSeparator() const
Definition: DependencyConfiguration.cpp:83
std::map::at
T at(T... args)
Elements::Services::DataSync::DependencyConfiguration::m_localRoot
path m_localRoot
Definition: DependencyConfiguration.h:78
DependencyConfiguration.h
std::map< path, path >
Elements::Services::DataSync::DependencyConfiguration::parseLineWithAlias
void parseLineWithAlias(std::string line)
Definition: DependencyConfiguration.cpp:92
std::string::substr
T substr(T... args)
std::vector::emplace_back
T emplace_back(T... args)
Elements::Services::DataSync::DependencyConfiguration::parseConfigurationFile
void parseConfigurationFile(path filename)
Definition: DependencyConfiguration.cpp:66
Elements::Services::DataSync::DependencyConfiguration::parseConfigurationLine
void parseConfigurationLine(std::string line)
Definition: DependencyConfiguration.cpp:75
std::getline
T getline(T... args)
Elements::Services::DataSync::DependencyConfiguration::localPaths
std::vector< path > localPaths() const
Definition: DependencyConfiguration.cpp:58
Elements::Services::DataSync::DependencyConfiguration::m_fileMap
std::map< path, path > m_fileMap
Definition: DependencyConfiguration.h:79
Elements::Services::DataSync::confFilePath
ELEMENTS_API path confFilePath(path filename)
Definition: DataSyncUtils.cpp:39
Elements::Services::DataSync::DependencyConfiguration::m_distantRoot
path m_distantRoot
Definition: DependencyConfiguration.h:77
Elements
Definition: callBackExample.h:35
std::ifstream
STL class.
Elements::Services::DataSync::path
Path::Item path
importing the path item from ElementsKernel
Definition: DataSyncUtils.h:41