LDMX Software
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
conditions::StringCSVLoader Class Reference

Specialization of the GeneralCSVLoader for loading from a string. More...

#include <GeneralCSVLoader.h>

Public Member Functions

 StringCSVLoader (const std::string &source, const std::string lineseparators="\n")
 Constructor.
 
- Public Member Functions inherited from conditions::GeneralCSVLoader
virtual ~GeneralCSVLoader ()
 Destructor.
 
std::vector< std::string > columnNames () const
 Get the column names.
 
bool nextRow ()
 Advance to next row if possible.
 
const std::string & get (const std::string &colname, bool ignore_case=true) const
 Get the value for the given column in the current row.
 
int getInteger (const std::string &colname, bool ignore_case=true) const
 Get the value for the given column in the current row as an integer.
 

Protected Member Functions

virtual std::string getNextLine ()
 Get the next line, returning an empty string when there is no further data.
 

Private Attributes

const std::string & source_
 The original string.
 
const std::string linesep_
 The separators.
 
std::string::size_type rowBegin_
 The current start and end pointers.
 
std::string::size_type rowEnd_
 

Detailed Description

Specialization of the GeneralCSVLoader for loading from a string.

Definition at line 57 of file GeneralCSVLoader.h.

Constructor & Destructor Documentation

◆ StringCSVLoader()

conditions::StringCSVLoader::StringCSVLoader ( const std::string &  source,
const std::string  lineseparators = "\n" 
)

Constructor.

Definition at line 68 of file GeneralCSVLoader.cxx.

70 : source_{source}, linesep_{lineseparators}, rowBegin_{0}, rowEnd_{0} {
72}
const std::string & source_
The original string.
std::string::size_type rowBegin_
The current start and end pointers.
const std::string linesep_
The separators.
virtual std::string getNextLine()
Get the next line, returning an empty string when there is no further data.

References getNextLine().

Member Function Documentation

◆ getNextLine()

std::string conditions::StringCSVLoader::getNextLine ( )
protectedvirtual

Get the next line, returning an empty string when there is no further data.

Implements conditions::GeneralCSVLoader.

Definition at line 74 of file GeneralCSVLoader.cxx.

74 {
75 std::string retval;
76 if (rowBegin_ != rowEnd_) {
77 if (rowEnd_ == std::string::npos) {
78 retval = source_.substr(rowBegin_, rowEnd_);
79 } else {
80 retval = source_.substr(rowBegin_, rowEnd_ - rowBegin_);
81 }
82 }
83 // now we look for the follow on.
84 // find the first non-end-of-line character
85 rowBegin_ = source_.find_first_not_of(linesep_, rowEnd_);
86 if (rowBegin_ != std::string::npos) {
87 rowEnd_ = source_.find_first_of(linesep_, rowBegin_);
88 } else {
89 rowEnd_ = std::string::npos;
90 }
91 return retval;
92}

References linesep_, rowBegin_, and source_.

Referenced by StringCSVLoader().

Member Data Documentation

◆ linesep_

const std::string conditions::StringCSVLoader::linesep_
private

The separators.

Definition at line 76 of file GeneralCSVLoader.h.

Referenced by getNextLine().

◆ rowBegin_

std::string::size_type conditions::StringCSVLoader::rowBegin_
private

The current start and end pointers.

Definition at line 80 of file GeneralCSVLoader.h.

Referenced by getNextLine().

◆ rowEnd_

std::string::size_type conditions::StringCSVLoader::rowEnd_
private

Definition at line 80 of file GeneralCSVLoader.h.

◆ source_

const std::string& conditions::StringCSVLoader::source_
private

The original string.

Definition at line 72 of file GeneralCSVLoader.h.

Referenced by getNextLine().


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