Added serilaisation wrapper for 256-byte char array (used for some AC string types)

This commit is contained in:
Ralph Wessel
2024-10-12 09:06:32 +01:00
parent 36e50bb63e
commit dbc2c79f2a
5 changed files with 70 additions and 3 deletions
@@ -1,7 +1,7 @@
#include "Speckle/Database/Content/BIMRecord.h"
#include "Active/Serialise/Item/Wrapper/ValueOptionWrap.h"
#include "Speckle/Serialise/Units/LengthUnit.h"
#include "Speckle/Serialise/Types/Units/LengthUnit.h"
#include "Speckle/Utility/Guid.h"
#include <array>
@@ -0,0 +1,55 @@
#ifndef SPECKLE_SERIALISE_LENGTH_UNIT
#define SPECKLE_SERIALISE_LENGTH_UNIT
#include "Active/Serialise/Item/Wrapper/ValueWrap.h"
#include "Active/Serialise/Item/Wrapper/ValueOptionWrap.h"
#include "Active/Utility/BufferOut.h"
namespace active::serialise {
constexpr size_t str256Size = 256;
///NB: This is primarily for Archicad that still uses fixed 256-bytes char array strings in some contexts
using Str256 = std::array<char, str256Size>;
// MARK: - Specialisations for bool
/*!
Import the object from the specified string (specialisation for bool)
@param source The string to read
@return True if the data was successfully read
*/
template<> inline
bool ValueWrap<Str256>::read(const utility::String& source) {
source.writeUTF8(active::utility::BufferOut{get()});
return true;
} //ValueWrap<bool>::read
/*!
Import the object from the specified string (specialisation for bool)
@param source The string to read
@return True if the data was successfully read
*/
template<> inline
bool ValueWrap<std::optional<Str256>>::read(const utility::String& source) {
base::get() = Str256{};
source.writeUTF8(active::utility::BufferOut{*base::get()});
return true;
} //ValueWrap<bool>::read
/*!
Export the object to the specified string (specialisation for bool)
@param dest The string to write the data to
@return True if the data was successfully written
*/
template<> inline
bool ValueWrap<Str256>::write(utility::String& dest) const {
dest.assign(reinterpret_cast<const char*>(&get()), str256Size);
return true;
} //ValueWrap<bool>::write
}
#endif //SPECKLE_SERIALISE_LENGTH_UNIT
@@ -1,4 +1,4 @@
#include "Speckle/Serialise/Units/LengthUnit.h"
#include "Speckle/Serialise/Types/Units/LengthUnit.h"
#include <algorithm>
#include <map>
@@ -49,6 +49,7 @@
2196F3052CB57E8000450DFC /* Storey.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2196F3032CB57E7F00450DFC /* Storey.cpp */; };
2199881E2BD833830035E5EA /* libArchicad27.a in CopyFiles */ = {isa = PBXBuildFile; fileRef = 21379E082AE47A6400A1584C /* libArchicad27.a */; };
21A0FBA42CB880690023F24E /* FinishCollector.h in Headers */ = {isa = PBXBuildFile; fileRef = 21A0FB9F2CB880690023F24E /* FinishCollector.h */; };
21A0FBB52CBA5E380023F24E /* Str256.h in Headers */ = {isa = PBXBuildFile; fileRef = 21A0FBB42CBA5E380023F24E /* Str256.h */; };
21AEF9BA2CA606B5000B8681 /* DetachedReference.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 21AEF9B92CA606B4000B8681 /* DetachedReference.cpp */; };
21AEF9BC2CA6DF84000B8681 /* DetachmentManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 21AEF9BB2CA6DF84000B8681 /* DetachmentManager.cpp */; };
21AEF9BE2CA6FDA4000B8681 /* DetachedWrap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 21AEF9BD2CA6FDA4000B8681 /* DetachedWrap.cpp */; };
@@ -189,6 +190,7 @@
219712682BE7E2D500D9EF7E /* Serialisation.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = Serialisation.md; sourceTree = "<group>"; };
21A0FB9F2CB880690023F24E /* FinishCollector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FinishCollector.h; sourceTree = "<group>"; };
21A0FBA92CB9324A0023F24E /* FinishProxy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FinishProxy.h; sourceTree = "<group>"; };
21A0FBB42CBA5E380023F24E /* Str256.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Str256.h; sourceTree = "<group>"; };
21AEF9B32CA5F7CF000B8681 /* DetachedWrap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DetachedWrap.h; sourceTree = "<group>"; };
21AEF9B52CA5FA02000B8681 /* DetachedReference.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DetachedReference.h; sourceTree = "<group>"; };
21AEF9B72CA5FCB6000B8681 /* DetachmentManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DetachmentManager.h; sourceTree = "<group>"; };
@@ -296,8 +298,8 @@
21A0FBA02CB880690023F24E /* Collection */,
21AEF9C72CA818EA000B8681 /* Detached */,
21F69F3A2C6B880B008B6A06 /* JSBase */,
2196F2DF2CB0566500450DFC /* Units */,
219712682BE7E2D500D9EF7E /* Serialisation.md */,
21A0FBB12CBA5E0E0023F24E /* Types */,
);
path = Serialise;
sourceTree = "<group>";
@@ -485,6 +487,15 @@
path = Collection;
sourceTree = "<group>";
};
21A0FBB12CBA5E0E0023F24E /* Types */ = {
isa = PBXGroup;
children = (
21A0FBB42CBA5E380023F24E /* Str256.h */,
2196F2DF2CB0566500450DFC /* Units */,
);
path = Types;
sourceTree = "<group>";
};
21AEF9C72CA818EA000B8681 /* Detached */ = {
isa = PBXGroup;
children = (
@@ -694,6 +705,7 @@
215F088C2CA195EC00CD343B /* ArchicadDBaseCore.h in Headers */,
21D0BDE72C943D3F0077E104 /* RecordID.h in Headers */,
21D0BD212C86F0280077E104 /* AccountDatabase.h in Headers */,
21A0FBB52CBA5E380023F24E /* Str256.h in Headers */,
210CC86F2C7E879700610F58 /* ArgumentBase.h in Headers */,
210CC8A02C81E34400610F58 /* Platform.h in Headers */,
219246132CA34DCE00CF5703 /* Mesh.h in Headers */,