diff options
author | LaG1924 <12997935+LaG1924@users.noreply.github.com> | 2020-07-25 18:49:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-25 18:49:18 +0200 |
commit | 0a2ba2cdb8e01bbd7e9e8ef1d0582ef6a892f837 (patch) | |
tree | 3c760d4d981aad30fa151343c224d3ea366c99d9 /external/optick/optick_serialization.h | |
parent | Merge pull request #36 from LaG1924/fix-windows-vs2019 (diff) | |
parent | Completely removed hardcoded list of blockstates (diff) | |
download | AltCraft-0a2ba2cdb8e01bbd7e9e8ef1d0582ef6a892f837.tar AltCraft-0a2ba2cdb8e01bbd7e9e8ef1d0582ef6a892f837.tar.gz AltCraft-0a2ba2cdb8e01bbd7e9e8ef1d0582ef6a892f837.tar.bz2 AltCraft-0a2ba2cdb8e01bbd7e9e8ef1d0582ef6a892f837.tar.lz AltCraft-0a2ba2cdb8e01bbd7e9e8ef1d0582ef6a892f837.tar.xz AltCraft-0a2ba2cdb8e01bbd7e9e8ef1d0582ef6a892f837.tar.zst AltCraft-0a2ba2cdb8e01bbd7e9e8ef1d0582ef6a892f837.zip |
Diffstat (limited to 'external/optick/optick_serialization.h')
-rw-r--r-- | external/optick/optick_serialization.h | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/external/optick/optick_serialization.h b/external/optick/optick_serialization.h new file mode 100644 index 0000000..91de32d --- /dev/null +++ b/external/optick/optick_serialization.h @@ -0,0 +1,120 @@ +#pragma once +#include "optick_common.h" + +#if USE_OPTICK +#include "optick_memory.h" + +#if defined(OPTICK_MSVC) +#pragma warning( push ) + +//C4250. inherits 'std::basic_ostream' +#pragma warning( disable : 4250 ) + +//C4127. Conditional expression is constant +#pragma warning( disable : 4127 ) +#endif + +namespace Optick +{ + class OutputDataStream : private ostringstream + { + public: + static OutputDataStream Empty; + // Move constructor rocks! + // Beware of one copy here(do not use it in performance critical parts) + string GetData(); + + // It is important to make private inheritance in order to avoid collision with default operator implementation + friend OutputDataStream &operator << ( OutputDataStream &stream, const char* val ); + friend OutputDataStream &operator << ( OutputDataStream &stream, int val ); + friend OutputDataStream &operator << ( OutputDataStream &stream, uint64 val ); + friend OutputDataStream &operator << ( OutputDataStream &stream, uint32 val ); + friend OutputDataStream &operator << ( OutputDataStream &stream, int64 val ); + friend OutputDataStream &operator << ( OutputDataStream &stream, char val ); + friend OutputDataStream &operator << ( OutputDataStream &stream, byte val ); + friend OutputDataStream &operator << ( OutputDataStream &stream, int8 val); + friend OutputDataStream &operator << ( OutputDataStream &stream, float val); + friend OutputDataStream &operator << ( OutputDataStream &stream, const string& val ); + friend OutputDataStream &operator << ( OutputDataStream &stream, const wstring& val ); + + OutputDataStream& Write(const char* buffer, size_t size); + }; + + template<class T> + OutputDataStream& operator<<(OutputDataStream &stream, const vector<T>& val) + { + stream << (uint32)val.size(); + + for(auto it = val.begin(); it != val.end(); ++it) + { + const T& element = *it; + stream << element; + } + + return stream; + } + + template<class T, uint32 N> + OutputDataStream& operator<<(OutputDataStream &stream, const MemoryPool<T, N>& val) + { + stream << (uint32)val.Size(); + + val.ForEach([&](const T& data) + { + stream << data; + }); + + return stream; + } + + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + class InputDataStream : private stringstream { + public: + bool CanRead() { return !eof(); } + + InputDataStream(); + + void Append(const char *buffer, size_t length); + bool Skip(size_t length); + size_t Length(); + + template<class T> + bool Peek(T& data) + { + if (Length() < sizeof(T)) + return false; + + pos_type currentPos = tellg(); + read((char*)&data, sizeof(T)); + seekg(currentPos); + return true; + } + + template<class T> + bool Read(T& data) + { + if (Length() < sizeof(T)) + return false; + + read((char*)&data, sizeof(T)); + return true; + } + + friend InputDataStream &operator >> (InputDataStream &stream, byte &val ); + friend InputDataStream &operator >> (InputDataStream &stream, int16 &val); + friend InputDataStream &operator >> (InputDataStream &stream, uint16 &val); + friend InputDataStream &operator >> (InputDataStream &stream, int32 &val ); + friend InputDataStream &operator >> (InputDataStream &stream, uint32 &val ); + friend InputDataStream &operator >> (InputDataStream &stream, int64 &val ); + friend InputDataStream &operator >> (InputDataStream &stream, uint64 &val ); + friend InputDataStream &operator >> (InputDataStream &stream, string &val); + }; + + +} + +#if defined(OPTICK_MSVC) +#pragma warning( pop ) +#endif + +#endif //USE_OPTICK
\ No newline at end of file |