1 // ***************************************************************************
2 // bamtools_options.h (c) 2010 Derek Barnett, Erik Garrison
3 // Marth Lab, Department of Biology, Boston College
4 // ---------------------------------------------------------------------------
5 // Last modified: 10 October 2011
6 // ---------------------------------------------------------------------------
7 // Parses command line arguments and creates a help menu
8 // ---------------------------------------------------------------------------
10 // The Mosaik suite's command line parser class: COptions
11 // (c) 2006 - 2009 Michael Str�mberg
12 // Marth Lab, Department of Biology, Boston College
13 // Re-licensed under MIT License with author's permission.
15 // * Modified slightly to fit BamTools, otherwise code is same.
16 // * (BamTools namespace, added stdin/stdout) (DB)
17 // ***************************************************************************
19 #ifndef BAMTOOLS_OPTIONS_H
20 #define BAMTOOLS_OPTIONS_H
22 #include "utils/bamtools_variant.h"
23 #include "utils/utils_global.h"
35 #define ARGUMENT_LENGTH 35
36 #define DESC_LENGTH_FIRST_ROW 30
37 #define DESC_LENGTH 42
38 #define MAX_LINE_LENGTH 78
41 #define snprintf _snprintf
42 typedef __int64 int64_t;
43 typedef unsigned __int64 uint64_t;
44 #define strtoui64 _strtoui64
46 #define strtoui64 strtoull
49 struct UTILS_EXPORT Option {
53 std::string ValueDescription;
54 std::string Description;
62 , HasDefaultValue(false)
66 struct UTILS_EXPORT OptionValue {
71 std::string ValueTypeDescription;
79 : pFoundArgument(NULL)
87 struct UTILS_EXPORT OptionGroup {
89 std::vector<Option> Options;
92 class UTILS_EXPORT Options {
94 // add option/argument rules
96 // adds a simple option to the parser
97 static void AddOption(const std::string& argument,
98 const std::string& optionDescription,
102 // adds a value option to the parser
104 static void AddValueOption(const std::string& argument,
105 const std::string& valueDescription,
106 const std::string& optionDescription,
107 const std::string& valueTypeDescription,
112 // adds a value option to the parser (with a default value)
113 template<typename T, typename D>
114 static void AddValueOption(const std::string& argument,
115 const std::string& valueDescription,
116 const std::string& optionDescription,
117 const std::string& valueTypeDescription,
125 // creates an option group
126 static OptionGroup* CreateOptionGroup(const std::string& groupName);
127 // displays the help menu
128 static void DisplayHelp(void);
129 // parses the command line
130 static void Parse(int argc, char* argv[], int offset = 0);
131 // sets the program info
132 static void SetProgramInfo(const std::string& programName,
133 const std::string& description,
134 const std::string& arguments);
135 // returns string representation of stdin
136 static const std::string& StandardIn(void);
137 // returns string representation of stdout
138 static const std::string& StandardOut(void);
140 // static data members
143 static std::string m_programName;
144 // the main description
145 static std::string m_description;
146 // the example arguments
147 static std::string m_exampleArguments;
148 // stores the option groups
149 static std::vector<OptionGroup> m_optionGroups;
150 // stores the options in a map
151 static std::map<std::string, OptionValue> m_optionsMap;
152 // string representation of stdin
153 static const std::string m_stdin;
154 // string representation of stdout
155 static const std::string m_stdout;
158 // adds a value option to the parser
160 void Options::AddValueOption(const std::string& argument,
161 const std::string& valueDescription,
162 const std::string& optionDescription,
163 const std::string& valueTypeDescription,
169 o.Argument = argument;
170 o.ValueDescription = valueDescription;
171 o.Description = optionDescription;
172 group->Options.push_back(o);
175 ov.pFoundArgument = &foundArgument;
176 ov.pValue = (void*)&val;
177 ov.VariantValue = val;
178 ov.IsRequired = (valueTypeDescription.empty() ? false : true);
179 ov.ValueTypeDescription = valueTypeDescription;
180 m_optionsMap[argument] = ov;
183 // adds a value option to the parser (with a default value)
184 template<typename T, typename D>
185 void Options::AddValueOption(const std::string& argument,
186 const std::string& valueDescription,
187 const std::string& optionDescription,
188 const std::string& valueTypeDescription,
195 o.Argument = argument;
196 o.ValueDescription = valueDescription;
197 o.Description = optionDescription;
198 o.DefaultValue = defaultValue;
199 o.HasDefaultValue = true;
200 group->Options.push_back(o);
203 ov.pFoundArgument = &foundArgument;
204 ov.pValue = (void*)&val;
205 ov.VariantValue = val;
206 ov.IsRequired = (valueTypeDescription.empty() ? false : true);
207 ov.ValueTypeDescription = valueTypeDescription;
208 m_optionsMap[argument] = ov;
211 } // namespace BamTools
213 #endif // BAMTOOLS_OPTIONS_H