DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
Path.cpp
Go to the documentation of this file.
1/*
2 * Path.cxx
3 * Test
4 *
5 * Created by Matthias Wiesmann on 09.02.05.
6 * Copyright 2005 CERN. All rights reserved.
7 *
8 */
9#include <sstream>
10#include <iostream>
11
12#include "okssystem/Path.hpp"
14
15const char OksSystem::Path::PATH_SEPARATOR = ':';
16
21
27 m_directories = other.m_directories;
28}
29
34OksSystem::Path::Path(const std::string &path_list) {
35 parse_path_list(path_list);
36} // Path
37
38OksSystem::Path::operator std::string() const {
39 return to_string();
40} // operator std::string()
41
42
43
49 m_directories.push_back(dir);
50} // add
51
52
57void OksSystem::Path::parse_path_list(const std::string &path_list) {
58 std::string rest = path_list;
59 while(! rest.empty()) {
60 std::string::size_type semi_colon = rest.find(PATH_SEPARATOR);
61 std::string name;
62
63 if(semi_colon==std::string::npos) {
64 name = rest;
65 rest.clear();
66 } else {
67 name = rest.substr(0,semi_colon);
68 rest = rest.substr(semi_colon+1);
69 }
70
71 if(!name.empty()) {
72 const OksSystem::File directory(name);
73 add(directory);
74 }
75 } // while
76} // parse_path_list
77
82void OksSystem::Path::write_to(std::ostream &stream) const {
83 bool first = true;
84 for(File::file_list_t::const_iterator pos = m_directories.begin(); pos!=m_directories.end();pos++) {
85 if (!first) {
86 stream << PATH_SEPARATOR;
87 } else {
88 first = false;
89 }
90 stream << pos->full_name();
91 } // for
92} // write_to
93
99std::string OksSystem::Path::to_string() const {
100 std::ostringstream stream;
101 write_to(stream);
102 return stream.str();
103} // to_string
104
111OksSystem::File OksSystem::Path::which(const std::string &name) const {
112 for(File::file_list_t::const_iterator pos = m_directories.begin(); pos!=m_directories.end();pos++) {
113 File child = pos->child(name);
114 if (child.exists()) return child;
115 } // for
116 throw OksSystem::NotFoundIssue( ERS_HERE, name.c_str() );
117} // which
118
124std::ostream& operator<<(std::ostream& stream, const OksSystem::Path& path) {
125 path.write_to(stream);
126 return stream;
127} // operator<<
128
129
std::ostream & operator<<(std::ostream &stream, const OksSystem::File &file)
Definition File.cpp:852
#define ERS_HERE
Wrapper for file operations.
Definition File.hpp:32
bool exists() const
does the file exist *‍/
Definition File.cpp:472
OksSystem::File child(const std::string &name) const
named child of the current directory *‍/
Definition File.cpp:450
Path list handling mechanism.
Definition Path.hpp:25
void parse_path_list(const std::string &path_list)
parse string containing path
Definition Path.cpp:57
OksSystem::File which(const std::string &name) const
resolve a name in the path
Definition Path.cpp:111
std::string to_string() const
converts path into a string
Definition Path.cpp:99
void add(const OksSystem::File &dir)
add a directory to the path
Definition Path.cpp:48
File::file_list_t m_directories
list of directories
Definition Path.hpp:28
void write_to(std::ostream &stream) const
displays the path in a stream
Definition Path.cpp:82
static const char PATH_SEPARATOR
char used as separator in strings (semi-colon)
Definition Path.hpp:31