Fesapi 2.14.0.0
This project provides C++ classes which allow an easy access in import and export to the Energistics standards.
Loading...
Searching...
No Matches
DiscreteProperty.h
1/*-----------------------------------------------------------------------
2Licensed to the Apache Software Foundation (ASF) under one
3or more contributor license agreements. See the NOTICE file
4distributed with this work for additional information
5regarding copyright ownership. The ASF licenses this file
6to you under the Apache License, Version 2.0 (the
7"License"; you may not use this file except in compliance
8with the License. You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12Unless required by applicable law or agreed to in writing,
13software distributed under the License is distributed on an
14"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15KIND, either express or implied. See the License for the
16specific language governing permissions and limitations
17under the License.
18-----------------------------------------------------------------------*/
19#pragma once
20
21#include "../resqml2/DiscreteProperty.h"
22
23namespace RESQML2_2_NS
24{
30 class DiscreteProperty final : public RESQML2_NS::DiscreteProperty
31 {
32 public:
33
39 DLL_IMPORT_OR_EXPORT DiscreteProperty(gsoap_resqml2_0_1::eml20__DataObjectReference* partialObject) : RESQML2_NS::DiscreteProperty(partialObject) {}
40
58 DiscreteProperty(RESQML2_NS::AbstractRepresentation* rep, const std::string& guid, const std::string& title,
59 unsigned int dimension, gsoap_eml2_3::eml23__IndexableElement attachmentKind, EML2_NS::PropertyKind* propKind);
60
66 DiscreteProperty(gsoap_eml2_3::_resqml22__DiscreteProperty* fromGsoap): RESQML2_NS::DiscreteProperty(fromGsoap) {}
67
69 ~DiscreteProperty() = default;
70
71 DLL_IMPORT_OR_EXPORT std::string pushBackRefToExistingIntegerDataset(EML2_NS::AbstractHdfProxy* proxy, const std::string & datasetName, int64_t nullValue, int64_t minimumValue, int64_t maximumValue) final;
72 using AbstractValuesProperty::pushBackRefToExistingIntegerDataset;
73
74 DLL_IMPORT_OR_EXPORT int64_t getNullValue(uint64_t patchIndex = (std::numeric_limits<uint64_t>::max)()) const final;
75
76 DLL_IMPORT_OR_EXPORT bool hasMinimumValue(uint64_t index = 0) const final;
77
78 DLL_IMPORT_OR_EXPORT int64_t getMinimumValue(uint64_t index = 0) const final;
79
80 DLL_IMPORT_OR_EXPORT bool hasMaximumValue(uint64_t index = 0) const final;
81
82 DLL_IMPORT_OR_EXPORT int64_t getMaximumValue(uint64_t index = 0) const final;
83
84 DLL_IMPORT_OR_EXPORT void setMinimumValue(int64_t value, uint64_t index = 0) const final;
85
86 DLL_IMPORT_OR_EXPORT void setMaximumValue(int64_t value, uint64_t index = 0) const final;
87
88 bool validatePropertyKindAssociation(EML2_NS::PropertyKind*) final { return true; }
89
90 bool validatePropertyKindAssociation(gsoap_resqml2_0_1::resqml20__ResqmlPropertyKind) final { return true; }
91
92 DLL_IMPORT_OR_EXPORT COMMON_NS::NumberArrayStatistics<int8_t> getInt8Statistics(uint64_t patchIndex) const final { return getStats<int8_t>(patchIndex); }
93 DLL_IMPORT_OR_EXPORT COMMON_NS::NumberArrayStatistics<uint8_t> getUInt8Statistics(uint64_t patchIndex) const final { return getStats<uint8_t>(patchIndex); }
94 DLL_IMPORT_OR_EXPORT COMMON_NS::NumberArrayStatistics<int16_t> getInt16Statistics(uint64_t patchIndex) const final { return getStats<int16_t>(patchIndex); }
95 DLL_IMPORT_OR_EXPORT COMMON_NS::NumberArrayStatistics<uint16_t> getUInt16Statistics(uint64_t patchIndex) const final { return getStats<uint16_t>(patchIndex); }
96 DLL_IMPORT_OR_EXPORT COMMON_NS::NumberArrayStatistics<int32_t> getInt32Statistics(uint64_t patchIndex) const final { return getStats<int32_t>(patchIndex); }
97 DLL_IMPORT_OR_EXPORT COMMON_NS::NumberArrayStatistics<uint32_t> getUInt32Statistics(uint64_t patchIndex) const final { return getStats<uint32_t>(patchIndex); }
98 DLL_IMPORT_OR_EXPORT COMMON_NS::NumberArrayStatistics<int64_t> getInt64Statistics(uint64_t patchIndex) const final { return getStats<int64_t>(patchIndex); }
99 DLL_IMPORT_OR_EXPORT COMMON_NS::NumberArrayStatistics<uint64_t> getUInt64Statistics(uint64_t patchIndex) const final { return getStats<uint64_t>(patchIndex); }
100
104 DLL_IMPORT_OR_EXPORT static const char* XML_NS;
105
109 DLL_IMPORT_OR_EXPORT std::string getXmlNamespace() const final { return XML_NS; }
110
111 private:
112
113 size_t getMinimumValueSize() const;
114 size_t getMaximumValueSize() const;
115
116 template<typename T>
117 COMMON_NS::NumberArrayStatistics<T> getStats(uint64_t patchIndex) const {
118 auto nullValue = getNullValueOfPatch(patchIndex);
119 if constexpr (std::is_signed_v<T>) {
120 if (nullValue > (std::numeric_limits<T>::max)() || nullValue < (std::numeric_limits<T>::min)()) {
121 nullValue = (std::numeric_limits<T>::max)();
122 }
123 }
124 else {
125 if (nullValue > 0 || static_cast<uint64_t>(nullValue) < (std::numeric_limits<T>::min)()) {
126 nullValue = (std::numeric_limits<T>::max)();
127 }
128 }
129 COMMON_NS::NumberArrayStatistics<T> result;
130 result.setNullValue(static_cast<T>(nullValue));
131
132 const auto* valuesforPatch = static_cast<gsoap_eml2_3::_resqml22__DiscreteProperty*>(gsoapProxy2_3)->ValuesForPatch.at(patchIndex);
133 auto const* intArray = dynamic_cast<gsoap_eml2_3::eml23__AbstractIntegerArray const*>(valuesforPatch);
134 if (intArray == nullptr) return result;
135
136 for (size_t i = 0; i < intArray->Statistics.size(); ++i) {
137 auto const* stats = intArray->Statistics[i];
138 if (stats->MaximumValue) {
139 if constexpr (std::is_signed_v<T>) {
140 if (*stats->MaximumValue > (std::numeric_limits<T>::min)() &&
141 *stats->MaximumValue < (std::numeric_limits<T>::max)()) {
142 result.setMaximum(static_cast<T>(*stats->MaximumValue), i);
143 }
144 }
145 else {
146 if (*stats->MaximumValue > 0 &&
147 static_cast<uint64_t>(*stats->MaximumValue) < (std::numeric_limits<T>::max)()) {
148 result.setMaximum(static_cast<T>(*stats->MaximumValue), i);
149 }
150 }
151 }
152 if (stats->MinimumValue) {
153 if constexpr (std::is_signed_v<T>) {
154 if (*stats->MinimumValue > (std::numeric_limits<T>::min)() &&
155 *stats->MinimumValue < (std::numeric_limits<T>::max)()) {
156 result.setMinimum(static_cast<T>(*stats->MinimumValue), i);
157 }
158 }
159 else {
160 if (*stats->MinimumValue > 0 &&
161 static_cast<uint64_t>(*stats->MinimumValue) < (std::numeric_limits<T>::max)()) {
162 result.setMinimum(static_cast<T>(*stats->MinimumValue), i);
163 }
164 }
165 }
166 if (stats->ModePercentage) {
167 result.setModePercentage(*stats->ModePercentage, i);
168 }
169 if (stats->ValidValueCount) {
170 result.setValidValueCount(*stats->ValidValueCount, i);
171 }
172 if (stats->ValuesMedian) {
173 result.setMedian(*stats->ValuesMedian, i);
174 }
175 if (stats->ValuesMode) {
176 if constexpr (std::is_signed_v<T>) {
177 if (*stats->ValuesMode > (std::numeric_limits<T>::min)() &&
178 *stats->ValuesMode < (std::numeric_limits<T>::max)()) {
179 result.setMode(static_cast<T>(*stats->ValuesMode), i);
180 }
181 }
182 else {
183 if (*stats->ValuesMode > 0 &&
184 static_cast<uint64_t>(*stats->ValuesMode) < (std::numeric_limits<T>::max)()) {
185 result.setMode(static_cast<T>(*stats->ValuesMode), i);
186 }
187 }
188 }
189 }
190
191 return result;
192 }
193 };
194}
int64_t getNullValue(uint64_t patchIndex=(std::numeric_limits< uint64_t >::max)()) const final
Gets the null value in this discrete property.
DiscreteProperty(gsoap_eml2_3::_resqml22__DiscreteProperty *fromGsoap)
Definition DiscreteProperty.h:66
bool validatePropertyKindAssociation(eml2::PropertyKind *) final
Definition DiscreteProperty.h:88
DiscreteProperty(gsoap_resqml2_0_1::eml20__DataObjectReference *partialObject)
Definition DiscreteProperty.h:39
std::string pushBackRefToExistingIntegerDataset(eml2::AbstractHdfProxy *proxy, const std::string &datasetName, int64_t nullValue, int64_t minimumValue, int64_t maximumValue) final
void setMaximumValue(int64_t value, uint64_t index=0) const final
Sets the maximum value of a non vector property or the maximum value of one given value of a vector p...
int64_t getMinimumValue(uint64_t index=0) const final
Gets the minimum value of a non vector property or the minimum value of one given value of a vector p...
void setMinimumValue(int64_t value, uint64_t index=0) const final
Sets the minimum value of a non vector property or the minimum value of one given value of a vector p...
bool validatePropertyKindAssociation(gsoap_resqml2_0_1::resqml20__ResqmlPropertyKind) final
Definition DiscreteProperty.h:90
bool hasMinimumValue(uint64_t index=0) const final
Checks if a non vector property or a given value of a vector property has got a minimum value already...
std::string getXmlNamespace() const final
Definition DiscreteProperty.h:109
int64_t getMaximumValue(uint64_t index=0) const final
Gets the maximum value of a non vector property or the maximum value of one given value of a vector p...
static const char * XML_NS
Definition DiscreteProperty.h:104
bool hasMaximumValue(uint64_t index=0) const final
Checks if a non vector property or a given value of a vector property has got a maximum value already...
DiscreteProperty(resqml2::AbstractRepresentation *rep, const std::string &guid, const std::string &title, unsigned int dimension, gsoap_eml2_3::eml23__IndexableElement attachmentKind, eml2::PropertyKind *propKind)