Loading...
Searching...
No Matches
basic_string_stream.h
Go to the documentation of this file.
/******************************************************************************
The MIT License(MIT)
Embedded Template Library.
https://github.com/ETLCPP/etl
https://www.etlcpp.com
Copyright(c) 2020 John Wellbelove
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files(the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions :
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
******************************************************************************/
#ifndef ETL_BASIC_STRING_STREAM_INCLUDED
#define ETL_BASIC_STRING_STREAM_INCLUDED
#include "platform.h"
#include "to_string.h"
#include "to_u16string.h"
#include "to_u32string.h"
#include "to_u8string.h"
#include "to_wstring.h"
namespace etl
{
template <typename TFormat, typename TIString, typename TStringView>
class basic_string_stream
{
public:
typedef TFormat format_spec_type;
typedef TIString istring_type;
typedef typename TIString::value_type value_type;
typedef typename TIString::pointer pointer;
typedef typename TIString::const_pointer const_pointer;
//*************************************************************************
//*************************************************************************
explicit basic_string_stream(TIString& text_)
: text(text_)
{
}
//*************************************************************************
//*************************************************************************
basic_string_stream(TIString& text_, const TFormat& spec_)
: text(text_)
, format(spec_)
{
}
//*************************************************************************
//*************************************************************************
void set_format(const TFormat& spec_)
{
format = spec_;
}
//*************************************************************************
//*************************************************************************
const TFormat& get_format() const
{
return format;
}
//*************************************************************************
//*************************************************************************
TIString& str()
{
return text;
}
//*************************************************************************
//*************************************************************************
const TIString& str() const
{
return text;
}
//*************************************************************************
//*************************************************************************
void str(const value_type* p)
{
text.assign(p);
}
//*************************************************************************
//*************************************************************************
void str(const TIString& is)
{
text.assign(is);
}
//*************************************************************************
//*************************************************************************
//*********************************
//*********************************
friend basic_string_stream& operator<<(basic_string_stream& ss, const TFormat& fmt)
{
ss.format = fmt;
return ss;
}
//*********************************
//*********************************
friend basic_string_stream& operator<<(basic_string_stream& ss, etl::private_basic_format_spec::base_spec fmt)
{
ss.format.base(fmt.base);
return ss;
}
//*********************************
//*********************************
friend basic_string_stream& operator<<(basic_string_stream& ss, etl::private_basic_format_spec::width_spec fmt)
{
ss.format.width(fmt.width);
return ss;
}
//*********************************
//*********************************
template <typename TChar>
friend basic_string_stream& operator<<(basic_string_stream& ss, etl::private_basic_format_spec::fill_spec<TChar> fmt)
{
ss.format.fill(fmt.fill);
return ss;
}
//*********************************
//*********************************
friend basic_string_stream& operator<<(basic_string_stream& ss, etl::private_basic_format_spec::precision_spec fmt)
{
ss.format.precision(fmt.precision);
return ss;
}
//*********************************
//*********************************
friend basic_string_stream& operator<<(basic_string_stream& ss, etl::private_basic_format_spec::boolalpha_spec fmt)
{
ss.format.boolalpha(fmt.boolalpha);
return ss;
}
//*********************************
//*********************************
friend basic_string_stream& operator<<(basic_string_stream& ss, etl::private_basic_format_spec::uppercase_spec fmt)
{
ss.format.upper_case(fmt.upper_case);
return ss;
}
//*********************************
//*********************************
friend basic_string_stream& operator<<(basic_string_stream& ss, etl::private_basic_format_spec::showbase_spec fmt)
{
ss.format.show_base(fmt.show_base);
return ss;
}
//*********************************
//*********************************
friend basic_string_stream& operator<<(basic_string_stream& ss, etl::private_basic_format_spec::left_spec /*fmt*/)
{
ss.format.left();
return ss;
}
//*********************************
//*********************************
friend basic_string_stream& operator<<(basic_string_stream& ss, etl::private_basic_format_spec::right_spec /*fmt*/)
{
ss.format.right();
return ss;
}
//*********************************
//*********************************
friend basic_string_stream& operator<<(basic_string_stream& ss, TStringView view)
{
etl::to_string(view, ss.text, ss.format, true);
return ss;
}
//*********************************
//*********************************
friend basic_string_stream& operator<<(basic_string_stream& ss, pointer p)
{
TStringView view(p);
ss << view;
return ss;
}
//*********************************
//*********************************
friend basic_string_stream& operator<<(basic_string_stream& ss, const_pointer p)
{
TStringView view(p);
ss << view;
return ss;
}
//*********************************
//*********************************
friend basic_string_stream& operator<<(basic_string_stream& ss, const TIString& t)
{
etl::to_string(t, ss.text, ss.format, true);
return ss;
}
//*********************************
//*********************************
template <template <size_t> class TString, size_t SIZE>
friend basic_string_stream& operator<<(basic_string_stream& ss, const TString<SIZE>& t)
{
const TIString& itext = t;
etl::to_string(itext, ss.str(), ss.get_format(), true);
return ss;
}
//*********************************
//*********************************
template <typename T>
friend basic_string_stream& operator<<(basic_string_stream& ss, const T& value)
{
etl::to_string(value, ss.text, ss.format, true);
return ss;
}
private:
TIString& text;
TFormat format;
basic_string_stream(const basic_string_stream&) ETL_DELETE;
basic_string_stream& operator=(const basic_string_stream&) ETL_DELETE;
};
} // namespace etl
#endif
etl::basic_string_stream
Definition basic_string_stream.h:47
etl::basic_string_stream::str
void str(const value_type *p)
Resets the stream to the supplied string.
Definition basic_string_stream.h:108
etl::basic_string_stream::operator<<
friend basic_string_stream & operator<<(basic_string_stream &ss, etl::private_basic_format_spec::precision_spec fmt)
etl::precision_spec from etl::setprecision stream manipulator
Definition basic_string_stream.h:166
etl::basic_string_stream::operator<<
friend basic_string_stream & operator<<(basic_string_stream &ss, etl::private_basic_format_spec::uppercase_spec fmt)
Definition basic_string_stream.h:186
etl::basic_string_stream::operator<<
friend basic_string_stream & operator<<(basic_string_stream &ss, pointer p)
From a character pointer to a string.
Definition basic_string_stream.h:232
etl::basic_string_stream::basic_string_stream
basic_string_stream(TIString &text_)
Construct from text.
Definition basic_string_stream.h:59
etl::basic_string_stream::operator<<
friend basic_string_stream & operator<<(basic_string_stream &ss, const TString< SIZE > &t)
From a string.
Definition basic_string_stream.h:262
etl::basic_string_stream::operator<<
friend basic_string_stream & operator<<(basic_string_stream &ss, const TIString &t)
From a string interface.
Definition basic_string_stream.h:252
etl::basic_string_stream::operator<<
friend basic_string_stream & operator<<(basic_string_stream &ss, etl::private_basic_format_spec::showbase_spec fmt)
Definition basic_string_stream.h:196
etl::basic_string_stream::operator<<
friend basic_string_stream & operator<<(basic_string_stream &ss, etl::private_basic_format_spec::left_spec)
etl::left_spec from etl::left stream manipulator
Definition basic_string_stream.h:205
etl::basic_string_stream::str
void str(const TIString &is)
Resets the stream to the supplied string.
Definition basic_string_stream.h:116
etl::basic_string_stream::operator<<
friend basic_string_stream & operator<<(basic_string_stream &ss, const TFormat &fmt)
Stream operators.
Definition basic_string_stream.h:128
etl::basic_string_stream::operator<<
friend basic_string_stream & operator<<(basic_string_stream &ss, const_pointer p)
From a const character pointer to a string.
Definition basic_string_stream.h:242
etl::basic_string_stream::operator<<
friend basic_string_stream & operator<<(basic_string_stream &ss, const T &value)
From anything else.
Definition basic_string_stream.h:273
etl::basic_string_stream::operator<<
friend basic_string_stream & operator<<(basic_string_stream &ss, etl::private_basic_format_spec::width_spec fmt)
etl::width_spec from etl::setw stream manipulator
Definition basic_string_stream.h:147
etl::basic_string_stream::operator<<
friend basic_string_stream & operator<<(basic_string_stream &ss, etl::private_basic_format_spec::base_spec fmt)
Definition basic_string_stream.h:138
etl::basic_string_stream::str
TIString & str()
Get a reference to the current string.
Definition basic_string_stream.h:92
etl::basic_string_stream::operator<<
friend basic_string_stream & operator<<(basic_string_stream &ss, etl::private_basic_format_spec::boolalpha_spec fmt)
Definition basic_string_stream.h:176
etl::basic_string_stream::set_format
void set_format(const TFormat &spec_)
Set the format fmt.
Definition basic_string_stream.h:76
etl::basic_string_stream::operator<<
friend basic_string_stream & operator<<(basic_string_stream &ss, TStringView view)
From a string view.
Definition basic_string_stream.h:223
etl::basic_string_stream::str
const TIString & str() const
Get a const reference to the current string.
Definition basic_string_stream.h:100
etl::basic_string_stream::get_format
const TFormat & get_format() const
Get a const reference to the format fmt.
Definition basic_string_stream.h:84
etl::basic_string_stream::operator<<
friend basic_string_stream & operator<<(basic_string_stream &ss, etl::private_basic_format_spec::right_spec)
etl::right_spec from etl::left stream manipulator
Definition basic_string_stream.h:214
etl::basic_string_stream::basic_string_stream
basic_string_stream(TIString &text_, const TFormat &spec_)
Construct from text and format fmt.
Definition basic_string_stream.h:67
etl::basic_string_stream::operator<<
friend basic_string_stream & operator<<(basic_string_stream &ss, etl::private_basic_format_spec::fill_spec< TChar > fmt)
etl::fill_spec from etl::setfill stream manipulator
Definition basic_string_stream.h:157
etl
Definition absolute.h:40
etl::to_string
etl::enable_if<!etl::is_same< T, etl::istring >::value &&!etl::is_same< T, etl::string_view >::value, constetl::istring & >::type to_string(const T value, etl::istring &str, bool append=false)
Definition to_string.h:50
platform.h
etl::private_basic_format_spec::base_spec
Definition basic_format_spec.h:48
etl::private_basic_format_spec::boolalpha_spec
Definition basic_format_spec.h:104
etl::private_basic_format_spec::fill_spec
Definition basic_format_spec.h:71
etl::private_basic_format_spec::left_spec
Definition basic_format_spec.h:126
etl::private_basic_format_spec::precision_spec
Definition basic_format_spec.h:82
etl::private_basic_format_spec::right_spec
Definition basic_format_spec.h:131
etl::private_basic_format_spec::showbase_spec
Definition basic_format_spec.h:115
etl::private_basic_format_spec::uppercase_spec
Definition basic_format_spec.h:93
etl::private_basic_format_spec::width_spec
Definition basic_format_spec.h:59
to_string.h
to_u16string.h
to_u32string.h
to_u8string.h
to_wstring.h