File indexing completed on 2026-04-05 08:04:37
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_INTERPROCESS_DETAIL_CHAR_WCHAR_HOLDER_HPP
0012 #define BOOST_INTERPROCESS_DETAIL_CHAR_WCHAR_HOLDER_HPP
0013
0014 #ifndef BOOST_CONFIG_HPP
0015 # include <boost/config.hpp>
0016 #endif
0017 0018 ">#
0019 #if defined(BOOST_HAS_PRAGMA_ONCE)
0020 # pragma once
0021 #endif
0022
0023 #include <boost/interprocess/detail/config_begin.hpp>
0024 #include <boost/interprocess/detail/workaround.hpp>
0025
0026 #include <cwchar>
0027 #include <cstring>
0028
0029 namespace boost {
0030 namespace interprocess {
0031
0032 class char_wchar_holder
0033 {
0034 public:
0035 char_wchar_holder()
0036 : m_str(), m_is_wide()
0037 {
0038 m_str.n = 0;
0039 }
0040
0041 char_wchar_holder(const char *nstr)
0042 : m_str(), m_is_wide()
0043 {
0044 m_str.n = new char [std::strlen(nstr)+1];
0045 std::strcpy(m_str.n, nstr);
0046 }
0047
0048 char_wchar_holder(const wchar_t *wstr)
0049 : m_str(), m_is_wide(true)
0050 {
0051 m_str.w = new wchar_t [std::wcslen(wstr)+1];
0052 std::wcscpy(m_str.w, wstr);
0053 }
0054
0055 char_wchar_holder& operator=(const char *nstr)
0056 {
0057 char *tmp = new char [std::strlen(nstr)+1];
0058 this->delete_mem();
0059 m_str.n = tmp;
0060 std::strcpy(m_str.n, nstr);
0061 m_is_wide = false;
0062 return *this;
0063 }
0064
0065 char_wchar_holder& operator=(const wchar_t *wstr)
0066 {
0067 wchar_t *tmp = new wchar_t [std::wcslen(wstr)+1];
0068 this->delete_mem();
0069 m_str.w = tmp;
0070 std::wcscpy(m_str.w, wstr);
0071 m_is_wide = true;
0072 return *this;
0073 }
0074
0075 char_wchar_holder& operator=(const char_wchar_holder &other)
0076 {
0077 if (other.m_is_wide)
0078 *this = other.getw();
0079 else
0080 *this = other.getn();
0081 return *this;
0082 }
0083
0084 ~char_wchar_holder()
0085 {
0086 this->delete_mem();
0087 }
0088
0089 wchar_t *getw() const
0090 { return m_is_wide ? m_str.w : 0; }
0091
0092 char *getn() const
0093 { return !m_is_wide ? m_str.n : 0; }
0094
0095 void swap(char_wchar_holder& other)
0096 {
0097 char_wchar tmp;
0098 std::memcpy(&tmp, &m_str, sizeof(char_wchar));
0099 std::memcpy(&m_str, &other.m_str, sizeof(char_wchar));
0100 std::memcpy(&other.m_str, &tmp, sizeof(char_wchar));
0101
0102 bool b_tmp(m_is_wide);
0103 m_is_wide = other.m_is_wide;
0104 other.m_is_wide = b_tmp;
0105 }
0106
0107 private:
0108
0109 void delete_mem()
0110 {
0111 if(m_is_wide)
0112 delete [] m_str.w;
0113 else
0114 delete [] m_str.n;
0115 }
0116
0117 union char_wchar
0118 {
0119 char *n;
0120 wchar_t *w;
0121 } m_str;
0122 bool m_is_wide;
0123 };
0124
0125 }
0126 }
0127
0128 #include <boost/interprocess/detail/config_end.hpp>
0129
0130 #endif