- throw TokenException( getFileName() + ": " + string("Tried to read a token from ") + this->getName() + string(" but there are no more elements") );
+ throw TokenException(__FILE__, __LINE__, getFileName() + ": " + string("Tried to read a token from ") + this->getName() + string(" but there are no more elements") );
- throw TokenException( getFileName() + ":" + string("Tried to read a string from '") + this->getLineage() + string("' but there no more elements") );
+ throw TokenException(__FILE__, __LINE__, getFileName() + ":" + string("Tried to read a string from '") + this->getLineage() + string("' but there no more elements") );
}
if (!l->isData()){
- throw TokenException(getFileName() + ":" + string(" Element is not a string"));
+ throw TokenException(__FILE__, __LINE__, getFileName() + ":" + string(" Element is not a string"));
}
rhs = l->getName();
// rhs = getName();
return *this;
}
Token & Token::operator>>( int & rhs ) throw( TokenException ){
Token * l = readToken();
if ( l == NULL ){
- throw TokenException( getFileName() + ": " + string("Tried to read an int from ") + this->getLineage() + string(" but there are no more elements") );
+ throw TokenException(__FILE__, __LINE__, getFileName() + ": " + string("Tried to read an int from ") + this->getLineage() + string(" but there are no more elements") );
}
if (!l->isData()){
- throw TokenException(getFileName() + ":" + string(" Element is not a string"));
+ throw TokenException(__FILE__, __LINE__, getFileName() + ":" + string(" Element is not a string"));
- throw TokenException( getFileName() + ": " + string("Tried to read a double from ") + this->getLineage() + string(" but there no more elements") );
+ throw TokenException(__FILE__, __LINE__, getFileName() + ": " + string("Tried to read a double from ") + this->getLineage() + string(" but there no more elements") );
}
if (!l->isData()){
- throw TokenException(getFileName() + ":" + string(" Element is not a string"));
+ throw TokenException(__FILE__, __LINE__, getFileName() + ":" + string(" Element is not a string"));
- throw TokenException( getFileName() + ": " + string("Tried to read a bool from ") + this->getLineage() + string(" but there no more elements") );
+ throw TokenException(__FILE__, __LINE__, getFileName() + ": " + string("Tried to read a bool from ") + this->getLineage() + string(" but there no more elements") );
}
if (!l->isData()){
- throw TokenException(getFileName() + ":" + string(" Element is not a string"));
+ throw TokenException(__FILE__, __LINE__, getFileName() + ":" + string(" Element is not a string"));
}
istringstream is ( l->getName() );
is >> rhs;
return *this;
}
void Token::addToken(Token * t){
if (!own){
- throw TokenException("This token does not own its own tokens, so you cannot add tokens to it");
+ throw TokenException(__FILE__, __LINE__, "This token does not own its own tokens, so you cannot add tokens to it");
}
tokens.push_back( t );
}
Token * Token::newToken(){
Token * token = new Token();
addToken(token);
return token;
}
/* put quotes around a string if there are spaces in it */
static string quoteify(const string & rhs){
if (rhs.find(' ') != string::npos){
return "\"" + rhs + "\"";
}
return rhs;
}
Token & Token::operator<<( const string rhs ){
Token * n = new Token(quoteify(rhs), false );
this->addToken(n);
return *this;
}
Token & Token::operator<<( const int rhs ){
ostringstream o;
o << rhs;
return *this << o.str();
}
Token & Token::operator<<( const double rhs ){
ostringstream o;
o << rhs;
return *this << o.str();
}
Token * Token::copy(){
Token * token = new Token();
token->filename = this->filename;
token->name = this->name;
for (vector<Token *>::iterator it = this->tokens.begin(); it != this->tokens.end(); it++){
Token * him = (*it)->copy();
him->setParent(token);
token->addToken(him);
}
return token;
}
/* Delete tokens that are commented.
* A commented token has a '!' character as the first
* character in the name, e.g:
* (!a_token (child_token 2))
*/
void Token::finalize(){
for ( vector< Token * >::iterator it = tokens.begin(); it != tokens.end(); ){
Token * t = *it;
if ( t->getName().find('!') == 0 ){
delete t;
it = tokens.erase( it );
} else {
t->finalize();
it++;
}
}
}
Token::~Token(){
if (own){
for ( vector< Token * >::iterator it = tokens.begin(); it != tokens.end(); it++ ){