Skip to content

Commit

Permalink
This file has been on my disk far too long, time to commit it, though…
Browse files Browse the repository at this point in the history
… it's not used anywhere(yet)
  • Loading branch information
lhog committed Dec 16, 2024
1 parent 05c5724 commit e41b715
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions rts/System/creg/STL_Bitset.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#pragma once

#include "creg_cond.h"
#include <bitset>
#include <bit>
#include <array>
#include <cstdint>
#include "../TemplateUtils.hpp"

#ifdef USING_CREG

namespace creg
{
template<size_t N>
class BitsetType : public IType
{
public:
using T = std::bitset<N>;
BitsetType() : IType(sizeof(T)) { }
~BitsetType() { }

void Serialize(ISerializer* s, void* instance)
{
T& ct = *(T*)instance;

std::array<uint8_t, sizeof(T)> bytesRep = {0};

if (s->IsWriting())
bytesRep = std::bit_cast<decltype(bytesRep)>(ct);

for (auto& b : bytesRep) {
s->SerializeInt(b, sizeof(b));
}

if (!s->IsWriting())
ct = std::bit_cast<T>(bytesRep);
}
std::string GetName() const {
return std::string("bitset<" + std::to_string(N) + ">");
}
};

template<size_t N>
struct DeduceType<std::bitset<N> > {
static std::unique_ptr<IType> Get() {
return std::unique_ptr<IType>(new BitsetType<N>());
}
};
}

#endif // USING_CREG

0 comments on commit e41b715

Please sign in to comment.