File: arg_parse_argument.h

package info (click to toggle)
seqan2 2.3.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 222,320 kB
  • ctags: 40,872
  • sloc: cpp: 252,894; ansic: 86,805; python: 6,534; sh: 985; xml: 570; makefile: 236; awk: 51
file content (1180 lines) | stat: -rw-r--r-- 41,400 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
// ==========================================================================
//                 SeqAn - The Library for Sequence Analysis
// ==========================================================================
// Copyright (c) 2006-2016, Knut Reinert, FU Berlin
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//     * Neither the name of Knut Reinert or the FU Berlin nor the names of
//       its contributors may be used to endorse or promote products derived
//       from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
//
// ==========================================================================
// Author: Stephan Aiche <stephan.aiche@fu-berlin.de>
// ==========================================================================

#ifndef SEQAN_INCLUDE_SEQAN_ARG_PARSE_ARG_PARSE_ARGUMENT_H_
#define SEQAN_INCLUDE_SEQAN_ARG_PARSE_ARG_PARSE_ARGUMENT_H_

#include <seqan/arg_parse/arg_parse_exceptions.h>
#include <seqan/arg_parse/arg_parse_type_support.h>

#include <string>
#include <vector>
#include <sstream>

namespace seqan {

// ==========================================================================
// Forwards
// ==========================================================================

// Required for _checkStringRestrictions().
inline std::string getFileExtension(ArgParseArgument const & me, unsigned pos);

// ==========================================================================
// Tags, Classes, Enums
// ==========================================================================

// ----------------------------------------------------------------------------
// Class ArgParseArgument
// ----------------------------------------------------------------------------

/*!
 * @class ArgParseArgument
 * @implements AssignableConcept
 * @headerfile <seqan/arg_parse.h>
 * @brief Information for a specific command line argument.
 *
 * @signature class ArgParseArgument
 */

/*!
 * @enum ArgParseArgument::ArgumentType
 * @headerfile <seqan/arg_parse.h>
 * @brief Define the type of an @link ArgParseArgument @endlink.
 *
 * @signature enum ArgParseArgument::ArgumentType;
 *
 * @section Examples
 *
 * In the following example, the types <tt>INPUT_FILE</tt>, <tt>OUTPUT_FILE</tt>, and <tt>DOUBLE</tt> are used.
 *
 * @include demos/dox/arg_parse/argument_parser.cpp
 */

/*!
 * @val ArgParseArgument::ArgumentType STRING
 * @brief Argument is a string.
 *
 * @val ArgParseArgument::ArgumentType ArgParseArgument::INTEGER;
 * @brief Argument is a signed 32 bit integer.
 *
 * @val ArgParseArgument::ArgumentType ArgParseArgument::INT64;
 * @brief Argument is a signed 64 bit integer.
 *
 * @val ArgParseArgument::ArgumentType ArgParseArgument::DOUBLE;
 * @brief Argument is a floating point number stored as double.
 *
 * @val ArgParseArgument::ArgumentType ArgParseArgument::INPUT_FILE;
 * @brief Argument is an input file.
 *
 * @val ArgParseArgument::ArgumentType ArgParseArgument::OUTPUT_FILE;
 * @brief Argument is an output file.
 *
 * @val ArgParseArgument::ArgumentType ArgParseArgument::INPUT_PREFIX;
 * @brief Argument is a prefix to input file(s).
 *
 * @val ArgParseArgument::ArgumentType ArgParseArgument::OUTPUT_PREFIX;
 * @brief Argument is a prefix to output file(s).
 */

/*!
 * @fn ArgParseArgument::ArgParseArgument
 * @brief Constructor
 *
 * @signature ArgParseArgument::ArgParseArgument(argumentType[, argumentLabel[, isListArgument[, numberOfArgument]]]);
 *
 * @param[in] argumentType      Type of the argument (<tt>ArgParseArgument::ArgumentType</tt>).
 * @param[in] argumentLabel     Label for the argument (<tt>char const *</tt>).
 * @param[in] isListArgument    Whether or not this argument can be given multiple times (<tt>bool</tt>).
 * @param[in] numberOfArguments Number of times the argument must be given.  E.g. set to 2 for the parser to always
 *                              expect two values (<tt>int</tt>, default is 1).
 */

class ArgParseArgument
{
public:
    enum ArgumentType
    {
        // argument is
        BOOL,
        STRING,      // .. a string
        INTEGER,     // .. an integer
        INT64,       // .. a 64 bit integer
        DOUBLE,      // .. a float
        INPUT_FILE,   // .. an inputfile (implicitly also a string)
        OUTPUT_FILE,  // .. an outputfile (implicitly also a string)
        INPUT_PREFIX, // .. an inputprefix (implicitly also a string)
        ///@deprecated use INPUT_PREFIX instead
        INPUTPREFIX = INPUT_PREFIX,
        OUTPUT_PREFIX, // .. an outoutprefix (implicitly also a string)
        INPUT_DIRECTORY,
        OUTPUT_DIRECTORY
    };


    // ----------------------------------------------------------------------------
    // Members to store type information
    // ----------------------------------------------------------------------------
    ArgumentType _argumentType;
    unsigned     _numberOfValues;
    std::string  _argumentLabel;
    bool         _isListArgument;

    // ----------------------------------------------------------------------------
    // Members to store the values
    // ----------------------------------------------------------------------------
    std::vector<std::string>  defaultValue;
    std::vector<std::string>  value;
    // Override for the file extension;  only used for input/output file arguments.
    std::vector<std::string> _fileExtensions;

    // ----------------------------------------------------------------------------
    // Members for restrictions
    // ----------------------------------------------------------------------------
    std::string           minValue;
    std::string           maxValue;
    std::vector<std::string> validValues;

    // ----------------------------------------------------------------------------
    // Tags
    // ----------------------------------------------------------------------------
    // Tags can be used to attach hints to the arguments (and options).  Currently,
    // this is used for tagging the "-file-ext" arguments as "file-ext-override"
    // and "gkn-ignore" for ignoring in GKN.
    std::vector<std::string> tags;

    // ----------------------------------------------------------------------------
    // Members to help text
    // ----------------------------------------------------------------------------
    std::string         _helpText;    // The help text shown on the command line

    // ----------------------------------------------------------------------------
    // Constructors
    // ----------------------------------------------------------------------------

    ArgParseArgument(ArgumentType argumentType,
                     std::string const & argumentLabel = "",
                     bool isListArgument = false,
                     unsigned numberOfValues = 1) :
        _argumentType(argumentType),
        _numberOfValues(numberOfValues),
        _argumentLabel(argumentLabel),
        _isListArgument(isListArgument),
        minValue(""),
        maxValue(""),
        _helpText("")
    {
        if (argumentType == ArgParseArgument::BOOL)
        {
            copy(BooleanArgumentValues_<>::LIST_TRUE.begin(), BooleanArgumentValues_<>::LIST_TRUE.end(),
                 std::back_inserter(validValues));
            copy(BooleanArgumentValues_<>::LIST_FALSE.begin(), BooleanArgumentValues_<>::LIST_FALSE.end(),
                 std::back_inserter(validValues));
        }
    }
};

// ==========================================================================
// Metafunctions
// ==========================================================================

// ==========================================================================
// Functions
// ==========================================================================

// ----------------------------------------------------------------------------
// Helper Function _typeToString()
// ----------------------------------------------------------------------------

inline std::string _typeToString(ArgParseArgument const & me)
{
    std::string typeName = "";

    switch (me._argumentType)
    {
    case ArgParseArgument::BOOL:
        typeName = "bool";
        break;

    case ArgParseArgument::DOUBLE:
        typeName = "double";
        break;

    case ArgParseArgument::INTEGER:
        typeName = "integer";
        break;

    case ArgParseArgument::INT64:
        typeName = "int64";
        break;

    case ArgParseArgument::STRING:
        typeName = "string";
        break;

    case ArgParseArgument::INPUT_FILE:
        typeName = "input_file";
        break;

    case ArgParseArgument::OUTPUT_FILE:
        typeName = "output_file";
        break;

    case ArgParseArgument::INPUT_PREFIX:
        typeName = "input_prefix";
        break;

    case ArgParseArgument::OUTPUT_PREFIX:
        typeName = "output_prefix";
        break;

    case ArgParseArgument::INPUT_DIRECTORY:
        typeName = "input_directory";
        break;

    case ArgParseArgument::OUTPUT_DIRECTORY:
        typeName = "output_directory";
        break;

    default:
        typeName = "unknown";
        break;
    }

    return typeName;
}

// ----------------------------------------------------------------------------
// Function isListArgument()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgParseArgument#isListArgument
 * @headerfile <seqan/arg_parse.h>
 *
 * @brief Returns whether the argument can be given more than one time.
 *
 * @signature bool isListArgument(arg);
 *
 * @param[in] arg The ArgParseArgument to query.
 *
 * @return bool <tt>true</tt> if it can be given multiple times, <tt>false</tt> otherwise.
 */

inline bool isListArgument(ArgParseArgument const & me)
{
    return me._isListArgument;
}

// ----------------------------------------------------------------------------
// Function isBooleanArgument()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgParseArgument#isBooleanArgument
 * @headerfile <seqan/arg_parse.h>
 * @brief Returns whether the argument is a bool.
 *
 * @signature bool isBooleanArgument(arg);
 *
 * @param[in] arg The ArgParseArgument to query.
 *
 * @return bool <tt>true</tt> if it is a bool, <tt>false</tt> otherwise.
 */

inline bool isBooleanArgument(ArgParseArgument const & me)
{
    return me._argumentType == ArgParseArgument::BOOL;
}

// ----------------------------------------------------------------------------
// Function isStringArgument()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgParseArgument#isStringArgument
 * @headerfile <seqan/arg_parse.h>
 *
 * @brief Returns whether the argument is a string.
 *
 * @signature bool isStringArgument(arg);
 *
 * @param[in] arg The ArgParseArgument to query.
 *
 * @return bool <tt>true</tt> if it is a string, <tt>false</tt> otherwise.
 */

inline bool isStringArgument(ArgParseArgument const & me)
{
    return (me._argumentType == ArgParseArgument::STRING) ||
           (me._argumentType == ArgParseArgument::INPUT_FILE) ||
           (me._argumentType == ArgParseArgument::OUTPUT_FILE) ||
           (me._argumentType == ArgParseArgument::INPUT_PREFIX) ||
           (me._argumentType == ArgParseArgument::OUTPUT_PREFIX) ||
           (me._argumentType == ArgParseArgument::INPUT_DIRECTORY) ||
           (me._argumentType == ArgParseArgument::OUTPUT_DIRECTORY);
}

// ----------------------------------------------------------------------------
// Function isIntegerArgument()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgParseArgument#isIntegerArgument
 * @headerfile <seqan/arg_parse.h>
 * @brief Returns whether the argument is an integer.
 *
 * @signature bool isIntegerArgument(arg);
 *
 * @param[in] arg The ArgParseArgument to query.
 *
 * @return bool <tt>true</tt> if it is an integer, <tt>false</tt> otherwise.
 */

inline bool isIntegerArgument(ArgParseArgument const & me)
{
    return me._argumentType == ArgParseArgument::INTEGER;
}

// ----------------------------------------------------------------------------
// Function isInt64Argument()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgParseArgument#isInt64Argument
 * @headerfile <seqan/arg_parse.h>
 * @brief Returns whether the argument is a 64 bit integer.
 *
 * @signature bool isInt64Argument(arg);
 *
 * @param[in] arg The ArgParseArgument to query.
 *
 * @return bool <tt>true</tt> if it is a 64 bit integer, <tt>false</tt> otherwise.
 */

inline bool isInt64Argument(ArgParseArgument const & me)
{
    return me._argumentType == ArgParseArgument::INT64;
}

// ----------------------------------------------------------------------------
// Function isDoubleArgument()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgParseArgument#isDoubleArgument
 * @headerfile <seqan/arg_parse.h>
 * @brief Returns whether the argument is a double integer.
 *
 * @signature bool isDoubleArgument(arg);
 *
 * @param[in] arg The ArgParseArgument to query.
 *
 * @return bool <tt>true</tt> if it is a double argument, <tt>false</tt> otherwise.
 */

inline bool isDoubleArgument(ArgParseArgument const & me)
{
    return me._argumentType == ArgParseArgument::DOUBLE;
}

// ----------------------------------------------------------------------------
// Function isInputFileArgument()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgParseArgument#isInputFileArgument
 * @headerfile <seqan/arg_parse.h>
 * @brief Returns whether the argument is a input file.
 *
 * @signature bool isInputFileArgument(arg);
 *
 * @param[in] arg The ArgParseArgument to query.
 *
 * @return bool <tt>true</tt> if it is a input file argument, <tt>false</tt> otherwise.
 */

inline bool isInputFileArgument(ArgParseArgument const & me)
{
    return me._argumentType == ArgParseArgument::INPUT_FILE ||
           me._argumentType == ArgParseArgument::INPUT_DIRECTORY;
}

// ----------------------------------------------------------------------------
// Function isOutputFileArgument()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgParseArgument#isOutputFileArgument
 * @headerfile <seqan/arg_parse.h>
 * @brief Returns whether the argument is a output file.
 *
 * @signature bool isOutputFileArgument(arg);
 *
 * @param[in] arg The ArgParseArgument to query.
 *
 * @return bool <tt>true</tt> if it is a output file argument, <tt>false</tt> otherwise.
 */

inline bool isOutputFileArgument(ArgParseArgument const & me)
{
    return me._argumentType == ArgParseArgument::OUTPUT_FILE ||
           me._argumentType == ArgParseArgument::OUTPUT_DIRECTORY;
}

// ----------------------------------------------------------------------------
// Function isOutputPrefixArgument()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgParseArgument#isOutputPrefixArgument
 * @headerfile <seqan/arg_parse.h>
 * @brief Returns whether the argument is an output prefix.
 *
 * @signature bool isOutputPrefixArgument(arg);
 *
 * @param[in] arg The ArgParseArgument to query.
 *
 * @return bool <tt>true</tt> if it is an output prefix argument, <tt>false</tt> otherwise.
 */

inline bool isOutputPrefixArgument(ArgParseArgument const & me)
{
    return me._argumentType == ArgParseArgument::OUTPUT_PREFIX;
}

// ----------------------------------------------------------------------------
// Function isOutputFileArgument()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgParseArgument#isInputPrefixArgument
 * @headerfile <seqan/arg_parse.h>
 * @brief Returns whether the argument is an input prefix argument.
 *
 * @signature bool isInputPrefixArgument(arg);
 *
 * @param[in] arg The ArgParseArgument to query.
 *
 * @return bool <tt>true</tt> if it is an input prefix argument, <tt>false</tt> otherwise.
 */

inline bool isInputPrefixArgument(ArgParseArgument const & me)
{
    return me._argumentType == ArgParseArgument::INPUT_PREFIX;
}

// ----------------------------------------------------------------------------
// Function getArgumentType()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgParseArgument#getArgumentType
 * @headerfile <seqan/arg_parse.h>
 * @brief Return the <tt>ArgParseArgument::ArgumentType</tt>.
 *
 * @signature std::string getArgumentType(arg);
 *
 * @param[in] arg The ArgParseArgument to query.
 *
 * @return ArgumentType The argument type.
 */

inline ArgParseArgument::ArgumentType getArgumentType(ArgParseArgument const & me)
{
    return me._argumentType;
}

// ----------------------------------------------------------------------------
// Function getArgumentTypeAsString()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgParseArgument#getArgumentTypeAsString
 * @headerfile <seqan/arg_parse.h>
 * @brief Return argument type As a string.
 *
 * @signature std::string getArgumentTypeAsString(arg);
 *
 * @param[in] arg The ArgParseArgument to query.
 *
 * @return std::string The argument type as a STL string.
 */

inline std::string getArgumentTypeAsString(ArgParseArgument const & me)
{
    return _typeToString(me._argumentType);
}

// ----------------------------------------------------------------------------
// Function getArgumentLabel()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgParseArgument#getArgumentLabel
 * @headerfile <seqan/arg_parse.h>
 * @brief Return argument label.
 *
 * @signature std::string getArgumentLabel(arg);
 *
 * @param[in] arg The ArgParseArgument to query.
 *
 * @return std::string The argument label as a STL string.
 */

inline std::string getArgumentLabel(ArgParseArgument const & me)
{
    return me._argumentLabel;
}

// ----------------------------------------------------------------------------
// Helper Function _intervalAssert()
// ----------------------------------------------------------------------------

// this methods ensures that the given arguments define a valid interval
// otherwise it will trigger a SEQAN_CHECK failure
template <typename TIntervalBorder>
inline void _intervalAssert(const std::string minValueAsString, const std::string maxValueAsString)
{
    if (minValueAsString != "" && maxValueAsString != "")
        SEQAN_CHECK(_cast<TIntervalBorder>(minValueAsString) <= _cast<TIntervalBorder>(maxValueAsString),
                    "The interval [%s:%s] is invalid. Please specify a valid interval.",
                    minValueAsString.c_str(),
                    maxValueAsString.c_str());
}

// ----------------------------------------------------------------------------
// Function setMinValue()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgParseArgument#setMinValue
 * @headerfile <seqan/arg_parse.h>
 * @brief Set smallest allowed value for the argument.
 *
 * @signature void setMinValue(arg, minValue);
 *
 * @param[in,out] arg      The ArgParseArgument to set the smallest value of.
 * @param[in]     minValue The smallest value to set (<tt>std::string</tt>).
 */

inline void setMinValue(ArgParseArgument & me, const std::string minValue)
{
    if (isDoubleArgument(me))
    {
        SEQAN_CHECK(_isCastable<double>(minValue), "The maximal value for a double argument must be double.");
        _intervalAssert<double>(minValue, me.maxValue);
        me.minValue = minValue;
    }
    else if (isIntegerArgument(me))
    {
        SEQAN_CHECK(_isCastable<int>(minValue), "The maximal value for an integer argument must be an integer");
        _intervalAssert<int>(minValue, me.maxValue);
        me.minValue = minValue;
    }
    else if (isInt64Argument(me))
    {
        SEQAN_CHECK(_isCastable<int64_t>(minValue), "The maximal value for a 64 integer argument must be a 64 bit integer");
        _intervalAssert<int64_t>(minValue, me.maxValue);
        me.minValue = minValue;
    }
    else
        SEQAN_FAIL("min/max values are not applicable to non numeric arguments");
}

// ----------------------------------------------------------------------------
// Function setMaxValue()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgParseArgument#setMaxValue
 * @headerfile <seqan/arg_parse.h>
 * @brief Set smallest allowed value for the argument.
 *
 * @signature void setMaxValue(arg, maxValue);
 *
 * @param[in,out] arg      The ArgParseArgument to set the smallest value of.
 * @param[in]     maxValue The largest value to set (<tt>std::string</tt>).
 */

inline void setMaxValue(ArgParseArgument & me, const std::string maxValue)
{
    if (isDoubleArgument(me))
    {
        SEQAN_CHECK(_isCastable<double>(maxValue), "The maximal value for a double argument must be double.");
        _intervalAssert<double>(me.minValue, maxValue);
        me.maxValue = maxValue;
    }
    else if (isIntegerArgument(me))
    {
        SEQAN_CHECK(_isCastable<int>(maxValue), "The maximal value for an integer argument must be an integer");
        _intervalAssert<int>(me.minValue, maxValue);
        me.maxValue = maxValue;
    }
    else if (isInt64Argument(me))
    {
        SEQAN_CHECK(_isCastable<int>(maxValue), "The maximal value for a 64 bit integer argument must be an 64 bit integer");
        _intervalAssert<int>(me.minValue, maxValue);
        me.maxValue = maxValue;
    }
    else
        SEQAN_FAIL("min/max values are not applicable to non numeric arguments");
}

// ----------------------------------------------------------------------------
// Function setValidValues()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgParseArgument#setValidValues
 * @headerfile <seqan/arg_parse.h>
 * @brief Set list of valid values.
 *
 * @signature void setValidValues(arg, values);
 *
 * @param[in,out] arg    The ArgParseArgument to set the valid values for.
 * @param[in]     values Either a <tt>std::string</tt> containing all valid entries, separated by spaces or a
 *                       <tt>std::vector&lt;std::string&gt;</tt> with the valid entries.
 *
 * If the argument is of type string then the list of valid values is the case-sensitive list of string values
 * allowed for this argument.  If it is an input or output file then the list of valid values is a list of
 * case-insentive file extensions identifying the allowed types.
 *
 * @section Examples
 *
 * An example of setting allowed values for a string option.
 *
 * @code{.cpp}
 * seqan::ArgParseArgument stringArg(seqan::ArgParseArgument::STRING);
 * setValidValues(stringArg, "one two three");  // one of {"one", "two", "three"}
 *
 * std::vector<std::string> values;
 * values.push_back("four");
 * values.push_back("five");
 * setValidValues(stringArg, values);  // one of {"four", "five"}
 * @endcode
 *
 * An example for an input file option.  Note that by changing <tt>INPUT_FILE</tt> to <tt>OUTPUT_FILE</tt> below,
 * the example would be the same for output files.
 *
 * @code{.cpp}
 * seqan::ArgParseArgument fileArg(seqan::ArgParseArgument::INPUT_FILE);
 * setValidValues(fileArg, "fq fastq");  // file must end in ".fq" or ".fastq"
 *
 * std::vector<std::string> values;
 * values.push_back("sam");
 * values.push_back("bam");
 * setValidValues(fileArg, values);  // file must end in ".sam" or ".bam"
 * @endcode
 */

inline void setValidValues(ArgParseArgument & me, std::vector<std::string> const & values)
{
    if (isDoubleArgument(me) || isIntegerArgument(me) || isBooleanArgument(me))
        SEQAN_FAIL("ArgParseArgument does not support setting valid values for numeric or boolean arguments.");

    me.validValues = values;
}

inline void setValidValues(ArgParseArgument & me, std::string const & valuesString)
{
    if (isDoubleArgument(me) || isIntegerArgument(me) || isBooleanArgument(me))
        SEQAN_FAIL("ArgParseArgument does not support setting valid values for numeric or boolean arguments.");

    // convert array to String<std::string>
    std::vector<std::string> values;
    std::string current_argument;

    for (std::string::const_iterator ch  = valuesString.begin(); ch != valuesString.end(); ++ch)
    {
        if (*ch == ' ')
        {
            appendValue(values, current_argument);
            current_argument = "";
        }
        else
        {
            append(current_argument, *ch);
        }
    }
    if (current_argument != "")
        appendValue(values, current_argument);

    setValidValues(me, values);
}

// ----------------------------------------------------------------------------
// Function setHelpText()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgParseArgument#setHelpText
 * @headerfile <seqan/arg_parse.h>
 * @brief Set the help text for an ArgParseArgument.
 *
 * @signature void setHelpText(arg, text);
 *
 * @param[in,out] arg  The ArgParseArgument to set the help text for.
 * @param[in]     text The text to display as the description of the argument (<tt>std::string</tt>).
 */

inline void setHelpText(ArgParseArgument & me, std::string const & text)
{
    me._helpText = text;
}

// ----------------------------------------------------------------------------
// Helper Function _isInInterval()
// ----------------------------------------------------------------------------

// check if the given value is in the provided interval
template <typename TTarget, typename TString>
inline bool _isInInterval(TString value, TString lowerIntervalBound, TString upperIntervalBound)
{
    bool isInInterval = true;

    if (lowerIntervalBound != "")
        isInInterval &= (_cast<TTarget>(lowerIntervalBound) <= _cast<TTarget>(value));
    if (upperIntervalBound != "")
        isInInterval &= (_cast<TTarget>(value) <= _cast<TTarget>(upperIntervalBound));

    return isInInterval;
}

// ----------------------------------------------------------------------------
// Helper Function _checkNumericArgument()
// ----------------------------------------------------------------------------

// test if the values can be assigned to the option and is in the given boundaries
template <typename TNumerical>
inline void _checkNumericArgument(ArgParseArgument const & me, std::string const & value)
{
    if (!_isCastable<TNumerical>(value))
    {
        std::stringstream what;
        what << "the given value '" << value << "' cannot be casted to " << _typeToString(me);
        SEQAN_THROW(ParseError(what.str()));
    }

    if (!_isInInterval<TNumerical>(value, me.minValue, me.maxValue))
    {
        std::stringstream what;
        what << "the given value '" << value << "' is not in the interval ["
             << (me.minValue != "" ? me.minValue : "-inf") << ":"
             << (me.maxValue != "" ? me.maxValue : "+inf") << "]";

        SEQAN_THROW(ParseError(what.str()));
    }
}

// ----------------------------------------------------------------------------
// Helper Function _compareExtension()
// ----------------------------------------------------------------------------

inline bool _compareExtension(std::string const & str, std::string const & ext)
{
    std::string str_ext = str.substr(str.size() - ext.size());
    for (size_t i = 0; i < str_ext.size() && i < ext.size(); ++i)
    {
        if (tolower(str_ext[i]) != tolower(ext[i]))
            return false;
    }
    return true;
}

// ----------------------------------------------------------------------------
// Helper Function _checkStringRestrictions()
// ----------------------------------------------------------------------------

// The parameter i gives the index of the value in the argument.

inline void _checkStringRestrictions(ArgParseArgument const & me, std::string const &value,
                                     unsigned i)
{
    typedef std::vector<std::string>::const_iterator TVectorIterator;

    // we only check valid values for files and string arguments, but not for prefix arguments
    if (!empty(me.validValues) && !(isInputPrefixArgument(me) || isOutputPrefixArgument(me)))
    {
        // The file name "-" is reserved for stdin or stdout
        if ((isInputFileArgument(me) || isOutputFileArgument(me)) && value == "-")
            return;

        // Allow the filename to be a pipe (without checking its extension)
        if (isInputFileArgument(me) && _isPipe(value.c_str()))
            return;

        bool isContained = false;
        for (TVectorIterator validValue = me.validValues.begin();
             validValue != me.validValues.end();
             ++validValue)
        {
            // if it is an input or output file, we only check the file endings
            if (isInputFileArgument(me) || isOutputFileArgument(me))
            {
                if (length(*validValue) > length(getFileExtension(me, i)))
                    continue;
                else
                    isContained |= _compareExtension(getFileExtension(me, i), *validValue);
            }
            else
            {
                isContained |= (*validValue == value);
            }
            if (isContained)
                break;
        }
        if (!isContained)
        {
            std::stringstream what;
            if (isInputFileArgument(me) || isOutputFileArgument(me))
                what << "the given path '" << value << "' does not have one of the valid file extensions [";
            else
                what << "the given value '" << value << "' is not in the list of allowed values [";
            for (TVectorIterator validValue = me.validValues.begin();
                 validValue != me.validValues.end();
                 ++validValue)
            {
                if (validValue != me.validValues.begin())
                    what << ", ";
                what << ((isInputFileArgument(me) || isOutputFileArgument(me)) ? "*" : "") << *validValue;
            }
            what << "]";
            if (i < me._fileExtensions.size())
                what << "; the file extension was overridden to be '" << getFileExtension(me, i) << "'";
            SEQAN_THROW(ParseError(what.str()));
        }
    }
}

// ----------------------------------------------------------------------------
// Helper Function _checkBooleanValidValues()
// ----------------------------------------------------------------------------

inline void _checkBooleanValidValues(ArgParseArgument const & me, std::string const & value)
{
    SEQAN_ASSERT(isBooleanArgument(me));

    std::string value_up{value};
    std::transform(value.begin(), value.end(), value_up.begin(), ::toupper); // allow for lowercase letters
    bool isContained = (std::find(me.validValues.begin(), me.validValues.end(), value_up)
                        != me.validValues.end());

    if (!isContained)
    {
        std::stringstream what;
        what << "the given value '" << value << "' is not in the list of allowed values [";

        for (auto validValue = me.validValues.begin(); validValue != me.validValues.end(); ++validValue)
        {
            if (validValue != me.validValues.begin())
                what << ", ";
            what << *validValue;
        }
        what << "]";
        SEQAN_THROW(ParseError(what.str()));
    }
}

// ----------------------------------------------------------------------------
// Function _checkValue()
// ----------------------------------------------------------------------------

// Check value before or after assignment.
//
// The parameter i gives the index of the value to check for overriding the extension in case of file arguments.

inline void _checkValue(ArgParseArgument const & me, std::string val, unsigned i = 0)
{
    // type checks
    if (isIntegerArgument(me))
        _checkNumericArgument<int>(me, val);

    if (isInt64Argument(me))
        _checkNumericArgument<int64_t>(me, val);

    if (isDoubleArgument(me))
        _checkNumericArgument<double>(me, val);

    // check valid values
    if (isBooleanArgument(me))
        _checkBooleanValidValues(me, val);

    if (isStringArgument(me))
        _checkStringRestrictions(me, val, i);
}

inline void _checkValue(ArgParseArgument const & me)
{
    unsigned i = 0;
    for (std::vector<std::string>::const_iterator it = me.value.begin(); it != me.value.end(); ++it, ++i)
        _checkValue(me, *it, i);
}

// ----------------------------------------------------------------------------
// Function _assignArgumentValue()
// ----------------------------------------------------------------------------

inline void _assignArgumentValue(ArgParseArgument & me, std::string const & value)
{
    // assignment
    if (isListArgument(me)) // just append
    {
        appendValue(me.value, value, Exact());
    }
    else
    {
        // check if we already set all expected arguments
        if (length(me.value) == me._numberOfValues)
            clear(me.value);
        appendValue(me.value, value, Exact());
    }
}

// ----------------------------------------------------------------------------
// Function getArgumentValue()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgParseArgument#getArgumentValue
 * @headerfile <seqan/arg_parse.h>
 * @brief Return the value of the argument.
 *
 * @signature std::string getArgumentValue(arg[, argNo]);
 *
 * @param[in,out] arg   The ArgParseArgument to query.
 * @param[in]     argNo In case that the ArgParseArgument allowed multiple values, give the index of the argument
 *                      that you want to retrieve (<tt>unsigned</tt>, starts at 0).
 *
 * @return std::string Const-reference to the argument value.
 */

inline std::string const & getArgumentValue(ArgParseArgument const & me, unsigned argNo)
{
    SEQAN_CHECK(argNo < me.value.size() || argNo < me.defaultValue.size(),
                "ArgParseArgument: No value set for index %d", argNo);

    if (argNo < me.value.size())
        return me.value[argNo];
    else
        return me.defaultValue[argNo];
}

inline std::string const & getArgumentValue(ArgParseArgument const & me)
{
    return getArgumentValue(me, 0);
}

// ----------------------------------------------------------------------------
// Function getArgumentValues()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgParseArgument#getArgumentValues
 * @headerfile <seqan/arg_parse.h>
 * @brief Return all values of the argument.
 *
 * @signature std::vector<std::string> getArgumentValue(arg);
 *
 * @param[in] arg   The ArgParseArgument to query.
 *
 * @return std::vector<std::string> Const-reference to the argument values.
 */

inline std::vector<std::string> const & getArgumentValues(ArgParseArgument const & me)
{
    if (!me.value.empty())
        return me.value;
    else
        return me.defaultValue;
}

// ----------------------------------------------------------------------------
// Function hasArgumentValue()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgParseArgument#hasArgumentValue
 * @headerfile <seqan/arg_parse.h>
 * @brief Return whether a value is available.
 *
 * @signature bool hasValue(arg[, pos]);
 *
 * @param[in] arg The ArgParseArgument to query.
 * @param[in] pos The position of the argument in case of being a list (<tt>unsigned</tt>, 0-based, default is 0).
 *
 * @return bool <tt>true</tt> if <tt>pos</tt> is less than the size and the argument is non-empty.
 */

inline bool hasValue(ArgParseArgument const & arg, unsigned position)
{
    return arg.value.size() > position || arg.defaultValue.size() > position;
}

inline bool hasValue(ArgParseArgument const & arg)
{
    return hasValue(arg, 0);
}

// ----------------------------------------------------------------------------
// Function isSet()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgParseArgument#isSet
 * @headerfile <seqan/arg_parse.h>
 * @brief Returns true if a value was assigned to the argument.
 *
 * @signature bool isSet(arg):
 *
 * @param[in] arg The ArgParseArgument to query.
 *
 * @return bool <tt>true</tt> if a value was assigned, <tt>false</tt> otherwise.
 */

inline bool isSet(ArgParseArgument const & me)
{
    return !me.value.empty();
}

// ----------------------------------------------------------------------------
// Function hasDefault()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgParseArgument#hasDefault
 * @headerfile <seqan/arg_parse.h>
 * @brief Returns whether the argument has a default value.
 *
 * @signature bool hasDefault(arg);
 *
 * @param[in] arg The argument to query.
 *
 * @return bool <tt>true</tt> if the argument has a default value and <tt>false</tt> if not.
 */

inline bool hasDefault(ArgParseArgument const & me)
{
    return !me.defaultValue.empty();
}

// ----------------------------------------------------------------------------
// Function numberOfArguments
// ----------------------------------------------------------------------------

/*!
 * @fn ArgParseArgument#numberOfAllowedValues
 * @headerfile <seqan/arg_parse.h>
 * @brief Returns the number of allowed values for this ArgParseArgument.
 *
 * @signature unsigned numberOfAllowedValues(arg);
 *
 * @param[in] arg The ArgParseArgument to query.
 *
 * @return unsigned The number of allowed values.
 */

inline unsigned numberOfAllowedValues(ArgParseArgument const & me)
{
    return me._numberOfValues;
}

// ----------------------------------------------------------------------------
// Function getFileExtension()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgParseArgument#getFileExtension
 * @headerfile <seqan/arg_parse.h>
 * @brief Returns the file extension for the given file argument.
 *
 * Only valid when argument is an INPUT_FILE or OUTPUT_FILE.
 *
 * Halts the program if not an input or output file argument.
 *
 * Can be overridden with special hidden options.
 * For arguments, you can pass <tt>--arg-&lt;num&gt;-file-ext</tt> for argument <tt>num</tt>.
 * For parameters, you can pass <tt>--&lt;param-name&gt;-file-ext</tt> for the option named <tt>param-name</tt>.
 *
 * @signature std::string getFileExtension(arg[, pos]);
 *
 * @param[in] arg The ArgParseArgument to query.
 * @param[in] pos The position of the value to retrieve if multiple values (<tt>unsigned</tt>).
 *
 * @return std::string The file extension, empty if no extension or not set.
 */

inline std::string getFileExtension(ArgParseArgument const & me, unsigned pos = 0)
{
    if (!isInputFileArgument(me) && !isOutputFileArgument(me))
        SEQAN_FAIL("Cannot get file extension from non-file argument/option.");

    // Short-circuit to override file extension if set.
    if (pos < me._fileExtensions.size())
    {
        std::string result = me._fileExtensions[pos];
        if (!result.empty() && result[0] != '.')
            result.insert(0, ".");
        return result;
    }

    // Get argument value and break if empty.
    std::string value = getArgumentValue(me, pos);
    if (value.empty())
        return "";

    // If there is a list of valid values then we look for each of these in the path.
    if (!me.validValues.empty())
    {
        for (unsigned i = 0; i < length(me.validValues); ++i)
        {
            unsigned len = std::min(me.validValues[i].size(), value.size());
            std::string tmp = value.substr(value.size() - len);
            std::transform(tmp.begin(), tmp.end(), tmp.begin(), ::tolower);
            if (tmp == me.validValues[i])
                return me.validValues[i];
        }
        return "";
    }

    // Fall back to finding position of last dot.  Return suffix if found and empty string if not.
    size_t dotPos = value.find_last_of('.');
    if (dotPos == std::string::npos)
        return "";
    return value.substr(dotPos + 1);
}

} // namespace seqan

#endif // SEQAN_INCLUDE_SEQAN_ARG_PARSE_ARG_PARSE_ARGUMENT_H_