Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ICommandVar {
- public:
- virtual ~ICommandVar() = default;
- virtual std::string GetName() = 0;
- };
- template <class T>
- class CommandVar : virtual public ICommandVar {
- public:
- CommandVar<T>(const char* name, T* defaultValue);
- std::string GetName() override;
- protected:
- std::string name_;
- T defaultValue_;
- T* currentValue_;
- };
- template <class T>
- CommandVar<T>::CommandVar(const char* name, T* defaultValue) : name_(name), defaultValue_(*defaultValue),currentValue_(defaultValue) {
- config::AddCommandVar(this);
- }
- namespace config {
- std::map<std::string, ICommandVar*>* CmdVars;
- void AddCommandVar(ICommandVar* cv) {
- if (!CmdVars) CmdVars = new std::map<std::string, ICommandVar*>();
- CmdVars->insert(std::pair<std::string, ICommandVar*>(cv->GetName(), cv));
- }
- void ParseLaunchArguments(int argc, char** argv) {
- for (auto& it : *CmdVars) {
- auto cmdVar = it.second;
- //cmdVar is a nullPtr here, cmdVar->GetName() fails
- }
- }
- template <typename T>
- T* declare_cmdvar(const char* name, T* defaultValue) {
- new CommandVar<T>(name, defaultValue);
- return defaultValue;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement