Simpatico  v1.10
List of all members | Public Member Functions | Static Public Member Functions | Static Public Attributes | Friends
Util::Label Class Reference

Detailed Description

A label string in a file format.

The operator >> for a label checks if the expected label was found. The operator << outputs the expected label.

The constructor takes a parameter isRequired that determines whether the label must be matched (isRequired == true), or if it is optional (isRequired == false). If the input value read by the >> operator does not match the expected value and isRequired is true, the >> operator will print an error message to the Log::file() and then throw an Exception. If the input value does not match and isRequired is false, the >> operator stores the input value in a string buffer, and will compare it to subsequent values until a match is found.

Definition at line 36 of file Label.h.

#include <Label.h>

Inheritance diagram for Util::Label:
Util::OptionalLabel

Public Member Functions

 Label (bool isRequired=true)
 Constructor. More...
 
 Label (std::string string, bool isRequired=true)
 Constructor. More...
 
 Label (const char *string, bool isRequired=true)
 Constructor. More...
 
 Label (const Label &other)
 Copy constructor. More...
 
virtual ~Label ()
 Destructor. More...
 
void setString (std::string string)
 Set the label string. More...
 
bool match (std::istream &in)
 Read and attempt to match next word in an input stream. More...
 
std::string string () const
 Return label string. More...
 
bool isRequired () const
 Is this the label for a required component? More...
 

Static Public Member Functions

static void clear ()
 Reset buffer and flags to initial state. More...
 
static bool isClear ()
 Is the input buffer clear? More...
 
static bool isMatched ()
 Did the most recent attempt to match a Label succeed? More...
 

Static Public Attributes

static const int LabelWidth = 20
 Width of label field in file output format. More...
 

Friends

std::istream & operator>> (std::istream &in, Label label)
 Extractor for Label. More...
 
std::ostream & operator<< (std::ostream &out, Label label)
 Inserter for Label. More...
 

Constructor & Destructor Documentation

Util::Label::Label ( bool  isRequired = true)
explicit

Constructor.

Parameters
isRequiredIs this label a required entry? (true by default)

Definition at line 45 of file Label.cpp.

Util::Label::Label ( std::string  string,
bool  isRequired = true 
)

Constructor.

Parameters
stringlabel string that precedes value in file format
isRequiredIs this label a required entry? (true by default)

Definition at line 53 of file Label.cpp.

Util::Label::Label ( const char *  string,
bool  isRequired = true 
)

Constructor.

Parameters
stringlabel string that precedes value in file format
isRequiredIs this label a required entry? (true by default)

Definition at line 61 of file Label.cpp.

Util::Label::Label ( const Label other)

Copy constructor.

Parameters
otherLabel object being copied.

Definition at line 69 of file Label.cpp.

Util::Label::~Label ( )
virtual

Destructor.

Definition at line 77 of file Label.cpp.

Member Function Documentation

void Util::Label::clear ( )
static

Reset buffer and flags to initial state.

Clears buffer, sets isClear = true and isMatched = false.

Definition at line 27 of file Label.cpp.

bool Util::Label::isClear ( )
static

Is the input buffer clear?

Definition at line 37 of file Label.cpp.

Referenced by McMd::SmpConfigIo::read(), Util::Begin::readParam(), Simp::Species::readStructure(), and McMd::SmpConfigIo::write().

bool Util::Label::isMatched ( )
inlinestatic

Did the most recent attempt to match a Label succeed?

Returns true after a succesful match by operator >> or the match() function. Returns false before any attempt to match any Label, after a failed attempt with an an optional label.

Definition at line 203 of file Label.h.

Referenced by Util::Parameter::readParam().

void Util::Label::setString ( std::string  string)

Set the label string.

Parameters
stringlabel string that precedes value in file format

Definition at line 83 of file Label.cpp.

References string().

Referenced by Util::Begin::Begin().

bool Util::Label::match ( std::istream &  in)

Read and attempt to match next word in an input stream.

This is a convenience function that invokes operator >> to read a word and then returns the value of Label::isMatched(). For an optional Label, this returns true upon a successful match and false otherwise. For a required label, returns true upon a successful match or throws an Exception.

Definition at line 95 of file Label.cpp.

Referenced by McMd::SmpConfigIo::read().

std::string Util::Label::string ( ) const

Return label string.

Definition at line 89 of file Label.cpp.

Referenced by Util::Parameter::label(), setString(), and Util::Begin::writeParam().

bool Util::Label::isRequired ( ) const
inline

Is this the label for a required component?

Definition at line 197 of file Label.h.

Referenced by Util::Begin::isRequired(), Util::Parameter::isRequired(), and Util::operator>>().

Friends And Related Function Documentation

std::istream& operator>> ( std::istream &  in,
Label  label 
)
friend

Extractor for Label.

Parameters
ininput stream
labelLabel to be read from file

Definition at line 104 of file Label.cpp.

std::ostream& operator<< ( std::ostream &  out,
Label  label 
)
friend

Inserter for Label.

Parameters
outoutput stream
labelLabel to be written to file

Definition at line 158 of file Label.cpp.

Member Data Documentation

const int Util::Label::LabelWidth = 20
static

Width of label field in file output format.

Definition at line 44 of file Label.h.

Referenced by Util::operator<<().


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