Complete the initialization sequence. This is a mainly a matter of calculating how member space within hdbObject will be arranged. Members are assigned space that depends on the datatype and max population, and they are given relative positions that ensure the correct byte alignment. To this end the members are first sorted by datum size ... Arguments: None
| Return Type | Function name | Arguments |
|---|---|---|
| hzEcode | hdbClass::InitDone | (void) |
Declared in file: hzDatabase.h
Defined in file : hdbClass.cpp
Function Logic:
Function body:
hzEcode hdbClass::InitDone (void)
{
// Complete the initialization sequence.
//
// This is a mainly a matter of calculating how member space within hdbObject will be arranged. Members are assigned space that depends on the datatype and max population, and
// they are given relative positions that ensure the correct byte alignment. To this end the members are first sorted by datum size ...
//
// Arguments: None
//
// Returns: E_SEQUENCE If this function is not called after a successful InitStart() and InitMember()
// E_OK If this function terminates an open initialization sequence
_hzfunc("hdbClass::InitDone") ;
const hdbMember* pMbr ; // Member pointer
uint32_t mbrNo ; // Member number
uint32_t nSofar ; // For adding up total core space needed by all members
// Check init sequence
if (m_eClassInit != HDB_CLASS_INIT_PROG)
return hzerr(E_SEQUENCE, "Called out of sequence (must be after InitStart() and at least one call to InitMember()") ;
// Allocate member space within hdbObject core. Start with 16-byte entities if any, then 8, then 4. Leave ENUM till last as a special case.
nSofar = 0;
// m_nNonBool = 0 ;
// Allocate 16-byte slots
for (mbrNo = 0; mbrNo < m_arrMembers.Count() ; mbrNo++)
{
pMbr = m_arrMembers[mbrNo] ;
if (pMbr->Basetype() == BASETYPE_ENUM)
continue ;
if (pMbr->SizeCore() < 16)
continue ;
pMbr->_setOset(nSofar) ;
nSofar += 16;
}
// Allocate 8-byte slots, including the aux slot for BINARY/TXTDOC members
for (mbrNo = 0; mbrNo < m_arrMembers.Count() ; mbrNo++)
{
pMbr = m_arrMembers[mbrNo] ;
if (pMbr->Basetype() == BASETYPE_ENUM)
continue ;
if (pMbr->Basetype() == BASETYPE_BINARY || pMbr->Basetype() == BASETYPE_TXTDOC)
{
pMbr->_setAux(nSofar) ;
nSofar += 8;
continue ;
}
if (pMbr->SizeCore() != 8)
continue ;
pMbr->_setOset(nSofar) ;
nSofar += 8;
}
// Allocate 4-byte slots
for (mbrNo = 0; mbrNo < m_arrMembers.Count() ; mbrNo++)
{
pMbr = m_arrMembers[mbrNo] ;
if (pMbr->Basetype() == BASETYPE_BINARY || pMbr->Basetype() == BASETYPE_TXTDOC)
{
// Allocate space for binary datum id
pMbr->_setOset(nSofar) ;
nSofar += 4;
continue ;
}
if (pMbr->Basetype() == BASETYPE_ENUM)
continue ;
if (pMbr->SizeCore() != 4)
continue ;
pMbr->_setOset(nSofar) ;
nSofar += 4;
}
// 2-byte allocations
for (mbrNo = 0; mbrNo < m_arrMembers.Count() ; mbrNo++)
{
pMbr = m_arrMembers[mbrNo] ;
if (pMbr->Basetype() == BASETYPE_ENUM)
continue ;
if (pMbr->SizeCore() != 2)
continue ;
pMbr->_setOset(nSofar) ;
nSofar += 2;
}
// Enums
for (mbrNo = 0; mbrNo < m_arrMembers.Count() ; mbrNo++)
{
pMbr = m_arrMembers[mbrNo] ;
if (pMbr->Basetype() != BASETYPE_ENUM)
continue ;
pMbr->_setOset(nSofar) ;
nSofar += pMbr->SizeCore() ;
}
// Bools
for (mbrNo = 0; mbrNo < m_arrMembers.Count() ; mbrNo++)
{
pMbr = m_arrMembers[mbrNo] ;
if (pMbr->Basetype() == BASETYPE_BOOL)
continue ;
if (pMbr->Basetype() == BASETYPE_TBOOL)
{
// pMbr->_setOset(nSofar) ;
// nSofar += 1 ;
m_nLitmusBits++ ;
continue ;
}
// m_nNonBool++ ;
}
// Core len is total core size
m_nLitmusBits += m_arrMembers.Count() ;
m_nLitmusSize = m_nLitmusBits/8;
if (m_nLitmusBits%8)
m_nLitmusSize++ ;
m_nCoreLen = nSofar ;
// Report class form
for (mbrNo = 0; mbrNo < m_arrMembers.Count() ; mbrNo++)
{
pMbr = m_arrMembers[mbrNo] ;
threadLog("Mbr %u %s: Posn %u Datum %u Core %u oset %d aux %d\n", mbrNo, pMbr->txtName(), pMbr->Posn(), pMbr->SizeDatum(), pMbr->SizeCore(), pMbr->OsetStd(), pMbr->OsetAux()) ;
}
threadLog("Class %s complete, core len %u\n", txtName(), m_nCoreLen) ;
// Move to Register Class
// hzChain desc ;
// DescClass(desc, 0) ;
// m_Desc = desc ;
// Indicate that class init is complete
m_eClassInit = HDB_CLASS_INIT_DONE ;
return E_OK ;
}