aboutsummaryrefslogtreecommitdiff
path: root/zencore/include
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-08-31 20:47:06 +0200
committerStefan Boberg <[email protected]>2021-08-31 20:47:06 +0200
commitf10e4d32e26603093d1986acabfa3147096e7586 (patch)
tree20f4762659e3c1ec90ec9d42091a03362e2b0c06 /zencore/include
parentRemoved unused packages from vcpkg.json (diff)
downloadzen-f10e4d32e26603093d1986acabfa3147096e7586.tar.xz
zen-f10e4d32e26603093d1986acabfa3147096e7586.zip
Make it possible to distinguish an empty buffer from a null buffer
Previously a size of zero was used to indicate null-ness. Now we use a additional flag to indicate null-ness instead
Diffstat (limited to 'zencore/include')
-rw-r--r--zencore/include/zencore/iobuffer.h14
1 files changed, 10 insertions, 4 deletions
diff --git a/zencore/include/zencore/iobuffer.h b/zencore/include/zencore/iobuffer.h
index 960918239..3e24b51a0 100644
--- a/zencore/include/zencore/iobuffer.h
+++ b/zencore/include/zencore/iobuffer.h
@@ -32,7 +32,7 @@ struct IoBufferFileReference
struct IoBufferCore
{
public:
- IoBufferCore() = default;
+ inline IoBufferCore() : m_Flags(kIsNull) {}
inline IoBufferCore(const void* DataPtr, size_t SizeBytes) : m_DataPtr(DataPtr), m_DataBytes(SizeBytes) {}
inline IoBufferCore(const IoBufferCore* Outer, const void* DataPtr, size_t SizeBytes)
: m_DataPtr(DataPtr)
@@ -74,7 +74,9 @@ public:
inline void EnsureDataValid() const
{
if ((m_Flags & kIsExtended) && !(m_Flags & kIsMaterialized))
+ {
Materialize();
+ }
}
inline bool IsOwnedByThis() const { return !!(m_Flags & kIsOwnedByThis); }
@@ -101,9 +103,9 @@ public:
return m_OuterCore && m_OuterCore->IsOwned();
}
- inline bool IsImmutable() const { return !(m_Flags & kIsMutable); }
- inline bool IsWholeFile() const { return !!(m_Flags & kIsWholeFile); }
- inline bool IsNull() const { return m_DataBytes == 0; }
+ inline bool IsImmutable() const { return (m_Flags & kIsMutable) == 0; }
+ inline bool IsWholeFile() const { return (m_Flags & kIsWholeFile) != 0; }
+ inline bool IsNull() const { return (m_Flags & kIsNull) != 0; }
inline IoBufferExtendedCore* ExtendedCore();
inline const IoBufferExtendedCore* ExtendedCore() const;
@@ -181,6 +183,10 @@ protected:
kIsMaterialized = 1 << 3, // Data pointers are valid
kLowLevelAlloc = 1 << 4, // Using direct memory allocation
kIsWholeFile = 1 << 5, // References an entire file
+ kIsNull = 1 << 7, // This is a null IoBuffer
+
+ // Note that we have some extended flags defined below
+ // so not all bits are available to use here
kContentTypeBit0 = 1 << (24 + 0), // These constants
kContentTypeBit1 = 1 << (24 + 1), // are here mostly to