BIND 10 #2370: define MasterToken
BIND 10 Development
do-not-reply at isc.org
Fri Oct 19 06:15:38 UTC 2012
#2370: define MasterToken
-------------------------------------+-------------------------------------
Reporter: jinmei | Owner:
Type: task | UnAssigned
Priority: medium | Status: new
Component: libdns++ | Milestone: New
Sensitive: 0 | Tasks
Sub-Project: DNS | Keywords:
Estimated Difficulty: 0 | Defect Severity: N/A
Total Hours: 0 | Feature Depending on Ticket:
| loadzone-ng
| Add Hours to Ticket: 0
| Internal?: 0
-------------------------------------+-------------------------------------
Subtask of #2368, (mostly) no dependency.
This defines a simple class encapsulating tokens returned by
`MasterLexer`.
This is probably a subclass of `MasterLexer`.
A sample definition is this:
{{{#!cpp
class MasterToken {
public:
enum TokenType {
ERROR, // getToken failed
STRING, NUMBER, QSTRING, EOL /* end of line */, EOF /* end of file
*/,
INITIAL_WS /* space at the beginning of line */
};
Token(TokenType type); // non value type
Token(type, const char* str_beg, size_t str_len); // type STRING or
QSTRING
Token(uint32_t num); // type NUMBER
const TokenType type;
// Only if type is STRING or QSTRING , otherwise throw
std::string getString() const; // convert region_ to std::string and
return
const StringRegion& getStringRegion() const { return (region_); }
// Only if type is NUMBER, otherwise throw
uint32_t getNumber() const { return (number_) };
struct StringRegion {
const char* beg;
size_t len;
};
private:
union {
StringRegion region_;
uint32_t number_;
};
};
}}}
For string, I suggest using a pair of const char* and size_t instead
of creating std::string unless it's really needed, to avoid
unnecessary copy.
--
Ticket URL: <http://bind10.isc.org/ticket/2370>
BIND 10 Development <http://bind10.isc.org>
BIND 10 Development
More information about the bind10-tickets
mailing list