aboutsummaryrefslogtreecommitdiff
path: root/build2/variable.ixx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-04-11 09:20:49 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-04-11 09:20:49 +0200
commit9da5febf1d9af9f5cb62d5d35fc87136e6e4cd60 (patch)
tree6a8d1f857810787cb6e25e6b416ac8bd5eb8b3d7 /build2/variable.ixx
parent0342dc2fcdd78ef28a4e59d84193a3807068d726 (diff)
Add basic support for variable value inheritance
Currently, only abs_dir_path inherits from dir_path.
Diffstat (limited to 'build2/variable.ixx')
-rw-r--r--build2/variable.ixx16
1 files changed, 13 insertions, 3 deletions
diff --git a/build2/variable.ixx b/build2/variable.ixx
index e52a150..9b29608 100644
--- a/build2/variable.ixx
+++ b/build2/variable.ixx
@@ -81,17 +81,27 @@ namespace build2
inline const T&
cast (const value& v)
{
- assert (!v.null () && v.type == &value_traits<T>::value_type);
+ assert (!v.null ());
+
+ // Find base if any.
+ //
+ const value_type* b (v.type);
+ for (; b != nullptr && b != &value_traits<T>::value_type; b = b->base) ;
+ assert (b != nullptr);
+
return *static_cast<const T*> (v.type->cast == nullptr
? static_cast<const void*> (&v.data_)
- : v.type->cast (v));
+ : v.type->cast (v, b));
}
template <typename T>
inline T&
cast (value& v)
{
- return const_cast<T&> (cast<T> (static_cast<const value&> (v)));
+ assert (!v.null () && v.type == &value_traits<T>::value_type);
+ return *static_cast<T*> (v.type->cast == nullptr
+ ? static_cast<void*> (&v.data_)
+ : const_cast<void*> (v.type->cast (v, v.type)));
}
template <typename T>