• Main Page
  • Classes
  • Files
  • File List

T:/Eigene Dateien/Visual Studio 2008/Projects/VisLuFramework/src/Arguments.h

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

Generated on Tue Dec 14 2010 03:52:55 for VolVis by  doxygen 1.7.2