S
Simon Elliott
I have a class (actually the same one described in part 1) which
implements a state machine. The state machine is inside a pimpl, and
looks a bit like this:
class foo::fooImpl
{
public:
foo(void);
void StartBloggs(const BloggsType& bloggsStuff)
{
bloggsStuff_ = bloggsStuff;
state_ = 1;
}
void StartJimmy(const JimmyType& jimmyStuff)
{
jimmyStuff_ = jimmyStuff;
state_ = 2;
}
void Exec(void)
{
switch (state_)
{
case 1:
execBloggs();
break;
case 2:
execJimmy();
break;
}
}
private:
int state_;
BloggsType bloggsStuff_;
JimmyType jimmyStuff_;
void execBloggs();
void execJimmy();
};
As before, I now want to make this code a bit more generic. The problem
I now have is that some callers may want to only use the Jimmy code, and
others only want to use the Bloggs code. But anyone who links my class
gets the overhead of having both Bloggs and Jimmy, whether needed or
not. (In my example above, I could probably dynamically allocate the
state data bloggsStuff_ and jimmyStuff_, but I'm more interested in not
linking the execBloggs() and execJimmy() methods.)
Is there any way of only linking the stuff the user of the class needs,
and still keeping the pimpl in some shape or form?
implements a state machine. The state machine is inside a pimpl, and
looks a bit like this:
class foo::fooImpl
{
public:
foo(void);
void StartBloggs(const BloggsType& bloggsStuff)
{
bloggsStuff_ = bloggsStuff;
state_ = 1;
}
void StartJimmy(const JimmyType& jimmyStuff)
{
jimmyStuff_ = jimmyStuff;
state_ = 2;
}
void Exec(void)
{
switch (state_)
{
case 1:
execBloggs();
break;
case 2:
execJimmy();
break;
}
}
private:
int state_;
BloggsType bloggsStuff_;
JimmyType jimmyStuff_;
void execBloggs();
void execJimmy();
};
As before, I now want to make this code a bit more generic. The problem
I now have is that some callers may want to only use the Jimmy code, and
others only want to use the Bloggs code. But anyone who links my class
gets the overhead of having both Bloggs and Jimmy, whether needed or
not. (In my example above, I could probably dynamically allocate the
state data bloggsStuff_ and jimmyStuff_, but I'm more interested in not
linking the execBloggs() and execJimmy() methods.)
Is there any way of only linking the stuff the user of the class needs,
and still keeping the pimpl in some shape or form?