diff --git a/CMakeLists.txt b/CMakeLists.txt index 21da841e..6fd51e4d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -388,8 +388,10 @@ list ( nocopy.hpp parallel/queue.cpp parallel/queue.hpp - parse.cpp - parse.hpp + parse/value.cpp + parse/value.hpp + parse/si.cpp + parse/si.hpp platform.hpp point.cpp point.hpp @@ -419,10 +421,8 @@ list ( region.hpp roots/bisection.hpp scoped.hpp - si.cpp signal.cpp signal.hpp - si.hpp singleton.hpp stats.cpp stats.hpp diff --git a/colour.cpp b/colour.cpp index ee35eebe..acc55084 100644 --- a/colour.cpp +++ b/colour.cpp @@ -9,7 +9,7 @@ #include "colour.hpp" #include "ascii.hpp" -#include "parse.hpp" +#include "parse/value.hpp" /////////////////////////////////////////////////////////////////////////////// @@ -45,7 +45,7 @@ parse_hex (cruft::view &str) /////////////////////////////////////////////////////////////////////////////// template <> cruft::srgba4f -cruft::parse (cruft::view &str) +cruft::parse::value (cruft::view &str) { return parse_hex (str); } \ No newline at end of file diff --git a/job/queue.cpp b/job/queue.cpp index 18e21731..da2d1aac 100644 --- a/job/queue.cpp +++ b/job/queue.cpp @@ -8,7 +8,7 @@ #include "queue.hpp" -#include "../parse.hpp" +#include "../parse/value.hpp" #include "../scoped.hpp" using cruft::job::queue; @@ -19,7 +19,7 @@ unsigned queue::default_parallelism (void) noexcept { if (auto var = getenv ("JOB_THREADS")) { - return cruft::from_string (var); + return cruft::parse::from_string (var); } return std::thread::hardware_concurrency (); @@ -31,7 +31,7 @@ static unsigned default_depth (void) { if (auto var = getenv ("JOB_DEPTH")) { - return cruft::from_string (var); + return cruft::parse::from_string (var); } return 1024; diff --git a/si.cpp b/parse/si.cpp similarity index 84% rename from si.cpp rename to parse/si.cpp index 0de87490..fd2306e7 100644 --- a/si.cpp +++ b/parse/si.cpp @@ -8,21 +8,20 @@ #include "si.hpp" -#include "std.hpp" -#include "parse.hpp" +#include "value.hpp" + +#include "../std.hpp" #include -#include - /////////////////////////////////////////////////////////////////////////////// template cruft::expected -cruft::si::parse (cruft::view const src) +cruft::parse::si (cruft::view const src) { auto remain = src; - ValueT dst = cruft::parse (remain); + ValueT dst = cruft::parse::value (remain); switch (remain.size ()) { case 0: @@ -43,7 +42,7 @@ cruft::si::parse (cruft::view const src) /////////////////////////////////////////////////////////////////////////////// -#define INSTANTIATE(KLASS) template cruft::expected cruft::si::parse (cruft::view); +#define INSTANTIATE(KLASS) template cruft::expected cruft::parse::si (cruft::view); MAP0 (INSTANTIATE, diff --git a/si.hpp b/parse/si.hpp similarity index 77% rename from si.hpp rename to parse/si.hpp index a09f8ba3..d30ac4de 100644 --- a/si.hpp +++ b/parse/si.hpp @@ -8,14 +8,14 @@ #pragma once -#include "expected.hpp" -#include "view.hpp" +#include "../expected.hpp" +#include "../view.hpp" #include -namespace cruft::si { +namespace cruft::parse { template expected - parse (cruft::view); + si (cruft::view); } diff --git a/parse.cpp b/parse/value.cpp similarity index 95% rename from parse.cpp rename to parse/value.cpp index a4582132..eac67da7 100644 --- a/parse.cpp +++ b/parse/value.cpp @@ -6,15 +6,15 @@ * Copyright 2017-2018 Danny Robson */ -#include "parse.hpp" +#include "value.hpp" -#include "cast.hpp" +#include "../cast.hpp" #include #include #include -using cruft::parse; +using cruft::parse::value; namespace { /////////////////////////////////////////////////////////////////////////// @@ -96,7 +96,7 @@ namespace { #define C_PARSE_ITERATOR(ITERATOR,PREFIX, KLASS)\ template <> \ KLASS \ -cruft::parse ( \ +cruft::parse::value ( \ cruft::view &str \ ) { \ return c_ ## PREFIX ## parse (str); \ @@ -137,9 +137,9 @@ MAP1(C_PARSE, f, #define C_PARSE_WITH_CAST(FINAL, USED) \ template<> \ FINAL \ -cruft::parse (cruft::view &str) { \ +cruft::parse::value (cruft::view &str) { \ auto remain = str; \ - auto res = parse (remain); \ + auto res = value (remain); \ if (res > std::numeric_limits::max ()) \ throw std::invalid_argument ("overflow during parse"); \ \ diff --git a/parse.hpp b/parse/value.hpp similarity index 85% rename from parse.hpp rename to parse/value.hpp index 82eec852..9a8be6fe 100644 --- a/parse.hpp +++ b/parse/value.hpp @@ -8,17 +8,17 @@ #pragma once -#include "view.hpp" +#include "../view.hpp" -namespace cruft { +namespace cruft::parse { /////////////////////////////////////////////////////////////////////////// /// Extracts an instance of a native type T from the string [first, last). /// /// Throws std::invalid_argument when the type cannot be parsed. /// /// The view is modified in place to reflect the unused data. - template T parse (cruft::view &); - template T parse (cruft::view< char *> &); + template T value (cruft::view &); + template T value (cruft::view< char *> &); /// Parses a prefix string to obtain an instance of T. @@ -30,7 +30,7 @@ namespace cruft { T from_string (cruft::view data) { - T res = parse (data); + T res = value (data); if (!data.empty ()) throw std::invalid_argument ("unable to parse"); return std::move (res); diff --git a/test/parse.cpp b/test/parse.cpp index 4f9475d5..53618d98 100644 --- a/test/parse.cpp +++ b/test/parse.cpp @@ -1,4 +1,4 @@ -#include "parse.hpp" +#include "parse/value.hpp" #include "tap.hpp" @@ -8,11 +8,11 @@ main (void) { cruft::TAP::logger tap; - tap.expect_eq (cruft::from_string ("1"), 1L, "parsing long '1'"); - tap.expect_throw ([] () { cruft::from_string ("a"); }, "parsing long 'a'"); + tap.expect_eq (cruft::parse::from_string ("1"), 1L, "parsing long '1'"); + tap.expect_throw ([] () { cruft::parse::from_string ("a"); }, "parsing long 'a'"); - tap.expect_eq (cruft::from_string ("1"), 1.f, "parsing float '1'"); - tap.expect_throw ([] () { cruft::from_string ("a"); }, "parsing float 'a'"); + tap.expect_eq (cruft::parse::from_string ("1"), 1.f, "parsing float '1'"); + tap.expect_throw ([] () { cruft::parse::from_string ("a"); }, "parsing float 'a'"); return tap.status (); } \ No newline at end of file diff --git a/test/si.cpp b/test/si.cpp index 5c94b13b..73ad0a70 100644 --- a/test/si.cpp +++ b/test/si.cpp @@ -1,5 +1,5 @@ #include "tap.hpp" -#include "si.hpp" +#include "parse/si.hpp" int main () @@ -21,7 +21,7 @@ int main () }; for (auto const &t: TESTS) { - auto res = cruft::si::parse (t.str); + auto res = cruft::parse::si (t.str); if (!res) { tap.fail ("SI parsing %!", t.str); } else {