1 // ***************************************************************************
2 // bamtools_options.h (c) 2010 Derek Barnett, Erik Garrison
3 // Marth Lab, Department of Biology, Boston College
4 // All rights reserved.
5 // ---------------------------------------------------------------------------
6 // Last modified: 19 November 2010
7 // ---------------------------------------------------------------------------
8 // Parses command line arguments and creates a help menu
9 // ---------------------------------------------------------------------------
11 // The Mosaik suite's command line parser class: COptions
12 // (c) 2006 - 2009 Michael Str�mberg
13 // Marth Lab, Department of Biology, Boston College
14 // Re-licensed under MIT License with author's permission.
16 // * Modified slightly to fit BamTools, otherwise code is same.
17 // * (BamTools namespace, added stdin/stdout) (DB)
18 // ***************************************************************************
20 #ifndef BAMTOOLS_OPTIONS_H
21 #define BAMTOOLS_OPTIONS_H
23 #include <utils/bamtools_variant.h>
24 #include <utils/utils_global.h>
36 #define ARGUMENT_LENGTH 35
37 #define DESC_LENGTH_FIRST_ROW 50
38 #define DESC_LENGTH 39
39 #define MAX_LINE_LENGTH 78
42 #define snprintf _snprintf
43 typedef __int64 int64_t;
44 typedef unsigned __int64 uint64_t;
45 #define strtoui64 _strtoui64
47 #define strtoui64 strtoull
50 struct UTILS_EXPORT Option {
54 std::string ValueDescription;
55 std::string Description;
63 , HasDefaultValue(false)
67 struct UTILS_EXPORT OptionValue {
72 std::string ValueTypeDescription;
80 : pFoundArgument(NULL)
88 struct UTILS_EXPORT OptionGroup {
90 std::vector<Option> Options;
93 class UTILS_EXPORT Options {
95 // add option/argument rules
97 // adds a simple option to the parser
98 static void AddOption(const std::string& argument,
99 const std::string& optionDescription,
103 // adds a value option to the parser
105 static void AddValueOption(const std::string& argument,
106 const std::string& valueDescription,
107 const std::string& optionDescription,
108 const std::string& valueTypeDescription,
113 // adds a value option to the parser (with a default value)
114 template<typename T, typename D>
115 static void AddValueOption(const std::string& argument,
116 const std::string& valueDescription,
117 const std::string& optionDescription,
118 const std::string& valueTypeDescription,
126 // creates an option group
127 static OptionGroup* CreateOptionGroup(const std::string& groupName);
128 // displays the help menu
129 static void DisplayHelp(void);
130 // parses the command line
131 static void Parse(int argc, char* argv[], int offset = 0);
132 // sets the program info
133 static void SetProgramInfo(const std::string& programName, const std::string& description, const std::string& arguments);
134 // returns string representation of stdin
135 static const std::string& StandardIn(void);
136 // returns string representation of stdout
137 static const std::string& StandardOut(void);
139 // static data members
142 static std::string m_programName;
143 // the main description
144 static std::string m_description;
145 // the example arguments
146 static std::string m_exampleArguments;
147 // stores the option groups
148 static std::vector<OptionGroup> m_optionGroups;
149 // stores the options in a map
150 static std::map<std::string, OptionValue> m_optionsMap;
151 // string representation of stdin
152 static std::string m_stdin;
153 // string representation of stdout
154 static std::string m_stdout;
157 // adds a value option to the parser
159 void Options::AddValueOption(const std::string& argument,
160 const std::string& valueDescription,
161 const std::string& optionDescription,
162 const std::string& valueTypeDescription,
168 o.Argument = argument;
169 o.ValueDescription = valueDescription;
170 o.Description = optionDescription;
171 group->Options.push_back(o);
174 ov.pFoundArgument = &foundArgument;
175 ov.pValue = (void*)&val;
176 ov.VariantValue = val;
177 ov.IsRequired = (valueTypeDescription.empty() ? false : true);
178 ov.ValueTypeDescription = valueTypeDescription;
179 m_optionsMap[argument] = ov;
182 // adds a value option to the parser (with a default value)
183 template<typename T, typename D>
184 void Options::AddValueOption(const std::string& argument,
185 const std::string& valueDescription,
186 const std::string& optionDescription,
187 const std::string& valueTypeDescription,
194 o.Argument = argument;
195 o.ValueDescription = valueDescription;
196 o.Description = optionDescription;
197 o.DefaultValue = defaultValue;
198 o.HasDefaultValue = true;
199 group->Options.push_back(o);
202 ov.pFoundArgument = &foundArgument;
203 ov.pValue = (void*)&val;
204 ov.VariantValue = val;
205 ov.IsRequired = (valueTypeDescription.empty() ? false : true);
206 ov.ValueTypeDescription = valueTypeDescription;
207 m_optionsMap[argument] = ov;
210 } // namespace BamTools
212 #endif // BAMTOOLS_OPTIONS_H