aboutsummaryrefslogtreecommitdiff
path: root/build2/variable.ixx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-03-28 15:59:06 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-03-28 16:03:35 +0200
commit96f2131e593e206f0e458409f22adfff8c1b5356 (patch)
treefdb71a7a435d631872e0413dbe13113a636932de /build2/variable.ixx
parent69801c4e23f877359118e55ed291737f4fbece04 (diff)
Clean up variable usage
Diffstat (limited to 'build2/variable.ixx')
-rw-r--r--build2/variable.ixx121
1 files changed, 121 insertions, 0 deletions
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 <typename T>
+ inline T*
+ cast_null (value& v)
+ {
+ return v ? &cast<T> (v) : nullptr;
+ }
+
+ template <typename T>
+ inline const T*
+ cast_null (const value& v)
+ {
+ return v ? &cast<T> (v) : nullptr;
+ }
+
+ template <typename T>
+ inline T*
+ cast_null (const lookup<value>& l)
+ {
+ return l ? &cast<T> (*l) : nullptr;
+ }
+
+ template <typename T>
+ inline const T*
+ cast_null (const lookup<const value>& l)
+ {
+ return l ? &cast<T> (*l) : nullptr;
+ }
+
+ template <typename T>
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<uint64_t>::
+ assign (value& v, uint64_t x)
+ {
+ if (v.null ())
+ new (&v.data_) uint64_t (x);
+ else
+ v.as<uint64_t> () = x;
+
+ return true;
+ }
+
+ inline bool value_traits<uint64_t>::
+ append (value& v, uint64_t x)
+ {
+ // ADD.
+ //
+ if (v.null ())
+ new (&v.data_) uint64_t (x);
+ else
+ v.as<uint64_t> () += x;
+
+ return true;
+ }
+
+ inline int value_traits<uint64_t>::
+ compare (uint64_t l, uint64_t r)
+ {
+ return l < r ? -1 : (l > r ? 1 : 0);
+ }
+
// string value
//
inline bool value_traits<string>::
@@ -245,6 +305,67 @@ namespace build2
return l.compare (r);
}
+ // path value
+ //
+ inline bool value_traits<path>::
+ assign (value& v, path&& x)
+ {
+ path* p;
+
+ if (v.null ())
+ p = new (&v.data_) path (move (x));
+ else
+ p = &(v.as<path> () = move (x));
+
+ return !p->empty ();
+ }
+
+ inline bool value_traits<path>::
+ append (value& v, path&& x)
+ {
+ path* p;
+
+ if (v.null ())
+ p = new (&v.data_) path (move (x));
+ else
+ {
+ p = &v.as<path> ();
+
+ if (p->empty ())
+ p->swap (x);
+ else
+ *p /= x;
+ }
+
+ return !p->empty ();
+ }
+
+ inline bool value_traits<path>::
+ prepend (value& v, path&& x)
+ {
+ path* p;
+
+ if (v.null ())
+ new (&v.data_) path (move (x));
+ else
+ {
+ p = &v.as<path> ();
+
+ if (!p->empty ())
+ x /= *p;
+
+ p->swap (x);
+ }
+
+ return !p->empty ();
+ }
+
+ inline int value_traits<path>::
+ compare (const path& l, const path& r)
+ {
+ return l.compare (r);
+ }
+
// dir_path value
//
inline bool value_traits<dir_path>::