From afc8cbf6fad71317ee11b6e6374f8f3ce4816197 Mon Sep 17 00:00:00 2001 From: Timo Weingärtner Date: Mon, 14 Apr 2014 21:38:45 +0200 Subject: rfc4251*: add constructors from std::istream and use them --- rfc4251.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'rfc4251.h') diff --git a/rfc4251.h b/rfc4251.h index 98734bf..2d01215 100644 --- a/rfc4251.h +++ b/rfc4251.h @@ -45,6 +45,7 @@ struct rfc4251byte { rfc4251byte () = default; explicit rfc4251byte (uint8_t v) : value(v) {} + inline explicit rfc4251byte (std::istream &); operator uint8_t () const { return value; } }; @@ -57,6 +58,9 @@ inline std::ostream & operator<< (std::ostream & os, rfc4251byte const & x) { return os.write(x.buf, sizeof(x.buf)); } +inline rfc4251byte::rfc4251byte (std::istream & is) { + is >> *this; +} struct rfc4251bool { union { @@ -66,6 +70,7 @@ struct rfc4251bool { rfc4251bool () = default; explicit rfc4251bool (uint8_t v) : value(v) {} + inline explicit rfc4251bool (std::istream &); operator uint8_t () const { return value; } }; @@ -78,6 +83,9 @@ inline std::ostream & operator<< (std::ostream & os, rfc4251bool const & x) { return os.write(x.buf, sizeof(x.buf)); } +inline rfc4251bool::rfc4251bool (std::istream & is) { + is >> *this; +} struct rfc4251uint32 { union { @@ -87,6 +95,7 @@ struct rfc4251uint32 { rfc4251uint32 () = default; explicit rfc4251uint32 (uint32_t v) { value = htonl(v); } + inline explicit rfc4251uint32 (std::istream &); operator uint32_t () const { return ntohl(value); } }; @@ -99,6 +108,9 @@ inline std::ostream & operator<< (std::ostream & os, rfc4251uint32 const & x) { return os.write(x.buf, sizeof(x.buf)); } +inline rfc4251uint32::rfc4251uint32 (std::istream & is) { + is >> *this; +} struct rfc4251uint64 { union { @@ -108,6 +120,7 @@ struct rfc4251uint64 { rfc4251uint64 () = default; inline explicit rfc4251uint64 (uint64_t v); + inline explicit rfc4251uint64 (std::istream &); inline explicit operator uint64_t () const; }; @@ -136,6 +149,9 @@ inline std::ostream & operator<< (std::ostream & os, rfc4251uint64 const & x) { return os.write(x.buf, sizeof(x.buf)); } +inline rfc4251uint64::rfc4251uint64 (std::istream & is) { + is >> *this; +} struct rfc4251string : boost::totally_ordered { std::vector value; @@ -147,6 +163,7 @@ struct rfc4251string : boost::totally_ordered { explicit rfc4251string (std::vector const &); explicit rfc4251string (mpz_srcptr); explicit rfc4251string (mpz_class const & x) : rfc4251string{x.get_mpz_t()} {} + inline explicit rfc4251string (std::istream &); operator std::string () const { return {value.begin(), value.end()}; } operator std::vector () const; @@ -213,6 +230,10 @@ inline std::ostream & operator<< (std::ostream & os, rfc4251string const & s) { return os; } +inline rfc4251string::rfc4251string (std::istream & is) { + is >> *this; +} + inline bool operator== (rfc4251string const & l, rfc4251string const & r) { return l.value == r.value; } -- cgit v1.2.3