Skip to content

Commit 04594a4

Browse files
Add support for EML2.3 PropertyKind deprecation date
1 parent 5c3a3c7 commit 04594a4

4 files changed

Lines changed: 117 additions & 0 deletions

File tree

example/example.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ void serializeWells(COMMON_NS::DataObjectRepository * repo, EML2_NS::AbstractHdf
302302
#if WITH_RESQML2_2
303303
else {
304304
unitNumberPropType = repo->createPropertyKind("358aac23-b377-4349-9e72-bff99a6edf34", "Unit number", gsoap_eml2_3::eml23__QuantityClassKind::not_x0020a_x0020measure);
305+
static_cast<EML2_3_NS::PropertyKind*>(unitNumberPropType)->setDeprecationDate(unitNumberPropType->getCreation() + 3600);
305306
}
306307
#endif
307308

src/eml2_3/PropertyKind.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ under the License.
1919
#include "PropertyKind.h"
2020

2121
#include <stdexcept>
22+
#include "../tools/TimeTools.h"
2223

2324
using namespace std;
2425
using namespace EML2_3_NS;
@@ -113,6 +114,63 @@ COMMON_NS::DataObjectReference PropertyKind::getParentPropertyKindDor() const
113114
return COMMON_NS::DataObjectReference(static_cast<gsoap_eml2_3::_eml23__PropertyKind*>(gsoapProxy2_3)->Parent);
114115
}
115116

117+
time_t PropertyKind::getDeprecationDate() const
118+
{
119+
tm result = getDeprecationDateAsTimeStructure();
120+
121+
if (result.tm_mday == 0) {
122+
return -1;
123+
}
124+
125+
return timeTools::timegm(result);
126+
}
127+
128+
tm PropertyKind::getDeprecationDateAsTimeStructure() const
129+
{
130+
cannotBePartial();
131+
132+
if (gsoapProxy2_3 != nullptr && static_cast<gsoap_eml2_3::_eml23__PropertyKind*>(gsoapProxy2_3)->DeprecationDate)
133+
return *static_cast<gsoap_eml2_3::_eml23__PropertyKind*>(gsoapProxy2_3)->DeprecationDate;
134+
else {
135+
tm result;
136+
result.tm_hour = 0;
137+
result.tm_isdst = 0;
138+
result.tm_mday = 0;
139+
result.tm_min = 0;
140+
result.tm_mon = 0;
141+
result.tm_sec = 0;
142+
result.tm_wday = 0;
143+
result.tm_yday = 0;
144+
result.tm_year = 0;
145+
return result;
146+
}
147+
}
148+
149+
void PropertyKind::setDeprecationDate(time_t deprecationDate)
150+
{
151+
cannotBePartial();
152+
153+
if (deprecationDate > 0) {
154+
155+
if (deprecationDate < getCreation()) {
156+
throw invalid_argument("Deprecation Date cannot be inferior to creation date.");
157+
}
158+
159+
std::tm tmConversion = timeTools::to_calendar_time(timeTools::from_time_t(deprecationDate));
160+
setDeprecationDate(tmConversion);
161+
}
162+
}
163+
164+
void PropertyKind::setDeprecationDate(const tm& deprecationDate)
165+
{
166+
cannotBePartial();
167+
168+
if (static_cast<gsoap_eml2_3::_eml23__PropertyKind*>(gsoapProxy2_3)->DeprecationDate == nullptr) {
169+
static_cast<gsoap_eml2_3::_eml23__PropertyKind*>(gsoapProxy2_3)->DeprecationDate = (tm*)soap_malloc(gsoapProxy2_3->soap, sizeof(tm));
170+
}
171+
*static_cast<gsoap_eml2_3::_eml23__PropertyKind*>(gsoapProxy2_3)->DeprecationDate = deprecationDate;
172+
}
173+
116174
void PropertyKind::loadTargetRelationships()
117175
{
118176
COMMON_NS::DataObjectReference dor = getParentPropertyKindDor();

src/eml2_3/PropertyKind.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,44 @@ namespace EML2_3_NS
124124
*/
125125
COMMON_NS::DataObjectReference getParentPropertyKindDor() const final;
126126

127+
/**
128+
* Gets the date and time at which this property dictionary entry must no longer be used.
129+
* Files generated before this date would have used this entry so it is left here for reference.
130+
*
131+
* @exception std::invalid_argument If this instance is actually a partial object.
132+
*
133+
* @returns deprecationDate The deprecation date and time of this data object.
134+
*/
135+
DLL_IMPORT_OR_EXPORT time_t getDeprecationDate() const;
136+
137+
/**
138+
* Same as {@link getDeprecationDate()}. Please use this method if you want to read some dates out of
139+
* the range of @c time_t
140+
*
141+
* @exception std::invalid_argument If this instance is actually a partial object.
142+
*
143+
* @returns The deprecation date and time of the data object.
144+
*/
145+
DLL_IMPORT_OR_EXPORT tm getDeprecationDateAsTimeStructure() const;
146+
147+
/**
148+
* Sets the date and time at which this property dictionary entry must no longer be used.
149+
* Files generated before this date would have used this entry so it is left here for reference.
150+
*
151+
* @exception std::invalid_argument If this instance is actually a partial object.
152+
*
153+
* @param deprecationDate The deprecation date and time to set to this data object.
154+
*/
155+
DLL_IMPORT_OR_EXPORT void setDeprecationDate(time_t deprecationDate);
156+
157+
/**
158+
* Same as {@link setDeprecationDate()}. Please use this method if you want to read some dates out of
159+
* the range of @c time_t
160+
*
161+
* @param lastUpdate The deprecation date and time to set to this data object.
162+
*/
163+
DLL_IMPORT_OR_EXPORT void setDeprecationDate(const tm& lastUpdate);
164+
127165
/** Loads target relationships */
128166
void loadTargetRelationships() final;
129167

swig/swigEml2_3Include.i

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,6 +2042,26 @@ namespace EML2_3_NS
20422042
class PropertyKind : public EML2_NS::PropertyKind
20432043
{
20442044
public:
2045+
2046+
/**
2047+
* Gets the date and time at which this property dictionary entry must no longer be used.
2048+
* Files generated before this date would have used this entry so it is left here for reference.
2049+
*
2050+
* @exception std::invalid_argument If this instance is actually a partial object.
2051+
*
2052+
* @returns deprecationDate The deprecation date and time of this data object.
2053+
*/
2054+
time_t getDeprecationDate() const;
2055+
2056+
/**
2057+
* Sets the date and time at which this property dictionary entry must no longer be used.
2058+
* Files generated before this date would have used this entry so it is left here for reference.
2059+
*
2060+
* @exception std::invalid_argument If this instance is actually a partial object.
2061+
*
2062+
* @param deprecationDate The deprecation date and time to set to this data object.
2063+
*/
2064+
void setDeprecationDate(time_t deprecationDate);
20452065
};
20462066

20472067
#if defined(SWIGJAVA) || defined(SWIGPYTHON)

0 commit comments

Comments
 (0)