Commit 9316130b authored by Morten Ofstad's avatar Morten Ofstad
Browse files

Added MetadataReadAccess/MetadataWriteAccess interfaces and implemented the...

Added MetadataReadAccess/MetadataWriteAccess interfaces and implemented the MetadataReadAccess in VolumeDataLayout.
parent 10967af6
......@@ -54,6 +54,98 @@ struct MetadataKey
inline bool operator==(const MetadataKey& a, const MetadataKey& b) { return a.type == b.type && a.category == b.category && a.name == b.name; }
/// \brief Interface for read access to Metadata
class MetadataReadAccess
{
protected:
virtual ~MetadataReadAccess() {}
virtual void GetMetadataBLOB(const char* category, const char* name, const void **data, size_t *size) const = 0; ///< Returns the metadata BLOB with the given category and name
public:
// These functions provide access to Metadata
virtual bool IsMetadataIntAvailable(const char* category, const char* name) const = 0; ///< Returns true if a metadata int with the given category and name is available
virtual bool IsMetadataIntVector2Available(const char* category, const char* name) const = 0; ///< Returns true if a metadata IntVector2 with the given category and name is available
virtual bool IsMetadataIntVector3Available(const char* category, const char* name) const = 0; ///< Returns true if a metadata IntVector3 with the given category and name is available
virtual bool IsMetadataIntVector4Available(const char* category, const char* name) const = 0; ///< Returns true if a metadata IntVector4 with the given category and name is available
virtual bool IsMetadataFloatAvailable(const char* category, const char* name) const = 0; ///< Returns true if a metadata float with the given category and name is available
virtual bool IsMetadataFloatVector2Available(const char* category, const char* name) const = 0; ///< Returns true if a metadata FloatVector2 with the given category and name is available
virtual bool IsMetadataFloatVector3Available(const char* category, const char* name) const = 0; ///< Returns true if a metadata FloatVector3 with the given category and name is available
virtual bool IsMetadataFloatVector4Available(const char* category, const char* name) const = 0; ///< Returns true if a metadata FloatVector4 with the given category and name is available
virtual bool IsMetadataDoubleAvailable(const char* category, const char* name) const = 0; ///< Returns true if a metadata double with the given category and name is available
virtual bool IsMetadataDoubleVector2Available(const char* category, const char* name) const = 0; ///< Returns true if a metadata DoubleVector2 with the given category and name is available
virtual bool IsMetadataDoubleVector3Available(const char* category, const char* name) const = 0; ///< Returns true if a metadata DoubleVector3 with the given category and name is available
virtual bool IsMetadataDoubleVector4Available(const char* category, const char* name) const = 0; ///< Returns true if a metadata DoubleVector4 with the given category and name is available
virtual bool IsMetadataStringAvailable(const char* category, const char* name) const = 0; ///< Returns true if a metadata string with the given category and name is available
virtual bool IsMetadataBLOBAvailable(const char* category, const char* name) const = 0; ///< Returns true if a metadata BLOB with the given category and name is available
virtual int GetMetadataInt(const char* category, const char* name) const = 0; ///< Returns the metadata int with the given category and name
virtual IntVector2 GetMetadataIntVector2(const char* category, const char* name) const = 0; ///< Returns the metadata IntVector2 with the given category and name
virtual IntVector3 GetMetadataIntVector3(const char* category, const char* name) const = 0; ///< Returns the metadata IntVector3 with the given category and name
virtual IntVector4 GetMetadataIntVector4(const char* category, const char* name) const = 0; ///< Returns the metadata IntVector4 with the given category and name
virtual float GetMetadataFloat(const char* category, const char* name) const = 0; ///< Returns the metadata float with the given category and name
virtual FloatVector2 GetMetadataFloatVector2(const char* category, const char* name) const = 0; ///< Returns the metadata FloatVector2 with the given category and name
virtual FloatVector3 GetMetadataFloatVector3(const char* category, const char* name) const = 0; ///< Returns the metadata FloatVector3 with the given category and name
virtual FloatVector4 GetMetadataFloatVector4(const char* category, const char* name) const = 0; ///< Returns the metadata FloatVector4 with the given category and name
virtual double GetMetadataDouble(const char* category, const char* name) const = 0; ///< Returns the metadata double with the given category and name
virtual DoubleVector2 GetMetadataDoubleVector2(const char* category, const char* name) const = 0; ///< Returns the metadata DoubleVector2 with the given category and name
virtual DoubleVector3 GetMetadataDoubleVector3(const char* category, const char* name) const = 0; ///< Returns the metadata DoubleVector3 with the given category and name
virtual DoubleVector4 GetMetadataDoubleVector4(const char* category, const char* name) const = 0; ///< Returns the metadata DoubleVector4 with the given category and name
virtual const char* GetMetadataString(const char* category, const char* name) const = 0; ///< Returns the metadata string with the given category and name
template <typename T>
inline void GetMetadataBLOB(const char* category, const char* name, std::vector<T> &value) const
{
const void* data; size_t size;
GetMetadataBLOB(category, name, &data, &size);
value.assign(reinterpret_cast<const T *>(data), reinterpret_cast<const T *>(data) + size/sizeof(T));
}
};
/// \brief Interface for write access to Metadata
class MetadataWriteAccess
{
protected:
virtual ~MetadataWriteAccess() {}
virtual void SetMetadataString(const char* category, const char* name, const char* value) = 0; ///< Sets a metadata string with the given category and name to the given value
virtual void SetMetadataBLOB(const char* category, const char* name, const void *data, size_t size) = 0; ///< Sets a metadata BLOB with the given category and name to the given value
public:
virtual void SetMetadataInt(const char* category, const char* name, int value) = 0; ///< Sets a metadata int with the given category and name to the given value
virtual void SetMetadataIntVector2(const char* category, const char* name, IntVector2 value) = 0; ///< Sets a metadata IntVector2 with the given category and name to the given value
virtual void SetMetadataIntVector3(const char* category, const char* name, IntVector3 value) = 0; ///< Sets a metadata IntVector3 with the given category and name to the given value
virtual void SetMetadataIntVector4(const char* category, const char* name, IntVector4 value) = 0; ///< Sets a metadata IntVector4 with the given category and name to the given value
virtual void SetMetadataFloat(const char* category, const char* name, float value) = 0; ///< Sets a metadata float with the given category and name to the given value
virtual void SetMetadataFloatVector2(const char* category, const char* name, FloatVector2 value) = 0; ///< Sets a metadata FloatVector2 with the given category and name to the given value
virtual void SetMetadataFloatVector3(const char* category, const char* name, FloatVector3 value) = 0; ///< Sets a metadata FloatVector3 with the given category and name to the given value
virtual void SetMetadataFloatVector4(const char* category, const char* name, FloatVector4 value) = 0; ///< Sets a metadata FloatVector4 with the given category and name to the given value
virtual void SetMetadataDouble(const char* category, const char* name, double value) = 0; ///< Sets a metadata double with the given category and name to the given value
virtual void SetMetadataDoubleVector2(const char* category, const char* name, DoubleVector2 value) = 0; ///< Sets a metadata DoubleVector2 with the given category and name to the given value
virtual void SetMetadataDoubleVector3(const char* category, const char* name, DoubleVector3 value) = 0; ///< Sets a metadata DoubleVector3 with the given category and name to the given value
virtual void SetMetadataDoubleVector4(const char* category, const char* name, DoubleVector4 value) = 0; ///< Sets a metadata DoubleVector4 with the given category and name to the given value
inline void SetMetadataString(const char* category, const char* name, std::string const &value) ///< Sets a metadata string with the given category and name to the given value
{
SetMetadataString(category, name, value.c_str());
}
template <typename T>
inline void SetMetadataBLOB(const char* category, const char* name, std::vector<T> const &value) ///< Sets a metadata BLOB with the given category and name to the given value
{
SetMetadataBLOB(category, name, value.empty() ? NULL : &value.front(), value.size() * sizeof(T));
}
/// Copy the metadata from another MetadataContainer
/// \param category the metadata category to copy
/// \param metadataReadAccess the MetadataReadAccess interface to copy from
virtual void CopyMetadata(const char* category, MetadataReadAccess const *metadataReadAccess) = 0;
virtual void ClearMetadata(const char* category, const char* name) = 0; ///< Clear the metadata with the given category and name
virtual void ClearMetadata(const char* category) = 0; ///< Clear the metadata with the given category
};
} // end namespace OpenVDS
namespace std
......@@ -72,7 +164,7 @@ struct hash<OpenVDS::MetadataKey>
namespace OpenVDS
{
struct MetadataContainer
struct MetadataContainer : public MetadataReadAccess /*, public MetadataWriteAccess */
{
std::unordered_map<MetadataKey, int> intData;
std::unordered_map<MetadataKey, IntVector2> intVector2Data;
......@@ -94,7 +186,44 @@ struct MetadataContainer
std::unordered_map<MetadataKey, std::vector<uint8_t>> blobData;
std::vector<MetadataKey> keys;
bool IsMetadataIntAvailable(const char* category, const char* name) const override { MetadataKey key = { MetadataType::Int, category, name }; return intData.find(key) != intData.end(); }
bool IsMetadataIntVector2Available(const char* category, const char* name) const override { MetadataKey key = { MetadataType::IntVector2, category, name }; return intVector2Data.find(key) != intVector2Data.end(); }
bool IsMetadataIntVector3Available(const char* category, const char* name) const override { MetadataKey key = { MetadataType::IntVector3, category, name }; return intVector3Data.find(key) != intVector3Data.end(); }
bool IsMetadataIntVector4Available(const char* category, const char* name) const override { MetadataKey key = { MetadataType::IntVector4, category, name }; return intVector4Data.find(key) != intVector4Data.end(); }
bool IsMetadataFloatAvailable(const char* category, const char* name) const override { MetadataKey key = { MetadataType::Float, category, name }; return floatData.find(key) != floatData.end(); }
bool IsMetadataFloatVector2Available(const char* category, const char* name) const override { MetadataKey key = { MetadataType::FloatVector2, category, name }; return floatVector2Data.find(key) != floatVector2Data.end(); }
bool IsMetadataFloatVector3Available(const char* category, const char* name) const override { MetadataKey key = { MetadataType::FloatVector3, category, name }; return floatVector3Data.find(key) != floatVector3Data.end(); }
bool IsMetadataFloatVector4Available(const char* category, const char* name) const override { MetadataKey key = { MetadataType::FloatVector4, category, name }; return floatVector4Data.find(key) != floatVector4Data.end(); }
bool IsMetadataDoubleAvailable(const char* category, const char* name) const override { MetadataKey key = { MetadataType::Double, category, name }; return doubleData.find(key) != doubleData.end(); }
bool IsMetadataDoubleVector2Available(const char* category, const char* name) const override { MetadataKey key = { MetadataType::DoubleVector2, category, name }; return doubleVector2Data.find(key) != doubleVector2Data.end(); }
bool IsMetadataDoubleVector3Available(const char* category, const char* name) const override { MetadataKey key = { MetadataType::DoubleVector3, category, name }; return doubleVector3Data.find(key) != doubleVector3Data.end(); }
bool IsMetadataDoubleVector4Available(const char* category, const char* name) const override { MetadataKey key = { MetadataType::DoubleVector4, category, name }; return doubleVector4Data.find(key) != doubleVector4Data.end(); }
bool IsMetadataStringAvailable(const char* category, const char* name) const override { MetadataKey key = { MetadataType::String, category, name }; return stringData.find(key) != stringData.end(); }
bool IsMetadataBLOBAvailable(const char* category, const char* name) const override { MetadataKey key = { MetadataType::BLOB, category, name }; return blobData.find(key) != blobData.end(); }
int GetMetadataInt(const char* category, const char* name) const override { MetadataKey key = { MetadataType::Int, category, name }; auto it = intData.find(key); return it != intData.end() ? it->second : int(); }
IntVector2 GetMetadataIntVector2(const char* category, const char* name) const override { MetadataKey key = { MetadataType::IntVector2, category, name }; auto it = intVector2Data.find(key); return it != intVector2Data.end() ? it->second : IntVector2(); }
IntVector3 GetMetadataIntVector3(const char* category, const char* name) const override { MetadataKey key = { MetadataType::IntVector3, category, name }; auto it = intVector3Data.find(key); return it != intVector3Data.end() ? it->second : IntVector3(); }
IntVector4 GetMetadataIntVector4(const char* category, const char* name) const override { MetadataKey key = { MetadataType::IntVector4, category, name }; auto it = intVector4Data.find(key); return it != intVector4Data.end() ? it->second : IntVector4(); }
float GetMetadataFloat(const char* category, const char* name) const override { MetadataKey key = { MetadataType::Float, category, name }; auto it = floatData.find(key); return it != floatData.end() ? it->second : float(); }
FloatVector2 GetMetadataFloatVector2(const char* category, const char* name) const override { MetadataKey key = { MetadataType::FloatVector2, category, name }; auto it = floatVector2Data.find(key); return it != floatVector2Data.end() ? it->second : FloatVector2(); }
FloatVector3 GetMetadataFloatVector3(const char* category, const char* name) const override { MetadataKey key = { MetadataType::FloatVector3, category, name }; auto it = floatVector3Data.find(key); return it != floatVector3Data.end() ? it->second : FloatVector3(); }
FloatVector4 GetMetadataFloatVector4(const char* category, const char* name) const override { MetadataKey key = { MetadataType::FloatVector4, category, name }; auto it = floatVector4Data.find(key); return it != floatVector4Data.end() ? it->second : FloatVector4(); }
double GetMetadataDouble(const char* category, const char* name) const override { MetadataKey key = { MetadataType::Double, category, name }; auto it = doubleData.find(key); return it != doubleData.end() ? it->second : double(); }
DoubleVector2 GetMetadataDoubleVector2(const char* category, const char* name) const override { MetadataKey key = { MetadataType::DoubleVector2, category, name }; auto it = doubleVector2Data.find(key); return it != doubleVector2Data.end() ? it->second : DoubleVector2(); }
DoubleVector3 GetMetadataDoubleVector3(const char* category, const char* name) const override { MetadataKey key = { MetadataType::DoubleVector3, category, name }; auto it = doubleVector3Data.find(key); return it != doubleVector3Data.end() ? it->second : DoubleVector3(); }
DoubleVector4 GetMetadataDoubleVector4(const char* category, const char* name) const override { MetadataKey key = { MetadataType::DoubleVector4, category, name }; auto it = doubleVector4Data.find(key); return it != doubleVector4Data.end() ? it->second : DoubleVector4(); }
const char* GetMetadataString(const char* category, const char* name) const override { MetadataKey key = { MetadataType::String, category, name }; auto it = stringData.find(key); return it != stringData.end() ? it->second.c_str() : ""; }
void GetMetadataBLOB(const char* category, const char* name, const void **data, size_t *size) const override
{
MetadataKey key = { MetadataType::BLOB, category, name };
auto it = blobData.find(key);
*data = (it != blobData.end()) ? it->second.data() : nullptr;
*size = (it != blobData.end()) ? it->second.size() : 0;
}
};
} // end namespace OpenVDS
#endif // OPENVDS_METADATA_H
......@@ -650,6 +650,9 @@ public:
virtual int addReference() = 0;
virtual int removeReference() = 0;
virtual int getMaxPages() = 0;
virtual void setMaxPages(int maxPages) = 0;
virtual VolumeDataPage *createPage(int64_t chunkIndex) = 0;
virtual VolumeDataPage *readPage(int64_t chunkIndex) = 0;
......
......@@ -20,6 +20,7 @@
#include <OpenVDS/VolumeDataChannelDescriptor.h>
#include <OpenVDS/VolumeDataAxisDescriptor.h>
#include <OpenVDS/Metadata.h>
namespace OpenVDS
{
......@@ -27,7 +28,7 @@ namespace OpenVDS
/// \brief a class that contains axis and channel information for a VDS
/// A layout is associated with a VDS object and contains information about axis and channels in the VDS.
/// A VolumeDataLayout can be invalidated when the VDS is invalidated.
class VolumeDataLayout //: public MetadataReadAccess
class VolumeDataLayout : public MetadataReadAccess
{
protected:
VolumeDataLayout() {};
......
......@@ -20,6 +20,7 @@
#include "VolumeDataLayoutImpl.h"
#include "VolumeDataChannelMapping.h"
#include "DimensionGroup.h"
#include "OpenVDSHandle.h"
#include "Bitmask.h"
......@@ -423,4 +424,34 @@ void VolumeDataLayoutImpl::createLayers(DimensionGroup dimensionGroup, int32_t b
}
}
bool VolumeDataLayoutImpl::IsMetadataIntAvailable(const char* category, const char* name) const { return m_handle.metadataContainer.IsMetadataIntAvailable(category, name); }
bool VolumeDataLayoutImpl::IsMetadataIntVector2Available(const char* category, const char* name) const { return m_handle.metadataContainer.IsMetadataIntVector2Available(category, name); }
bool VolumeDataLayoutImpl::IsMetadataIntVector3Available(const char* category, const char* name) const { return m_handle.metadataContainer.IsMetadataIntVector3Available(category, name); }
bool VolumeDataLayoutImpl::IsMetadataIntVector4Available(const char* category, const char* name) const { return m_handle.metadataContainer.IsMetadataIntVector4Available(category, name); }
bool VolumeDataLayoutImpl::IsMetadataFloatAvailable(const char* category, const char* name) const { return m_handle.metadataContainer.IsMetadataFloatAvailable(category, name); }
bool VolumeDataLayoutImpl::IsMetadataFloatVector2Available(const char* category, const char* name) const { return m_handle.metadataContainer.IsMetadataFloatVector2Available(category, name); }
bool VolumeDataLayoutImpl::IsMetadataFloatVector3Available(const char* category, const char* name) const { return m_handle.metadataContainer.IsMetadataFloatVector3Available(category, name); }
bool VolumeDataLayoutImpl::IsMetadataFloatVector4Available(const char* category, const char* name) const { return m_handle.metadataContainer.IsMetadataFloatVector4Available(category, name); }
bool VolumeDataLayoutImpl::IsMetadataDoubleAvailable(const char* category, const char* name) const { return m_handle.metadataContainer.IsMetadataDoubleAvailable(category, name); }
bool VolumeDataLayoutImpl::IsMetadataDoubleVector2Available(const char* category, const char* name) const { return m_handle.metadataContainer.IsMetadataDoubleVector2Available(category, name); }
bool VolumeDataLayoutImpl::IsMetadataDoubleVector3Available(const char* category, const char* name) const { return m_handle.metadataContainer.IsMetadataDoubleVector3Available(category, name); }
bool VolumeDataLayoutImpl::IsMetadataDoubleVector4Available(const char* category, const char* name) const { return m_handle.metadataContainer.IsMetadataDoubleVector4Available(category, name); }
bool VolumeDataLayoutImpl::IsMetadataStringAvailable(const char* category, const char* name) const { return m_handle.metadataContainer.IsMetadataStringAvailable(category, name); }
bool VolumeDataLayoutImpl::IsMetadataBLOBAvailable(const char* category, const char* name) const { return m_handle.metadataContainer.IsMetadataBLOBAvailable(category, name); }
int VolumeDataLayoutImpl::GetMetadataInt(const char* category, const char* name) const { return m_handle.metadataContainer.GetMetadataInt(category, name); }
IntVector2 VolumeDataLayoutImpl::GetMetadataIntVector2(const char* category, const char* name) const { return m_handle.metadataContainer.GetMetadataIntVector2(category, name); }
IntVector3 VolumeDataLayoutImpl::GetMetadataIntVector3(const char* category, const char* name) const { return m_handle.metadataContainer.GetMetadataIntVector3(category, name); }
IntVector4 VolumeDataLayoutImpl::GetMetadataIntVector4(const char* category, const char* name) const { return m_handle.metadataContainer.GetMetadataIntVector4(category, name); }
float VolumeDataLayoutImpl::GetMetadataFloat(const char* category, const char* name) const { return m_handle.metadataContainer.GetMetadataFloat(category, name); }
FloatVector2 VolumeDataLayoutImpl::GetMetadataFloatVector2(const char* category, const char* name) const { return m_handle.metadataContainer.GetMetadataFloatVector2(category, name); }
FloatVector3 VolumeDataLayoutImpl::GetMetadataFloatVector3(const char* category, const char* name) const { return m_handle.metadataContainer.GetMetadataFloatVector3(category, name); }
FloatVector4 VolumeDataLayoutImpl::GetMetadataFloatVector4(const char* category, const char* name) const { return m_handle.metadataContainer.GetMetadataFloatVector4(category, name); }
double VolumeDataLayoutImpl::GetMetadataDouble(const char* category, const char* name) const { return m_handle.metadataContainer.GetMetadataDouble(category, name); }
DoubleVector2 VolumeDataLayoutImpl::GetMetadataDoubleVector2(const char* category, const char* name) const { return m_handle.metadataContainer.GetMetadataDoubleVector2(category, name); }
DoubleVector3 VolumeDataLayoutImpl::GetMetadataDoubleVector3(const char* category, const char* name) const { return m_handle.metadataContainer.GetMetadataDoubleVector3(category, name); }
DoubleVector4 VolumeDataLayoutImpl::GetMetadataDoubleVector4(const char* category, const char* name) const { return m_handle.metadataContainer.GetMetadataDoubleVector4(category, name); }
const char* VolumeDataLayoutImpl::GetMetadataString(const char* category, const char* name) const { return m_handle.metadataContainer.GetMetadataString(category, name); }
void VolumeDataLayoutImpl::GetMetadataBLOB(const char* category, const char* name, const void **data, size_t *size) const { return m_handle.metadataContainer.GetMetadataBLOB(category, name, data, size); }
}
......@@ -173,6 +173,36 @@ public:
bool isDimensionLODDecimated(int32_t dimension) const { return dimension != m_fullResolutionDimension; }
int32_t getFullResolutionDimension() const { return m_fullResolutionDimension; }
bool IsMetadataIntAvailable(const char* category, const char* name) const override;
bool IsMetadataIntVector2Available(const char* category, const char* name) const override;
bool IsMetadataIntVector3Available(const char* category, const char* name) const override;
bool IsMetadataIntVector4Available(const char* category, const char* name) const override;
bool IsMetadataFloatAvailable(const char* category, const char* name) const override;
bool IsMetadataFloatVector2Available(const char* category, const char* name) const override;
bool IsMetadataFloatVector3Available(const char* category, const char* name) const override;
bool IsMetadataFloatVector4Available(const char* category, const char* name) const override;
bool IsMetadataDoubleAvailable(const char* category, const char* name) const override;
bool IsMetadataDoubleVector2Available(const char* category, const char* name) const override;
bool IsMetadataDoubleVector3Available(const char* category, const char* name) const override;
bool IsMetadataDoubleVector4Available(const char* category, const char* name) const override;
bool IsMetadataStringAvailable(const char* category, const char* name) const override;
bool IsMetadataBLOBAvailable(const char* category, const char* name) const override;
int GetMetadataInt(const char* category, const char* name) const override;
IntVector2 GetMetadataIntVector2(const char* category, const char* name) const override;
IntVector3 GetMetadataIntVector3(const char* category, const char* name) const override;
IntVector4 GetMetadataIntVector4(const char* category, const char* name) const override;
float GetMetadataFloat(const char* category, const char* name) const override;
FloatVector2 GetMetadataFloatVector2(const char* category, const char* name) const override;
FloatVector3 GetMetadataFloatVector3(const char* category, const char* name) const override;
FloatVector4 GetMetadataFloatVector4(const char* category, const char* name) const override;
double GetMetadataDouble(const char* category, const char* name) const override;
DoubleVector2 GetMetadataDoubleVector2(const char* category, const char* name) const override;
DoubleVector3 GetMetadataDoubleVector3(const char* category, const char* name) const override;
DoubleVector4 GetMetadataDoubleVector4(const char* category, const char* name) const override;
const char* GetMetadataString(const char* category, const char* name) const override;
void GetMetadataBLOB(const char* category, const char* name, const void **data, size_t *size) const override;
};
}
#endif //VOLUMEDATALAYOUTIMPL_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment