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<string>& configuration_files_directories)
31  : configuration_files_directories_(configuration_files_directories) {
32  configuration_files_directories_.push_back(kConfigurationFilesDirectory);
33 }
34 
35 string ConfigurationFileResolver::GetFullPathOrDie(const string& basename) {
36  for (const auto& path : configuration_files_directories_) {
37  const string filename = path + "/" + basename;
38  std::ifstream stream(filename.c_str());
39  if (stream.good()) {
40  LOG(INFO) << "Found '" << filename << "' for '" << basename << "'.";
41  return filename;
42  }
43  }
44  LOG(FATAL) << "File '" << basename << "' was not found.";
45 }
46 
47 string ConfigurationFileResolver::GetFileContentOrDie(const string& basename) {
48  const string filename = GetFullPathOrDie(basename);
49  std::ifstream stream(filename.c_str());
50  return string((std::istreambuf_iterator<char>(stream)),
51  std::istreambuf_iterator<char>());
52 }
53 
54 } // namespace common
55 } // namespace cartographer
ConfigurationFileResolver(const std::vector< string > &configuration_files_directories)
string GetFullPathOrDie(const string &basename) override
string GetFileContentOrDie(const string &basename) override


cartographer
Author(s):
autogenerated on Wed Jun 5 2019 21:57:58