aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-08-13 13:41:26 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-08-13 13:41:26 +0200
commit4eb833507b1a974aa2c6aa89612b85aab3b43407 (patch)
tree830746eef347b65d4f752b2789643cc2c8c9a799
parent5dc5097486637e825c75560317bd2109c5e4bd58 (diff)
Add public_name(), use it in column_name()
-rw-r--r--odb/context.cxx49
-rw-r--r--odb/context.hxx6
2 files changed, 31 insertions, 24 deletions
diff --git a/odb/context.cxx b/odb/context.cxx
index 15d1adb..77ca708 100644
--- a/odb/context.cxx
+++ b/odb/context.cxx
@@ -120,6 +120,28 @@ context::
}
string context::
+public_name (semantics::data_member& m) const
+{
+ string s (m.name ());
+ size_t n (s.size ());
+
+ // Do basic processing: remove trailing and leading underscores
+ // as well as the 'm_' prefix.
+ //
+ // @@ What if the resulting names conflict?
+ //
+ size_t b (0), e (n - 1);
+
+ if (n > 2 && s[0] == 'm' && s[1] == '_')
+ b += 2;
+
+ for (; b <= e && s[b] == '_'; b++) ;
+ for (; e >= b && s[e] == '_'; e--) ;
+
+ return b > e ? s : string (s, b, e - b + 1);
+}
+
+string context::
table_name (semantics::type& t) const
{
if (t.count ("table"))
@@ -131,28 +153,7 @@ table_name (semantics::type& t) const
string context::
column_name (semantics::data_member& m) const
{
- if (m.count ("column"))
- return m.get<string> ("column");
- else
- {
- string s (m.name ());
- size_t n (s.size ());
-
- // Do basic processing: remove trailing and leading underscores
- // as well as the 'm_' prefix.
- //
- // @@ What if the resulting names conflict?
- //
- size_t b (0), e (n - 1);
-
- if (n > 2 && s[0] == 'm' && s[1] == '_')
- b += 2;
-
- for (; b <= e && s[b] == '_'; b++) ;
- for (; e >= b && s[e] == '_'; e--) ;
-
- return b > e ? s : string (s, b, e - b + 1);
- }
+ return m.count ("column") ? m.get<string> ("column") : public_name (m);
}
string context::
@@ -167,11 +168,11 @@ column_type (semantics::data_member& m) const
if (i != data_->type_map_.end ())
return m.count ("id") ? i->second.id_type : i->second.type;
- cerr << m.file () << ":" << m.line () << ":" << m.column ()
+ cerr << m.file () << ":" << m.line () << ":" << m.column () << ":"
<< " error: unable to map C++ type '" << name << "' used in "
<< "data member '" << m.name () << "' to a database type" << endl;
- cerr << m.file () << ":" << m.line () << ":" << m.column ()
+ cerr << m.file () << ":" << m.line () << ":" << m.column () << ":"
<< " info: use '#pragma odb type' to specify the database type"
<< endl;
diff --git a/odb/context.hxx b/odb/context.hxx
index 9f5723a..3ca8d1e 100644
--- a/odb/context.hxx
+++ b/odb/context.hxx
@@ -35,6 +35,12 @@ public:
// Database names and types.
//
public:
+ // Cleaned-up member name that can be used in public interfaces
+ // such as queries, column names, etc.
+ //
+ string
+ public_name (semantics::data_member&) const;
+
string
table_name (semantics::type&) const;