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