Hi,
I am trying to implement a class hierarchy where there will be a base class
defining the interface and some common operations (interface+impl entation):
Constraints : no STL. This will be implemented for an ARM processor for an
embedded application.
class ActorA: public Actor;
class ActorB: public Actor;
class ActorC: public Actor;
Actor {
virtual void decide() = 0;
void Preprocess();
virtual void Process() = 0;
}
Decide() and Process() are interfaces defined by this base class.
My problem is with the types associated with these actor objects. Internally
all these classes act on a two dimensional array of values of size (X, Y)
which will be configurable. SizeX and SizeY are in the order of 20-40. Each
element of the array can be a single value, two values, or 7 values. .
Specifically,
ActorA will act on a 2-D array of single values
ActorB will act on a 2-D array of doublets.
ActorC will act on a 2-D array of 7-lets.
The fact that you may have 1, 2, or 7 values only affect the decide()
function. The process() functions acts on each of these values independently
of the decision is made.
Possibilities:
1) Everything is a parameter
Actor::Actor(Si zeX, SizeY, N) {
// N : n-tuple
pArray = new int(SizeX*SizeY *N);
// Define access operators
// etc.
Actor will be general enough to do everything.
ActorX will be using the access operators etc. from Actor class and just
implement decide() and process().
2) Define a template
template <int SizeX, int SizeY, int N>
class Actor {
private:
int[SizeX][SizeY][N];
public:
Actor() {}
// etc.
Alll other actor classes will be inherited from this template base class. i
believe this is doable. No need to define access operators in this case.
Those are the two ideas I have. Later there may be a need to define other
Actors defining other decide/process pairs. As you realize, SizeX and Y are
not known at compile time, but N is known. I would be happy to find a way to
make the dependency on N specific to actors. Template based idea seems to do
it, but I am not sure...
Which one is better? Which is a better design? code size is a slightly
lesser issue than speed.
Thanks for the feedback.
Arcin
I am trying to implement a class hierarchy where there will be a base class
defining the interface and some common operations (interface+impl entation):
Constraints : no STL. This will be implemented for an ARM processor for an
embedded application.
class ActorA: public Actor;
class ActorB: public Actor;
class ActorC: public Actor;
Actor {
virtual void decide() = 0;
void Preprocess();
virtual void Process() = 0;
}
Decide() and Process() are interfaces defined by this base class.
My problem is with the types associated with these actor objects. Internally
all these classes act on a two dimensional array of values of size (X, Y)
which will be configurable. SizeX and SizeY are in the order of 20-40. Each
element of the array can be a single value, two values, or 7 values. .
Specifically,
ActorA will act on a 2-D array of single values
ActorB will act on a 2-D array of doublets.
ActorC will act on a 2-D array of 7-lets.
The fact that you may have 1, 2, or 7 values only affect the decide()
function. The process() functions acts on each of these values independently
of the decision is made.
Possibilities:
1) Everything is a parameter
Actor::Actor(Si zeX, SizeY, N) {
// N : n-tuple
pArray = new int(SizeX*SizeY *N);
// Define access operators
// etc.
Actor will be general enough to do everything.
ActorX will be using the access operators etc. from Actor class and just
implement decide() and process().
2) Define a template
template <int SizeX, int SizeY, int N>
class Actor {
private:
int[SizeX][SizeY][N];
public:
Actor() {}
// etc.
Alll other actor classes will be inherited from this template base class. i
believe this is doable. No need to define access operators in this case.
Those are the two ideas I have. Later there may be a need to define other
Actors defining other decide/process pairs. As you realize, SizeX and Y are
not known at compile time, but N is known. I would be happy to find a way to
make the dependency on N specific to actors. Template based idea seems to do
it, but I am not sure...
Which one is better? Which is a better design? code size is a slightly
lesser issue than speed.
Thanks for the feedback.
Arcin
Comment