Posting the complete objects would take a lot of space, and give a lot of unnecessary information, so I'll post snippets, if that's OK. But first, a (long overdue) explanation:
The complete data structure is several classes deep. A given container class, upon construction, needs to invoke the constructors of the classes it contains. (We're not talking parent/sub class relationship; just a heirarchy to the data structure.)
The first wrinkle in this is that one class, the DemodNyq, will contain a vector of objects of the class DemodNyqCell. DemodNyqCell has a vector containing a combination of (parent class) NyqMultBlock and (subclass) NmbDelay elements.
HOWEVER:
Not all DemodNyq objects will contain the same combination of these two classes. Some will have 8 of one, and 0 of the other, others will have different combinations. I have tried to solve this by passing an argument to the DemodNyqCell constructor, telling it how many to make of each.
So, with this as background (I hope it made sense), here's some code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
class DemodNyq {
private:
vector<DemodNyqCell> cells;
vector<int32_t> inpBuffer;
vector<int32_t> coeffBuffer;
public:
DemodNyq(int32_t rv);
DemodNyq(const DemodNyq &d);
~DemodNyq();
.
.
.
DemodNyq::DemodNyq(int32_t rv)
{
int32_t delayCount; // how many of the NyqMultBlocks contain delays
DemodNyqCell* pCell;
cells.reserve(DEM_NYQ_NBR_CELLS);
for (int i = 0; i < DEM_NYQ_NBR_CELLS; ++i)
{
delayCount = min(16 - i, 8);
pCell = new (DemodNyqCell);
*pCell = DemodNyqCell(rv, delayCount);
cells.push_back(*pCell);
}
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
class DemodNyqCell
{
private:
vector<NyqMultBlock *> blocks;
FlipFlopReg32 sum;
int32_t resetValue;
public:
DemodNyqCell(int32_t rv = 0, int32_t delay = 0); // default constructor
.
.
.
DemodNyqCell::DemodNyqCell(int32_t rv, int32_t delay) // default constructor
: sum(rv), resetValue(rv)
{
NyqMultBlock* pBlock;
blocks.reserve(DEMOD_NYQ_NBR_BLOCKS);
for (int i = 0; i <= DEMOD_NYQ_NBR_BLOCKS; ++i)
{
if (i < delay)
pBlock = new (NmbDelay);
else
pBlock = new (NyqMultBlock);
*pBlock = NyqMultBlock(rv);
blocks.push_back(pBlock);
}
}
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
class NyqMultBlock // base class; no delay register
{
protected:
FlipFlopReg32 regProduct;
public:
NyqMultBlock(int32_t rv=0); // constructor w/ reset parameter
NyqMultBlock (const NyqMultBlock &nmb); // copy constructor
~NyqMultBlock(); // destructor
void cycle(int32_t inp,
int32_t coeff,
bool clockEnable,
bool resetFlag);
void reset();
void display();
int32_t get();
};
class NmbDelay : public NyqMultBlock // inherited class w/ delay register.
{
private:
FlipFlopReg32 regDelay;
public:
NmbDelay(int32_t rv=0);
NmbDelay(const NmbDelay &nmbd);
~NmbDelay();
void cycle(int32_t inp,
int32_t coeff,
bool clockEnable,
bool resetFlag);
void reset();
void display();
};
// I can include the code as well for this, if you're interested.
|
This at least compiles and survives the constructions; I haven't exercised it enough yet to know if it works right.