Loading...
Searching...
No Matches
PLMD::TokenizedLine Class Reference

This class abstracts the input line in tokens. More...

#include <TokenizedLine.h>

Classes

struct  presentAndFound
 

Public Types

using line = std::vector<std::string>
 
using mapType = std::map<std::string,line,std::less<void>>
 

Public Member Functions

 TokenizedLine (const std::vector< std::string > &)
 Initializer from a vector of strings (ideally the output of getWords)
 
 TokenizedLine (const_vectorIt begin, const_vectorIt end)
 Initializer from vector iterators.
 
 TokenizedLine (vectorIt begin, vectorIt end)
 Initializer from vector iterators.
 
std::string convertToString (bool alsoClear)
 return a plain string with the all the current KEY=value combinations, it is possible to clear the tokens after that
 
bool empty () const
 Returns true if the underlying container is empty.
 
std::string getKeyword (std::string_view key) const
 return a keyword and its argument
 
std::string getValue (std::string_view key, int rep=-1) const
 return the value of the asked key, "" otherwise;
 
std::string keyList (std::string_view sep=", ")
 returns the list of the keys:
 
template<typename T>
presentAndFound readAndRemove (std::string_view key, T &value, int rep=-1)
 Read a value from the tokens and remove it from the list.
 
bool readAndRemoveFlag (std::string_view key)
 return true if the flag is present and removes it from the tokens
 
template<typename T>
presentAndFound readAndRemoveVector (std::string_view key, std::vector< T > &value, int rep=-1)
 Read a list of values from the tokens and remove it from the list.
 
std::size_t size () const
 Return the size of the underlying container;.
 

Static Public Member Functions

static std::string_view replica (const line &, int rep=-1)
 

Private Types

using const_vectorIt = typename std::vector<std::string>::const_iterator
 
using vectorIt = typename std::vector<std::string>::iterator
 

Private Attributes

mapType tokens
 

Detailed Description

This class abstracts the input line in tokens.

The underlying container accelerates the lookup for the keywords ISSUE: In case of a vector keyword and the use of the '@replicas:' idiom: If the user wants to chante only the FIRS element of the vector with @replica the parse will interpret the whole string as a replica string There are no problem with @replicas: applied on other components:

  • {@replicas:{1,3,4},1,3} won't work (the result ideally is equivalent to "@replicas:{{1,1,3},{3,1,3},{4,1,3}}"
  • {1,@replicas:{1,3,4},3} will work (the result is equivalent to "@replicas:{{1,1,3},{1,3,3},{1,4,3}}"

Member Typedef Documentation

◆ const_vectorIt

using PLMD::TokenizedLine::const_vectorIt = typename std::vector<std::string>::const_iterator
private

◆ line

using PLMD::TokenizedLine::line = std::vector<std::string>

◆ mapType

using PLMD::TokenizedLine::mapType = std::map<std::string,line,std::less<void>>

◆ vectorIt

using PLMD::TokenizedLine::vectorIt = typename std::vector<std::string>::iterator
private

Constructor & Destructor Documentation

◆ TokenizedLine() [1/3]

PLMD::TokenizedLine::TokenizedLine ( vectorIt begin,
vectorIt end )

Initializer from vector iterators.

◆ TokenizedLine() [2/3]

PLMD::TokenizedLine::TokenizedLine ( const_vectorIt begin,
const_vectorIt end )

Initializer from vector iterators.

◆ TokenizedLine() [3/3]

PLMD::TokenizedLine::TokenizedLine ( const std::vector< std::string > & dataline)

Initializer from a vector of strings (ideally the output of getWords)

Member Function Documentation

◆ convertToString()

std::string PLMD::TokenizedLine::convertToString ( bool alsoClear)

return a plain string with the all the current KEY=value combinations, it is possible to clear the tokens after that

◆ empty()

bool PLMD::TokenizedLine::empty ( ) const

Returns true if the underlying container is empty.

◆ getKeyword()

std::string PLMD::TokenizedLine::getKeyword ( std::string_view key) const

return a keyword and its argument

◆ getValue()

std::string PLMD::TokenizedLine::getValue ( std::string_view key,
int rep = -1 ) const

return the value of the asked key, "" otherwise;

◆ keyList()

std::string PLMD::TokenizedLine::keyList ( std::string_view sep = ", ")

returns the list of the keys:

◆ readAndRemove()

template<typename T>
TokenizedLine::presentAndFound PLMD::TokenizedLine::readAndRemove ( std::string_view key,
T & value,
int rep = -1 )

Read a value from the tokens and remove it from the list.

◆ readAndRemoveFlag()

bool PLMD::TokenizedLine::readAndRemoveFlag ( std::string_view key)

return true if the flag is present and removes it from the tokens

◆ readAndRemoveVector()

template<typename T>
TokenizedLine::presentAndFound PLMD::TokenizedLine::readAndRemoveVector ( std::string_view key,
std::vector< T > & value,
int rep = -1 )

Read a list of values from the tokens and remove it from the list.

◆ replica()

std::string_view PLMD::TokenizedLine::replica ( const line & l,
int rep = -1 )
static

◆ size()

std::size_t PLMD::TokenizedLine::size ( ) const

Return the size of the underlying container;.

Member Data Documentation

◆ tokens

mapType PLMD::TokenizedLine::tokens
private

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