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.ixx | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) (limited to 'build2/variable.ixx') diff --git a/build2/variable.ixx b/build2/variable.ixx index 8a03996..67f8c56 100644 --- a/build2/variable.ixx +++ b/build2/variable.ixx @@ -118,6 +118,34 @@ namespace build2 } template + inline T* + cast_null (value& v) + { + return v ? &cast (v) : nullptr; + } + + template + inline const T* + cast_null (const value& v) + { + return v ? &cast (v) : nullptr; + } + + template + inline T* + cast_null (const lookup& l) + { + return l ? &cast (*l) : nullptr; + } + + template + inline const T* + cast_null (const lookup& l) + { + return l ? &cast (*l) : nullptr; + } + + template inline void typify (value& v, const variable& var) { @@ -184,6 +212,38 @@ namespace build2 return l < r ? -1 : (l > r ? 1 : 0); } + // uint64_t value + // + inline bool value_traits:: + assign (value& v, uint64_t x) + { + if (v.null ()) + new (&v.data_) uint64_t (x); + else + v.as () = x; + + return true; + } + + inline bool value_traits:: + append (value& v, uint64_t x) + { + // ADD. + // + if (v.null ()) + new (&v.data_) uint64_t (x); + else + v.as () += x; + + return true; + } + + inline int value_traits:: + compare (uint64_t l, uint64_t r) + { + return l < r ? -1 : (l > r ? 1 : 0); + } + // string value // inline bool value_traits:: @@ -245,6 +305,67 @@ namespace build2 return l.compare (r); } + // path value + // + inline bool value_traits:: + assign (value& v, path&& x) + { + path* p; + + if (v.null ()) + p = new (&v.data_) path (move (x)); + else + p = &(v.as () = move (x)); + + return !p->empty (); + } + + inline bool value_traits:: + append (value& v, path&& x) + { + path* p; + + if (v.null ()) + p = new (&v.data_) path (move (x)); + else + { + p = &v.as (); + + if (p->empty ()) + p->swap (x); + else + *p /= x; + } + + return !p->empty (); + } + + inline bool value_traits:: + prepend (value& v, path&& x) + { + path* p; + + if (v.null ()) + new (&v.data_) path (move (x)); + else + { + p = &v.as (); + + if (!p->empty ()) + x /= *p; + + p->swap (x); + } + + return !p->empty (); + } + + inline int value_traits:: + compare (const path& l, const path& r) + { + return l.compare (r); + } + // dir_path value // inline bool value_traits:: -- cgit v1.1