From 94b04d166c1041028571222b9931121b0f7dfded Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 22 May 2017 23:31:10 +0300 Subject: Implement brep-clean --- clean/types-parsers.cxx | 60 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 clean/types-parsers.cxx (limited to 'clean/types-parsers.cxx') diff --git a/clean/types-parsers.cxx b/clean/types-parsers.cxx new file mode 100644 index 0000000..26b9a02 --- /dev/null +++ b/clean/types-parsers.cxx @@ -0,0 +1,60 @@ +// file : clean/types-parsers.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include +#include // strtoull() + +#include + +#include +#include // cli namespace + +using namespace std; +using namespace brep; + +namespace cli +{ + void parser:: + parse (toolchain_timeouts& x, bool& xs, scanner& s) + { + const char* o (s.next ()); + + if (!s.more ()) + throw missing_value (o); + + string ov (s.next ()); + size_t p (ov.find ('=')); + + timestamp now (timestamp::clock::now ()); + + // Convert timeout duration into the time point. + // + auto timeout = [o, &ov, &now] (const string& tm) -> timestamp + { + char* e (nullptr); + uint64_t t (strtoull (tm.c_str (), &e, 10)); + + if (*e != '\0' || tm.empty ()) + throw invalid_value (o, ov); + + if (t == 0) + return timestamp_nonexistent; + + return now - chrono::duration> (t); + }; + + if (p == string::npos) + x[string ()] = timeout (ov); // Default timeout. + else + { + string k (ov, 0, p); + if (k.empty ()) + throw invalid_value (o, ov); + + x[k] = timeout (string (ov, p + 1)); + } + + xs = true; + } +} -- cgit v1.1