summaryrefslogtreecommitdiff
path: root/odb
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-11-09 14:52:34 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-11-09 14:52:34 +0200
commit1b2da148946713f57dfe883c25953c488889e5a9 (patch)
tree31740f00d3118acf981726b97354cd205c8f77cb /odb
parentedae7d98cfac5f55782236d397c831f68ebe11a6 (diff)
Add support for standard and custom ODB compilation prologues and epilogues
Diffstat (limited to 'odb')
-rw-r--r--odb/context.hxx21
-rw-r--r--odb/mysql/header.cxx18
-rw-r--r--odb/odb.cxx25
-rw-r--r--odb/options.cli18
4 files changed, 53 insertions, 29 deletions
diff --git a/odb/context.hxx b/odb/context.hxx
index 7fe392b..3fad543 100644
--- a/odb/context.hxx
+++ b/odb/context.hxx
@@ -159,39 +159,18 @@ public:
return *c.get<semantics::type*> ("tree-value-type");
}
- static string
- container_fq_vt (semantics::data_member& m)
- {
- return "container_traits< " + m.type ().fq_name (m.belongs ().hint ()) +
- " >::value_type";
- }
-
static semantics::type&
container_it (semantics::type& c)
{
return *c.get<semantics::type*> ("tree-index-type");
}
- static string
- container_fq_it (semantics::data_member& m)
- {
- return "container_traits< " + m.type ().fq_name (m.belongs ().hint ()) +
- " >::index_type";
- }
-
static semantics::type&
container_kt (semantics::type& c)
{
return *c.get<semantics::type*> ("tree-key-type");
}
- static string
- container_fq_kt (semantics::data_member& m)
- {
- return "container_traits< " + m.type ().fq_name (m.belongs ().hint ()) +
- " >::key_type";
- }
-
protected:
struct data;
typedef cutl::shared_ptr<data> data_ptr;
diff --git a/odb/mysql/header.cxx b/odb/mysql/header.cxx
index b4781f9..195263c 100644
--- a/odb/mysql/header.cxx
+++ b/odb/mysql/header.cxx
@@ -320,6 +320,7 @@ namespace mysql
<< "{";
// container_type
+ // container_traits
// index_type
// key_type
// value_type
@@ -327,18 +328,20 @@ namespace mysql
os << "typedef " << t.fq_name (m.belongs ().hint ()) <<
" container_type;";
+ os << "typedef odb::access::container_traits< container_type > " <<
+ "container_traits;";
switch (ck)
{
case ck_ordered:
{
- os << "typedef " << container_fq_it (m) << " index_type;";
+ os << "typedef container_traits::index_type index_type;";
break;
}
case ck_map:
case ck_multimap:
{
- os << "typedef " << container_fq_kt (m) << " key_type;";
+ os << "typedef container_traits::key_type key_type;";
}
case ck_set:
case ck_multiset:
@@ -347,12 +350,9 @@ namespace mysql
}
}
- os << "typedef " << container_fq_vt (m) << " value_type;"
+ os << "typedef container_traits::value_type value_type;"
<< endl;
- os << "typedef odb::access::container_traits< container_type > " <<
- "container_traits;";
-
// functions_type
//
switch (ck)
@@ -928,8 +928,10 @@ namespace mysql
<< endl;
if (ctx.options.generate_query ())
- ctx.os << "#include <odb/result.hxx>" << endl
- << endl;
+ ctx.os << "#include <odb/result.hxx>" << endl;
+
+ ctx.os << "#include <odb/container-traits.hxx>" << endl
+ << endl;
ctx.os << "#include <odb/mysql/version.hxx>" << endl
<< "#include <odb/mysql/forward.hxx>" << endl
diff --git a/odb/odb.cxx b/odb/odb.cxx
index 2a947f5..1f1d45a 100644
--- a/odb/odb.cxx
+++ b/odb/odb.cxx
@@ -480,6 +480,16 @@ main (int argc, char* argv[])
pi.fd, ios_base::out | ios_base::binary);
ostream os (&fb);
+ // Add custom prologue if any.
+ //
+ strings const& pro (ops.odb_prologue ());
+ for (size_t i (0); i < pro.size (); ++i)
+ {
+ os << "#line 1 \"<odb-prologue-" << i + 1 << ">\"" << endl
+ << pro[i]
+ << endl;
+ }
+
// Write the synthesized translation unit to stdout.
//
os << "#line 1 \"" << escape_path (input) << "\"" << endl;
@@ -490,6 +500,21 @@ main (int argc, char* argv[])
wait_process (pi, argv[0]);
return 1;
}
+
+ // Add the standard epilogue.
+ //
+ os << "#line 1 \"<standard-odb-epilogue>\"" << endl
+ << "#include <odb/container-traits.hxx>" << endl;
+
+ // Add custom epilogue if any.
+ //
+ strings const& epi (ops.odb_epilogue ());
+ for (size_t i (0); i < epi.size (); ++i)
+ {
+ os << "#line 1 \"<odb-epilogue-" << i + 1 << ">\"" << endl
+ << epi[i]
+ << endl;
+ }
}
if (!wait_process (pi, argv[0]))
diff --git a/odb/options.cli b/odb/options.cli
index 5d24f8a..8c9a965 100644
--- a/odb/options.cli
+++ b/odb/options.cli
@@ -218,6 +218,24 @@ class options
schema file."
};
+ // ODB compilation prologue/epilogue.
+ //
+ std::vector<std::string> --odb-prologue
+ {
+ "<text>",
+ "Compile <text> before the input header file. This option allows you
+ to add additional declarations, such as custom traits specializations,
+ to the ODB compilation process."
+ };
+
+ std::vector<std::string> --odb-epilogue
+ {
+ "<text>",
+ "Compile <text> after the input header file. This option allows you
+ to add additional declarations, such as custom traits specializations,
+ to the ODB compilation process."
+ };
+
// Include options.
//
bool --include-with-brackets