class Poco::Token

Overview

The base class for all token classes that can be registered with the StreamTokenizer. More…

#include <Token.h>

class Token
{
public:
    // enums

    enum Class;

    // methods

    virtual
    bool
    start(
        char c,
        std::istream& istr
        );

    virtual
    void
    finish(std::istream& istr);

    virtual
    Class
    tokenClass() const;

    const std::string&
    tokenString() const;

    virtual
    std::string
    asString() const;

    virtual
    int
    asInteger() const;

    virtual
    unsigned
    asUnsignedInteger() const;

    virtual
    double
    asFloat() const;

    virtual
    char
    asChar() const;

    bool
    is(Class tokenClass) const;

protected:
    // fields

    std::string _value;
};

// direct descendants

class EOFToken;
class InvalidToken;
class WhitespaceToken;

Detailed Documentation

The base class for all token classes that can be registered with the StreamTokenizer.

Construction

virtual
~Token()

Destroys the Token.

Methods

virtual
bool
start(
    char c,
    std::istream& istr
    )

Checks if the given character (and, optionally, the next character in the input stream) start a valid token.

Returns true if so, false otherwise.

The current read position in istr must not be changed. In other words, only the peek() method of istream may be used.

If the character starts the token, it should be set as the token’s value.

virtual
void
finish(std::istream& istr)

Builds the token by reading and appending the remaining characters from istr.

virtual
Class
tokenClass() const

Returns the kind of the token.

const std::string&
tokenString() const

Returns the token’s raw string.

virtual
std::string
asString() const

Returns a string representation of the token.

virtual
int
asInteger() const

Returns an integer representation of the token.

virtual
unsigned
asUnsignedInteger() const

Returns an unsigned integer representation of the token.

virtual
double
asFloat() const

Returns a floating-point representation of the token.

virtual
char
asChar() const

Returns a char representation of the token.

bool
is(Class tokenClass) const

Returns true iff the token has the given class.