OSG How to parse command-line arguments

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.