// file : clean/types-parsers.cxx -*- C++ -*- // copyright : Copyright (c) 2014-2018 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 (system_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; } }