root/OpenSceneGraph/trunk/include/osg/ApplicationUsage @ 13041

Revision 13041, 4.8 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
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.
7 *
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.
12*/
13
14#ifndef OSG_APPLICATIONUSAGE
15#define OSG_APPLICATIONUSAGE 1
16
17#include <osg/Referenced>
18
19#include <map>
20#include <string>
21#include <ostream>
22
23namespace osg {
24
25class OSG_EXPORT ApplicationUsage : public osg::Referenced
26{
27    public:
28
29        static ApplicationUsage* instance();
30
31        ApplicationUsage() {}
32
33        ApplicationUsage(const std::string& commandLineUsage);
34
35        typedef std::map<std::string,std::string> UsageMap;
36
37
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; }
41
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; }
46
47        enum Type
48        {
49            NO_HELP = 0x0,
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
54        };
55
56        void addUsageExplanation(Type type,const std::string& option,const std::string& explanation);
57
58        void setCommandLineUsage(const std::string& explanation) { _commandLineUsage=explanation; }
59        const std::string& getCommandLineUsage() const { return _commandLineUsage; }
60
61
62        void addCommandLineOption(const std::string& option,const std::string& explanation, const std::string &defaultValue = "");
63
64        void setCommandLineOptions(const UsageMap& usageMap) { _commandLineOptions=usageMap; }
65        const UsageMap& getCommandLineOptions() const { return _commandLineOptions; }
66
67        void setCommandLineOptionsDefaults(const UsageMap& usageMap) { _commandLineOptionsDefaults=usageMap; }
68        const UsageMap& getCommandLineOptionsDefaults() const { return _commandLineOptionsDefaults; }
69
70
71        void addEnvironmentalVariable(const std::string& option,const std::string& explanation, const std::string& defaultValue = "");
72
73        void setEnvironmentalVariables(const UsageMap& usageMap) { _environmentalVariables=usageMap; }
74        const UsageMap& getEnvironmentalVariables() const { return _environmentalVariables; }
75
76        void setEnvironmentalVariablesDefaults(const UsageMap& usageMap) { _environmentalVariablesDefaults=usageMap; }
77        const UsageMap& getEnvironmentalVariablesDefaults() const { return _environmentalVariablesDefaults; }
78
79
80        void addKeyboardMouseBinding(const std::string& option,const std::string& explanation);
81
82        void setKeyboardMouseBindings(const UsageMap& usageMap) { _keyboardMouse=usageMap; }
83        const UsageMap& getKeyboardMouseBindings() const { return _keyboardMouse; }
84
85
86        void getFormattedString(std::string& str, const UsageMap& um,unsigned int widthOfOutput=80,bool showDefaults=false,const UsageMap& ud=UsageMap());
87
88        void write(std::ostream& output,const UsageMap& um,unsigned int widthOfOutput=80,bool showDefaults=false,const UsageMap& ud=UsageMap());
89
90        void write(std::ostream& output,unsigned int type=COMMAND_LINE_OPTION, unsigned int widthOfOutput=80,bool showDefaults=false);
91
92        void writeEnvironmentSettings(std::ostream& output);
93
94    protected:
95
96        virtual ~ApplicationUsage() {}
97
98        std::string _applicationName;
99        std::string _description;
100        std::string _commandLineUsage;
101        UsageMap    _commandLineOptions;
102        UsageMap    _environmentalVariables;
103        UsageMap    _keyboardMouse;
104        UsageMap    _environmentalVariablesDefaults;
105        UsageMap    _commandLineOptionsDefaults;
106
107};
108
109class ApplicationUsageProxy
110{
111    public:
112
113        /** register an explanation of commandline/environmentvariable/keyboard mouse usage.*/
114        ApplicationUsageProxy(ApplicationUsage::Type type,const std::string& option,const std::string& explanation)
115        {
116            ApplicationUsage::instance()->addUsageExplanation(type,option,explanation);
117        }
118};
119
120}
121
122#endif
Note: See TracBrowser for help on using the browser.