resolver.h
Go to the documentation of this file.
1 /*
2  resolver.h -- A simple class for cross-platform path resolution
3 
4  Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
5 
6  All rights reserved. Use of this source code is governed by a
7  BSD-style license that can be found in the LICENSE file.
8 */
9 
10 #pragma once
11 
12 #include "path.h"
13 
14 NAMESPACE_BEGIN(filesystem)
15 
16 
23 class resolver {
24 public:
25  typedef std::vector<path>::iterator iterator;
26  typedef std::vector<path>::const_iterator const_iterator;
27 
29  m_paths.push_back(path::getcwd());
30  }
31 
32  size_t size() const { return m_paths.size(); }
33 
34  iterator begin() { return m_paths.begin(); }
35  iterator end() { return m_paths.end(); }
36 
37  const_iterator begin() const { return m_paths.begin(); }
38  const_iterator end() const { return m_paths.end(); }
39 
40  void erase(iterator it) { m_paths.erase(it); }
41 
42  void prepend(const path &path) { m_paths.insert(m_paths.begin(), path); }
43  void append(const path &path) { m_paths.push_back(path); }
44  const path &operator[](size_t index) const { return m_paths[index]; }
45  path &operator[](size_t index) { return m_paths[index]; }
46 
47  path resolve(const path &value) const {
48  for (const_iterator it = m_paths.begin(); it != m_paths.end(); ++it) {
49  path combined = *it / value;
50  if (combined.exists())
51  return combined;
52  }
53  return value;
54  }
55 
56  friend std::ostream &operator<<(std::ostream &os, const resolver &r) {
57  os << "resolver[" << std::endl;
58  for (size_t i = 0; i < r.m_paths.size(); ++i) {
59  os << " \"" << r.m_paths[i] << "\"";
60  if (i + 1 < r.m_paths.size())
61  os << ",";
62  os << std::endl;
63  }
64  os << "]";
65  return os;
66  }
67 
68 private:
69  std::vector<path> m_paths;
70 };
71 
72 NAMESPACE_END(filesystem)
void append(const path &path)
Definition: resolver.h:43
#define NAMESPACE_END(name)
Definition: fwd.h:16
#define NAMESPACE_BEGIN(name)
Definition: fwd.h:13
static path getcwd()
Definition: path.h:266
const_iterator begin() const
Definition: resolver.h:37
resolver()
Definition: resolver.h:28
Simple class for resolving paths on Linux/Windows/Mac OS.
Definition: resolver.h:23
std::vector< path >::iterator iterator
Definition: resolver.h:25
path resolve(const path &value) const
Definition: resolver.h:47
const path & operator[](size_t index) const
Definition: resolver.h:44
iterator end()
Definition: resolver.h:35
bool exists() const
Definition: path.h:93
std::vector< path > m_paths
Definition: resolver.h:69
std::vector< path >::const_iterator const_iterator
Definition: resolver.h:26
friend std::ostream & operator<<(std::ostream &os, const resolver &r)
Definition: resolver.h:56
iterator begin()
Definition: resolver.h:34
path & operator[](size_t index)
Definition: resolver.h:45
void erase(iterator it)
Definition: resolver.h:40
const_iterator end() const
Definition: resolver.h:38
Simple class for manipulating paths on Linux/Windows/Mac OS.
Definition: path.h:42
void prepend(const path &path)
Definition: resolver.h:42
size_t size() const
Definition: resolver.h:32


behaviortree_cpp
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Sat Feb 2 2019 04:01:53