Skip to content

Commit ec0e345

Browse files
authored
Merge pull request #98 from cse-sim/PkgRSYS
Pkg RSYS / solar hot water
2 parents e03611c + e1670a3 commit ec0e345

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+11943
-6671
lines changed

src/ANCREC.CPP

Lines changed: 30 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,25 @@
3939
// class record: base class for application records.
4040
// destructor: inline, ancrec.h.
4141
//***************************************************************************************************************************
42+
record::record(BP _b, TI i, SI noZ/*=0*/) // construct record i of basAnc b, zero all members unless noZ
43+
{
44+
/* possible conditional statSetup elimination:
45+
if (i==0 (and at least b->rt matches if no validate()) and b->p==0 and b->n < b->mn,
46+
set b->p=this, mn/n/nAl 1 record, RFSTAT. BE SURE to override mn: 1-->0.
47+
if (i > 0 and b RFSTAT and b->p consistent and b->n==i-1,
48+
b->n++ : additional record in static array.
49+
CAUTION can be called from statSetup (til eliminated). */
50+
51+
_b->validate("record::record"); // abort if base bad -- we depend on it for size
52+
if (!noZ) // can be suppressed for data-init (static) records
53+
memset((char *)this + SZVFTP, 0, _b->eSz - SZVFTP); /* zero all members of DERIVED CLASS record
54+
except virtFcnTblPtr in 1st 2 or 4 bytes (ancrec.h define) */
55+
b = _b;
56+
rt = _b->rt;
57+
ss = i; // set base class members, for appl and anchor class use
58+
gud = 1; // say space in use and record good
59+
} // record::record
60+
//---------------------------------------------------------------------------------------------------------------------------
4261
void* record::field( int fn) // point to member in record by FIELD #
4362
{ return (void *)((char *)this + b->fir[fn].off); }
4463
//-----------------------------------------------------------------------------
@@ -87,63 +106,10 @@ int record::DType( int fn) const
87106
return dt;
88107
} // record::DType
89108
//-----------------------------------------------------------------------------
90-
record::record( BP _b, TI i, SI noZ/*=0*/) // construct record i of basAnc b, zero all members unless noZ
91-
{
92-
/* possible conditional statSetup elimination:
93-
if (i==0 (and at least b->rt matches if no validate()) and b->p==0 and b->n < b->mn,
94-
set b->p=this, mn/n/nAl 1 record, RFSTAT. BE SURE to override mn: 1-->0.
95-
if (i > 0 and b RFSTAT and b->p consistent and b->n==i-1,
96-
b->n++ : additional record in static array.
97-
CAUTION can be called from statSetup (til eliminated). */
98-
99-
_b->validate("record::record"); // abort if base bad -- we depend on it for size
100-
if (!noZ) // can be suppressed for data-init (static) records
101-
memset( (char *)this+SZVFTP, 0, _b->eSz-SZVFTP); /* zero all members of DERIVED CLASS record
102-
except virtFcnTblPtr in 1st 2 or 4 bytes (ancrec.h define) */
103-
b = _b;
104-
rt = _b->rt;
105-
ss = i; // set base class members, for appl and anchor class use
106-
gud = 1; // say space in use and record good
107-
} // record::record
108-
//---------------------------------------------------------------------------------------------------------------------------
109-
#if 0
110-
x // 7-20-92: NOT COMPLETED: believe nothing would set virt fcn tbl ptr.
111-
x
112-
x not completed, believe won't work without further changes cuz virtual fcn table pointer of record won't get set.
113-
x Instead, do same thing as record::record in record::init.
114-
x User derived class constructors won't work (none anyway). Tested here, ancrec.h. 7-20-92. */
115-
x // failed cuz our operator= does not copy front members; = probably never copies vft.
116-
x construct-in-place thoughts:
117-
x 1. won't work as now cuz virt fcn tbl ptr not init since not constructed.
118-
x 2. would be constructed if alloc'd with 'new'.. .p = new BLAHRAT[n].
119-
x --> interface record::new to dmAl( , WRN | DMZERO)
120-
x then set .b, .i, etc on return (maybe at add(), in .init)?
121-
x problem: no way to add records, unless we copy the virt fcn tbl ptr?
122-
x x3. make = non-virtual, init on stack and copy. maybe provide an afterCopy virt fcn to dup ptrs. failed (above).
123-
x 4. init on stack and memcpy!
124-
x
125-
x record::init( BP _b, TI i, SI noZ/*=0*/) // pseudo-construct record i of basAnc b, zero all members unless noZ.
126-
x
127-
x /* used to 'construct' previously-allocated record in place at use (when .add()'d) under BC 3.1,
128-
x cuz couldn't get compiler to recognize call to constructor for method used under BC 3.0 (see ancrec.h).
129-
x ***** --> derived class constructors won't override (but derived class init() should). 7-20-92. */
130-
x{
131-
x _b->validate("record::init"); // abort if base bad -- we depend on it for size
132-
x if (!noZ) // can be suppressed for data-init (static) records
133-
x memset( (char *)this+2, 0, _b->eSz-2); // zero all members of DERIVED CLASS record except virtFcnTblPtr in 1st 2 bytes
134-
x b = _b; rt = _b->rt; ss = i; // set base class members, for appl and anchor class use
135-
x gud = 1; // say space in use and record good
136-
x} // record::init
137-
#endif
138-
//-----------------------------------------------------------------------------
139109
int record::IsNameMatch( const char* _name) const
140110
{
141-
#if 0 // 7-2-2013
142-
x return strMatch( _name, name);
143-
#else
144111
// Note: prior (1994) version disregarded unexpected excess chars
145112
return !_strnicmp( _name, name, sizeof(ANAME)-1);
146-
#endif
147113
} // record::IsNameMatch
148114
//-----------------------------------------------------------------------------
149115
/*virtual*/ record& record::CopyFrom(
@@ -257,6 +223,17 @@ const char* record::getChoiTx(
257223

258224
} // record::getChoiTx
259225
//-----------------------------------------------------------------------------
226+
record* record::getOwner() const
227+
// return ptr to owner record
228+
// NULL if linkage bad
229+
{
230+
BP bOf = b->ownB;
231+
record* r = bOf ? bOf->GetAtSafe(ownTi) : NULL;
232+
if (!r)
233+
oer("getOwner() fail for %s", objIdTx());
234+
return r;
235+
} // record::getOwner
236+
//-----------------------------------------------------------------------------
260237
const char* record::whatIn() const // return basAnc record owner text
261238
// e.g. "zone 'Z1'" or "sgdist 'foo' of glazing 'gl1' of zone 'Z1'"
262239
{

src/ANCREC.H

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class basAnc // base class for record anchors: basAnc<recordName>
7070
// members set at construction only
7171
SFIR* fir; // pointer to record type's "small fields-in-record table" (in srfd.cpp)
7272
USI nFlds; // number of fields excluding base-class members (front overhead)
73-
char* what; // name of the record group (for probes, error messages)
73+
const char* what; // name of the record group (for probes, error messages)
7474
USI eSz; // record size
7575
USI sOff; // offset in record to "status byte" array at end
7676
USI ancN; // anchor number
@@ -262,6 +262,7 @@ class record // base class for records
262262

263263
RC oerI( int shoTx, int shoFnLn, int isWarn, const char* fmt, va_list ap) const;
264264

265+
record* getOwner() const;
265266
const char* whatIn() const;
266267
const char* objIdTx( int op=0) const;
267268
const char* classObjTx( int op=0) const;
@@ -306,6 +307,7 @@ template <class T> class anc : public basAnc
306307
virtual void * recMbr(TI i, USI off) { return (void *)((char *)(p + i) + off); } // point record i member by offset
307308
RC add( T **r, int erOp, TI i = 0) { return basAnc::add((record * *)r, erOp, i); }
308309
RC RunDup( const anc< T> &src, BP _ownB=NULL, int erOp=ABT);
310+
RC AllocResultsRecs(basAnc& src);
309311
void statSetup( T &r, TI n=1, SI noZ=0, SI inHeap=0) { basAnc::statSetup( r, n, noZ, inHeap); }
310312
int GetCount( int options=0) const;
311313

@@ -438,6 +440,32 @@ template <class T> RC anc<T>::RunDup( // duplicate records for run
438440
return rc;
439441
} // anc<T>::RunDup
440442
//-----------------------------------------------------------------------------
443+
template <class T> RC anc<T>::AllocResultsRecs( // allocate/init results records
444+
basAnc& src) // Source run records
445+
// allocates N+1 results record< T>s (1..N paired with run recs; N+1 = sum)
446+
// sets names to match src; 0s all values
447+
// returns RCOK iff success
448+
{
449+
RC rc = RCOK;
450+
int i = src.n + 1;
451+
rc = al(i, WRN); // alloc all recs at once for less fragmentation. destroys old.
452+
T* pR;
453+
if (!rc) do
454+
{ rc |= add(&pR, WRN, i); // init (to 0) results record, 1 thru i.
455+
const char* name;
456+
if (i > src.n)
457+
name = strtprintf("sum_of_%s", src.what);
458+
else
459+
{ name = src.rec(i).name;
460+
if (IsBlank(name))
461+
name = strtprintf("%s_%d", src.what, i);
462+
pR->SetName(name); // results records have same name as their source
463+
}
464+
} while (--i > 0);
465+
466+
return rc;
467+
} // anc< T>::AllocResultsRecs
468+
//-----------------------------------------------------------------------------
441469
#if defined( _DEBUG)
442470
template <class T> T* anc<T>::GetAt( int i) const
443471
{

0 commit comments

Comments
 (0)