aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/binsaver
diff options
context:
space:
mode:
authorAnton Samokhvalov <pg83@yandex.ru>2022-02-10 16:45:15 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:15 +0300
commit72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch)
treeda2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /library/cpp/binsaver
parent778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff)
downloadydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/binsaver')
-rw-r--r--library/cpp/binsaver/bin_saver.cpp18
-rw-r--r--library/cpp/binsaver/bin_saver.h290
-rw-r--r--library/cpp/binsaver/blob_io.h34
-rw-r--r--library/cpp/binsaver/buffered_io.cpp4
-rw-r--r--library/cpp/binsaver/buffered_io.h78
-rw-r--r--library/cpp/binsaver/class_factory.h116
-rw-r--r--library/cpp/binsaver/ut/binsaver_ut.cpp158
-rw-r--r--library/cpp/binsaver/util_stream_io.h76
-rw-r--r--library/cpp/binsaver/ya.make4
9 files changed, 389 insertions, 389 deletions
diff --git a/library/cpp/binsaver/bin_saver.cpp b/library/cpp/binsaver/bin_saver.cpp
index fe0775af9f..36ec9efdfc 100644
--- a/library/cpp/binsaver/bin_saver.cpp
+++ b/library/cpp/binsaver/bin_saver.cpp
@@ -1,19 +1,19 @@
#include "bin_saver.h"
-TClassFactory<IObjectBase>* pSaverClasses;
+TClassFactory<IObjectBase>* pSaverClasses;
void StartRegisterSaveload() {
- if (!pSaverClasses)
+ if (!pSaverClasses)
pSaverClasses = new TClassFactory<IObjectBase>;
}
struct SBasicChunkInit {
- ~SBasicChunkInit() {
- if (pSaverClasses)
- delete pSaverClasses;
- }
+ ~SBasicChunkInit() {
+ if (pSaverClasses)
+ delete pSaverClasses;
+ }
} initSaver;
//////////////////////////////////////////////////////////////////////////
-void IBinSaver::StoreObject(IObjectBase* pObject) {
+void IBinSaver::StoreObject(IObjectBase* pObject) {
if (pObject) {
Y_ASSERT(pSaverClasses->GetObjectTypeID(pObject) != -1 && "trying to save unregistered object");
}
@@ -50,7 +50,7 @@ void IBinSaver::StoreObject(IObjectBase* pObject) {
}
}
-IObjectBase* IBinSaver::LoadObject() {
+IObjectBase* IBinSaver::LoadObject() {
ui64 ptrId = 0;
DataChunk(&ptrId, sizeof(ptrId));
if (ptrId != 0) {
@@ -61,7 +61,7 @@ IObjectBase* IBinSaver::LoadObject() {
return pFound->second;
int typeId;
DataChunk(&typeId, sizeof(typeId));
- IObjectBase* pObj = pSaverClasses->CreateObject(typeId);
+ IObjectBase* pObj = pSaverClasses->CreateObject(typeId);
Y_ASSERT(pObj != nullptr);
if (pObj == nullptr) {
fprintf(stderr, "IBinSaver: trying to load unregistered object\n");
diff --git a/library/cpp/binsaver/bin_saver.h b/library/cpp/binsaver/bin_saver.h
index 412424889f..c8b1873938 100644
--- a/library/cpp/binsaver/bin_saver.h
+++ b/library/cpp/binsaver/bin_saver.h
@@ -2,9 +2,9 @@
#include "buffered_io.h"
#include "class_factory.h"
-
+
#include <library/cpp/containers/2d_array/2d_array.h>
-
+
#include <util/generic/hash_set.h>
#include <util/generic/buffer.h>
#include <util/generic/list.h>
@@ -17,16 +17,16 @@
#include <array>
#include <bitset>
-#include <list>
-#include <string>
+#include <list>
+#include <string>
#ifdef _MSC_VER
-#pragma warning(disable : 4127)
+#pragma warning(disable : 4127)
#endif
-enum ESaverMode {
- SAVER_MODE_READ = 1,
- SAVER_MODE_WRITE = 2,
+enum ESaverMode {
+ SAVER_MODE_READ = 1,
+ SAVER_MODE_WRITE = 2,
SAVER_MODE_WRITE_COMPRESSED = 3,
};
@@ -43,7 +43,7 @@ namespace NBinSaverInternals {
}
//////////////////////////////////////////////////////////////////////////
-struct IBinSaver {
+struct IBinSaver {
public:
typedef unsigned char chunk_id;
typedef ui32 TStoredSize; // changing this will break compatibility
@@ -62,18 +62,18 @@ private:
// return 0;
// }
// };
- template <class T, typename = decltype(std::declval<T*>()->T::operator&(std::declval<IBinSaver&>()))>
+ template <class T, typename = decltype(std::declval<T*>()->T::operator&(std::declval<IBinSaver&>()))>
void CallObjectSerialize(T* p, NBinSaverInternals::TOverloadPriority<2>) { // highest priority - will be resolved first if enabled
- // Note: p->operator &(*this) would lead to infinite recursion
- p->T::operator&(*this);
+ // Note: p->operator &(*this) would lead to infinite recursion
+ p->T::operator&(*this);
}
- template <class T, typename = decltype(std::declval<T&>() & std::declval<IBinSaver&>())>
+ template <class T, typename = decltype(std::declval<T&>() & std::declval<IBinSaver&>())>
void CallObjectSerialize(T* p, NBinSaverInternals::TOverloadPriority<1>) { // lower priority - will be resolved second if enabled
(*p) & (*this);
}
- template <class T>
+ template <class T>
void CallObjectSerialize(T* p, NBinSaverInternals::TOverloadPriority<0>) { // lower priority - will be resolved last
#if (!defined(_MSC_VER))
// In MSVC __has_trivial_copy returns false to enums, primitive types and arrays.
@@ -83,8 +83,8 @@ private:
}
// vector
- template <class T, class TA>
- void DoVector(TVector<T, TA>& data) {
+ template <class T, class TA>
+ void DoVector(TVector<T, TA>& data) {
TStoredSize nSize;
if (IsReading()) {
data.clear();
@@ -99,23 +99,23 @@ private:
Add(1, &data[i]);
}
- template <class T, int N>
- void DoArray(T (&data)[N]) {
+ template <class T, int N>
+ void DoArray(T (&data)[N]) {
for (size_t i = 0; i < N; i++) {
Add(1, &(data[i]));
}
}
- template <typename TLarge>
- void CheckOverflow(TStoredSize nSize, TLarge origSize) {
+ template <typename TLarge>
+ void CheckOverflow(TStoredSize nSize, TLarge origSize) {
if (nSize != origSize) {
fprintf(stderr, "IBinSaver: object size is too large to be serialized (%" PRIu32 " != %" PRIu64 ")\n", nSize, (ui64)origSize);
abort();
}
}
- template <class T, class TA>
- void DoDataVector(TVector<T, TA>& data) {
+ template <class T, class TA>
+ void DoDataVector(TVector<T, TA>& data) {
TStoredSize nSize = data.size();
CheckOverflow(nSize, data.size());
Add(1, &nSize);
@@ -127,8 +127,8 @@ private:
DataChunk(&data[0], sizeof(T) * nSize);
}
- template <class AM>
- void DoAnyMap(AM& data) {
+ template <class AM>
+ void DoAnyMap(AM& data) {
if (IsReading()) {
data.clear();
TStoredSize nSize;
@@ -138,7 +138,7 @@ private:
for (TStoredSize i = 0; i < nSize; ++i)
Add(1, &indices[i]);
for (TStoredSize i = 0; i < nSize; ++i)
- Add(2, &data[indices[i]]);
+ Add(2, &data[indices[i]]);
} else {
TStoredSize nSize = data.size();
CheckOverflow(nSize, data.size());
@@ -148,17 +148,17 @@ private:
indices.resize(nSize);
TStoredSize i = 1;
for (auto pos = data.begin(); pos != data.end(); ++pos, ++i)
- indices[nSize - i] = pos->first;
+ indices[nSize - i] = pos->first;
for (TStoredSize j = 0; j < nSize; ++j)
Add(1, &indices[j]);
for (TStoredSize j = 0; j < nSize; ++j)
- Add(2, &data[indices[j]]);
+ Add(2, &data[indices[j]]);
}
}
// hash_multimap
- template <class AMM>
- void DoAnyMultiMap(AMM& data) {
+ template <class AMM>
+ void DoAnyMultiMap(AMM& data) {
if (IsReading()) {
data.clear();
TStoredSize nSize;
@@ -178,14 +178,14 @@ private:
CheckOverflow(nSize, data.size());
Add(3, &nSize);
for (auto pos = data.begin(); pos != data.end(); ++pos)
- Add(1, (typename AMM::key_type*)(&pos->first));
+ Add(1, (typename AMM::key_type*)(&pos->first));
for (auto pos = data.begin(); pos != data.end(); ++pos)
Add(2, &pos->second);
}
}
- template <class T>
- void DoAnySet(T& data) {
+ template <class T>
+ void DoAnySet(T& data) {
if (IsReading()) {
data.clear();
TStoredSize nSize;
@@ -207,18 +207,18 @@ private:
}
// 2D array
- template <class T>
- void Do2DArray(TArray2D<T>& a) {
+ template <class T>
+ void Do2DArray(TArray2D<T>& a) {
int nXSize = a.GetXSize(), nYSize = a.GetYSize();
Add(1, &nXSize);
Add(2, &nYSize);
if (IsReading())
a.SetSizes(nXSize, nYSize);
for (int i = 0; i < nXSize * nYSize; i++)
- Add(3, &a[i / nXSize][i % nXSize]);
+ Add(3, &a[i / nXSize][i % nXSize]);
}
- template <class T>
- void Do2DArrayData(TArray2D<T>& a) {
+ template <class T>
+ void Do2DArrayData(TArray2D<T>& a) {
int nXSize = a.GetXSize(), nYSize = a.GetYSize();
Add(1, &nXSize);
Add(2, &nYSize);
@@ -228,8 +228,8 @@ private:
DataChunk(&a[0][0], sizeof(T) * nXSize * nYSize);
}
// strings
- template <class TStringType>
- void DataChunkStr(TStringType& data, i64 elemSize) {
+ template <class TStringType>
+ void DataChunkStr(TStringType& data, i64 elemSize) {
if (bRead) {
TStoredSize nCount = 0;
File.Read(&nCount, sizeof(TStoredSize));
@@ -243,20 +243,20 @@ private:
File.Write(data.c_str(), nCount * elemSize);
}
}
- void DataChunkString(std::string& data) {
+ void DataChunkString(std::string& data) {
DataChunkStr(data, sizeof(char));
}
- void DataChunkStroka(TString& data) {
+ void DataChunkStroka(TString& data) {
DataChunkStr(data, sizeof(TString::char_type));
}
- void DataChunkWtroka(TUtf16String& data) {
+ void DataChunkWtroka(TUtf16String& data) {
DataChunkStr(data, sizeof(wchar16));
}
- void DataChunk(void* pData, i64 nSize) {
+ void DataChunk(void* pData, i64 nSize) {
i64 chunkSize = 1 << 30;
for (i64 offset = 0; offset < nSize; offset += chunkSize) {
- void* ptr = (char*)pData + offset;
+ void* ptr = (char*)pData + offset;
i64 size = offset + chunkSize < nSize ? chunkSize : (nSize - offset);
if (bRead)
File.Read(ptr, size);
@@ -266,7 +266,7 @@ private:
}
// storing/loading pointers to objects
- void StoreObject(IObjectBase* pObject);
+ void StoreObject(IObjectBase* pObject);
IObjectBase* LoadObject();
bool bRead;
@@ -278,38 +278,38 @@ private:
typedef THashMap<void*, ui32> PtrIdHash;
TAutoPtr<PtrIdHash> PtrIds;
- typedef THashMap<ui64, TPtr<IObjectBase>> CObjectsHash;
+ typedef THashMap<ui64, TPtr<IObjectBase>> CObjectsHash;
TAutoPtr<CObjectsHash> Objects;
TVector<IObjectBase*> ObjectQueue;
-
+
public:
- bool IsReading() {
- return bRead;
- }
- void AddRawData(const chunk_id, void* pData, i64 nSize) {
- DataChunk(pData, nSize);
- }
+ bool IsReading() {
+ return bRead;
+ }
+ void AddRawData(const chunk_id, void* pData, i64 nSize) {
+ DataChunk(pData, nSize);
+ }
// return type of Add() is used to detect specialized serializer (see HasNonTrivialSerializer below)
- template <class T>
- char Add(const chunk_id, T* p) {
+ template <class T>
+ char Add(const chunk_id, T* p) {
CallObjectSerialize(p, NBinSaverInternals::TOverloadPriority<2>());
return 0;
}
- int Add(const chunk_id, std::string* pStr) {
+ int Add(const chunk_id, std::string* pStr) {
DataChunkString(*pStr);
return 0;
}
- int Add(const chunk_id, TString* pStr) {
+ int Add(const chunk_id, TString* pStr) {
DataChunkStroka(*pStr);
return 0;
}
- int Add(const chunk_id, TUtf16String* pStr) {
+ int Add(const chunk_id, TUtf16String* pStr) {
DataChunkWtroka(*pStr);
return 0;
}
- int Add(const chunk_id, TBlob* blob) {
+ int Add(const chunk_id, TBlob* blob) {
if (bRead) {
ui64 size = 0;
File.Read(&size, sizeof(size));
@@ -325,8 +325,8 @@ public:
}
return 0;
}
- template <class T1, class TA>
- int Add(const chunk_id, TVector<T1, TA>* pVec) {
+ template <class T1, class TA>
+ int Add(const chunk_id, TVector<T1, TA>* pVec) {
if (HasNonTrivialSerializer<T1>(0u))
DoVector(*pVec);
else
@@ -334,8 +334,8 @@ public:
return 0;
}
- template <class T, int N>
- int Add(const chunk_id, T (*pVec)[N]) {
+ template <class T, int N>
+ int Add(const chunk_id, T (*pVec)[N]) {
if (HasNonTrivialSerializer<T>(0u))
DoArray(*pVec);
else
@@ -343,49 +343,49 @@ public:
return 0;
}
- template <class T1, class T2, class T3, class T4>
- int Add(const chunk_id, TMap<T1, T2, T3, T4>* pMap) {
+ template <class T1, class T2, class T3, class T4>
+ int Add(const chunk_id, TMap<T1, T2, T3, T4>* pMap) {
DoAnyMap(*pMap);
return 0;
}
- template <class T1, class T2, class T3, class T4, class T5>
- int Add(const chunk_id, THashMap<T1, T2, T3, T4, T5>* pHash) {
+ template <class T1, class T2, class T3, class T4, class T5>
+ int Add(const chunk_id, THashMap<T1, T2, T3, T4, T5>* pHash) {
DoAnyMap(*pHash);
return 0;
}
- template <class T1, class T2, class T3, class T4, class T5>
- int Add(const chunk_id, THashMultiMap<T1, T2, T3, T4, T5>* pHash) {
+ template <class T1, class T2, class T3, class T4, class T5>
+ int Add(const chunk_id, THashMultiMap<T1, T2, T3, T4, T5>* pHash) {
DoAnyMultiMap(*pHash);
return 0;
}
- template <class K, class L, class A>
- int Add(const chunk_id, TSet<K, L, A>* pSet) {
+ template <class K, class L, class A>
+ int Add(const chunk_id, TSet<K, L, A>* pSet) {
DoAnySet(*pSet);
return 0;
}
- template <class T1, class T2, class T3, class T4>
- int Add(const chunk_id, THashSet<T1, T2, T3, T4>* pHash) {
+ template <class T1, class T2, class T3, class T4>
+ int Add(const chunk_id, THashSet<T1, T2, T3, T4>* pHash) {
DoAnySet(*pHash);
return 0;
}
-
- template <class T1>
- int Add(const chunk_id, TArray2D<T1>* pArr) {
+
+ template <class T1>
+ int Add(const chunk_id, TArray2D<T1>* pArr) {
if (HasNonTrivialSerializer<T1>(0u))
Do2DArray(*pArr);
else
Do2DArrayData(*pArr);
return 0;
}
- template <class T1>
- int Add(const chunk_id, TList<T1>* pList) {
- TList<T1>& data = *pList;
- if (IsReading()) {
+ template <class T1>
+ int Add(const chunk_id, TList<T1>* pList) {
+ TList<T1>& data = *pList;
+ if (IsReading()) {
int nSize;
Add(2, &nSize);
data.clear();
data.insert(data.begin(), nSize, T1());
- } else {
+ } else {
int nSize = data.size();
Add(2, &nSize);
}
@@ -394,38 +394,38 @@ public:
Add(i + 2, &(*k));
return 0;
}
- template <class T1, class T2>
- int Add(const chunk_id, std::pair<T1, T2>* pData) {
+ template <class T1, class T2>
+ int Add(const chunk_id, std::pair<T1, T2>* pData) {
Add(1, &(pData->first));
Add(2, &(pData->second));
return 0;
}
- template <class T1, size_t N>
- int Add(const chunk_id, std::array<T1, N>* pData) {
+ template <class T1, size_t N>
+ int Add(const chunk_id, std::array<T1, N>* pData) {
if (HasNonTrivialSerializer<T1>(0u)) {
for (size_t i = 0; i < N; ++i)
Add(1, &(*pData)[i]);
} else {
- DataChunk((void*)pData->data(), pData->size() * sizeof(T1));
+ DataChunk((void*)pData->data(), pData->size() * sizeof(T1));
}
return 0;
}
template <size_t N>
- int Add(const chunk_id, std::bitset<N>* pData) {
+ int Add(const chunk_id, std::bitset<N>* pData) {
if (IsReading()) {
std::string s;
Add(1, &s);
*pData = std::bitset<N>(s);
} else {
- std::string s = pData->template to_string<char, std::char_traits<char>, std::allocator<char>>();
+ std::string s = pData->template to_string<char, std::char_traits<char>, std::allocator<char>>();
Add(1, &s);
}
return 0;
}
- int Add(const chunk_id, TDynBitMap* pData) {
+ int Add(const chunk_id, TDynBitMap* pData) {
if (IsReading()) {
ui64 count = 0;
Add(1, &count);
@@ -491,17 +491,17 @@ public:
}
- void AddPolymorphicBase(chunk_id, IObjectBase* pObject) {
+ void AddPolymorphicBase(chunk_id, IObjectBase* pObject) {
(*pObject) & (*this);
}
- template <class T1, class T2>
- void DoPtr(TPtrBase<T1, T2>* pData) {
+ template <class T1, class T2>
+ void DoPtr(TPtrBase<T1, T2>* pData) {
if (pData && pData->Get()) {
}
- if (IsReading())
+ if (IsReading())
pData->Set(CastToUserObject(LoadObject(), (T1*)nullptr));
- else
+ else
StoreObject(pData->GetBarePtr());
}
template <class T, class TPolicy>
@@ -525,52 +525,52 @@ public:
}
template <typename TOne>
- void AddMulti(TOne& one) {
+ void AddMulti(TOne& one) {
Add(0, &one);
}
- template <typename THead, typename... TTail>
- void AddMulti(THead& head, TTail&... tail) {
+ template <typename THead, typename... TTail>
+ void AddMulti(THead& head, TTail&... tail) {
Add(0, &head);
- AddMulti(tail...);
+ AddMulti(tail...);
}
- template <class T, typename = decltype(std::declval<T&>() & std::declval<IBinSaver&>())>
+ template <class T, typename = decltype(std::declval<T&>() & std::declval<IBinSaver&>())>
static bool HasNonTrivialSerializer(ui32) {
return true;
}
- template <class T>
+ template <class T>
static bool HasNonTrivialSerializer(...) {
return sizeof(std::declval<IBinSaver*>()->Add(0, std::declval<T*>())) != 1;
}
-
+
public:
- IBinSaver(IBinaryStream& stream, bool _bRead, bool stableOutput = false)
- : bRead(_bRead)
- , File(_bRead, stream)
- , StableOutput(stableOutput)
- {
- }
+ IBinSaver(IBinaryStream& stream, bool _bRead, bool stableOutput = false)
+ : bRead(_bRead)
+ , File(_bRead, stream)
+ , StableOutput(stableOutput)
+ {
+ }
virtual ~IBinSaver();
- bool IsValid() const {
- return File.IsValid();
- }
+ bool IsValid() const {
+ return File.IsValid();
+ }
};
// realisation of forward declared serialisation operator
-template <class TUserObj, class TRef>
-int TPtrBase<TUserObj, TRef>::operator&(IBinSaver& f) {
+template <class TUserObj, class TRef>
+int TPtrBase<TUserObj, TRef>::operator&(IBinSaver& f) {
f.DoPtr(this);
return 0;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
-extern TClassFactory<IObjectBase>* pSaverClasses;
+extern TClassFactory<IObjectBase>* pSaverClasses;
void StartRegisterSaveload();
-template <class TReg>
+template <class TReg>
struct TRegisterSaveLoadType {
TRegisterSaveLoadType(int num) {
StartRegisterSaveload();
@@ -578,52 +578,52 @@ struct TRegisterSaveLoadType {
}
};
-#define Y_BINSAVER_REGISTER(name) \
- BASIC_REGISTER_CLASS(name) \
+#define Y_BINSAVER_REGISTER(name) \
+ BASIC_REGISTER_CLASS(name) \
static TRegisterSaveLoadType<name> init##name(MurmurHash<int>(#name, sizeof(#name)));
-#define REGISTER_SAVELOAD_CLASS(N, name) \
- BASIC_REGISTER_CLASS(name) \
+#define REGISTER_SAVELOAD_CLASS(N, name) \
+ BASIC_REGISTER_CLASS(name) \
static TRegisterSaveLoadType<name> init##name##N(N);
// using TObj/TRef on forward declared templ class will not work
// but multiple registration with same id is allowed
-#define REGISTER_SAVELOAD_TEMPL1_CLASS(N, className, T) \
- static TRegisterSaveLoadType<className<T>> init##className##T##N(N);
+#define REGISTER_SAVELOAD_TEMPL1_CLASS(N, className, T) \
+ static TRegisterSaveLoadType<className<T>> init##className##T##N(N);
-#define REGISTER_SAVELOAD_TEMPL2_CLASS(N, className, T1, T2) \
- typedef className<T1, T2> temp##className##T1##_##T2##temp; \
- static TRegisterSaveLoadType<className<T1, T2>> init##className##T1##_##T2##N(N);
+#define REGISTER_SAVELOAD_TEMPL2_CLASS(N, className, T1, T2) \
+ typedef className<T1, T2> temp##className##T1##_##T2##temp; \
+ static TRegisterSaveLoadType<className<T1, T2>> init##className##T1##_##T2##N(N);
-#define REGISTER_SAVELOAD_TEMPL3_CLASS(N, className, T1, T2, T3) \
- typedef className<T1, T2, T3> temp##className##T1##_##T2##_##T3##temp; \
- static TRegisterSaveLoadType<className<T1, T2, T3>> init##className##T1##_##T2##_##T3##N(N);
+#define REGISTER_SAVELOAD_TEMPL3_CLASS(N, className, T1, T2, T3) \
+ typedef className<T1, T2, T3> temp##className##T1##_##T2##_##T3##temp; \
+ static TRegisterSaveLoadType<className<T1, T2, T3>> init##className##T1##_##T2##_##T3##N(N);
-#define REGISTER_SAVELOAD_NM_CLASS(N, nmspace, className) \
- BASIC_REGISTER_CLASS(nmspace::className) \
+#define REGISTER_SAVELOAD_NM_CLASS(N, nmspace, className) \
+ BASIC_REGISTER_CLASS(nmspace::className) \
static TRegisterSaveLoadType<nmspace::className> init_##nmspace##_##name##N(N);
#define REGISTER_SAVELOAD_NM2_CLASS(N, nmspace1, nmspace2, className) \
BASIC_REGISTER_CLASS(nmspace1::nmspace2::className) \
static TRegisterSaveLoadType<nmspace1::nmspace2::className> init_##nmspace1##_##nmspace2##_##name##N(N);
-#define REGISTER_SAVELOAD_TEMPL1_NM_CLASS(N, nmspace, className, T) \
- typedef nmspace::className<T> temp_init##nmspace##className##T##temp; \
- BASIC_REGISTER_CLASS(nmspace::className<T>) \
- static TRegisterSaveLoadType<nmspace::className<T>> temp_init##nmspace##_##name##T##N(N);
+#define REGISTER_SAVELOAD_TEMPL1_NM_CLASS(N, nmspace, className, T) \
+ typedef nmspace::className<T> temp_init##nmspace##className##T##temp; \
+ BASIC_REGISTER_CLASS(nmspace::className<T>) \
+ static TRegisterSaveLoadType<nmspace::className<T>> temp_init##nmspace##_##name##T##N(N);
#define REGISTER_SAVELOAD_CLASS_NAME(N, cls, name) \
- BASIC_REGISTER_CLASS(cls) \
- static TRegisterSaveLoadType<cls> init##name##N(N);
+ BASIC_REGISTER_CLASS(cls) \
+ static TRegisterSaveLoadType<cls> init##name##N(N);
#define REGISTER_SAVELOAD_CLASS_NS_PREF(N, cls, ns, pref) \
- REGISTER_SAVELOAD_CLASS_NAME(N, ns ::cls, _##pref##_##cls)
+ REGISTER_SAVELOAD_CLASS_NAME(N, ns ::cls, _##pref##_##cls)
-#define SAVELOAD(...) \
- int operator&(IBinSaver& f) { \
- f.AddMulti(__VA_ARGS__); \
- return 0; \
- }
+#define SAVELOAD(...) \
+ int operator&(IBinSaver& f) { \
+ f.AddMulti(__VA_ARGS__); \
+ return 0; \
+ }
#define SAVELOAD_OVERRIDE_WITHOUT_BASE(...) \
int operator&(IBinSaver& f) override { \
@@ -638,9 +638,9 @@ struct TRegisterSaveLoadType {
return 0; \
}
-#define SAVELOAD_BASE(...) \
- int operator&(IBinSaver& f) { \
- TBase::operator&(f); \
- f.AddMulti(__VA_ARGS__); \
- return 0; \
+#define SAVELOAD_BASE(...) \
+ int operator&(IBinSaver& f) { \
+ TBase::operator&(f); \
+ f.AddMulti(__VA_ARGS__); \
+ return 0; \
}
diff --git a/library/cpp/binsaver/blob_io.h b/library/cpp/binsaver/blob_io.h
index abe518ef30..efde51fe88 100644
--- a/library/cpp/binsaver/blob_io.h
+++ b/library/cpp/binsaver/blob_io.h
@@ -5,15 +5,15 @@
#include <util/memory/blob.h>
-class TYaBlobStream: public IBinaryStream {
+class TYaBlobStream: public IBinaryStream {
TBlob Blob;
i64 Pos;
- int WriteImpl(const void*, int) override {
+ int WriteImpl(const void*, int) override {
Y_ASSERT(0);
return 0;
}
- int ReadImpl(void* userBuffer, int size) override {
+ int ReadImpl(void* userBuffer, int size) override {
if (size == 0)
return 0;
i64 res = Min<i64>(Blob.Length() - Pos, size);
@@ -22,23 +22,23 @@ class TYaBlobStream: public IBinaryStream {
Pos += res;
return res;
}
- bool IsValid() const override {
- return true;
- }
- bool IsFailed() const override {
- return false;
- }
-
+ bool IsValid() const override {
+ return true;
+ }
+ bool IsFailed() const override {
+ return false;
+ }
+
public:
- TYaBlobStream(const TBlob& blob)
- : Blob(blob)
- , Pos(0)
- {
- }
+ TYaBlobStream(const TBlob& blob)
+ : Blob(blob)
+ , Pos(0)
+ {
+ }
};
-template <class T>
-inline void SerializeBlob(const TBlob& data, T& c) {
+template <class T>
+inline void SerializeBlob(const TBlob& data, T& c) {
TYaBlobStream f(data);
{
IBinSaver bs(f, true);
diff --git a/library/cpp/binsaver/buffered_io.cpp b/library/cpp/binsaver/buffered_io.cpp
index dd88b04bc5..81ca656bf3 100644
--- a/library/cpp/binsaver/buffered_io.cpp
+++ b/library/cpp/binsaver/buffered_io.cpp
@@ -1,6 +1,6 @@
#include "buffered_io.h"
-i64 IBinaryStream::LongWrite(const void* userBuffer, i64 size) {
+i64 IBinaryStream::LongWrite(const void* userBuffer, i64 size) {
Y_VERIFY(size >= 0, "IBinaryStream::Write() called with a negative buffer size.");
i64 leftToWrite = size;
@@ -18,7 +18,7 @@ i64 IBinaryStream::LongWrite(const void* userBuffer, i64 size) {
return size - leftToWrite;
}
-i64 IBinaryStream::LongRead(void* userBuffer, i64 size) {
+i64 IBinaryStream::LongRead(void* userBuffer, i64 size) {
Y_VERIFY(size >= 0, "IBinaryStream::Read() called with a negative buffer size.");
i64 leftToRead = size;
diff --git a/library/cpp/binsaver/buffered_io.h b/library/cpp/binsaver/buffered_io.h
index 75465c9c5c..893f93cddd 100644
--- a/library/cpp/binsaver/buffered_io.h
+++ b/library/cpp/binsaver/buffered_io.h
@@ -1,15 +1,15 @@
#pragma once
-
+
#include <util/system/yassert.h>
#include <util/generic/utility.h>
#include <util/generic/ylimits.h>
#include <string.h>
-struct IBinaryStream {
- virtual ~IBinaryStream() = default;
- ;
+struct IBinaryStream {
+ virtual ~IBinaryStream() = default;
+ ;
- inline i64 Write(const void* userBuffer, i64 size) {
+ inline i64 Write(const void* userBuffer, i64 size) {
if (size <= Max<int>()) {
return WriteImpl(userBuffer, static_cast<int>(size));
} else {
@@ -17,7 +17,7 @@ struct IBinaryStream {
}
}
- inline i64 Read(void* userBuffer, i64 size) {
+ inline i64 Read(void* userBuffer, i64 size) {
if (size <= Max<int>()) {
return ReadImpl(userBuffer, static_cast<int>(size));
} else {
@@ -29,26 +29,26 @@ struct IBinaryStream {
virtual bool IsFailed() const = 0;
private:
- virtual int WriteImpl(const void* userBuffer, int size) = 0;
- virtual int ReadImpl(void* userBuffer, int size) = 0;
+ virtual int WriteImpl(const void* userBuffer, int size) = 0;
+ virtual int ReadImpl(void* userBuffer, int size) = 0;
- i64 LongRead(void* userBuffer, i64 size);
- i64 LongWrite(const void* userBuffer, i64 size);
+ i64 LongRead(void* userBuffer, i64 size);
+ i64 LongWrite(const void* userBuffer, i64 size);
};
template <int N_SIZE = 16384>
-class TBufferedStream {
+class TBufferedStream {
char Buf[N_SIZE];
i64 Pos, BufSize;
- IBinaryStream& Stream;
+ IBinaryStream& Stream;
bool bIsReading, bIsEof, bFailed;
- void ReadComplex(void* userBuffer, i64 size) {
+ void ReadComplex(void* userBuffer, i64 size) {
if (bIsEof) {
memset(userBuffer, 0, size);
return;
}
- char* dst = (char*)userBuffer;
+ char* dst = (char*)userBuffer;
i64 leftBytes = BufSize - Pos;
memcpy(dst, Buf + Pos, leftBytes);
dst += leftBytes;
@@ -70,28 +70,28 @@ class TBufferedStream {
}
}
- void WriteComplex(const void* userBuffer, i64 size) {
+ void WriteComplex(const void* userBuffer, i64 size) {
Flush();
if (size >= N_SIZE) {
Stream.Write(userBuffer, size);
bFailed = Stream.IsFailed();
- } else
+ } else
Write(userBuffer, size);
}
- void operator=(const TBufferedStream&) {
- }
-
+ void operator=(const TBufferedStream&) {
+ }
+
public:
- TBufferedStream(bool bRead, IBinaryStream& stream)
- : Pos(0)
- , BufSize(0)
- , Stream(stream)
- , bIsReading(bRead)
- , bIsEof(false)
- , bFailed(false)
- {
- }
+ TBufferedStream(bool bRead, IBinaryStream& stream)
+ : Pos(0)
+ , BufSize(0)
+ , Stream(stream)
+ , bIsReading(bRead)
+ , bIsEof(false)
+ , bFailed(false)
+ {
+ }
~TBufferedStream() {
if (!bIsReading)
Flush();
@@ -104,10 +104,10 @@ public:
bFailed = Stream.IsFailed();
Pos = 0;
}
- bool IsEof() const {
- return bIsEof;
- }
- inline void Read(void* userBuffer, i64 size) {
+ bool IsEof() const {
+ return bIsEof;
+ }
+ inline void Read(void* userBuffer, i64 size) {
Y_ASSERT(bIsReading);
if (!bIsEof && size + Pos <= BufSize) {
memcpy(userBuffer, Buf + Pos, size);
@@ -116,7 +116,7 @@ public:
}
ReadComplex(userBuffer, size);
}
- inline void Write(const void* userBuffer, i64 size) {
+ inline void Write(const void* userBuffer, i64 size) {
Y_ASSERT(!bIsReading);
if (Pos + size < N_SIZE) {
memcpy(Buf + Pos, userBuffer, size);
@@ -125,10 +125,10 @@ public:
}
WriteComplex(userBuffer, size);
}
- bool IsValid() const {
- return Stream.IsValid();
- }
- bool IsFailed() const {
- return bFailed;
- }
+ bool IsValid() const {
+ return Stream.IsValid();
+ }
+ bool IsFailed() const {
+ return bFailed;
+ }
};
diff --git a/library/cpp/binsaver/class_factory.h b/library/cpp/binsaver/class_factory.h
index e83512331b..f01f2c33a3 100644
--- a/library/cpp/binsaver/class_factory.h
+++ b/library/cpp/binsaver/class_factory.h
@@ -1,5 +1,5 @@
#pragma once
-
+
#include <typeinfo>
#include <util/generic/hash.h>
#include <util/generic/vector.h>
@@ -10,96 +10,96 @@
// factory is using RTTI
// objects should inherit T and T must have at least 1 virtual function
template <class T>
-class TClassFactory {
+class TClassFactory {
public:
- typedef const std::type_info* VFT;
-
+ typedef const std::type_info* VFT;
+
private:
typedef T* (*newFunc)();
- typedef THashMap<int, newFunc> CTypeNewHash; // typeID->newFunc()
+ typedef THashMap<int, newFunc> CTypeNewHash; // typeID->newFunc()
typedef THashMap<VFT, int> CTypeIndexHash; // vftable->typeID
CTypeIndexHash typeIndex;
CTypeNewHash typeInfo;
- void RegisterTypeBase(int nTypeID, newFunc func, VFT vft);
- static VFT GetObjectType(T* pObject) {
- return &typeid(*pObject);
- }
- int VFT2TypeID(VFT t) {
- CTypeIndexHash::iterator i = typeIndex.find(t);
- if (i != typeIndex.end())
+ void RegisterTypeBase(int nTypeID, newFunc func, VFT vft);
+ static VFT GetObjectType(T* pObject) {
+ return &typeid(*pObject);
+ }
+ int VFT2TypeID(VFT t) {
+ CTypeIndexHash::iterator i = typeIndex.find(t);
+ if (i != typeIndex.end())
return i->second;
- for (i = typeIndex.begin(); i != typeIndex.end(); ++i) {
- if (*i->first == *t) {
+ for (i = typeIndex.begin(); i != typeIndex.end(); ++i) {
+ if (*i->first == *t) {
typeIndex[t] = i->second;
return i->second;
}
}
return -1;
}
-
+
public:
- template <class TT>
- void RegisterType(int nTypeID, newFunc func, TT*) {
- RegisterTypeBase(nTypeID, func, &typeid(TT));
- }
- void RegisterTypeSafe(int nTypeID, newFunc func) {
+ template <class TT>
+ void RegisterType(int nTypeID, newFunc func, TT*) {
+ RegisterTypeBase(nTypeID, func, &typeid(TT));
+ }
+ void RegisterTypeSafe(int nTypeID, newFunc func) {
TPtr<T> pObj = func();
- VFT vft = GetObjectType(pObj);
- RegisterTypeBase(nTypeID, func, vft);
- }
- T* CreateObject(int nTypeID) {
- newFunc f = typeInfo[nTypeID];
- if (f)
- return f();
- return nullptr;
- }
- int GetObjectTypeID(T* pObject) {
- return VFT2TypeID(GetObjectType(pObject));
- }
- template <class TT>
- int GetTypeID(TT* p = 0) {
- (void)p;
- return VFT2TypeID(&typeid(TT));
+ VFT vft = GetObjectType(pObj);
+ RegisterTypeBase(nTypeID, func, vft);
}
+ T* CreateObject(int nTypeID) {
+ newFunc f = typeInfo[nTypeID];
+ if (f)
+ return f();
+ return nullptr;
+ }
+ int GetObjectTypeID(T* pObject) {
+ return VFT2TypeID(GetObjectType(pObject));
+ }
+ template <class TT>
+ int GetTypeID(TT* p = 0) {
+ (void)p;
+ return VFT2TypeID(&typeid(TT));
+ }
- void GetAllTypeIDs(TVector<int>& typeIds) const {
+ void GetAllTypeIDs(TVector<int>& typeIds) const {
typeIds.clear();
- for (typename CTypeNewHash::const_iterator iter = typeInfo.begin();
- iter != typeInfo.end();
- ++iter) {
- typeIds.push_back(iter->first);
+ for (typename CTypeNewHash::const_iterator iter = typeInfo.begin();
+ iter != typeInfo.end();
+ ++iter) {
+ typeIds.push_back(iter->first);
}
}
};
////////////////////////////////////////////////////////////////////////////////////////////////////
template <class T>
-void TClassFactory<T>::RegisterTypeBase(int nTypeID, newFunc func, VFT vft) {
- if (typeInfo.find(nTypeID) != typeInfo.end()) {
+void TClassFactory<T>::RegisterTypeBase(int nTypeID, newFunc func, VFT vft) {
+ if (typeInfo.find(nTypeID) != typeInfo.end()) {
TObj<IObjectBase> o1 = typeInfo[nTypeID]();
TObj<IObjectBase> o2 = func();
-
- // stupid clang warning
- auto& o1v = *o1;
- auto& o2v = *o2;
-
- if (typeid(o1v) != typeid(o2v)) {
- fprintf(stderr, "IBinSaver: Type ID 0x%08X has been already used\n", nTypeID);
+
+ // stupid clang warning
+ auto& o1v = *o1;
+ auto& o2v = *o2;
+
+ if (typeid(o1v) != typeid(o2v)) {
+ fprintf(stderr, "IBinSaver: Type ID 0x%08X has been already used\n", nTypeID);
abort();
}
}
- CTypeIndexHash::iterator typeIndexIt = typeIndex.find(vft);
- if (typeIndexIt != typeIndex.end() && nTypeID != typeIndexIt->second) {
- fprintf(stderr, "IBinSaver: class (Type ID 0x%08X) has been already registered (Type ID 0x%08X)\n", nTypeID, typeIndexIt->second);
+ CTypeIndexHash::iterator typeIndexIt = typeIndex.find(vft);
+ if (typeIndexIt != typeIndex.end() && nTypeID != typeIndexIt->second) {
+ fprintf(stderr, "IBinSaver: class (Type ID 0x%08X) has been already registered (Type ID 0x%08X)\n", nTypeID, typeIndexIt->second);
abort();
}
- typeIndex[vft] = nTypeID;
- typeInfo[nTypeID] = func;
+ typeIndex[vft] = nTypeID;
+ typeInfo[nTypeID] = func;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// macro for registering CFundament derivatives
-#define REGISTER_CLASS(factory, N, name) factory.RegisterType(N, name::New##name, (name*)0);
-#define REGISTER_TEMPL_CLASS(factory, N, name, className) factory.RegisterType(N, name::New##className, (name*)0);
-#define REGISTER_CLASS_NM(factory, N, name, nmspace) factory.RegisterType(N, nmspace::name::New##name, (nmspace::name*)0);
+#define REGISTER_CLASS(factory, N, name) factory.RegisterType(N, name::New##name, (name*)0);
+#define REGISTER_TEMPL_CLASS(factory, N, name, className) factory.RegisterType(N, name::New##className, (name*)0);
+#define REGISTER_CLASS_NM(factory, N, name, nmspace) factory.RegisterType(N, nmspace::name::New##name, (nmspace::name*)0);
diff --git a/library/cpp/binsaver/ut/binsaver_ut.cpp b/library/cpp/binsaver/ut/binsaver_ut.cpp
index 37eba5406f..e4237e0875 100644
--- a/library/cpp/binsaver/ut/binsaver_ut.cpp
+++ b/library/cpp/binsaver/ut/binsaver_ut.cpp
@@ -27,14 +27,14 @@ struct TCustomOuterSerializer {
TString StrData;
};
-void operator&(TCustomOuterSerializer& s, IBinSaver& f);
+void operator&(TCustomOuterSerializer& s, IBinSaver& f);
struct TCustomOuterSerializerTmpl {
ui32 Data = 0;
TString StrData;
};
-struct TCustomOuterSerializerTmplDerived: public TCustomOuterSerializerTmpl {
+struct TCustomOuterSerializerTmplDerived: public TCustomOuterSerializerTmpl {
ui32 Data = 0;
TString StrData;
};
@@ -45,7 +45,7 @@ struct TMoveOnlyType {
TMoveOnlyType() = default;
TMoveOnlyType(TMoveOnlyType&&) = default;
- bool operator==(const TMoveOnlyType& obj) const {
+ bool operator==(const TMoveOnlyType& obj) const {
return Data == obj.Data;
}
};
@@ -55,13 +55,13 @@ struct TTypeWithArray {
TString Array[2][2]{{"test", "data"}, {"and", "more"}};
SAVELOAD(Data, Array);
- bool operator==(const TTypeWithArray& obj) const {
- return Data == obj.Data && std::equal(std::begin(Array[0]), std::end(Array[0]), obj.Array[0]) && std::equal(std::begin(Array[1]), std::end(Array[1]), obj.Array[1]);
+ bool operator==(const TTypeWithArray& obj) const {
+ return Data == obj.Data && std::equal(std::begin(Array[0]), std::end(Array[0]), obj.Array[0]) && std::equal(std::begin(Array[1]), std::end(Array[1]), obj.Array[1]);
}
};
-template <typename T, typename = std::enable_if_t<std::is_base_of<TCustomOuterSerializerTmpl, T>::value>>
-int operator&(T& s, IBinSaver& f);
+template <typename T, typename = std::enable_if_t<std::is_base_of<TCustomOuterSerializerTmpl, T>::value>>
+int operator&(T& s, IBinSaver& f);
static bool operator==(const TBlob& l, const TBlob& r) {
return TStringBuf(l.AsCharPtr(), l.Size()) == TStringBuf(r.AsCharPtr(), r.Size());
@@ -69,45 +69,45 @@ static bool operator==(const TBlob& l, const TBlob& r) {
Y_UNIT_TEST_SUITE(BinSaver){
Y_UNIT_TEST(HasTrivialSerializer){
- UNIT_ASSERT(!IBinSaver::HasNonTrivialSerializer<TBinarySerializable>(0u));
-UNIT_ASSERT(!IBinSaver::HasNonTrivialSerializer<TNonBinarySerializable>(0u));
-UNIT_ASSERT(IBinSaver::HasNonTrivialSerializer<TCustomSerializer>(0u));
-UNIT_ASSERT(IBinSaver::HasNonTrivialSerializer<TCustomOuterSerializer>(0u));
-UNIT_ASSERT(IBinSaver::HasNonTrivialSerializer<TCustomOuterSerializerTmpl>(0u));
-UNIT_ASSERT(IBinSaver::HasNonTrivialSerializer<TCustomOuterSerializerTmplDerived>(0u));
-UNIT_ASSERT(IBinSaver::HasNonTrivialSerializer<TVector<TCustomSerializer>>(0u));
-}
+ UNIT_ASSERT(!IBinSaver::HasNonTrivialSerializer<TBinarySerializable>(0u));
+UNIT_ASSERT(!IBinSaver::HasNonTrivialSerializer<TNonBinarySerializable>(0u));
+UNIT_ASSERT(IBinSaver::HasNonTrivialSerializer<TCustomSerializer>(0u));
+UNIT_ASSERT(IBinSaver::HasNonTrivialSerializer<TCustomOuterSerializer>(0u));
+UNIT_ASSERT(IBinSaver::HasNonTrivialSerializer<TCustomOuterSerializerTmpl>(0u));
+UNIT_ASSERT(IBinSaver::HasNonTrivialSerializer<TCustomOuterSerializerTmplDerived>(0u));
+UNIT_ASSERT(IBinSaver::HasNonTrivialSerializer<TVector<TCustomSerializer>>(0u));
+}
Y_UNIT_TEST(TestStroka) {
TestBinSaverSerialization(TString("QWERTY"));
-}
+}
Y_UNIT_TEST(TestMoveOnlyType) {
TestBinSaverSerializationToBuffer(TMoveOnlyType());
-}
+}
Y_UNIT_TEST(TestVectorStrok) {
TestBinSaverSerialization(TVector<TString>{"A", "B", "C"});
-}
+}
Y_UNIT_TEST(TestCArray) {
TestBinSaverSerialization(TTypeWithArray());
-}
+}
Y_UNIT_TEST(TestSets) {
TestBinSaverSerialization(THashSet<TString>{"A", "B", "C"});
TestBinSaverSerialization(TSet<TString>{"A", "B", "C"});
-}
+}
Y_UNIT_TEST(TestMaps) {
TestBinSaverSerialization(THashMap<TString, ui32>{{"A", 1}, {"B", 2}, {"C", 3}});
TestBinSaverSerialization(TMap<TString, ui32>{{"A", 1}, {"B", 2}, {"C", 3}});
-}
+}
Y_UNIT_TEST(TestBlob) {
TestBinSaverSerialization(TBlob::FromStringSingleThreaded("qwerty"));
-}
+}
Y_UNIT_TEST(TestVariant) {
{
@@ -126,73 +126,73 @@ Y_UNIT_TEST(TestVariant) {
}
Y_UNIT_TEST(TestPod) {
- struct TPod {
- ui32 A = 5;
- ui64 B = 7;
- bool operator==(const TPod& other) const {
- return A == other.A && B == other.B;
- }
- };
+ struct TPod {
+ ui32 A = 5;
+ ui64 B = 7;
+ bool operator==(const TPod& other) const {
+ return A == other.A && B == other.B;
+ }
+ };
TestBinSaverSerialization(TPod());
- TPod custom;
- custom.A = 25;
- custom.B = 37;
+ TPod custom;
+ custom.A = 25;
+ custom.B = 37;
TestBinSaverSerialization(custom);
TestBinSaverSerialization(TVector<TPod>{custom});
-}
+}
Y_UNIT_TEST(TestSubPod) {
- struct TPod {
- struct TSub {
- ui32 X = 10;
- bool operator==(const TSub& other) const {
- return X == other.X;
+ struct TPod {
+ struct TSub {
+ ui32 X = 10;
+ bool operator==(const TSub& other) const {
+ return X == other.X;
}
};
- TVector<TSub> B;
- int operator&(IBinSaver& f) {
- f.Add(0, &B);
- return 0;
- }
- bool operator==(const TPod& other) const {
- return B == other.B;
- }
- };
+ TVector<TSub> B;
+ int operator&(IBinSaver& f) {
+ f.Add(0, &B);
+ return 0;
+ }
+ bool operator==(const TPod& other) const {
+ return B == other.B;
+ }
+ };
TestBinSaverSerialization(TPod());
- TPod::TSub sub;
- sub.X = 1;
- TPod custom;
- custom.B = {sub};
+ TPod::TSub sub;
+ sub.X = 1;
+ TPod custom;
+ custom.B = {sub};
TestBinSaverSerialization(TVector<TPod>{custom});
-}
+}
Y_UNIT_TEST(TestMemberAndOpIsMain) {
- struct TBase {
- TString S;
- virtual int operator&(IBinSaver& f) {
- f.Add(0, &S);
- return 0;
- }
- virtual ~TBase() = default;
- };
-
- struct TDerived: public TBase {
- int A = 0;
- int operator&(IBinSaver& f)override {
- f.Add(0, static_cast<TBase*>(this));
- f.Add(0, &A);
- return 0;
- }
- bool operator==(const TDerived& other) const {
- return A == other.A && S == other.S;
- }
- };
-
- TDerived obj;
- obj.S = "TString";
- obj.A = 42;
+ struct TBase {
+ TString S;
+ virtual int operator&(IBinSaver& f) {
+ f.Add(0, &S);
+ return 0;
+ }
+ virtual ~TBase() = default;
+ };
+
+ struct TDerived: public TBase {
+ int A = 0;
+ int operator&(IBinSaver& f)override {
+ f.Add(0, static_cast<TBase*>(this));
+ f.Add(0, &A);
+ return 0;
+ }
+ bool operator==(const TDerived& other) const {
+ return A == other.A && S == other.S;
+ }
+ };
+
+ TDerived obj;
+ obj.S = "TString";
+ obj.A = 42;
TestBinSaverSerialization(obj);
-}
-}
-;
+}
+}
+;
diff --git a/library/cpp/binsaver/util_stream_io.h b/library/cpp/binsaver/util_stream_io.h
index d65d630b93..bc560cd5c3 100644
--- a/library/cpp/binsaver/util_stream_io.h
+++ b/library/cpp/binsaver/util_stream_io.h
@@ -1,37 +1,37 @@
#pragma once
-
+
#include "bin_saver.h"
#include <util/stream/input.h>
#include <util/stream/output.h>
#include <util/stream/file.h>
-class TYaStreamInput: public IBinaryStream {
- IInputStream& Stream;
+class TYaStreamInput: public IBinaryStream {
+ IInputStream& Stream;
- int WriteImpl(const void*, int) override {
+ int WriteImpl(const void*, int) override {
Y_ASSERT(0);
return 0;
}
- int ReadImpl(void* userBuffer, int size) override {
- return (int)Stream.Read(userBuffer, (size_t)size);
- }
- bool IsValid() const override {
- return true;
- }
- bool IsFailed() const override {
- return false;
+ int ReadImpl(void* userBuffer, int size) override {
+ return (int)Stream.Read(userBuffer, (size_t)size);
}
-
+ bool IsValid() const override {
+ return true;
+ }
+ bool IsFailed() const override {
+ return false;
+ }
+
public:
- TYaStreamInput(IInputStream& stream)
- : Stream(stream)
- {
+ TYaStreamInput(IInputStream& stream)
+ : Stream(stream)
+ {
}
};
-template <class T>
-inline void SerializeFromStream(IInputStream& stream, T& c) {
+template <class T>
+inline void SerializeFromStream(IInputStream& stream, T& c) {
TYaStreamInput f(stream);
{
IBinSaver bs(f, true);
@@ -39,38 +39,38 @@ inline void SerializeFromStream(IInputStream& stream, T& c) {
}
}
-template <class T>
-inline void SerializeFromFile(const TString& fileName, T& c) {
+template <class T>
+inline void SerializeFromFile(const TString& fileName, T& c) {
TIFStream in(fileName);
SerializeFromStream(in, c);
}
-class TYaStreamOutput: public IBinaryStream {
- IOutputStream& Stream;
+class TYaStreamOutput: public IBinaryStream {
+ IOutputStream& Stream;
- int WriteImpl(const void* what, int size) override {
- Stream.Write(what, (size_t)size);
+ int WriteImpl(const void* what, int size) override {
+ Stream.Write(what, (size_t)size);
return size;
}
- int ReadImpl(void*, int) override {
+ int ReadImpl(void*, int) override {
Y_ASSERT(0);
return 0;
}
- bool IsValid() const override {
- return true;
- }
- bool IsFailed() const override {
- return false;
- }
-
+ bool IsValid() const override {
+ return true;
+ }
+ bool IsFailed() const override {
+ return false;
+ }
+
public:
- TYaStreamOutput(IOutputStream& stream)
- : Stream(stream)
- {
+ TYaStreamOutput(IOutputStream& stream)
+ : Stream(stream)
+ {
}
};
-template <class T>
+template <class T>
inline void SerializeToArcadiaStream(IOutputStream& stream, T& c) {
TYaStreamOutput f(stream);
{
@@ -79,8 +79,8 @@ inline void SerializeToArcadiaStream(IOutputStream& stream, T& c) {
}
}
-template <class T>
-inline void SerializeToFile(const TString& fileName, T& c) {
+template <class T>
+inline void SerializeToFile(const TString& fileName, T& c) {
TOFStream out(fileName);
SerializeToArcadiaStream(out, c);
}
diff --git a/library/cpp/binsaver/ya.make b/library/cpp/binsaver/ya.make
index 9693c54639..417055decf 100644
--- a/library/cpp/binsaver/ya.make
+++ b/library/cpp/binsaver/ya.make
@@ -1,7 +1,7 @@
LIBRARY()
-OWNER(gulin)
-
+OWNER(gulin)
+
SRCS(
class_factory.h
bin_saver.cpp