The two classes that are responsible for command-line parsing in OSG are Osg::argumentparser and osg::applicationusage, and this article gives a brief description of the implementation and usage of the two classes.
Argumentparser This class is primarily responsible for reading command-line arguments, which is typically the case when we use command-line tools
Test.exe-s c:/src.txt-d C:/dst.txt
This command line contains the parameters: ARGC = 5, argv = ["Text.ext", "-S", "C:/src.txt", "-D", "c:/dst.txt"] such a character array, Argumentparser is the processing of this parameter.
ARGUMENTPARSER includes structure: Parameter, which mainly records the type of the parameter and the value of the type parameter (for example, the type of a Parameter is bool type, the value is true). Argumentparser the most important function of this class is to get the values of parameters and parameters, for example, we need to get a value of an option in a parameter list, for example, we want to get the value specified by-s in the command line above, then you can use the Read method to obtain the The value "C:/src.txt" also removes "-S" and "C:/src.txt" from the parameter list.
Applicationusage This class name is exactly what it does, application usage: The way the application is used, it gives the user a big explanation of how the application is used, a bit similar to the application's instruction manual. This class handles parameter types by three: 1) command line parameter 2) environment variable parameter 3) keyboard action parameters their corresponding enumeration variables are:
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
};
When we use its write method, we can print out the Help information for the type of enactment.
Another point to note is that Applicationusage uses a singleton pattern that can be used by another class to get this instance, the class is: Applicationusageproxy, which is implemented as follows:
Applicationusageproxy (applicationusage::type type,const std::string& option,const std::string& explanation)
{
applicationusage::instance ()->addusageexplanation (type,option,explanation);
}
This means that when we need to add a program description, we just need to construct a variable of this type.