2003-02-19 00:36:42 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 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/Export>
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
2004-03-03 21:27:21 +08:00
|
|
|
#include <ostream>
|
2003-02-19 00:36:42 +08:00
|
|
|
|
|
|
|
namespace osg {
|
|
|
|
|
|
|
|
class SG_EXPORT ApplicationUsage
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
static ApplicationUsage* instance();
|
|
|
|
|
|
|
|
ApplicationUsage() {}
|
|
|
|
|
|
|
|
ApplicationUsage(const std::string& commandLineUsage);
|
|
|
|
|
|
|
|
typedef std::map<std::string,std::string> UsageMap;
|
|
|
|
|
2003-03-26 20:50:30 +08:00
|
|
|
|
2003-04-09 16:20:08 +08:00
|
|
|
void setApplicationName(const std::string& name) { _applicationName = name; }
|
|
|
|
const std::string& getApplicationName() const { return _applicationName; }
|
2003-03-26 20:50:30 +08:00
|
|
|
|
|
|
|
void setDescription(const std::string& desc) { _description = desc; }
|
|
|
|
const std::string& getDescription() const { return _description; }
|
|
|
|
|
2003-02-19 00:36:42 +08:00
|
|
|
enum Type
|
|
|
|
{
|
2003-04-07 05:32:44 +08:00
|
|
|
COMMAND_LINE_OPTION = 0x1,
|
|
|
|
ENVIRONMENTAL_VARIABLE = 0x2,
|
|
|
|
KEYBOARD_MOUSE_BINDING = 0x4
|
2003-02-19 00:36:42 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
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; }
|
|
|
|
|
|
|
|
|
2004-09-01 17:48:17 +08:00
|
|
|
void addCommandLineOption(const std::string& option,const std::string& explanation, const std::string &defaultValue = "");
|
2003-02-19 00:36:42 +08:00
|
|
|
|
|
|
|
const UsageMap& getCommandLineOptions() const { return _commandLineOptions; }
|
|
|
|
|
2004-09-01 17:48:17 +08:00
|
|
|
const UsageMap& getCommandLineOptionsDefaults() const { return _commandLineOptionsDefaults; }
|
2003-02-19 00:36:42 +08:00
|
|
|
|
2004-09-01 17:48:17 +08:00
|
|
|
|
|
|
|
void addEnvironmentalVariable(const std::string& option,const std::string& explanation, const std::string& defaultValue = "");
|
2003-02-19 00:36:42 +08:00
|
|
|
|
|
|
|
const UsageMap& getEnvironmentalVariables() const { return _environmentalVariables; }
|
|
|
|
|
2004-09-01 17:48:17 +08:00
|
|
|
const UsageMap& getEnvironmentalVariablesDefaults() const { return _environmentalVariablesDefaults; }
|
|
|
|
|
2003-02-19 00:36:42 +08:00
|
|
|
|
|
|
|
void addKeyboardMouseBinding(const std::string& option,const std::string& explanation);
|
|
|
|
|
|
|
|
const UsageMap& getKeyboardMouseBindings() const { return _keyboardMouse; }
|
|
|
|
|
|
|
|
|
2004-09-01 17:48:17 +08:00
|
|
|
void getFormattedString(std::string& str, const UsageMap& um,unsigned int widthOfOutput=80,bool showDefaults=false,const UsageMap& ud=UsageMap());
|
2003-03-26 20:50:30 +08:00
|
|
|
|
2004-09-01 17:48:17 +08:00
|
|
|
void write(std::ostream& output,const UsageMap& um,unsigned int widthOfOutput=80,bool showDefaults=false,const UsageMap& ud=UsageMap());
|
2003-02-19 00:36:42 +08:00
|
|
|
|
2004-10-26 03:16:57 +08:00
|
|
|
void write(std::ostream& output,unsigned int type=COMMAND_LINE_OPTION, unsigned int widthOfOutput=80,bool showDefaults=false);
|
2003-02-19 00:36:42 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2003-03-26 20:50:30 +08:00
|
|
|
std::string _applicationName;
|
|
|
|
std::string _description;
|
2003-02-19 00:36:42 +08:00
|
|
|
std::string _commandLineUsage;
|
|
|
|
UsageMap _commandLineOptions;
|
|
|
|
UsageMap _environmentalVariables;
|
|
|
|
UsageMap _keyboardMouse;
|
2004-09-01 17:48:17 +08:00
|
|
|
UsageMap _environmentalVariablesDefaults;
|
|
|
|
UsageMap _commandLineOptionsDefaults;
|
2003-02-19 00:36:42 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class ApplicationUsageProxy
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
/** register an explanation of commandline/evironmentalvaraible/keyboard mouse usage.*/
|
|
|
|
ApplicationUsageProxy(ApplicationUsage::Type type,const std::string& option,const std::string& explanation)
|
|
|
|
{
|
|
|
|
ApplicationUsage::instance()->addUsageExplanation(type,option,explanation);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|