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 <iostream>
15#include <sstream>
16
17#include "okssystem/Path.hpp"
19
20const char OksSystem::Path::PATH_SEPARATOR = ':';
21
24
26
30
32{
34}
35
39
40OksSystem::Path::Path(const std::string& path_list)
41{
42 parse_path_list(path_list);
43} // Path
44
45OksSystem::Path::operator std::string() const
46{
47 return to_string();
48} // operator std::string()
49
53
54void
56{
57 m_directories.push_back(dir);
58} // add
59
63
64void
65OksSystem::Path::parse_path_list(const std::string& path_list)
66{
67 std::string rest = path_list;
68 while (!rest.empty()) {
69 std::string::size_type semi_colon = rest.find(PATH_SEPARATOR);
70 std::string name;
71
72 if (semi_colon == std::string::npos) {
73 name = rest;
74 rest.clear();
75 } else {
76 name = rest.substr(0, semi_colon);
77 rest = rest.substr(semi_colon + 1);
78 }
79
80 if (!name.empty()) {
81 const OksSystem::File directory(name);
82 add(directory);
83 }
84 } // while
85} // parse_path_list
86
90
91void
92OksSystem::Path::write_to(std::ostream& stream) const
93{
94 bool first = true;
95 for (File::file_list_t::const_iterator pos = m_directories.begin(); pos != m_directories.end(); pos++) {
96 if (!first) {
97 stream << PATH_SEPARATOR;
98 } else {
99 first = false;
100 }
101 stream << pos->full_name();
102 } // for
103} // write_to
104
109
110std::string
112{
113 std::ostringstream stream;
114 write_to(stream);
115 return stream.str();
116} // to_string
117
123
125OksSystem::Path::which(const std::string& name) const
126{
127 for (File::file_list_t::const_iterator pos = m_directories.begin(); pos != m_directories.end(); pos++) {
128 File child = pos->child(name);
129 if (child.exists())
130 return child;
131 } // for
132 throw OksSystem::NotFoundIssue(ERS_HERE, name.c_str());
133} // which
134
139
140std::ostream&
141operator<<(std::ostream& stream, const OksSystem::Path& path)
142{
143 path.write_to(stream);
144 return stream;
145} // operator<<
#define ERS_HERE
void operator<<(TraceStreamer &x, const ers::Issue &r)
Definition Logger.hxx:128
Wrapper for file operations.
Definition File.hpp:38
bool exists() const
does the file exist *‍/
Definition File.cpp:526
OksSystem::File child(const std::string &name) const
named child of the current directory *‍/
Definition File.cpp:501
Path list handling mechanism.
Definition Path.hpp:30
void parse_path_list(const std::string &path_list)
parse string containing path
Definition Path.cpp:65
OksSystem::File which(const std::string &name) const
resolve a name in the path
Definition Path.cpp:125
std::string to_string() const
converts path into a string
Definition Path.cpp:111
void add(const OksSystem::File &dir)
add a directory to the path
Definition Path.cpp:55
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:92
static const char PATH_SEPARATOR
char used as separator in strings (semi-colon)
Definition Path.hpp:36