00001 #pragma once
00002
00003 #include "common.h"
00004 #include <iostream>
00005 #include <map>
00006
00007
00008
00009 class Arguments
00010 {
00011 friend std::ostream & operator << (std::ostream & os, const Arguments & argArguments);
00012
00013 public:
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
00051 ~Arguments()
00052 {
00053
00054 };
00055
00060 void SetApplicationFilename(const std::string & strApplicationFilename)
00061 {
00062 m_strApplicationFilename = strApplicationFilename;
00063 };
00064
00069 const std::string & GetApplicationFilename() const
00070 {
00071 return m_strApplicationFilename;
00072 };
00073
00079 const bool HasOption(const std::string & strOptionName) const
00080 {
00081 return m_mapOptions.find(strOptionName) != m_mapOptions.end();
00082 };
00083
00089 void SetOption(const std::string & strOptionName, const std::string & strOptionValue)
00090 {
00091 m_mapOptions[strOptionName] = strOptionValue;
00092 };
00093
00099 const std::string GetOption(const std::string & strOptionName) const
00100 {
00101 std::map<std::string,std::string>::const_iterator i = m_mapOptions.find(strOptionName);
00102
00103 if (i != m_mapOptions.end())
00104 return i->second;
00105
00106 return std::string();
00107 };
00108
00109 private:
00111 std::string m_strApplicationFilename;
00113 std::map<std::string,std::string> m_mapOptions;
00114 };
00115
00116 inline std::ostream & operator << (std::ostream & os, const Arguments & argArguments)
00117 {
00118 if (argArguments.GetApplicationFilename().find(" ") != std::string::npos)
00119 os << "\"" << argArguments.GetApplicationFilename() << "\"";
00120 else
00121 os << argArguments.GetApplicationFilename();
00122
00123
00124 for (std::map<std::string,std::string>::const_iterator i=argArguments.m_mapOptions.begin();i!=argArguments.m_mapOptions.end();i++)
00125 {
00126 if (i->second.find(" ") != std::string::npos)
00127 os << " -" << i->first << " " << "\"" << i->second << "\"";
00128 else
00129 os << " -" << i->first << " " << i->second;
00130 }
00131
00132 return os;
00133 }
00134