1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
14#ifndef OSG_APPLICATIONUSAGE
15#define OSG_APPLICATIONUSAGE 1
17#include <osg/Referenced>
25class OSG_EXPORT ApplicationUsage : public osg::Referenced
29 static ApplicationUsage* instance();
33 ApplicationUsage(const std::string& commandLineUsage);
35 typedef std::map<std::string,std::string> UsageMap;
38 /** The ApplicationName is often displayed when logging errors, and frequently incorporated into the Description (below). */
39 void setApplicationName(const std::string& name) { _applicationName = name; }
40 const std::string& getApplicationName() const { return _applicationName; }
42 /** If non-empty, the Description is typically shown by the Help Handler
43 * as text on the Help display (which also lists keyboard abbreviations. */
44 void setDescription(const std::string& desc) { _description = desc; }
45 const std::string& getDescription() const { return _description; }
50 COMMAND_LINE_OPTION = 0x1,
51 ENVIRONMENTAL_VARIABLE = 0x2,
52 KEYBOARD_MOUSE_BINDING = 0x4,
53 HELP_ALL = KEYBOARD_MOUSE_BINDING|ENVIRONMENTAL_VARIABLE|COMMAND_LINE_OPTION
56 void addUsageExplanation(Type type,const std::string& option,const std::string& explanation);
58 void setCommandLineUsage(const std::string& explanation) { _commandLineUsage=explanation; }
59 const std::string& getCommandLineUsage() const { return _commandLineUsage; }
62 void addCommandLineOption(const std::string& option,const std::string& explanation, const std::string &defaultValue = "");
64 void setCommandLineOptions(const UsageMap& usageMap) { _commandLineOptions=usageMap; }
65 const UsageMap& getCommandLineOptions() const { return _commandLineOptions; }
67 void setCommandLineOptionsDefaults(const UsageMap& usageMap) { _commandLineOptionsDefaults=usageMap; }
68 const UsageMap& getCommandLineOptionsDefaults() const { return _commandLineOptionsDefaults; }
71 void addEnvironmentalVariable(const std::string& option,const std::string& explanation, const std::string& defaultValue = "");
73 void setEnvironmentalVariables(const UsageMap& usageMap) { _environmentalVariables=usageMap; }
74 const UsageMap& getEnvironmentalVariables() const { return _environmentalVariables; }
76 void setEnvironmentalVariablesDefaults(const UsageMap& usageMap) { _environmentalVariablesDefaults=usageMap; }
77 const UsageMap& getEnvironmentalVariablesDefaults() const { return _environmentalVariablesDefaults; }
80 void addKeyboardMouseBinding(const std::string& prefix, int key, const std::string& explanation);
81 void addKeyboardMouseBinding(int key, const std::string& explanation);
82 void addKeyboardMouseBinding(const std::string& option,const std::string& explanation);
84 void setKeyboardMouseBindings(const UsageMap& usageMap) { _keyboardMouse=usageMap; }
85 const UsageMap& getKeyboardMouseBindings() const { return _keyboardMouse; }
88 void getFormattedString(std::string& str, const UsageMap& um,unsigned int widthOfOutput=80,bool showDefaults=false,const UsageMap& ud=UsageMap());
90 void write(std::ostream& output,const UsageMap& um,unsigned int widthOfOutput=80,bool showDefaults=false,const UsageMap& ud=UsageMap());
92 void write(std::ostream& output,unsigned int type=COMMAND_LINE_OPTION, unsigned int widthOfOutput=80,bool showDefaults=false);
94 void writeEnvironmentSettings(std::ostream& output);
98 virtual ~ApplicationUsage() {}
100 std::string _applicationName;
101 std::string _description;
102 std::string _commandLineUsage;
103 UsageMap _commandLineOptions;
104 UsageMap _environmentalVariables;
105 UsageMap _keyboardMouse;
106 UsageMap _environmentalVariablesDefaults;
107 UsageMap _commandLineOptionsDefaults;
111class ApplicationUsageProxy
115 /** register an explanation of commandline/environmentvariable/keyboard mouse usage.*/
116 ApplicationUsageProxy(ApplicationUsage::Type type,const std::string& option,const std::string& explanation)
118 ApplicationUsage::instance()->addUsageExplanation(type,option,explanation);