Coverage Report

Created: 2026-12-01 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/vvenc/source/Lib/apputils/ParseArg.h
Line
Count
Source
1
/* -----------------------------------------------------------------------------
2
The copyright in this software is being made available under the Clear BSD
3
License, included below. No patent rights, trademark rights and/or 
4
other Intellectual Property Rights other than the copyrights concerning 
5
the Software are granted under this license.
6
7
The Clear BSD License
8
9
Copyright (c) 2019-2026, Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. & The VVenC Authors.
10
All rights reserved.
11
12
Redistribution and use in source and binary forms, with or without modification,
13
are permitted (subject to the limitations in the disclaimer below) provided that
14
the following conditions are met:
15
16
     * Redistributions of source code must retain the above copyright notice,
17
     this list of conditions and the following disclaimer.
18
19
     * Redistributions in binary form must reproduce the above copyright
20
     notice, this list of conditions and the following disclaimer in the
21
     documentation and/or other materials provided with the distribution.
22
23
     * Neither the name of the copyright holder nor the names of its
24
     contributors may be used to endorse or promote products derived from this
25
     software without specific prior written permission.
26
27
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
28
THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
29
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
31
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
32
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
33
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
34
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
35
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
36
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38
POSSIBILITY OF SUCH DAMAGE.
39
40
41
------------------------------------------------------------------------------------------- */
42
#pragma once
43
44
#include <iostream>
45
#include <sstream>
46
#include <fstream>
47
#include <string>
48
#include <list>
49
#include <map>
50
51
#include <algorithm>
52
#include <regex>
53
#include <cctype>
54
55
//! \ingroup Interface
56
//! \{
57
58
namespace apputils {
59
60
namespace program_options {
61
62
struct Options;
63
64
struct ParseFailure : public std::exception
65
{
66
  ParseFailure(std::string arg0, std::string val0) throw()
67
0
  : arg(arg0), val(val0)
68
0
  {}
69
70
0
  ~ParseFailure() throw() {};
71
72
  std::string arg;
73
  std::string val;
74
75
0
  const char* what() const throw() { return "Option Parse Failure"; }
76
};
77
78
struct ErrorReporter
79
{
80
14
  ErrorReporter() : is_errored(0) {}
81
0
  virtual ~ErrorReporter() {}
82
  virtual std::ostream& error(const std::string& where)
83
0
  {
84
0
    is_errored = 1;
85
0
    outstr << where << " error: ";
86
0
    return outstr;
87
0
  }
88
89
  virtual std::ostream& warn(const std::string& where)
90
0
  {
91
0
    is_warning = 1;
92
0
    outstr << where << " warning: ";
93
0
    return outstr;
94
0
  }
95
96
  bool is_errored = false;
97
  bool is_warning = false;
98
  std::stringstream outstr;
99
};
100
101
static ErrorReporter default_error_reporter;
102
103
struct SilentReporter : ErrorReporter
104
{
105
0
  SilentReporter() { }
106
0
  virtual ~SilentReporter() { }
107
0
  virtual std::ostream& error( const std::string& ) { return dest; }
108
0
  virtual std::ostream& warn ( const std::string& ) { return dest; }
109
  std::stringstream dest;
110
};
111
112
113
/** OptionBase: Virtual base class for storing information relating to a
114
 * specific option This base class describes common elements.  Type specific
115
 * information should be stored in a derived class. */
116
struct OptionBase
117
{
118
  OptionBase(const std::string& name, const std::string& desc, const bool bool_switch )
119
0
  : opt_string(name), opt_desc(desc), is_bool_switch(bool_switch)
120
0
  {};
121
122
0
  virtual ~OptionBase() {}
123
124
  /* parse argument arg, to obtain a value for the option */
125
  virtual void parse(const std::string& arg, ErrorReporter&) = 0;
126
  /* set the argument to the default value */
127
  virtual void setDefault() = 0;
128
0
  virtual const std::string getDefault( ) { return std::string(); }
129
0
  virtual const std::string getValue( ) { return std::string(); }
130
131
  std::string opt_string;
132
  std::string opt_desc;
133
  bool        is_bool_switch = false;
134
};
135
136
/** Type specific option storage */
137
template<typename T>
138
struct Option : public OptionBase
139
{
140
  Option(const std::string& name, T& storage, T default_val, const std::string& desc, const bool bool_switch )
141
0
  : OptionBase(name, desc, bool_switch), opt_storage(storage), opt_default_val(default_val)
142
0
  {}
Unexecuted instantiation: apputils::program_options::Option<bool>::Option(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool&, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencMsgLevel> >::Option(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToEnum<vvencMsgLevel>&, apputils::IStreamToEnum<vvencMsgLevel>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::Option<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::Option(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToRefVec<int> >::Option(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToRefVec<int>&, apputils::IStreamToRefVec<int>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToFunc<apputils::BitDepthAndColorSpace> >::Option(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToFunc<apputils::BitDepthAndColorSpace>&, apputils::IStreamToFunc<apputils::BitDepthAndColorSpace>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::Option<int>::Option(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int&, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToFunc<vvencPresetMode> >::Option(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToFunc<vvencPresetMode>&, apputils::IStreamToFunc<vvencPresetMode>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToAbbr<int, int> >::Option(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToAbbr<int, int>&, apputils::IStreamToAbbr<int, int>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToQP>::Option(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToQP&, apputils::IStreamToQP, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<bool> >::Option(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToEnum<bool>&, apputils::IStreamToEnum<bool>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<signed char> >::Option(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToEnum<signed char>&, apputils::IStreamToEnum<signed char>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencDecodingRefreshType> >::Option(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToEnum<vvencDecodingRefreshType>&, apputils::IStreamToEnum<vvencDecodingRefreshType>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToInt8>::Option(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToInt8&, apputils::IStreamToInt8, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencProfile> >::Option(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToEnum<vvencProfile>&, apputils::IStreamToEnum<vvencProfile>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencLevel> >::Option(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToEnum<vvencLevel>&, apputils::IStreamToEnum<vvencLevel>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencTier> >::Option(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToEnum<vvencTier>&, apputils::IStreamToEnum<vvencTier>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencHDRMode> >::Option(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToEnum<vvencHDRMode>&, apputils::IStreamToEnum<vvencHDRMode>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToFunc<int> >::Option(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToFunc<int>&, apputils::IStreamToFunc<int>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<int> >::Option(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToEnum<int>&, apputils::IStreamToEnum<int>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencHashType> >::Option(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToEnum<vvencHashType>&, apputils::IStreamToEnum<vvencHashType>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencSegmentMode> >::Option(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToEnum<vvencSegmentMode>&, apputils::IStreamToEnum<vvencSegmentMode>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencChromaFormat> >::Option(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToEnum<vvencChromaFormat>&, apputils::IStreamToEnum<vvencChromaFormat>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::Option<unsigned int>::Option(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned int&, unsigned int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToRefVec<double> >::Option(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToRefVec<double>&, apputils::IStreamToRefVec<double>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToArr<double> >::Option(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToArr<double>&, apputils::IStreamToArr<double>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::Option<double>::Option(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, double&, double, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToArr<int> >::Option(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToArr<int>&, apputils::IStreamToArr<int>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencCostMode> >::Option(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToEnum<vvencCostMode>&, apputils::IStreamToEnum<vvencCostMode>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToFixedPointU8>::Option(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToFixedPointU8&, apputils::IStreamToFixedPointU8, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToArr<unsigned int> >::Option(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToArr<unsigned int>&, apputils::IStreamToArr<unsigned int>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToArr<char> >::Option(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToArr<char>&, apputils::IStreamToArr<char>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::Option<vvencGOPEntry>::Option(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, vvencGOPEntry&, vvencGOPEntry, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
143
144
  void parse(const std::string& arg, ErrorReporter&);
145
146
  void setDefault()
147
0
  {
148
0
    opt_storage = opt_default_val;
149
0
  }
Unexecuted instantiation: apputils::program_options::Option<bool>::setDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencMsgLevel> >::setDefault()
Unexecuted instantiation: apputils::program_options::Option<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::setDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToRefVec<int> >::setDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToFunc<apputils::BitDepthAndColorSpace> >::setDefault()
Unexecuted instantiation: apputils::program_options::Option<int>::setDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToFunc<vvencPresetMode> >::setDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToAbbr<int, int> >::setDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToQP>::setDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<bool> >::setDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<signed char> >::setDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencDecodingRefreshType> >::setDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToInt8>::setDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencProfile> >::setDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencLevel> >::setDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencTier> >::setDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencHDRMode> >::setDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToFunc<int> >::setDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<int> >::setDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencHashType> >::setDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencSegmentMode> >::setDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencChromaFormat> >::setDefault()
Unexecuted instantiation: apputils::program_options::Option<unsigned int>::setDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToRefVec<double> >::setDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToArr<double> >::setDefault()
Unexecuted instantiation: apputils::program_options::Option<double>::setDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToArr<int> >::setDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencCostMode> >::setDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToFixedPointU8>::setDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToArr<unsigned int> >::setDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToArr<char> >::setDefault()
Unexecuted instantiation: apputils::program_options::Option<vvencGOPEntry>::setDefault()
150
  virtual const std::string getDefault( );
151
  virtual const std::string getValue  ( );
152
153
  T& opt_storage;
154
  T opt_default_val;
155
};
156
157
template<typename T>
158
inline
159
const std::string Option<T>::getValue( )
160
0
{
161
0
  std::ostringstream oss;
162
0
  oss << opt_storage;
163
0
  return oss.str();
164
0
}
Unexecuted instantiation: apputils::program_options::Option<bool>::getValue()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencMsgLevel> >::getValue()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToRefVec<int> >::getValue()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToFunc<apputils::BitDepthAndColorSpace> >::getValue()
Unexecuted instantiation: apputils::program_options::Option<int>::getValue()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToFunc<vvencPresetMode> >::getValue()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToAbbr<int, int> >::getValue()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToQP>::getValue()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<bool> >::getValue()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<signed char> >::getValue()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencDecodingRefreshType> >::getValue()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToInt8>::getValue()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencProfile> >::getValue()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencLevel> >::getValue()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencTier> >::getValue()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencHDRMode> >::getValue()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToFunc<int> >::getValue()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<int> >::getValue()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencHashType> >::getValue()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencSegmentMode> >::getValue()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencChromaFormat> >::getValue()
Unexecuted instantiation: apputils::program_options::Option<unsigned int>::getValue()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToRefVec<double> >::getValue()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToArr<double> >::getValue()
Unexecuted instantiation: apputils::program_options::Option<double>::getValue()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToArr<int> >::getValue()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencCostMode> >::getValue()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToFixedPointU8>::getValue()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToArr<unsigned int> >::getValue()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToArr<char> >::getValue()
Unexecuted instantiation: apputils::program_options::Option<vvencGOPEntry>::getValue()
165
166
template<>
167
inline
168
const std::string Option<std::string>::getValue( )
169
0
{
170
0
  std::ostringstream oss;
171
0
  if( opt_storage.empty() )
172
0
  {
173
0
    oss << "\"\"";
174
0
  }
175
0
  else
176
0
  {
177
0
    oss << opt_storage;
178
0
  }
179
0
  return oss.str();
180
0
}
181
182
template<typename T>
183
inline 
184
const std::string Option<T>::getDefault( )
185
0
{ 
186
0
  std::ostringstream oss;
187
0
  oss << opt_default_val;
188
0
  return oss.str(); 
189
0
}
Unexecuted instantiation: apputils::program_options::Option<bool>::getDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencMsgLevel> >::getDefault()
Unexecuted instantiation: apputils::program_options::Option<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::getDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToRefVec<int> >::getDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToFunc<apputils::BitDepthAndColorSpace> >::getDefault()
Unexecuted instantiation: apputils::program_options::Option<int>::getDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToFunc<vvencPresetMode> >::getDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToAbbr<int, int> >::getDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToQP>::getDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<bool> >::getDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<signed char> >::getDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencDecodingRefreshType> >::getDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToInt8>::getDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencProfile> >::getDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencLevel> >::getDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencTier> >::getDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencHDRMode> >::getDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToFunc<int> >::getDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<int> >::getDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencHashType> >::getDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencSegmentMode> >::getDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencChromaFormat> >::getDefault()
Unexecuted instantiation: apputils::program_options::Option<unsigned int>::getDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToRefVec<double> >::getDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToArr<double> >::getDefault()
Unexecuted instantiation: apputils::program_options::Option<double>::getDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToArr<int> >::getDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencCostMode> >::getDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToFixedPointU8>::getDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToArr<unsigned int> >::getDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToArr<char> >::getDefault()
Unexecuted instantiation: apputils::program_options::Option<vvencGOPEntry>::getDefault()
190
191
/* A value must be the whole argument: "1,CuTreePicStrength=2" is not the value 1. Trailing whitespace is allowed.
192
 * (std::ws on a stream already at its end would set failbit, hence the eof checks.) */
193
inline void failOnTrailingChars( std::istringstream& arg_ss )
194
0
{
195
0
  if( !arg_ss.eof() && !( arg_ss >> std::ws ).eof() )
196
0
  {
197
0
    arg_ss.setstate( std::ios::failbit ); // throws, failbit exceptions are on
198
0
  }
199
0
}
200
201
/* Generic parsing */
202
template<typename T>
203
inline void
204
Option<T>::parse(const std::string& arg, ErrorReporter&)
205
0
{
206
0
  std::string param = arg;
207
0
  if( is_bool_switch )
208
0
  {
209
0
    if( arg.empty() ) { param = "1"; }
210
0
  }
211
212
0
  if( arg == "" )
213
0
  {
214
0
    param = "''";
215
0
  }
216
217
0
  std::istringstream arg_ss (param,std::istringstream::in);
218
0
  arg_ss.exceptions(std::ios::failbit);
219
0
  try
220
0
  {
221
0
    arg_ss >> opt_storage;
222
0
    failOnTrailingChars( arg_ss );
223
0
  }
224
0
  catch (...)
225
0
  {
226
0
    throw ParseFailure(opt_string, param);
227
0
  }
228
0
}
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencMsgLevel> >::parse(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::program_options::ErrorReporter&)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToRefVec<int> >::parse(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::program_options::ErrorReporter&)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToFunc<apputils::BitDepthAndColorSpace> >::parse(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::program_options::ErrorReporter&)
Unexecuted instantiation: apputils::program_options::Option<int>::parse(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::program_options::ErrorReporter&)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToFunc<vvencPresetMode> >::parse(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::program_options::ErrorReporter&)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToAbbr<int, int> >::parse(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::program_options::ErrorReporter&)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToQP>::parse(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::program_options::ErrorReporter&)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<bool> >::parse(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::program_options::ErrorReporter&)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<signed char> >::parse(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::program_options::ErrorReporter&)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencDecodingRefreshType> >::parse(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::program_options::ErrorReporter&)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToInt8>::parse(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::program_options::ErrorReporter&)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencProfile> >::parse(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::program_options::ErrorReporter&)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencLevel> >::parse(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::program_options::ErrorReporter&)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencTier> >::parse(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::program_options::ErrorReporter&)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencHDRMode> >::parse(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::program_options::ErrorReporter&)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToFunc<int> >::parse(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::program_options::ErrorReporter&)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<int> >::parse(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::program_options::ErrorReporter&)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencHashType> >::parse(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::program_options::ErrorReporter&)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencSegmentMode> >::parse(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::program_options::ErrorReporter&)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencChromaFormat> >::parse(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::program_options::ErrorReporter&)
Unexecuted instantiation: apputils::program_options::Option<unsigned int>::parse(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::program_options::ErrorReporter&)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToRefVec<double> >::parse(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::program_options::ErrorReporter&)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToArr<double> >::parse(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::program_options::ErrorReporter&)
Unexecuted instantiation: apputils::program_options::Option<double>::parse(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::program_options::ErrorReporter&)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToArr<int> >::parse(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::program_options::ErrorReporter&)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToEnum<vvencCostMode> >::parse(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::program_options::ErrorReporter&)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToFixedPointU8>::parse(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::program_options::ErrorReporter&)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToArr<unsigned int> >::parse(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::program_options::ErrorReporter&)
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToArr<char> >::parse(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::program_options::ErrorReporter&)
Unexecuted instantiation: apputils::program_options::Option<vvencGOPEntry>::parse(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::program_options::ErrorReporter&)
229
230
/* string parsing is specialized -- copy the whole string, not just the
231
  * first word */
232
template<>
233
inline void
234
Option<std::string>::parse(const std::string& arg, ErrorReporter&)
235
0
{
236
0
  opt_storage = arg;
237
0
}
238
239
template<>
240
inline void
241
Option<bool>::parse(const std::string& arg, ErrorReporter&)
242
0
{
243
0
  if( arg.empty() )
244
0
  {
245
0
    opt_storage = true;
246
0
  }
247
0
  else
248
0
  {
249
0
    std::istringstream arg_ss (arg,std::istringstream::in);
250
0
    arg_ss.exceptions(std::ios::failbit);
251
0
    try
252
0
    {
253
0
      arg_ss >> opt_storage;
254
0
      failOnTrailingChars( arg_ss );
255
0
    }
256
0
    catch (...)
257
0
    {
258
0
      throw ParseFailure(opt_string, arg);
259
0
    }
260
0
  }
261
0
}
262
263
264
class OptionSpecific;
265
struct Options;
266
267
/** Option class for argument handling using a user provided function */
268
struct OptionFunc : public OptionBase
269
{
270
  typedef void (Func)(Options&, const std::string&, ErrorReporter&);
271
272
  OptionFunc(const std::string& name, Options& parent_, Func *func_, const std::string& desc)
273
0
  : OptionBase(name, desc, false), parent(parent_), func(func_)
274
0
  {}
275
276
  void parse(const std::string& arg, ErrorReporter& error_reporter)
277
0
  {
278
0
    func(parent, arg, error_reporter);
279
0
  }
280
281
  void setDefault()
282
0
  {
283
0
    return;
284
0
  }
285
286
private:
287
  Options& parent;
288
  Func* func;
289
};
290
291
292
struct Options
293
{
294
  ~Options()
295
0
  {
296
0
    for(Options::NamesPtrList::iterator it = opt_list.begin(); it != opt_list.end(); it++)
297
0
    {
298
0
      delete *it;
299
0
    }
300
0
  }
301
302
  inline OptionSpecific addOptions();
303
304
  struct Names
305
  {
306
0
    Names() : opt(0) {};
307
    ~Names()
308
0
    {
309
0
      if (opt)
310
0
      {
311
0
        delete opt;
312
0
      }
313
0
    }
314
    std::list<std::string> opt_long;
315
    std::list<std::string> opt_short;
316
    OptionBase* opt;
317
  };
318
319
  void addOption(OptionBase *opt)
320
0
  {
321
0
    Names* names = new Names();
322
0
    names->opt = opt;
323
0
    std::string& opt_string = opt->opt_string;
324
325
0
    if( useLowerNamesOnly )
326
0
    {
327
0
      std::transform( opt_string.begin(), opt_string.end(), opt_string.begin(), ::tolower );
328
0
    }
329
330
0
    size_t opt_start = 0;
331
0
    for (size_t opt_end = 0; opt_end != std::string::npos;)
332
0
    {
333
0
      opt_end = opt_string.find_first_of(',', opt_start);
334
0
      bool force_short = 0;
335
0
      if (opt_string[opt_start] == '-')
336
0
      {
337
0
        opt_start++;
338
0
        force_short = 1;
339
0
      }
340
0
      std::string opt_name = opt_string.substr(opt_start, opt_end - opt_start);
341
0
      if (force_short || opt_name.size() == 1)
342
0
      {
343
0
        names->opt_short.push_back(opt_name);
344
0
        opt_short_map[opt_name].push_back(names);
345
0
      }
346
0
      else
347
0
      {
348
0
        names->opt_long.push_back(opt_name);
349
350
0
        std::string optLongLower = opt_name;
351
0
        std::transform( optLongLower.begin(), optLongLower.end(), optLongLower.begin(), ::tolower );
352
0
        opt_long_map[optLongLower].push_back(names);
353
0
      }
354
0
      opt_start += opt_end + 1;
355
0
    }
356
357
0
    if( !subSections_list.empty() )
358
0
    {
359
0
      if( curSubSection.empty() ){ curSubSection = subSections_list.back(); }
360
0
      sub_section_namelist_map[curSubSection].push_back(opt_string);
361
0
    }
362
363
0
    opt_list.push_back(names);
364
0
  }
365
366
  typedef std::list<Names*> NamesPtrList;
367
  NamesPtrList opt_list;
368
369
  typedef std::map<std::string, NamesPtrList> NamesMap;
370
  NamesMap opt_long_map;
371
  NamesMap opt_short_map;
372
373
  int setSubSection(std::string subSection)
374
0
  {
375
0
    curSubSection = subSection;
376
0
    for( auto s : subSections_list )
377
0
    {
378
0
      if( s == subSection )
379
0
      {
380
0
        return -1;
381
0
      }
382
0
    }
383
0
    subSections_list.push_back( subSection );
384
0
    return 0;
385
0
  } 
386
387
0
  void setLowerCaseOnly() { useLowerNamesOnly = true; }
388
389
  typedef std::list<std::string> subSectionsPtrList;
390
  subSectionsPtrList subSections_list;
391
  std::string curSubSection;
392
  
393
  typedef std::map<std::string, std::list<std::string> > SubSectionNamesListMap;
394
  SubSectionNamesListMap sub_section_namelist_map;
395
396
  bool useLowerNamesOnly = false; // if true, option names are always set to lower case
397
};
398
399
/* Class with templated overloaded operator(), for use by Options::addOptions() */
400
class OptionSpecific
401
{
402
public:
403
0
  OptionSpecific(Options& parent_) : parent(parent_) {}
404
405
  /**
406
   * Add option described by name to the parent Options list,
407
   *   with storage for the option's value
408
   *   with default_val as the default value
409
   *   with desc as an optional help description
410
   */
411
  template<typename T>
412
  OptionSpecific&
413
  operator()(const std::string& name, T& storage, T default_val, const std::string& desc = "", bool bool_switch = false)
414
  {
415
    parent.addOption(new Option<T>(name, storage, default_val, desc, bool_switch));
416
    return *this;
417
  }
418
419
  /**
420
   * Add option described by name to the parent Options list,
421
   *   without separate default value
422
   */
423
  template<typename T>
424
  OptionSpecific&
425
  operator()(const std::string& name, T& storage, const std::string& desc = "", bool bool_switch = false )
426
0
  {
427
0
    parent.addOption(new Option<T>(name, storage, storage, desc, bool_switch));
428
0
    return *this;
429
0
  }
Unexecuted instantiation: apputils::program_options::OptionSpecific& apputils::program_options::OptionSpecific::operator()<bool>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::OptionSpecific& apputils::program_options::OptionSpecific::operator()<apputils::IStreamToEnum<vvencMsgLevel> >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToEnum<vvencMsgLevel>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::OptionSpecific& apputils::program_options::OptionSpecific::operator()<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::OptionSpecific& apputils::program_options::OptionSpecific::operator()<apputils::IStreamToRefVec<int> >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToRefVec<int>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::OptionSpecific& apputils::program_options::OptionSpecific::operator()<apputils::IStreamToFunc<apputils::BitDepthAndColorSpace> >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToFunc<apputils::BitDepthAndColorSpace>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::OptionSpecific& apputils::program_options::OptionSpecific::operator()<int>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::OptionSpecific& apputils::program_options::OptionSpecific::operator()<apputils::IStreamToFunc<vvencPresetMode> >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToFunc<vvencPresetMode>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::OptionSpecific& apputils::program_options::OptionSpecific::operator()<apputils::IStreamToAbbr<int, int> >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToAbbr<int, int>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::OptionSpecific& apputils::program_options::OptionSpecific::operator()<apputils::IStreamToQP>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToQP&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::OptionSpecific& apputils::program_options::OptionSpecific::operator()<apputils::IStreamToEnum<bool> >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToEnum<bool>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::OptionSpecific& apputils::program_options::OptionSpecific::operator()<apputils::IStreamToEnum<signed char> >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToEnum<signed char>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::OptionSpecific& apputils::program_options::OptionSpecific::operator()<apputils::IStreamToEnum<vvencDecodingRefreshType> >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToEnum<vvencDecodingRefreshType>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::OptionSpecific& apputils::program_options::OptionSpecific::operator()<apputils::IStreamToInt8>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToInt8&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::OptionSpecific& apputils::program_options::OptionSpecific::operator()<apputils::IStreamToEnum<vvencProfile> >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToEnum<vvencProfile>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::OptionSpecific& apputils::program_options::OptionSpecific::operator()<apputils::IStreamToEnum<vvencLevel> >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToEnum<vvencLevel>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::OptionSpecific& apputils::program_options::OptionSpecific::operator()<apputils::IStreamToEnum<vvencTier> >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToEnum<vvencTier>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::OptionSpecific& apputils::program_options::OptionSpecific::operator()<apputils::IStreamToEnum<vvencHDRMode> >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToEnum<vvencHDRMode>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::OptionSpecific& apputils::program_options::OptionSpecific::operator()<apputils::IStreamToFunc<int> >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToFunc<int>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::OptionSpecific& apputils::program_options::OptionSpecific::operator()<apputils::IStreamToEnum<int> >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToEnum<int>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::OptionSpecific& apputils::program_options::OptionSpecific::operator()<apputils::IStreamToEnum<vvencHashType> >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToEnum<vvencHashType>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::OptionSpecific& apputils::program_options::OptionSpecific::operator()<apputils::IStreamToEnum<vvencSegmentMode> >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToEnum<vvencSegmentMode>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::OptionSpecific& apputils::program_options::OptionSpecific::operator()<apputils::IStreamToEnum<vvencChromaFormat> >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToEnum<vvencChromaFormat>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::OptionSpecific& apputils::program_options::OptionSpecific::operator()<unsigned int>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned int&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::OptionSpecific& apputils::program_options::OptionSpecific::operator()<apputils::IStreamToRefVec<double> >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToRefVec<double>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::OptionSpecific& apputils::program_options::OptionSpecific::operator()<apputils::IStreamToArr<double> >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToArr<double>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::OptionSpecific& apputils::program_options::OptionSpecific::operator()<double>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, double&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::OptionSpecific& apputils::program_options::OptionSpecific::operator()<apputils::IStreamToArr<int> >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToArr<int>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::OptionSpecific& apputils::program_options::OptionSpecific::operator()<apputils::IStreamToEnum<vvencCostMode> >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToEnum<vvencCostMode>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::OptionSpecific& apputils::program_options::OptionSpecific::operator()<apputils::IStreamToFixedPointU8>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToFixedPointU8&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::OptionSpecific& apputils::program_options::OptionSpecific::operator()<apputils::IStreamToArr<unsigned int> >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToArr<unsigned int>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::OptionSpecific& apputils::program_options::OptionSpecific::operator()<apputils::IStreamToArr<char> >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, apputils::IStreamToArr<char>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
Unexecuted instantiation: apputils::program_options::OptionSpecific& apputils::program_options::OptionSpecific::operator()<vvencGOPEntry>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, vvencGOPEntry&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)
430
431
  /**
432
   * Add option described by name to the parent Options list,
433
   *   with desc as an optional help description
434
   * instead of storing the value somewhere, a function of type
435
   * OptionFunc::Func is called.  It is upto this function to correctly
436
   * handle evaluating the option's value.
437
   */
438
  OptionSpecific&
439
  operator()(const std::string& name, OptionFunc::Func *func, const std::string& desc = "")
440
0
  {
441
0
    parent.addOption(new OptionFunc(name, parent, func, desc));
442
0
    return *this;
443
0
  }
444
private:
445
  Options& parent;
446
};
447
448
static void setOptions(Options::NamesPtrList& opt_list, const std::string& value, ErrorReporter& error_reporter)
449
0
{
450
  /* multiple options may be registered for the same name:
451
    *   allow each to parse value */
452
0
  for (Options::NamesPtrList::iterator it = opt_list.begin(); it != opt_list.end(); ++it)
453
0
  {
454
0
    (*it)->opt->parse(value, error_reporter);
455
0
  }
456
0
}
457
458
459
static const char spaces[41] = "                                        ";
460
461
462
/* format help text for a single option:
463
  * using the formatting: "-x, --long",
464
  * if a short/long option isn't specified, it is not printed
465
  */
466
static void doHelpOpt(std::ostream& out, const Options::Names& entry, unsigned pad_short = 0)
467
0
{
468
0
  pad_short = std::min(pad_short, 8u);
469
470
0
  if (!entry.opt_short.empty())
471
0
  {
472
0
    unsigned pad = std::max((int)pad_short - (int)entry.opt_short.front().size(), 0);
473
0
    out << "-" << entry.opt_short.front();
474
0
    if (!entry.opt_long.empty())
475
0
    {
476
0
      out << ", ";
477
0
    }
478
0
    out << &(spaces[40 - pad]);
479
0
  }
480
0
  else
481
0
  {
482
0
    out << "   ";
483
0
    out << &(spaces[40 - pad_short]);
484
0
  }
485
486
0
  if (!entry.opt_long.empty())
487
0
  {
488
0
    out << "--" << entry.opt_long.front();
489
0
  }
490
0
  out << " [" << entry.opt->getDefault() << "] ";
491
0
}
492
493
/* format text for 'additional' string options for a single option:
494
  * using the formatting: "option",
495
  */
496
 static void doAdditionalOpt(std::ostream& out, const Options::Names& entry, unsigned pad_short = 0)
497
0
 {
498
0
   pad_short = std::min(pad_short, 8u);
499
500
0
   out << "   ";
501
0
   out << &(spaces[40 - pad_short]);
502
503
0
   if (!entry.opt_long.empty())
504
0
   {
505
0
     out << entry.opt_long.front();
506
0
   }
507
0
   out << " [" << entry.opt->getDefault() << "] ";
508
0
 }
509
510
static void doPrintHelpEntry( std::ostream& out, const Options::Names& entry, unsigned desc_width, unsigned opt_width, unsigned pad_short = 0, bool isAdditionalOpt = false )
511
0
{
512
0
  std::ostringstream line(std::ios_base::out);
513
0
  line << "  ";
514
515
0
  if ( isAdditionalOpt )
516
0
    doAdditionalOpt(line, entry, pad_short);
517
0
  else
518
0
    doHelpOpt(line, entry, pad_short);
519
520
0
  const std::string& opt_desc = entry.opt->opt_desc;
521
0
  if (opt_desc.empty())
522
0
  {
523
    /* no help text: output option, skip further processing */
524
0
    out << line.str() << std::endl;
525
0
    return;
526
0
  }
527
0
  size_t currlength = size_t(line.tellp());
528
0
  if (currlength > opt_width)
529
0
  {
530
    /* if option text is too long (and would collide with the
531
      * help text, split onto next line */
532
0
    line << std::endl;
533
0
    currlength = 0;
534
0
  }
535
  /* split up the help text, taking into account new lines,
536
    *   (add opt_width of padding to each new line) */
537
0
  for (size_t newline_pos = 0, cur_pos = 0; cur_pos != std::string::npos; currlength = 0)
538
0
  {
539
    /* print any required padding space for vertical alignment */
540
0
    line << &(spaces[40 - opt_width + currlength]);
541
0
    newline_pos = opt_desc.find_first_of('\n', newline_pos);
542
0
    if (newline_pos != std::string::npos)
543
0
    {
544
      /* newline found, print substring (newline needn't be stripped) */
545
0
      newline_pos++;
546
0
      line << opt_desc.substr(cur_pos, newline_pos - cur_pos);
547
0
      cur_pos = newline_pos;
548
0
      continue;
549
0
    }
550
0
    if (cur_pos + desc_width > opt_desc.size())
551
0
    {
552
      /* no need to wrap text, remainder is less than avaliable width */
553
0
      line << opt_desc.substr(cur_pos);
554
0
      break;
555
0
    }
556
    /* find a suitable point to split text (avoid spliting in middle of word) */
557
0
    size_t split_pos = opt_desc.find_last_of(' ', cur_pos + desc_width);
558
0
    if (split_pos != std::string::npos)
559
0
    {
560
      /* eat up multiple space characters */
561
0
      split_pos = opt_desc.find_last_not_of(' ', split_pos) + 1;
562
0
    }
563
564
    /* bad split if no suitable space to split at.  fall back to width */
565
0
    bool bad_split = split_pos == std::string::npos || split_pos <= cur_pos;
566
0
    if (bad_split)
567
0
    {
568
0
      split_pos = cur_pos + desc_width;
569
0
    }
570
0
    line << opt_desc.substr(cur_pos, split_pos - cur_pos);
571
572
    /* eat up any space for the start of the next line */
573
0
    if (!bad_split)
574
0
    {
575
0
      split_pos = opt_desc.find_first_not_of(' ', split_pos);
576
0
    }
577
0
    cur_pos = newline_pos = split_pos;
578
579
0
    if (cur_pos >= opt_desc.size())
580
0
    {
581
0
      break;
582
0
    }
583
0
    line << std::endl;
584
0
  }
585
586
0
  out << line.str() << std::endl;
587
0
}
588
589
/* prints a formated config entry */
590
static void printFormattedConfigEntry( std::ostream& out, const Options::Names& entry, unsigned desc_width, unsigned opt_width, unsigned opt_value_width )
591
0
{
592
  // prints a config entry. format:
593
  // option       : vaue        # help  [default]
594
595
0
  std::ostringstream line(std::ios_base::out);
596
597
0
  if (!entry.opt_long.empty())
598
0
  {
599
0
    line << entry.opt_long.front();
600
601
0
    for( size_t s = 0 ; s < (opt_width - entry.opt_long.front().length()) ; ++s )
602
0
    {
603
0
      line << ' ' ;
604
0
    }
605
606
0
    line << ": " << entry.opt->getValue();
607
0
  }
608
0
  else
609
0
  {
610
0
    return;
611
0
  }
612
613
0
  const std::string& opt_desc = entry.opt->opt_desc;
614
0
  if (opt_desc.empty())
615
0
  {
616
    /* no help text: output option, skip further processing */
617
0
    out << line.str() << std::endl;
618
0
    return;
619
0
  }
620
621
0
  size_t currlength = size_t(line.tellp());
622
0
  if (currlength > opt_value_width)
623
0
  {
624
    /* if option text is too long (and would collide with the
625
      * help text, split onto next line */
626
0
    line << std::endl;
627
0
    currlength = 0;
628
0
  }
629
  /* split up the help text, taking into account new lines,
630
    *   (add opt_value_width of padding to each new line) */
631
0
  for (size_t newline_pos = 0, cur_pos = 0; cur_pos != std::string::npos; currlength = 0)
632
0
  {
633
    /* print any required padding space for vertical alignment */
634
635
0
    for( size_t num_sp = 0 ; num_sp < opt_value_width - currlength ; ++num_sp )
636
0
    {
637
0
      line << ' ' ;
638
0
    }
639
0
    newline_pos = opt_desc.find_first_of('\n', newline_pos);
640
0
    if (newline_pos != std::string::npos)
641
0
    {
642
      /* newline found, print substring (newline needn't be stripped) */
643
0
      newline_pos++;
644
0
      line << " # ";
645
0
      line << opt_desc.substr(cur_pos, newline_pos - cur_pos);
646
0
      cur_pos = newline_pos;
647
0
      continue;
648
0
    }
649
0
    if (cur_pos + desc_width > opt_desc.size())
650
0
    {
651
      /* no need to wrap text, remainder is less than avaliable width */
652
0
      line << " # ";
653
0
      line << opt_desc.substr(cur_pos);
654
0
      line << " [" << entry.opt->getDefault( ) << "] ";
655
0
      break;
656
0
    }
657
    /* find a suitable point to split text (avoid spliting in middle of word) */
658
0
    size_t split_pos = opt_desc.find_last_of(' ', cur_pos + desc_width);
659
0
    if (split_pos != std::string::npos)
660
0
    {
661
      /* eat up multiple space characters */
662
0
      split_pos = opt_desc.find_last_not_of(' ', split_pos) + 1;
663
0
    }
664
665
    /* bad split if no suitable space to split at.  fall back to width */
666
0
    bool bad_split = split_pos == std::string::npos || split_pos <= cur_pos;
667
0
    if (bad_split)
668
0
    {
669
0
      split_pos = cur_pos + desc_width;
670
0
    }
671
0
    line << " # ";
672
0
    line << opt_desc.substr(cur_pos, split_pos - cur_pos);
673
674
    /* eat up any space for the start of the next line */
675
0
    if (!bad_split)
676
0
    {
677
0
      split_pos = opt_desc.find_first_not_of(' ', split_pos);
678
0
    }
679
0
    cur_pos = newline_pos = split_pos;
680
681
0
    if (cur_pos >= opt_desc.size())
682
0
    {
683
0
      break;
684
0
    }
685
0
    line << std::endl;
686
0
  }
687
688
0
  out << line.str() << std::endl;
689
0
}
690
691
/* format the help text */
692
inline void doHelp(std::ostream& out, Options& opts, unsigned columns  = 120)
693
0
{
694
0
  const unsigned pad_short = 3;
695
  /* first pass: work out the longest option name */
696
0
  unsigned max_width = 0;
697
0
  for(Options::NamesPtrList::iterator it = opts.opt_list.begin(); it != opts.opt_list.end(); it++)
698
0
  {
699
0
    std::ostringstream line(std::ios_base::out);
700
0
    doHelpOpt(line, **it, pad_short);
701
0
    max_width = std::max(max_width, (unsigned) line.tellp());
702
0
  }
703
704
0
  unsigned opt_width = std::min(max_width+2, 32u + pad_short) + 2;
705
0
  unsigned desc_width = columns - opt_width;
706
707
  /* second pass: write out formatted option and help text.
708
    *  - align start of help text to start at opt_width
709
    *  - if the option text is longer than opt_width, place the help
710
    *    text at opt_width on the next line.
711
    */
712
0
  if( opts.subSections_list.empty())
713
0
  {
714
0
    for (const auto& opt: opts.opt_list)
715
0
    {
716
0
      doPrintHelpEntry( out, *opt, desc_width, opt_width, pad_short );
717
0
    }
718
0
    return;
719
0
  }
720
721
0
  for (const auto& section: opts.subSections_list)
722
0
  {
723
0
    if( section != "__$PLACEHOLDER$__")  // print sub section name (if not dummy section)
724
0
    {
725
0
      out << std::endl << "#======== " << section << " ================" << std::endl;
726
0
    }
727
728
0
    Options::SubSectionNamesListMap::const_iterator itSectionMap = opts.sub_section_namelist_map.find(section);  // get list of options in subsection
729
0
    if (itSectionMap != opts.sub_section_namelist_map.end())
730
0
    {
731
0
      for( auto & s : itSectionMap->second ) // iterate over options in subsections and find/print entry in opts list
732
0
      {
733
0
        for(Options::NamesPtrList::const_iterator itopt = opts.opt_list.begin(); itopt != opts.opt_list.end(); itopt++)
734
0
        {
735
0
          if( (*itopt)->opt->opt_string == s )  // names are equal
736
0
          {
737
0
            doPrintHelpEntry( out, **itopt, desc_width, opt_width, pad_short );
738
0
            break;
739
0
            }
740
0
        }
741
0
      }
742
0
    }
743
0
  }
744
0
}
745
746
/* format the help text */
747
inline void doAdditionalOptList(std::ostream& out, Options& opts, unsigned columns  = 80)
748
0
{
749
0
  const unsigned pad_short = 3;
750
  /* first pass: work out the longest option name */
751
0
  unsigned max_width = 0;
752
0
  for(Options::NamesPtrList::iterator it = opts.opt_list.begin(); it != opts.opt_list.end(); it++)
753
0
  {
754
0
    std::ostringstream line(std::ios_base::out);
755
0
    doAdditionalOpt(line, **it, pad_short);
756
0
    max_width = std::max(max_width, (unsigned) line.tellp());
757
0
  }
758
759
0
  unsigned opt_width = std::min(max_width+2, 32u + pad_short) + 2;
760
0
  unsigned desc_width = columns - opt_width;
761
762
  /* second pass: write out formatted option and help text.
763
    *  - align start of help text to start at opt_width
764
    *  - if the option text is longer than opt_width, place the help
765
    *    text at opt_width on the next line.
766
    */
767
0
  if( opts.subSections_list.empty())
768
0
  {
769
0
    for (const auto& opt: opts.opt_list)
770
0
    {
771
0
      doPrintHelpEntry( out, *opt, desc_width, opt_width, pad_short, true );
772
0
    }
773
0
    return;
774
0
  }
775
776
0
  for (const auto& section: opts.subSections_list)
777
0
  {
778
0
    if( section != "__$PLACEHOLDER$__")  // print sub section name (if not dummy section)
779
0
    {
780
0
      out << std::endl << "#======== " << section << " ================" << std::endl;
781
0
    }
782
783
0
    Options::SubSectionNamesListMap::const_iterator itSectionMap = opts.sub_section_namelist_map.find(section);  // get list of options in subsection
784
0
    if (itSectionMap != opts.sub_section_namelist_map.end())
785
0
    {
786
0
      for( auto & s : itSectionMap->second ) // iterate over options in subsections and find/print entry in opts list
787
0
      {
788
0
        for(Options::NamesPtrList::const_iterator itopt = opts.opt_list.begin(); itopt != opts.opt_list.end(); itopt++)
789
0
        {
790
0
          if( (*itopt)->opt->opt_string == s )  // names are equal
791
0
          {
792
0
            doPrintHelpEntry( out, **itopt, desc_width, opt_width, pad_short, true );
793
0
            break;
794
0
            }
795
0
        }
796
0
      }
797
0
    }
798
0
  }
799
0
}
800
801
/* prints a formated configuration of Options into a ostream */
802
inline void saveConfig(std::ostream& out, Options& opts, std::list<std::string> ignoreParamLst, unsigned columns = 240 )
803
0
{
804
  /* first pass: work out the longest option name */
805
0
  unsigned max_width_optname = 0;
806
0
  for(Options::NamesPtrList::iterator it = opts.opt_list.begin(); it != opts.opt_list.end(); it++)
807
0
  {
808
0
    if (!(**it).opt_long.empty())
809
0
    {
810
0
      unsigned w = (unsigned)(**it).opt_long.front().size();
811
0
      max_width_optname = std::max(max_width_optname, w);
812
0
    }
813
0
  }
814
815
  /* second pass: work out the longest value*/
816
0
  unsigned max_width_value = 0;
817
0
  for(Options::NamesPtrList::iterator it = opts.opt_list.begin(); it != opts.opt_list.end(); it++)
818
0
  {
819
0
    std::string value = (**it).opt->getValue();
820
0
    max_width_value = std::max(max_width_value, (unsigned) value.length() );
821
0
  }
822
823
0
  unsigned max_width_opt_value = max_width_optname + max_width_value +3; // max size of option + " : " + value
824
0
  unsigned desc_width = (columns > max_width_opt_value) ? (columns - max_width_opt_value) : 1;  // nj-fix: guard unsigned underflow
825
826
  /* 3rd pass: write out formatted option + current value +  help text + default value.
827
    * format is:
828
    * option       : vaue        # help  [default]
829
    *  - if the option text is longer than opt_width, place the help
830
    *    text at opt_width on the next line.
831
    */
832
0
  if( opts.subSections_list.empty())
833
0
  {
834
0
    for (const auto& opt: opts.opt_list)
835
0
    {
836
0
      bool ignore = ignoreParamLst.end() != std::find(ignoreParamLst.begin(), ignoreParamLst.end(), opt->opt->opt_string);
837
0
      if( !ignore)
838
0
      {
839
0
        printFormattedConfigEntry( out, *opt, desc_width, max_width_optname, max_width_opt_value );
840
0
      }
841
0
    }
842
0
    return;
843
0
  }
844
845
  // iterate over all subsections and print all entries for each subsection
846
0
  for (const auto& section: opts.subSections_list)
847
0
  {
848
0
    if( section != "__$PLACEHOLDER$__")  // print sub section name (if not dummy section)
849
0
    {
850
0
      out << std::endl << "#======== " << section << " ================" << std::endl;
851
0
    }
852
853
0
    Options::SubSectionNamesListMap::const_iterator itSectionMap = opts.sub_section_namelist_map.find(section);  // get list of options in subsection
854
0
    if (itSectionMap != opts.sub_section_namelist_map.end())
855
0
    {
856
0
      for( auto & s : itSectionMap->second ) // iterate over options in subsections and find/print entry in opts list
857
0
      {
858
0
        for(Options::NamesPtrList::const_iterator itopt = opts.opt_list.begin(); itopt != opts.opt_list.end(); itopt++)
859
0
        {
860
0
          if( (*itopt)->opt->opt_string == s )  // names are equal
861
0
          {
862
0
            bool ignore = ignoreParamLst.end() != std::find(ignoreParamLst.begin(), ignoreParamLst.end(), (*itopt)->opt->opt_string);
863
0
            if( !ignore)
864
0
            {
865
0
              printFormattedConfigEntry( out, **itopt, desc_width, max_width_optname, max_width_opt_value );
866
0
            }
867
868
0
            break;
869
0
          }
870
0
        }
871
0
      }
872
0
    }
873
0
  }
874
0
}
875
876
877
// OptionWriter
878
struct OptionWriter
879
{
880
  OptionWriter(Options& rOpts, ErrorReporter& err)
881
0
  : opts(rOpts), error_reporter(err)
882
0
  {}
883
0
  virtual ~OptionWriter() {}
884
885
  virtual const std::string where() = 0;
886
887
  bool storePair(bool allow_long, bool allow_short, const std::string& name, const std::string& value)
888
0
  {
889
0
    bool found = false;
890
0
    Options::NamesMap::iterator opt_it;
891
0
    if (allow_long)
892
0
    {
893
0
      std::string optLongLower = name;
894
0
      std::transform( optLongLower.begin(), optLongLower.end(), optLongLower.begin(), ::tolower );
895
896
0
      opt_it = opts.opt_long_map.find(optLongLower);
897
0
      if (opt_it != opts.opt_long_map.end())
898
0
      {
899
0
        found = true;
900
0
      }
901
0
    }
902
903
    /* check for the short list */
904
0
    if (allow_short && !(found && allow_long))
905
0
    {
906
0
      opt_it = opts.opt_short_map.find(name);
907
0
      if (opt_it != opts.opt_short_map.end())
908
0
      {
909
0
        found = true;
910
0
      }
911
0
    }
912
913
0
    if (!found)
914
0
    {
915
0
      error_reporter.error(where())
916
0
        << "Unknown option `" << name << "' (value:`" << value << "')\n";
917
0
      return false;
918
0
    }
919
920
0
    setOptions((*opt_it).second, value, error_reporter);
921
0
    return true;
922
0
  }
923
924
  bool storePair(const std::string& name, const std::string& value)
925
0
  {
926
0
    return storePair(true, true, name, value);
927
0
  }
928
929
  Options& opts;
930
  ErrorReporter& error_reporter;
931
};
932
933
934
struct ArgvParser : public OptionWriter
935
{
936
  ArgvParser(Options& rOpts, ErrorReporter& rError_reporter)
937
0
  : OptionWriter(rOpts, rError_reporter)
938
0
  {}
939
940
0
  const std::string where() { return "command line"; }
941
942
  /**
943
   * returns number of extra arguments consumed
944
   */
945
  unsigned parseGNU(unsigned argc, const char* argv[])
946
0
  {
947
    /* gnu style long options can take the forms:
948
    *  --option=arg
949
    *  --option arg
950
    */
951
0
    std::string arg(argv[0]);
952
0
    size_t arg_opt_start = arg.find_first_not_of('-');
953
0
    size_t arg_opt_sep = arg.find_first_of('=');
954
0
    if (arg_opt_start == std::string::npos) arg_opt_start = arg.size();  // nj-fix: all-dash token, avoid substr(npos) throw
955
0
    std::string option = arg.substr(arg_opt_start, arg_opt_sep - arg_opt_start);
956
957
0
    std::transform( option.begin(), option.end(), option.begin(), ::tolower ); // compare option always in lower case
958
959
0
    unsigned extra_argc_consumed = 0;
960
0
    if (arg_opt_sep == std::string::npos)
961
0
    {
962
      // check if we have an argument 
963
0
      if( argc > 1)
964
0
      {
965
0
        std::string val(argv[1]);
966
0
        size_t val_sep = val.find_first_of('-');
967
        //check if either have no - or the parameter is a number 
968
0
        if( 0 != val_sep || std::regex_match( val, std::regex( ( "((\\+|-)?[[:digit:]]+)(\\.(([[:digit:]]+)?))?" ) ) ) ) 
969
0
        {
970
0
          extra_argc_consumed++;
971
          /* argument occurs after option_sep */
972
0
          storePair(true, false, option, val);
973
0
          return extra_argc_consumed;
974
0
        }
975
0
        else if( val_sep == 0 && val.size() == 1 )
976
0
        {
977
0
          extra_argc_consumed++;
978
          /* argument occurs after option_sep */
979
0
          storePair(true, false, option, val);
980
0
          return extra_argc_consumed;
981
0
        }
982
0
      }
983
984
      /* no argument found => argument in argv[1] (maybe) */
985
      /* xxx, need to handle case where option isn't required */
986
0
      if(!storePair(true, false, option, ""))
987
0
      {
988
0
        return 0;
989
0
      }
990
0
    }
991
0
    else
992
0
    {
993
      /* argument occurs after option_sep */
994
0
      std::string val = arg.substr(arg_opt_sep + 1);
995
0
      storePair(true, false, option, val);
996
0
    }
997
998
0
    return extra_argc_consumed;
999
0
  }
1000
1001
1002
  unsigned parseSHORT(unsigned argc, const char* argv[])
1003
0
  {
1004
    /* short options can take the forms:
1005
    *  --option arg
1006
    *  -option arg
1007
    */
1008
0
    std::string arg(argv[0]);
1009
0
    size_t arg_opt_start = arg.find_first_not_of('-');
1010
0
    std::string option = arg.substr(arg_opt_start);
1011
    /* lookup option */
1012
1013
    /* argument in argv[1] */
1014
    /* xxx, need to handle case where option isn't required */
1015
0
    if (argc == 1)
1016
0
    {
1017
0
      storePair(false, true, option, std::string(""));
1018
0
      return 1;
1019
0
    }
1020
1021
0
    std::string argNext = argv[1];
1022
0
    if( !argNext.empty() && argNext[0] == '-' )
1023
0
    {
1024
      // check if bool switch and check if next param is not an option
1025
0
      if( argNext.size() > 1 )
1026
0
      {
1027
0
        if( argNext[1] == '-' ) // is long option --
1028
0
        {
1029
0
          storePair(false, true, option, std::string(""));
1030
0
          return 0;
1031
0
        }
1032
1033
        // check if argv is an digit number
1034
0
        if( !std::isdigit(argNext[1]) )
1035
0
        {
1036
0
          storePair(false, true, option, std::string(""));
1037
0
          return 0;
1038
0
        }
1039
0
      }
1040
0
    }
1041
1042
0
    storePair(false, true, option, std::string(argv[1]));
1043
1044
0
    return 1;
1045
0
  }
1046
};
1047
1048
struct CfgStreamParser : public OptionWriter
1049
{
1050
  CfgStreamParser(const std::string& rName, Options& rOpts, ErrorReporter& rError_reporter)
1051
0
  : OptionWriter(rOpts, rError_reporter)
1052
0
  , name(rName)
1053
0
  , linenum(0)
1054
0
  {}
1055
1056
  const std::string name;
1057
  int linenum;
1058
  const std::string where()
1059
0
  {
1060
0
    std::ostringstream os;
1061
0
    os << name << ":" << linenum;
1062
0
    return os.str();
1063
0
  }
1064
1065
  void scanLine(std::string& line)
1066
0
  {
1067
    /* strip any leading whitespace */
1068
0
    size_t start = line.find_first_not_of(" \t\n\r");
1069
0
    if (start == std::string::npos)
1070
0
    {
1071
      /* blank line */
1072
0
      return;
1073
0
    }
1074
0
    if (line[start] == '#')
1075
0
    {
1076
      /* comment line */
1077
0
      return;
1078
0
    }
1079
    /* look for first whitespace or ':' after the option end */
1080
0
    size_t option_end = line.find_first_of(": \t\n\r",start);
1081
0
    std::string option = line.substr(start, option_end - start);
1082
1083
    /* look for ':', eat up any whitespace first */
1084
0
    start = line.find_first_not_of(" \t\n\r", option_end);
1085
0
    if (start == std::string::npos)
1086
0
    {
1087
      /* error: badly formatted line */
1088
0
      error_reporter.warn(where()) << "line formatting error\n";
1089
0
      return;
1090
0
    }
1091
0
    if (line[start] != ':')
1092
0
    {
1093
      /* error: badly formatted line */
1094
0
      error_reporter.warn(where()) << "line formatting error\n";
1095
0
      return;
1096
0
    }
1097
1098
    /* look for start of value std::string -- eat up any leading whitespace */
1099
0
    start = line.find_first_not_of(" \t\n\r", ++start);
1100
0
    if (start == std::string::npos)
1101
0
    {
1102
      /* error: badly formatted line */
1103
0
      error_reporter.warn(where()) << "line formatting error\n";
1104
0
      return;
1105
0
    }
1106
1107
    /* extract the value part, which may contain embedded spaces
1108
    * by searching for a word at a time, until we hit a comment or end of line */
1109
0
    size_t value_end = start;
1110
0
    do
1111
0
    {
1112
0
      if (line[value_end] == '#')
1113
0
      {
1114
        /* rest of line is a comment */
1115
0
        value_end--;
1116
0
        break;
1117
0
      }
1118
0
      value_end = line.find_first_of(" \t\n\r", value_end);
1119
      /* consume any white space, incase there is another word.
1120
      * any trailing whitespace will be removed shortly */
1121
0
      value_end = line.find_first_not_of(" \t\n\r", value_end);
1122
0
    } while (value_end != std::string::npos);
1123
    /* strip any trailing space from value*/
1124
0
    value_end = line.find_last_not_of(" \t\n\r", value_end);
1125
1126
0
    std::string value;
1127
0
    if (value_end >= start)
1128
0
    {
1129
0
      value = line.substr(start, value_end +1 - start);
1130
0
    }
1131
0
    else
1132
0
    {
1133
      /* error: no value */
1134
0
      error_reporter.warn(where()) << "no value found for option " << option << "\n";
1135
0
      return;
1136
0
    }
1137
1138
    // reset empty strings
1139
0
    if( value == "\"\"" || value == "''")
1140
0
    {
1141
0
      value.clear();
1142
0
    }
1143
1144
    /* store the value in option */
1145
0
    storePair(true, false, option, value);
1146
0
  }
1147
1148
  void scanStream(std::istream& in)
1149
0
  {
1150
0
    do
1151
0
    {
1152
0
      linenum++;
1153
0
      std::string line;
1154
0
      getline(in, line);
1155
0
      scanLine(line);
1156
0
    } while(!!in);
1157
0
  }
1158
1159
};  
1160
1161
1162
1163
inline std::list<const char*> scanArgv(Options& opts, unsigned argc, const char* argv[], ErrorReporter& error_reporter = default_error_reporter)
1164
0
{
1165
0
  ArgvParser avp(opts, error_reporter);
1166
1167
  /* a list for anything that didn't get handled as an option */
1168
0
  std::list<const char*> non_option_arguments;
1169
1170
0
  for(unsigned i = 0; i < argc; i++)
1171
0
  {
1172
0
    if (argv[i][0] != '-')
1173
0
    {
1174
0
      non_option_arguments.push_back(argv[i]);
1175
0
      continue;
1176
0
    }
1177
1178
0
    if (argv[i][1] == 0)
1179
0
    {
1180
      /* a lone single dash is an argument (usually signifying stdin) */
1181
0
      non_option_arguments.push_back(argv[i]);
1182
0
      continue;
1183
0
    }
1184
1185
0
    if (argv[i][1] != '-')
1186
0
    {
1187
      /* handle short (single dash) options */
1188
0
      i += avp.parseSHORT(argc - i, &argv[i]);
1189
0
      continue;
1190
0
    }
1191
1192
0
    if (argv[i][2] == 0)
1193
0
    {
1194
      /* a lone double dash ends option processing */
1195
0
      while (++i < argc)
1196
0
      {
1197
0
        non_option_arguments.push_back(argv[i]);
1198
0
      }
1199
0
      break;
1200
0
    }
1201
1202
    /* handle long (double dash) options */
1203
0
    i += avp.parseGNU(argc - i, &argv[i]);
1204
0
  }
1205
1206
0
  return non_option_arguments;
1207
0
}
1208
1209
1210
/* for all options in opts, set their storage to their specified
1211
  * default value */
1212
inline void setDefaults(Options& opts)
1213
0
{
1214
0
  for(Options::NamesPtrList::iterator it = opts.opt_list.begin(); it != opts.opt_list.end(); it++)
1215
0
  {
1216
0
    (*it)->opt->setDefault();
1217
0
  }
1218
0
}
1219
1220
inline void parseConfigFile(Options& opts, const std::string& filename, ErrorReporter& error_reporter = default_error_reporter)
1221
0
{
1222
0
  std::ifstream cfgstream(filename.c_str(), std::ifstream::in);
1223
0
  if (!cfgstream)
1224
0
  {
1225
0
    error_reporter.error(filename) << "Failed to open config file\n";
1226
0
    return;
1227
0
  }
1228
0
  CfgStreamParser csp(filename, opts, error_reporter);
1229
0
  csp.scanStream(cfgstream);
1230
0
}
1231
1232
OptionSpecific Options::addOptions()
1233
0
{
1234
0
  if( subSections_list.empty()){ subSections_list.push_back( "__$PLACEHOLDER$__" ); } // add dummy section if nothing is given
1235
0
  return OptionSpecific(*this);
1236
0
}
1237
1238
} /* namespace: df */
1239
1240
} // namespace
1241
1242
//! \}
1243