mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-19 13:03:36 +00:00
Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run: git remote add om-historic [om-historic.git repo url] git fetch --tags om-historic git replace squashed-history historic-commits
This commit is contained in:
82
coding/streams_sink.hpp
Normal file
82
coding/streams_sink.hpp
Normal file
@@ -0,0 +1,82 @@
|
||||
#pragma once
|
||||
|
||||
#include "coding/streams_common.hpp"
|
||||
#include "coding/reader.hpp"
|
||||
#include "coding/write_to_sink.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
namespace stream
|
||||
{
|
||||
template <class TReader> class SinkReaderStream
|
||||
{
|
||||
TReader & m_reader;
|
||||
|
||||
public:
|
||||
SinkReaderStream(TReader & reader) : m_reader(reader) {}
|
||||
|
||||
template <typename T>
|
||||
std::enable_if_t<std::is_integral<T>::value, SinkReaderStream &> operator>>(T & t)
|
||||
{
|
||||
t = ReadPrimitiveFromSource<T>(m_reader);
|
||||
return (*this);
|
||||
}
|
||||
|
||||
SinkReaderStream & operator >> (bool & t)
|
||||
{
|
||||
detail::ReadBool(*this, t);
|
||||
return *this;
|
||||
}
|
||||
|
||||
SinkReaderStream & operator >> (string & t)
|
||||
{
|
||||
detail::ReadString(*this, t);
|
||||
return *this;
|
||||
}
|
||||
|
||||
SinkReaderStream & operator >> (double & t)
|
||||
{
|
||||
static_assert(sizeof(double) == sizeof(int64_t), "");
|
||||
int64_t * tInt = reinterpret_cast<int64_t *>(&t);
|
||||
operator >> (*tInt);
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
template <class TWriter> class SinkWriterStream
|
||||
{
|
||||
TWriter & m_writer;
|
||||
|
||||
public:
|
||||
SinkWriterStream(TWriter & writer) : m_writer(writer) {}
|
||||
|
||||
template <typename T>
|
||||
std::enable_if_t<std::is_integral<T>::value, SinkWriterStream &> operator<<(T const & t)
|
||||
{
|
||||
WriteToSink(m_writer, t);
|
||||
return (*this);
|
||||
}
|
||||
|
||||
SinkWriterStream & operator << (bool t)
|
||||
{
|
||||
detail::WriteBool(*this, t);
|
||||
return (*this);
|
||||
}
|
||||
|
||||
SinkWriterStream & operator<<(std::string const & t)
|
||||
{
|
||||
detail::WriteString(*this, m_writer, t);
|
||||
return *this;
|
||||
}
|
||||
|
||||
SinkWriterStream & operator << (double t)
|
||||
{
|
||||
static_assert(sizeof(double) == sizeof(int64_t), "");
|
||||
int64_t const tInt = *reinterpret_cast<int64_t const *>(&t);
|
||||
operator << (tInt);
|
||||
return (*this);
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user