TrueReality  v0.1.1912
ApplicationUsage.h
Go to the documentation of this file.
1 /*
2 * True Reality Open Source Game and Simulation Engine
3 * Copyright © 2021 Acid Rain Studios LLC
4 *
5 * This library is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU Lesser General Public License as published by the Free
7 * Software Foundation; either version 3.0 of the License, or (at your option)
8 * any later version.
9 *
10 * This library is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this library; if not, write to the Free Software Foundation, Inc.,
17 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * @author Maxim Serebrennik
20 */
21 
22 #pragma once
23 
24 #include <trUtil/Export.h>
25 
26 #include <osg/ApplicationUsage>
27 #include <osg/ref_ptr>
28 
29 #include <string>
30 #include <map>
31 
32 
38 namespace trUtil
39 {
46  {
47  public:
48 
50  using UsageMap = std::map<std::string, std::string>;
51 
52  enum class Type
53  {
54  NO_HELP = osg::ApplicationUsage::NO_HELP,
55  COMMAND_LINE_OPTION = osg::ApplicationUsage::COMMAND_LINE_OPTION,
56  ENVIRONMENTAL_VARIABLE = osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE,
57  KEYBOARD_MOUSE_BINDING = osg::ApplicationUsage::KEYBOARD_MOUSE_BINDING,
58  HELP_ALL = KEYBOARD_MOUSE_BINDING | ENVIRONMENTAL_VARIABLE | COMMAND_LINE_OPTION
59  };
60 
67 
75  ApplicationUsage(osg::ApplicationUsage* applicationUsage);
76 
84  ApplicationUsage(const std::string& commandLineUsage);
85 
92 
100  void SetApplicationName(const std::string& name);
101 
109  const std::string& GetApplicationName() const;
110 
119  void SetDescription(const std::string& desc);
120 
128  const std::string& GetDescription() const;
129 
139  void AddUsageExplanation(Type type, const std::string& option, const std::string& explanation);
140 
148  void SetCommandLineUsage(const std::string& explanation);
149 
157  const std::string& GetCommandLineUsage() const;
158 
168  void AddCommandLineOption(const std::string& option, const std::string& explanation, const std::string &defaultValue = "");
169 
177  void SetCommandLineOptions(const UsageMap& usageMap);
178 
186  const UsageMap& GetCommandLineOptions() const;
187 
195  void SetCommandLineOptionsDefaults(const UsageMap& usageMap);
196 
204  const UsageMap& GetCommandLineOptionsDefaults() const;
205 
215  void AddEnvironmentalVariable(const std::string& option, const std::string& explanation, const std::string& defaultValue = "");
216 
224  void SetEnvironmentalVariables(const UsageMap& usageMap);
225 
233  const UsageMap& GetEnvironmentalVariables() const;
234 
242  void SetEnvironmentalVariablesDefaults(const UsageMap& usageMap);
243 
251  const UsageMap& GetEnvironmentalVariablesDefaults() const;
252 
262  void AddKeyboardMouseBinding(const std::string& prefix, int key, const std::string& explanation);
263 
272  void AddKeyboardMouseBinding(int key, const std::string& explanation);
273 
282  void AddKeyboardMouseBinding(const std::string& option, const std::string& explanation);
283 
291  void SetKeyboardMouseBindings(const UsageMap& usageMap);
292 
300  const UsageMap& GetKeyboardMouseBindings() const;
301 
313  void GetFormattedString(std::string& str, const UsageMap& um, unsigned int widthOfOutput = 80, bool showDefaults = false, const UsageMap& ud = UsageMap());
314 
326  void Write(std::ostream& output, const UsageMap& um, unsigned int widthOfOutput = 80, bool showDefaults = false, const UsageMap& ud = UsageMap());
327 
338  void Write(std::ostream& output, Type type = Type::COMMAND_LINE_OPTION, unsigned int widthOfOutput = 80, bool showDefaults = false);
339 
347  void WriteEnvironmentSettings(std::ostream& output);
348 
356  operator osg::ApplicationUsage& ();
357 
365  operator const osg::ApplicationUsage& () const;
366 
374  operator osg::ApplicationUsage* ();
375 
383  operator const osg::ApplicationUsage* () const;
384 
385  protected:
386  osg::ref_ptr<osg::ApplicationUsage> mAppUsage = nullptr;
387  };
388 }
389 
390 
An application usage class for the argument parser.
A class that represents date time utility.
std::map< std::string, std::string > UsageMap
The message to command usage map.
Namespace that holds various utility classes for the engine.
Definition: SmrtPtr.h:208