00001 #pragma once
00002
00003 #include "common.h"
00004 #include <iostream>
00005 #include <map>
00006
00008
00013 class Arguments
00014 {
00015 friend std::ostream & operator << (std::ostream & os, const Arguments & argArguments);
00016
00017 public:
00018
00019 Arguments(int argc = 0, char **argv = NULL) : m_strApplicationFilename("VisLuFramework.exe")
00020 {
00021 if (argc > 0)
00022 {
00023 m_strApplicationFilename = argv[0];
00024
00025 for (int i=1;i<argc;i++)
00026 {
00027 const std::string strArgument = trim(argv[i]);
00028
00029 if (strArgument.size() > 1)
00030 {
00031 if (strArgument[0] == '-')
00032 {
00033 const std::string strOptionName = trim(strArgument.substr(1,strArgument.size()-1));
00034
00035 if (i < argc-1)
00036 {
00037 const std::string strOptionValue = trim(argv[i+1]);
00038 m_mapOptions[strOptionName] = strOptionValue;
00039 i++;
00040 }
00041 }
00042
00043 }
00044 }
00045 }
00046 };
00047
00048 ~Arguments()
00049 {
00050
00051 };
00052
00053 void SetApplicationFilename(const std::string & strApplicationFilename)
00054 {
00055 m_strApplicationFilename = strApplicationFilename;
00056 };
00057
00058 const std::string & GetApplicationFilename() const
00059 {
00060 return m_strApplicationFilename;
00061 };
00062
00063 const bool HasOption(const std::string & strOptionName) const
00064 {
00065 return m_mapOptions.find(strOptionName) != m_mapOptions.end();
00066 };
00067
00068 void SetOption(const std::string & strOptionName, const std::string & strOptionValue)
00069 {
00070 m_mapOptions[strOptionName] = strOptionValue;
00071 };
00072
00073 const std::string GetOption(const std::string & strOptionName) const
00074 {
00075 std::map<std::string,std::string>::const_iterator i = m_mapOptions.find(strOptionName);
00076
00077 if (i != m_mapOptions.end())
00078 return i->second;
00079
00080 return std::string();
00081 };
00082
00083 private:
00084 std::string m_strApplicationFilename;
00085 std::map<std::string,std::string> m_mapOptions;
00086 };
00087
00088 inline std::ostream & operator << (std::ostream & os, const Arguments & argArguments)
00089 {
00090 if (argArguments.GetApplicationFilename().find(" ") != std::string::npos)
00091 os << "\"" << argArguments.GetApplicationFilename() << "\"";
00092 else
00093 os << argArguments.GetApplicationFilename();
00094
00095
00096 for (std::map<std::string,std::string>::const_iterator i=argArguments.m_mapOptions.begin();i!=argArguments.m_mapOptions.end();i++)
00097 {
00098 if (i->second.find(" ") != std::string::npos)
00099 os << " -" << i->first << " " << "\"" << i->second << "\"";
00100 else
00101 os << " -" << i->first << " " << i->second;
00102 }
00103
00104 return os;
00105 }
00106