aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/restricted/boost/libs/locale/src/shared/ios_prop.hpp
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /contrib/restricted/boost/libs/locale/src/shared/ios_prop.hpp
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'contrib/restricted/boost/libs/locale/src/shared/ios_prop.hpp')
-rw-r--r--contrib/restricted/boost/libs/locale/src/shared/ios_prop.hpp109
1 files changed, 109 insertions, 0 deletions
diff --git a/contrib/restricted/boost/libs/locale/src/shared/ios_prop.hpp b/contrib/restricted/boost/libs/locale/src/shared/ios_prop.hpp
new file mode 100644
index 0000000000..0a820e126b
--- /dev/null
+++ b/contrib/restricted/boost/libs/locale/src/shared/ios_prop.hpp
@@ -0,0 +1,109 @@
+//
+// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
+//
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+#ifndef BOOST_SRC_LOCALE_IOS_PROP_HPP
+#define BOOST_SRC_LOCALE_IOS_PROP_HPP
+#include <ios>
+
+namespace boost {
+ namespace locale {
+ namespace impl {
+
+ template<typename Property>
+ class ios_prop {
+ public:
+ static void set(Property const &prop,std::ios_base &ios)
+ {
+ int id=get_id();
+ if(ios.pword(id)==0) {
+ ios.pword(id) = new Property(prop);
+ ios.register_callback(callback,id);
+ }
+ else if(ios.pword(id)==invalid) {
+ ios.pword(id) = new Property(prop);
+ }
+ else {
+ *static_cast<Property *>(ios.pword(id))=prop;
+ }
+ }
+
+ static Property &get(std::ios_base &ios)
+ {
+ int id=get_id();
+ if(!has(ios))
+ set(Property(),ios);
+ return *static_cast<Property *>(ios.pword(id));
+ }
+
+ static bool has(std::ios_base &ios)
+ {
+ int id=get_id();
+ if(ios.pword(id)==0 || ios.pword(id)==invalid)
+ return false;
+ return true;
+ }
+
+ static void unset(std::ios_base &ios)
+ {
+ if(has(ios)) {
+ int id=get_id();
+ Property *p=static_cast<Property *>(ios.pword(id));
+ delete p;
+ ios.pword(id)=invalid;
+ }
+ }
+ static void global_init()
+ {
+ get_id();
+ }
+ private:
+ static void * const invalid;
+
+ static void callback(std::ios_base::event ev,std::ios_base &ios,int id)
+ {
+ switch(ev) {
+ case std::ios_base::erase_event:
+ if(!has(ios))
+ break;
+ delete reinterpret_cast<Property *>(ios.pword(id));
+ break;
+ case std::ios_base::copyfmt_event:
+ if(ios.pword(id)==invalid || ios.pword(id)==0)
+ break;
+ ios.pword(id)=new Property(*reinterpret_cast<Property *>(ios.pword(id)));
+ break;
+ case std::ios_base::imbue_event:
+ if(ios.pword(id)==invalid || ios.pword(id)==0)
+ break;
+ reinterpret_cast<Property *>(ios.pword(id))->on_imbue();
+ break;
+
+ default: ;
+ }
+ }
+ static int get_id()
+ {
+ static int id = std::ios_base::xalloc();
+ return id;
+ }
+ };
+
+ template<typename Property>
+ void * const ios_prop<Property>::invalid = (void *)(-1);
+
+
+
+ }
+ }
+}
+
+
+
+#endif
+
+// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
+