44
55// ancrec.h: record and record anchor base class definitions for cse
66
7-
8- // before #include, #define NEEDLIKECTOR if including file calls the anc<T> like-another constructor
9-
10-
11- // ************************
12- // unsuccessful OPTIONS
13- // ************************
14-
15-
16- // ---------------------------------------------------------------------------------------------------------------------------
17-
18-
197#ifndef ANCREC_H // endif at end file
208#define ANCREC_H
219
@@ -91,7 +79,7 @@ class basAnc // base class for record anchors: basAnc<recordName>
9179 // nullptr if none; see cuprobe.cpp
9280
9381 basAnc ();
94- basAnc ( int flags, SFIR * fir, USI nFlds, const char * what, USI eSz, RCT rt, USI sOff , const CULT* pCult, int dontRegister=0 );
82+ basAnc ( int flags, SFIR * fir, USI nFlds, const char * what, USI eSz, RCT rt, USI sOff , const CULT* pCult, bool dontRegister=false );
9583 void FC regis ();
9684 virtual ~basAnc (); // destroyed in deriv classes, to use vf
9785 virtual record* ptr () = 0; // access block ptr (in drv class: typed)
@@ -101,6 +89,7 @@ class basAnc // base class for record anchors: basAnc<recordName>
10189 virtual const record& rec (TI i) const = 0; // ditto const
10290 virtual record* GetAtSafe ( int i) const = 0; // typed pointer to ith record or NULL
10391 virtual void * recMbr (TI i, USI off) = 0; // point record i member by offset
92+ virtual basAnc* CloneForType (const char * what, int _flags, BP _ownB) const = 0;
10493 void * FC recFld (TI i, SI fn); // point record i member by FIELD # 3-92
10594 RC FC al ( TI n, int erOp=ABT, BP _ownB=NULL ); // allocate records block. destroys old recs.
10695 RC FC reAl ( TI n, int erOp=ABT); // (re)allocate records block. keeps old recs <= n.
@@ -340,12 +329,11 @@ class record // base class for records
340329
341330template <class T > class anc : public basAnc
342331{ public:
343- anc ( const char *what, SFIR *sFir , USI nFlds, RCT rt, CULT* pCULT=nullptr ) // cpp'tor used for static instances
344- : basAnc( 0 , sFir , nFlds, what, sizeof (T), rt, offsetof( T, sstat), pCULT)
332+ anc ( const char *what, SFIR *sFir , USI nFlds, RCT rt, const CULT* pCULT=nullptr , bool dontregister= false ) // cpp'tor used for static instances
333+ : basAnc( 0 , sFir , nFlds, what, sizeof (T), rt, offsetof( T, sstat), pCULT, dontregister )
345334 { p = 0 ; }
346- anc ( const BP src, int flags, char *_what, // like-another constructor,
347- BP _ownB, int dontRegister=0 ); // code included only ifdef NEEDLIKECTOR.
348335 virtual ~anc (); // destroys records, and types anchor & its recs.
336+ virtual anc<T>* CloneForType (const char * _what, int _flags, BP _ownB) const ;
349337
350338 T* p; // typed pointer to record array storage block
351339 virtual T* GetAtSafe ( int i) const // typed pointer to ith record or NULL
@@ -428,27 +416,24 @@ template <class T> class anc : public basAnc
428416 rp <= (record *)( (char *)ptr() + eSz*n ); \
429417 IncP ( DMPP( rp), eSz) ) \
430418 if (((record *)rp)->r_status > 0)
419+
431420// =============================================================================
432- #ifdef NEEDLIKECTOR // define where this constructor is USED: avoids generating for classes where not used.
433-
434- template <class T > anc<T>::anc( const BP src, int flags, char *_what, BP _ownB, int dontRegister/* =0*/ )
435-
436- // like-another-with-records-deleted constructor.
437-
438- // Generates the same derived class as src, using generic code; assumes size of all anc<T>'s is the same.
439-
440- { // for subsidiary types anchor, cul.cpp::ratTyR, 2-92; only used for one (arbitrary) T.
441- // must copy: virt fcns, fir,nFlds,eSz,sOff,rt.
442- memcpy ( this , src, sizeof (anc<T>) ); // bitwise copy ALL, to incude virt fcn table ptr.
443- ancN= nAl= n= 0 ; p= 0 ; tyB= 0 ; // clear what don't want: anchor #, records, ul stuff.
444- mn = 1 ; // mn = 1 when no records allocated even if will be static
445- ba_flags = flags; what = _what; ownB = _ownB; // store members given by caller
446- if (!dontRegister)
447- regis (); // conditionally include in nextAnc iteration.
448- // CAUTION: don't regis() tyB's or any dm anc<T>'s without
449- // adding unregister logic to destructor, 10-93.
450- } // anc<T>::anc
451- #endif // NEEDLIKECTOR
421+ template <class T> anc<T>* anc<T>::CloneForType( // copy c-tor-ish re creating anc<T> for DEFTYPE
422+ const char *_what, // new 'what' -- generally "<source what> type" (in DM)
423+ int _flags, // flags
424+ BP _ownB) const // owner
425+ {
426+
427+ // make new anc<T> with data from *this
428+ // combined with defaults from anc<T>::anc<T> and basAnc::basAnc
429+ anc<T>* pC = new anc<T>(_what, fir, nFlds, rt, ba_pCULT, true );
430+
431+ pC->ba_flags = _flags; // caller specific values
432+ pC->ownB = _ownB;
433+
434+ return pC;
435+
436+ } // anc<T>::CloneForType
452437// -------------------------------------------------------------------------------------------------------------------------
453438template <class T > anc<T>::~anc () // destroy anchor: destroy its records and types.
454439
0 commit comments