Class OStringStream

Synopsis

#include <lib/inc/drogon/utils/OStringStream.h>

class OStringStream

Description

No description yet.

Methods

OStringStream
operator<<
reserve
str

Source

Lines 44-139 in lib/inc/drogon/utils/OStringStream.h. Line 45 in lib/inc/drogon/utils/OStringStream.h.

class OStringStream
{
  public:
    OStringStream() = default;
    void reserve(size_t size)
    {
        buffer_.reserve(size);
    }
    template <typename T>
    std::enable_if_t<!internal::CanConvertToString<T>::value, OStringStream&>
    operator<<(T&& value)
    {
        std::stringstream ss;
        ss << std::forward<T>(value);
        buffer_.append(ss.str());
        return *this;
    }
    template <typename T>
    std::enable_if_t<internal::CanConvertToString<T>::value, OStringStream&>
    operator<<(T&& value)
    {
        buffer_.append(std::to_string(std::forward<T>(value)));
        return *this;
    }
    template <int N>
    OStringStream& operator<<(const char (&buf)[N])
    {
        buffer_.append(buf, N - 1);
        return *this;
    }
    OStringStream& operator<<(const string_view& str)
    {
        buffer_.append(str.data(), str.length());
        return *this;
    }
    OStringStream& operator<<(string_view&& str)
    {
        buffer_.append(str.data(), str.length());
        return *this;
    }

    OStringStream& operator<<(const std::string& str)
    {
        buffer_.append(str);
        return *this;
    }
    OStringStream& operator<<(std::string&& str)
    {
        buffer_.append(std::move(str));
        return *this;
    }

    OStringStream& operator<<(const double& d)
    {
        std::stringstream ss;
        ss << d;
        buffer_.append(ss.str());
        return *this;
    }

    OStringStream& operator<<(const float& f)
    {
        std::stringstream ss;
        ss << f;
        buffer_.append(ss.str());
        return *this;
    }

    OStringStream& operator<<(double&& d)
    {
        std::stringstream ss;
        ss << d;
        buffer_.append(ss.str());
        return *this;
    }

    OStringStream& operator<<(float&& f)
    {
        std::stringstream ss;
        ss << f;
        buffer_.append(ss.str());
        return *this;
    }

    std::string& str()
    {
        return buffer_;
    }
    const std::string& str() const
    {
        return buffer_;
    }

  private:
    std::string buffer_;
};





Add Discussion as Guest

Log in to DocsForge