aboutsummaryrefslogtreecommitdiff
path: root/build2/variable.cxx
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.cxx
parent69801c4e23f877359118e55ed291737f4fbece04 (diff)
Clean up variable usage
Diffstat (limited to 'build2/variable.cxx')
-rw-r--r--build2/variable.cxx79
1 files changed, 79 insertions, 0 deletions
diff --git a/build2/variable.cxx b/build2/variable.cxx
index c15a773..7b7f16d 100644
--- a/build2/variable.cxx
+++ b/build2/variable.cxx
@@ -316,6 +316,43 @@ namespace build2
nullptr // No compare (compare as POD).
};
+ // uint64_t value
+ //
+ uint64_t value_traits<uint64_t>::
+ convert (name&& n, name* r)
+ {
+ if (r == nullptr && n.simple ())
+ {
+ try
+ {
+ // May throw invalid_argument or out_of_range.
+ //
+ return stoull (n.value);
+ }
+ catch (const out_of_range&)
+ {
+ // Fall through.
+ }
+ }
+
+ throw invalid_argument (string ());
+ }
+
+ const value_type value_traits<uint64_t>::value_type
+ {
+ "uint64",
+ sizeof (uint64_t),
+ nullptr, // No dtor (POD).
+ nullptr, // No copy_ctor (POD).
+ nullptr, // No copy_assign (POD).
+ &simple_assign<uint64_t, false>, // No empty value.
+ &simple_append<uint64_t, false>,
+ &simple_append<uint64_t, false>, // Prepend same as append.
+ &simple_reverse<uint64_t>,
+ nullptr, // No cast (cast data_ directly).
+ nullptr // No compare (compare as POD).
+ };
+
// string value
//
string value_traits<string>::
@@ -399,6 +436,48 @@ namespace build2
&simple_compare<string>
};
+ // path value
+ //
+ path value_traits<path>::
+ convert (name&& n, name* r)
+ {
+ if (r == nullptr)
+ {
+ // A directory path is a path.
+ //
+ if (n.directory ())
+ return move (n.dir);
+
+ if (n.simple ())
+ {
+ try
+ {
+ return path (move (n.value));
+ }
+ catch (const invalid_path&) {} // Fall through.
+ }
+
+ // Fall through.
+ }
+
+ throw invalid_argument (string ());
+ }
+
+ const value_type value_traits<path>::value_type
+ {
+ "path",
+ sizeof (path),
+ &default_dtor<path>,
+ &default_copy_ctor<path>,
+ &default_copy_assign<path>,
+ &simple_assign<path, true>, // Allow empty paths.
+ &simple_append<path, true>,
+ &simple_prepend<path, true>,
+ &simple_reverse<path>,
+ nullptr, // No cast (cast data_ directly).
+ &simple_compare<path>
+ };
+
// dir_path value
//
dir_path value_traits<dir_path>::