configuration_file_resolver.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2016 The Cartographer Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #include <fstream>
20 #include <iostream>
21 #include <streambuf>
22 
23 #include "cartographer/common/config.h"
24 #include "glog/logging.h"
25 
26 namespace cartographer {
27 namespace common {
28 
30  const std::vector<std::string>& configuration_files_directories)
31  : configuration_files_directories_(configuration_files_directories) {
32  configuration_files_directories_.push_back(kConfigurationFilesDirectory);
33 }
34 
36  const std::string& basename) {
37  for (const auto& path : configuration_files_directories_) {
38  const std::string filename = path + "/" + basename;
39  std::ifstream stream(filename.c_str());
40  if (stream.good()) {
41  LOG(INFO) << "Found '" << filename << "' for '" << basename << "'.";
42  return filename;
43  }
44  }
45  LOG(FATAL) << "File '" << basename << "' was not found.";
46 }
47 
49  const std::string& basename) {
50  const std::string filename = GetFullPathOrDie(basename);
51  std::ifstream stream(filename.c_str());
52  return std::string((std::istreambuf_iterator<char>(stream)),
53  std::istreambuf_iterator<char>());
54 }
55 
56 } // namespace common
57 } // namespace cartographer
ConfigurationFileResolver(const std::vector< std::string > &configuration_files_directories)
std::string GetFileContentOrDie(const std::string &basename) override
std::string GetFullPathOrDie(const std::string &basename) override


cartographer
Author(s): The Cartographer Authors
autogenerated on Mon Feb 28 2022 22:00:58