Skip to content

Commit 09c7972

Browse files
authored
Make some verification functions public in C++ (#448)
We make the logical checks for XSD data types public, so that the clients can check their structures in a fine-grained manner.
1 parent b343ef6 commit 09c7972

File tree

6 files changed

+227
-175
lines changed

6 files changed

+227
-175
lines changed

test_data/cpp/test_main/aas_core_meta.v3/expected_output/verification.cpp

+6-80
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,6 @@ const std::wregex kRegexDatePrefix(
223223
L"^(-?[0-9]+)-(0[1-9]|11|12)-(0[0-9]|1[0-9]|2[0-9]|30|31)"
224224
);
225225

226-
/**
227-
* \brief Check whether the given \p year is a leap year.
228-
*
229-
* Year 1 BCE is a leap year.
230-
*
231-
* \param year to be checked
232-
* \return true if \p year is a leap year
233-
*/
234226
bool IsLeapYear(long long year) {
235227
// NOTE (mristin):
236228
// We consider the years B.C. to be one-off.
@@ -2247,12 +2239,6 @@ bool MatchesXsString(
22472239
);
22482240
}
22492241

2250-
/**
2251-
* \brief Check that \p value is a valid `xs:double`.
2252-
*
2253-
* \param value to be checked
2254-
* \return true if \p value is a valid `xs:double`
2255-
*/
22562242
bool IsXsDouble(const std::wstring& value) {
22572243
// NOTE (mristin):
22582244
// We need to check explicitly for the regular expression since
@@ -2304,12 +2290,6 @@ bool IsXsDouble(const std::wstring& value) {
23042290
return true;
23052291
}
23062292

2307-
/**
2308-
* \brief Check that \p value is a valid `xs:float`.
2309-
*
2310-
* \param value to be checked
2311-
* \return true if \p value is a valid `xs:float`
2312-
*/
23132293
bool IsXsFloat(const std::wstring& value) {
23142294
// NOTE (mristin):
23152295
// We need to check explicitly for the regular expression since
@@ -2361,12 +2341,6 @@ bool IsXsFloat(const std::wstring& value) {
23612341
return true;
23622342
}
23632343

2364-
/**
2365-
* \brief Check that \p value is a valid `xs:gMonthDay`.
2366-
*
2367-
* \param value to be checked
2368-
* \return true if \p value is a valid `xs:gMonthDay`
2369-
*/
23702344
bool IsXsGMonthDay(const std::wstring& value) {
23712345
if (!MatchesXsGMonthDay(value)) {
23722346
return false;
@@ -2381,12 +2355,6 @@ bool IsXsGMonthDay(const std::wstring& value) {
23812355
return day <= kDaysInMonth.at(month);
23822356
}
23832357

2384-
/**
2385-
* \brief Check that \p value is a valid `xs:long`.
2386-
*
2387-
* \param value to be checked
2388-
* \return true if \p value is a valid `xs:long`
2389-
*/
23902358
bool IsXsLong(const std::wstring& value) {
23912359
if (!MatchesXsLong(value)) {
23922360
return false;
@@ -2432,12 +2400,6 @@ bool IsXsLong(const std::wstring& value) {
24322400
return true;
24332401
}
24342402

2435-
/**
2436-
* \brief Check that \p value is a valid `xs:int`.
2437-
*
2438-
* \param value to be checked
2439-
* \return true if \p value is a valid `xs:int`
2440-
*/
24412403
bool IsXsInt(const std::wstring& value) {
24422404
if (!MatchesXsInt(value)) {
24432405
return false;
@@ -2483,12 +2445,6 @@ bool IsXsInt(const std::wstring& value) {
24832445
return true;
24842446
}
24852447

2486-
/**
2487-
* \brief Check that \p value is a valid `xs:short`.
2488-
*
2489-
* \param value to be checked
2490-
* \return true if \p value is a valid `xs:short`
2491-
*/
24922448
bool IsXsShort(const std::wstring& value) {
24932449
if (!MatchesXsShort(value)) {
24942450
return false;
@@ -2513,12 +2469,6 @@ bool IsXsShort(const std::wstring& value) {
25132469
return -32768 <= converted && converted <= 32767;
25142470
}
25152471

2516-
/**
2517-
* \brief Check that \p value is a valid `xs:byte`.
2518-
*
2519-
* \param value to be checked
2520-
* \return true if \p value is a valid `xs:byte`
2521-
*/
25222472
bool IsXsByte(const std::wstring& value) {
25232473
if (!MatchesXsByte(value)) {
25242474
return false;
@@ -2543,12 +2493,6 @@ bool IsXsByte(const std::wstring& value) {
25432493
return -128 <= converted && converted <= 127;
25442494
}
25452495

2546-
/**
2547-
* \brief Check that \p value is a valid `xs:unsignedLong`.
2548-
*
2549-
* \param value to be checked
2550-
* \return true if \p value is a valid `xs:unsignedLong`
2551-
*/
25522496
bool IsXsUnsignedLong(const std::wstring& value) {
25532497
if (!MatchesXsUnsignedLong(value)) {
25542498
return false;
@@ -2559,8 +2503,8 @@ bool IsXsUnsignedLong(const std::wstring& value) {
25592503
// We remove the warning C4101 in MSVC with constants.
25602504
// See: https://stackoverflow.com/questions/25573996/c4127-conditional-expression-is-constant
25612505
const bool sizeof_unsigned_long_is_8 = sizeof(unsigned long) == 8;
2562-
const bool sizeof_unsigned_long_long_is_8 = sizeof(unsigned long long) == 8;
2563-
2506+
const bool sizeof_unsigned_long_long_is_8 = sizeof(unsigned long long) == 8;
2507+
25642508
if (sizeof_unsigned_long_is_8) {
25652509
static_cast<void>(
25662510
std::stoul(value)
@@ -2594,12 +2538,6 @@ bool IsXsUnsignedLong(const std::wstring& value) {
25942538
return true;
25952539
}
25962540

2597-
/**
2598-
* \brief Check that \p value is a valid `xs:unsignedInt`.
2599-
*
2600-
* \param value to be checked
2601-
* \return true if \p value is a valid `xs:unsignedInt`
2602-
*/
26032541
bool IsXsUnsignedInt(const std::wstring& value) {
26042542
if (!MatchesXsUnsignedInt(value)) {
26052543
return false;
@@ -2615,8 +2553,8 @@ bool IsXsUnsignedInt(const std::wstring& value) {
26152553
// We remove the warning C4101 in MSVC with constants.
26162554
// See: https://stackoverflow.com/questions/25573996/c4127-conditional-expression-is-constant
26172555
const bool sizeof_unsigned_long_ge_4 = sizeof(unsigned long) >= 4;
2618-
const bool sizeof_unsigned_long_long_ge_4 = sizeof(unsigned long long) >= 4;
2619-
2556+
const bool sizeof_unsigned_long_long_ge_4 = sizeof(unsigned long long) >= 4;
2557+
26202558
if (sizeof_unsigned_long_ge_4) {
26212559
const unsigned long number = std::stoul(value);
26222560
return number <= 4294967295ul;
@@ -2648,12 +2586,6 @@ bool IsXsUnsignedInt(const std::wstring& value) {
26482586
}
26492587
}
26502588

2651-
/**
2652-
* \brief Check that \p value is a valid `xs:unsignedShort`.
2653-
*
2654-
* \param value to be checked
2655-
* \return true if \p value is a valid `xs:unsignedShort`
2656-
*/
26572589
bool IsXsUnsignedShort(const std::wstring& value) {
26582590
if (!MatchesXsUnsignedShort(value)) {
26592591
return false;
@@ -2673,8 +2605,8 @@ bool IsXsUnsignedShort(const std::wstring& value) {
26732605
);
26742606
const bool sizeof_unsigned_long_long_ge_4(
26752607
sizeof(unsigned long long) >= 4
2676-
);
2677-
2608+
);
2609+
26782610
if (sizeof_unsigned_long_ge_4) {
26792611
const unsigned long number = std::stoul(value);
26802612
return number <= 65535ul;
@@ -2706,12 +2638,6 @@ bool IsXsUnsignedShort(const std::wstring& value) {
27062638
}
27072639
}
27082640

2709-
/**
2710-
* \brief Check that \p value is a valid `xs:unsignedByte`.
2711-
*
2712-
* \param value to be checked
2713-
* \return true if \p value is a valid `xs:unsignedByte`
2714-
*/
27152641
bool IsXsUnsignedByte(const std::wstring& value) {
27162642
if (!MatchesXsUnsignedByte(value)) {
27172643
return false;

test_data/cpp/test_main/aas_core_meta.v3/expected_output/verification.hpp

+107-7
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,25 @@ bool MatchesXsDateTimeUtc(
240240
const std::wstring& text
241241
);
242242

243-
/// \brief Check that \p text is a `xs:dateTime` with time zone set to UTC.
244-
///
245-
/// The `text` is assumed to match a pre-defined pattern for `xs:dateTime` with
246-
/// the time zone set to UTC. In this function, we check for days of month (e.g.,
247-
/// February 29th).
248-
///
249-
/// See: https://www.w3.org/TR/xmlschema-2/#dateTime
243+
/**
244+
* \brief Check whether the given \p year is a leap year.
245+
*
246+
* Year 1 BCE is a leap year.
247+
*
248+
* \param year to be checked
249+
* \return true if \p year is a leap year
250+
*/
251+
bool IsLeapYear(long long year);
252+
253+
/**
254+
* \brief Check that \p text is a `xs:dateTime` with time zone set to UTC.
255+
*
256+
* The `text` is assumed to match a pre-defined pattern for `xs:dateTime` with
257+
* the time zone set to UTC. In this function, we check for days of month (e.g.,
258+
* February 29th).
259+
*
260+
* See: https://www.w3.org/TR/xmlschema-2/#dateTime
261+
*/
250262
bool IsXsDateTimeUtc(
251263
const std::wstring& text
252264
);
@@ -549,6 +561,94 @@ bool ValueConsistentWithXsdType(
549561
types::DataTypeDefXsd value_type
550562
);
551563

564+
/**
565+
* \brief Check that \p value is a valid `xs:double`.
566+
*
567+
* \param value to be checked
568+
* \return true if \p value is a valid `xs:double`
569+
*/
570+
bool IsXsDouble(const std::wstring& value);
571+
572+
/**
573+
* \brief Check that \p value is a valid `xs:float`.
574+
*
575+
* \param value to be checked
576+
* \return true if \p value is a valid `xs:float`
577+
*/
578+
bool IsXsFloat(const std::wstring& value);
579+
580+
/**
581+
* \brief Check that \p value is a valid `xs:gMonthDay`.
582+
*
583+
* \param value to be checked
584+
* \return true if \p value is a valid `xs:gMonthDay`
585+
*/
586+
bool IsXsGMonthDay(const std::wstring& value);
587+
588+
/**
589+
* \brief Check that \p value is a valid `xs:long`.
590+
*
591+
* \param value to be checked
592+
* \return true if \p value is a valid `xs:long`
593+
*/
594+
bool IsXsLong(const std::wstring& value);
595+
596+
/**
597+
* \brief Check that \p value is a valid `xs:int`.
598+
*
599+
* \param value to be checked
600+
* \return true if \p value is a valid `xs:int`
601+
*/
602+
bool IsXsInt(const std::wstring& value);
603+
604+
/**
605+
* \brief Check that \p value is a valid `xs:short`.
606+
*
607+
* \param value to be checked
608+
* \return true if \p value is a valid `xs:short`
609+
*/
610+
bool IsXsShort(const std::wstring& value);
611+
612+
/**
613+
* \brief Check that \p value is a valid `xs:byte`.
614+
*
615+
* \param value to be checked
616+
* \return true if \p value is a valid `xs:byte`
617+
*/
618+
bool IsXsByte(const std::wstring& value);
619+
620+
/**
621+
* \brief Check that \p value is a valid `xs:unsignedLong`.
622+
*
623+
* \param value to be checked
624+
* \return true if \p value is a valid `xs:unsignedLong`
625+
*/
626+
bool IsXsUnsignedLong(const std::wstring& value);
627+
628+
/**
629+
* \brief Check that \p value is a valid `xs:unsignedInt`.
630+
*
631+
* \param value to be checked
632+
* \return true if \p value is a valid `xs:unsignedInt`
633+
*/
634+
bool IsXsUnsignedInt(const std::wstring& value);
635+
636+
/**
637+
* \brief Check that \p value is a valid `xs:unsignedShort`.
638+
*
639+
* \param value to be checked
640+
* \return true if \p value is a valid `xs:unsignedShort`
641+
*/
642+
bool IsXsUnsignedShort(const std::wstring& value);
643+
644+
/**
645+
* \brief Check that \p value is a valid `xs:unsignedByte`.
646+
*
647+
* \param value to be checked
648+
* \return true if \p value is a valid `xs:unsignedByte`
649+
*/
650+
bool IsXsUnsignedByte(const std::wstring& value);
651+
552652
/// \brief Check that the target of the model reference matches the \p expected_type.
553653
bool IsModelReferenceTo(
554654
const std::shared_ptr<types::IReference>& reference,

test_data/cpp/test_main/aas_core_meta.v3/input/snippets/verification/is_xs_date_time_UTC.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,6 @@ const std::wregex kRegexDatePrefix(
22
L"^(-?[0-9]+)-(0[1-9]|11|12)-(0[0-9]|1[0-9]|2[0-9]|30|31)"
33
);
44

5-
/**
6-
* \brief Check whether the given \p year is a leap year.
7-
*
8-
* Year 1 BCE is a leap year.
9-
*
10-
* \param year to be checked
11-
* \return true if \p year is a leap year
12-
*/
135
bool IsLeapYear(long long year) {
146
// NOTE (mristin):
157
// We consider the years B.C. to be one-off.
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
1-
/// \brief Check that \p text is a `xs:dateTime` with time zone set to UTC.
2-
///
3-
/// The `text` is assumed to match a pre-defined pattern for `xs:dateTime` with
4-
/// the time zone set to UTC. In this function, we check for days of month (e.g.,
5-
/// February 29th).
6-
///
7-
/// See: https://www.w3.org/TR/xmlschema-2/#dateTime
1+
/**
2+
* \brief Check whether the given \p year is a leap year.
3+
*
4+
* Year 1 BCE is a leap year.
5+
*
6+
* \param year to be checked
7+
* \return true if \p year is a leap year
8+
*/
9+
bool IsLeapYear(long long year);
10+
11+
/**
12+
* \brief Check that \p text is a `xs:dateTime` with time zone set to UTC.
13+
*
14+
* The `text` is assumed to match a pre-defined pattern for `xs:dateTime` with
15+
* the time zone set to UTC. In this function, we check for days of month (e.g.,
16+
* February 29th).
17+
*
18+
* See: https://www.w3.org/TR/xmlschema-2/#dateTime
19+
*/
820
bool IsXsDateTimeUtc(
921
const std::wstring& text
1022
);

0 commit comments

Comments
 (0)