diff options
author | monster <monster@yandex-team.ru> | 2022-02-10 16:47:19 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:47:19 +0300 |
commit | b23c1d7a8015c2006a148fd93b84cdeb0aee17a3 (patch) | |
tree | 9814fbd1c3effac9b8377c5d604b367b14e2db55 /library/cpp/binsaver | |
parent | dd76ae1f6213d065375ab296699f764faafbe5bd (diff) | |
download | ydb-b23c1d7a8015c2006a148fd93b84cdeb0aee17a3.tar.gz |
Restoring authorship annotation for <monster@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/binsaver')
-rw-r--r-- | library/cpp/binsaver/bin_saver.cpp | 14 | ||||
-rw-r--r-- | library/cpp/binsaver/bin_saver.h | 28 | ||||
-rw-r--r-- | library/cpp/binsaver/buffered_io.h | 82 | ||||
-rw-r--r-- | library/cpp/binsaver/class_factory.h | 24 | ||||
-rw-r--r-- | library/cpp/binsaver/mem_io.h | 4 |
5 files changed, 76 insertions, 76 deletions
diff --git a/library/cpp/binsaver/bin_saver.cpp b/library/cpp/binsaver/bin_saver.cpp index ca215fa809..fe0775af9f 100644 --- a/library/cpp/binsaver/bin_saver.cpp +++ b/library/cpp/binsaver/bin_saver.cpp @@ -42,10 +42,10 @@ void IBinSaver::StoreObject(IObjectBase* pObject) { ObjectQueue.push_back(pObject); (*Objects)[ptrId]; int typeId = pSaverClasses->GetObjectTypeID(pObject); - if (typeId == -1) { - fprintf(stderr, "IBinSaver: trying to save unregistered object\n"); - abort(); - } + if (typeId == -1) { + fprintf(stderr, "IBinSaver: trying to save unregistered object\n"); + abort(); + } DataChunk(&typeId, sizeof(typeId)); } } @@ -64,9 +64,9 @@ IObjectBase* IBinSaver::LoadObject() { IObjectBase* pObj = pSaverClasses->CreateObject(typeId); Y_ASSERT(pObj != nullptr); if (pObj == nullptr) { - fprintf(stderr, "IBinSaver: trying to load unregistered object\n"); - abort(); - } + fprintf(stderr, "IBinSaver: trying to load unregistered object\n"); + abort(); + } (*Objects)[ptrId] = pObj; ObjectQueue.push_back(pObj); return pObj; diff --git a/library/cpp/binsaver/bin_saver.h b/library/cpp/binsaver/bin_saver.h index 0e9e46a2e5..412424889f 100644 --- a/library/cpp/binsaver/bin_saver.h +++ b/library/cpp/binsaver/bin_saver.h @@ -156,13 +156,13 @@ private: } } - // hash_multimap + // hash_multimap template <class AMM> void DoAnyMultiMap(AMM& data) { - if (IsReading()) { - data.clear(); + if (IsReading()) { + data.clear(); TStoredSize nSize; - Add(3, &nSize); + Add(3, &nSize); TVector<typename AMM::key_type, typename std::allocator_traits<typename AMM::allocator_type>::template rebind_alloc<typename AMM::key_type>> indices; indices.resize(nSize); for (TStoredSize i = 0; i < nSize; ++i) @@ -170,19 +170,19 @@ private: for (TStoredSize i = 0; i < nSize; ++i) { std::pair<typename AMM::key_type, typename AMM::mapped_type> valToInsert; valToInsert.first = indices[i]; - Add(2, &valToInsert.second); - data.insert(valToInsert); - } - } else { + Add(2, &valToInsert.second); + data.insert(valToInsert); + } + } else { TStoredSize nSize = data.size(); CheckOverflow(nSize, data.size()); - Add(3, &nSize); + Add(3, &nSize); for (auto pos = data.begin(); pos != data.end(); ++pos) Add(1, (typename AMM::key_type*)(&pos->first)); for (auto pos = data.begin(); pos != data.end(); ++pos) - Add(2, &pos->second); - } - } + Add(2, &pos->second); + } + } template <class T> void DoAnySet(T& data) { @@ -270,7 +270,7 @@ private: IObjectBase* LoadObject(); bool bRead; - TBufferedStream<> File; + TBufferedStream<> File; // maps objects addresses during save(first) to addresses during load(second) - during loading // or serves as a sign that some object has been already stored - during storing bool StableOutput; @@ -357,7 +357,7 @@ public: 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) { DoAnySet(*pSet); diff --git a/library/cpp/binsaver/buffered_io.h b/library/cpp/binsaver/buffered_io.h index 659bc9f62b..75465c9c5c 100644 --- a/library/cpp/binsaver/buffered_io.h +++ b/library/cpp/binsaver/buffered_io.h @@ -26,7 +26,7 @@ struct IBinaryStream { } virtual bool IsValid() const = 0; - virtual bool IsFailed() const = 0; + virtual bool IsFailed() const = 0; private: virtual int WriteImpl(const void* userBuffer, int size) = 0; @@ -36,49 +36,49 @@ private: i64 LongWrite(const void* userBuffer, i64 size); }; -template <int N_SIZE = 16384> +template <int N_SIZE = 16384> class TBufferedStream { char Buf[N_SIZE]; i64 Pos, BufSize; IBinaryStream& Stream; - bool bIsReading, bIsEof, bFailed; + bool bIsReading, bIsEof, bFailed; void ReadComplex(void* userBuffer, i64 size) { - if (bIsEof) { - memset(userBuffer, 0, size); - return; - } + if (bIsEof) { + memset(userBuffer, 0, size); + return; + } char* dst = (char*)userBuffer; i64 leftBytes = BufSize - Pos; - memcpy(dst, Buf + Pos, leftBytes); - dst += leftBytes; - size -= leftBytes; - Pos = BufSize = 0; - if (size > N_SIZE) { + memcpy(dst, Buf + Pos, leftBytes); + dst += leftBytes; + size -= leftBytes; + Pos = BufSize = 0; + if (size > N_SIZE) { i64 n = Stream.Read(dst, size); - bFailed = Stream.IsFailed(); - if (n != size) { - bIsEof = true; - memset(dst + n, 0, size - n); - } - } else { - BufSize = Stream.Read(Buf, N_SIZE); - bFailed = Stream.IsFailed(); - if (BufSize == 0) - bIsEof = true; - Read(dst, size); - } - } - + bFailed = Stream.IsFailed(); + if (n != size) { + bIsEof = true; + memset(dst + n, 0, size - n); + } + } else { + BufSize = Stream.Read(Buf, N_SIZE); + bFailed = Stream.IsFailed(); + if (BufSize == 0) + bIsEof = true; + Read(dst, size); + } + } + void WriteComplex(const void* userBuffer, i64 size) { - Flush(); - if (size >= N_SIZE) { - Stream.Write(userBuffer, size); - bFailed = Stream.IsFailed(); + Flush(); + if (size >= N_SIZE) { + Stream.Write(userBuffer, size); + bFailed = Stream.IsFailed(); } else - Write(userBuffer, size); - } - + Write(userBuffer, size); + } + void operator=(const TBufferedStream&) { } @@ -94,16 +94,16 @@ public: } ~TBufferedStream() { if (!bIsReading) - Flush(); + Flush(); } - void Flush() { + void Flush() { Y_ASSERT(!bIsReading); - if (bIsReading) - return; - Stream.Write(Buf, Pos); - bFailed = Stream.IsFailed(); - Pos = 0; - } + if (bIsReading) + return; + Stream.Write(Buf, Pos); + bFailed = Stream.IsFailed(); + Pos = 0; + } bool IsEof() const { return bIsEof; } diff --git a/library/cpp/binsaver/class_factory.h b/library/cpp/binsaver/class_factory.h index 4bfb225b28..e83512331b 100644 --- a/library/cpp/binsaver/class_factory.h +++ b/library/cpp/binsaver/class_factory.h @@ -15,12 +15,12 @@ public: typedef const std::type_info* VFT; private: - typedef T* (*newFunc)(); + typedef T* (*newFunc)(); typedef THashMap<int, newFunc> CTypeNewHash; // typeID->newFunc() typedef THashMap<VFT, int> CTypeIndexHash; // vftable->typeID - CTypeIndexHash typeIndex; - CTypeNewHash typeInfo; + CTypeIndexHash typeIndex; + CTypeNewHash typeInfo; void RegisterTypeBase(int nTypeID, newFunc func, VFT vft); static VFT GetObjectType(T* pObject) { @@ -29,15 +29,15 @@ private: int VFT2TypeID(VFT t) { CTypeIndexHash::iterator i = typeIndex.find(t); if (i != typeIndex.end()) - return i->second; + return i->second; for (i = typeIndex.begin(); i != typeIndex.end(); ++i) { if (*i->first == *t) { - typeIndex[t] = i->second; - return i->second; - } - } - return -1; - } + typeIndex[t] = i->second; + return i->second; + } + } + return -1; + } public: template <class TT> @@ -45,10 +45,10 @@ public: RegisterTypeBase(nTypeID, func, &typeid(TT)); } void RegisterTypeSafe(int nTypeID, newFunc func) { - TPtr<T> pObj = func(); + TPtr<T> pObj = func(); VFT vft = GetObjectType(pObj); RegisterTypeBase(nTypeID, func, vft); - } + } T* CreateObject(int nTypeID) { newFunc f = typeInfo[nTypeID]; if (f) diff --git a/library/cpp/binsaver/mem_io.h b/library/cpp/binsaver/mem_io.h index ca5cf0598a..2a9e36fe68 100644 --- a/library/cpp/binsaver/mem_io.h +++ b/library/cpp/binsaver/mem_io.h @@ -6,7 +6,7 @@ namespace NMemIoInternals { class TMemoryStream: public IBinaryStream { TVector<char>& Data; ui64 Pos; - + public: TMemoryStream(TVector<char>* data, ui64 pos = 0) : Data(*data) @@ -15,7 +15,7 @@ namespace NMemIoInternals { } ~TMemoryStream() override { } // keep gcc happy - + bool IsValid() const override { return true; } |