Add skeleton support for CAtlStringW

svn path=/trunk/; revision=67579
This commit is contained in:
Ged Murphy 2015-05-06 21:31:40 +00:00
parent df3b279994
commit 41044145e2
3 changed files with 258 additions and 0 deletions

View file

@ -0,0 +1,126 @@
#ifndef __ATLSIMPSTR_H__
#define __ATLSIMPSTR_H__
#pragma once
#include <atlcore.h>
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<BaseType>::XCHAR XCHAR;
typedef typename ChTraitsBase<BaseType>::PXSTR PXSTR;
typedef typename ChTraitsBase<BaseType>::PCXSTR PCXSTR;
typedef typename ChTraitsBase<BaseType>::YCHAR YCHAR;
typedef typename ChTraitsBase<BaseType>::PYSTR PYSTR;
typedef typename ChTraitsBase<BaseType>::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<BaseType, !t_bMFCDLL>& strSrc)
{
CStringData* pSrcData = strSrc.GetData();
CStringData* pNewData = CloneData(pSrcData);
Attach(pNewData);
}
};
}
#endif

55
reactos/lib/atl/atlstr.h Normal file
View file

@ -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 <atlbase.h>
#include <cstringt.h>
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<wchar_t, StrTraitATL<wchar_t, ChTraitsCRT<wchar_t>>> CAtlStringW;
#else
typedef CStringT<wchar_t, StrTraitATL<wchar_t>> CAtlStringW;
#endif
#ifndef _AFX
typedef CAtlStringW CStringW;
#endif
} //namespace ATL
#endif

View file

@ -0,0 +1,77 @@
#ifndef __CSTRINGT_H__
#define __CSTRINGT_H__
#pragma once
#include <atlsimpstr.h>
#include <stddef.h>
#include <stdio.h>
#include <wchar.h>
namespace ATL
{
template< typename _CharType = wchar_t>
class ChTraitsCRT :
public ChTraitsBase<_CharType>
{
public:
};
namespace _CSTRING_IMPL_
{
template <typename _CharType, class StringTraits>
struct _MFCDLLTraitsCheck
{
const static bool c_bIsMFCDLLTraits = false;
};
}
template< typename BaseType, class StringTraits>
class CStringT :
public CSimpleStringT <BaseType, _CSTRING_IMPL_::_MFCDLLTraitsCheck<BaseType, StringTraits>::c_bIsMFCDLLTraits>
{
public:
typedef CSimpleStringT<BaseType, _CSTRING_IMPL_::_MFCDLLTraitsCheck<BaseType, StringTraits>::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