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 30 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.

31 {
32 m_directories = other.m_directories;
33}
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 39 of file Path.cpp.

39 {
40 parse_path_list(path_list);
41} // Path
void parse_path_list(const std::string &path_list)
parse string containing path
Definition Path.cpp:62

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 53 of file Path.cpp.

53 {
54 m_directories.push_back(dir);
55} // add

◆ operator std::string()

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

Definition at line 43 of file Path.cpp.

43 {
44 return to_string();
45} // operator std::string()
std::string to_string() const
converts path into a string
Definition Path.cpp:104

◆ 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 62 of file Path.cpp.

62 {
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
void add(const OksSystem::File &dir)
add a directory to the path
Definition Path.cpp:53
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 104 of file Path.cpp.

104 {
105 std::ostringstream stream;
106 write_to(stream);
107 return stream.str();
108} // to_string
void write_to(std::ostream &stream) const
displays the path in a stream
Definition Path.cpp:87

◆ 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 116 of file Path.cpp.

116 {
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
#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 87 of file Path.cpp.

87 {
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

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: