mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-19 21:13:35 +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:
53
coding/streams_common.hpp
Normal file
53
coding/streams_common.hpp
Normal file
@@ -0,0 +1,53 @@
|
||||
#pragma once
|
||||
|
||||
#include "base/base.hpp"
|
||||
#include "base/assert.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
namespace stream
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template <class TStream>
|
||||
void ReadString(TStream & s, std::string & t)
|
||||
{
|
||||
uint32_t count;
|
||||
s >> count;
|
||||
t.reserve(count);
|
||||
|
||||
while (count > 0)
|
||||
{
|
||||
char c;
|
||||
s >> c;
|
||||
t.push_back(c);
|
||||
--count;
|
||||
}
|
||||
}
|
||||
|
||||
template <class TStream, class TWriter>
|
||||
void WriteString(TStream & s, TWriter & w, std::string const & t)
|
||||
{
|
||||
uint32_t const count = static_cast<uint32_t>(t.size());
|
||||
s << count;
|
||||
if (count > 0)
|
||||
w.Write(t.c_str(), count);
|
||||
}
|
||||
|
||||
template <class TStream>
|
||||
void ReadBool(TStream & s, bool & t)
|
||||
{
|
||||
char tt;
|
||||
s >> tt;
|
||||
ASSERT(tt == 0 || tt == 1, (tt));
|
||||
t = (tt != 0);
|
||||
}
|
||||
|
||||
template <class TStream>
|
||||
void WriteBool(TStream & s, bool t)
|
||||
{
|
||||
s << char(t ? 1 : 0);
|
||||
}
|
||||
} // namespace detail
|
||||
} // namespace stream
|
||||
Reference in New Issue
Block a user