2021-06-20 14:13:23 +02:00
|
|
|
/*
|
|
|
|
* This file is a part of PikoTools
|
2022-06-30 12:09:22 +02:00
|
|
|
* and is distributed under the 2-Clause BSD licence.
|
2021-06-20 14:13:23 +02:00
|
|
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Tomasz Sowa
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
2022-06-30 12:09:22 +02:00
|
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
2021-06-20 14:13:23 +02:00
|
|
|
*
|
2022-06-30 12:09:22 +02:00
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2021-06-20 14:13:23 +02:00
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
2022-06-30 12:09:22 +02:00
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
2021-06-20 14:13:23 +02:00
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
2022-06-30 12:09:22 +02:00
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
2021-06-20 14:13:23 +02:00
|
|
|
*/
|
|
|
|
|
2022-06-30 12:45:08 +02:00
|
|
|
#ifndef headerfile_pikotools_src_textstream_stream
|
|
|
|
#define headerfile_pikotools_src_textstream_stream
|
2021-06-20 14:13:23 +02:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
2021-06-24 20:52:48 +02:00
|
|
|
#ifdef PT_HAS_MORM_LIBRARY
|
|
|
|
namespace morm
|
|
|
|
{
|
|
|
|
class Model;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-06-20 14:13:23 +02:00
|
|
|
namespace pt
|
|
|
|
{
|
|
|
|
class Space;
|
|
|
|
class Date;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Stream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
virtual ~Stream() {};
|
|
|
|
|
2021-06-24 20:52:48 +02:00
|
|
|
virtual bool is_char_stream() const = 0;
|
|
|
|
virtual bool is_wchar_stream() const = 0;
|
|
|
|
|
2021-06-20 14:13:23 +02:00
|
|
|
virtual void clear() = 0;
|
|
|
|
virtual bool empty() const = 0;
|
|
|
|
virtual size_t size() const = 0;
|
|
|
|
virtual void reserve(size_t len) = 0;
|
|
|
|
virtual size_t capacity() const = 0;
|
|
|
|
|
2021-06-20 16:46:08 +02:00
|
|
|
virtual void to_str(std::string & str, bool clear_string = true) const = 0;
|
|
|
|
virtual void to_str(std::wstring & str, bool clear_string = true) const = 0;
|
|
|
|
|
|
|
|
virtual std::string to_str() const = 0;
|
|
|
|
virtual std::wstring to_wstr() const = 0;
|
2021-06-20 14:13:23 +02:00
|
|
|
|
2021-06-24 20:52:48 +02:00
|
|
|
virtual char get_char(size_t index) const = 0;
|
|
|
|
virtual wchar_t get_wchar(size_t index) const = 0;
|
|
|
|
|
2021-06-20 14:13:23 +02:00
|
|
|
virtual Stream & operator<<(const char * str) = 0;
|
|
|
|
virtual Stream & operator<<(const std::string & str) = 0;
|
|
|
|
virtual Stream & operator<<(const wchar_t * str) = 0;
|
|
|
|
virtual Stream & operator<<(const std::wstring & str) = 0;
|
|
|
|
|
2021-06-24 20:52:48 +02:00
|
|
|
/*
|
|
|
|
* IMPROVEME
|
|
|
|
* https://en.cppreference.com/w/cpp/string
|
|
|
|
* add support for:
|
|
|
|
* char8_t
|
|
|
|
* char16_t
|
|
|
|
* char32_t
|
|
|
|
* const char8_t *
|
|
|
|
* const char16_t *
|
|
|
|
* const char32_t *
|
|
|
|
* std::u8string
|
|
|
|
* std::u16string
|
|
|
|
* std::u32string
|
|
|
|
* std::string_view
|
|
|
|
* std::wstring_view
|
|
|
|
* std::u8string_view
|
|
|
|
* std::u16string_view
|
|
|
|
* std::u32string_view
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2021-06-20 14:13:23 +02:00
|
|
|
virtual Stream & operator<<(char) = 0;
|
|
|
|
virtual Stream & operator<<(unsigned char) = 0;
|
|
|
|
virtual Stream & operator<<(wchar_t) = 0;
|
|
|
|
virtual Stream & operator<<(bool) = 0;
|
|
|
|
virtual Stream & operator<<(short) = 0;
|
|
|
|
virtual Stream & operator<<(int) = 0;
|
|
|
|
virtual Stream & operator<<(long) = 0;
|
|
|
|
virtual Stream & operator<<(long long) = 0;
|
|
|
|
virtual Stream & operator<<(unsigned short) = 0;
|
|
|
|
virtual Stream & operator<<(unsigned int) = 0;
|
|
|
|
virtual Stream & operator<<(unsigned long) = 0;
|
|
|
|
virtual Stream & operator<<(unsigned long long) = 0;
|
|
|
|
virtual Stream & operator<<(float) = 0;
|
|
|
|
virtual Stream & operator<<(double) = 0;
|
|
|
|
virtual Stream & operator<<(long double) = 0;
|
|
|
|
virtual Stream & operator<<(const void *) = 0; // printing a pointer
|
2021-06-24 20:52:48 +02:00
|
|
|
|
|
|
|
virtual Stream & operator<<(const Stream & stream) = 0;
|
2021-06-20 14:13:23 +02:00
|
|
|
virtual Stream & operator<<(const Space & space) = 0;
|
|
|
|
virtual Stream & operator<<(const Date & date) = 0;
|
|
|
|
|
2021-06-24 20:52:48 +02:00
|
|
|
#ifdef PT_HAS_MORM_LIBRARY
|
|
|
|
/*
|
|
|
|
* this Stream base class can be used by other consumers so creating this operator
|
|
|
|
* as a pure virtual would be inconvinient for them if they do not use morm library
|
|
|
|
*/
|
|
|
|
virtual Stream & operator<<(morm::Model & model) { operator<<("serializing morm::Model objects not available"); return *this; };
|
|
|
|
#endif
|
2021-06-20 14:13:23 +02:00
|
|
|
|
2021-06-24 20:52:48 +02:00
|
|
|
virtual Stream & write(const char * buf, size_t len) = 0;
|
|
|
|
virtual Stream & write(const wchar_t * buf, size_t len) = 0;
|
2021-06-20 14:13:23 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|