From e07d1d419f49435b077fb9b628ab969508f3ff87 Mon Sep 17 00:00:00 2001 From: BenLangmead Date: Mon, 13 Mar 2017 17:29:47 -0400 Subject: [PATCH] overload output operator for some SStringExpandable operations --- sstring.h | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 58 insertions(+), 7 deletions(-) diff --git a/sstring.h b/sstring.h index 06bdbe7..956a638 100644 --- a/sstring.h +++ b/sstring.h @@ -501,7 +501,7 @@ inline const char * sstr_to_cstr >( */ template class SString { - + public: explicit SString() : @@ -519,7 +519,7 @@ class SString { } /** - * Create an SStringExpandable from another SStringExpandable. + * Create an SString from another SString. */ SString(const SString& o) : cs_(NULL), @@ -530,7 +530,7 @@ class SString { } /** - * Create an SStringExpandable from a std::basic_string of the + * Create an SString from a std::basic_string of the * appropriate type. */ explicit SString(const std::basic_string& str) : @@ -542,7 +542,7 @@ class SString { } /** - * Create an SStringExpandable from an array and size. + * Create an SString from an array and size. */ explicit SString(const T* b, size_t sz) : cs_(NULL), @@ -553,7 +553,7 @@ class SString { } /** - * Create an SStringExpandable from a zero-terminated array. + * Create an SString from a zero-terminated array. */ explicit SString(const T* b) : cs_(NULL), @@ -907,7 +907,7 @@ class S2bDnaString { } /** - * Create an SStringExpandable from a std::basic_string of the + * Create an S2bDnaString from a std::basic_string of the * appropriate type. */ explicit S2bDnaString( @@ -930,7 +930,7 @@ class S2bDnaString { } /** - * Create an SStringExpandable from an array and size. + * Create an S2bDnaString from an array and size. */ explicit S2bDnaString( const char* b, @@ -2118,6 +2118,57 @@ class SStringExpandable { size_t sz_; // size capacity of cs_ }; + +/** + * Use stream operator to append char c. + */ +template +SStringExpandable& operator<<( + SStringExpandable& o, + char c) +{ + o.append(c); + return o; +} + +/** + * Use stream operator to append char c. + */ +template +SStringExpandable& operator<<( + SStringExpandable& o, + const A& i) +{ + char buf[1024]; + itoa10(static_cast(i), buf); + o.append(buf); + return o; +} + +/** + * Use stream operator to append zero-terminated string. + */ +template +SStringExpandable& operator<<( + SStringExpandable& o, + const char *s) +{ + o.append(s); + return o; +} + +/** + * Use stream operator to append C++ string. + */ +template +SStringExpandable& operator<<( + SStringExpandable& o, + const std::string& s) +{ + o.append(s.c_str()); + return o; +} + /** * Simple string class with in-object storage. *