For simplicity you could do a std::vector<boost::any> for parameters.
void load(std::vector<boost::any>&)
void save(std::vector<boost::any>&)
void dostuff(std::vector<boost::any>&)
or you can do a parameters class
class Parameters {
public:
virtual unsigned int paramCount() const = 0;
};
class NoParameters : public Parameters {
public:
virtual unsigned int paramCount() const { return 0; };
};
class LoadParameters : public Parameters {
std::string filename_;
public:
LoadParameters(std::string const & f):filename_(f) {};
virtual unsigned int paramCount() const { return 1; };
std::string const & filename() const { return filename_; }
};
....
If your parameters are the same from invocation to invocation. A
boost::function from a map might cut it, or you could make a factory that
read the parameters from your command sequence, and created a function..
There are lots of implementations, if your commands were translated from
strings to ints perhaps enums, you could do the switching using templates..
--
Jesper Madsen, SAXoTECH
"The truth of the matter is that you always know the right thing to do. The
hard part is doing it"
- General H. Norman Schwartzoff
<sh*****@gmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
Hi
I have a list of strings in a file and I want to call different
functions according to each string I parsed from the file.
For example, if I read "LOAD" from the file, I should call void
read(void) . If I read "SAVE" from the file, I should call function
void save(string fileName).
I do not want to use switch here. Also, I know I may use map of
function pointers here.
typedef void (*Function_Ptr)(void );
typedef std::map<string, Function_Ptr> Processing_Map;
...
However, each function has different parameters, what's the best to
code the above case?
thanks