Skip to content

Commit d247155

Browse files
Refactor integer array pushing in AbstractValuesProperty
Replaces multiple type-specific pushBack*Hdf5Array*OfValues methods with a set of templated functions for pushing integer arrays of various types and dimensions. The previous pushBack*Hdf5Array*OfValues are still there but are flagged as deprecated. Updates tests and SWIG interface to cover all integer types (signed and unsigned, 8/16/32/64 bits). Simplifies and unifies the API for pushing integer property values, improving maintainability and extensibility.
1 parent d38a405 commit d247155

15 files changed

Lines changed: 378 additions & 240 deletions

example/example.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ void serializeWells(COMMON_NS::DataObjectRepository * repo, EML2_NS::AbstractHdf
309309
RESQML2_NS::DiscreteProperty* discreteProp = repo->createDiscreteProperty(w1i1FrameRep, "61c2917c-2334-4205-824e-d4f4a0cf6d8e", "Wellbore1 Interp1 FrameRep IntervalIndex", 1,
310310
gsoap_eml2_3::eml23__IndexableElement::intervals, unitNumberPropType);
311311
int8_t unitNumbers[5] = { 0, 1, 2, 3, 4 };
312-
discreteProp->pushBackInt8Hdf5Array1dOfValues(unitNumbers, 5, hdfProxy, -1);
312+
discreteProp->pushBackIntegerArray1dOfValues(unitNumbers, 5, hdfProxy, static_cast<std::int8_t>(-1));
313313
#if WITH_RESQML2_2
314314
// SeismicWellboreFrameRepresentation
315315
RESQML2_NS::SeismicWellboreFrameRepresentation* w1i1SeismicFrameRep = repo->createSeismicWellboreFrameRepresentation(
@@ -416,7 +416,7 @@ void serializeGraphicalInformationSet(COMMON_NS::DataObjectRepository * repo, EM
416416
RESQML2_NS::DiscreteProperty* discreteProp2 = repo->createDiscreteProperty(twoCellsIjkGrid, "1e2822ef-b6cb-4123-bdf4-c99df84a896f", "Another two faulted sugar cubes cellIndex", 1,
417417
gsoap_eml2_3::eml23__IndexableElement::cells, propType1);
418418
uint16_t prop2Values[2] = { 0, 1 };
419-
discreteProp2->pushBackUInt16Hdf5Array3dOfValues(prop2Values, 2, 1, 1, hdfProxy, -1);
419+
discreteProp2->pushBackIntegerArray3dOfValues(prop2Values, 2, 1, 1, hdfProxy, (std::numeric_limits<uint16_t>::max)());
420420

421421
// ********************
422422
// Continuous color map
@@ -1021,12 +1021,12 @@ void serializeGrid(COMMON_NS::DataObjectRepository * repo, EML2_NS::AbstractHdfP
10211021
#endif
10221022
discreteProp1 = repo->createDiscreteProperty(twoCellsIjkGrid, "ee0857fe-23ad-4dd9-8300-21fa2e9fb572", "Two faulted sugar cubes cellIndex", 1,
10231023
gsoap_eml2_3::eml23__IndexableElement::cells, propType1);
1024-
unsigned short prop1Values[2] = { 0, 1 };
1025-
discreteProp1->pushBackUInt16Hdf5Array3dOfValues(prop1Values, 2, 1, 1, hdfProxy, 1111);
1024+
uint16_t prop1Values[2] = { 0, 1 };
1025+
discreteProp1->pushBackIntegerArray3dOfValues(prop1Values, 2, 1, 1, hdfProxy, static_cast<uint16_t>(1111));
10261026
RESQML2_NS::DiscreteProperty* discreteProp2 = repo->createDiscreteProperty(twoCellsIjkGrid, "da73937c-2c60-4e10-8917-5154fde4ded5", "Two faulted sugar cubes other cellIndex", 1,
10271027
gsoap_eml2_3::eml23__IndexableElement::cells, propType1);
10281028
int64_t prop2Values[2] = { 10, 11 };
1029-
discreteProp2->pushBackInt64Hdf5Array3dOfValues(prop2Values, 2, 1, 1, hdfProxy, 1111);
1029+
discreteProp2->pushBackIntegerArray3dOfValues(prop2Values, 2, 1, 1, hdfProxy, static_cast<int64_t>(1111));
10301030

10311031
RESQML2_0_1_NS::PropertySet* parentPropSet = repo->createPropertySet("3135a6c1-1204-4c30-a0ec-c9357ec13510", "Testing parent property set", false, true, gsoap_resqml2_0_1::resqml20__TimeSetKind::not_x0020a_x0020time_x0020set);
10321032
RESQML2_0_1_NS::PropertySet* childPropSet = repo->createPropertySet("1d4b4342-288d-47c1-9572-9f330f8e632a", "Testing child property set", false, true,gsoap_resqml2_0_1::resqml20__TimeSetKind::not_x0020a_x0020time_x0020set);
@@ -1046,7 +1046,7 @@ void serializeGrid(COMMON_NS::DataObjectRepository * repo, EML2_NS::AbstractHdfP
10461046
int64_t discreteProp432Values[24] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
10471047
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 };
10481048
//hdfProxy->setMaxChunkSize(192/2); // Create two chunks
1049-
discreteProp432->pushBackInt64Hdf5Array3dOfValues(discreteProp432Values, 4, 3, 2, hdfProxy, 1111);
1049+
discreteProp432->pushBackIntegerArray3dOfValues(discreteProp432Values, 4, 3, 2, hdfProxy, static_cast<std::int64_t>(1111));
10501050

10511051
/**************
10521052
Continuous Properties

src/resqml2/AbstractValuesProperty.cpp

Lines changed: 3 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -367,79 +367,6 @@ void AbstractValuesProperty::pushBackIntegerConstantArrayOfValues(int64_t value,
367367
}
368368
}
369369

370-
void AbstractValuesProperty::pushBackInt32Hdf5Array1dOfValues(const int * values, uint64_t valueCount, EML2_NS::AbstractHdfProxy * proxy,
371-
int nullValue)
372-
{
373-
pushBackInt32Hdf5ArrayOfValues(values, &valueCount, 1, proxy, nullValue);
374-
}
375-
376-
void AbstractValuesProperty::pushBackInt16Hdf5Array1dOfValues(const short * values, uint64_t valueCount, EML2_NS::AbstractHdfProxy * proxy,
377-
short nullValue)
378-
{
379-
pushBackInt16Hdf5ArrayOfValues(values, &valueCount, 1, proxy, nullValue);
380-
}
381-
382-
void AbstractValuesProperty::pushBackInt8Hdf5Array1dOfValues(const int8_t * values, uint64_t valueCount, EML2_NS::AbstractHdfProxy * proxy,
383-
int8_t nullValue)
384-
{
385-
pushBackInt8Hdf5ArrayOfValues(values, &valueCount, 1, proxy, nullValue);
386-
}
387-
388-
void AbstractValuesProperty::pushBackInt32Hdf5Array2dOfValues(const int * values, uint64_t valueCountInFastestDim, uint64_t valueCountInSlowestDim, EML2_NS::AbstractHdfProxy * proxy,
389-
int nullValue)
390-
{
391-
uint64_t valueCountPerDimension[2] = { valueCountInSlowestDim, valueCountInFastestDim };
392-
pushBackInt32Hdf5ArrayOfValues(values, valueCountPerDimension, 2, proxy, nullValue);
393-
}
394-
395-
void AbstractValuesProperty::pushBackInt16Hdf5Array2dOfValues(const short * values, uint64_t valueCountInFastestDim, uint64_t valueCountInSlowestDim, EML2_NS::AbstractHdfProxy * proxy,
396-
short nullValue)
397-
{
398-
uint64_t valueCountPerDimension[2] = { valueCountInSlowestDim, valueCountInFastestDim };
399-
pushBackInt16Hdf5ArrayOfValues(values, valueCountPerDimension, 2, proxy, nullValue);
400-
}
401-
402-
void AbstractValuesProperty::pushBackUInt16Hdf5Array2dOfValues(const unsigned short * values, uint64_t valueCountInFastestDim, uint64_t valueCountInSlowestDim, EML2_NS::AbstractHdfProxy* proxy, unsigned short nullValue)
403-
{
404-
uint64_t valueCountPerDimension[2] = { valueCountInSlowestDim, valueCountInFastestDim };
405-
pushBackUInt16Hdf5ArrayOfValues(values, valueCountPerDimension, 2, proxy, nullValue);
406-
}
407-
408-
void AbstractValuesProperty::pushBackInt8Hdf5Array2dOfValues(const int8_t * values, uint64_t valueCountInFastestDim, uint64_t valueCountInSlowestDim, EML2_NS::AbstractHdfProxy * proxy,
409-
int8_t nullValue)
410-
{
411-
uint64_t valueCountPerDimension[2] = { valueCountInSlowestDim, valueCountInFastestDim };
412-
pushBackInt8Hdf5ArrayOfValues(values, valueCountPerDimension, 2, proxy, nullValue);
413-
}
414-
415-
void AbstractValuesProperty::pushBackInt32Hdf5Array3dOfValues(const int * values, uint64_t valueCountInFastestDim, uint64_t valueCountInMiddleDim, uint64_t valueCountInSlowestDim, EML2_NS::AbstractHdfProxy * proxy,
416-
int nullValue)
417-
{
418-
uint64_t valueCountPerDimension[3] = { valueCountInSlowestDim, valueCountInMiddleDim, valueCountInFastestDim };
419-
pushBackInt32Hdf5ArrayOfValues(values, valueCountPerDimension, 3, proxy, nullValue);
420-
}
421-
422-
void AbstractValuesProperty::pushBackInt16Hdf5Array3dOfValues(const short * values, uint64_t valueCountInFastestDim, uint64_t valueCountInMiddleDim, uint64_t valueCountInSlowestDim, EML2_NS::AbstractHdfProxy * proxy,
423-
short nullValue)
424-
{
425-
uint64_t valueCountPerDimension[3] = { valueCountInSlowestDim, valueCountInMiddleDim, valueCountInFastestDim };
426-
pushBackInt16Hdf5ArrayOfValues(values, valueCountPerDimension, 3, proxy, nullValue);
427-
}
428-
429-
void AbstractValuesProperty::pushBackUInt16Hdf5Array3dOfValues(const unsigned short * values, uint64_t valueCountInFastestDim, uint64_t valueCountInMiddleDim, uint64_t valueCountInSlowestDim, EML2_NS::AbstractHdfProxy * proxy,
430-
unsigned short nullValue)
431-
{
432-
uint64_t valueCountPerDimension[3] = { valueCountInSlowestDim, valueCountInMiddleDim, valueCountInFastestDim };
433-
pushBackUInt16Hdf5ArrayOfValues(values, valueCountPerDimension, 3, proxy, nullValue);
434-
}
435-
436-
void AbstractValuesProperty::pushBackInt8Hdf5Array3dOfValues(const int8_t * values, uint64_t valueCountInFastestDim, uint64_t valueCountInMiddleDim, uint64_t valueCountInSlowestDim, EML2_NS::AbstractHdfProxy * proxy,
437-
int8_t nullValue)
438-
{
439-
uint64_t valueCountPerDimension[3] = { valueCountInSlowestDim, valueCountInMiddleDim, valueCountInFastestDim };
440-
pushBackInt8Hdf5ArrayOfValues(values, valueCountPerDimension, 3, proxy, nullValue);
441-
}
442-
443370
std::string AbstractValuesProperty::pushBackRefToExistingIntegerDataset(EML2_NS::AbstractHdfProxy* hdfProxy, const std::string & datasetName, int64_t nullValue)
444371
{
445372
if (hdfProxy == nullptr) {
@@ -550,87 +477,8 @@ std::string AbstractValuesProperty::pushBackRefToExistingFloatingPointDataset(EM
550477
throw logic_error("Unrecognized RESQML version");
551478
}
552479

553-
void AbstractValuesProperty::pushBackInt64Hdf5ArrayOfValues(const int64_t * values, const uint64_t * numValues, unsigned int numDimensionsInArray, EML2_NS::AbstractHdfProxy * proxy, int64_t nullValue)
554-
{
555-
if (proxy == nullptr) {
556-
proxy = getRepository()->getDefaultHdfProxy();
557-
if (proxy == nullptr) {
558-
throw std::invalid_argument("A (default) HDF Proxy must be provided.");
559-
}
560-
}
561-
562-
const std::string datasetName = "values_patch" + std::to_string(getPatchCount());
563-
564-
proxy->writeArrayNd(getHdfGroup(),
565-
datasetName,
566-
COMMON_NS::AbstractObject::numericalDatatypeEnum::INT64,
567-
values,
568-
numValues, numDimensionsInArray);
569-
570-
pushBackRefToExistingIntegerDataset(proxy, getHdfGroup() + "/" + datasetName, nullValue);
571-
}
572-
573-
void AbstractValuesProperty::pushBackInt32Hdf5ArrayOfValues(const int * values, const uint64_t * numValues, unsigned int numDimensionsInArray, EML2_NS::AbstractHdfProxy* proxy, int nullValue)
574-
{
575-
if (proxy == nullptr) {
576-
proxy = getRepository()->getDefaultHdfProxy();
577-
if (proxy == nullptr) {
578-
throw std::invalid_argument("A (default) HDF Proxy must be provided.");
579-
}
580-
}
581-
582-
const std::string datasetName = "values_patch" + std::to_string(getPatchCount());
583-
584-
proxy->writeArrayNd(getHdfGroup(),
585-
datasetName,
586-
COMMON_NS::AbstractObject::numericalDatatypeEnum::INT32,
587-
values,
588-
numValues, numDimensionsInArray);
589-
590-
pushBackRefToExistingIntegerDataset(proxy, getHdfGroup() + "/" + datasetName, nullValue);
591-
}
592-
593-
void AbstractValuesProperty::pushBackInt16Hdf5ArrayOfValues(const short * values, const uint64_t * numValues, unsigned int numDimensionsInArray, EML2_NS::AbstractHdfProxy* proxy, short nullValue)
594-
{
595-
if (proxy == nullptr) {
596-
proxy = getRepository()->getDefaultHdfProxy();
597-
if (proxy == nullptr) {
598-
throw std::invalid_argument("A (default) HDF Proxy must be provided.");
599-
}
600-
}
601-
602-
const std::string datasetName = "values_patch" + std::to_string(getPatchCount());
603-
604-
proxy->writeArrayNd(getHdfGroup(),
605-
datasetName,
606-
COMMON_NS::AbstractObject::numericalDatatypeEnum::INT16,
607-
values,
608-
numValues, numDimensionsInArray);
609-
610-
pushBackRefToExistingIntegerDataset(proxy, getHdfGroup() + "/" + datasetName, nullValue);
611-
}
612-
613-
void AbstractValuesProperty::pushBackUInt16Hdf5ArrayOfValues(const unsigned short * values, const uint64_t * numValues, unsigned int numDimensionsInArray, EML2_NS::AbstractHdfProxy* proxy, unsigned short nullValue)
614-
{
615-
if (proxy == nullptr) {
616-
proxy = getRepository()->getDefaultHdfProxy();
617-
if (proxy == nullptr) {
618-
throw std::invalid_argument("A (default) HDF Proxy must be provided.");
619-
}
620-
}
621-
622-
const std::string datasetName = "values_patch" + std::to_string(getPatchCount());
623-
624-
proxy->writeArrayNd(getHdfGroup(),
625-
datasetName,
626-
COMMON_NS::AbstractObject::numericalDatatypeEnum::UINT16,
627-
values,
628-
numValues, numDimensionsInArray);
629-
630-
pushBackRefToExistingIntegerDataset(proxy, getHdfGroup() + "/" + datasetName, nullValue);
631-
}
632-
633-
void AbstractValuesProperty::pushBackInt8Hdf5ArrayOfValues(const int8_t * values, const uint64_t * numValues, unsigned int numDimensionsInArray, EML2_NS::AbstractHdfProxy* proxy, int8_t nullValue)
480+
void AbstractValuesProperty::pushBackIntegerArrayOfValues(const void* values, COMMON_NS::AbstractObject::numericalDatatypeEnum numericalDatatype, const uint64_t* numValues, unsigned int numDimensionsInArray,
481+
EML2_NS::AbstractHdfProxy* proxy, int64_t nullValue)
634482
{
635483
if (proxy == nullptr) {
636484
proxy = getRepository()->getDefaultHdfProxy();
@@ -643,7 +491,7 @@ void AbstractValuesProperty::pushBackInt8Hdf5ArrayOfValues(const int8_t * values
643491

644492
proxy->writeArrayNd(getHdfGroup(),
645493
datasetName,
646-
COMMON_NS::AbstractObject::numericalDatatypeEnum::INT8,
494+
numericalDatatype,
647495
values,
648496
numValues, numDimensionsInArray);
649497

0 commit comments

Comments
 (0)