diff options
| author | thegeorg <[email protected]> | 2025-05-07 11:09:12 +0300 | 
|---|---|---|
| committer | thegeorg <[email protected]> | 2025-05-07 11:25:22 +0300 | 
| commit | 4c98f14a2491da2bc1a9d40fed1d1682c7ec5dd6 (patch) | |
| tree | 8142081775c27c8780fa0282a0273ee268e13b98 /contrib/restricted/boost/locale/src/shared/ios_prop.hpp | |
| parent | 40b86c68b431bb65d67bba51ef9159066a833b68 (diff) | |
Update contrib/restricted/boost/locale to 1.88.0
commit_hash:87b595328ea79c6ba38cb973580804486ca4a3ff
Diffstat (limited to 'contrib/restricted/boost/locale/src/shared/ios_prop.hpp')
| -rw-r--r-- | contrib/restricted/boost/locale/src/shared/ios_prop.hpp | 65 | 
1 files changed, 65 insertions, 0 deletions
diff --git a/contrib/restricted/boost/locale/src/shared/ios_prop.hpp b/contrib/restricted/boost/locale/src/shared/ios_prop.hpp new file mode 100644 index 00000000000..d8256592f79 --- /dev/null +++ b/contrib/restricted/boost/locale/src/shared/ios_prop.hpp @@ -0,0 +1,65 @@ +// +// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh) +// Copyright (c) 2022 Alexander Grund +// +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#ifndef BOOST_SRC_LOCALE_IOS_PROP_HPP +#define BOOST_SRC_LOCALE_IOS_PROP_HPP + +#include <boost/locale/config.hpp> +#include <boost/assert.hpp> +#include <ios> + +namespace boost { namespace locale { namespace impl { + +    template<typename Property> +    class BOOST_SYMBOL_VISIBLE ios_prop { +    public: +        static Property& get(std::ios_base& ios) +        { +            Property* result = get_impl(ios); +            return result ? *result : create(ios); +        } + +        static void global_init() { get_id(); } + +    private: +        static Property* get_impl(std::ios_base& ios) { return static_cast<Property*>(ios.pword(get_id())); } + +        static Property& create(std::ios_base& ios) +        { +            BOOST_ASSERT_MSG(!get_impl(ios), "Called create while the property already exists"); +            const int id = get_id(); +            ios.register_callback(callback, id); +            Property* value = new Property(); +            ios.pword(id) = value; +            return *value; +        } + +        static void callback(std::ios_base::event ev, std::ios_base& ios, int id) +        { +            Property* prop = get_impl(ios); +            if(!prop) +                return; +            switch(ev) { +                case std::ios_base::erase_event: +                    delete prop; +                    ios.pword(id) = nullptr; +                    break; +                case std::ios_base::copyfmt_event: ios.pword(id) = new Property(*prop); break; +                case std::ios_base::imbue_event: prop->on_imbue(); break; +                default: break; +            } +        } +        static int get_id() +        { +            static int id = std::ios_base::xalloc(); +            return id; +        } +    }; + +}}} // namespace boost::locale::impl + +#endif  | 
