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)); })
63 GetField(fieldId, val);
87 WriteFieldTyped(fieldId, value);
101 CVB_CALL_CAPI_CHECKED(CVSMetaDataGetFieldnameAsStringTyped(handle_.Handle(),
102 static_cast<CExports::CVSField
>(fieldId),
103 reinterpret_cast<Char*
>(NULL), sz));
105 CVB_CALL_CAPI_CHECKED(CVSMetaDataGetFieldnameAsStringTyped(handle_.Handle(),
106 static_cast<CExports::CVSField
>(fieldId),
108 return String(cvbVal.data());
120 auto fieldType = CFieldType(fieldId);
132 auto valOut = Internal::DoResCallValueOut<size_t>([&](
size_t& val)
134 return CVB_CALL_CAPI(CVSMetaDataGetNumberOfFields(handle_.Handle(), val));
136 return static_cast<int>(valOut);
147 Internal::DoResCall([&]()
149 return CVB_CALL_CAPI(CVSMetaDataClearField(handle_.Handle(),
150 static_cast<CExports::CVSField
>(fieldId)));
163 auto valOut = Internal::DoResCallValueOut<CExports::cvbbool_t>([&](CExports::cvbbool_t& isDefined)
165 return CVB_CALL_CAPI(CVSMetaDataIsFieldDefined(handle_.Handle(),
166 static_cast<CExports::CVSField
>(fieldId),
169 return valOut ? true :
false;
214 std::transform(interleaveStr.begin(), interleaveStr.end(), interleaveStr.begin(), [](String::value_type ch)
216 return static_cast<String::value_type>(std::toupper(ch));
218 if (interleaveStr == CVB_LIT(
"BIL"))
220 if (interleaveStr == CVB_LIT(
"BSQ"))
222 if (interleaveStr == CVB_LIT(
"BIP"))
248 return Internal::DoResCallObjectOut<MetaData>([&](
void* & metaDataOut)
250 return CVB_CALL_CAPI(CVSCreateMetaData(metaDataOut));
261 return handle_.Handle();
282 explicit MetaData(HandleGuard<MetaData>&& guard) noexcept
283 : handle_(std::move(guard))
290 void GetField(
FieldID fieldId,
int& valueOut)
const
292 CExports::cvbint64_t cvbVal = 0;
293 CVB_CALL_CAPI_CHECKED(CVSMetaDataGetAsInteger(handle_.Handle(),
294 static_cast<CExports::CVSField
>(fieldId), cvbVal));
295 valueOut =
static_cast<int>(cvbVal);
299 void GetField(
FieldID fieldId,
double& valueOut)
const
302 CVB_CALL_CAPI_CHECKED(CVSMetaDataGetAsFloat(handle_.Handle(),
303 static_cast<CExports::CVSField
>(fieldId), cvbVal));
304 valueOut = std::move(cvbVal);
308 void GetField(
FieldID fieldId, String& valueOut)
const
311 CVB_CALL_CAPI_CHECKED(CVSMetaDataGetAsStringTyped(handle_.Handle(),
312 static_cast<CExports::CVSField
>(fieldId),
reinterpret_cast<char*
>(NULL), sz));
314 CVB_CALL_CAPI_CHECKED(CVSMetaDataGetAsStringTyped(handle_.Handle(),
315 static_cast<CExports::CVSField
>(fieldId), cvbVal.data(), sz));
317 valueOut =
String(str.begin(), str.end());
324 CVB_CALL_CAPI_CHECKED(CVSMetaDataGetArraySize(handle_.Handle(),
325 static_cast<CExports::CVSField
>(fieldId), sz));
327 for (CExports::cvbval_t i = 0; i < static_cast<CExports::cvbval_t>(sz); ++i)
329 CExports::cvbint64_t cvbElement = 0;
330 CVB_CALL_CAPI_CHECKED(CVSMetaDataGetAsIntegerArray(handle_.Handle(),
331 static_cast<CExports::CVSField
>(fieldId), i, cvbElement));
332 cvbVal.at(i) =
static_cast<int>(cvbElement);
334 valueOut = std::move(cvbVal);
341 CVB_CALL_CAPI_CHECKED(CVSMetaDataGetArraySize(handle_.Handle(),
342 static_cast<CExports::CVSField
>(fieldId), sz));
344 for (CExports::cvbval_t i = 0; i < static_cast<CExports::cvbval_t>(sz); ++i)
346 double cvbElement = 0;
347 CVB_CALL_CAPI_CHECKED(CVSMetaDataGetAsFloatArray(handle_.Handle(),
348 static_cast<CExports::CVSField
>(fieldId), i, cvbElement));
349 cvbVal.at(i) =
static_cast<double>(cvbElement);
351 valueOut = std::move(cvbVal);
358 CVB_CALL_CAPI_CHECKED(CVSMetaDataGetArraySize(handle_.Handle(),
359 static_cast<CExports::CVSField
>(fieldId), sz));
362 for (CExports::cvbval_t i = 0; i < static_cast<CExports::cvbval_t>(sz); ++i)
365 CVB_CALL_CAPI_CHECKED(CVSMetaDataGetAsStringArrayTyped(handle_.Handle(),
366 static_cast<CExports::CVSField
>(fieldId), i,
reinterpret_cast<char*
>(NULL), szString));
368 CVB_CALL_CAPI_CHECKED(CVSMetaDataGetAsStringArrayTyped(handle_.Handle(),
369 static_cast<CExports::CVSField
>(fieldId), i, cvbElement.data(), szString));
371 cvbVal.at(i) =
String(tmpStr.begin(), tmpStr.end());
374 valueOut = std::move(cvbVal);
378 void WriteFieldTyped(
FieldID fieldId,
const int& value)
380 CVB_CALL_CAPI_CHECKED(CVSMetaDataSetAsInteger(handle_.Handle(),
381 static_cast<CExports::CVSField
>(fieldId),
382 static_cast<CExports::cvbint64_t
>(value)));
386 void WriteFieldTyped(
FieldID fieldId,
const double& value)
388 CVB_CALL_CAPI_CHECKED(CVSMetaDataSetAsFloat(handle_.Handle(),
389 static_cast<CExports::CVSField
>(fieldId),
394 void WriteFieldTyped(
FieldID fieldId,
const String& value)
396 CVB_CALL_CAPI_CHECKED(CVSMetaDataSetAsStringTyped(handle_.Handle(),
397 static_cast<CExports::CVSField
>(fieldId),
404 CVB_CALL_CAPI_CHECKED(CVSMetaDataClearField(handle_.Handle(),
405 static_cast<CExports::CVSField
>(fieldId)));
407 CVB_CALL_CAPI_CHECKED(CVSMetaDataAddToIntegerArray(handle_.Handle(),
408 static_cast<CExports::CVSField
>(fieldId),
409 static_cast<CExports::cvbint64_t
>(e)));
415 CVB_CALL_CAPI_CHECKED(CVSMetaDataClearField(handle_.Handle(),
416 static_cast<CExports::CVSField
>(fieldId)));
418 CVB_CALL_CAPI_CHECKED(CVSMetaDataAddToFloatArray(handle_.Handle(),
419 static_cast<CExports::CVSField
>(fieldId),
420 static_cast<double>(e)));
426 CVB_CALL_CAPI_CHECKED(CVSMetaDataClearField(handle_.Handle(),
427 static_cast<CExports::CVSField
>(fieldId)));
429 CVB_CALL_CAPI_CHECKED(CVSMetaDataAddToStringArrayTyped(handle_.Handle(),
430 static_cast<CExports::CVSField
>(fieldId),
441 CExports::CVSFieldType CFieldType(
FieldID fieldId)
const
443 return Internal::DoResCallValueOut<CExports::CVSFieldType>([&](CExports::CVSFieldType& val)
445 return CVB_CALL_CAPI(CVSMetaDataGetFieldType(handle_.Handle(),
446 static_cast<CExports::CVSField
>(fieldId), val));
452 HandleGuard<MetaData> handle_;
458using 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:15
char Char
Character type for wide characters or unicode characters.
Definition: string.hpp:70
std::string String
String for wide characters or unicode characters.
Definition: string.hpp:56