// File: mgo1977[P]c---parsing-argument-options/example1.cc
// Function: main
int main(int argc, char** argv) {

    /*
     * This is a simple example, to show the usage of this tool.
     * These are the main steps to use:
     *
     *  a. create all options, between set of the existing ones you have:
     *  b. Now, the easy part: create the parser, add the options and parse it
     *
     *  Please, take a look at the documentation in the header file "Parser.h"
     *  for a full description of each option
     *
     */

    BoolOption    debug         ('d', "debug",      false, "enables the debug mode");
    StringOption  username      ('u', "username",   true , "set the username");
    IntegerOption port          ('p', "port",       false, 23, "server port");
    FloatOption   portability   ('n', "portability",false, "smart option...");
    StringListOption  book      ('j', "book",       false, "book of interest. could be more than one");

    // default value is the limit of the type. for int types => (sizeof(int) * 1024)
    std::list<int> defaultPortRange;
    defaultPortRange.push_back(1);
    defaultPortRange.push_back(sizeof(int)*1024);
    IntegerRange  portRange     ('r', "portrange",  false, defaultPortRange, "range of ports");

    Parser parser;

    parser.addOption(debug)
          .addOption(username)
          .addOption(port)
          .addOption(portability)
          .addOption(book)
          .addOption(portRange);

    vector<string> otherArguments = parser.parse(argc, argv);

    if ( debug.isSet() ) {
        cout << "debug flag was set" << endl;
    }

    // username is mandatory, so we don't need to check it
    cout << "username was set to '" << username.getValue() << "'" << endl;

    // port has a default value, so we can choose not to check it
    // and work with the default value transparently
    cout << "port was set to '" << port.getValue() << "'" << endl;


    if ( portability.isSet() ) {
        cout << "portability was set to '" << portability.getValue() << "'" << endl;
    }

    if ( book.isSet() ) {
        std::list<std::string> values = book.getValue();

        cout << "book was set with " << values.size() << " entries: ";

        for(std::list<string>::iterator entry = values.begin();
            entry != values.end();
            ++entry
        ) {
            if ( entry != values.begin() )
                cout << ", ";

            cout << "'" << *entry << "'";
        }

        cout << endl;

    }

    //if ( portRange.isSet() ) {
        std::list<int> list = portRange.getValue();
        if ( list.size() > 0 ) {
            cout << "Range seted from '" << list.front() << "' to '" << list.back() << "'." << endl;
        } else {
            cout << "is null" << std::endl;
        }
    //}
 
    // if other arguments were specified, we can easily access them
    if ( ! otherArguments.empty() ) {

        cout << "otherArguments: ";

        for(vector<string>::iterator argIter = otherArguments.begin();
            argIter != otherArguments.end();
            ++argIter
        ) {

            if ( argIter != otherArguments.begin() )
                cout << ", ";

            cout << "'" << *argIter << "'";

        }

        cout << endl;

    }


}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x570, %rsp            # imm = 0x570
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq 0x7453(%rip), %rdx      # 0xc0d3
leaq 0x7452(%rip), %r8       # 0xc0d9
leaq -0x70(%rbp), %rdi
movl $0x64, %esi
xorl %ecx, %ecx
callq 0x5f40
leaq 0x745a(%rip), %rdx      # 0xc0f8
leaq 0x744b(%rip), %r8       # 0xc0f0
leaq -0x110(%rbp), %rdi
movl $0x75, %esi
movl $0x1, %ecx
callq 0x5fb0
jmp 0x4cbd
movl $0x17, -0x18c(%rbp)
leaq 0x743a(%rip), %rdx      # 0xc108
leaq 0x742c(%rip), %r9       # 0xc101
leaq -0x188(%rbp), %rdi
movl $0x70, %esi
xorl %ecx, %ecx
leaq -0x18c(%rbp), %r8
callq 0x6050
jmp 0x4cf1
leaq 0x7415(%rip), %rdx      # 0xc10d
leaq 0x741a(%rip), %r8       # 0xc119
leaq -0x1f8(%rbp), %rdi
movl $0x6e, %esi
xorl %ecx, %ecx
callq 0x60f0
jmp 0x4d14
leaq 0x740e(%rip), %rdx      # 0xc129
leaq 0x740c(%rip), %r8       # 0xc12e
leaq -0x288(%rbp), %rdi
movl $0x6a, %esi
xorl %ecx, %ecx
callq 0x6180
jmp 0x4d37
leaq -0x2a0(%rbp), %rdi
movq %rdi, -0x470(%rbp)
callq 0x6200
movq -0x470(%rbp), %rdi
movl $0x1, -0x2a4(%rbp)
leaq -0x2a4(%rbp), %rsi
callq 0x6220
jmp 0x4d69
movl $0x1000, -0x2a8(%rbp)   # imm = 0x1000
leaq -0x2a0(%rbp), %rdi
leaq -0x2a8(%rbp), %rsi
callq 0x6220
jmp 0x4d88
leaq 0x73c8(%rip), %rdx      # 0xc157
leaq 0x73cb(%rip), %r9       # 0xc161
leaq -0x338(%rbp), %rdi
movl $0x72, %esi
xorl %ecx, %ecx
leaq -0x2a0(%rbp), %r8
callq 0x6260
jmp 0x4db2
leaq -0x3d0(%rbp), %rdi
callq 0x62d0
jmp 0x4dc0
leaq -0x3d0(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x6370
movq %rax, -0x478(%rbp)
jmp 0x4dd9
movq -0x478(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x6370
movq %rax, -0x480(%rbp)
jmp 0x4df5
movq -0x480(%rbp), %rdi
leaq -0x188(%rbp), %rsi
callq 0x6370
movq %rax, -0x488(%rbp)
jmp 0x4e11
movq -0x488(%rbp), %rdi
leaq -0x1f8(%rbp), %rsi
callq 0x6370
movq %rax, -0x490(%rbp)
jmp 0x4e2d
movq -0x490(%rbp), %rdi
leaq -0x288(%rbp), %rsi
callq 0x6370
movq %rax, -0x498(%rbp)
jmp 0x4e49
movq -0x498(%rbp), %rdi
leaq -0x338(%rbp), %rsi
callq 0x6370
jmp 0x4e5e
movl -0x8(%rbp), %edx
movq -0x10(%rbp), %rcx
leaq -0x3e8(%rbp), %rdi
leaq -0x3d0(%rbp), %rsi
callq 0x3630
jmp 0x4e7a
leaq -0x70(%rbp), %rdi
callq 0x5830
movb %al, -0x499(%rbp)
jmp 0x4e8b
movb -0x499(%rbp), %al
testb $0x1, %al
jne 0x4e9a
jmp 0x4f88
movq 0xd12f(%rip), %rdi      # 0x11fd0
leaq 0x72c8(%rip), %rsi      # 0xc170
callq 0x3260
movq %rax, -0x4a8(%rbp)
jmp 0x4eb6
movq -0x4a8(%rbp), %rdi
movq 0xd0fc(%rip), %rsi      # 0x11fc0
callq 0x32a0
jmp 0x4ecb
jmp 0x4f88
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x118(%rbp)
movl %eax, -0x11c(%rbp)
jmp 0x5654
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x118(%rbp)
movl %eax, -0x11c(%rbp)
jmp 0x5648
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x118(%rbp)
movl %eax, -0x11c(%rbp)
jmp 0x563c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x118(%rbp)
movl %eax, -0x11c(%rbp)
jmp 0x5630
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x118(%rbp)
movl %eax, -0x11c(%rbp)
jmp 0x5618
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x118(%rbp)
movl %eax, -0x11c(%rbp)
jmp 0x560c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x118(%rbp)
movl %eax, -0x11c(%rbp)
jmp 0x5600
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x118(%rbp)
movl %eax, -0x11c(%rbp)
jmp 0x55f4
movq 0xd041(%rip), %rdi      # 0x11fd0
leaq 0x71ed(%rip), %rsi      # 0xc183
callq 0x3260
movq %rax, -0x4b0(%rbp)
jmp 0x4fa4
leaq -0x408(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x63b0
jmp 0x4fb9
movq -0x4b0(%rbp), %rdi
leaq -0x408(%rbp), %rsi
callq 0x3230
movq %rax, -0x4b8(%rbp)
jmp 0x4fd5
movq -0x4b8(%rbp), %rdi
leaq 0x7210(%rip), %rsi      # 0xc1f3
callq 0x3260
movq %rax, -0x4c0(%rbp)
jmp 0x4ff1
movq -0x4c0(%rbp), %rdi
movq 0xcfc1(%rip), %rsi      # 0x11fc0
callq 0x32a0
jmp 0x5006
leaq -0x408(%rbp), %rdi
callq 0x3160
movq 0xcfb7(%rip), %rdi      # 0x11fd0
leaq 0x7179(%rip), %rsi      # 0xc199
callq 0x3260
movq %rax, -0x4c8(%rbp)
jmp 0x502e
leaq -0x188(%rbp), %rdi
callq 0x6410
movl %eax, -0x4cc(%rbp)
jmp 0x5042
movl -0x4cc(%rbp), %esi
movq -0x4c8(%rbp), %rdi
callq 0x3470
movq %rax, -0x4d8(%rbp)
jmp 0x505d
movq -0x4d8(%rbp), %rdi
leaq 0x7188(%rip), %rsi      # 0xc1f3
callq 0x3260
movq %rax, -0x4e0(%rbp)
jmp 0x5079
movq -0x4e0(%rbp), %rdi
movq 0xcf39(%rip), %rsi      # 0x11fc0
callq 0x32a0
jmp 0x508e
leaq -0x1f8(%rbp), %rdi
callq 0x5830
movb %al, -0x4e1(%rbp)
jmp 0x50a2
movb -0x4e1(%rbp), %al
testb $0x1, %al
jne 0x50b1
jmp 0x5156
movq 0xcf18(%rip), %rdi      # 0x11fd0
leaq 0x70ec(%rip), %rsi      # 0xc1ab
callq 0x3260
movq %rax, -0x4f0(%rbp)
jmp 0x50cd
leaq -0x1f8(%rbp), %rdi
callq 0x6450
movss %xmm0, -0x4f4(%rbp)
jmp 0x50e3
movss -0x4f4(%rbp), %xmm0
movq -0x4f0(%rbp), %rdi
callq 0x31c0
movq %rax, -0x500(%rbp)
jmp 0x5100
movq -0x500(%rbp), %rdi
leaq 0x70e5(%rip), %rsi      # 0xc1f3
callq 0x3260
movq %rax, -0x508(%rbp)
jmp 0x511c
movq -0x508(%rbp), %rdi
movq 0xce96(%rip), %rsi      # 0x11fc0
callq 0x32a0
jmp 0x5131
jmp 0x5156
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x118(%rbp)
movl %eax, -0x11c(%rbp)
leaq -0x408(%rbp), %rdi
callq 0x3160
jmp 0x55f4
leaq -0x288(%rbp), %rdi
callq 0x5830
movb %al, -0x509(%rbp)
jmp 0x516a
movb -0x509(%rbp), %al
testb $0x1, %al
jne 0x5179
jmp 0x5314
leaq -0x420(%rbp), %rdi
leaq -0x288(%rbp), %rsi
callq 0x6490
jmp 0x518e
movq 0xce3b(%rip), %rdi      # 0x11fd0
leaq 0x7028(%rip), %rsi      # 0xc1c4
callq 0x3260
movq %rax, -0x518(%rbp)
jmp 0x51aa
leaq -0x420(%rbp), %rdi
callq 0x64f0
movq -0x518(%rbp), %rdi
movq %rax, %rsi
callq 0x3070
movq %rax, -0x520(%rbp)
jmp 0x51ce
movq -0x520(%rbp), %rdi
leaq 0x6ffb(%rip), %rsi      # 0xc1d7
callq 0x3260
jmp 0x51e3
leaq -0x420(%rbp), %rdi
callq 0x6520
movq %rax, -0x428(%rbp)
leaq -0x420(%rbp), %rdi
callq 0x6580
movq %rax, -0x430(%rbp)
leaq -0x428(%rbp), %rdi
leaq -0x430(%rbp), %rsi
callq 0x6550
testb $0x1, %al
jne 0x5225
jmp 0x52f3
leaq -0x420(%rbp), %rdi
callq 0x6520
movq %rax, -0x438(%rbp)
leaq -0x428(%rbp), %rdi
leaq -0x438(%rbp), %rsi
callq 0x6550
testb $0x1, %al
jne 0x5251
jmp 0x528b
movq 0xcd78(%rip), %rdi      # 0x11fd0
leaq 0x6e16(%rip), %rsi      # 0xc075
callq 0x3260
jmp 0x5266
jmp 0x528b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x118(%rbp)
movl %eax, -0x11c(%rbp)
leaq -0x420(%rbp), %rdi
callq 0x65f0
jmp 0x55f4
movq 0xcd3e(%rip), %rdi      # 0x11fd0
leaq 0x6f5a(%rip), %rsi      # 0xc1f3
callq 0x3260
movq %rax, -0x528(%rbp)
jmp 0x52a7
leaq -0x428(%rbp), %rdi
callq 0x65b0
movq -0x528(%rbp), %rdi
movq %rax, %rsi
callq 0x3230
movq %rax, -0x530(%rbp)
jmp 0x52cb
movq -0x530(%rbp), %rdi
leaq 0x6f1a(%rip), %rsi      # 0xc1f3
callq 0x3260
jmp 0x52e0
jmp 0x52e2
leaq -0x428(%rbp), %rdi
callq 0x65d0
jmp 0x51f6
movq 0xccd6(%rip), %rdi      # 0x11fd0
movq 0xccbf(%rip), %rsi      # 0x11fc0
callq 0x32a0
jmp 0x5308
leaq -0x420(%rbp), %rdi
callq 0x65f0
leaq -0x450(%rbp), %rdi
leaq -0x338(%rbp), %rsi
callq 0x6610
jmp 0x5329
leaq -0x450(%rbp), %rdi
callq 0x6670
cmpq $0x0, %rax
jbe 0x5413
movq 0xcc8a(%rip), %rdi      # 0x11fd0
leaq 0x6e95(%rip), %rsi      # 0xc1e2
callq 0x3260
movq %rax, -0x538(%rbp)
jmp 0x535b
leaq -0x450(%rbp), %rdi
callq 0x66a0
movq -0x538(%rbp), %rdi
movl (%rax), %esi
callq 0x3470
movq %rax, -0x540(%rbp)
jmp 0x537e
movq -0x540(%rbp), %rdi
leaq 0x6e69(%rip), %rsi      # 0xc1f5
callq 0x3260
movq %rax, -0x548(%rbp)
jmp 0x539a
leaq -0x450(%rbp), %rdi
callq 0x66d0
movq -0x548(%rbp), %rdi
movl (%rax), %esi
callq 0x3470
movq %rax, -0x550(%rbp)
jmp 0x53bd
movq -0x550(%rbp), %rdi
leaq 0x6e31(%rip), %rsi      # 0xc1fc
callq 0x3260
movq %rax, -0x558(%rbp)
jmp 0x53d9
movq -0x558(%rbp), %rdi
movq 0xcbd9(%rip), %rsi      # 0x11fc0
callq 0x32a0
jmp 0x53ee
jmp 0x5446
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x118(%rbp)
movl %eax, -0x11c(%rbp)
leaq -0x450(%rbp), %rdi
callq 0x6830
jmp 0x55f4
movq 0xcbb6(%rip), %rdi      # 0x11fd0
leaq 0x6dde(%rip), %rsi      # 0xc1ff
callq 0x3260
movq %rax, -0x560(%rbp)
jmp 0x542f
movq -0x560(%rbp), %rdi
movq 0xcb83(%rip), %rsi      # 0x11fc0
callq 0x32a0
jmp 0x5444
jmp 0x5446
leaq -0x3e8(%rbp), %rdi
callq 0x6710
testb $0x1, %al
jne 0x5573
movq 0xcb6f(%rip), %rdi      # 0x11fd0
leaq 0x6d9f(%rip), %rsi      # 0xc207
callq 0x3260
jmp 0x546f
leaq -0x3e8(%rbp), %rdi
callq 0x6750
movq %rax, -0x458(%rbp)
leaq -0x3e8(%rbp), %rdi
callq 0x67c0
movq %rax, -0x460(%rbp)
leaq -0x458(%rbp), %rdi
leaq -0x460(%rbp), %rsi
callq 0x6780
testb $0x1, %al
jne 0x54b1
jmp 0x555c
leaq -0x3e8(%rbp), %rdi
callq 0x6750
movq %rax, -0x468(%rbp)
leaq -0x458(%rbp), %rdi
leaq -0x468(%rbp), %rsi
callq 0x6780
testb $0x1, %al
jne 0x54dd
jmp 0x54f4
movq 0xcaec(%rip), %rdi      # 0x11fd0
leaq 0x6b8a(%rip), %rsi      # 0xc075
callq 0x3260
jmp 0x54f2
jmp 0x54f4
movq 0xcad5(%rip), %rdi      # 0x11fd0
leaq 0x6cf1(%rip), %rsi      # 0xc1f3
callq 0x3260
movq %rax, -0x568(%rbp)
jmp 0x5510
leaq -0x458(%rbp), %rdi
callq 0x67f0
movq -0x568(%rbp), %rdi
movq %rax, %rsi
callq 0x3230
movq %rax, -0x570(%rbp)
jmp 0x5534
movq -0x570(%rbp), %rdi
leaq 0x6cb1(%rip), %rsi      # 0xc1f3
callq 0x3260
jmp 0x5549
jmp 0x554b
leaq -0x458(%rbp), %rdi
callq 0x6810
jmp 0x5482
movq 0xca6d(%rip), %rdi      # 0x11fd0
movq 0xca56(%rip), %rsi      # 0x11fc0
callq 0x32a0
jmp 0x5571
jmp 0x5573
leaq -0x450(%rbp), %rdi
callq 0x6830
leaq -0x3e8(%rbp), %rdi
callq 0x5aa0
leaq -0x3d0(%rbp), %rdi
callq 0x6850
leaq -0x338(%rbp), %rdi
callq 0x6890
leaq -0x2a0(%rbp), %rdi
callq 0x6830
leaq -0x288(%rbp), %rdi
callq 0x68b0
leaq -0x1f8(%rbp), %rdi
callq 0x6900
leaq -0x188(%rbp), %rdi
callq 0x6920
leaq -0x110(%rbp), %rdi
callq 0x6940
leaq -0x70(%rbp), %rdi
callq 0x6990
movl -0x4(%rbp), %eax
addq $0x570, %rsp            # imm = 0x570
popq %rbp
retq
leaq -0x3e8(%rbp), %rdi
callq 0x5aa0
leaq -0x3d0(%rbp), %rdi
callq 0x6850
leaq -0x338(%rbp), %rdi
callq 0x6890
leaq -0x2a0(%rbp), %rdi
callq 0x6830
leaq -0x288(%rbp), %rdi
callq 0x68b0
leaq -0x1f8(%rbp), %rdi
callq 0x6900
leaq -0x188(%rbp), %rdi
callq 0x6920
leaq -0x110(%rbp), %rdi
callq 0x6940
leaq -0x70(%rbp), %rdi
callq 0x6990
movq -0x118(%rbp), %rdi
callq 0x3480
nopl (%rax)