resolver.h
Go to the documentation of this file.
00001 /*
00002     resolver.h -- A simple class for cross-platform path resolution
00003 
00004     Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
00005 
00006     All rights reserved. Use of this source code is governed by a
00007     BSD-style license that can be found in the LICENSE file.
00008 */
00009 
00010 #pragma once
00011 
00012 #include "path.h"
00013 
00014 NAMESPACE_BEGIN(filesystem)
00015 
00016 
00023 class resolver {
00024 public:
00025     typedef std::vector<path>::iterator iterator;
00026     typedef std::vector<path>::const_iterator const_iterator;
00027 
00028     resolver() {
00029         m_paths.push_back(path::getcwd());
00030     }
00031 
00032     size_t size() const { return m_paths.size(); }
00033 
00034     iterator begin() { return m_paths.begin(); }
00035     iterator end()   { return m_paths.end(); }
00036 
00037     const_iterator begin() const { return m_paths.begin(); }
00038     const_iterator end()   const { return m_paths.end(); }
00039 
00040     void erase(iterator it) { m_paths.erase(it); }
00041 
00042     void prepend(const path &path) { m_paths.insert(m_paths.begin(), path); }
00043     void append(const path &path) { m_paths.push_back(path); }
00044     const path &operator[](size_t index) const { return m_paths[index]; }
00045     path &operator[](size_t index) { return m_paths[index]; }
00046 
00047     path resolve(const path &value) const {
00048         for (const_iterator it = m_paths.begin(); it != m_paths.end(); ++it) {
00049             path combined = *it / value;
00050             if (combined.exists())
00051                 return combined;
00052         }
00053         return value;
00054     }
00055 
00056     friend std::ostream &operator<<(std::ostream &os, const resolver &r) {
00057         os << "resolver[" << std::endl;
00058         for (size_t i = 0; i < r.m_paths.size(); ++i) {
00059             os << "  \"" << r.m_paths[i] << "\"";
00060             if (i + 1 < r.m_paths.size())
00061                 os << ",";
00062             os << std::endl;
00063         }
00064         os << "]";
00065         return os;
00066     }
00067 
00068 private:
00069     std::vector<path> m_paths;
00070 };
00071 
00072 NAMESPACE_END(filesystem)


behaviortree_cpp
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Sat Feb 2 2019 03:50:10