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 25 of file Path.hpp.

Constructor & Destructor Documentation

◆ Path() [1/3]

OksSystem::Path::Path ( )

Empty constructor

Definition at line 20 of file Path.cpp.

20{}

◆ Path() [2/3]

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

Copy constructor

Parameters
otherthe original object

Definition at line 26 of file Path.cpp.

26 {
27 m_directories = other.m_directories;
28}
File::file_list_t m_directories
list of directories
Definition Path.hpp:28

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

34 {
35 parse_path_list(path_list);
36} // Path
void parse_path_list(const std::string &path_list)
parse string containing path
Definition Path.cpp:57

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

48 {
49 m_directories.push_back(dir);
50} // add

◆ operator std::string()

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

Definition at line 38 of file Path.cpp.

38 {
39 return to_string();
40} // operator std::string()
std::string to_string() const
converts path into a string
Definition Path.cpp:99

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

57 {
58 std::string rest = path_list;
59 while(! rest.empty()) {
60 std::string::size_type semi_colon = rest.find(PATH_SEPARATOR);
61 std::string name;
62
63 if(semi_colon==std::string::npos) {
64 name = rest;
65 rest.clear();
66 } else {
67 name = rest.substr(0,semi_colon);
68 rest = rest.substr(semi_colon+1);
69 }
70
71 if(!name.empty()) {
72 const OksSystem::File directory(name);
73 add(directory);
74 }
75 } // while
76} // parse_path_list
Wrapper for file operations.
Definition File.hpp:32
void add(const OksSystem::File &dir)
add a directory to the path
Definition Path.cpp:48
static const char PATH_SEPARATOR
char used as separator in strings (semi-colon)
Definition Path.hpp:31

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

99 {
100 std::ostringstream stream;
101 write_to(stream);
102 return stream.str();
103} // to_string
void write_to(std::ostream &stream) const
displays the path in a stream
Definition Path.cpp:82

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

111 {
112 for(File::file_list_t::const_iterator pos = m_directories.begin(); pos!=m_directories.end();pos++) {
113 File child = pos->child(name);
114 if (child.exists()) return child;
115 } // for
116 throw OksSystem::NotFoundIssue( ERS_HERE, name.c_str() );
117} // 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 82 of file Path.cpp.

82 {
83 bool first = true;
84 for(File::file_list_t::const_iterator pos = m_directories.begin(); pos!=m_directories.end();pos++) {
85 if (!first) {
86 stream << PATH_SEPARATOR;
87 } else {
88 first = false;
89 }
90 stream << pos->full_name();
91 } // for
92} // write_to

Member Data Documentation

◆ m_directories

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

list of directories

Definition at line 28 of file Path.hpp.

◆ PATH_SEPARATOR

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

char used as separator in strings (semi-colon)

Definition at line 31 of file Path.hpp.


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