program design issue

This is something I've been mildly wrestling with for some time.

I'm writing a simulator for an ASIC modem, which of course is composed of many components and subcomponents. My class hierarchy is up to five levels deep. One of the components represents a block of coefficients which are periodically updated and retrieved by calls from other components.

The problem: how do I make this coefficients object visible to the rest of the classes in the program?

The rules:

1. I must have only one copy of this object.
2. It must be accessible to various other objects all over the class hierarchy.
3. It has to be within one program (no RPC calls or anything like that).
4. All values initialized at startup from reading a file (no biggie).

Any ideas on how to go about this?

Thanks for any suggestions.
Make it a global in one file. Put extern declarations in all the other files.
OK, I might need a little walkthrough on this. In my current implementation, the host (coefficients) class look like this:

(header file)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
enum	hostOffsets	 {
	COEFF_DEMOD_NYQ_00_03,
	COEFF_DEMOD_NYQ_04_07,
	COEFF_DEMOD_AGC,
	COEFF_DEMOD_SYMB_PHASE_00,
.
.
.
};

class Host
{
	std::vector<FlipFlopReg32>		hostValues;
public:
	Host (long rv = 0);			//  constructor
	Host (const Host &host);	// copy constructor
	~Host();						// destructor
	long	get(int i);
};


The get function looks like this:

1
2
3
long	Host::get(int i)	// return a single register
{
	return (hostValues.at(i).get());


So, as you can see, all the coefficients are stored in a big array. Accessing classes include the header file to get the correct offset for the coeff they want, and make a call to get().

So...how do I make this "global?" Instantiate an object of this class in the program file?

And then, I guess I'd add an extern reference to the object in the header file? Am I on the right track?

Thanks for responding.

OK, I just experimented with it, and it seems to work. I created an object called "host" in my top-level file, and in my host.h (after the class declaration), I do an external reference. That was easier than I thought. Thanks, Rocket.
Topic archived. No new replies allowed.