From ad8e2949024e502aad3cc53c26d2afd73a4e07cd Mon Sep 17 00:00:00 2001 From: sauron Date: Sun, 19 Oct 2025 13:00:37 +0900 Subject: [PATCH] commit 2025-10-19 13:00 add ZCtDataRing in ZCppMain/ZMainHead.H --- ZCppMain/ZMainHead.H | 341 ++++++++++++++++++++++++++++++++++++++++++ ZCppMainTest/c++_test_006.cpp | 27 ++++ 2 files changed, 368 insertions(+) diff --git a/ZCppMain/ZMainHead.H b/ZCppMain/ZMainHead.H index 145d837..e60dbed 100644 --- a/ZCppMain/ZMainHead.H +++ b/ZCppMain/ZMainHead.H @@ -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(*this);} + TypeData & operator() () {return static_cast(*this);} + operator TypeData & () {return static_cast(*this);} + + TypeDataC& operator * () const{return static_cast(*this);} + TypeDataC& operator() () const{return static_cast(*this);} + operator TypeDataC& () const{return static_cast(*this);} + + TypeData & GetData () {return static_cast(*this);} + TypeDataC& GetData () const{return static_cast(*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 + > + 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::ZCtDataRing(const ZNsMain::ZCtDataRing&)’: + ../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(*this);} + TypeLink & operator() () {return static_cast(*this);} + operator TypeData & () {return static_cast(*this);} + + TypeLinkC& operator * () const{return static_cast(*this);} + TypeLinkC& operator() () const{return static_cast(*this);} + operator TypeLinkC& () const{return static_cast(*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 + > + class ZCtDataRing : ###################################################*/ + + + + template std::ostream& operator << + ( + std::ostream& AR_COStream, const ZCtDataRing& AR_CDataRing + ) + /*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/ + { + /*///////////////////////////////////////////////////////////////////////////////////// + + ■ ZCtDataRing~ 앞에 const 를 붙이지 않으면, 비 const ZCtDataRing object 에 대하여, 이 + 중첩 함수는 호출되지 않는다. 따라서 const 는 아주 중요한 역할을 한다. + + /////////////////////////////////////////////////////////////////////////////////////*/ + + AR_COStream< 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 std::ostream& operator << + ( + std::ostream& AR_COStream, const ZCtDataRing& AR_CDataRing + ) + :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/ + + + namespace ZNsTmplChain { /*//////////////////////////////////////////////////////////// diff --git a/ZCppMainTest/c++_test_006.cpp b/ZCppMainTest/c++_test_006.cpp index f9edf87..fc91ac8 100644 --- a/ZCppMainTest/c++_test_006.cpp +++ b/ZCppMainTest/c++_test_006.cpp @@ -1,6 +1,7 @@ #include +#include #include "ZCppMain/ZMainHead.H" @@ -60,6 +61,10 @@ namespace ZNsMain { cout<<"ZCTypeView(const ZCTypeView& rhs)"< void OnMeetType() { @@ -178,8 +183,30 @@ namespace ZNsMain cout<<"************************************"<:: IterTail(VO_ZCTypeView, ZftMCP(VI_CallNo=0)); + cout<<"************************************"< ZCDataRing; + + ZCDataRing VO_CDataRing = string("123"); + + VO_CDataRing.AddTail(string("ABC")); + VO_CDataRing.AddTail(string("XYZ")); + + cout<<"# VO_CDataRing Size = "< ZCViewRing; + + ZCViewRing VO_ZCViewRing; + + VO_ZCViewRing.AddTail(); + VO_ZCViewRing.AddTail(); + VO_ZCViewRing.DeleteAll(); + cout<<"************************************"<