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: 7 September 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
26 #include "bamtools_variant.h"
34 #define ARGUMENT_LENGTH 35
35 #define DESC_LENGTH_FIRST_ROW 50
36 #define DESC_LENGTH 39
37 #define MAX_LINE_LENGTH 78
40 #define snprintf _snprintf
41 typedef __int64 int64_t;
42 typedef unsigned __int64 uint64_t;
43 #define strtoui64 _strtoui64
45 #define strtoui64 strtoull
52 std::string ValueDescription;
53 std::string Description;
61 , HasDefaultValue(false)
70 std::string ValueTypeDescription;
78 : pFoundArgument(NULL)
88 std::vector<Option> Options;
93 // add option/argument rules
95 // adds a simple option to the parser
96 static void AddOption(const std::string& argument,
97 const std::string& optionDescription,
101 // adds a value option to the parser
103 static void AddValueOption(const std::string& argument,
104 const std::string& valueDescription,
105 const std::string& optionDescription,
106 const std::string& valueTypeDescription,
111 // adds a value option to the parser (with a default value)
112 template<typename T, typename D>
113 static void AddValueOption(const std::string& argument,
114 const std::string& valueDescription,
115 const std::string& optionDescription,
116 const std::string& valueTypeDescription,
124 // creates an option group
125 static OptionGroup* CreateOptionGroup(const std::string& groupName);
126 // displays the help menu
127 static void DisplayHelp(void);
128 // parses the command line
129 static void Parse(int argc, char* argv[], int offset = 0);
130 // sets the program info
131 static void SetProgramInfo(const std::string& programName, const std::string& description, const std::string& arguments);
132 // returns string representation of stdin
133 static const std::string& StandardIn(void);
134 // returns string representation of stdout
135 static const std::string& StandardOut(void);
137 // static data members
140 static std::string m_programName;
141 // the main description
142 static std::string m_description;
143 // the example arguments
144 static std::string m_exampleArguments;
145 // stores the option groups
146 static std::vector<OptionGroup> m_optionGroups;
147 // stores the options in a map
148 static std::map<std::string, OptionValue> m_optionsMap;
149 // string representation of stdin
150 static std::string m_stdin;
151 // string representation of stdout
152 static std::string m_stdout;
155 // adds a value option to the parser
157 void Options::AddValueOption(const std::string& argument,
158 const std::string& valueDescription,
159 const std::string& optionDescription,
160 const std::string& valueTypeDescription,
166 o.Argument = argument;
167 o.ValueDescription = valueDescription;
168 o.Description = optionDescription;
169 group->Options.push_back(o);
172 ov.pFoundArgument = &foundArgument;
173 ov.pValue = (void*)&val;
174 ov.VariantValue = val;
175 ov.IsRequired = (valueTypeDescription.empty() ? false : true);
176 ov.ValueTypeDescription = valueTypeDescription;
177 m_optionsMap[argument] = ov;
180 // adds a value option to the parser (with a default value)
181 template<typename T, typename D>
182 void Options::AddValueOption(const std::string& argument,
183 const std::string& valueDescription,
184 const std::string& optionDescription,
185 const std::string& valueTypeDescription,
192 o.Argument = argument;
193 o.ValueDescription = valueDescription;
194 o.Description = optionDescription;
195 o.DefaultValue = defaultValue;
196 o.HasDefaultValue = true;
197 group->Options.push_back(o);
200 ov.pFoundArgument = &foundArgument;
201 ov.pValue = (void*)&val;
202 ov.VariantValue = val;
203 ov.IsRequired = (valueTypeDescription.empty() ? false : true);
204 ov.ValueTypeDescription = valueTypeDescription;
205 m_optionsMap[argument] = ov;
208 } // namespace BamTools
210 #endif // BAMTOOLS_OPTIONS_H