DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
okssystem
src
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
"
18
#include "
okssystem/exceptions.hpp
"
19
20
const
char
OksSystem::Path::PATH_SEPARATOR
=
':'
;
21
24
25
OksSystem::Path::Path
() {}
26
30
31
OksSystem::Path::Path
(
const
Path
& other)
32
{
33
m_directories
= other.
m_directories
;
34
}
35
39
40
OksSystem::Path::Path
(
const
std::string& path_list)
41
{
42
parse_path_list
(path_list);
43
}
// Path
44
45
OksSystem::Path::operator std::string()
const
46
{
47
return
to_string
();
48
}
// operator std::string()
49
53
54
void
55
OksSystem::Path::add
(
const
OksSystem::File
& dir)
56
{
57
m_directories
.push_back(dir);
58
}
// add
59
63
64
void
65
OksSystem::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
91
void
92
OksSystem::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
110
std::string
111
OksSystem::Path::to_string
()
const
112
{
113
std::ostringstream stream;
114
write_to
(stream);
115
return
stream.str();
116
}
// to_string
117
123
124
OksSystem::File
125
OksSystem::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
140
std::ostream&
141
operator<<
(std::ostream& stream,
const
OksSystem::Path
& path)
142
{
143
path.
write_to
(stream);
144
return
stream;
145
}
// operator<<
ERS_HERE
#define ERS_HERE
Definition
LocalContext.hpp:127
operator<<
void operator<<(TraceStreamer &x, const ers::Issue &r)
Definition
Logger.hxx:128
Path.hpp
OksSystem::File
Wrapper for file operations.
Definition
File.hpp:38
OksSystem::File::exists
bool exists() const
does the file exist */
Definition
File.cpp:526
OksSystem::File::child
OksSystem::File child(const std::string &name) const
named child of the current directory */
Definition
File.cpp:501
OksSystem::Path
Path list handling mechanism.
Definition
Path.hpp:30
OksSystem::Path::parse_path_list
void parse_path_list(const std::string &path_list)
parse string containing path
Definition
Path.cpp:65
OksSystem::Path::which
OksSystem::File which(const std::string &name) const
resolve a name in the path
Definition
Path.cpp:125
OksSystem::Path::to_string
std::string to_string() const
converts path into a string
Definition
Path.cpp:111
OksSystem::Path::add
void add(const OksSystem::File &dir)
add a directory to the path
Definition
Path.cpp:55
OksSystem::Path::m_directories
File::file_list_t m_directories
list of directories
Definition
Path.hpp:33
OksSystem::Path::Path
Path()
Definition
Path.cpp:25
OksSystem::Path::write_to
void write_to(std::ostream &stream) const
displays the path in a stream
Definition
Path.cpp:92
OksSystem::Path::PATH_SEPARATOR
static const char PATH_SEPARATOR
char used as separator in strings (semi-colon)
Definition
Path.hpp:36
exceptions.hpp
Generated on
for DUNE-DAQ by
1.18.0