aboutsummaryrefslogtreecommitdiff
path: root/odb/header.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-03-10 12:07:10 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-03-21 15:40:00 +0200
commitfa1fa57d5fe1cb901520f03e7f802a156aae1034 (patch)
treeb97d57e4a1262add1ff57f76bdbbf9b4b1495e0f /odb/header.cxx
parentb0f28bd39db1732db794c6ba1f02d244bce0641c (diff)
Move the rest of generators to new ctor-less context
Diffstat (limited to 'odb/header.cxx')
-rw-r--r--odb/header.cxx108
1 files changed, 55 insertions, 53 deletions
diff --git a/odb/header.cxx b/odb/header.cxx
index 458c822..140a781 100644
--- a/odb/header.cxx
+++ b/odb/header.cxx
@@ -4,17 +4,15 @@
// license : GNU GPL v3; see accompanying LICENSE file
#include <odb/common.hxx>
-#include <odb/header.hxx>
+#include <odb/context.hxx>
+#include <odb/generate.hxx>
+
+using namespace std;
namespace
{
struct data_member: traversal::data_member, context
{
- data_member (context& c)
- : context (c)
- {
- }
-
virtual void
traverse (semantics::data_member& m)
{
@@ -36,8 +34,7 @@ namespace
struct class_: traversal::class_, context
{
- class_ (context& c)
- : context (c), member_ (c)
+ class_ ()
{
member_names_ >> member_;
}
@@ -77,62 +74,67 @@ namespace
};
}
-void
-generate_header (context& ctx)
+namespace header
{
- ctx.os << "#include <memory>" << endl
- << "#include <cstddef>" << endl // std::size_t
- << endl;
-
- ctx.os << "#include <odb/core.hxx>" << endl
- << "#include <odb/traits.hxx>" << endl
- << "#include <odb/pointer-traits.hxx>" << endl;
-
- // In case of a boost TR1 implementation, we cannot distinguish
- // between the boost::shared_ptr and std::tr1::shared_ptr usage since
- // the latter is just a using-declaration for the former. To resolve
- // this we will include TR1 traits if the Boost TR1 header is included.
- //
- if (ctx.unit.count ("tr1-pointer-used") &&
- ctx.unit.get<bool> ("tr1-pointer-used"))
- {
- ctx.os << "#include <odb/tr1/pointer-traits.hxx>" << endl;
- }
- else if (ctx.unit.count ("boost-pointer-used") &&
- ctx.unit.get<bool> ("boost-pointer-used"))
+ void
+ generate ()
{
- ctx.os << "#ifdef BOOST_TR1_MEMORY_HPP_INCLUDED" << endl
- << "# include <odb/tr1/pointer-traits.hxx>" << endl
- << "#endif" << endl;
- }
-
- ctx.os << "#include <odb/container-traits.hxx>" << endl;
+ context ctx;
+ ostream& os (ctx.os);
+
+ os << "#include <memory>" << endl
+ << "#include <cstddef>" << endl // std::size_t
+ << endl;
+
+ os << "#include <odb/core.hxx>" << endl
+ << "#include <odb/traits.hxx>" << endl
+ << "#include <odb/pointer-traits.hxx>" << endl;
+
+ // In case of a boost TR1 implementation, we cannot distinguish
+ // between the boost::shared_ptr and std::tr1::shared_ptr usage since
+ // the latter is just a using-declaration for the former. To resolve
+ // this we will include TR1 traits if the Boost TR1 header is included.
+ //
+ if (ctx.unit.count ("tr1-pointer-used") &&
+ ctx.unit.get<bool> ("tr1-pointer-used"))
+ {
+ os << "#include <odb/tr1/pointer-traits.hxx>" << endl;
+ }
+ else if (ctx.unit.count ("boost-pointer-used") &&
+ ctx.unit.get<bool> ("boost-pointer-used"))
+ {
+ os << "#ifdef BOOST_TR1_MEMORY_HPP_INCLUDED" << endl
+ << "# include <odb/tr1/pointer-traits.hxx>" << endl
+ << "#endif" << endl;
+ }
- if (ctx.options.generate_query ())
- ctx.os << "#include <odb/result.hxx>" << endl;
+ os << "#include <odb/container-traits.hxx>" << endl;
- ctx.os << endl;
+ if (ctx.options.generate_query ())
+ os << "#include <odb/result.hxx>" << endl;
+ os << endl;
- /*
- traversal::unit unit;
- traversal::defines unit_defines;
- traversal::namespace_ ns;
- class_ c (ctx);
+ /*
+ traversal::unit unit;
+ traversal::defines unit_defines;
+ traversal::namespace_ ns;
+ class_ c;
- unit >> unit_defines >> ns;
- unit_defines >> c;
+ unit >> unit_defines >> ns;
+ unit_defines >> c;
- traversal::defines ns_defines;
+ traversal::defines ns_defines;
- ns >> ns_defines >> ns;
- ns_defines >> c;
+ ns >> ns_defines >> ns;
+ ns_defines >> c;
- ctx.os << "namespace odb"
+ os << "namespace odb"
<< "{";
- unit.dispatch (ctx.unit);
+ unit.dispatch (ctx.unit);
- ctx.os << "}";
- */
+ os << "}";
+ */
+ }
}