-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refs #3545 added missing file, updated types
- Loading branch information
Showing
20 changed files
with
774 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
# -*- mode: qore; indent-tabs-mode: nil -*- | ||
#! Qore QoreDateDataTypeBase class definition | ||
|
||
/** QoreDateDataTypeBase.qc Copyright 2019 Qore Technologies, s.r.o. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a | ||
copy of this software and associated documentation files (the "Software"), | ||
to deal in the Software without restriction, including without limitation | ||
the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
and/or sell copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
# assume local scope for variables, do not use "$" signs | ||
%new-style | ||
# require type definitions everywhere | ||
%require-types | ||
#! strict argument handling | ||
%strict-args | ||
# enable all warnings | ||
%enable-all-warnings | ||
|
||
%requires reflection | ||
|
||
#! contains all public definitions in the DataProvider module | ||
public namespace DataProvider { | ||
#! describes a data type based on a date type with validation for string parsing and time zone support | ||
/** @note %Qore "soft" types that do not accept @ref nothing also accept @ref null; to ensure that soft types | ||
inheriting this class do not accept @ref null, use the \c qore.no_null option in the constructor | ||
*/ | ||
public class QoreDateDataTypeBase inherits QoreDataType { | ||
private { | ||
#! supported options | ||
const SupportedOptions = { | ||
"date.output_timezone": <DataProviderTypeOptionInfo>{ | ||
"type": "object<TimeZone>", | ||
"desc": "the time zone to use when writing to the type", | ||
}, | ||
}; | ||
|
||
#! supported soft options | ||
const SupportedSoftOptions = { | ||
"date.format": <DataProviderTypeOptionInfo>{ | ||
"type": Type::String, | ||
"desc": "the format string for converting strings to dates", | ||
}, | ||
"date.input_timezone": <DataProviderTypeOptionInfo>{ | ||
"type": "object<TimeZone>", | ||
"desc": "the time zone for external data when writing to the type and converting strings to dates", | ||
}, | ||
}; | ||
} | ||
|
||
#! creates the object | ||
/** @throw TYPE-ERROR invalid type; must be a date type | ||
*/ | ||
private constructor(Type type, *hash<auto> options) : QoreDataType(type, options) { | ||
if (type.getBaseTypeCode() != NT_DATE) { | ||
throw "TYPE-ERROR", sprintf("cannot create a %s object from type %y", self.className(), | ||
type.getName()); | ||
} | ||
# translations are performed on date types if there is an output_timezone | ||
if (options.output_timezone) { | ||
remove base_type_hash{NT_DATE}; | ||
} | ||
# set the input timezone option unconditionally | ||
if (!options."date.input_timezone") { | ||
self.options."date.input_timezone" = TimeZone::get(); | ||
} | ||
} | ||
|
||
#! returns the value if the value can be assigned to the type | ||
/** @param value the value to assign to the type | ||
|
||
@return the value to be assigned; can be converted by the type | ||
|
||
@throw RUNTIME-TYPE-ERROR value cannot be assigned to type | ||
*/ | ||
auto acceptsValue(auto value) { | ||
if (exists value && value !== NULL) { | ||
# try to convert from the source type | ||
if (value.typeCode() !== NT_DATE) { | ||
# only convert if the type can be converted | ||
if (!soft_type || !accept_type_hash{value.type()}) { | ||
throw "RUNTIME-TYPE-ERROR", sprintf("type %y cannot be assigned from a value of type %y", | ||
getName(), value.type()); | ||
} | ||
value = options."date.input_timezone".date(value, options."date.format"); | ||
} | ||
|
||
# convert to the output TimeZone if necessary | ||
if (options."date.output_timezone") { | ||
value = options."date.output_timezone".date(value); | ||
} | ||
return value; | ||
} | ||
return QoreDataType::acceptsValue(value); | ||
} | ||
|
||
#! returns supported options | ||
*hash<string, hash<DataProviderTypeOptionInfo>> getSupportedOptions() { | ||
return QoreDataType::getSupportedOptions() + SupportedOptions + (soft_type ? SupportedSoftOptions : NOTHING); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# -*- mode: qore; indent-tabs-mode: nil -*- | ||
#! Qore QoreFloatDataType class definition | ||
|
||
/** QoreFloatDataType.qc Copyright 2019 Qore Technologies, s.r.o. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a | ||
copy of this software and associated documentation files (the "Software"), | ||
to deal in the Software without restriction, including without limitation | ||
the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
and/or sell copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
# assume local scope for variables, do not use "$" signs | ||
%new-style | ||
# require type definitions everywhere | ||
%require-types | ||
#! strict argument handling | ||
%strict-args | ||
# enable all warnings | ||
%enable-all-warnings | ||
|
||
%requires reflection | ||
|
||
#! contains all public definitions in the DataProvider module | ||
public namespace DataProvider { | ||
#! describes a data type based on float | ||
public class QoreFloatDataType inherits QoreFloatDataTypeBase { | ||
#! creates the object | ||
constructor(*hash<auto> options) : QoreFloatDataTypeBase(FloatType, options) { | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# -*- mode: qore; indent-tabs-mode: nil -*- | ||
#! Qore QoreFloatDataTypeBase class definition | ||
|
||
/** QoreFloatDataTypeBase.qc Copyright 2019 Qore Technologies, s.r.o. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a | ||
copy of this software and associated documentation files (the "Software"), | ||
to deal in the Software without restriction, including without limitation | ||
the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
and/or sell copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
# assume local scope for variables, do not use "$" signs | ||
%new-style | ||
# require type definitions everywhere | ||
%require-types | ||
#! strict argument handling | ||
%strict-args | ||
# enable all warnings | ||
%enable-all-warnings | ||
|
||
%requires reflection | ||
|
||
#! contains all public definitions in the DataProvider module | ||
public namespace DataProvider { | ||
#! describes a data type based on softnumber with validation for parsing strings | ||
public class QoreFloatDataTypeBase inherits QoreDataType { | ||
private { | ||
#! supported soft options | ||
const SupportedSoftOptions = { | ||
"number.format": <DataProviderTypeOptionInfo>{ | ||
"type": Type::String, | ||
"desc": "the format string for converting strings to numbers", | ||
}, | ||
}; | ||
} | ||
|
||
#! creates the object | ||
/** @throw TYPE-ERROR invalid type; must be a number type | ||
*/ | ||
private constructor(Type type, *hash<auto> options) : QoreDataType(type, options) { | ||
if (type.getBaseTypeCode() != NT_FLOAT) { | ||
throw "TYPE-ERROR", sprintf("cannot create a %s object from type %y", self.className(), | ||
type.getName()); | ||
} | ||
} | ||
|
||
#! returns the value if the value can be assigned to the type | ||
/** @param value the value to assign to the type | ||
|
||
@return the value to be assigned; can be converted by the type | ||
|
||
@throw RUNTIME-TYPE-ERROR value cannot be assigned to type | ||
*/ | ||
auto acceptsValue(auto value) { | ||
# try to convert from a string | ||
if (value.typeCode() == NT_STRING && soft_type) { | ||
if (options."number.format") { | ||
return parse_float(value, options."number.format"); | ||
} | ||
if (value !~ /^([-+])?[0-9]+(\.[0-9]+)?+$/) | ||
throw "RUNTIME-TYPE-ERROR", sprintf("value %y cannot be parsed by type %y; the input data " | ||
"contains non-numeric text", value, getName()); | ||
return number(value); | ||
} | ||
return QoreDataType::acceptsValue(value); | ||
} | ||
|
||
#! returns supported options | ||
*hash<string, hash<DataProviderTypeOptionInfo>> getSupportedOptions() { | ||
return QoreDataType::getSupportedOptions() + (soft_type ? SupportedSoftOptions : NOTHING); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# -*- mode: qore; indent-tabs-mode: nil -*- | ||
#! Qore QoreFloatOrNothingDataType class definition | ||
|
||
/** QoreFloatOrNothingDataType.qc Copyright 2019 Qore Technologies, s.r.o. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a | ||
copy of this software and associated documentation files (the "Software"), | ||
to deal in the Software without restriction, including without limitation | ||
the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
and/or sell copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
# assume local scope for variables, do not use "$" signs | ||
%new-style | ||
# require type definitions everywhere | ||
%require-types | ||
#! strict argument handling | ||
%strict-args | ||
# enable all warnings | ||
%enable-all-warnings | ||
|
||
%requires reflection | ||
|
||
#! contains all public definitions in the DataProvider module | ||
public namespace DataProvider { | ||
#! describes a data type based on *float | ||
public class QoreFloatOrNothingDataType inherits QoreFloatDataTypeBase { | ||
#! creates the object | ||
constructor(*hash<auto> options) : QoreFloatDataTypeBase(FloatOrNothingType, options) { | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.