DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
Path.cpp
Go to the documentation of this file.
1// DUNE DAQ modification notice:
2// This file has been modified from the original ATLAS system source for the DUNE DAQ project.
3// Fork baseline commit: system-00-00-20 (2020-09-25).
4// Renamed since fork: yes (from src/Path.cxx to src/Path.cpp).
5
6/*
7 * Path.cxx
8 * Test
9 *
10 * Created by Matthias Wiesmann on 09.02.05.
11 * Copyright 2005 CERN. All rights reserved.
12 *
13 */
14#include <sstream>
15#include <iostream>
16
17#include "okssystem/Path.hpp"
19
20const char OksSystem::Path::PATH_SEPARATOR = ':';
21
24
26
30
33}
34
38
39OksSystem::Path::Path(const std::string &path_list) {
40 parse_path_list(path_list);
41} // Path
42
43OksSystem::Path::operator std::string() const {
44 return to_string();
45} // operator std::string()
46
47
48
52
54 m_directories.push_back(dir);
55} // add
56
57
61
62void OksSystem::Path::parse_path_list(const std::string &path_list) {
63 std::string rest = path_list;
64 while(! rest.empty()) {
65 std::string::size_type semi_colon = rest.find(PATH_SEPARATOR);
66 std::string name;
67
68 if(semi_colon==std::string::npos) {
69 name = rest;
70 rest.clear();
71 } else {
72 name = rest.substr(0,semi_colon);
73 rest = rest.substr(semi_colon+1);
74 }
75
76 if(!name.empty()) {
77 const OksSystem::File directory(name);
78 add(directory);
79 }
80 } // while
81} // parse_path_list
82
86
87void OksSystem::Path::write_to(std::ostream &stream) const {
88 bool first = true;
89 for(File::file_list_t::const_iterator pos = m_directories.begin(); pos!=m_directories.end();pos++) {
90 if (!first) {
91 stream << PATH_SEPARATOR;
92 } else {
93 first = false;
94 }
95 stream << pos->full_name();
96 } // for
97} // write_to
98
103
104std::string OksSystem::Path::to_string() const {
105 std::ostringstream stream;
106 write_to(stream);
107 return stream.str();
108} // to_string
109
115
116OksSystem::File OksSystem::Path::which(const std::string &name) const {
117 for(File::file_list_t::const_iterator pos = m_directories.begin(); pos!=m_directories.end();pos++) {
118 File child = pos->child(name);
119 if (child.exists()) return child;
120 } // for
121 throw OksSystem::NotFoundIssue( ERS_HERE, name.c_str() );
122} // which
123
128
129std::ostream& operator<<(std::ostream& stream, const OksSystem::Path& path) {
130 path.write_to(stream);
131 return stream;
132} // operator<<
133
134
#define ERS_HERE
void operator<<(TraceStreamer &x, const ers::Issue &r)
Definition Logger.hxx:102
Wrapper for file operations.
Definition File.hpp:37
bool exists() const
does the file exist *‍/
Definition File.cpp:477
OksSystem::File child(const std::string &name) const
named child of the current directory *‍/
Definition File.cpp:455
Path list handling mechanism.
Definition Path.hpp:30
void parse_path_list(const std::string &path_list)
parse string containing path
Definition Path.cpp:62
OksSystem::File which(const std::string &name) const
resolve a name in the path
Definition Path.cpp:116
std::string to_string() const
converts path into a string
Definition Path.cpp:104
void add(const OksSystem::File &dir)
add a directory to the path
Definition Path.cpp:53
File::file_list_t m_directories
list of directories
Definition Path.hpp:33
void write_to(std::ostream &stream) const
displays the path in a stream
Definition Path.cpp:87
static const char PATH_SEPARATOR
char used as separator in strings (semi-colon)
Definition Path.hpp:36