ApplicationUsage
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_APPLICATIONUSAGE
#define OSG_APPLICATIONUSAGE 1
#include <osg/Referenced>
#include <map>
#include <string>
#include <ostream>
namespace osg {
class OSG_EXPORT ApplicationUsage : public osg::Referenced
{
public:
static ApplicationUsage* instance();
ApplicationUsage() {}
ApplicationUsage(const std::string& commandLineUsage);
typedef std::map<std::string,std::string> UsageMap;
void setApplicationName(const std::string& name) { _applicationName = name; }
const std::string& getApplicationName() const { return _applicationName; }
void setDescription(const std::string& desc) { _description = desc; }
const std::string& getDescription() const { return _description; }
enum Type
{
NO_HELP = 0x0,
COMMAND_LINE_OPTION = 0x1,
ENVIRONMENTAL_VARIABLE = 0x2,
KEYBOARD_MOUSE_BINDING = 0x4,
HELP_ALL = KEYBOARD_MOUSE_BINDING|ENVIRONMENTAL_VARIABLE|COMMAND_LINE_OPTION
};
void addUsageExplanation(Type type,const std::string& option,const std::string& explanation);
void setCommandLineUsage(const std::string& explanation) { _commandLineUsage=explanation; }
const std::string& getCommandLineUsage() const { return _commandLineUsage; }
void addCommandLineOption(const std::string& option,const std::string& explanation, const std::string &defaultValue = "");
void setCommandLineOptions(const UsageMap& usageMap) { _commandLineOptions=usageMap; }
const UsageMap& getCommandLineOptions() const { return _commandLineOptions; }
void setCommandLineOptionsDefaults(const UsageMap& usageMap) { _commandLineOptionsDefaults=usageMap; }
const UsageMap& getCommandLineOptionsDefaults() const { return _commandLineOptionsDefaults; }
void addEnvironmentalVariable(const std::string& option,const std::string& explanation, const std::string& defaultValue = "");
void setEnvironmentalVariables(const UsageMap& usageMap) { _environmentalVariables=usageMap; }
const UsageMap& getEnvironmentalVariables() const { return _environmentalVariables; }
void setEnvironmentalVariablesDefaults(const UsageMap& usageMap) { _environmentalVariablesDefaults=usageMap; }
const UsageMap& getEnvironmentalVariablesDefaults() const { return _environmentalVariablesDefaults; }
void addKeyboardMouseBinding(const std::string& prefix, int key, const std::string& explanation);
void addKeyboardMouseBinding(int key, const std::string& explanation);
void addKeyboardMouseBinding(const std::string& option,const std::string& explanation);
void setKeyboardMouseBindings(const UsageMap& usageMap) { _keyboardMouse=usageMap; }
const UsageMap& getKeyboardMouseBindings() const { return _keyboardMouse; }
void getFormattedString(std::string& str, const UsageMap& um,unsigned int widthOfOutput=80,bool showDefaults=false,const UsageMap& ud=UsageMap());
void write(std::ostream& output,const UsageMap& um,unsigned int widthOfOutput=80,bool showDefaults=false,const UsageMap& ud=UsageMap());
void write(std::ostream& output,unsigned int type=COMMAND_LINE_OPTION, unsigned int widthOfOutput=80,bool showDefaults=false);
void writeEnvironmentSettings(std::ostream& output);
protected:
virtual ~ApplicationUsage() {}
std::string _applicationName;
std::string _description;
std::string _commandLineUsage;
UsageMap _commandLineOptions;
UsageMap _environmentalVariables;
UsageMap _keyboardMouse;
UsageMap _environmentalVariablesDefaults;
UsageMap _commandLineOptionsDefaults;
};
class ApplicationUsageProxy
{
public:
ApplicationUsageProxy(ApplicationUsage::Type type,const std::string& option,const std::string& explanation)
{
ApplicationUsage::instance()->addUsageExplanation(type,option,explanation);
}
};
}
#endif
Referenced
osg::ApplicationUsageProxy::ApplicationUsageProxy
ApplicationUsageProxy(ApplicationUsage::Type type, const std::string &option, const std::string &explanation)
Definition ApplicationUsage:116
osg::ApplicationUsage::setEnvironmentalVariablesDefaults
void setEnvironmentalVariablesDefaults(const UsageMap &usageMap)
Definition ApplicationUsage:76
osg::ApplicationUsage::_commandLineOptions
UsageMap _commandLineOptions
Definition ApplicationUsage:103
osg::ApplicationUsage::getDescription
const std::string & getDescription() const
Definition ApplicationUsage:45
osg::ApplicationUsage::getApplicationName
const std::string & getApplicationName() const
Definition ApplicationUsage:40
osg::ApplicationUsage::addKeyboardMouseBinding
void addKeyboardMouseBinding(int key, const std::string &explanation)
osg::ApplicationUsage::setCommandLineUsage
void setCommandLineUsage(const std::string &explanation)
Definition ApplicationUsage:58
osg::ApplicationUsage::getCommandLineOptionsDefaults
const UsageMap & getCommandLineOptionsDefaults() const
Definition ApplicationUsage:68
osg::ApplicationUsage::getEnvironmentalVariablesDefaults
const UsageMap & getEnvironmentalVariablesDefaults() const
Definition ApplicationUsage:77
osg::ApplicationUsage::addUsageExplanation
void addUsageExplanation(Type type, const std::string &option, const std::string &explanation)
osg::ApplicationUsage::_commandLineUsage
std::string _commandLineUsage
Definition ApplicationUsage:102
osg::ApplicationUsage::setCommandLineOptions
void setCommandLineOptions(const UsageMap &usageMap)
Definition ApplicationUsage:64
osg::ApplicationUsage::write
void write(std::ostream &output, const UsageMap &um, unsigned int widthOfOutput=80, bool showDefaults=false, const UsageMap &ud=UsageMap())
osg::ApplicationUsage::_environmentalVariablesDefaults
UsageMap _environmentalVariablesDefaults
Definition ApplicationUsage:106
osg::ApplicationUsage::writeEnvironmentSettings
void writeEnvironmentSettings(std::ostream &output)
osg::ApplicationUsage::addCommandLineOption
void addCommandLineOption(const std::string &option, const std::string &explanation, const std::string &defaultValue="")
osg::ApplicationUsage::write
void write(std::ostream &output, unsigned int type=COMMAND_LINE_OPTION, unsigned int widthOfOutput=80, bool showDefaults=false)
osg::ApplicationUsage::getEnvironmentalVariables
const UsageMap & getEnvironmentalVariables() const
Definition ApplicationUsage:74
osg::ApplicationUsage::setEnvironmentalVariables
void setEnvironmentalVariables(const UsageMap &usageMap)
Definition ApplicationUsage:73
osg::ApplicationUsage::~ApplicationUsage
virtual ~ApplicationUsage()
Definition ApplicationUsage:98
osg::ApplicationUsage::ApplicationUsage
ApplicationUsage()
Definition ApplicationUsage:31
osg::ApplicationUsage::getCommandLineOptions
const UsageMap & getCommandLineOptions() const
Definition ApplicationUsage:65
osg::ApplicationUsage::getFormattedString
void getFormattedString(std::string &str, const UsageMap &um, unsigned int widthOfOutput=80, bool showDefaults=false, const UsageMap &ud=UsageMap())
osg::ApplicationUsage::UsageMap
std::map< std::string, std::string > UsageMap
Definition ApplicationUsage:35
osg::ApplicationUsage::setKeyboardMouseBindings
void setKeyboardMouseBindings(const UsageMap &usageMap)
Definition ApplicationUsage:84
osg::ApplicationUsage::_description
std::string _description
Definition ApplicationUsage:101
osg::ApplicationUsage::_commandLineOptionsDefaults
UsageMap _commandLineOptionsDefaults
Definition ApplicationUsage:107
osg::ApplicationUsage::ApplicationUsage
ApplicationUsage(const std::string &commandLineUsage)
osg::ApplicationUsage::setDescription
void setDescription(const std::string &desc)
Definition ApplicationUsage:44
osg::ApplicationUsage::getKeyboardMouseBindings
const UsageMap & getKeyboardMouseBindings() const
Definition ApplicationUsage:85
osg::ApplicationUsage::addEnvironmentalVariable
void addEnvironmentalVariable(const std::string &option, const std::string &explanation, const std::string &defaultValue="")
osg::ApplicationUsage::addKeyboardMouseBinding
void addKeyboardMouseBinding(const std::string &prefix, int key, const std::string &explanation)
osg::ApplicationUsage::setCommandLineOptionsDefaults
void setCommandLineOptionsDefaults(const UsageMap &usageMap)
Definition ApplicationUsage:67
osg::ApplicationUsage::_keyboardMouse
UsageMap _keyboardMouse
Definition ApplicationUsage:105
osg::ApplicationUsage::Type
Type
Definition ApplicationUsage:48
osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE
@ ENVIRONMENTAL_VARIABLE
Definition ApplicationUsage:51
osg::ApplicationUsage::KEYBOARD_MOUSE_BINDING
@ KEYBOARD_MOUSE_BINDING
Definition ApplicationUsage:52
osg::ApplicationUsage::HELP_ALL
@ HELP_ALL
Definition ApplicationUsage:53
osg::ApplicationUsage::NO_HELP
@ NO_HELP
Definition ApplicationUsage:49
osg::ApplicationUsage::COMMAND_LINE_OPTION
@ COMMAND_LINE_OPTION
Definition ApplicationUsage:50
osg::ApplicationUsage::setApplicationName
void setApplicationName(const std::string &name)
Definition ApplicationUsage:39
osg::ApplicationUsage::addKeyboardMouseBinding
void addKeyboardMouseBinding(const std::string &option, const std::string &explanation)
osg::ApplicationUsage::_environmentalVariables
UsageMap _environmentalVariables
Definition ApplicationUsage:104
osg::ApplicationUsage::getCommandLineUsage
const std::string & getCommandLineUsage() const
Definition ApplicationUsage:59
osg::ApplicationUsage::instance
static ApplicationUsage * instance()
osg::ApplicationUsage::_applicationName
std::string _applicationName
Definition ApplicationUsage:100
osg::Referenced
Definition Referenced:44
osg
Definition AlphaFunc:19
OSG_EXPORT
#define OSG_EXPORT
Definition osg/Export:39