commit 2025-10-19 13:00 add ZCtDataRing in ZCppMain/ZMainHead.H
This commit is contained in:
@ -4115,6 +4115,347 @@ namespace ZNsMain
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace ZNsType
|
||||||
|
{
|
||||||
|
|
||||||
|
template
|
||||||
|
< typename TTypData, typename TTypSize=ZTypLength >
|
||||||
|
class ZtCTypeSelfLink
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
class ZCDataLink ;
|
||||||
|
public:
|
||||||
|
typedef TTypData TypeData ;
|
||||||
|
typedef ZCDataLink TypeLink ;
|
||||||
|
typedef TTypSize TypeSize ;
|
||||||
|
|
||||||
|
typedef const TypeData TypeDataC;
|
||||||
|
typedef const TypeLink TypeLinkC;
|
||||||
|
public:
|
||||||
|
|
||||||
|
class ZCDataLink : public TypeData
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
TypeLink* mp_NextLink;
|
||||||
|
TypeLink* mp_PrevLink;
|
||||||
|
protected:
|
||||||
|
/* alwayse mp_NextLink!=0 && mp_PrevLink!=0 */
|
||||||
|
protected:
|
||||||
|
static void JoinLink(TypeLink* AP_PrevLink, TypeLink* AP_NextLink)
|
||||||
|
{
|
||||||
|
AP_PrevLink->mp_NextLink=AP_NextLink;
|
||||||
|
AP_NextLink->mp_PrevLink=AP_PrevLink;
|
||||||
|
}/*
|
||||||
|
static void JoinLink(TypeLink* AP_PrevLink, TypeLink* AP_NextLink)*/
|
||||||
|
static void MakeRing(TypeLink* AP_HeadLink, TypeLink* AP_TailLink)
|
||||||
|
{
|
||||||
|
AP_HeadLink->mp_PrevLink=AP_TailLink;
|
||||||
|
AP_TailLink->mp_NextLink=AP_HeadLink;
|
||||||
|
}/*
|
||||||
|
static void MakeRing(TypeLink* AP_HeadLink, TypeLink* AP_TailLink)*/
|
||||||
|
public :
|
||||||
|
TypeData & operator * () {return static_cast<TypeData &>(*this);}
|
||||||
|
TypeData & operator() () {return static_cast<TypeData &>(*this);}
|
||||||
|
operator TypeData & () {return static_cast<TypeData &>(*this);}
|
||||||
|
|
||||||
|
TypeDataC& operator * () const{return static_cast<TypeDataC&>(*this);}
|
||||||
|
TypeDataC& operator() () const{return static_cast<TypeDataC&>(*this);}
|
||||||
|
operator TypeDataC& () const{return static_cast<TypeDataC&>(*this);}
|
||||||
|
|
||||||
|
TypeData & GetData () {return static_cast<TypeData &>(*this);}
|
||||||
|
TypeDataC& GetData () const{return static_cast<TypeDataC&>(*this);}
|
||||||
|
|
||||||
|
TypeLink & GetNext () {return *mp_NextLink;}
|
||||||
|
TypeLink & GetPrev () {return *mp_PrevLink;}
|
||||||
|
|
||||||
|
TypeLinkC& GetNext () const{return *mp_NextLink;}
|
||||||
|
TypeLinkC& GetPrev () const{return *mp_PrevLink;}
|
||||||
|
|
||||||
|
public :
|
||||||
|
ZCDataLink()
|
||||||
|
{
|
||||||
|
mp_NextLink = mp_PrevLink = 0 ;
|
||||||
|
}/*
|
||||||
|
ZCDataLink()*/
|
||||||
|
ZCDataLink(TypeLinkC& rhs)
|
||||||
|
{
|
||||||
|
mp_NextLink = mp_PrevLink = 0 ; GetData() = rhs.GetData() ;
|
||||||
|
}/*
|
||||||
|
ZCDataLink(TypeLinkC& rhs)*/
|
||||||
|
ZCDataLink(TypeDataC& AR_Data)
|
||||||
|
{
|
||||||
|
mp_NextLink = mp_PrevLink = 0 ; GetData() = AR_Data ;
|
||||||
|
}/*
|
||||||
|
ZCDataLink(TypeDataC& AR_Data)*/
|
||||||
|
|
||||||
|
TypeLink& operator=(TypeLinkC& rhs)
|
||||||
|
{ GetData() = rhs.GetData(); return *this; }
|
||||||
|
TypeLink& operator=(TypeData & rhs)
|
||||||
|
{ GetData() = rhs ; return *this; }
|
||||||
|
TypeLink& operator=(TypeDataC& rhs)
|
||||||
|
{ GetData() = rhs ; return *this; }
|
||||||
|
|
||||||
|
public :
|
||||||
|
};/*
|
||||||
|
class ZCDataLink : public TypeData*/
|
||||||
|
|
||||||
|
public:
|
||||||
|
};/*
|
||||||
|
template
|
||||||
|
< typename TTypData, typename TTypSize=ZTypLength >
|
||||||
|
class ZtCTypeSelfLink */
|
||||||
|
|
||||||
|
}/*
|
||||||
|
namespace ZNsType*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template ////////////////////////////////////////////////////////////////
|
||||||
|
<
|
||||||
|
typename TDataNow, typename TTypeSelfLink =
|
||||||
|
ZNsType::ZtCTypeSelfLink<TDataNow>
|
||||||
|
>
|
||||||
|
class ZCtDataRing : /*#################################################*/
|
||||||
|
public TTypeSelfLink::TypeLink
|
||||||
|
{
|
||||||
|
public :
|
||||||
|
typedef ZCtDataRing TypeThis ;
|
||||||
|
typedef TDataNow TypeData ;
|
||||||
|
public :
|
||||||
|
typedef typename TTypeSelfLink::TypeLink TypeLink;
|
||||||
|
typedef typename TTypeSelfLink::TypeSize TypeSize;
|
||||||
|
public :
|
||||||
|
typedef const TypeData TypeDataC;
|
||||||
|
typedef const TypeLink TypeLinkC;
|
||||||
|
typedef const TypeThis TypeThisC;
|
||||||
|
private:
|
||||||
|
using TypeLink::JoinLink; using TypeLink::MakeRing;
|
||||||
|
private:
|
||||||
|
TypeLink* mp_HeadLink;
|
||||||
|
TypeLink* mp_TailLink;
|
||||||
|
TypeSize ml_LinkSize;
|
||||||
|
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
■ mp_HeadLink 부터 mp_TailLink 까지의 링크 수는 this 를 포함해서
|
||||||
|
ml_LinkSize+1 개가 된다. 따라서 this 객체 자신이 동적으로 생성
|
||||||
|
한 객체의 처음은 mp_HeadLink->mp_NextLink 임에 주의한다.
|
||||||
|
-- 2025-10-19 12:55
|
||||||
|
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
public :
|
||||||
|
|
||||||
|
ZCtDataRing()
|
||||||
|
{
|
||||||
|
mp_HeadLink=this;
|
||||||
|
mp_TailLink=this;
|
||||||
|
ml_LinkSize=0 ;
|
||||||
|
/* alwayse mp_NextLink!=0 && mp_PrevLink!=0 */
|
||||||
|
|
||||||
|
MakeRing(mp_HeadLink, mp_TailLink);
|
||||||
|
}/*
|
||||||
|
ZCtDataRing()*/
|
||||||
|
|
||||||
|
/*#######################################################################
|
||||||
|
|
||||||
|
ZCtDataRing(const ZCtDataRing& rhs) : ZCtDataRing()
|
||||||
|
{ this->GetData() = rhs.GetData() ; }
|
||||||
|
ZCtDataRing(const TypeLink & rhs) : ZCtDataRing()
|
||||||
|
{ this->GetData() = rhs.GetData() ; }
|
||||||
|
ZCtDataRing(const TypeData & rhs) : ZCtDataRing()
|
||||||
|
{ this->GetData() = rhs ; }
|
||||||
|
|
||||||
|
../ZCppMain/ZMainHead.H: In copy constructor ‘ZNsMain::ZCtDataRing<TDataNow, TTypeSelfLink>::ZCtDataRing(const ZNsMain::ZCtDataRing<TDataNow, TTypeSelfLink>&)’:
|
||||||
|
../ZCppMain/ZMainHead.H:4242:59: warning: delegating constructors only available with ‘-std=c++11’ or ‘-std=gnu++11’
|
||||||
|
4242 | ZCtDataRing(const ZCtDataRing& rhs) : ZCtDataRing()
|
||||||
|
|
||||||
|
sauron@q381-2673:/mnt/e/my_CPP/ZCpp/ZCppMainTest$ g++ --version
|
||||||
|
g++ (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
|
||||||
|
Copyright (C) 2019 Free Software Foundation, Inc.
|
||||||
|
This is free software; see the source for copying conditions. There is NO
|
||||||
|
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
|
||||||
|
-- 2025-10-19 11:41
|
||||||
|
|
||||||
|
#######################################################################*/
|
||||||
|
|
||||||
|
ZCtDataRing(const ZCtDataRing& rhs)
|
||||||
|
{
|
||||||
|
mp_HeadLink=this;
|
||||||
|
mp_TailLink=this;
|
||||||
|
ml_LinkSize=0 ;
|
||||||
|
|
||||||
|
MakeRing(mp_HeadLink, mp_TailLink);
|
||||||
|
|
||||||
|
this->GetData() = rhs.GetData() ;
|
||||||
|
}/*
|
||||||
|
ZCtDataRing(const ZCtDataRing& rhs)*/
|
||||||
|
ZCtDataRing(const TypeLink & rhs)
|
||||||
|
{
|
||||||
|
mp_HeadLink=this;
|
||||||
|
mp_TailLink=this;
|
||||||
|
ml_LinkSize=0 ;
|
||||||
|
|
||||||
|
MakeRing(mp_HeadLink, mp_TailLink);
|
||||||
|
|
||||||
|
this->GetData() = rhs.GetData() ;
|
||||||
|
}/*
|
||||||
|
ZCtDataRing(const TypeLink & rhs)*/
|
||||||
|
ZCtDataRing(const TypeData & rhs)
|
||||||
|
{
|
||||||
|
mp_HeadLink=this;
|
||||||
|
mp_TailLink=this;
|
||||||
|
ml_LinkSize=0 ;
|
||||||
|
|
||||||
|
MakeRing(mp_HeadLink, mp_TailLink);
|
||||||
|
|
||||||
|
this->GetData() = rhs ; /*********/
|
||||||
|
}/*
|
||||||
|
ZCtDataRing(const TypeData & rhs)*/
|
||||||
|
|
||||||
|
|
||||||
|
~ZCtDataRing(){DeleteAll();}
|
||||||
|
|
||||||
|
|
||||||
|
TypeSize size () const{return ml_LinkSize;}
|
||||||
|
TypeSize Size () const{return ml_LinkSize;}
|
||||||
|
TypeSize GetSize() const{return ml_LinkSize;}
|
||||||
|
|
||||||
|
TypeLink & operator * () {return static_cast<TypeLink &>(*this);}
|
||||||
|
TypeLink & operator() () {return static_cast<TypeLink &>(*this);}
|
||||||
|
operator TypeData & () {return static_cast<TypeLink &>(*this);}
|
||||||
|
|
||||||
|
TypeLinkC& operator * () const{return static_cast<TypeLinkC&>(*this);}
|
||||||
|
TypeLinkC& operator() () const{return static_cast<TypeLinkC&>(*this);}
|
||||||
|
operator TypeLinkC& () const{return static_cast<TypeLinkC&>(*this);}
|
||||||
|
|
||||||
|
TypeData & GetData () {return this->TypeLink::GetData();}
|
||||||
|
TypeDataC& GetData () const{return this->TypeLink::GetData();}
|
||||||
|
|
||||||
|
|
||||||
|
TypeThis& operator=(TypeThisC& rhs)
|
||||||
|
{ this->GetData() = rhs.GetData(); return *this; }
|
||||||
|
TypeThis& operator=(TypeLinkC& rhs)
|
||||||
|
{ this->GetData() = rhs.GetData(); return *this; }
|
||||||
|
TypeThis& operator=(TypeDataC& rhs)
|
||||||
|
{ this->GetData() = rhs ; return *this; }
|
||||||
|
TypeThis& operator=(TypeData & rhs)
|
||||||
|
{ this->GetData() = rhs ; return *this; }
|
||||||
|
|
||||||
|
|
||||||
|
TypeLink & GetHead() {return *mp_HeadLink;}
|
||||||
|
TypeLink & GetTail() {return *mp_TailLink;}
|
||||||
|
|
||||||
|
TypeLinkC& GetHead() const{return *mp_HeadLink;}
|
||||||
|
TypeLinkC& GetTail() const{return *mp_TailLink;}
|
||||||
|
|
||||||
|
|
||||||
|
TypeLink& AddTail()
|
||||||
|
{
|
||||||
|
TypeLink* VP_NewLink = new TypeLink;
|
||||||
|
|
||||||
|
JoinLink(mp_TailLink, VP_NewLink);
|
||||||
|
MakeRing(mp_HeadLink, VP_NewLink);
|
||||||
|
|
||||||
|
mp_TailLink = VP_NewLink ;
|
||||||
|
|
||||||
|
++ml_LinkSize; return *VP_NewLink;
|
||||||
|
}/*
|
||||||
|
TypeLink& AddTail()*/
|
||||||
|
|
||||||
|
TypeLink& AddTail(TypeLinkC& AR_TypeLink)
|
||||||
|
{
|
||||||
|
TypeLink* VP_NewLink =
|
||||||
|
new TypeLink( AR_TypeLink ) ;
|
||||||
|
|
||||||
|
JoinLink(mp_TailLink, VP_NewLink);
|
||||||
|
MakeRing(mp_HeadLink, VP_NewLink);
|
||||||
|
|
||||||
|
mp_TailLink = VP_NewLink ;
|
||||||
|
|
||||||
|
++ml_LinkSize; return *VP_NewLink;
|
||||||
|
}/*
|
||||||
|
TypeLink& AddTail(TypeLinkC& AR_TypeLink)*/
|
||||||
|
TypeLink& AddTail(TypeDataC& AR_TypeData)
|
||||||
|
{
|
||||||
|
TypeLink* VP_NewLink =
|
||||||
|
new TypeLink( AR_TypeData ) ;
|
||||||
|
|
||||||
|
JoinLink(mp_TailLink, VP_NewLink);
|
||||||
|
MakeRing(mp_HeadLink, VP_NewLink);
|
||||||
|
|
||||||
|
mp_TailLink = VP_NewLink ;
|
||||||
|
|
||||||
|
++ml_LinkSize; return *VP_NewLink;
|
||||||
|
}/*
|
||||||
|
TypeLink& AddTail(TypeDataC& AR_TypeData)*/
|
||||||
|
|
||||||
|
|
||||||
|
void DeleteAll()
|
||||||
|
{
|
||||||
|
TypeLink* VP_CutLink = &mp_HeadLink->GetNext();
|
||||||
|
TypeLink* VP_CutNext = &VP_CutLink ->GetNext();
|
||||||
|
|
||||||
|
__for0(TypeSize, i, ml_LinkSize)
|
||||||
|
{
|
||||||
|
delete VP_CutLink;
|
||||||
|
|
||||||
|
VP_CutLink = VP_CutNext ;
|
||||||
|
VP_CutNext = &VP_CutLink ->GetNext();
|
||||||
|
}/*
|
||||||
|
__for0(TypeSize, i, ml_LinkSize)*/
|
||||||
|
|
||||||
|
mp_HeadLink=this;
|
||||||
|
mp_TailLink=this;
|
||||||
|
ml_LinkSize=0 ;
|
||||||
|
}/*
|
||||||
|
void DeleteAll()*/
|
||||||
|
|
||||||
|
public :
|
||||||
|
};/*
|
||||||
|
template ////////////////////////////////////////////////////////////////
|
||||||
|
<
|
||||||
|
typename TDataNow, typename TTypeSelfLink =
|
||||||
|
ZNsType::ZtCTypeSelfLink<TDataNow>
|
||||||
|
>
|
||||||
|
class ZCtDataRing : ###################################################*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<typename TDataNow, typename TTypeSelfLink> std::ostream& operator <<
|
||||||
|
(
|
||||||
|
std::ostream& AR_COStream, const ZCtDataRing<TDataNow, TTypeSelfLink>& AR_CDataRing
|
||||||
|
)
|
||||||
|
/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
|
||||||
|
{
|
||||||
|
/*/////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
■ ZCtDataRing~ 앞에 const 를 붙이지 않으면, 비 const ZCtDataRing object 에 대하여, 이
|
||||||
|
중첩 함수는 호출되지 않는다. 따라서 const 는 아주 중요한 역할을 한다.
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
AR_COStream<<AR_CDataRing.GetData();
|
||||||
|
|
||||||
|
typedef ZCtDataRing
|
||||||
|
<TDataNow, TTypeSelfLink> TypeRing ;
|
||||||
|
typedef typename TypeRing::TypeSize TypeSize ;
|
||||||
|
typedef typename TypeRing::TypeLinkC TypeLinkC;
|
||||||
|
|
||||||
|
TypeLinkC* VP_NowLink = &AR_CDataRing.GetNext();
|
||||||
|
|
||||||
|
__for0(TypeSize, i, AR_CDataRing.size())
|
||||||
|
{
|
||||||
|
AR_COStream<<", "<<*VP_NowLink;
|
||||||
|
VP_NowLink = &VP_NowLink->GetNext();
|
||||||
|
}
|
||||||
|
return AR_COStream; /******************/
|
||||||
|
}/*
|
||||||
|
template<typename TDataNow, typename TTypeSelfLink> std::ostream& operator <<
|
||||||
|
(
|
||||||
|
std::ostream& AR_COStream, const ZCtDataRing<TDataNow, TTypeSelfLink>& AR_CDataRing
|
||||||
|
)
|
||||||
|
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace ZNsTmplChain
|
namespace ZNsTmplChain
|
||||||
{
|
{
|
||||||
/*////////////////////////////////////////////////////////////
|
/*////////////////////////////////////////////////////////////
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
#include "ZCppMain/ZMainHead.H"
|
#include "ZCppMain/ZMainHead.H"
|
||||||
|
|
||||||
|
|
||||||
@ -60,6 +61,10 @@ namespace ZNsMain
|
|||||||
{
|
{
|
||||||
cout<<"ZCTypeView(const ZCTypeView& rhs)"<<endl;
|
cout<<"ZCTypeView(const ZCTypeView& rhs)"<<endl;
|
||||||
}
|
}
|
||||||
|
~ZCTypeView()
|
||||||
|
{
|
||||||
|
cout<<"# ~ZCTypeView()"<<endl;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename TTypChain> void OnMeetType()
|
template<typename TTypChain> void OnMeetType()
|
||||||
{
|
{
|
||||||
@ -178,8 +183,30 @@ namespace ZNsMain
|
|||||||
cout<<"************************************"<<endl;
|
cout<<"************************************"<<endl;
|
||||||
ZCTypeChain::ZtCIterChain<ZCTypeView&>::
|
ZCTypeChain::ZtCIterChain<ZCTypeView&>::
|
||||||
IterTail(VO_ZCTypeView, ZftMCP(VI_CallNo=0));
|
IterTail(VO_ZCTypeView, ZftMCP(VI_CallNo=0));
|
||||||
|
cout<<"************************************"<<endl;
|
||||||
|
|
||||||
|
|
||||||
|
typedef ZCtDataRing<std::string> ZCDataRing;
|
||||||
|
|
||||||
|
ZCDataRing VO_CDataRing = string("123");
|
||||||
|
|
||||||
|
VO_CDataRing.AddTail(string("ABC"));
|
||||||
|
VO_CDataRing.AddTail(string("XYZ"));
|
||||||
|
|
||||||
|
cout<<"# VO_CDataRing Size = "<<VO_CDataRing.size()<<endl;
|
||||||
|
cout<<"# VO_CDataRing Data = "<<VO_CDataRing <<endl;
|
||||||
|
cout<<"************************************"<<endl;
|
||||||
|
|
||||||
|
|
||||||
|
typedef ZCtDataRing<ZCTypeView> ZCViewRing;
|
||||||
|
|
||||||
|
ZCViewRing VO_ZCViewRing;
|
||||||
|
|
||||||
|
VO_ZCViewRing.AddTail();
|
||||||
|
VO_ZCViewRing.AddTail();
|
||||||
|
VO_ZCViewRing.DeleteAll();
|
||||||
|
cout<<"************************************"<<endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}/*
|
}/*
|
||||||
static int Main(int AI_ArgCnt=0, char* APP_ArgVal[]=0)*/
|
static int Main(int AI_ArgCnt=0, char* APP_ArgVal[]=0)*/
|
||||||
|
Reference in New Issue
Block a user