commit 2025-10-08 07:14 edit a bit ZCppMain/ZtCLinkList.H

This commit is contained in:
2025-10-08 07:14:38 +09:00
parent 8d7745ac90
commit 71f2c6fd54
3 changed files with 71 additions and 149 deletions

View File

@ -353,10 +353,6 @@ namespace ZNsMain
GetObjRef(AO_Functor)( *VP_TypeArr ); GetObjRef(AO_Functor)( *VP_TypeArr );
++VP_TypeArr; ////////////////// ++VP_TypeArr; //////////////////
/* ZtCTypeData 으로 인해서, AO_Functor 이 함수일 때뿐이 아니라,
operator() 연산자를 가진 object 포인터일 때도 사용할 수 있게 되었다.
*/
}/* }/*
__for0(TypeSize, i, ml_UseSize)*/ __for0(TypeSize, i, ml_UseSize)*/
}/* }/*
@ -384,35 +380,20 @@ namespace ZNsMain
void IterElement(TFunctor AO_Functor, TTypeHelp AO_TypeHelp)*/ void IterElement(TFunctor AO_Functor, TTypeHelp AO_TypeHelp)*/
template template /*#####################################################*/
<typename TFunctor, typename TTypeHelp1, typename TTypeHelp2> <
typename TFunctor ,
typename TTypeHelp1 ,
typename TTypeHelp2
>
void IterElement void IterElement
(TFunctor AO_Functor, TTypeHelp1 AO_TypeHelp1, TTypeHelp2 AO_TypeHelp2) (
TFunctor AO_Functor ,
TTypeHelp1 AO_TypeHelp1 ,
TTypeHelp2 AO_TypeHelp2
)
/*##############################################################*/
{ {
/*/////////////////////////////////////////////////////////////////////////////
■ TTypeHelp 가 class 일 경우, 크기가 커서 참조로 넘어가야 한다면,
IterElement<myFunctor, myClass&>(myFunctor_obj, myClass_Obj);
의 형태로 호출할 게 아니라, ZNsMain::ZtCObjectPtr<> 을 사용하여,
myClass myClass_Obj; ZNsMain::ZtCObjectPtr<myClass> myCObjPtr(myClass_Obj);
IterElement(myFunctor_obj, ZNsMain::ZtCObjectPtr<myClass>(myClass_Obj));
형태를 사용하면 좋을 것 같다. -- 2014-06-16 23:11:00
ZCCheckRef::PassData() 으로 인해, 인수를 ZtCRef 클래스를 이용해 인수를 참조
로 넘길 수 있게 되었다. -- 2021-03-10 16:56
이제는 ZtCRef 과 ZCCheckRef 클래스 템플릿을 사용하면 된다. -- 2021-03-11 11:00
/////////////////////////////////////////////////////////////////////////////*/
typedef ZNsMain::ZtCCheckRef<TTypeHelp1> ZCCheckRef1; typedef ZNsMain::ZtCCheckRef<TTypeHelp1> ZCCheckRef1;
typedef ZNsMain::ZtCCheckRef<TTypeHelp2> ZCCheckRef2; typedef ZNsMain::ZtCCheckRef<TTypeHelp2> ZCCheckRef2;
@ -430,10 +411,19 @@ namespace ZNsMain
}/* }/*
__for0(TypeSize, i, ml_UseSize)*/ __for0(TypeSize, i, ml_UseSize)*/
}/* }/*
template template #########################################################
<typename TFunctor, typename TTypeHelp1, typename TTypeHelp2> <
typename TFunctor ,
typename TTypeHelp1 ,
typename TTypeHelp2
>
void IterElement void IterElement
(TFunctor AO_Functor, TTypeHelp1 AO_TypeHelp1, TTypeHelp2 AO_TypeHelp2)*/ (
TFunctor AO_Functor ,
TTypeHelp1 AO_TypeHelp1 ,
TTypeHelp2 AO_TypeHelp2
)
################################################################*/
/*/////////////////////////////////////////////////////////////////////////// /*///////////////////////////////////////////////////////////////////////////
@ -706,44 +696,12 @@ namespace ZNsMain
Type& operator[](TSize AL_Index) Type& operator[](TSize AL_Index)
{ {
#ifdef _DEBUG
if(AL_Index>=ml_UseSize)
{
std::fstream fileout("DEBUG.txt",std::ios::out | std::ios::app);
fileout<<std::endl<<"File : "<<__FILE__<<std::endl<<"Line : "<<__LINE__<<std::endl;
fileout<<"Error In 'Type& operator[](TSize AL_Index)"<<std::endl;
fileout<<" AL_Index>=ml_UseSize"<<", "<<AL_Index<<">="<<ml_UseSize<<std::endl;
fileout.close();
::exit(1);
}/*
if(AL_Index>=ml_UseSize)*/
#endif //_DEBUG
return mp_TypeArr[AL_Index] ; return mp_TypeArr[AL_Index] ;
}/* }/*
Type& operator[](TSize AL_Index)*/ Type& operator[](TSize AL_Index)*/
const Type& operator[](TSize AL_Index) const const Type& operator[](TSize AL_Index) const
{ {
#ifdef _DEBUG
if(AL_Index>=ml_UseSize)
{
std::fstream fileout("DEBUG.txt",std::ios::out | std::ios::app);
fileout<<std::endl<<"File : "<<__FILE__<<std::endl<<"Line : "<<__LINE__<<std::endl;
fileout<<"Error In 'const Type& operator[](TSize AL_Index) const"<<std::endl;
fileout<<" AL_Index>=ml_UseSize"<<std::endl;
fileout.close();
::exit(1);
}/*
if(AL_Index>=ml_UseSize)*/
#endif //_DEBUG
return mp_TypeArr[AL_Index] ; return mp_TypeArr[AL_Index] ;
}/* }/*
const Type& operator[](TSize AL_Index) const*/ const Type& operator[](TSize AL_Index) const*/
@ -751,44 +709,12 @@ namespace ZNsMain
Type& GetData(TSize AL_Index) Type& GetData(TSize AL_Index)
{ {
#ifdef _DEBUG
if(AL_Index>=ml_UseSize)
{
std::fstream fileout("DEBUG.txt",std::ios::out | std::ios::app);
fileout<<std::endl<<"File : "<<__FILE__<<std::endl<<"Line : "<<__LINE__<<std::endl;
fileout<<"Error In 'Type& GetData(TSize AL_Index)"<<std::endl;
fileout<<" AL_Index>=ml_UseSize"<<std::endl;
fileout.close();
::exit(1);
}/*
if(AL_Index>=ml_UseSize)*/
#endif //_DEBUG
return mp_TypeArr[AL_Index] ; return mp_TypeArr[AL_Index] ;
}/* }/*
Type& GetData(TSize AL_Index)*/ Type& GetData(TSize AL_Index)*/
const Type& GetData(TSize AL_Index) const const Type& GetData(TSize AL_Index) const
{ {
#ifdef _DEBUG
if(AL_Index>=ml_UseSize)
{
std::fstream fileout("DEBUG.txt",std::ios::out | std::ios::app);
fileout<<std::endl<<"File : "<<__FILE__<<std::endl<<"Line : "<<__LINE__<<std::endl;
fileout<<"Error In 'const Type& GetData(TSize AL_Index) const"<<std::endl;
fileout<<" AL_Index>=ml_UseSize"<<std::endl;
fileout.close();
::exit(1);
}/*
if(AL_Index>=ml_UseSize)*/
#endif //_DEBUG
return mp_TypeArr[AL_Index]; return mp_TypeArr[AL_Index];
}/* }/*
const Type& GetData(TSize AL_Index) const*/ const Type& GetData(TSize AL_Index) const*/

View File

@ -184,15 +184,23 @@ namespace ZNsMain
) )
/*/////////////////////////////////////////////////*/ /*/////////////////////////////////////////////////*/
{ {
// AL_FarNum > 0 /*//////////////////////////////////////////////////////////////////////
// AP_LinkOrgin 링크부터,
// AP_LinkOrgin 에서 AL_FarNum 만큼 떨어진 링크까지를 복사하여 ■ AL_FarNum > 0
// 복사생성된 처음 링크 포인터를 APR_HeadCopy 에,
// 마지막 링크를 APR_TailCopy 에 대입한다. AP_LinkOrgin 링크부터, AP_LinkOrgin 에서 AL_FarNum 만큼 떨어진 링크까
// AP_LinkOrgin 링크에서 그 다음 링크로 접근하면서 링크를 복사할 것이다. 지를 복사하여 복사 생성된
// 따라서 총 AL_FarNum + 1 개의 링크가 만들어진다.
// 이 함수는 각 링크를 새로 생성하는 MakeLinkCopy() 함수와는 달리 처음 링크 포인터를 APR_HeadCopy 에,
// 기존에 있는 ml_UseSize 개의 링크를 먼저 사용한다. 마지막 링크 포인터를 APR_TailCopy 에
대입한다. AP_LinkOrgin 링크에서 그 다음 링크로 접근하면서 링크를 복사
할 것이다. 따라서 총 AL_FarNum + 1 개의 링크가 만들어진다.
이 함수는 각 링크를 새로 생성하는 MakeLinkCopy() 함수와는 달리, 기존
에 있는 ml_UseSize 개의 링크를 먼저 사용한다.
//////////////////////////////////////////////////////////////////////*/
if(mp_NoUseHead==0) if(mp_NoUseHead==0)
{ {
@ -295,14 +303,17 @@ namespace ZNsMain
ZCLink* VP_TempLink = APR_HeadLink; ZCLink* VP_TempLink = APR_HeadLink;
bool VB_IsHeapOver= false ; bool VB_IsHeapOver= false ;
// bool VB_IsHeapOver 은 new 연산자가 NULL 포인터를 반환했을 때 /*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
// true 를 대입받는다. 이 값을 조사함으로써 heap overflow 를 처리한다.
// bool VB_IsHeapOver 변수를 두지 않고 bool VB_IsHeapOver 은 new 연산자가 NULL 포인터를 반환했을 때
// 아래 for 문에서 직접 메모리 처리를 하는 코드를 둘 수 있으나 true 를 대입받는다. 이 값을 조사함으로써 heap overflow 를 처리한다.
// for 문 안에 if 문 속에서 또 for 문을 써야 함으로
// 가독성이 떨어질 수가 있다. bool VB_IsHeapOver 변수를 두지 않고 아래 for 문에서 직접 메모리 처리
// 그래서 heap over 에 대한 예외처리 코드를 를 하는 코드를 둘 수 있으나, for 문 안에 if 문 속에서 또 for 문을 써
// for 문 바깥으로 빼려는 것이다. 야 함으로 가독성이 떨어질 수가 있다. 그래서 heap over 에 대한 예외처
리 코드를 for 문 바깥으로 빼려는 것이다.
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
while(--AL_MakeSize>0) // AL_MakeSize - 1 번 순환 while(--AL_MakeSize>0) // AL_MakeSize - 1 번 순환
{ {
@ -373,11 +384,17 @@ namespace ZNsMain
) const ) const
///////////////////////////////////////////////////*/ ///////////////////////////////////////////////////*/
{ {
// AP_LinkOrgin 링크부터, /*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
// AP_LinkOrgin 에서 AL_FarNum 만큼 떨어진 링크까지를 복사하여
// 복사생성된 처음 링크 포인터를 APR_HeadCopy 에, ■ AP_LinkOrgin 링크부터, AP_LinkOrgin 에서 AL_FarNum 만큼 떨어진 링크까
// 마지막 링크를 APR_TailCopy 에 대입한다. 지를 복사하여, 복사 생성된
// AL_FarNum > 0 , 총 AL_FarNum + 1 개의 링크가 만들어진다.
처음 링크 포인터를 APR_HeadCopy 에,
마지막 링크 포인터를 APR_TailCopy 에
대입한다. AL_FarNum > 0 , 총 AL_FarNum + 1 개의 링크가 만들어진다.
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
ZCLink* VP_MakeLink = 0 ; ZCLink* VP_MakeLink = 0 ;
ZCLink* VP_TailLink = 0 ; ZCLink* VP_TailLink = 0 ;
@ -1998,23 +2015,15 @@ namespace ZNsMain
ZtCObjList& AddHead(TypeArg AR_Type) ZtCObjList& AddHead(TypeArg AR_Type)
{ {
#if(_CODE_NEW_)
ZCLink* VP_NewNode = mo_FreeObjt.SendFreeOut(); ZCLink* VP_NewNode = mo_FreeObjt.SendFreeOut();
#else
ZCLink* VP_NewNode = new ZCLink ;
#endif
#if(_CODE_NEW_)
if(TypeMoveObj::ZEUseMoveObj>0) //////////////////// if(TypeMoveObj::ZEUseMoveObj>0) ////////////////////
{ {
TypeMoveObj::Exec(**VP_NewNode, AR_Type); TypeMoveObj::Exec(**VP_NewNode, AR_Type);
JoinAfter(VP_NewNode, 0); return *this ; JoinAfter(VP_NewNode, 0); return *this ;
} }
//////////////////////////////////////////////////// **VP_NewNode = AR_Type; ////////////////////////////
#endif
**VP_NewNode = AR_Type;
JoinAfter(VP_NewNode, 0); return *this; JoinAfter(VP_NewNode, 0); return *this;
}/* }/*
@ -2033,23 +2042,15 @@ namespace ZNsMain
ZtCObjList& AddTail(TypeArg AR_Type) ZtCObjList& AddTail(TypeArg AR_Type)
{ {
#if(_CODE_NEW_)
ZCLink* VP_NewNode = mo_FreeObjt.SendFreeOut(); ZCLink* VP_NewNode = mo_FreeObjt.SendFreeOut();
#else
ZCLink* VP_NewNode = new ZCLink ;
#endif
#if(_CODE_NEW_)
if(TypeMoveObj::ZEUseMoveObj>0) //////////////////// if(TypeMoveObj::ZEUseMoveObj>0) ////////////////////
{ {
TypeMoveObj::Exec(**VP_NewNode, AR_Type); TypeMoveObj::Exec(**VP_NewNode, AR_Type);
JoinAfter(VP_NewNode, GetTailLinkPtr()); return *this; JoinAfter(VP_NewNode, GetTailLinkPtr()); return *this;
} }
//////////////////////////////////////////////////// **VP_NewNode = AR_Type; ////////////////////////////
#endif
**VP_NewNode = AR_Type;
JoinAfter JoinAfter
(VP_NewNode, GetTailLinkPtr()); (VP_NewNode, GetTailLinkPtr());
@ -2074,22 +2075,17 @@ namespace ZNsMain
ZCLink& AddHeadDef() ZCLink& AddHeadDef()
{ {
#if(_CODE_NEW_)
ZCLink* VP_NewLink = mo_FreeObjt.SendFreeOut(); ZCLink* VP_NewLink = mo_FreeObjt.SendFreeOut();
#else
ZCLink* VP_NewLink = new ZCLink ;
#endif
JoinAfter(VP_NewLink, 0); return *VP_NewLink ; JoinAfter(VP_NewLink, 0); return *VP_NewLink ;
} }
ZCLink& AddTailDef() ZCLink& AddTailDef()
{ {
#if(_CODE_NEW_)
ZCLink* VP_NewLink = mo_FreeObjt.SendFreeOut(); ZCLink* VP_NewLink = mo_FreeObjt.SendFreeOut();
#else
ZCLink* VP_NewLink = new ZCLink ;
#endif
JoinAfter(VP_NewLink, GetTailLinkPtr()); return *VP_NewLink; JoinAfter(VP_NewLink, GetTailLinkPtr()); return *VP_NewLink;
} }/*
ZCLink& AddTailDef()*/
ZtCObjList& pop_back (TypeArg AR_Type){return AddHead(AR_Type);} ZtCObjList& pop_back (TypeArg AR_Type){return AddHead(AR_Type);}