From 41044145e2f1cb6924f273042d6700e042716fc0 Mon Sep 17 00:00:00 2001 From: Ged Murphy Date: Wed, 6 May 2015 21:31:40 +0000 Subject: [PATCH] [ATL] Add skeleton support for CAtlStringW svn path=/trunk/; revision=67579 --- reactos/lib/atl/atlsimpstr.h | 126 +++++++++++++++++++++++++++++++++++ reactos/lib/atl/atlstr.h | 55 +++++++++++++++ reactos/lib/atl/cstringt.h | 77 +++++++++++++++++++++ 3 files changed, 258 insertions(+) create mode 100644 reactos/lib/atl/atlsimpstr.h create mode 100644 reactos/lib/atl/atlstr.h create mode 100644 reactos/lib/atl/cstringt.h diff --git a/reactos/lib/atl/atlsimpstr.h b/reactos/lib/atl/atlsimpstr.h new file mode 100644 index 00000000000..98a6e516524 --- /dev/null +++ b/reactos/lib/atl/atlsimpstr.h @@ -0,0 +1,126 @@ +#ifndef __ATLSIMPSTR_H__ +#define __ATLSIMPSTR_H__ + +#pragma once + +#include + + +namespace ATL +{ + struct CStringData; + + __interface IAtlStringMgr + { + public: + + _Ret_maybenull_ _Post_writable_byte_size_(sizeof(CStringData) + nAllocLength*nCharSize) + CStringData* Allocate( + _In_ int nAllocLength, + _In_ int nCharSize) throw(); + + void Free(_Inout_ CStringData* pData) throw(); + + virtual _Ret_maybenull_ _Post_writable_byte_size_(sizeof(CStringData) + nAllocLength*nCharSize) + CStringData* Reallocate( + _Inout_ CStringData* pData, + _In_ int nAllocLength, + _In_ int nCharSize) throw(); + + CStringData* GetNilString() throw(); + + IAtlStringMgr* Clone() throw(); + }; + + struct CStringData + { + IAtlStringMgr* pStringMgr; + int nDataLength; + int nAllocLength; + long nRefs; + + void* data() throw() + { + return (this + 1); + } + + void AddRef() throw() + { + ATLASSERT(nRefs > 0); + _InterlockedIncrement(&nRefs); + } + + void Release() throw() + { + ATLASSERT(nRefs != 0); + + if (_InterlockedDecrement(&nRefs) <= 0) + { + pStringMgr->Free(this); + } + } + }; + + template< typename BaseType = char > + class ChTraitsBase + { + public: + typedef char XCHAR; + typedef LPSTR PXSTR; + typedef LPCSTR PCXSTR; + typedef wchar_t YCHAR; + typedef LPWSTR PYSTR; + typedef LPCWSTR PCYSTR; + }; + + template<> + class ChTraitsBase< wchar_t > + { + public: + typedef wchar_t XCHAR; + typedef LPWSTR PXSTR; + typedef LPCWSTR PCXSTR; + typedef char YCHAR; + typedef LPSTR PYSTR; + typedef LPCSTR PCYSTR; + }; + + + + template< typename BaseType, bool t_bMFCDLL = false> + class CSimpleStringT + { + public: + typedef typename ChTraitsBase::XCHAR XCHAR; + typedef typename ChTraitsBase::PXSTR PXSTR; + typedef typename ChTraitsBase::PCXSTR PCXSTR; + typedef typename ChTraitsBase::YCHAR YCHAR; + typedef typename ChTraitsBase::PYSTR PYSTR; + typedef typename ChTraitsBase::PCYSTR PCYSTR; + + public: + explicit CSimpleStringT(_Inout_ IAtlStringMgr* pStringMgr) + { + ATLENSURE(pStringMgr != NULL); + CStringData* pData = pStringMgr->GetNilString(); + Attach(pData); + } + + CSimpleStringT(_In_ const CSimpleStringT& strSrc) + { + CStringData* pSrcData = strSrc.GetData(); + CStringData* pNewData = CloneData(pSrcData); + Attach(pNewData); + } + + CSimpleStringT(_In_ const CSimpleStringT& strSrc) + { + CStringData* pSrcData = strSrc.GetData(); + CStringData* pNewData = CloneData(pSrcData); + Attach(pNewData); + } + + }; +} + +#endif \ No newline at end of file diff --git a/reactos/lib/atl/atlstr.h b/reactos/lib/atl/atlstr.h new file mode 100644 index 00000000000..7764e38ca41 --- /dev/null +++ b/reactos/lib/atl/atlstr.h @@ -0,0 +1,55 @@ +#ifndef __ATLSTR_H__ +#define __ATLSTR_H__ + +#pragma once + +#ifndef __cplusplus + #error ATL requires C++ compilation (use a .cpp suffix) +#endif + +#include +#include + +namespace ATL +{ + template< typename _BaseType = char, class StringIterator = ChTraitsOS<_BaseType>> + class StrTraitATL : + public StringIterator + { + public: + static HINSTANCE FindStringResourceInstance(_In_ UINT nID) throw() + { + return(AtlFindStringResourceInstance(nID)); + } + + static IAtlStringMgr* GetDefaultManager() throw() + { + return CAtlStringMgr::GetInstance(); + } + }; + + + template< typename _CharType = wchar_t> + class ChTraitsOS : + public ChTraitsBase<_CharType> + { + protected: + + public: + + }; + +#ifndef _ATL_CSTRING_NO_CRT + typedef CStringT>> CAtlStringW; +#else + typedef CStringT> CAtlStringW; +#endif + +#ifndef _AFX + typedef CAtlStringW CStringW; +#endif + + +} //namespace ATL + +#endif \ No newline at end of file diff --git a/reactos/lib/atl/cstringt.h b/reactos/lib/atl/cstringt.h new file mode 100644 index 00000000000..f72dfb54738 --- /dev/null +++ b/reactos/lib/atl/cstringt.h @@ -0,0 +1,77 @@ +#ifndef __CSTRINGT_H__ +#define __CSTRINGT_H__ + +#pragma once + +#include +#include + +#include +#include + + +namespace ATL +{ + + template< typename _CharType = wchar_t> + class ChTraitsCRT : + public ChTraitsBase<_CharType> + { + public: + + }; + + + + namespace _CSTRING_IMPL_ + { + template + struct _MFCDLLTraitsCheck + { + const static bool c_bIsMFCDLLTraits = false; + }; + } + + template< typename BaseType, class StringTraits> + class CStringT : + public CSimpleStringT ::c_bIsMFCDLLTraits> + { + public: + typedef CSimpleStringT::c_bIsMFCDLLTraits> CThisSimpleString; + typedef StringTraits StrTraits; + typedef typename CThisSimpleString::XCHAR XCHAR; + typedef typename CThisSimpleString::PXSTR PXSTR; + typedef typename CThisSimpleString::PCXSTR PCXSTR; + typedef typename CThisSimpleString::YCHAR YCHAR; + typedef typename CThisSimpleString::PYSTR PYSTR; + typedef typename CThisSimpleString::PCYSTR PCYSTR; + + public: + CStringT() throw() : + CThisSimpleString(StringTraits::GetDefaultManager()) + { + } + explicit CStringT( _In_ IAtlStringMgr* pStringMgr) throw() : + CThisSimpleString(pStringMgr) + { + } + + CStringT(_In_ const VARIANT& varSrc); + CStringT( + _In_ const VARIANT& varSrc, + _In_ IAtlStringMgr* pStringMgr); + + static void __cdecl Construct(_In_ CStringT* pString) + { + new(pString)CStringT; + } + + CStringT(_In_ const CStringT& strSrc) : + CThisSimpleString(strSrc) + { + } + }; + +} //namespace ATL + +#endif \ No newline at end of file