📄 guid.hpp
字号:
{
return stlsoft_ns_qual(c_str_data)(g.get());
}
inline size_t c_str_len(guid const &g)
{
return stlsoft_ns_qual(c_str_len)(g.get());
}
#if 0
inline size_t c_str_size_a(guid const &g)
{
return stlsoft_ns_qual(c_str_size_a)(g.get());
}
#endif /* 0 */
#if 0
inline size_t c_str_size_w(guid const &g)
{
return stlsoft_ns_qual(c_str_size_w)(g.get());
}
#endif /* 0 */
#if 0
inline size_t c_str_size(guid const &g)
{
return stlsoft_ns_qual(c_str_size)(g.get());
}
#endif /* 0 */
/* /////////////////////////////////////////////////////////////////////////
* Operators
*/
inline cs_bool_t operator ==(guid const &lhs, guid const &rhs)
{
return lhs.equal(rhs);
}
inline cs_bool_t operator !=(guid const &lhs, guid const &rhs)
{
return !operator ==(lhs, rhs);
}
inline cs_bool_t operator ==(guid const &lhs, GUID const &rhs)
{
return lhs.equal(rhs);
}
inline cs_bool_t operator !=(guid const &lhs, GUID const &rhs)
{
return !operator ==(lhs, rhs);
}
inline cs_bool_t operator ==(GUID const &lhs, guid const &rhs)
{
return rhs.equal(lhs);
}
inline cs_bool_t operator !=(GUID const &lhs, guid const &rhs)
{
return !operator ==(lhs, rhs);
}
////////////////////////////////////////////////////////////////////////////
// Unit-testing
#ifdef STLSOFT_UNITTEST
# include "./unittest/guid_unittest_.h"
#endif /* STLSOFT_UNITTEST */
/* /////////////////////////////////////////////////////////////////////////
* Implementation
*/
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
inline guid::guid()
{
HRESULT hr = ::CoCreateGuid(&m_guid);
if(FAILED(hr))
{
#ifdef STLSOFT_CF_EXCEPTION_SUPPORT
throw com_exception("Could not allocate GUID", hr);
#else /* ? STLSOFT_CF_EXCEPTION_SUPPORT */
m_guid = GUID_NULL;
#endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
}
}
inline /* ss_explicit_k */ guid::guid(cs_char_a_t const *s)
{
OLECHAR osz[1 + COMSTL_CCH_GUID];
HRESULT hr = S_OK;
switch(::MultiByteToWideChar(0, 0, s, -1, &osz[0], 1 + COMSTL_CCH_GUID))
{
case 1 + COMSTL_CCH_GUID:
osz[COMSTL_CCH_GUID] = L'\0';
hr = ::CLSIDFromString(osz, &m_guid);
break;
default:
if(S_OK == (hr = HRESULT_FROM_WIN32(::GetLastError())))
{
hr = E_INVALIDARG;
}
break;
}
if(FAILED(hr))
{
#ifdef STLSOFT_CF_EXCEPTION_SUPPORT
throw com_exception("Could not convert string to valid GUID", hr);
#else /* ? STLSOFT_CF_EXCEPTION_SUPPORT */
m_guid = GUID_NULL;
#endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
}
}
inline /* ss_explicit_k */ guid::guid(cs_char_w_t const *s)
{
HRESULT hr = ::CLSIDFromString(const_cast<LPOLESTR>(s), &m_guid);
if(FAILED(hr))
{
#ifdef STLSOFT_CF_EXCEPTION_SUPPORT
throw com_exception("Could not convert string to valid GUID", hr);
#else /* ? STLSOFT_CF_EXCEPTION_SUPPORT */
m_guid = GUID_NULL;
#endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
}
}
inline guid::guid(GUID const &g)
: m_guid(g)
{}
inline guid::guid(guid const &rhs)
: m_guid(rhs.m_guid)
{}
inline guid &guid::operator =(guid const &rhs)
{
m_guid = rhs.m_guid;
return *this;
}
inline guid &guid::operator =(cs_char_a_t const *s)
{
guid t(s);
t.swap(*this);
return *this;
}
inline guid &guid::operator =(cs_char_w_t const *s)
{
guid t(s);
t.swap(*this);
return *this;
}
inline guid &guid::operator =(GUID const &g)
{
guid t(g);
t.swap(*this);
return *this;
}
inline GUID const &guid::get() const
{
return m_guid;
}
inline cs_bool_t guid::equal(class_type const &rhs) const
{
return 0 != IsEqualGUID(m_guid, rhs.m_guid);
}
inline cs_bool_t guid::equal(GUID const &rhs) const
{
return 0 != IsEqualGUID(m_guid, rhs);
}
inline void guid::swap(guid::class_type &rhs) stlsoft_throw_0()
{
stlsoft_ns_qual(std_swap)(m_guid, rhs.m_guid);
}
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/* ////////////////////////////////////////////////////////////////////// */
#ifndef _COMSTL_NO_NAMESPACE
# if defined(_STLSOFT_NO_NAMESPACE) || \
defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
} // namespace comstl
# else
} // namespace stlsoft::comstl_project
} // namespace stlsoft
# endif /* _STLSOFT_NO_NAMESPACE */
#endif /* !_COMSTL_NO_NAMESPACE */
/* /////////////////////////////////////////////////////////////////////////
* Namespace
*
* The string access shims exist either in the stlsoft namespace, or in the
* global namespace. This is required by the lookup rules.
*
*/
#ifndef _COMSTL_NO_NAMESPACE
# if !defined(_STLSOFT_NO_NAMESPACE) && \
!defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
namespace stlsoft
{
# else /* ? _STLSOFT_NO_NAMESPACE */
/* There is no stlsoft namespace, so must define in the global namespace */
# endif /* !_STLSOFT_NO_NAMESPACE */
using ::comstl::c_str_ptr_null_a;
using ::comstl::c_str_ptr_null_w;
using ::comstl::c_str_ptr_null_o;
using ::comstl::c_str_ptr_null;
using ::comstl::c_str_ptr_a;
using ::comstl::c_str_ptr_w;
using ::comstl::c_str_ptr_o;
using ::comstl::c_str_ptr;
using ::comstl::c_str_data_a;
using ::comstl::c_str_data_w;
using ::comstl::c_str_data_o;
using ::comstl::c_str_data;
using ::comstl::c_str_len_a;
using ::comstl::c_str_len_w;
using ::comstl::c_str_len_o;
using ::comstl::c_str_len;
#if 0
using ::comstl::c_str_size_a;
using ::comstl::c_str_size_w;
using ::comstl::c_str_size_o;
using ::comstl::c_str_size;
#endif /* 0 */
# if !defined(_STLSOFT_NO_NAMESPACE) && \
!defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
} // namespace stlsoft
# else /* ? _STLSOFT_NO_NAMESPACE */
/* There is no stlsoft namespace, so must define in the global namespace */
# endif /* !_STLSOFT_NO_NAMESPACE */
#endif /* !_COMSTL_NO_NAMESPACE */
/* ////////////////////////////////////////////////////////////////////// */
#endif /* !COMSTL_INCL_HPP_COMSTL_GUID */
/* ////////////////////////////////////////////////////////////////////// */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -