aboutsummaryrefslogtreecommitdiff
path: root/odb/source.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-07-22 14:33:21 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-07-22 14:33:21 +0200
commitcea6fb57ac8c9a893c0f404fef6c1469f0b6222b (patch)
treefed8b6ffa8ea2cb6347ece69c0cb81003d0ccbf6 /odb/source.cxx
parent5f71c55a1c24c23af1eeb0d664922497a0e5c071 (diff)
Next chunk of functionality
Add SQL language lexer. Implement MySQL type declaration parser. Create sub-directories for databases, currently mysql and tracer. Create MySQL-specific context.
Diffstat (limited to 'odb/source.cxx')
-rw-r--r--odb/source.cxx148
1 files changed, 0 insertions, 148 deletions
diff --git a/odb/source.cxx b/odb/source.cxx
deleted file mode 100644
index 168dfae..0000000
--- a/odb/source.cxx
+++ /dev/null
@@ -1,148 +0,0 @@
-// file : odb/source.cxx
-// author : Boris Kolpackov <boris@codesynthesis.com>
-// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
-// license : GNU GPL v2; see accompanying LICENSE file
-
-#include <odb/common.hxx>
-#include <odb/source.hxx>
-
-namespace
-{
- struct class_: traversal::class_, context
- {
- class_ (context& c)
- : context (c)
- {
- }
-
- virtual void
- traverse (type& c)
- {
- if (c.file () != unit.file ())
- return;
-
- if (!c.count ("object"))
- return;
-
- string const& type (c.fq_name ());
- string traits ("access::object_traits< " + type + " >");
-
- id_member t (*this);
- t.traverse (c);
- semantics::data_member& id (*t.member ());
-
- os << "// " << c.name () << endl
- << "//" << endl
- << endl;
-
- // type_name ()
- //
- os << "const char* " << traits << "::" << endl
- << "type_name ()"
- << "{"
- << "return \"" << type << "\";"
- << "}";
-
- // insert ()
- //
- os << "void " << traits << "::" << endl
- << "insert (database&, object_type& obj)"
- << "{"
- << "std::cout << \"insert \" << type_name () << \" id \" << " <<
- "id (obj) << std::endl;"
- << endl
- << "if (id (obj) == id_type ())" << endl
- << "throw object_already_persistent ();"
- << "}";
-
- // update ()
- //
- os << "void " << traits << "::" << endl
- << "update (database&, object_type& obj)"
- << "{"
- << "std::cout << \"update \" << type_name () << \" id \" << " <<
- "id (obj) << std::endl;"
- << endl
- << "if (id (obj) == id_type ())" << endl
- << "throw object_not_persistent ();"
- << "}";
-
- // erase ()
- //
- os << "void " << traits << "::" << endl
- << "erase (database&, const id_type& id)"
- << "{"
- << "std::cout << \"delete \" << type_name () << \" id \" << " <<
- "id << std::endl;"
- << endl
- << "if (id == id_type ())" << endl
- << "throw object_not_persistent ();"
- << "}";
-
- // find ()
- //
- os << traits << "::pointer_type" << endl
- << traits << "::" << endl
- << "find (database&, const id_type& id)"
- << "{"
- << "std::cout << \"select \" << type_name () << \" id \" << " <<
- "id << std::endl;"
- << endl
- << "if (id == id_type ())" << endl
- << "return pointer_type (0);"
- << endl
- << "pointer_type r (access::object_factory< " << type <<
- " >::create ());"
- << "r->" << id.name () << " = id;"
- << "return r;"
- << "}";
-
- os << "bool " << traits << "::" << endl
- << "find (database&, const id_type& id, object_type& obj)"
- << "{"
- << "std::cout << \"select \" << type_name () << \" id \" << " <<
- "id << std::endl;"
- << endl
- << "if (id == id_type ())" << endl
- << "return false;"
- << endl
- << "obj." << id.name () << " = id;"
- << "return true;"
- << "}";
- }
- };
-}
-
-void
-generate_source (context& ctx)
-{
- traversal::unit unit;
- traversal::defines unit_defines;
- traversal::namespace_ ns;
- class_ c (ctx);
-
- unit >> unit_defines >> ns;
- unit_defines >> c;
-
- traversal::defines ns_defines;
-
- ns >> ns_defines >> ns;
- ns_defines >> c;
-
- ctx.os << "#include <iostream>" << endl
- << endl;
-
- ctx.os << "#include <odb/exceptions.hxx>" << endl
- << endl;
-
- //ctx.os << "#include <odb/tracer/database.hxx>" << endl
- // << "#include <odb/tracer/exceptions.hxx>" << endl
- // << endl;
-
- ctx.os << "namespace odb"
- << "{";
-
- unit.dispatch (ctx.unit);
-
- ctx.os << "}";
-}