From 2504538a3a164f27a96f413f5b389f8dad6b2cac Mon Sep 17 00:00:00 2001 From: Mattes D Date: Wed, 28 Aug 2019 08:29:02 +0200 Subject: Added a basic PalettedBlockArea implementation (#4377) --- src/BlockTypePalette.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/BlockTypePalette.h (limited to 'src/BlockTypePalette.h') diff --git a/src/BlockTypePalette.h b/src/BlockTypePalette.h new file mode 100644 index 000000000..47318f171 --- /dev/null +++ b/src/BlockTypePalette.h @@ -0,0 +1,44 @@ +#pragma once + +#include +#include "BlockState.h" + + + + + +/** Holds a palette that maps block type + state into numbers. +Used primarily by PalettedBlockArea to translate between numeric and stringular block representation. +The object itself provides no thread safety, users of this class need to handle locking, if required. */ +class BlockTypePalette +{ +public: + + /** Create a new empty instance. */ + BlockTypePalette(); + + /** Returns the index of the specified block type name and state. + If the combination is not found, it is added to the palette and the new index is returned. */ + UInt32 index(const AString & aBlockTypeName, const BlockState & aBlockState); + + /** Returns the of the specified block type name and state, if it exists. + If the combination is not found, returns . */ + std::pair maybeIndex(const AString & aBlockTypeName, const BlockState & aBlockState) const; + + /** Returns the total number of entries in the palette. */ + UInt32 count() const; + + /** Returns the blockspec represented by the specified palette index. + The index must be valid (ASSERTed). */ + const std::pair & entry(UInt32 aIndex) const; + + /** Adds missing entries from aOther to this, and returns an index-transform map from aOther to this. + Used when pasting two areas, to transform the src palette to dst palette. */ + std::map createTransformMap(const BlockTypePalette & aOther); + + +protected: + + /** The palette. Each item in the vector represents a single entry in the palette, the vector index is the palette index. */ + std::vector> mPalette; +}; -- cgit v1.2.3