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 <sstream>
15
#include <iostream>
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
m_directories
= other.
m_directories
;
33
}
34
38
39
OksSystem::Path::Path
(
const
std::string &path_list) {
40
parse_path_list
(path_list);
41
}
// Path
42
43
OksSystem::Path::operator std::string()
const
{
44
return
to_string
();
45
}
// operator std::string()
46
47
48
52
53
void
OksSystem::Path::add
(
const
OksSystem::File
&dir) {
54
m_directories
.push_back(dir);
55
}
// add
56
57
61
62
void
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
87
void
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
104
std::string
OksSystem::Path::to_string
()
const
{
105
std::ostringstream stream;
106
write_to
(stream);
107
return
stream.str();
108
}
// to_string
109
115
116
OksSystem::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
129
std::ostream&
operator<<
(std::ostream& stream,
const
OksSystem::Path
& path) {
130
path.
write_to
(stream);
131
return
stream;
132
}
// operator<<
133
134
ERS_HERE
#define ERS_HERE
Definition
LocalContext.hpp:141
operator<<
void operator<<(TraceStreamer &x, const ers::Issue &r)
Definition
Logger.hxx:102
Path.hpp
OksSystem::File
Wrapper for file operations.
Definition
File.hpp:37
OksSystem::File::exists
bool exists() const
does the file exist */
Definition
File.cpp:477
OksSystem::File::child
OksSystem::File child(const std::string &name) const
named child of the current directory */
Definition
File.cpp:455
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:62
OksSystem::Path::which
OksSystem::File which(const std::string &name) const
resolve a name in the path
Definition
Path.cpp:116
OksSystem::Path::to_string
std::string to_string() const
converts path into a string
Definition
Path.cpp:104
OksSystem::Path::add
void add(const OksSystem::File &dir)
add a directory to the path
Definition
Path.cpp:53
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:87
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.17.0