Isis 3 Developer Reference
Isis::PvlTokenizer Class Reference

Construct Token list from a stream. More...

#include <PvlTokenizer.h>

Collaboration diagram for Isis::PvlTokenizer:
Collaboration graph

Public Member Functions

 PvlTokenizer ()
 Constructs a Tokenizer with an empty token list. More...
 
 ~PvlTokenizer ()
 Destroys the Tokenizer object and token list. More...
 
void Load (std::istream &stream, const QString &terminator="END")
 Loads the Token list from a stream. More...
 
void Clear ()
 Empties the token list. More...
 
std::vector< Isis::PvlToken > & GetTokenList ()
 

Protected Member Functions

QString ReadComment (std::istream &stream)
 Reads and returns a comment from the stream. More...
 
QString ReadToken (std::istream &stream)
 Reads and returns a token from the stream. More...
 
bool SkipWhiteSpace (std::istream &stream)
 Skips over whitespace so long as it is not inside quotes. More...
 
QString ReadToSingleQuote (std::istream &stream)
 
QString ReadToDoubleQuote (std::istream &stream)
 
QString ReadToParen (std::istream &stream)
 
QString ReadToBrace (std::istream &stream)
 
void ParseCommaList (Isis::PvlToken &t, const QString &cl)
 This routine parses a QString containing a comma separated list. More...
 
void ValidateCharacter (int c)
 Make sure a character is valid printable (non-control) character. More...
 

Protected Attributes

std::vector< Isis::PvlTokentokens
 The array of Tokens parse out of the stream. More...
 

Detailed Description

Construct Token list from a stream.

This class tokenizes a stream. That is, it will take a stream, from a file or a string, and break the contents of the stream into keyword-value pairs. Examples of such are PDS labels, the standard Isis command line, and VICAR labels. Note that this does not validate the stream to ensure it is of PDS- or VICAR-type. It simply creates a list of keyword-value pairs which can be parsed by another object. The ruleset for tokenizing is straightforward. Consider SPACECRAFT=MARS_GLOBAL_SURVEYOR. The keyword would be SPACECRAFT and the value would be MARS_GLOBAL_SURVEYOR. Other valid examples include: LINES=5, FOCAL_LENGTH=12.4, INSTRUMENT="CAMERA_A", LIST=(0,1,5), and DOGS=("LAB","PUG","BULL"). The later examples, are considered arrays and therefore, will have multiple values associated with the keyword. Comments are allowed in the stream and are indicated by either "#" or "/ *" as the first character on the line.

Author
2002-02-15 Jeff Anderson

Constructor & Destructor Documentation

◆ PvlTokenizer()

Isis::PvlTokenizer::PvlTokenizer ( )

Constructs a Tokenizer with an empty token list.

◆ ~PvlTokenizer()

Isis::PvlTokenizer::~PvlTokenizer ( )

Destroys the Tokenizer object and token list.

Member Function Documentation

◆ Clear()

void Isis::PvlTokenizer::Clear ( )

Empties the token list.

◆ GetTokenList()

vector< Isis::PvlToken > & Isis::PvlTokenizer::GetTokenList ( )

◆ Load()

void Isis::PvlTokenizer::Load ( std::istream &  stream,
const QString &  terminator = "END" 
)

Loads the Token list from a stream.

The loading will be terminated upon reaching either 1) end-of-stream, or 2) a programmer specified terminator QString

Parameters
streamThe input stream to tokenize
terminatorIf the tokenizer see's this QString as a token in the input stream it will cease tokenizing. Defaults to "END"
Exceptions
Isis::iException::Parse

References _FILEINFO_, Isis::PvlToken::addValue(), Isis::PvlToken::key(), Isis::PvlToken::keyUpper(), and Isis::Message::KeywordValueBad().

◆ ParseCommaList()

void Isis::PvlTokenizer::ParseCommaList ( Isis::PvlToken t,
const QString &  cl 
)
protected

This routine parses a QString containing a comma separated list.

Each of the items in the list is stored as a value in the Token.

Parameters
tToken to load the comma separated list
clQString containing comma separated list

References Isis::PvlToken::addValue().

◆ ReadComment()

QString Isis::PvlTokenizer::ReadComment ( std::istream &  stream)
protected

Reads and returns a comment from the stream.

Parameters
streamInput stream to read from
Returns
QString

◆ ReadToBrace()

QString Isis::PvlTokenizer::ReadToBrace ( std::istream &  stream)
protected

◆ ReadToDoubleQuote()

QString Isis::PvlTokenizer::ReadToDoubleQuote ( std::istream &  stream)
protected

◆ ReadToken()

QString Isis::PvlTokenizer::ReadToken ( std::istream &  stream)
protected

Reads and returns a token from the stream.

A token is delimited by either whitespace or an equal sign. In the case of whitespace the token will be considered valueless. That is, there will be no value in the value side of the token (e.g., KEYWORD=).

Parameters
streamInput stream to read from
Returns
QString

◆ ReadToParen()

QString Isis::PvlTokenizer::ReadToParen ( std::istream &  stream)
protected

◆ ReadToSingleQuote()

QString Isis::PvlTokenizer::ReadToSingleQuote ( std::istream &  stream)
protected

◆ SkipWhiteSpace()

bool Isis::PvlTokenizer::SkipWhiteSpace ( std::istream &  stream)
protected

Skips over whitespace so long as it is not inside quotes.

Whitespace is tabs, blanks, line feeds, carriage returns, and NULLs.

Parameters
streamInput stream to read from

◆ ValidateCharacter()

void Isis::PvlTokenizer::ValidateCharacter ( int  c)
protected

Make sure a character is valid printable (non-control) character.

Parameters
cCharacter to be validated

References _FILEINFO_.

Member Data Documentation

◆ tokens

std::vector<Isis::PvlToken> Isis::PvlTokenizer::tokens
protected

The array of Tokens parse out of the stream.


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