From febb9c275b5247df596876e4eea7fa17b7ec45e7 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 22 Aug 2018 17:26:08 +0200 Subject: Add support for UUID generation --- libbutl/uuid-io.cxx | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 libbutl/uuid-io.cxx (limited to 'libbutl/uuid-io.cxx') diff --git a/libbutl/uuid-io.cxx b/libbutl/uuid-io.cxx new file mode 100644 index 0000000..7eed134 --- /dev/null +++ b/libbutl/uuid-io.cxx @@ -0,0 +1,43 @@ +// file : libbutl/uuid-io.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2018 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include + +#include +#include +#include // invalid_argument + +using namespace std; + +namespace butl +{ + ostream& + operator<< (ostream& os, const uuid& u) + { + return os << u.c_string ().data (); + } + + istream& + operator>> (istream& is, uuid& u) + { + u = uuid (); + + char s[37]; + if (is.read (s, 36)) + { + s[36] ='\0'; + + try + { + u = uuid (s); + } + catch (const invalid_argument&) + { + is.setstate (istream::failbit); + } + } + + return is; + } +} -- cgit v1.1