NASA Astrobee Robot Software  0.19.1
Flight software for the Astrobee robots operating inside the International Space Station.
utils.h
Go to the documentation of this file.
1 /* Copyright (c) 2017, United States Government, as represented by the
2  * Administrator of the National Aeronautics and Space Administration.
3  *
4  * All rights reserved.
5  *
6  * The Astrobee platform is licensed under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with the
8  * License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15  * License for the specific language governing permissions and limitations
16  * under the License.
17  */
18 
19 #ifndef FF_COMMON_UTILS_H_
20 #define FF_COMMON_UTILS_H_
21 
22 #include <string>
23 #include <vector>
24 #include <algorithm>
25 #include <numeric>
26 
27 namespace ff_common {
28 
29  // List all files in given directory with given extension, e.g.,
30  // 'jpg'. The directory name is pre-pended to the file names, that
31  // is, the output is in the form dir/file.jpg. Sort the list
32  // alphabetically.
33  void ListFiles(std::string const& input_dir, std::string const& ext,
34  std::vector<std::string> * files);
35  void PrintProgressBar(FILE* stream, float progress);
36 
37  // Replace in given string
38  std::string ReplaceInStr(std::string const& in_str,
39  std::string const& before,
40  std::string const& after);
41 
42  // A little utility for finding the permutation which sorts
43  // a vector in decreasing order by value.
44  template<class T>
45  struct sorter {
46  const std::vector<T> &values;
47  explicit sorter(const std::vector<T> &v) : values(v) {}
48  bool operator()(int a, int b) { return values[a] > values[b]; }
49  };
50  template<class T> std::vector<int> rv_order(const std::vector<T> &values) {
51  std::vector<int> rv(values.size());
52  std::iota(rv.begin(), rv.end(), 0);
53  std::sort(rv.begin(), rv.end(), sorter<T>(values));
54  return rv;
55  }
56 
57  std::string dirname(std::string const& file);
58  std::string basename(std::string const& file);
59  std::string file_extension(std::string const& file);
60 
61  // Extract values from a string to a vector of doubles
62  void parseStr(std::string const& str, std::vector<double> & values);
63 } // namespace ff_common
64 
65 #endif // FF_COMMON_UTILS_H_
ff_common::basename
std::string basename(std::string const &file)
Definition: utils.cc:92
ros_graph_vio
Definition: imu_bias_initializer.h:31
ff_common::sorter
Definition: utils.h:45
ff_common::sorter::sorter
sorter(const std::vector< T > &v)
Definition: utils.h:47
ff_common
Definition: init.h:29
ff_common::dirname
std::string dirname(std::string const &file)
Definition: utils.cc:85
ff_common::ReplaceInStr
std::string ReplaceInStr(std::string const &in_str, std::string const &before, std::string const &after)
Definition: utils.cc:74
ff_common::sorter::values
const std::vector< T > & values
Definition: utils.h:46
ff_common::rv_order
std::vector< int > rv_order(const std::vector< T > &values)
Definition: utils.h:50
ff_common::ListFiles
void ListFiles(std::string const &input_dir, std::string const &ext, std::vector< std::string > *files)
Definition: utils.cc:31
ff_common::sorter::operator()
bool operator()(int a, int b)
Definition: utils.h:48
ff_common::file_extension
std::string file_extension(std::string const &file)
Definition: utils.cc:101
ff_common::parseStr
void parseStr(std::string const &str, std::vector< double > &values)
Definition: utils.cc:111
ff_common::PrintProgressBar
void PrintProgressBar(FILE *stream, float progress)
Definition: utils.cc:57