commit 2025-10-08 09:48 add ZtCCharInt in ZCppMain/ZMainHead.H

This commit is contained in:
2025-10-08 09:48:42 +09:00
parent 6a5b24e62c
commit ff8b9667d9
3 changed files with 132 additions and 36 deletions

View File

@ -781,6 +781,37 @@ namespace ZNsMain
namespace ZNsEnum*/
/*//////////////////////////////////////////////////////////////////////
■ ZtCCharInt 는 문자형 TTypChar 을 충분히 표현할 수 있는 정수형을 정의
cf) 'char 의 int 확장에 따른 문제의 코드'
cf) ZtCCharInt<char>::TypeInt, ZtCCharInt<wchar_t>::TypeInt
-- 2025-10-08 09:37
//////////////////////////////////////////////////////////////////////*/
template<typename TTypChar> class ZtCCharInt
{
public: typedef int TypeInt;
};/*
template<typename TTypChar> class ZtCCharInt*/
template<> class ZtCCharInt<char>
{
public: typedef int TypeInt;
};/*
template<> class ZtCCharInt<char>*/
template<> class ZtCCharInt<wchar_t>
{
public: typedef int TypeInt;
};/*
template<> class ZtCCharInt<wchar_t>*/
template<typename TTyChar, typename TTyiLength> ZTypIntE ZftGetCompareCode
(
const TTyChar* ZApcLeft , TTyiLength ZAiLenLeft ,
@ -791,13 +822,15 @@ namespace ZNsMain
if(ZAiLenLeft<1 && zAiLenRight<1)
return ZNsEnum::ZECompareResult_Equal;
typedef typename ZtCCharInt<TTyChar>::TypeInt TypeInt;
TTyiLength ViLoopCnt =
(ZAiLenLeft<=zAiLenRight ? ZAiLenLeft : zAiLenRight);
__for0(TTyiLength, i, ViLoopCnt)
{
if(ZApcLeft[i] > ZApcRight[i]) return ZNsEnum::ZECompareResult_More;
if(ZApcLeft[i] < ZApcRight[i]) return ZNsEnum::ZECompareResult_Less;
if(TypeInt(ZApcLeft[i]) > TypeInt(ZApcRight[i])) return ZNsEnum::ZECompareResult_More;
if(TypeInt(ZApcLeft[i]) < TypeInt(ZApcRight[i])) return ZNsEnum::ZECompareResult_Less;
}/*
__for0(TTyiLength, i, ViLoopCnt)*/
@ -6981,58 +7014,92 @@ namespace ZNsMain
public :
typedef TTypeChar TypeChar ;
typedef TTypeLength TypeLength ;
typedef TTypeLength TypeSize ;
public:
typedef const TTypeChar TypeCharC ;
typedef const TTypeChar* TypeCharCP ;
private:
TypeChar* mp_TypeChar ;
TypeLength ml_TypeLength;
TypeChar* mp_TypeChar ;
TypeSize ml_TypeSize ;
public :
ZtCChars()
{
mp_TypeChar =0;
ml_TypeLength=0;
mp_TypeChar = 0;
ml_TypeSize = 0;
}/*
ZtCChars()*/
ZtCChars(TypeCharC* APC_TypeChar)
{
mp_TypeChar =
const_cast<TypeChar*> (APC_TypeChar);
ml_TypeLength = ZftGetLength(mp_TypeChar );
const_cast<TypeChar*>(APC_TypeChar);
ml_TypeSize = ZftGetLength(mp_TypeChar);
}/*
ZtCChars(TypeCharC* APC_TypeChar)*/
ZtCChars(TypeCharC* APC_TypeChar, TypeLength AL_Length)
ZtCChars(TypeCharC* APC_TypeChar, TypeSize AL_Length)
{
mp_TypeChar = const_cast
<TypeChar*>(APC_TypeChar) ;
ml_TypeLength= AL_Length ;
mp_TypeChar = const_cast
<TypeChar*>(APC_TypeChar);
ml_TypeSize = AL_Length ;
}/*
ZtCChars(TypeCharC* APC_TypeChar, TypeLength AL_Length)*/
ZtCChars(TypeCharC* APC_TypeChar, TypeSize AL_Length)*/
ZtCChars(const ZtCChars& rhs)
{
mp_TypeChar = const_cast<ZtCChars&>(rhs).mp_TypeChar ;
ml_TypeSize = const_cast<ZtCChars&>(rhs).ml_TypeSize ;
}/*
ZtCChars(const ZtCChars& rhs)*/
ZtCChars(ZtCChars& rhs)
{
mp_TypeChar = rhs.mp_TypeChar ;
ml_TypeSize = rhs.ml_TypeSize ;
}/*
ZtCChars(ZtCChars& rhs)*/
ZtCChars& operator=(const ZtCChars& rhs)
{
mp_TypeChar = const_cast<ZtCChars&>(rhs).mp_TypeChar ;
ml_TypeSize = const_cast<ZtCChars&>(rhs).ml_TypeSize ;
return *this;
}/*
ZtCChars& operator=(const ZtCChars& rhs)*/
ZtCChars& operator=(ZtCChars& rhs)
{
mp_TypeChar = rhs.mp_TypeChar ;
ml_TypeSize = rhs.ml_TypeSize ;
return *this;
}/*
ZtCChars& operator=(ZtCChars& rhs)*/
void Init()
{
mp_TypeChar = 0;
ml_TypeLength= 0;
mp_TypeChar = 0;
ml_TypeSize = 0;
}/*
void Init()*/
void Init(TypeCharC* APC_TypeChar)
{
mp_TypeChar =
const_cast<TypeChar*> (APC_TypeChar);
ml_TypeLength= ZftGetLength(mp_TypeChar );
mp_TypeChar =
const_cast<TypeChar*>(APC_TypeChar);
ml_TypeSize = ZftGetLength(mp_TypeChar);
}/*
void Init(TypeCharC* APC_TypeChar)*/
void Init(TypeCharC* APC_TypeChar, TypeLength AL_Length)
{
mp_TypeChar =const_cast
mp_TypeChar = const_cast
<TypeChar*>(APC_TypeChar) ;
ml_TypeLength=AL_Length ;
ml_TypeSize = AL_Length ;
}/*
void Init(TypeCharC* APC_TypeChar, TypeLength AL_Length)*/
@ -7045,13 +7112,13 @@ namespace ZNsMain
void InitLength(TypeLength AL_Length)
{
ml_TypeLength=AL_Length;
ml_TypeSize=AL_Length;
}/*
void InitLength(TypeLength AL_Length)*/
TypeChar* data() {return mp_TypeChar ;}
TypeCharC* data() const{return mp_TypeChar ;}
TypeLength size() const{return ml_TypeLength;}
TypeChar* data() {return mp_TypeChar ;}
TypeCharC* data() const{return mp_TypeChar ;}
TypeLength size() const{return ml_TypeSize ;}
ZtCChars& operator+=(TypeLength AI_MovePos)
{
@ -7076,9 +7143,9 @@ namespace ZNsMain
TypeLength VL_Index = 0;
TypeLength VL_Loop = /*::::::::::::::::::::::::::*/
(
ml_TypeLength <= rhs.ml_TypeLength ?
this->ml_TypeLength :
rhs. ml_TypeLength
ml_TypeSize <= rhs.ml_TypeSize ?
this->ml_TypeSize :
rhs. ml_TypeSize
) ;
/*::::::::::::::::::::::::::::::::::::::::::::::::*/
@ -7102,7 +7169,7 @@ namespace ZNsMain
}/*
while(VL_Index<VL_Loop)*/
return ml_TypeLength-rhs.ml_TypeLength;
return ml_TypeSize-rhs.ml_TypeSize;
}/*
int operator-(const ZtCChars& rhs) const*/
@ -7114,8 +7181,8 @@ namespace ZNsMain
ZtCChars& MoveChar(TypeLength AI_MovePos)
{
mp_TypeChar += AI_MovePos ;
ml_TypeLength -= AI_MovePos ;
mp_TypeChar += AI_MovePos ;
ml_TypeSize -= AI_MovePos ;
return *this;
}/*
@ -7126,7 +7193,7 @@ namespace ZNsMain
{
ZTycIntI CI_IntByte = sizeof(ZTypIntI);
ZTycIntI CI_SearchSize =
(ml_TypeLength<CI_IntByte ? ml_TypeLength : CI_IntByte) ;
(ml_TypeSize<CI_IntByte ? ml_TypeSize : CI_IntByte) ;
ZTypIntI VI_Result = 0 ;
ZTypIntI VI_TempInt = 1 ;
@ -7160,7 +7227,7 @@ namespace ZNsMain
{
ZTycIntI CI_IntByte = sizeof(ZTypIntL);
ZTycIntI CI_SearchSize =
(ml_TypeLength<CI_IntByte ? ml_TypeLength : CI_IntByte) ;
(ml_TypeSize<CI_IntByte ? ml_TypeSize : CI_IntByte) ;
ZTypIntL VI_Result = 0 ;
ZTypIntL VI_TempInt = 1 ;
@ -7194,7 +7261,7 @@ namespace ZNsMain
{
ZTycIntI CI_IntByte = sizeof(ZTypIntLL);
ZTycIntI CI_SearchSize =
(ml_TypeLength<CI_IntByte ? ml_TypeLength : CI_IntByte) ;
(ml_TypeSize<CI_IntByte ? ml_TypeSize : CI_IntByte) ;
ZTypIntLL VI_Result = 0 ;
ZTypIntLL VI_TempInt = 1 ;
@ -8345,6 +8412,35 @@ namespace ZNsCPP */
-- 2025-08-25 00:56
■ 'char 의 int 확장에 따른 문제의 코드'
아래 함수에서
int ZtCMainChars<>::Minus(TypeCharC*, TypeCharC*, TypeLength, TypeLength)
return 문을
return VC_Minus; // VC_Minus 는 *(VP_Left-1)-*(VP_Right-1)
에서
return int(*(VP_Left-1))-int(*(VP_Right-1));
로 고쳤다. 컴파일러에 따라, 음수 char 을 int 로 확장하면 양수(+)가 될 수 있는 것이다. 이
것을 언제 알았냐면, LG CNS 에서 충전기 프로젝트를 할 때다. 그때 ELDK 4.0 tool chain 의
컴파일러를 사용했는데, NsUtility::CLoadSimUrlConfig_T<> 으로 설정 파일을 읽어들일 때, 자
꾸 몇몇 설정값을 인식하지 못하고 있었다. CLoadSimUrlConfig_T<> 은 ns1.cppschool.com 과
ns2.cppschool.com 에서 테스트된 클래스이다. 그런데도 이런 문제가 발생한 것이다. 이전에
Hemose 의 메신저 서버를 만들 때에도 이런 문제가 있었는데, 풀리지 않을 것 같은 문제로 여
기고 매우 긴장하고 있었다. CObjAVL.H 파일의 AddKey() 함수의 비교하는 부분에 cout 으로
출력해 보니까, 항상 '>' 조건이 아닌가. 그래서 ZtCMainChars<>::Minus() 함수까지 파들어가
리턴하는 값을 보니까 항상 양수였다! 이럴수가, 왼쪽이 작으면 음수를 리턴해야 한다. 그런
데 항상 양수라니. 좀 더 조사해 보니까, 해당 컴파일러의, char 의 int 형 확장에 따른 문제
였고 코드를 위처럼 고치게 되었다.
-- 2011-12-29 17:35:00
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

View File

@ -423,7 +423,7 @@ namespace ZNsMain
static ZCChars& Trim(ZCChars& ARR_CChars)
{
ZtCMainChars::Trim(ARR_CChars.data(), RR(ARR_CChars.ml_TypeLength)); return ARR_CChars;
ZtCMainChars::Trim(ARR_CChars.data(), RR(ARR_CChars.ml_TypeSize)); return ARR_CChars;
}/*
static ZCChars& Trim(ZCChars& ARR_CChars)*/
@ -623,7 +623,7 @@ namespace ZNsMain
for(TypeLength i=0; i<VI_CompareCnt; ++i)
{
if(*(--VPC_OrginStart)!=*(--VPC_SearchStart)) return false;
if(*(--VPC_OrginStart) != *(--VPC_SearchStart)) return false;
}/*
for(TypeLength i=0; i<VI_CompareCnt; ++i)*/

View File

@ -977,7 +977,7 @@ namespace ZNsMain
///////////////////////////////////////////////////////////////
ZtCSimList& CopyLink const /*################################*/
ZtCSimList& CopyLink /*######################################*/
(
const ZCLink* const AP_CopyLink ,
TTypSize AL_FarNum ,