OpenMD  2.5
Molecular Dynamics in the Open
OpenMD::StringTokenizer Class Reference

The string tokenizer class allows an application to break a string into tokens The set of delimiters (the characters that separate tokens) may be specified either at creation time or on a per-token basis. An instance of StringTokenizer behaves in one of two ways, depending on whether it was created with the returnTokens flag having the value true or false. More...

#include <StringTokenizer.hpp>

Public Member Functions

 StringTokenizer (const std::string &str, const std::string &delim=" ;\\)
 
 StringTokenizer (std::string::const_iterator &first, std::string::const_iterator &last, const std::string &delim=" ;\\)
 
 StringTokenizer (const std::string &str, const std::string &delim, bool returnTokens)
 
int countTokens ()
 
bool hasMoreTokens ()
 
std::string nextToken ()
 
void skipToken ()
 
bool nextTokenAsBool ()
 
int nextTokenAsInt ()
 
float nextTokenAsFloat ()
 
RealType nextTokenAsDouble ()
 
std::string peekNextToken ()
 
const std::string & getDelimiters ()
 
const std::string & getOriginal ()
 
std::vector< std::string > getAllTokens ()
 
std::string getRemainingString ()
 

Private Member Functions

bool isDelimiter (const char c)
 
void convertFortranNumber (std::string &fortranNumber)
 

Private Attributes

std::string tokenString_
 
std::string delim_
 
bool returnTokens_
 
std::string::const_iterator currentPos_
 
std::string::const_iterator end_
 

Detailed Description

The string tokenizer class allows an application to break a string into tokens The set of delimiters (the characters that separate tokens) may be specified either at creation time or on a per-token basis. An instance of StringTokenizer behaves in one of two ways, depending on whether it was created with the returnTokens flag having the value true or false.

Definition at line 67 of file StringTokenizer.hpp.

Constructor & Destructor Documentation

◆ StringTokenizer() [1/3]

OpenMD::StringTokenizer::StringTokenizer ( const std::string &  str,
const std::string &  delim = " ;\t\n\r" 
)

Constructs a string tokenizer for the specified string. The characters in the delim argument are the delimiters for separating tokens. characters are skipped and only serve as separators between tokens.

Parameters
stra string to be parsed.
delimthe delimiters, default value is " ;\t\n\r".
Note
this is still a little bit java like implementation. Pure c++ one should use TokenIterator. Boost's tokenizer class is one of them

Definition at line 51 of file StringTokenizer.cpp.

◆ StringTokenizer() [2/3]

OpenMD::StringTokenizer::StringTokenizer ( std::string::const_iterator &  first,
std::string::const_iterator &  last,
const std::string &  delim = " ;\t\n\r" 
)

Constructs a string tokenizer for an iterator range [first, last). The characters in the delim argument are the delimiters for separating tokens. characters are skipped and only serve as separators between tokens.

Parameters
firstbegin iterator
lastend iterator
delimthe delimiters, default value is " ;\t\n\r".
Note
this is still a little bit java like implementation. Pure c++ one should use TokenIterator. Boost's tokenizer class is one of them

Definition at line 57 of file StringTokenizer.cpp.

◆ StringTokenizer() [3/3]

OpenMD::StringTokenizer::StringTokenizer ( const std::string &  str,
const std::string &  delim,
bool  returnTokens 
)

Constructs a string tokenizer for the specified string. The characters in the delim argument are the delimiters for separating tokens. If the returnTokens flag is true, then the delimiter characters are also returned as tokens. Each delimiter is returned as a string of length one. If the flag is false, the delimiter characters are skipped and only serve as separators between tokens.

Parameters
stra string to be parsed.
delimthe delimiters.
returnTokensflag indicating whether to return the delimiters as tokens.

Definition at line 64 of file StringTokenizer.cpp.

Member Function Documentation

◆ convertFortranNumber()

void OpenMD::StringTokenizer::convertFortranNumber ( std::string &  fortranNumber)
private

convert a fortran number to a c/c++ number

Definition at line 236 of file StringTokenizer.cpp.

Referenced by getOriginal(), nextTokenAsDouble(), and nextTokenAsFloat().

◆ countTokens()

int OpenMD::StringTokenizer::countTokens ( )

Calculates the number of times that this tokenizer's nextToken method can be called before it generates an exception.

Returns
the number of tokens remaining in the string using the current delimiter set.

Definition at line 75 of file StringTokenizer.cpp.

References currentPos_, end_, isDelimiter(), and returnTokens_.

Referenced by ParameterTraits< std::pair< int, int > >::convert(), ParameterTraits< std::vector< RealType > >::convert(), OpenMD::HydroProp::HydroProp(), OpenMD::SectionParser::isEndSection(), OpenMD::SectionParserManager::parse(), OpenMD::DumpReader::parseDumpLine(), OpenMD::RestReader::parseDumpLine(), OpenMD::EAMAtomTypesSectionParser::parseEAMArray(), OpenMD::EAMAtomTypesSectionParser::parseFuncflFile(), OpenMD::DirectionalAtomTypesSectionParser::parseLine(), OpenMD::LennardJonesAtomTypesSectionParser::parseLine(), OpenMD::GayBerneAtomTypesSectionParser::parseLine(), OpenMD::MultipoleAtomTypesSectionParser::parseLine(), OpenMD::BendTypesSectionParser::parseLine(), OpenMD::AtomTypesSectionParser::parseLine(), OpenMD::PolarizableAtomTypesSectionParser::parseLine(), OpenMD::BondTypesSectionParser::parseLine(), OpenMD::ChargeAtomTypesSectionParser::parseLine(), OpenMD::StickyAtomTypesSectionParser::parseLine(), OpenMD::BaseAtomTypesSectionParser::parseLine(), OpenMD::StickyPowerAtomTypesSectionParser::parseLine(), OpenMD::BendTypeParser::parseLine(), OpenMD::TorsionTypesSectionParser::parseLine(), OpenMD::BondTypeParser::parseLine(), OpenMD::InversionTypeParser::parseLine(), OpenMD::EAMAtomTypesSectionParser::parseLine(), OpenMD::ShapeAtomTypesSectionParser::parseLine(), OpenMD::TorsionTypeParser::parseLine(), OpenMD::SCAtomTypesSectionParser::parseLine(), OpenMD::FluctuatingChargeAtomTypesSectionParser::parseLine(), OpenMD::OptionSectionParser::parseLine(), OpenMD::NonBondedInteractionsSectionParser::parseLine(), OpenMD::InversionTypesSectionParser::parseLine(), OpenMD::MultipoleAtomTypesSectionParser::parseQuadrupole(), OpenMD::ShapeAtomTypesSectionParser::parseShapeFile(), and OpenMD::DumpReader::parseSiteLine().

◆ getAllTokens()

std::vector< std::string > OpenMD::StringTokenizer::getAllTokens ( )

Returns all of the tokens

Returns
all of the tokens

Definition at line 229 of file StringTokenizer.cpp.

References hasMoreTokens(), and nextToken().

Referenced by OpenMD::SimplePreprocessor::doPreprocess(), and getOriginal().

◆ getDelimiters()

const std::string& OpenMD::StringTokenizer::getDelimiters ( )
inline

Returns the current delimiter set of this string tokenizer

Returns
the current delimiter set

Definition at line 173 of file StringTokenizer.hpp.

References delim_.

◆ getOriginal()

const std::string& OpenMD::StringTokenizer::getOriginal ( )
inline

Returns the original string before tokenizing.

Returns
the original string before tokenizing

Definition at line 181 of file StringTokenizer.hpp.

References convertFortranNumber(), getAllTokens(), getRemainingString(), isDelimiter(), and tokenString_.

◆ getRemainingString()

std::string OpenMD::StringTokenizer::getRemainingString ( )

◆ hasMoreTokens()

◆ isDelimiter()

bool OpenMD::StringTokenizer::isDelimiter ( const char  c)
private

Test if character is in current delimiter set.

Parameters
ccharacter to be tested
Returns
true if character is in current delimiter set, flase otherwise.

Definition at line 71 of file StringTokenizer.cpp.

References delim_.

Referenced by countTokens(), getOriginal(), hasMoreTokens(), nextToken(), peekNextToken(), and skipToken().

◆ nextToken()

std::string OpenMD::StringTokenizer::nextToken ( void  )

Returns the next token from this string tokenizer.

Returns
the next token from this string tokenizer.
Exceptions
NoSuchElementExceptionif there are no more tokens in this tokenizer's string

Definition at line 127 of file StringTokenizer.cpp.

References currentPos_, end_, isDelimiter(), and returnTokens_.

Referenced by OpenMD::SimCreator::createSim(), getAllTokens(), OpenMD::HydroProp::HydroProp(), OpenMD::SectionParser::isEndSection(), OpenMD::NameFinder::match(), nextTokenAsBool(), nextTokenAsDouble(), nextTokenAsFloat(), nextTokenAsInt(), OpenMD::ContainsConstraint::operator()(), OpenMD::SectionParserManager::parse(), OpenMD::DumpReader::parseDumpLine(), OpenMD::RestReader::parseDumpLine(), OpenMD::EAMAtomTypesSectionParser::parseFuncflFile(), OpenMD::DirectionalAtomTypesSectionParser::parseLine(), OpenMD::GayBerneAtomTypesSectionParser::parseLine(), OpenMD::LennardJonesAtomTypesSectionParser::parseLine(), OpenMD::AtomTypesSectionParser::parseLine(), OpenMD::ChargeAtomTypesSectionParser::parseLine(), OpenMD::MultipoleAtomTypesSectionParser::parseLine(), OpenMD::PolarizableAtomTypesSectionParser::parseLine(), OpenMD::BendTypesSectionParser::parseLine(), OpenMD::BaseAtomTypesSectionParser::parseLine(), OpenMD::BondTypesSectionParser::parseLine(), OpenMD::StickyAtomTypesSectionParser::parseLine(), OpenMD::TorsionTypesSectionParser::parseLine(), OpenMD::BendTypeParser::parseLine(), OpenMD::StickyPowerAtomTypesSectionParser::parseLine(), OpenMD::InversionTypeParser::parseLine(), OpenMD::BondTypeParser::parseLine(), OpenMD::EAMAtomTypesSectionParser::parseLine(), OpenMD::TorsionTypeParser::parseLine(), OpenMD::ShapeAtomTypesSectionParser::parseLine(), OpenMD::SCAtomTypesSectionParser::parseLine(), OpenMD::FluctuatingChargeAtomTypesSectionParser::parseLine(), OpenMD::OptionSectionParser::parseLine(), OpenMD::NonBondedInteractionsSectionParser::parseLine(), OpenMD::InversionTypesSectionParser::parseLine(), OpenMD::RNEMD::parseOutputFileFormat(), OpenMD::ShapeAtomTypesSectionParser::parseShapeFile(), OpenMD::DumpReader::parseSiteLine(), OpenMD::Stats::parseStatFileFormat(), and OpenMD::DumpReader::readFrameProperties().

◆ nextTokenAsBool()

bool OpenMD::StringTokenizer::nextTokenAsBool ( )

Returns the next token from this string tokenizer as a bool.

Returns
the next token from this string tokenizer as a bool.

Definition at line 171 of file StringTokenizer.cpp.

References nextToken().

◆ nextTokenAsDouble()

RealType OpenMD::StringTokenizer::nextTokenAsDouble ( )

Returns the next token from this string tokenizer as a RealType.

Returns
the next token from this string tokenizer as a RealType.

Definition at line 198 of file StringTokenizer.cpp.

References convertFortranNumber(), and nextToken().

Referenced by ParameterTraits< std::vector< RealType > >::convert(), OpenMD::HydroProp::HydroProp(), OpenMD::MultipoleAtomTypesSectionParser::parseDipole(), OpenMD::DumpReader::parseDumpLine(), OpenMD::RestReader::parseDumpLine(), OpenMD::EAMAtomTypesSectionParser::parseEAMArray(), OpenMD::EAMAtomTypesSectionParser::parseFuncflFile(), OpenMD::DirectionalAtomTypesSectionParser::parseLine(), OpenMD::GayBerneAtomTypesSectionParser::parseLine(), OpenMD::LennardJonesAtomTypesSectionParser::parseLine(), OpenMD::ChargeAtomTypesSectionParser::parseLine(), OpenMD::PolarizableAtomTypesSectionParser::parseLine(), OpenMD::AtomTypesSectionParser::parseLine(), OpenMD::StickyAtomTypesSectionParser::parseLine(), OpenMD::BaseAtomTypesSectionParser::parseLine(), OpenMD::MultipoleAtomTypesSectionParser::parseLine(), OpenMD::BendTypeParser::parseLine(), OpenMD::StickyPowerAtomTypesSectionParser::parseLine(), OpenMD::BondTypeParser::parseLine(), OpenMD::InversionTypeParser::parseLine(), OpenMD::EAMAtomTypesSectionParser::parseLine(), OpenMD::TorsionTypeParser::parseLine(), OpenMD::SCAtomTypesSectionParser::parseLine(), OpenMD::FluctuatingChargeAtomTypesSectionParser::parseLine(), OpenMD::NonBondedInteractionsSectionParser::parseLine(), OpenMD::MultipoleAtomTypesSectionParser::parseQuadrupole(), OpenMD::ShapeAtomTypesSectionParser::parseShapeFile(), OpenMD::DumpReader::parseSiteLine(), and OpenMD::DumpReader::readFrameProperties().

◆ nextTokenAsFloat()

float OpenMD::StringTokenizer::nextTokenAsFloat ( )

Returns the next token from this string tokenizer as a float.

Returns
the next token from this string tokenizer as a float.

Definition at line 192 of file StringTokenizer.cpp.

References convertFortranNumber(), and nextToken().

◆ nextTokenAsInt()

◆ peekNextToken()

std::string OpenMD::StringTokenizer::peekNextToken ( )

Returns the next token without advancing the position of the StringTokenizer.

Returns
the next token

Definition at line 204 of file StringTokenizer.cpp.

References currentPos_, end_, isDelimiter(), and returnTokens_.

Referenced by OpenMD::DumpReader::parseSiteLine().

◆ skipToken()

void OpenMD::StringTokenizer::skipToken ( )

Skips the next token from this string tokenizer.

Exceptions
NoSuchElementExceptionif there are no more tokens in this tokenizer's string

Definition at line 152 of file StringTokenizer.cpp.

References currentPos_, end_, isDelimiter(), and returnTokens_.

Referenced by OpenMD::ShapeAtomTypesSectionParser::parseShapeFile().

Member Data Documentation

◆ currentPos_

std::string::const_iterator OpenMD::StringTokenizer::currentPos_
private

◆ delim_

std::string OpenMD::StringTokenizer::delim_
private

current delimiter set of this string tokenizer

Definition at line 210 of file StringTokenizer.hpp.

Referenced by getDelimiters(), and isDelimiter().

◆ end_

std::string::const_iterator OpenMD::StringTokenizer::end_
private

◆ returnTokens_

bool OpenMD::StringTokenizer::returnTokens_
private

flag indicating whether to return the delimiters as tokens

Definition at line 212 of file StringTokenizer.hpp.

Referenced by countTokens(), hasMoreTokens(), nextToken(), peekNextToken(), and skipToken().

◆ tokenString_

std::string OpenMD::StringTokenizer::tokenString_
private

Definition at line 208 of file StringTokenizer.hpp.

Referenced by getOriginal().


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