From 96f2131e593e206f0e458409f22adfff8c1b5356 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 28 Mar 2016 15:59:06 +0200 Subject: Clean up variable usage --- build2/variable | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'build2/variable') diff --git a/build2/variable b/build2/variable index 57debfa..931b4f7 100644 --- a/build2/variable +++ b/build2/variable @@ -200,6 +200,15 @@ namespace build2 template T& cast (const lookup&); template const T& cast (const lookup&); + // As above but returns NULL if the value is NULL (or not defined, in + // case of lookup). + // + template T* cast_null (value&); + template const T* cast_null (const value&); + + template T* cast_null (const lookup&); + template const T* cast_null (const lookup&); + // Assign value type to the value. Variable is normally only used for // diagnostics. // @@ -367,6 +376,20 @@ namespace build2 static const build2::value_type value_type; }; + template <> + struct value_traits + { + static_assert (sizeof (uint64_t) <= value::size_, "insufficient space"); + + static uint64_t convert (name&&, name*); + static bool assign (value&, uint64_t); + static bool append (value&, uint64_t); // ADD. + static name reverse (uint64_t x) {return name (to_string (x));} + static int compare (uint64_t, uint64_t); + + static const build2::value_type value_type; + }; + // string // template <> @@ -384,6 +407,23 @@ namespace build2 static const build2::value_type value_type; }; + // path + // + template <> + struct value_traits + { + static_assert (sizeof (path) <= value::size_, "insufficient space"); + + static path convert (name&&, name*); + static bool assign (value&, path&&); + static bool append (value&, path&&); // operator/ + static bool prepend (value&, path&&); // operator/ + static name reverse (const path& x) {return name (x.string ());} + static int compare (const path&, const path&); + + static const build2::value_type value_type; + }; + // dir_path // template <> -- cgit v1.1