diff --git a/src/space/space.cpp b/src/space/space.cpp index db2a131..a9dddb8 100644 --- a/src/space/space.cpp +++ b/src/space/space.cpp @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2008-2022, Tomasz Sowa + * Copyright (c) 2008-2023, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -1305,6 +1305,19 @@ std::wstring Space::to_wstr() const } +Date Space::to_date() const +{ + if( type == type_wstring ) + return Date(value.value_wstring); + + if( type == type_string ) + return Date(value.value_string); + + if( type == type_long ) + return Date(static_cast(value.value_long)); + + return Date(); +} void Space::to_list(std::list & output_list, bool clear_list) const @@ -1471,6 +1484,20 @@ std::wstring Space::to_wstr(const wchar_t * field, const std::wstring & default_ } +Date Space::to_date(const wchar_t * field) const +{ + const Space * space = get_space(field); + return space ? space->to_date() : Date(); +} + + +Date Space::to_date(const wchar_t * field, const Date & default_value) const +{ + const Space * space = get_space(field); + return space ? space->to_date() : default_value; +} + + bool Space::to_list(const wchar_t * field, std::list & output_list, bool clear_list) const { return to_list_generic(field, output_list, clear_list); diff --git a/src/space/space.h b/src/space/space.h index 82a780f..de659a7 100644 --- a/src/space/space.h +++ b/src/space/space.h @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2010-2022, Tomasz Sowa + * Copyright (c) 2010-2023, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -382,6 +382,7 @@ public: long double to_long_double() const; std::string to_str() const; std::wstring to_wstr() const; + Date to_date() const; void to_list(std::list & output_list, bool clear_list = true) const; void to_list(std::list & output_list, bool clear_list = true) const; @@ -410,6 +411,9 @@ public: std::wstring to_wstr(const wchar_t * field, const wchar_t * default_value = nullptr) const; std::wstring to_wstr(const wchar_t * field, const std::wstring & default_value) const; + Date to_date(const wchar_t * field) const; + Date to_date(const wchar_t * field, const Date & default_value) const; + bool to_list(const wchar_t * field, std::list & output_list, bool clear_list = true) const; bool to_list(const wchar_t * field, std::list & output_list, bool clear_list = true) const; bool to_list(const std::wstring & field, std::list & output_list, bool clear_list = true) const;