MySQL++ SSQLS v2 Translator
3.2.5
|
27 #if !defined(MYSQLPP_SSX_PARSEV2_H)
28 #define MYSQLPP_SSX_PARSEV2_H
30 #include <exceptions.h>
62 File(
const char* file_name);
65 void error(
const std::string& msg)
const;
68 void error(
const std::ostringstream& msg)
const
72 const char*
name()
const {
return file_name_.c_str(); }
79 void parse_error(
const std::ostringstream& msg)
const
92 bool read_line(std::string& line,
bool& subdirective);
104 void add_directory_to_search_path(
const char* filepath);
108 void split_path(
StringList& parts,
const std::string& path)
const;
116 std::string file_name_;
157 virtual void print(std::ostream& os)
const = 0;
167 typedef std::vector<Line*>
LineList;
176 class Field :
public Line
192 Field(
const std::string& name,
const std::string& type,
193 bool is_unsigned =
false,
bool is_null =
false,
194 bool is_autoinc =
false,
bool is_key =
false,
195 const std::string& alias = 0) :
198 is_autoinc_(is_autoinc),
201 is_unsigned_(is_unsigned),
218 void print(std::ostream& os)
const;
266 Type(
const std::string& s);
279 operator Value()
const {
return value_; }
283 {
return value_ == rhs.value_; }
308 Include(
const char* file_name) :
339 void print(std::ostream&)
const { assert(0); }
351 class Option :
public Line
395 const char*
value()
const {
return value_.c_str(); }
403 class AccessorStyleOption :
public Option
415 void print(std::ostream& os)
const;
435 static Type parse_type(
const std::string& style,
455 operator bool()
const {
return throw_; }
459 void print(std::ostream& os)
const;
466 class HeaderExtensionOption :
public Option
480 void print(std::ostream& os)
const;
484 class ImplementationExtensionOption :
public Option
499 void print(std::ostream& os)
const;
512 Table(
const std::string& name,
const std::string& alias,
513 const std::string& filebase);
530 std::string name_, alias_, filebase_;
547 class ParseException :
public mysqlpp::Exception
567 const char*
file_name()
const {
return file_name_.c_str(); }
570 size_t line()
const {
return line_; }
573 std::string file_name_;
593 for (
LineListIt it = lines_.begin(); it != lines_.end(); ++it) {
605 void clear() { lines_.clear(); }
612 void tokenize(
StringList& tokens,
const std::string& line)
const;
635 std::ostream& operator<<(std::ostream& os,
const ParseV2::Line& line);
637 #endif // !defined(MYSQLPP_SSX_PARSEV2_H)
@ ft_smallint
SMALLINT, INT2.
Definition: parsev2.h:271
@ ft_mediumint
INT, MEDIUMINT, INT3, INT4.
Definition: parsev2.h:272
@ ft_set
SET.
Definition: parsev2.h:281
AccessorStyleOption(const std::string &value, const File &file)
Constructor.
Definition: parsev2.h:431
Option(const std::string &value)
Protected ctor, so we cannot be directly instantiated.
Definition: parsev2.h:395
void clear()
Dump our line list.
Definition: parsev2.h:629
FileException(const std::string &what)
Constructor.
Definition: parsev2.h:566
Field(const std::string &name, const std::string &type, bool is_unsigned=false, bool is_null=false, bool is_autoinc=false, bool is_key=false, const std::string &alias=0)
Holds information about a SQL field declared in the SSQLS v2 language.
Definition: parsev2.h:216
LineList::const_iterator LineListIt
Iterator into a LineList.
Definition: parsev2.h:197
Exception object thrown to indicate a file I/O error.
Definition: parsev2.h:559
~ParseV2()
Destructor.
Definition: parsev2.h:615
'option exception_on_schema_mismatch' directive line
Definition: parsev2.h:467
Parses SSQLS v2 documents and holds the parse result.
Definition: parsev2.h:41
void print(std::ostream &os) const
Print the option description out to a stream in SSQLS v2 form.
Definition: parsev2.cpp:162
const char * extension() const
Return the extension used for C++ implementation files we emit.
Definition: parsev2.h:519
File(const char *file_name)
Open a file for reading, using the search path to file the file if the direct path isn't readable.
Definition: parsev2.cpp:325
Exception object thrown by File::error() to report an SSQLS v2 parsing error.
Definition: parsev2.h:571
'table' directive line
Definition: parsev2.h:527
std::vector< std::string > StringList
List of tokens as returned by boost::algorithm::split.
Definition: parsev2.h:69
LineListIt end() const
Get an iterator pointing to just past the end of the sub-parse's LineList.
Definition: parsev2.h:346
void print(std::ostream &os) const
Print type description out to a stream in SSQLS v2 form.
Definition: parsev2.cpp:305
static bool parse_bool(const std::string &value)
Convert a string expressing a boolean value to a bool.
Definition: parsev2.cpp:575
ExceptionOnSchemaMismatchOption(const std::string &value)
Constructor.
Definition: parsev2.h:471
void print(std::ostream &os) const
Print the option description out to a stream in SSQLS v2 form.
Definition: parsev2.cpp:459
static Option * parse(const StringList &tl, bool subdirective, const File &file)
Attempt to create an Option object from information in the passed StringList.
Definition: parsev2.cpp:536
size_t line() const
Get line number where error occurred.
Definition: parsev2.h:594
static Include * parse(const StringList &tl, bool subdirective, const File &file)
Attempt to create an Include object from information in the passed StringList.
Definition: parsev2.cpp:466
const char * file_name() const
Get name of file where error occurred.
Definition: parsev2.h:591
~ParseException()
Destructor.
Definition: parsev2.h:588
bool operator==(const Type &rhs) const
Equality operator.
Definition: parsev2.h:306
Holds information about an SSQLS v2 file we're parsing.
Definition: parsev2.h:81
static Field * parse(const StringList &tl, bool subdirective, const File &file)
Attempt to create a Field object from information in the passed StringList.
Definition: parsev2.cpp:170
virtual void print(std::ostream &os) const =0
Print line's contents out to a stream in SSQLS v2 form.
static Line * parse(const StringList &tl, bool subdirective, const File &file)
Virtual ctor, creating one of our subclass objects based on what we're passed.
Definition: parsev2.cpp:485
Base class for parsed SSQLS v2 declaration lines.
Definition: parsev2.h:160
ImplementationExtensionOption(const std::string &value)
Constructor.
Definition: parsev2.h:512
std::vector< Line * > LineList
A list of pointers to Line objects.
Definition: parsev2.h:191
~Include()
Destructor.
Definition: parsev2.h:338
'option implementation_extension' directive line
Definition: parsev2.h:508
void parse_error(const std::string &msg) const
Throw a ParseException containing the given message and our stored info about the file name and curre...
Definition: parsev2.cpp:399
Table(const std::string &name, const std::string &alias, const std::string &filebase)
Constructor.
Definition: parsev2.cpp:595
@ ft_datetime
DATETIME, TIMESTAMP.
Definition: parsev2.h:279
void error(const std::string &msg) const
Throw a FileException containing the given message.
Definition: parsev2.cpp:392
static Table * parse(const StringList &tl, bool subdirective, const File &file)
Attempt to create a Table object from information in the passed StringList.
Definition: parsev2.cpp:605
@ ft_tinyint
TINYINT, INT1, BOOL.
Definition: parsev2.h:270
const char * value() const
Return the option's value in string form, unmodified from the original parse.
Definition: parsev2.h:419
@ ft_string
*CHAR, ENUM, *TEXT
Definition: parsev2.h:276
@ ft_float
FLOAT, FLOAT4, FLOAT8.
Definition: parsev2.h:274
'option accessor_style' directive line
Definition: parsev2.h:427
virtual ~Line()
Virtual dtor, since this is a base class.
Definition: parsev2.h:164
Type(const std::string &s)
Constructor.
Definition: parsev2.cpp:251
Line()
Protected ctor, to prevent instantiation.
Definition: parsev2.h:185
@ ft_time
TIME.
Definition: parsev2.h:280
Include(const char *file_name)
Given the name of another SSQLS v2 file, load it up and parse it. Its contents will appear transparen...
Definition: parsev2.h:332
StringList::const_iterator StringListIt
Iterator into a StringList.
Definition: parsev2.h:74
A smart enum for converting SQL type strings to one of a relatively few types we directly support.
Definition: parsev2.h:253
@ ft_double
DOUBLE, DECIMAL, FIXED, NUMERIC.
Definition: parsev2.h:275
LineListIt begin() const
Get an iterator pointing to the start of our LineList.
Definition: parsev2.h:623
Value
Known SQL field types.
Definition: parsev2.h:269
@ ft_date
DATE.
Definition: parsev2.h:278
@ ft_blob
*BLOB, VARBINARY
Definition: parsev2.h:277
bool read_line(std::string &line, bool &subdirective)
Read a line in from a file.
Definition: parsev2.cpp:406
void print(std::ostream &os) const
Print field description out to a stream in SSQLS v2 form.
Definition: parsev2.cpp:239
Base class for known SSQLS v2 'option' directives.
Definition: parsev2.h:375
LineListIt end() const
Get an iterator pointing just past the end of our LineList.
Definition: parsev2.h:632
virtual ~Option()
Virtual dtor, since this is a base class.
Definition: parsev2.h:379
'include' directive line
Definition: parsev2.h:324
LineListIt begin() const
Get an iterator pointing to the start of the.
Definition: parsev2.h:342
const char * name() const
Return the file's name.
Definition: parsev2.h:96
ParseV2(const char *file_name)
Constructor.
Definition: parsev2.cpp:52
void print(std::ostream &os) const
Print the option description out to a stream in SSQLS v2 form.
Definition: parsev2.cpp:122
void print(std::ostream &os) const
Print the table description out to a stream in SSQLS v2 form.
Definition: parsev2.cpp:645
'field' directive line
Definition: parsev2.h:200
@ ft_bigint
BIGINT, INT8.
Definition: parsev2.h:273
ParseException(const std::string &what, const std::string &file_name, size_t line)
Constructor.
Definition: parsev2.h:579