Skip to content

Commit

Permalink
DoubleTableLookup is now uint64 indexed
Browse files Browse the repository at this point in the history
  • Loading branch information
philippeVerney committed Sep 19, 2024
1 parent 680f031 commit a1bfae1
Show file tree
Hide file tree
Showing 12 changed files with 405 additions and 84 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ set (FESAPI_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})

# version mechanism
set (Fesapi_VERSION_MAJOR 2)
set (Fesapi_VERSION_MINOR 10)
set (Fesapi_VERSION_PATCH 1)
set (Fesapi_VERSION_MINOR 11)
set (Fesapi_VERSION_PATCH 0)
set (Fesapi_VERSION_TWEAK 0)

set (Fesapi_VERSION ${Fesapi_VERSION_MAJOR}.${Fesapi_VERSION_MINOR}.${Fesapi_VERSION_PATCH}.${Fesapi_VERSION_TWEAK})
Expand Down
4 changes: 2 additions & 2 deletions example/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2668,9 +2668,9 @@ void showAllProperties(RESQML2_NS::AbstractRepresentation const * rep, bool* ena
cout << "\tPress enter to continue..." << endl;
cin.get();
}
const unsigned int itemCount = stl->getItemCount();
const uint64_t itemCount = stl->getItemCount();
std::cout << "\tAssociated Double Table lookup" << endl;
for (unsigned int itemIndex = 0; itemIndex < itemCount; ++itemIndex) {
for (uint64_t itemIndex = 0; itemIndex < itemCount; ++itemIndex) {
std::cout << stl->getKeyAtIndex(itemIndex) << "->" << stl->getValueAtIndex(itemIndex) << endl;
}
std::unique_ptr<double[]> values(new double[valueCount]);
Expand Down
16 changes: 14 additions & 2 deletions src/common/AbstractObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -906,8 +906,14 @@ void AbstractObject::readArrayNdOfFloatValues(gsoap_resqml2_0_1::resqml20__Abstr
if (latticeArray->Offset.size() > 1) {
throw invalid_argument("The integer lattice array contains more than one offset.");
}
if (latticeArray->StartValue < (std::numeric_limits<float>::min)() || latticeArray->StartValue > (std::numeric_limits<float>::max)()) {
throw out_of_range("The double start value of the lattice array " + std::to_string(latticeArray->StartValue) + " is out of float range value");
}
if (latticeArray->Offset[0]->Value < (std::numeric_limits<float>::min)() || latticeArray->Offset[0]->Value >(std::numeric_limits<float>::max)()) {
throw out_of_range("The double offset value of the lattice array " + std::to_string(latticeArray->Offset[0]->Value) + " is out of float range value");
}
for (size_t i = 0; i <= latticeArray->Offset[0]->Count; ++i) {
arrayOutput[i] = latticeArray->StartValue + (i * latticeArray->Offset[0]->Value);
arrayOutput[i] = static_cast<float>(latticeArray->StartValue) + (i * static_cast<float>(latticeArray->Offset[0]->Value));
}
}
else
Expand Down Expand Up @@ -942,8 +948,14 @@ void AbstractObject::readArrayNdOfFloatValues(gsoap_eml2_3::eml23__AbstractFloat
if (latticeArray->Offset[0]->Count < 0) {
throw invalid_argument("The count of the floating point lattice array of UUID " + getUuid() + " is negative which is not valid.");
}
if (latticeArray->StartValue < (std::numeric_limits<float>::min)() || latticeArray->StartValue >(std::numeric_limits<float>::max)()) {
throw out_of_range("The double start value of the lattice array " + std::to_string(latticeArray->StartValue) + " is out of float range value");
}
if (latticeArray->Offset[0]->Value < (std::numeric_limits<float>::min)() || latticeArray->Offset[0]->Value >(std::numeric_limits<float>::max)()) {
throw out_of_range("The double offset value of the lattice array " + std::to_string(latticeArray->Offset[0]->Value) + " is out of float range value");
}
for (size_t i = 0; i <= static_cast<size_t>(latticeArray->Offset[0]->Count); ++i) {
arrayOutput[i] = latticeArray->StartValue + (i * latticeArray->Offset[0]->Value);
arrayOutput[i] = static_cast<float>(latticeArray->StartValue) + (i * static_cast<float>(latticeArray->Offset[0]->Value));
}
break;
}
Expand Down
8 changes: 4 additions & 4 deletions src/common/DataObjectRepository.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ bool DataObjectRepository::addDataObject(COMMON_NS::AbstractObject* proxy)
backwardRels.emplace(proxy, std::vector<COMMON_NS::AbstractObject*>());

auto now = std::chrono::system_clock::now();
journal.push_back(std::make_tuple(now, DataObjectReference(proxy), CREATED));
journal.push_back(std::make_tuple(now, DataObjectReference(proxy), CUD::CREATED));
on_CreateDataObject(std::vector<std::pair<std::chrono::time_point<std::chrono::system_clock>, COMMON_NS::AbstractObject*>> { std::make_pair(now, proxy) });

auto* crs = dynamic_cast<EML2_NS::AbstractLocal3dCrs*>(proxy);
Expand Down Expand Up @@ -634,7 +634,7 @@ COMMON_NS::AbstractObject* DataObjectRepository::addOrReplaceDataObject(COMMON_N
// New version of an existing UUID
dataObjects[proxy->getUuid()].push_back(proxy);
auto now = std::chrono::system_clock::now();
journal.push_back(std::make_tuple(now, DataObjectReference(proxy), CREATED));
journal.push_back(std::make_tuple(now, DataObjectReference(proxy), CUD::CREATED));
on_CreateDataObject(std::vector<std::pair<std::chrono::time_point<std::chrono::system_clock>, COMMON_NS::AbstractObject*>> { std::make_pair(now, proxy) });
}
else {
Expand All @@ -648,7 +648,7 @@ COMMON_NS::AbstractObject* DataObjectRepository::addOrReplaceDataObject(COMMON_N

if (!(*same)->isPartial()) {
auto now = std::chrono::system_clock::now();
journal.push_back(std::make_tuple(now, DataObjectReference(proxy), UPDATED));
journal.push_back(std::make_tuple(now, DataObjectReference(proxy), CUD::UPDATED));
on_UpdateDataObject(std::vector<std::pair<std::chrono::time_point<std::chrono::system_clock>, COMMON_NS::AbstractObject*>> { std::make_pair(now, proxy) });
}

Expand All @@ -658,7 +658,7 @@ COMMON_NS::AbstractObject* DataObjectRepository::addOrReplaceDataObject(COMMON_N
else {
if (!(*same)->isPartial()) {
auto now = std::chrono::system_clock::now();
journal.push_back(std::make_tuple(now, DataObjectReference(*same), UPDATED));
journal.push_back(std::make_tuple(now, DataObjectReference(*same), CUD::UPDATED));
on_UpdateDataObject(std::vector<std::pair<std::chrono::time_point<std::chrono::system_clock>, COMMON_NS::AbstractObject*>> { std::make_pair(now, proxy) });
}

Expand Down
6 changes: 3 additions & 3 deletions src/resqml2/DoubleTableLookup.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace RESQML2_NS
*
* @returns The count of items.
*/
DLL_IMPORT_OR_EXPORT virtual unsigned int getItemCount() const = 0;
DLL_IMPORT_OR_EXPORT virtual uint64_t getItemCount() const = 0;

/**
* Gets the key of a key/value pair at a particular index of this double table lookup (in its
Expand All @@ -69,7 +69,7 @@ namespace RESQML2_NS
*
* @returns The key of the key/value pair at position @p index.
*/
DLL_IMPORT_OR_EXPORT virtual double getKeyAtIndex(unsigned int index) const = 0;
DLL_IMPORT_OR_EXPORT virtual double getKeyAtIndex(uint64_t index) const = 0;

/**
* Gets the value of a key/value pair at a particular index of this double table lookup
Expand All @@ -81,7 +81,7 @@ namespace RESQML2_NS
*
* @returns The value of the key/value pair at position @p index.
*/
DLL_IMPORT_OR_EXPORT virtual double getValueAtIndex(unsigned int index) const = 0;
DLL_IMPORT_OR_EXPORT virtual double getValueAtIndex(uint64_t index) const = 0;

/**
* Gets a value from its associated key.
Expand Down
2 changes: 1 addition & 1 deletion src/resqml2/IjkGridParametricRepresentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void IjkGridParametricRepresentation::BSpline::setParameterAndValueAtControlPoin
c[c.size() - 1] = 0;
b.resize(h.size());
d.resize(h.size());
for (int i = h.size() - 1; i >= 0; --i) {
for (int64_t i = h.size() - 1; i >= 0; --i) {
c[i] = z[i] - mu[i] * c[i + 1];
b[i] = (valuesAtControlPoint[i + 1] - valuesAtControlPoint[i]) / h[i] - h[i] * (c[i + 1] + 2 * c[i]) / 3;
d[i] = (c[i + 1] - c[i]) / (3 * h[i]);
Expand Down
14 changes: 10 additions & 4 deletions src/resqml2/SeismicWellboreFrameRepresentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,16 @@ void SeismicWellboreFrameRepresentation::getTimeAsFloatValues(float* values) con
}
else if (frame->NodeTimeValues->soap_type() == SOAP_TYPE_gsoap_eml2_3_eml23__FloatingPointLatticeArray)
{
values[0] = static_cast<eml23__FloatingPointLatticeArray*>(frame->NodeTimeValues)->StartValue;
eml23__FloatingPointConstantArray* constantArray = static_cast<eml23__FloatingPointLatticeArray*>(frame->NodeTimeValues)->Offset[0];
for (int64_t inc = 1; inc <= constantArray->Count; ++inc) {
values[inc] = values[0] + (inc * constantArray->Value);
auto const* nodeTimeValues = static_cast<eml23__FloatingPointLatticeArray*>(frame->NodeTimeValues);
if (nodeTimeValues->StartValue < (std::numeric_limits<float>::min)() || nodeTimeValues->StartValue >(std::numeric_limits<float>::max)()) {
throw out_of_range("The double start value of the nodeTimeValues array " + std::to_string(nodeTimeValues->StartValue) + " is out of float range value");
}
values[0] = static_cast<float>(nodeTimeValues->StartValue);
if (nodeTimeValues->Offset[0]->Value < (std::numeric_limits<float>::min)() || nodeTimeValues->Offset[0]->Value >(std::numeric_limits<float>::max)()) {
throw out_of_range("The double offset value of the nodeTimeValues array " + std::to_string(nodeTimeValues->Offset[0]->Value) + " is out of float range value");
}
for (int64_t inc = 1; inc <= nodeTimeValues->Offset[0]->Count; ++inc) {
values[inc] = values[0] + (inc * static_cast<float>(nodeTimeValues->Offset[0]->Value));
}
}
else {
Expand Down
26 changes: 18 additions & 8 deletions src/resqml2/WellboreFrameRepresentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,15 @@ void WellboreFrameRepresentation::getMdAsFloatValues(float* values) const
else if (frame->NodeMd->soap_type() == SOAP_TYPE_gsoap_resqml2_0_1_resqml20__DoubleLatticeArray)
{
auto const* dla = static_cast<resqml20__DoubleLatticeArray*>(frame->NodeMd);
values[0] = dla->StartValue;
resqml20__DoubleConstantArray* constantArray = dla->Offset[0];
for (uint64_t inc = 1; inc <= constantArray->Count; ++inc) {
values[inc] = values[inc - 1] + constantArray->Value;
if (dla->StartValue < (std::numeric_limits<float>::min)() || dla->StartValue >(std::numeric_limits<float>::max)()) {
throw out_of_range("The double start value of the NodeMd array " + std::to_string(dla->StartValue) + " is out of float range value");
}
values[0] = static_cast<float>(dla->StartValue);
if (dla->Offset[0]->Value < (std::numeric_limits<float>::min)() || dla->Offset[0]->Value >(std::numeric_limits<float>::max)()) {
throw out_of_range("The double offset value of the NodeMd array " + std::to_string(dla->Offset[0]->Value) + " is out of float range value");
}
for (uint64_t inc = 1; inc <= dla->Offset[0]->Count; ++inc) {
values[inc] = values[inc - 1] + static_cast<float>(dla->Offset[0]->Value);
}
}
else {
Expand All @@ -358,10 +363,15 @@ void WellboreFrameRepresentation::getMdAsFloatValues(float* values) const
else if (frame->NodeMd->soap_type() == SOAP_TYPE_gsoap_eml2_3_eml23__FloatingPointLatticeArray)
{
auto const* fla = static_cast<eml23__FloatingPointLatticeArray*>(frame->NodeMd);
values[0] = fla->StartValue;
eml23__FloatingPointConstantArray* constantArray = fla->Offset[0];
for (int64_t inc = 1; inc <= constantArray->Count; ++inc) {
values[inc] = values[inc - 1] + constantArray->Value;
if (fla->StartValue < (std::numeric_limits<float>::min)() || fla->StartValue >(std::numeric_limits<float>::max)()) {
throw out_of_range("The double start value of the NodeMd array " + std::to_string(fla->StartValue) + " is out of float range value");
}
values[0] = static_cast<float>(fla->StartValue);
if (fla->Offset[0]->Value < (std::numeric_limits<float>::min)() || fla->Offset[0]->Value >(std::numeric_limits<float>::max)()) {
throw out_of_range("The double offset value of the NodeMd array " + std::to_string(fla->Offset[0]->Value) + " is out of float range value");
}
for (int64_t inc = 1; inc <= fla->Offset[0]->Count; ++inc) {
values[inc] = values[inc - 1] + static_cast<float>(fla->Offset[0]->Value);
}
}
else {
Expand Down
64 changes: 21 additions & 43 deletions src/resqml2_0_1/DoubleTableLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ using namespace std;
using namespace RESQML2_0_1_NS;
using namespace gsoap_resqml2_0_1;

const char* DoubleTableLookup::XML_NS = "resqml20";

DoubleTableLookup::DoubleTableLookup(COMMON_NS::DataObjectRepository* repo, const string & guid, const string & title)
DoubleTableLookup::DoubleTableLookup(COMMON_NS::DataObjectRepository* repo, const string& guid, const string& title)
{
if (repo == nullptr) {
throw invalid_argument("The repo cannot be null.");
Expand All @@ -36,58 +34,43 @@ DoubleTableLookup::DoubleTableLookup(COMMON_NS::DataObjectRepository* repo, cons
gsoapProxy2_0_1 = soap_new_resqml20__obj_USCOREDoubleTableLookup(repo->getGsoapContext());

initMandatoryMetadata();
setMetadata(guid, title, std::string(), -1, std::string(), std::string(), -1, std::string());
setMetadata(guid, title, "", -1, "", "", -1, "");

repo->addDataObject(this);
}

unsigned int DoubleTableLookup::getItemCount() const
uint64_t DoubleTableLookup::getItemCount() const
{
return static_cast<_resqml20__DoubleTableLookup*>(gsoapProxy2_0_1)->Value.size();
}

double DoubleTableLookup::getKeyAtIndex(unsigned int index) const
double DoubleTableLookup::getKeyAtIndex(uint64_t index) const
{
if (getItemCount() <= index) {
throw out_of_range("The index is out of range.");
}

return (static_cast<_resqml20__DoubleTableLookup*>(gsoapProxy2_0_1)->Value)[index]->Key;
return (static_cast<_resqml20__DoubleTableLookup*>(gsoapProxy2_0_1)->Value).at(index)->Key;
}

double DoubleTableLookup::getValueAtIndex(unsigned int index) const
double DoubleTableLookup::getValueAtIndex(uint64_t index) const
{
if (getItemCount() <= index) {
throw out_of_range("The index is out of range.");
}

return (static_cast<_resqml20__DoubleTableLookup*>(gsoapProxy2_0_1)->Value)[index]->Value;
return (static_cast<_resqml20__DoubleTableLookup*>(gsoapProxy2_0_1)->Value).at(index)->Value;
}

bool DoubleTableLookup::containsKey(double key)
{
_resqml20__DoubleTableLookup* stringLookup = static_cast<_resqml20__DoubleTableLookup*>(gsoapProxy2_0_1);

for (size_t i = 0; i < stringLookup->Value.size(); ++i) {
if (stringLookup->Value[i]->Key == key) {
return true;
}
}
const auto dblLookups = static_cast<_resqml20__DoubleTableLookup*>(gsoapProxy2_0_1)->Value;

return false;
return std::find_if(dblLookups.begin(), dblLookups.end(),
[key](resqml20__DoubleLookup const* element) {return element->Key == key; })
!= dblLookups.end();
}

double DoubleTableLookup::getValueAtKey(double key)
{
_resqml20__DoubleTableLookup* stringLookup = static_cast<_resqml20__DoubleTableLookup*>(gsoapProxy2_0_1);
const auto dblLookups = static_cast<_resqml20__DoubleTableLookup*>(gsoapProxy2_0_1)->Value;

for (size_t i = 0; i < stringLookup->Value.size(); ++i) {
if (stringLookup->Value[i]->Key == key) {
return stringLookup->Value[i]->Value;
}
}
auto it = std::find_if(dblLookups.begin(), dblLookups.end(),
[key](resqml20__DoubleLookup const* element) {return element->Key == key; });

return std::numeric_limits<double>::quiet_NaN();
return it == dblLookups.end() ? std::numeric_limits<double>::quiet_NaN() : (*it)->Value;
}

void DoubleTableLookup::addValue(double key, double value)
Expand All @@ -102,14 +85,11 @@ void DoubleTableLookup::addValue(double key, double value)

void DoubleTableLookup::setValue(double key, double value)
{
_resqml20__DoubleTableLookup* stringLookup = static_cast<_resqml20__DoubleTableLookup*>(gsoapProxy2_0_1);
auto dblLookups = static_cast<_resqml20__DoubleTableLookup*>(gsoapProxy2_0_1)->Value;
auto it = std::find_if(dblLookups.begin(), dblLookups.end(),
[key](resqml20__DoubleLookup const* element) {return element->Key == key; });

for (size_t i = 0; i < stringLookup->Value.size(); ++i) {
if (stringLookup->Value[i]->Key == key) {
stringLookup->Value[i]->Value = value;
return;
}
}
if (it != dblLookups.end()) (*it)->Value = value;
}

namespace {
Expand Down Expand Up @@ -137,10 +117,8 @@ std::map<double, double> DoubleTableLookup::getMap() const
{
map<double, double> result;

_resqml20__DoubleTableLookup* stringLookup = static_cast<_resqml20__DoubleTableLookup*>(gsoapProxy2_0_1);

for (size_t i = 0; i < stringLookup->Value.size(); ++i) {
result[stringLookup->Value[i]->Key] = stringLookup->Value[i]->Value;
for (auto const* dblLookup : static_cast<_resqml20__DoubleTableLookup const*>(gsoapProxy2_0_1)->Value) {
result[dblLookup->Key] = dblLookup->Value;
}

return result;
Expand Down
8 changes: 4 additions & 4 deletions src/resqml2_0_1/DoubleTableLookup.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ namespace RESQML2_0_1_NS

DLL_IMPORT_OR_EXPORT bool containsKey(double key) final;

DLL_IMPORT_OR_EXPORT unsigned int getItemCount() const final;
DLL_IMPORT_OR_EXPORT uint64_t getItemCount() const final;

DLL_IMPORT_OR_EXPORT double getKeyAtIndex(unsigned int index) const final;
DLL_IMPORT_OR_EXPORT double getKeyAtIndex(uint64_t index) const final;

DLL_IMPORT_OR_EXPORT double getValueAtIndex(unsigned int index) const final;
DLL_IMPORT_OR_EXPORT double getValueAtIndex(uint64_t index) const final;

DLL_IMPORT_OR_EXPORT double getValueAtKey(double key) final;

Expand All @@ -79,7 +79,7 @@ namespace RESQML2_0_1_NS
/**
* The standard XML namespace for serializing this data object.
*/
DLL_IMPORT_OR_EXPORT static const char* XML_NS;
DLL_IMPORT_OR_EXPORT static constexpr char const* XML_NS = "resqml20";

/**
* Get the standard XML namespace for serializing this data object.
Expand Down
4 changes: 2 additions & 2 deletions src/resqml2_2/DiscreteProperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ size_t DiscreteProperty::getMinimumValueSize() const
if (intArray == nullptr) return 0;

size_t result = 0;
for (size_t result = 0; result < intArray->Statistics.size(); ++result) {
for (result = 0; result < intArray->Statistics.size(); ++result) {
if (intArray->Statistics[result]->MinimumValue == nullptr) return result;
}
return result;
Expand All @@ -189,7 +189,7 @@ size_t DiscreteProperty::getMaximumValueSize() const
if (intArray == nullptr) return 0;

size_t result = 0;
for (size_t result = 0; result < intArray->Statistics.size(); ++result) {
for (result = 0; result < intArray->Statistics.size(); ++result) {
if (intArray->Statistics[result]->MaximumValue == nullptr) return result;
}
return result;
Expand Down
Loading

0 comments on commit a1bfae1

Please sign in to comment.