diff options
author | orivej <orivej@yandex-team.ru> | 2022-02-10 16:45:01 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:01 +0300 |
commit | 2d37894b1b037cf24231090eda8589bbb44fb6fc (patch) | |
tree | be835aa92c6248212e705f25388ebafcf84bc7a1 /contrib/libs/poco/Foundation/include/Poco/Optional.h | |
parent | 718c552901d703c502ccbefdfc3c9028d608b947 (diff) | |
download | ydb-2d37894b1b037cf24231090eda8589bbb44fb6fc.tar.gz |
Restoring authorship annotation for <orivej@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/libs/poco/Foundation/include/Poco/Optional.h')
-rw-r--r-- | contrib/libs/poco/Foundation/include/Poco/Optional.h | 322 |
1 files changed, 161 insertions, 161 deletions
diff --git a/contrib/libs/poco/Foundation/include/Poco/Optional.h b/contrib/libs/poco/Foundation/include/Poco/Optional.h index c896bb9e56..54593b16cc 100644 --- a/contrib/libs/poco/Foundation/include/Poco/Optional.h +++ b/contrib/libs/poco/Foundation/include/Poco/Optional.h @@ -1,161 +1,161 @@ -// -// Optional.h -// -// Library: Foundation -// Package: Core -// Module: Optional -// -// Definition of the Optional class template. -// -// Copyright (c) 2012, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// SPDX-License-Identifier: BSL-1.0 -// - - -#ifndef Foundation_Optional_INCLUDED -#define Foundation_Optional_INCLUDED - - -#include "Poco/Foundation.h" -#include "Poco/Exception.h" -#include <algorithm> - - -namespace Poco { - - -template <typename C> -class Optional - /// Optional is a simple wrapper class for value types - /// that allows to introduce a specified/unspecified state - /// to value objects. - /// - /// An Optional can be default constructed. In this case, - /// the Optional will have a Null value and isSpecified() will - /// return false. Calling value()(without default value) on - /// a Null object will throw a NullValueException. - /// - /// An Optional can also be constructed from a value. - /// It is possible to assign a value to an Optional, and - /// to reset an Optional to contain a Null value by calling - /// clear(). - /// - /// For use with Optional, the value type should support - /// default construction. - /// - /// Note that the Optional class is basically the same as - /// Nullable. However, serializers may treat Nullable - /// and Optional differently. An example is XML serialization based - /// on XML Schema, where Optional would be used for an element with - /// minOccurs == 0, whereas Nullable would be used on an element with - /// nillable == true. -{ -public: - Optional(): - /// Creates an empty Optional. - _value(), - _isSpecified(false) - { - } - - Optional(const C& value): - /// Creates a Optional with the given value. - _value(value), - _isSpecified(true) - { - } - - Optional(const Optional& other): - /// Creates a Optional by copying another one. - _value(other._value), - _isSpecified(other._isSpecified) - { - } - - ~Optional() - /// Destroys the Optional. - { - } - - Optional& assign(const C& value) - /// Assigns a value to the Optional. - { - _value = value; - _isSpecified = true; - return *this; - } - - Optional& assign(const Optional& other) - /// Assigns another Optional. - { - Optional tmp(other); - swap(tmp); - return *this; - } - - Optional& operator = (const C& value) - { - return assign(value); - } - - Optional& operator = (const Optional& other) - { - return assign(other); - } - - void swap(Optional& other) - { - std::swap(_value, other._value); - std::swap(_isSpecified, other._isSpecified); - } - - const C& value() const - /// Returns the Optional's value. - /// - /// Throws a Poco::NullValueException if the value has not been specified. - { - if (_isSpecified) - return _value; - else - throw Poco::NullValueException(); - } - - const C& value(const C& deflt) const - /// Returns the Optional's value, or the - /// given default value if the Optional's - /// value has not been specified. - { - return _isSpecified ? _value : deflt; - } - - bool isSpecified() const - /// Returns true iff the Optional's value has been specified. - { - return _isSpecified; - } - - void clear() - /// Clears the Optional. - { - _isSpecified = false; - } - -private: - C _value; - bool _isSpecified; -}; - - -template <typename C> -inline void swap(Optional<C>& n1, Optional<C>& n2) -{ - n1.swap(n2); -} - - -} // namespace Poco - - -#endif // Foundation_Optional_INCLUDED +// +// Optional.h +// +// Library: Foundation +// Package: Core +// Module: Optional +// +// Definition of the Optional class template. +// +// Copyright (c) 2012, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// SPDX-License-Identifier: BSL-1.0 +// + + +#ifndef Foundation_Optional_INCLUDED +#define Foundation_Optional_INCLUDED + + +#include "Poco/Foundation.h" +#include "Poco/Exception.h" +#include <algorithm> + + +namespace Poco { + + +template <typename C> +class Optional + /// Optional is a simple wrapper class for value types + /// that allows to introduce a specified/unspecified state + /// to value objects. + /// + /// An Optional can be default constructed. In this case, + /// the Optional will have a Null value and isSpecified() will + /// return false. Calling value()(without default value) on + /// a Null object will throw a NullValueException. + /// + /// An Optional can also be constructed from a value. + /// It is possible to assign a value to an Optional, and + /// to reset an Optional to contain a Null value by calling + /// clear(). + /// + /// For use with Optional, the value type should support + /// default construction. + /// + /// Note that the Optional class is basically the same as + /// Nullable. However, serializers may treat Nullable + /// and Optional differently. An example is XML serialization based + /// on XML Schema, where Optional would be used for an element with + /// minOccurs == 0, whereas Nullable would be used on an element with + /// nillable == true. +{ +public: + Optional(): + /// Creates an empty Optional. + _value(), + _isSpecified(false) + { + } + + Optional(const C& value): + /// Creates a Optional with the given value. + _value(value), + _isSpecified(true) + { + } + + Optional(const Optional& other): + /// Creates a Optional by copying another one. + _value(other._value), + _isSpecified(other._isSpecified) + { + } + + ~Optional() + /// Destroys the Optional. + { + } + + Optional& assign(const C& value) + /// Assigns a value to the Optional. + { + _value = value; + _isSpecified = true; + return *this; + } + + Optional& assign(const Optional& other) + /// Assigns another Optional. + { + Optional tmp(other); + swap(tmp); + return *this; + } + + Optional& operator = (const C& value) + { + return assign(value); + } + + Optional& operator = (const Optional& other) + { + return assign(other); + } + + void swap(Optional& other) + { + std::swap(_value, other._value); + std::swap(_isSpecified, other._isSpecified); + } + + const C& value() const + /// Returns the Optional's value. + /// + /// Throws a Poco::NullValueException if the value has not been specified. + { + if (_isSpecified) + return _value; + else + throw Poco::NullValueException(); + } + + const C& value(const C& deflt) const + /// Returns the Optional's value, or the + /// given default value if the Optional's + /// value has not been specified. + { + return _isSpecified ? _value : deflt; + } + + bool isSpecified() const + /// Returns true iff the Optional's value has been specified. + { + return _isSpecified; + } + + void clear() + /// Clears the Optional. + { + _isSpecified = false; + } + +private: + C _value; + bool _isSpecified; +}; + + +template <typename C> +inline void swap(Optional<C>& n1, Optional<C>& n2) +{ + n1.swap(n2); +} + + +} // namespace Poco + + +#endif // Foundation_Optional_INCLUDED |