Permalink
Browse files

overload output operator for some SStringExpandable operations

  • Loading branch information...
1 parent f2d79e8 commit e07d1d419f49435b077fb9b628ab969508f3ff87 @BenLangmead committed Mar 13, 2017
Showing with 58 additions and 7 deletions.
  1. +58 −7 sstring.h
View
@@ -501,7 +501,7 @@ inline const char * sstr_to_cstr<std::basic_string<char> >(
*/
template<typename T>
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<T>& 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<T>& 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<typename T, int S, int M, int I>
+SStringExpandable<T, S, M, I>& operator<<(
+ SStringExpandable<T, S, M, I>& o,
+ char c)
+{
+ o.append(c);
+ return o;
+}
+
+/**
+ * Use stream operator to append char c.
+ */
+template<typename T, int S, int M, int I, typename A>
+SStringExpandable<T, S, M, I>& operator<<(
+ SStringExpandable<T, S, M, I>& o,
+ const A& i)
+{
+ char buf[1024];
+ itoa10<A>(static_cast<A>(i), buf);
+ o.append(buf);
+ return o;
+}
+
+/**
+ * Use stream operator to append zero-terminated string.
+ */
+template<typename T, int S, int M, int I>
+SStringExpandable<T, S, M, I>& operator<<(
+ SStringExpandable<T, S, M, I>& o,
+ const char *s)
+{
+ o.append(s);
+ return o;
+}
+
+/**
+ * Use stream operator to append C++ string.
+ */
+template<typename T, int S, int M, int I>
+SStringExpandable<T, S, M, I>& operator<<(
+ SStringExpandable<T, S, M, I>& o,
+ const std::string& s)
+{
+ o.append(s.c_str());
+ return o;
+}
+
/**
* Simple string class with in-object storage.
*

0 comments on commit e07d1d4

Please sign in to comment.