You'd probably want to use a [constant] string to hold the default values, unless there are a lot of them.
You'd probably want to use a [constant] string to hold the default values, unless there are a lot of them.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
Are these settings known at compile time? In other words, do you know what settings your program needs when you write the program? I'm not talking about the values entered by the user, I'm talking about what those values mean. Can the user type in anything they want, or does it have to have meaning? If it has specific meaning, create a variable for each specific setting. That variable can be a class that holds the name, type, and value. That class can set the value to the default and then provide a function to change the value if the user enters something different. You can have a different class if you want for the different types of settings (string, int, or whatever), but you do that at compile time instead of using a variant that doesn't know what it is until run-time.
I have a config file reader class that a friend of mine coded. Internally it stores everything as strings, in a std::map<std::string, std::string>, where the first string is the name of the setting, and the second is the value.
The public interface of the class, however, has functions like GetInt(std::string name) which basically does string->int conversion. How you handle failure is up to you -- you can return 0, you could throw an exception, or you could set an error flag. You could even have a second parameter which specifies the default value, which is returned if the variable doesn't exist/isn't an integer (which actually is a pretty decent way of doing things).
Likewise, there are SetInt() and such functions as well. They convert the int to a string and store it in the map.
You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.
Thats what I work on. Except I want to have vector string for settings since there may be more options for each.Originally Posted by Cat