commit 2025-10-08 20:43 add ZtCCharType in ZCppMain/ZMainHead.H

This commit is contained in:
2025-10-08 22:43:47 +09:00
parent 443ebf4fd1
commit 6974c13d16
4 changed files with 182 additions and 14 deletions

View File

@ -793,21 +793,44 @@ namespace ZNsMain
//////////////////////////////////////////////////////////////////////*/
namespace ZNsIn
{
const int CI_Char1Byte = 1;
const int CI_Char2Byte = 2;
const int CI_Char4Byte = 4;
}/*
namespace ZNsIn*/
template<int TTyiByteSize> class ZtCCharIntBySize
{
public: typedef ZTypLong TypeInt;
};/*
template<int TTyiByteSize> class ZtCCharIntBySize*/
template<> class ZtCCharIntBySize<ZNsIn::CI_Char1Byte>
{ public: typedef ZTypInt TypeInt; };
template<> class ZtCCharIntBySize<ZNsIn::CI_Char2Byte>
{ public: typedef ZTypInt TypeInt; };
template<> class ZtCCharIntBySize<ZNsIn::CI_Char4Byte>
{ public: typedef ZTypLong TypeInt; };
template<typename TTypChar> class ZtCCharInt
{
public: typedef int TypeInt;
public: typedef typename ZtCCharIntBySize<sizeof(TTypChar)>::TypeInte TypeInt;
};/*
template<typename TTypChar> class ZtCCharInt*/
template<> class ZtCCharInt<char>
{
public: typedef int TypeInt;
public: typedef typename ZtCCharIntBySize<sizeof(char) >::TypeInt TypeInt;
};/*
template<> class ZtCCharInt<char>*/
template<> class ZtCCharInt<wchar_t>
{
public: typedef int TypeInt;
public: typedef typename ZtCCharIntBySize<sizeof(wchar_t) >::TypeInt TypeInt;
};/*
template<> class ZtCCharInt<wchar_t>*/
@ -7321,6 +7344,83 @@ namespace ZNsMain
template<> string& ZftMakeStr(string& ARR_SaveCStr, const ZCCharView& AR_View)*/
/*//////////////////////////////////////////////////////////////////////////////////////
■ template<typename TTypString> class ZtCCharType
stl 의 string 나 wstring 같은 문자열 클래스를 인자로 받는 템플릿이 있다고 할 때, 해당
자열 클래스가 다루는 문자형이 char 인지 wchar_t 인지 알기가 약간 번거로운데, 이를 쉽
게 하기 위해서, 특히 ZtCStringBase 와 통일적으로 일관성있게 알 수 있도록
template<> class ZtCCharType
cf) typedef ZtCCharType::TypeChar TypeChar;
을 설계한다. 물론
string::traits_type::char_type
string::traits_type::int_type
을 사용하면 관련 자료형을 알 수 있기는 한데, 혹시나 나중에 string 보다 간단한 문자열
클래스가 있을 경우를 대비하는 의미에서라도 이렇게 한 번 해보자.
-- 2025-10-08 21:24
//////////////////////////////////////////////////////////////////////////////////////*/
template<typename TTypString> class ZtCCharType
{
public:
typedef typename TTypString::
traits_type::char_type /*++*/ TypeChar;
typedef TTypString /*+++++++++*/ TypeCStr;
public:
typedef typename
ZtCCharInt<TypeChar>::TypeInt TypeInt ;
public:
static const int CI_ByteSize = sizeof(TypeChar);
public:
typedef TypeChar char_type ; // for stl
typedef TypeInt int_type ; // for stl
public:
};/*
template<typename TTypString> class ZtCCharType*/
template<> class ZtCCharType<std::string>
{
public:
typedef std::string /*+++++++*/ TypeCStr;
typedef char /*+++++++++++++++*/ TypeChar;
public:
typedef typename
ZtCCharInt<char>::TypeInt TypeInt ;
public:
static const int CI_ByteSize = sizeof(TypeChar);
public:
typedef TypeChar char_type ; // for stl
typedef TypeInt int_type ; // for stl
public:
};/*
template<> class ZtCCharType<std::string>*/
template<> class ZtCCharType<std::wstring>
{
public:
typedef std::wstring /*+++++++*/ TypeCStr;
typedef wchar_t /*+++++++++++*/ TypeChar;
public:
typedef typename
ZtCCharInt<wchar_t>::TypeInt TypeInt ;
public:
static const int CI_ByteSize = sizeof(TypeChar);
public:
typedef TypeChar char_type ; // for stl
typedef TypeInt int_type ; // for stl
public:
};/*
template<> class ZtCCharType<std::wstring>*/
namespace ZNsView
{

View File

@ -7399,7 +7399,7 @@ namespace ZNsMain
ZTypLength VL_ReadSize = 0 ;
ZTypCPChar VP_CopyStart =
const_cast<ZTypPChar>(ARR_SaveCStr.c_str())+VL_PrevSize ;
const_cast<ZTypPChar>(ARR_SaveCStr.data())+VL_PrevSize ;
if((VL_ReadSize = read(AH_FileDesc, VP_CopyStart, VL_LastPos))<0)
{
@ -7446,7 +7446,7 @@ namespace ZNsMain
::SetFilePointer(VH_File, AL_Offset, NULL, FILE_BEGIN);
ZTypCPChar VP_CopyStart =
const_cast<ZTypPChar>(ARR_SaveCStr.c_str())+VL_PrevSize ;
const_cast<ZTypPChar>(ARR_SaveCStr.data())+VL_PrevSize ;
if(::ReadFile(VH_File, (LPVOID)VP_CopyStart, dwRead, &dwRead2, NULL)==FALSE)
{

View File

@ -131,6 +131,40 @@ namespace ZNsMain
class ZtCStringBase; /*::::::::::::::::::::::::::::::::::::::::::::*/
template //////////////////////////////////////////////////////////////////
<
template<typename, typename, typename, typename>
class ZtCStringBase,
typename TTypCh , typename TAlloc,
typename TAllocSize, typename TTypeString
>
class ZtCCharType
< ZtCStringBase<TTypCh, TAlloc, TAllocSize, TTypeString> >
/*#######################################################################*/
{
public:
typedef ZtCStringBase ///////////////////////////
<
TTypCh, TAlloc, TAllocSize, TTypeString
>
/*/////////////////////////////////*/ TypeCStr ;
public:
typedef TTypCh /*//////////////////*/ TypeChar ;
public:
static const int CI_ByteSize = sizeof(TypeChar) ;
public:
typedef typename
ZtCCharInt<TypeChar>::TypeInt TypeInt ;
public:
typedef TypeChar char_type ; // for stl
typedef TypeInt int_type ; // for stl
public:
};/*
class ZtCCharType /*#####################################################*/
namespace ZNsType
{
@ -258,12 +292,11 @@ namespace ZNsMain
{
public:
typedef typename TTypeString::template ZtCHelpBase< ///////
ZtCStringBase
typedef typename TTypeString::template ZtCHelpBase ///////////
<
TTypCh, TAlloc, TAllocSize, TTypeString
ZtCStringBase<TTypCh, TAlloc, TAllocSize, TTypeString>
>
/*////////*/ > TypeHelpBase; /////////////////////////////
TypeHelpBase; ////////////////////////////////////////////////
typedef typename TypeHelpBase::ZCStringList ZCStringList ;
@ -298,6 +331,10 @@ namespace ZNsMain
typedef TAlloc TypeAlloc ;
typedef ZCStringList TypeList ;
public:
typedef ZNsMain::ZtCCharType<ZtCStringBase> ZCCharType ;
typedef ZNsMain::ZtCCharType<ZtCStringBase> traits_type;
typedef typename ZCCharType::TypeInt TypeCharInt;
public:
enum EWriteFile // WriteFile() 에서 사용한다.
{

View File

@ -14,8 +14,19 @@ namespace ZNsMain
namespace ZNsExam
{
typedef ZtCStringBase<char> CStringBase;
typedef CStringBase::ZCCharView ZCCharView ;
typedef ZtCStringBase<char> ZCStringBase ;
typedef ZtCStringBase<wchar_t> ZCStringBaseW ;
typedef ZCStringBase::ZCCharView ZCCharView ;
typedef ZtCCharType<ZCStringBase> ZCCharType ;
typedef ZtCCharType<ZCStringBaseW> ZCCharTypeW ;
typedef ZCCharType ::TypeChar TypeChar ;
typedef ZCCharTypeW::TypeChar TypeCharW ;
typedef ZCCharType ::TypeInt TypeCharInt ;
typedef ZCCharTypeW::TypeInt TypeCharIntW ;
const int CI_ByteSize = ZCCharType ::CI_ByteSize ;
const int CI_ByteSizeW= ZCCharTypeW::CI_ByteSize ;
template<typename TDummy=void*> class ZtCExamCStringBase_000
@ -24,9 +35,29 @@ namespace ZNsMain
static int Main(int AI_ArgCnt=0, char* APP_ArgVal[]=0)
{
cout<<"# TypeChar ="<<typeid(TypeChar ).name()<<endl;
cout<<"# TypeCharW ="<<typeid(TypeCharW ).name()<<endl;
cout<<"# TypeCharInt ="<<typeid(TypeCharInt ).name()<<endl;
cout<<"# TypeCharIntW="<<typeid(TypeCharIntW).name()<<endl;
cout<<"# CI_ByteSize ="<<CI_ByteSize <<endl;
cout<<"# CI_ByteSizeW="<<CI_ByteSizeW <<endl;
cout<<"# ZCStringBase ::TypeCharInt="<<typeid(ZCStringBase ::TypeCharInt).name()<<endl;
cout<<"# ZCStringBaseW::TypeCharInt="<<typeid(ZCStringBaseW::TypeCharInt).name()<<endl;
cout<<"# ZCStringBase ::traits_type::char_type="<<typeid(ZCStringBase ::traits_type::char_type).name()<<endl;
cout<<"# ZCStringBaseW::traits_type::char_type="<<typeid(ZCStringBaseW::traits_type::char_type).name()<<endl;
cout<<"# ZCStringBase ::traits_type::int_type ="<<typeid(ZCStringBase ::traits_type::int_type ).name()<<endl;
cout<<"# ZCStringBaseW::traits_type::int_type ="<<typeid(ZCStringBaseW::traits_type::int_type ).name()<<endl;
cout<<"# ZCStringBase ::traits_type="<<typeid(ZCStringBase ::traits_type).name()<<endl;
cout<<"# ZCStringBaseW::traits_type="<<typeid(ZCStringBaseW::traits_type).name()<<endl;
cout<<"*****************************************************"<<endl;
const ZCCharView CO_ZCCharView("1234AA5678AA90abcAAss");
CStringBase VO_ZCStringStd(CO_ZCCharView);
ZCStringBase VO_ZCStringStd(CO_ZCCharView);
cout<<"# "<<VO_ZCStringStd<<endl;
cout<<"* after Replace('12', '***')"<<endl;