Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F126662
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
5 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/util/token.h b/util/token.h
index c9b7a519..bcb4d0e8 100644
--- a/util/token.h
+++ b/util/token.h
@@ -1,189 +1,217 @@
#ifndef _paintown_token_h
#define _paintown_token_h
#include <string>
#include <vector>
#include <ostream>
#include "token_exception.h"
class TokenReader;
class Configuration;
class Token;
class TokenMatcher{
public:
template <typename X1>
bool match(X1 & obj1){
if (current == tokens.end()){
return false;
}
Token * token = *current;
current++;
try{
*token >> obj1;
return true;
} catch (const TokenException & t){
}
return false;
}
template <typename X1, typename X2>
bool match(X1 & obj1, X2 & obj2){
if (current == tokens.end()){
return false;
}
Token * token = *current;
current++;
try{
*token >> obj1 >> obj2;
return true;
} catch (const TokenException & t){
}
return false;
}
TokenMatcher & operator=(const TokenMatcher & matcher);
protected:
TokenMatcher(std::vector<Token*> tokens);
explicit TokenMatcher();
friend class Token;
std::vector<Token*> tokens;
std::vector<Token*>::iterator current;
};
/* Token:
* Basically a tree where each node stores a value in a string
* and can have 0 or more children
*/
class Token{
public:
typedef TokenMatcher Matcher;
Token(Token const & copy);
virtual ~Token();
/* add an existing token to the tree */
void addToken(Token * t);
/* creates a new empty token and returns it */
Token * newToken();
/*
inline const string & getName(){
return name;
}
*/
const std::string & getName() const;
const Token * getParent() const;
void setFile( const std::string & s );
const std::string getFileName() const;
const std::string getLineage() const;
void print( const std::string space );
void toString( std::ostream & stream, const std::string & space );
bool match(const std::string & subject){
TokenMatcher matcher = getMatcher(subject);
return false;
}
template <typename X>
bool match(const std::string & subject, X & obj){
TokenMatcher matcher = getMatcher(subject);
return matcher.match(obj);
}
- template <typename X>
- bool match(const std::string & subject, X & obj1, X & obj2){
+ template <typename X1, typename X2>
+ bool match(const std::string & subject, X1 & obj1, X2 & obj2){
+ TokenMatcher matcher = getMatcher(subject);
+ return matcher.match(obj1) &&
+ matcher.match(obj2);
+ }
+
+ template <typename X1, typename X2, typename X3>
+ bool match(const std::string & subject, X1 & obj1, X2 & obj2, X3 & obj3){
+ TokenMatcher matcher = getMatcher(subject);
+ return matcher.match(obj1) &&
+ matcher.match(obj2) &&
+ matcher.match(obj3);
+ }
+
+ template <typename X1, typename X2, typename X3, typename X4>
+ bool match(const std::string & subject, X1 & obj1, X2 & obj2, X3 & obj3, X4 & obj4){
+ TokenMatcher matcher = getMatcher(subject);
+ return matcher.match(obj1) &&
+ matcher.match(obj2) &&
+ matcher.match(obj3) &&
+ matcher.match(obj4);
+ }
+
+ template <typename X1, typename X2, typename X3, typename X4, typename X5>
+ bool match(const std::string & subject, X1 & obj1, X2 & obj2, X3 & obj3, X4 & obj4, X5 & obj5){
TokenMatcher matcher = getMatcher(subject);
- return matcher.match(obj1, obj2);
+ return matcher.match(obj1) &&
+ matcher.match(obj2) &&
+ matcher.match(obj3) &&
+ matcher.match(obj4) &&
+ matcher.match(obj5);
}
TokenMatcher getMatcher(const std::string & subject);
Token * getToken( unsigned int n ) const;
/* xpath-esque searching for tokens
* '/' delimits tokens
* <literal> matches a token
*/
Token * findToken(const std::string & path);
/* find all tokens */
std::vector<Token *> findTokens(const std::string & path);
inline signed int numTokens() const {
return tokens.size() - 1;
}
inline bool isData() const {
return numTokens() == -1;
}
inline const std::vector< Token * > * getTokens() const{
return &tokens;
}
inline void resetToken(){
num_token = 1;
}
/* returns a deep copy of this token. the parent field is set to null */
Token * copy();
Token * readToken();
bool hasTokens();
bool operator== ( const std::string & rhs );
bool operator!= ( const std::string & rhs );
Token & operator>>( std::string & rhs ) throw( TokenException );
Token & operator>>( int & rhs ) throw( TokenException );
Token & operator>>( double & rhs ) throw( TokenException );
Token & operator>>( Token * & rhs ) throw( TokenException );
Token & operator>>( bool & rhs ) throw( TokenException );
protected:
/* Only TokenReader and Configuration can create and destroy a Token */
Token();
Token( std::string tok, bool parse = true );
friend class TokenReader;
friend class Configuration;
Token & operator<<( const std::string rhs );
Token & operator<<( const int rhs );
Token & operator<<( const double rhs );
virtual inline const std::string & _getName(){
return name;
}
virtual inline void setParent( const Token * const parent ){
this->parent = parent;
}
std::string lowerCase( const std::string & s );
void finalize();
unsigned int num_token;
std::vector< Token * > tokens;
std::string filename;
Token const * parent;
std::string name;
bool own;
};
#endif
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Jun 11, 12:26 PM (3 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
69026
Default Alt Text
(5 KB)
Attached To
Mode
R75 R-Tech1
Attached
Detach File
Event Timeline