From a482f1c4dd4efab83d3b19309900f1cbf54383a5 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 15 Oct 2013 07:01:17 +0200 Subject: Automatically map C++11 enum classes (strong enums) --- odb/semantics/enum.hxx | 90 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 86 insertions(+), 4 deletions(-) (limited to 'odb/semantics/enum.hxx') diff --git a/odb/semantics/enum.hxx b/odb/semantics/enum.hxx index de07885..02f2b27 100644 --- a/odb/semantics/enum.hxx +++ b/odb/semantics/enum.hxx @@ -7,6 +7,7 @@ #include #include +#include namespace semantics { @@ -101,7 +102,62 @@ namespace semantics // // - class enum_: public type + class underlies: public edge + { + public: + typedef semantics::enum_ enum_type; + + integral_type& + type () const + { + return *type_; + } + + enum_type& + enum_ () const + { + return *enum__; + } + + // Names edge in terms of which this edge was defined. Can be NULL. + // + public: + void + hint (names& hint) + { + hint_ = &hint; + } + + names* + hint () const + { + return hint_; + } + + public: + underlies (); + + void + set_left_node (integral_type& n) + { + type_ = &n; + } + + void + set_right_node (enum_type& n) + { + enum__ = &n; + } + + protected: + integral_type* type_; + enum_type* enum__; + names* hint_; + }; + + // + // + class enum_: public type, public scope { private: typedef std::vector enumerates_list; @@ -123,14 +179,38 @@ namespace semantics return enumerates_.end (); } + underlies& + underlied () const + { + return *underlied_; + } + + integral_type& + underlying_type () const + { + return underlied_->type (); + } + + names* + underlying_type_hint () const + { + return underlied_->hint (); + } + bool unsigned_ () const { - return unsigned__; + return underlying_type ().unsigned_ (); } public: - enum_ (path const&, size_t line, size_t column, tree, bool unsigned_); + enum_ (path const&, size_t line, size_t column, tree); + + void + add_edge_right (underlies& e) + { + underlied_ = &e; + } void add_edge_left (enumerates& e) @@ -138,9 +218,11 @@ namespace semantics enumerates_.push_back (&e); } + using scope::add_edge_left; + private: - bool unsigned__; enumerates_list enumerates_; + underlies* underlied_; }; } -- cgit v1.1