DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
OksSystem::Path Class Reference

Path list handling mechanism. More...

#include <Path.hpp>

Public Member Functions

 Path ()
 Path (const Path &other)
 Path (const std::string &path_list)
 contructor with a string
 operator std::string () const
void add (const OksSystem::File &dir)
 add a directory to the path
OksSystem::File which (const std::string &name) const
 resolve a name in the path
void write_to (std::ostream &stream) const
 displays the path in a stream
std::string to_string () const
 converts path into a string

Static Public Attributes

static const char PATH_SEPARATOR = ':'
 char used as separator in strings (semi-colon)

Protected Member Functions

void parse_path_list (const std::string &path_list)
 parse string containing path

Protected Attributes

File::file_list_t m_directories
 list of directories

Detailed Description

Path list handling mechanism.

This class represents an ordered set of directories. The main goal of this class is to proved tools to find a file in this set.

Author
Matthias Wiesmann
Version
1.0

Definition at line 29 of file Path.hpp.

Constructor & Destructor Documentation

◆ Path() [1/3]

OksSystem::Path::Path ( )

Empty constructor

Definition at line 25 of file Path.cpp.

25{}

◆ Path() [2/3]

OksSystem::Path::Path ( const Path & other)

Copy constructor

Parameters
otherthe original object

Definition at line 31 of file Path.cpp.

32{
33 m_directories = other.m_directories;
34}
File::file_list_t m_directories
list of directories
Definition Path.hpp:33

◆ Path() [3/3]

OksSystem::Path::Path ( const std::string & path_list)

contructor with a string

Constructor

Parameters
path_liststring containing the list of directories

Definition at line 40 of file Path.cpp.

41{
42 parse_path_list(path_list);
43} // Path
void parse_path_list(const std::string &path_list)
parse string containing path
Definition Path.cpp:65

Member Function Documentation

◆ add()

void OksSystem::Path::add ( const OksSystem::File & dir)

add a directory to the path

Add a directory to the path

Parameters
dirthe file to add

Definition at line 55 of file Path.cpp.

56{
57 m_directories.push_back(dir);
58} // add

◆ operator std::string()

OksSystem::Path::operator std::string ( ) const

Definition at line 45 of file Path.cpp.

46{
47 return to_string();
48} // operator std::string()
std::string to_string() const
converts path into a string
Definition Path.cpp:111

◆ parse_path_list()

void OksSystem::Path::parse_path_list ( const std::string & path_list)
protected

parse string containing path

Parses a string containing the path separated by semi-colons.

Parameters
path_listthe path

Definition at line 65 of file Path.cpp.

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
void add(const OksSystem::File &dir)
add a directory to the path
Definition Path.cpp:55
static const char PATH_SEPARATOR
char used as separator in strings (semi-colon)
Definition Path.hpp:36

◆ to_string()

std::string OksSystem::Path::to_string ( ) const

converts path into a string

Prints the path into a string

Returns
string containing description
See also
write_to()

Definition at line 111 of file Path.cpp.

112{
113 std::ostringstream stream;
114 write_to(stream);
115 return stream.str();
116} // to_string
void write_to(std::ostream &stream) const
displays the path in a stream
Definition Path.cpp:92

◆ which()

OksSystem::File OksSystem::Path::which ( const std::string & name) const

resolve a name in the path

Finds the first occurence of a named file in the path.

Parameters
namethe name of the file to search for
Returns
a File object representing the file
Exceptions
EntityNotFoundIssueif no matching file is found

Definition at line 125 of file Path.cpp.

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
#define ERS_HERE

◆ write_to()

void OksSystem::Path::write_to ( std::ostream & stream) const

displays the path in a stream

Prints the path into a stream

Parameters
streamdestination stream

Definition at line 92 of file Path.cpp.

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

Member Data Documentation

◆ m_directories

File::file_list_t OksSystem::Path::m_directories
protected

list of directories

Definition at line 33 of file Path.hpp.

◆ PATH_SEPARATOR

const char OksSystem::Path::PATH_SEPARATOR = ':'
static

char used as separator in strings (semi-colon)

Definition at line 36 of file Path.hpp.


The documentation for this class was generated from the following files: