aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/dexon-foundation/mcl/include/cybozu/option.hpp
blob: a5dfd137d8dc5dce72e31d85cee397ba0b95675e (plain) (blame)
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
#pragma once
/**
    @file
    @brief command line parser

    @author MITSUNARI Shigeo(@herumi)
*/
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <iostream>
#include <limits>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <cybozu/exception.hpp>
#include <cybozu/atoi.hpp>

/*
    Option parser

    progName (opt1-name|opt2-name|...) param1 param2 ...
      param1:param1-help
      param2:param2-help
      -op1-name:opt1-help
      ...

    How to setup
    int num;
    -n num ; (optional) option => appendOpt(&x, <defaultValue>, "num", "num-help");
    -n num ; must option       => appendMust(&x, "num", "num-help");

    std::vector<int> v;
    -v s1 s2 s3 ...            => appendVec(&v, "v");

    Remark1: terminate parsing of v if argv begins with '-[^0-9]'
    Remark2: the begining character of opt-name is not a number ('0'...'9')
             because avoid conflict with minus number

    std::string file1;
    file1 is param             => appendParam(&file1, "input-file");
    file2 is optional param    => appendParamOpt(&file2, "output-file");

    How to use
    opt.parse(argc, argv);

    see sample/option_smpl.cpp
*/

namespace cybozu {

struct OptionError : public cybozu::Exception {
    enum Type {
        NoError = 0,
        BAD_OPT = 1,
        BAD_VALUE,
        NO_VALUE,
        OPT_IS_NECESSARY,
        PARAM_IS_NECESSARY,
        REDUNDANT_VAL,
        BAD_ARGC
    };
    Type type;
    int argPos;
    OptionError()
        : cybozu::Exception("OptionError", false)
        , type(NoError)
        , argPos(0)
    {
    }
    cybozu::Exception& set(Type _type, int _argPos = 0)
    {
        this->type = _type;
        this->argPos = _argPos;
        switch (_type) {
        case BAD_OPT:
            (*this) << "bad opt";
            break;
        case BAD_VALUE:
            (*this) << "bad value";
            break;
        case NO_VALUE:
            (*this) << "no value";
            break;
        case OPT_IS_NECESSARY:
            (*this) << "opt is necessary";
            break;
        case PARAM_IS_NECESSARY:
            (*this) << "param is necessary";
            break;
        case REDUNDANT_VAL:
            (*this) << "redundant argVal";
            break;
        case BAD_ARGC:
            (*this) << "bad argc";
        default:
            break;
        }
        return *this;
    }
};

namespace option_local {

template<class T>
bool convert(T* x, const char *str)
{
    std::istringstream is(str);
    is >> *x;
    return !!is;
}

template<>
inline bool convert(std::string* x, const char *str)
{
    *x = str;
    return true;
}

template<class T>
bool convertInt(T* x, const char *str)
{
    if (str[0] == '0' && str[1] == 'x') {
        bool b;
        *x = cybozu::hextoi(&b, str + 2);
        return b;
    }
    size_t len = strlen(str);
    int factor = 1;
    if (len > 1) {
        switch (str[len - 1]) {
        case 'k': factor = 1000; len--; break;
        case 'm': factor = 1000 * 1000; len--; break;
        case 'g': factor = 1000 * 1000 * 1000; len--; break;
        case 'K': factor = 1024; len--; break;
        case 'M': factor = 1024 * 1024; len--; break;
        case 'G': factor = 1024 * 1024 * 1024; len--; break;
        default: break;
        }
    }
    bool b;
    T y = cybozu::atoi(&b, str, len);
    if (!b) return false;
    if (factor > 1) {
        if ((std::numeric_limits<T>::min)() / factor <= y
            && y <= (std::numeric_limits<T>::max)() / factor) {
            *x = y * factor;
        } else {
            return false;
        }
    } else {
        *x = y;
    }
    return true;
}

#define CYBOZU_OPTION_DEFINE_CONVERT_INT(type) \
template<>inline bool convert(type* x, const char *str) { return convertInt(x, str); }

CYBOZU_OPTION_DEFINE_CONVERT_INT(int)
CYBOZU_OPTION_DEFINE_CONVERT_INT(long)
CYBOZU_OPTION_DEFINE_CONVERT_INT(long long)

CYBOZU_OPTION_DEFINE_CONVERT_INT(unsigned int)
CYBOZU_OPTION_DEFINE_CONVERT_INT(unsigned long)
CYBOZU_OPTION_DEFINE_CONVERT_INT(unsigned long long)

#undef CYBOZU_OPTION_DEFINE_CONVERT_INT

struct HolderBase {
    virtual ~HolderBase(){}
    virtual bool set(const char*) = 0;
    virtual HolderBase *clone() const = 0;
    virtual std::string toStr() const = 0;
    virtual const void *get() const = 0;
};

template<class T>
struct Holder : public HolderBase {
    T *p_;
    Holder(T *p) : p_(p) {}
    HolderBase *clone() const { return new Holder(p_); }
    bool set(const char *str) { return option_local::convert(p_, str); }
    std::string toStr() const
    {
        std::ostringstream os;
        os << *p_;
        return os.str();
    }
    const void *get() const { return (void*)p_; }
};

/*
    for gcc 7 with -fnew-ttp-matching
    this specialization is not necessary under -fno-new-ttp-matching
*/
template struct Holder<std::string>;

template<class T, class Alloc, template<class T_, class Alloc_>class Container>
struct Holder<Container<T, Alloc> > : public HolderBase {
    typedef Container<T, Alloc> Vec;
    Vec *p_;
    Holder(Vec *p) : p_(p) {}
    HolderBase *clone() const { return new Holder<Vec>(p_); }
    bool set(const char *str)
    {
        T t;
        bool b = option_local::convert(&t, str);
        if (b) p_->push_back(t);
        return b;
    }
    std::string toStr() const
    {
        std::ostringstream os;
        bool isFirst = true;
        for (typename Vec::const_iterator i = p_->begin(), ie = p_->end(); i != ie; ++i) {
            if (isFirst) {
                isFirst = false;
            } else {
                os << ' ';
            }
            os << *i;
        }
        return os.str();
    }
    const void *get() const { return (void*)p_; }
};

class Var {
    HolderBase *p_;
    bool isSet_;
public:
    Var() : p_(0), isSet_(false) { }
    Var(const Var& rhs) : p_(rhs.p_->clone()), isSet_(false) { }
    template<class T>
    explicit Var(T *x) : p_(new Holder<T>(x)), isSet_(false) { }

    ~Var() { delete p_; }

    void swap(Var& rhs) CYBOZU_NOEXCEPT
    {
        std::swap(p_, rhs.p_);
        std::swap(isSet_, rhs.isSet_);
    }
    void operator=(const Var& rhs)
    {
        Var v(rhs);
        swap(v);
    }
    bool set(const char *str)
    {
        isSet_ = true;
        return p_->set(str);
    }
    std::string toStr() const { return p_ ? p_->toStr() : ""; }
    bool isSet() const { return isSet_; }
    const void *get() const { return p_ ? p_->get() : 0; }
};

} // option_local

class Option {
    enum Mode { // for opt
        N_is0 = 0, // for bool by appendBoolOpt()
        N_is1 = 1,
        N_any = 2
    };
    enum ParamMode {
        P_exact = 0, // one
        P_optional = 1, // zero or one
        P_variable = 2 // zero or greater
    };
    struct Info {
        option_local::Var var;
        Mode mode; // 0 or 1 or any ; for opt, not used for Param
        bool isMust; // this option is must
        std::string opt; // option param name without '-'
        std::string help; // description of option

        Info() : mode(N_is0), isMust(false) {}
        template<class T>
        Info(T* pvar, Mode mode, bool isMust, const char *opt, const std::string& help)
            : var(pvar)
            , mode(mode)
            , isMust(isMust)
            , opt(opt)
            , help(help)
        {
        }
        friend inline std::ostream& operator<<(std::ostream& os, const Info& self)
        {
            os << self.opt << '=' << self.var.toStr();
            if (self.var.isSet()) {
                os << " (set)";
            } else {
                os << " (default)";
            }
            return os;
        }
        void put() const
        {
            std::cout << *this;
        }
        void usage() const
        {
            printf("  -%s %s%s\n", opt.c_str(), help.c_str(), isMust ? " (must)" : "");
        }
        void shortUsage() const
        {
            printf(" -%s %s", opt.c_str(), mode == N_is0 ? "" : mode == N_is1 ? "para" : "para...");
        }
        bool isSet() const { return var.isSet(); }
        const void *get() const { return var.get(); }
    };
    typedef std::vector<Info> InfoVec;
    typedef std::vector<std::string> StrVec;
    typedef std::map<std::string, size_t> OptMap;
    InfoVec infoVec_;
    InfoVec paramVec_;
    Info remains_;
    OptMap optMap_;
    bool showOptUsage_;
    ParamMode paramMode_;
    std::string progName_;
    std::string desc_;
    std::string helpOpt_;
    std::string help_;
    std::string usage_;
    StrVec delimiters_;
    StrVec *remainsAfterDelimiter_;
    int nextDelimiter_;
    template<class T>
    void appendSub(T *pvar, Mode mode, bool isMust, const char *opt, const std::string& help)
    {
        const char c = opt[0];
        if ('0' <= c && c <= '9') throw cybozu::Exception("Option::appendSub:opt must begin with not number") << opt;
        if (optMap_.find(opt) != optMap_.end()) {
            throw cybozu::Exception("Option::append:duplicate option") << opt;
        }
        optMap_[opt] = infoVec_.size();
        infoVec_.push_back(Info(pvar, mode, isMust, opt, help));
    }

    template<class T, class U>
    void append(T *pvar, const U& defaultVal, bool isMust, const char *opt, const std::string& help = "")
    {
        *pvar = defaultVal;
        appendSub(pvar, N_is1, isMust, opt, help);
    }
    /*
        don't deal with negative number as option
    */
    bool isOpt(const char *str) const
    {
        if (str[0] != '-') return false;
        const char c = str[1];
        if ('0' <= c && c <= '9') return false;
        return true;
    }
    void verifyParamMode()
    {
        if (paramMode_ != P_exact) throw cybozu::Exception("Option:appendParamVec:appendParam is forbidden after appendParamOpt/appendParamVec");
    }
    std::string getBaseName(const std::string& name) const
    {
        size_t pos = name.find_last_of("/\\");
        if (pos == std::string::npos) return name;
        return name.substr(pos + 1);
    }
    bool inDelimiters(const std::string& str) const
    {
        return std::find(delimiters_.begin(), delimiters_.end(), str) != delimiters_.end();
    }
public:
    Option()
        : showOptUsage_(true)
        , paramMode_(P_exact)
        , remainsAfterDelimiter_(0)
        , nextDelimiter_(-1)
    {
    }
    virtual ~Option() {}
    /*
        append optional option with default value
        @param pvar [in] pointer to option variable
        @param defaultVal [in] default value
        @param opt [in] option name
        @param help [in] option help
        @note you can use 123k, 56M if T is int/long/long long
        k : *1000
        m : *1000000
        g : *1000000000
        K : *1024
        M : *1024*1024
        G : *1024*1024*1024
    */
    template<class T, class U>
    void appendOpt(T *pvar, const U& defaultVal, const char *opt, const std::string& help = "")
    {
        append(pvar, defaultVal, false, opt, help);
    }
    /*
        default value of *pvar is false
    */
    void appendBoolOpt(bool *pvar, const char *opt, const std::string& help = "")
    {
        *pvar = false;
        appendSub(pvar, N_is0, false, opt, help);
    }
    /*
        append necessary option
        @param pvar [in] pointer to option variable
        @param opt [in] option name
        @param help [in] option help
    */
    template<class T>
    void appendMust(T *pvar, const char *opt, const std::string& help = "")
    {
        append(pvar, T(), true, opt, help);
    }
    /*
        append vector option
        @param pvar [in] pointer to option variable
        @param opt [in] option name
        @param help [in] option help
    */
    template<class T, class Alloc, template<class T_, class Alloc_>class Container>
    void appendVec(Container<T, Alloc> *pvar, const char *opt, const std::string& help = "")
    {
        appendSub(pvar, N_any, false, opt, help);
    }
    /*
        append parameter
        @param pvar [in] pointer to parameter
        @param opt [in] option name
        @param help [in] option help
    */
    template<class T>
    void appendParam(T *pvar, const char *opt, const std::string& help = "")
    {
        verifyParamMode();
        paramVec_.push_back(Info(pvar, N_is1, true, opt, help));
    }
    /*
        append optional parameter
        @param pvar [in] pointer to parameter
        @param defaultVal [in] default value
        @param opt [in] option name
        @param help [in] option help
        @note you can call appendParamOpt once after appendParam
    */
    template<class T, class U>
    void appendParamOpt(T *pvar, const U& defaultVal, const char *opt, const std::string& help = "")
    {
        verifyParamMode();
        *pvar = defaultVal;
        paramMode_ = P_optional;
        paramVec_.push_back(Info(pvar, N_is1, false, opt, help));
    }
    /*
        append remain parameter
        @param pvar [in] pointer to vector of parameter
        @param opt [in] option name
        @param help [in] option help
        @note you can call appendParamVec once after appendParam
    */
    template<class T, class Alloc, template<class T_, class Alloc_>class Container>
    void appendParamVec(Container<T, Alloc> *pvar, const char *name, const std::string& help = "")
    {
        verifyParamMode();
        paramMode_ = P_variable;
        remains_.var = option_local::Var(pvar);
        remains_.mode = N_any;
        remains_.isMust = false;
        remains_.opt = name;
        remains_.help = help;
    }
    void appendHelp(const char *opt, const std::string& help = ": show this message")
    {
        helpOpt_ = opt;
        help_ = help;
    }
    /*
        stop parsing after delimiter is found
        @param delimiter [in] string to stop
        @param remain [out] set remaining strings if remain
    */
    void setDelimiter(const std::string& delimiter, std::vector<std::string> *remain = 0)
    {
        delimiters_.push_back(delimiter);
        remainsAfterDelimiter_ = remain;
    }
    /*
        stop parsing after delimiter is found
        @param delimiter [in] string to stop to append list of delimiters
    */
    void appendDelimiter(const std::string& delimiter)
    {
        delimiters_.push_back(delimiter);
    }
    /*
        clear list of delimiters
    */
    void clearDelimiterList() { delimiters_.clear(); }
    /*
        return the next position of delimiter between [0, argc]
        @note return argc if delimiter is not set nor found
    */
    int getNextPositionOfDelimiter() const { return nextDelimiter_; }
    /*
        parse (argc, argv)
        @param argc [in] argc of main
        @param argv [in] argv of main
        @param startPos [in] start position of argc
        @param progName [in] used instead of argv[0]
    */
    bool parse(int argc, const char *const argv[], int startPos = 1, const char *progName = 0)
    {
        if (argc < 1 || startPos > argc) return false;
        progName_ = getBaseName(progName ? progName : argv[startPos - 1]);
        nextDelimiter_ = argc;
        OptionError err;
        for (int pos = startPos; pos < argc; pos++) {
            if (inDelimiters(argv[pos])) {
                nextDelimiter_ = pos + 1;
                if (remainsAfterDelimiter_) {
                    for (int i = nextDelimiter_; i < argc; i++) {
                        remainsAfterDelimiter_->push_back(argv[i]);
                    }
                }
                break;
            }
            if (isOpt(argv[pos])) {
                const std::string str = argv[pos] + 1;
                if (helpOpt_ == str) {
                    usage();
                    exit(0);
                }
                OptMap::const_iterator i = optMap_.find(str);
                if (i == optMap_.end()) {
                    err.set(OptionError::BAD_OPT, pos);
                    goto ERR;
                }

                Info& info = infoVec_[i->second];
                switch (info.mode) {
                case N_is0:
                    if (!info.var.set("1")) {
                        err.set(OptionError::BAD_VALUE, pos);
                        goto ERR;
                    }
                    break;
                case N_is1:
                    pos++;
                    if (pos == argc) {
                        err.set(OptionError::BAD_VALUE, pos) << (std::string("no value for -") + info.opt);
                        goto ERR;
                    }
                    if (!info.var.set(argv[pos])) {
                        err.set(OptionError::BAD_VALUE, pos) << (std::string(argv[pos]) + " for -" + info.opt);
                        goto ERR;
                    }
                    break;
                case N_any:
                default:
                    {
                        pos++;
                        int j = 0;
                        while (pos < argc && !isOpt(argv[pos])) {
                            if (!info.var.set(argv[pos])) {
                                err.set(OptionError::BAD_VALUE, pos) << (std::string(argv[pos]) + " for -" + info.opt) << j;
                                goto ERR;
                            }
                            pos++;
                            j++;
                        }
                        if (j > 0) {
                            pos--;
                        } else {
                            err.set(OptionError::NO_VALUE, pos) << (std::string("for -") + info.opt);
                            goto ERR;
                        }
                    }
                    break;
                }
            } else {
                bool used = false;
                for (size_t i = 0; i < paramVec_.size(); i++) {
                    Info& param = paramVec_[i];
                    if (!param.var.isSet()) {
                        if (!param.var.set(argv[pos])) {
                            err.set(OptionError::BAD_VALUE, pos) << (std::string(argv[pos]) + " for " + param.opt);
                            goto ERR;
                        }
                        used = true;
                        break;
                    }
                }
                if (!used) {
                    if (paramMode_ == P_variable) {
                        remains_.var.set(argv[pos]);
                    } else {
                        err.set(OptionError::REDUNDANT_VAL, pos) << argv[pos];
                        goto ERR;
                    }
                }
            }
        }
        // check whether must-opt is set
        for (size_t i = 0; i < infoVec_.size(); i++) {
            const Info& info = infoVec_[i];
            if (info.isMust && !info.var.isSet()) {
                err.set(OptionError::OPT_IS_NECESSARY) << info.opt;
                goto ERR;
            }
        }
        // check whether param is set
        for (size_t i = 0; i < paramVec_.size(); i++) {
            const Info& param = paramVec_[i];
            if (param.isMust && !param.var.isSet()) {
                err.set(OptionError::PARAM_IS_NECESSARY) << param.opt;
                goto ERR;
            }
        }
        // check whether remains is set
        if (paramMode_ == P_variable && remains_.isMust && !remains_.var.isSet()) {
            err.set(OptionError::PARAM_IS_NECESSARY) << remains_.opt;
            goto ERR;
        }
        return true;
    ERR:
        assert(err.type);
        printf("%s\n", err.what());
        return false;
    }
    /*
        show desc at first in usage()
    */
    void setDescription(const std::string& desc)
    {
        desc_ = desc;
    }
    /*
        show command line after desc
        don't put option message if not showOptUsage
    */
    void setUsage(const std::string& usage, bool showOptUsage = false)
    {
        usage_ = usage;
        showOptUsage_ = showOptUsage;
    }
    void usage() const
    {
        if (!desc_.empty()) printf("%s\n", desc_.c_str());
        if (usage_.empty()) {
            printf("usage:%s", progName_.c_str());
            if (!infoVec_.empty()) printf(" [opt]");
            for (size_t i = 0; i < infoVec_.size(); i++) {
                if (infoVec_[i].isMust) infoVec_[i].shortUsage();
            }
            for (size_t i = 0; i < paramVec_.size(); i++) {
                printf(" %s", paramVec_[i].opt.c_str());
            }
            if (paramMode_ == P_variable) {
                printf(" %s", remains_.opt.c_str());
            }
            printf("\n");
        } else {
            printf("%s\n", usage_.c_str());
            if (!showOptUsage_) return;
        }
        for (size_t i = 0; i < paramVec_.size(); i++) {
            const Info& param = paramVec_[i];
            if (!param.help.empty()) printf("  %s %s\n", paramVec_[i].opt.c_str(), paramVec_[i].help.c_str());
        }
        if (!remains_.help.empty()) printf("  %s %s\n", remains_.opt.c_str(), remains_.help.c_str());
        if (!helpOpt_.empty()) {
            printf("  -%s %s\n", helpOpt_.c_str(), help_.c_str());
        }
        for (size_t i = 0; i < infoVec_.size(); i++) {
            infoVec_[i].usage();
        }
    }
    friend inline std::ostream& operator<<(std::ostream& os, const Option& self)
    {
        for (size_t i = 0; i < self.paramVec_.size(); i++) {
            const Info& param = self.paramVec_[i];
            os << param.opt << '=' << param.var.toStr() << std::endl;
        }
        if (self.paramMode_ == P_variable) {
            os << "remains=" << self.remains_.var.toStr() << std::endl;
        }
        for (size_t i = 0; i < self.infoVec_.size(); i++) {
            os << self.infoVec_[i] << std::endl;
        }
        return os;
    }
    void put() const
    {
        std::cout << *this;
    }
    /*
        whether pvar is set or not
    */
    template<class T>
    bool isSet(const T* pvar) const
    {
        const void *p = static_cast<const void*>(pvar);
        for (size_t i = 0; i < paramVec_.size(); i++) {
            const Info& v = paramVec_[i];
            if (v.get() == p) return v.isSet();
        }
        if (remains_.get() == p) return remains_.isSet();
        for (size_t i = 0; i < infoVec_.size(); i++) {
            const Info& v = infoVec_[i];
            if (v.get() == p) return v.isSet();
        }
        throw cybozu::Exception("Option:isSet:no assigned var") << pvar;
    }
};

} // cybozu