* lyxlex.[Ch]: make interface more similar to std::stream

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8179 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2003-12-02 10:19:51 +00:00
parent 8a3f21cd29
commit a5e85854f8
4 changed files with 94 additions and 18 deletions

View File

@ -1,3 +1,8 @@
2003-12-02 André Pönitz <poenitz@gmx.net>
* lyxlex.[Ch]: make interface more similar to std::stream
2003-12-01 Martin Vermeer <martin.vermeer@hut.fi>
* lyxtextclass.[Ch]: add latexparam to CharStyle inset

View File

@ -246,18 +246,10 @@ void InsetVSpaceMailer::string2params(string const & in, VSpace & vspace)
istringstream data(in);
LyXLex lex(0,0);
lex.setStream(data);
if (lex.isOK()) {
lex.next();
string const name = lex.getString();
}
// This is part of the inset proper that is usually swallowed
// by Buffer::readInset
if (lex.isOK()) {
lex.next();
vspace = VSpace(lex.getString());
}
string name, vsp;
lex >> name >> vsp;
if (lex)
vspace = VSpace(vsp);
}

View File

@ -254,3 +254,67 @@ int LyXLex::findToken(char const * str[])
return i;
}
LyXLex::operator void *() const
{
return isOK() ? const_cast<LyXLex *>(this) : 0;
}
bool LyXLex::operator!() const
{
return !isOK();
}
LyXLex & LyXLex::operator>>(std::string & s)
{
if (isOK()) {
next();
s = getString();
}
return *this;
}
LyXLex & LyXLex::operator>>(float & s)
{
if (isOK()) {
next();
s = getFloat();
}
return *this;
}
LyXLex & LyXLex::operator>>(int & s)
{
if (isOK()) {
next();
s = getInteger();
}
return *this;
}
LyXLex & LyXLex::operator>>(unsigned int & s)
{
if (isOK()) {
next();
s = getInteger();
}
return *this;
}
LyXLex & LyXLex::operator>>(bool & s)
{
if (isOK()) {
next();
s = getBool();
}
return *this;
}

View File

@ -55,8 +55,12 @@ public:
LEX_TOKEN = -4
};
/// file is open and end of file is not reached
/// straem is open and end of straem is not reached
bool isOK() const;
/// stream is ok
operator void *() const;
/// stream is not ok
bool operator!() const;
/// return true if able to open file, else false
bool setFile(std::string const & filename);
///
@ -110,8 +114,7 @@ public:
///
int findToken(char const * str[]);
/** Pushes a token list on a stack and replaces it with a new one.
*/
/// Pushes a token list on a stack and replaces it with a new one.
void pushTable(keyword_item *, int);
/** Pops a token list into void and replaces it with the one now
@ -125,10 +128,22 @@ public:
*/
void printError(std::string const & message) const;
/**
Prints the current token table on the supplied ostream.
*/
/// Prints the current token table on the supplied ostream.
void printTable(std::ostream &);
/// extract string
LyXLex & operator>>(std::string &);
/// extract float
LyXLex & operator>>(float &);
/// extract double
LyXLex & operator>>(double &);
/// extract integer
LyXLex & operator>>(int &);
/// extract unsigned integer
LyXLex & operator>>(unsigned int &);
/// extract bool
LyXLex & operator>>(bool &);
private:
struct Pimpl;
///