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: 11 June 2011
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 30
38 #define DESC_LENGTH 42
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,
134 const std::string& description,
135 const std::string& arguments);
136 // returns string representation of stdin
137 static const std::string& StandardIn(void);
138 // returns string representation of stdout
139 static const std::string& StandardOut(void);
141 // static data members
144 static std::string m_programName;
145 // the main description
146 static std::string m_description;
147 // the example arguments
148 static std::string m_exampleArguments;
149 // stores the option groups
150 static std::vector<OptionGroup> m_optionGroups;
151 // stores the options in a map
152 static std::map<std::string, OptionValue> m_optionsMap;
153 // string representation of stdin
154 static const std::string m_stdin;
155 // string representation of stdout
156 static const std::string m_stdout;
159 // adds a value option to the parser
161 void Options::AddValueOption(const std::string& argument,
162 const std::string& valueDescription,
163 const std::string& optionDescription,
164 const std::string& valueTypeDescription,
170 o.Argument = argument;
171 o.ValueDescription = valueDescription;
172 o.Description = optionDescription;
173 group->Options.push_back(o);
176 ov.pFoundArgument = &foundArgument;
177 ov.pValue = (void*)&val;
178 ov.VariantValue = val;
179 ov.IsRequired = (valueTypeDescription.empty() ? false : true);
180 ov.ValueTypeDescription = valueTypeDescription;
181 m_optionsMap[argument] = ov;
184 // adds a value option to the parser (with a default value)
185 template<typename T, typename D>
186 void Options::AddValueOption(const std::string& argument,
187 const std::string& valueDescription,
188 const std::string& optionDescription,
189 const std::string& valueTypeDescription,
196 o.Argument = argument;
197 o.ValueDescription = valueDescription;
198 o.Description = optionDescription;
199 o.DefaultValue = defaultValue;
200 o.HasDefaultValue = true;
201 group->Options.push_back(o);
204 ov.pFoundArgument = &foundArgument;
205 ov.pValue = (void*)&val;
206 ov.VariantValue = val;
207 ov.IsRequired = (valueTypeDescription.empty() ? false : true);
208 ov.ValueTypeDescription = valueTypeDescription;
209 m_optionsMap[argument] = ov;
212 } // namespace BamTools
214 #endif // BAMTOOLS_OPTIONS_H