5#include "../global.hpp"
6#include "../_cexports/c_img.h"
7#include "../string.hpp"
8#include "../_cexports/c_spectral.h"
10#include "../exception.hpp"
20 inline HandleGuard<Spectral::MetaData>::HandleGuard(
void * handle) noexcept
21 : HandleGuard<Spectral::MetaData>(handle, [](
void* handle) { CVB_CALL_CAPI(ReleaseObject(handle)); })
57 GetField(fieldId, val);
81 WriteFieldTyped(fieldId, value);
95 CVB_CALL_CAPI_CHECKED(CVSMetaDataGetFieldnameAsStringTyped(handle_.Handle(),
96 static_cast<CExports::CVSField
>(fieldId),
97 reinterpret_cast<Char*
>(NULL), sz));
99 CVB_CALL_CAPI_CHECKED(CVSMetaDataGetFieldnameAsStringTyped(handle_.Handle(),
100 static_cast<CExports::CVSField
>(fieldId),
102 return String(cvbVal.data());
114 auto fieldType = CFieldType(fieldId);
126 auto valOut = Internal::DoResCallValueOut<size_t>([&](
size_t& val)
128 return CVB_CALL_CAPI(CVSMetaDataGetNumberOfFields(handle_.Handle(), val));
130 return static_cast<int>(valOut);
141 Internal::DoResCall([&]()
143 return CVB_CALL_CAPI(CVSMetaDataClearField(handle_.Handle(),
144 static_cast<CExports::CVSField
>(fieldId)));
157 auto valOut = Internal::DoResCallValueOut<CExports::cvbbool_t>([&](CExports::cvbbool_t& isDefined)
159 return CVB_CALL_CAPI(CVSMetaDataIsFieldDefined(handle_.Handle(),
160 static_cast<CExports::CVSField
>(fieldId),
163 return valOut ? true :
false;
208 std::transform(interleaveStr.begin(), interleaveStr.end(), interleaveStr.begin(), [](String::value_type ch)
210 return static_cast<String::value_type>(std::toupper(ch));
212 if (interleaveStr == CVB_LIT(
"BIL"))
214 if (interleaveStr == CVB_LIT(
"BSQ"))
216 if (interleaveStr == CVB_LIT(
"BIP"))
219 throw Cvb::CvbException::FromCvbResult(CExports::CVC_E_NOTSUPPORTED,
"Unknown interleaved type");
242 return Internal::DoResCallObjectOut<MetaData>([&](
void* & metaDataOut)
244 return CVB_CALL_CAPI(CVSCreateMetaData(metaDataOut));
255 return handle_.Handle();
276 MetaData(HandleGuard<MetaData>&& guard) noexcept
277 : handle_(std::move(guard))
282 : handle_(std::move(other.handle_))
286 MetaData & operator=(MetaData && other) =
default;
289 void GetField(
FieldID fieldId,
int& valueOut)
const
291 CExports::cvbint64_t cvbVal = 0;
292 CVB_CALL_CAPI_CHECKED(CVSMetaDataGetAsInteger(handle_.Handle(),
293 static_cast<CExports::CVSField
>(fieldId), cvbVal));
294 valueOut =
static_cast<int>(cvbVal);
298 void GetField(
FieldID fieldId,
double& valueOut)
const
301 CVB_CALL_CAPI_CHECKED(CVSMetaDataGetAsFloat(handle_.Handle(),
302 static_cast<CExports::CVSField
>(fieldId), cvbVal));
303 valueOut = std::move(cvbVal);
307 void GetField(
FieldID fieldId, String& valueOut)
const
310 CVB_CALL_CAPI_CHECKED(CVSMetaDataGetAsStringTyped(handle_.Handle(),
311 static_cast<CExports::CVSField
>(fieldId),
reinterpret_cast<char*
>(NULL), sz));
313 CVB_CALL_CAPI_CHECKED(CVSMetaDataGetAsStringTyped(handle_.Handle(),
314 static_cast<CExports::CVSField
>(fieldId), cvbVal.data(), sz));
316 valueOut =
String(str.begin(), str.end());
323 CVB_CALL_CAPI_CHECKED(CVSMetaDataGetArraySize(handle_.Handle(),
324 static_cast<CExports::CVSField
>(fieldId), sz));
326 for (CExports::cvbval_t i = 0; i < static_cast<CExports::cvbval_t>(sz); ++i)
328 CExports::cvbint64_t cvbElement = 0;
329 CVB_CALL_CAPI_CHECKED(CVSMetaDataGetAsIntegerArray(handle_.Handle(),
330 static_cast<CExports::CVSField
>(fieldId), i, cvbElement));
331 cvbVal.at(i) =
static_cast<int>(cvbElement);
333 valueOut = std::move(cvbVal);
340 CVB_CALL_CAPI_CHECKED(CVSMetaDataGetArraySize(handle_.Handle(),
341 static_cast<CExports::CVSField
>(fieldId), sz));
343 for (CExports::cvbval_t i = 0; i < static_cast<CExports::cvbval_t>(sz); ++i)
345 double cvbElement = 0;
346 CVB_CALL_CAPI_CHECKED(CVSMetaDataGetAsFloatArray(handle_.Handle(),
347 static_cast<CExports::CVSField
>(fieldId), i, cvbElement));
348 cvbVal.at(i) =
static_cast<double>(cvbElement);
350 valueOut = std::move(cvbVal);
357 CVB_CALL_CAPI_CHECKED(CVSMetaDataGetArraySize(handle_.Handle(),
358 static_cast<CExports::CVSField
>(fieldId), sz));
361 for (CExports::cvbval_t i = 0; i < static_cast<CExports::cvbval_t>(sz); ++i)
364 CVB_CALL_CAPI_CHECKED(CVSMetaDataGetAsStringArrayTyped(handle_.Handle(),
365 static_cast<CExports::CVSField
>(fieldId), i,
reinterpret_cast<char*
>(NULL), szString));
367 CVB_CALL_CAPI_CHECKED(CVSMetaDataGetAsStringArrayTyped(handle_.Handle(),
368 static_cast<CExports::CVSField
>(fieldId), i, cvbElement.data(), szString));
370 cvbVal.at(i) =
String(tmpStr.begin(), tmpStr.end());
373 valueOut = std::move(cvbVal);
377 void WriteFieldTyped(
FieldID fieldId,
const int& value)
379 CVB_CALL_CAPI_CHECKED(CVSMetaDataSetAsInteger(handle_.Handle(),
380 static_cast<CExports::CVSField
>(fieldId),
381 static_cast<CExports::cvbint64_t
>(value)));
385 void WriteFieldTyped(
FieldID fieldId,
const double& value)
387 CVB_CALL_CAPI_CHECKED(CVSMetaDataSetAsFloat(handle_.Handle(),
388 static_cast<CExports::CVSField
>(fieldId),
393 void WriteFieldTyped(
FieldID fieldId,
const String& value)
395 CVB_CALL_CAPI_CHECKED(CVSMetaDataSetAsStringTyped(handle_.Handle(),
396 static_cast<CExports::CVSField
>(fieldId),
403 CVB_CALL_CAPI_CHECKED(CVSMetaDataClearField(handle_.Handle(),
404 static_cast<CExports::CVSField
>(fieldId)));
406 CVB_CALL_CAPI_CHECKED(CVSMetaDataAddToIntegerArray(handle_.Handle(),
407 static_cast<CExports::CVSField
>(fieldId),
408 static_cast<CExports::cvbint64_t
>(e)));
414 CVB_CALL_CAPI_CHECKED(CVSMetaDataClearField(handle_.Handle(),
415 static_cast<CExports::CVSField
>(fieldId)));
417 CVB_CALL_CAPI_CHECKED(CVSMetaDataAddToFloatArray(handle_.Handle(),
418 static_cast<CExports::CVSField
>(fieldId),
419 static_cast<double>(e)));
425 CVB_CALL_CAPI_CHECKED(CVSMetaDataClearField(handle_.Handle(),
426 static_cast<CExports::CVSField
>(fieldId)));
428 CVB_CALL_CAPI_CHECKED(CVSMetaDataAddToStringArrayTyped(handle_.Handle(),
429 static_cast<CExports::CVSField
>(fieldId),
440 CExports::CVSFieldType CFieldType(
FieldID fieldId)
const
442 return Internal::DoResCallValueOut<CExports::CVSFieldType>([&](CExports::CVSFieldType& val)
444 return CVB_CALL_CAPI(CVSMetaDataGetFieldType(handle_.Handle(),
445 static_cast<CExports::CVSField
>(fieldId), val));
451 HandleGuard<MetaData> handle_;
457using Spectral::MetaData;
FieldID
FieldID enum class to access fields in the MetaData object.
Definition: spectral.hpp:121
@ Bands
The number of bands.
@ Lines
The number of lines.
@ Wavelength
Array of wavelengths with the unit given in FieldID::WavelengthUnit.
@ Interleave
Defines the way the spectral data of the buffer is ordered (CubeEncoding)
@ Samples
The number of samples.
FieldType
Data type of a field.
Definition: spectral.hpp:180
CubeEncoding
View Perspective: Defines how the mapping between a typical x-y image and samples-lines-bands is done...
Definition: spectral.hpp:211
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24
char Char
Character type for wide characters or unicode characters.
Definition: string.hpp:59
std::string String
String for wide characters or unicode characters.
Definition: string.hpp:45