Is there an easy way in C++ to have a message lookup table that allows the use of variables.
For example in C you can have something like this:
const char* transaction_messages[] = {
"UNAUTHORIZED",
"UNKNOWN_ORDER",
"UNKNOWN_DEALER",
"UNKNOWN_COMMODITY",
"INVALID_MESSAGE",
"BOUGHT %d %s @ %f.1 FROM %s", //amount, commodity, price, dealer
"SOLD %d %s @ %f.1 FROM %s", //amount, commodity, price, dealer
"%d HAS BEEN FILLED", //order id
"%d HAS BEEN REVOKED", //order id
"%d %s %s %s %d %f.1 HAS BEEN POSTED", //order id, dealer, side, commodity, amount, price
"%d %s %s %s %d %f.1" //order id, dealer, side, commodity, amount, price
};
and then use it in a function like thislike this:
void myfunction(int amount, char* commodity, double price, char* dealer){
char *msg = transaction_message[6];
printf(msg, amount, commodity, price, dealer);
}
I want to be able to do the same with an ostream instead of having to do something with the << operator where the same thing would look like:
ostream << "BOUGHT" << amount << " " << commodity << " @ " << price << " FROM " << dealer;
the only way I can think of doing this right now would be to have a bunch of inline functions that return strings and instead of having a char* table instead have a function table that looks up the inline functions. There must be an easier way tho.