well ... there are alternatives to "big switches" but the fact they are convenient depends case by case.
Think to different "actions" ("create this" / "create that") as different functions, and think to a table having the numbers you mention as key and function pointer as values
with an
std::map<unsigned, creatable* (createfn*)()> yourmap;
initialized appropriately, you can just create your objects (suppsed to derive from
shape
) as
creatable* newobject= yourmap[id]();
Similarly, every time you have to differentiate an action based on an ID you can use similar dispatch tables or -where a common interface exist- virtual functions.
In C++11 you can even declare
std::map<unsigned, std::function<creatable*> >
having the capability -at that point- to use whatever
functor type (classes implementing the
()
operator, or even lambda expressions) returning a
creatable*
...
Note that you can replace what I used to be
unsigned
(referring to numbers) with
std::string
to use textual identifiers