Go to the documentation of this file.00001
00002
00003 #if !defined(CommandLineParser_H)
00004 #define CommandLineParser_H
00005
00006 #include "PhysicsTools/FWLite/interface/VariableMapCont.h"
00007
00008 namespace optutl
00009 {
00010
00011 class CommandLineParser : public VariableMapCont
00012 {
00013 public:
00015
00017
00018 static const std::string kSpaces;
00019
00020 enum
00021 {
00022 kEventContOpt = 1 << 0
00023 };
00024
00026
00028
00029 friend std::ostream& operator<< (std::ostream& o_stream,
00030 const CommandLineParser &rhs);
00031
00033
00034
00035
00036
00038
00040
00042 CommandLineParser (const std::string &usage,
00043 unsigned int optionsType = kEventContOpt);
00044
00046
00048
00049
00050 void setPrintOptoins (bool print) { m_printOptions = print; }
00051
00052
00053 const SVec argVec() const { return m_fullArgVec; }
00054
00056
00058
00059
00060
00061 void parseArguments (int argc, char** argv, bool allowArgs = false);
00062
00063
00064 void help();
00065
00066
00067 void printOptionValues();
00068
00069
00070
00071
00072
00073 void _finishDefaultOptions (std::string tag = "");
00074
00076
00078
00079
00080 static std::string removeEnding (const std::string &input,
00081 const std::string &ending);
00082
00083
00084 static void split (SVec &retval, std::string line,
00085 std::string match = " \t",
00086 bool ignoreComments = true);
00087
00088
00089 static void removeComment (std::string &line);
00090
00091
00092 static void removeLeadingAndTrailingSpaces (std::string &line);
00093
00094
00095 static void findCommand (const std::string &line,
00096 std::string &command,
00097 std::string &rest);
00098
00099
00100 private:
00102
00104
00105
00106
00107
00108
00109
00110
00111 bool _setVariableFromString (const std::string &arg,
00112 bool dontOverrideChange = false,
00113 int offset = 0);
00114
00115
00116
00117 bool _setVariablesFromFile (const std::string &filename);
00118
00119
00120 bool _runVariableCommandFromString (const std::string &arg);
00121
00122
00123
00124
00125 void _getSectionFiles (const SVec &inputList, SVec &outputList,
00126 int section, int totalSection);
00127
00129
00131 SVec m_fullArgVec;
00132 std::string m_argv0;
00133 std::string m_usageString;
00134 bool m_printOptions;
00135 unsigned int m_optionsType;
00136
00137 };
00138
00139 }
00140
00141 #endif // CommandLineParser_H