Coverage Report

Created: 2026-04-01 07:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/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
256
  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::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::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::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::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::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::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::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::IStreamToArr<unsigned int> >::getDefault()
Unexecuted instantiation: apputils::program_options::Option<apputils::IStreamToArr<char> >::getDefault()
Unexecuted instantiation: apputils::program_options::Option<vvencGOPEntry>::getDefault()
190
191
/* Generic parsing */
192
template<typename T>
193
inline void
194
Option<T>::parse(const std::string& arg, ErrorReporter&)
195
0
{
196
0
  std::string param = arg;
197
0
  if( is_bool_switch )
198
0
  {
199
0
    if( arg.empty() ) { param = "1"; }
200
0
  }
201
202
0
  if( arg == "" )
203
0
  {
204
0
    param = "''";
205
0
  }
206
207
0
  std::istringstream arg_ss (param,std::istringstream::in);
208
0
  arg_ss.exceptions(std::ios::failbit);
209
0
  try
210
0
  {
211
0
    arg_ss >> opt_storage;
212
0
  }
213
0
  catch (...)
214
0
  {
215
0
    throw ParseFailure(opt_string, param);
216
0
  }
217
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::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::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&)
218
219
/* string parsing is specialized -- copy the whole string, not just the
220
  * first word */
221
template<>
222
inline void
223
Option<std::string>::parse(const std::string& arg, ErrorReporter&)
224
0
{
225
0
  opt_storage = arg;
226
0
}
227
228
template<>
229
inline void
230
Option<bool>::parse(const std::string& arg, ErrorReporter&)
231
0
{
232
0
  if( arg.empty() )
233
0
  {
234
0
    opt_storage = true;
235
0
  }
236
0
  else
237
0
  {
238
0
    std::istringstream arg_ss (arg,std::istringstream::in);
239
0
    arg_ss.exceptions(std::ios::failbit);
240
0
    try
241
0
    {
242
0
      arg_ss >> opt_storage;
243
0
    }
244
0
    catch (...)
245
0
    {
246
0
      throw ParseFailure(opt_string, arg);
247
0
    }
248
0
  }
249
0
}
250
251
252
class OptionSpecific;
253
struct Options;
254
255
/** Option class for argument handling using a user provided function */
256
struct OptionFunc : public OptionBase
257
{
258
  typedef void (Func)(Options&, const std::string&, ErrorReporter&);
259
260
  OptionFunc(const std::string& name, Options& parent_, Func *func_, const std::string& desc)
261
0
  : OptionBase(name, desc, false), parent(parent_), func(func_)
262
0
  {}
263
264
  void parse(const std::string& arg, ErrorReporter& error_reporter)
265
0
  {
266
0
    func(parent, arg, error_reporter);
267
0
  }
268
269
  void setDefault()
270
0
  {
271
0
    return;
272
0
  }
273
274
private:
275
  Options& parent;
276
  Func* func;
277
};
278
279
280
struct Options
281
{
282
  ~Options()
283
0
  {
284
0
    for(Options::NamesPtrList::iterator it = opt_list.begin(); it != opt_list.end(); it++)
285
0
    {
286
0
      delete *it;
287
0
    }
288
0
  }
289
290
  inline OptionSpecific addOptions();
291
292
  struct Names
293
  {
294
0
    Names() : opt(0) {};
295
    ~Names()
296
0
    {
297
0
      if (opt)
298
0
      {
299
0
        delete opt;
300
0
      }
301
0
    }
302
    std::list<std::string> opt_long;
303
    std::list<std::string> opt_short;
304
    OptionBase* opt;
305
  };
306
307
  void addOption(OptionBase *opt)
308
0
  {
309
0
    Names* names = new Names();
310
0
    names->opt = opt;
311
0
    std::string& opt_string = opt->opt_string;
312
313
0
    if( useLowerNamesOnly )
314
0
    {
315
0
      std::transform( opt_string.begin(), opt_string.end(), opt_string.begin(), ::tolower );
316
0
    }
317
318
0
    size_t opt_start = 0;
319
0
    for (size_t opt_end = 0; opt_end != std::string::npos;)
320
0
    {
321
0
      opt_end = opt_string.find_first_of(',', opt_start);
322
0
      bool force_short = 0;
323
0
      if (opt_string[opt_start] == '-')
324
0
      {
325
0
        opt_start++;
326
0
        force_short = 1;
327
0
      }
328
0
      std::string opt_name = opt_string.substr(opt_start, opt_end - opt_start);
329
0
      if (force_short || opt_name.size() == 1)
330
0
      {
331
0
        names->opt_short.push_back(opt_name);
332
0
        opt_short_map[opt_name].push_back(names);
333
0
      }
334
0
      else
335
0
      {
336
0
        names->opt_long.push_back(opt_name);
337
338
0
        std::string optLongLower = opt_name;
339
0
        std::transform( optLongLower.begin(), optLongLower.end(), optLongLower.begin(), ::tolower );
340
0
        opt_long_map[optLongLower].push_back(names);
341
0
      }
342
0
      opt_start += opt_end + 1;
343
0
    }
344
345
0
    if( !subSections_list.empty() )
346
0
    {
347
0
      if( curSubSection.empty() ){ curSubSection = subSections_list.back(); }
348
0
      sub_section_namelist_map[curSubSection].push_back(opt_string);
349
0
    }
350
351
0
    opt_list.push_back(names);
352
0
  }
353
354
  typedef std::list<Names*> NamesPtrList;
355
  NamesPtrList opt_list;
356
357
  typedef std::map<std::string, NamesPtrList> NamesMap;
358
  NamesMap opt_long_map;
359
  NamesMap opt_short_map;
360
361
  int setSubSection(std::string subSection)
362
0
  {
363
0
    curSubSection = subSection;
364
0
    for( auto s : subSections_list )
365
0
    {
366
0
      if( s == subSection )
367
0
      {
368
0
        return -1;
369
0
      }
370
0
    }
371
0
    subSections_list.push_back( subSection );
372
0
    return 0;
373
0
  } 
374
375
0
  void setLowerCaseOnly() { useLowerNamesOnly = true; }
376
377
  typedef std::list<std::string> subSectionsPtrList;
378
  subSectionsPtrList subSections_list;
379
  std::string curSubSection;
380
  
381
  typedef std::map<std::string, std::list<std::string> > SubSectionNamesListMap;
382
  SubSectionNamesListMap sub_section_namelist_map;
383
384
  bool useLowerNamesOnly = false; // if true, option names are always set to lower case
385
};
386
387
/* Class with templated overloaded operator(), for use by Options::addOptions() */
388
class OptionSpecific
389
{
390
public:
391
0
  OptionSpecific(Options& parent_) : parent(parent_) {}
392
393
  /**
394
   * Add option described by name to the parent Options list,
395
   *   with storage for the option's value
396
   *   with default_val as the default value
397
   *   with desc as an optional help description
398
   */
399
  template<typename T>
400
  OptionSpecific&
401
  operator()(const std::string& name, T& storage, T default_val, const std::string& desc = "", bool bool_switch = false)
402
  {
403
    parent.addOption(new Option<T>(name, storage, default_val, desc, bool_switch));
404
    return *this;
405
  }
406
407
  /**
408
   * Add option described by name to the parent Options list,
409
   *   without separate default value
410
   */
411
  template<typename T>
412
  OptionSpecific&
413
  operator()(const std::string& name, T& storage, const std::string& desc = "", bool bool_switch = false )
414
0
  {
415
0
    parent.addOption(new Option<T>(name, storage, storage, desc, bool_switch));
416
0
    return *this;
417
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::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::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)
418
419
  /**
420
   * Add option described by name to the parent Options list,
421
   *   with desc as an optional help description
422
   * instead of storing the value somewhere, a function of type
423
   * OptionFunc::Func is called.  It is upto this function to correctly
424
   * handle evaluating the option's value.
425
   */
426
  OptionSpecific&
427
  operator()(const std::string& name, OptionFunc::Func *func, const std::string& desc = "")
428
0
  {
429
0
    parent.addOption(new OptionFunc(name, parent, func, desc));
430
0
    return *this;
431
0
  }
432
private:
433
  Options& parent;
434
};
435
436
static void setOptions(Options::NamesPtrList& opt_list, const std::string& value, ErrorReporter& error_reporter)
437
0
{
438
  /* multiple options may be registered for the same name:
439
    *   allow each to parse value */
440
0
  for (Options::NamesPtrList::iterator it = opt_list.begin(); it != opt_list.end(); ++it)
441
0
  {
442
0
    (*it)->opt->parse(value, error_reporter);
443
0
  }
444
0
}
445
446
447
static const char spaces[41] = "                                        ";
448
449
450
/* format help text for a single option:
451
  * using the formatting: "-x, --long",
452
  * if a short/long option isn't specified, it is not printed
453
  */
454
static void doHelpOpt(std::ostream& out, const Options::Names& entry, unsigned pad_short = 0)
455
0
{
456
0
  pad_short = std::min(pad_short, 8u);
457
458
0
  if (!entry.opt_short.empty())
459
0
  {
460
0
    unsigned pad = std::max((int)pad_short - (int)entry.opt_short.front().size(), 0);
461
0
    out << "-" << entry.opt_short.front();
462
0
    if (!entry.opt_long.empty())
463
0
    {
464
0
      out << ", ";
465
0
    }
466
0
    out << &(spaces[40 - pad]);
467
0
  }
468
0
  else
469
0
  {
470
0
    out << "   ";
471
0
    out << &(spaces[40 - pad_short]);
472
0
  }
473
474
0
  if (!entry.opt_long.empty())
475
0
  {
476
0
    out << "--" << entry.opt_long.front();
477
0
  }
478
0
  out << " [" << entry.opt->getDefault() << "] ";
479
0
}
480
481
/* format text for 'additional' string options for a single option:
482
  * using the formatting: "option",
483
  */
484
 static void doAdditionalOpt(std::ostream& out, const Options::Names& entry, unsigned pad_short = 0)
485
0
 {
486
0
   pad_short = std::min(pad_short, 8u);
487
488
0
   out << "   ";
489
0
   out << &(spaces[40 - pad_short]);
490
491
0
   if (!entry.opt_long.empty())
492
0
   {
493
0
     out << entry.opt_long.front();
494
0
   }
495
0
   out << " [" << entry.opt->getDefault() << "] ";
496
0
 }
497
498
static void doPrintHelpEntry( std::ostream& out, const Options::Names& entry, unsigned desc_width, unsigned opt_width, unsigned pad_short = 0, bool isAdditionalOpt = false )
499
0
{
500
0
  std::ostringstream line(std::ios_base::out);
501
0
  line << "  ";
502
503
0
  if ( isAdditionalOpt )
504
0
    doAdditionalOpt(line, entry, pad_short);
505
0
  else
506
0
    doHelpOpt(line, entry, pad_short);
507
508
0
  const std::string& opt_desc = entry.opt->opt_desc;
509
0
  if (opt_desc.empty())
510
0
  {
511
    /* no help text: output option, skip further processing */
512
0
    out << line.str() << std::endl;
513
0
    return;
514
0
  }
515
0
  size_t currlength = size_t(line.tellp());
516
0
  if (currlength > opt_width)
517
0
  {
518
    /* if option text is too long (and would collide with the
519
      * help text, split onto next line */
520
0
    line << std::endl;
521
0
    currlength = 0;
522
0
  }
523
  /* split up the help text, taking into account new lines,
524
    *   (add opt_width of padding to each new line) */
525
0
  for (size_t newline_pos = 0, cur_pos = 0; cur_pos != std::string::npos; currlength = 0)
526
0
  {
527
    /* print any required padding space for vertical alignment */
528
0
    line << &(spaces[40 - opt_width + currlength]);
529
0
    newline_pos = opt_desc.find_first_of('\n', newline_pos);
530
0
    if (newline_pos != std::string::npos)
531
0
    {
532
      /* newline found, print substring (newline needn't be stripped) */
533
0
      newline_pos++;
534
0
      line << opt_desc.substr(cur_pos, newline_pos - cur_pos);
535
0
      cur_pos = newline_pos;
536
0
      continue;
537
0
    }
538
0
    if (cur_pos + desc_width > opt_desc.size())
539
0
    {
540
      /* no need to wrap text, remainder is less than avaliable width */
541
0
      line << opt_desc.substr(cur_pos);
542
0
      break;
543
0
    }
544
    /* find a suitable point to split text (avoid spliting in middle of word) */
545
0
    size_t split_pos = opt_desc.find_last_of(' ', cur_pos + desc_width);
546
0
    if (split_pos != std::string::npos)
547
0
    {
548
      /* eat up multiple space characters */
549
0
      split_pos = opt_desc.find_last_not_of(' ', split_pos) + 1;
550
0
    }
551
552
    /* bad split if no suitable space to split at.  fall back to width */
553
0
    bool bad_split = split_pos == std::string::npos || split_pos <= cur_pos;
554
0
    if (bad_split)
555
0
    {
556
0
      split_pos = cur_pos + desc_width;
557
0
    }
558
0
    line << opt_desc.substr(cur_pos, split_pos - cur_pos);
559
560
    /* eat up any space for the start of the next line */
561
0
    if (!bad_split)
562
0
    {
563
0
      split_pos = opt_desc.find_first_not_of(' ', split_pos);
564
0
    }
565
0
    cur_pos = newline_pos = split_pos;
566
567
0
    if (cur_pos >= opt_desc.size())
568
0
    {
569
0
      break;
570
0
    }
571
0
    line << std::endl;
572
0
  }
573
574
0
  out << line.str() << std::endl;
575
0
}
576
577
/* prints a formated config entry */
578
static void printFormattedConfigEntry( std::ostream& out, const Options::Names& entry, unsigned desc_width, unsigned opt_width, unsigned opt_value_width )
579
0
{
580
  // prints a config entry. format:
581
  // option       : vaue        # help  [default]
582
583
0
  std::ostringstream line(std::ios_base::out);
584
585
0
  if (!entry.opt_long.empty())
586
0
  {
587
0
    line << entry.opt_long.front();
588
589
0
    for( size_t s = 0 ; s < (opt_width - entry.opt_long.front().length()) ; ++s )
590
0
    {
591
0
      line << ' ' ;
592
0
    }
593
594
0
    line << ": " << entry.opt->getValue();
595
0
  }
596
0
  else
597
0
  {
598
0
    return;
599
0
  }
600
601
0
  const std::string& opt_desc = entry.opt->opt_desc;
602
0
  if (opt_desc.empty())
603
0
  {
604
    /* no help text: output option, skip further processing */
605
0
    out << line.str() << std::endl;
606
0
    return;
607
0
  }
608
609
0
  size_t currlength = size_t(line.tellp());
610
0
  if (currlength > opt_value_width)
611
0
  {
612
    /* if option text is too long (and would collide with the
613
      * help text, split onto next line */
614
0
    line << std::endl;
615
0
    currlength = 0;
616
0
  }
617
  /* split up the help text, taking into account new lines,
618
    *   (add opt_value_width of padding to each new line) */
619
0
  for (size_t newline_pos = 0, cur_pos = 0; cur_pos != std::string::npos; currlength = 0)
620
0
  {
621
    /* print any required padding space for vertical alignment */
622
623
0
    for( size_t num_sp = 0 ; num_sp < opt_value_width - currlength ; ++num_sp )
624
0
    {
625
0
      line << ' ' ;
626
0
    }
627
0
    newline_pos = opt_desc.find_first_of('\n', newline_pos);
628
0
    if (newline_pos != std::string::npos)
629
0
    {
630
      /* newline found, print substring (newline needn't be stripped) */
631
0
      newline_pos++;
632
0
      line << " # ";
633
0
      line << opt_desc.substr(cur_pos, newline_pos - cur_pos);
634
0
      cur_pos = newline_pos;
635
0
      continue;
636
0
    }
637
0
    if (cur_pos + desc_width > opt_desc.size())
638
0
    {
639
      /* no need to wrap text, remainder is less than avaliable width */
640
0
      line << " # ";
641
0
      line << opt_desc.substr(cur_pos);
642
0
      line << " [" << entry.opt->getDefault( ) << "] ";
643
0
      break;
644
0
    }
645
    /* find a suitable point to split text (avoid spliting in middle of word) */
646
0
    size_t split_pos = opt_desc.find_last_of(' ', cur_pos + desc_width);
647
0
    if (split_pos != std::string::npos)
648
0
    {
649
      /* eat up multiple space characters */
650
0
      split_pos = opt_desc.find_last_not_of(' ', split_pos) + 1;
651
0
    }
652
653
    /* bad split if no suitable space to split at.  fall back to width */
654
0
    bool bad_split = split_pos == std::string::npos || split_pos <= cur_pos;
655
0
    if (bad_split)
656
0
    {
657
0
      split_pos = cur_pos + desc_width;
658
0
    }
659
0
    line << " # ";
660
0
    line << opt_desc.substr(cur_pos, split_pos - cur_pos);
661
662
    /* eat up any space for the start of the next line */
663
0
    if (!bad_split)
664
0
    {
665
0
      split_pos = opt_desc.find_first_not_of(' ', split_pos);
666
0
    }
667
0
    cur_pos = newline_pos = split_pos;
668
669
0
    if (cur_pos >= opt_desc.size())
670
0
    {
671
0
      break;
672
0
    }
673
0
    line << std::endl;
674
0
  }
675
676
0
  out << line.str() << std::endl;
677
0
}
678
679
/* format the help text */
680
inline void doHelp(std::ostream& out, Options& opts, unsigned columns  = 120)
681
0
{
682
0
  const unsigned pad_short = 3;
683
  /* first pass: work out the longest option name */
684
0
  unsigned max_width = 0;
685
0
  for(Options::NamesPtrList::iterator it = opts.opt_list.begin(); it != opts.opt_list.end(); it++)
686
0
  {
687
0
    std::ostringstream line(std::ios_base::out);
688
0
    doHelpOpt(line, **it, pad_short);
689
0
    max_width = std::max(max_width, (unsigned) line.tellp());
690
0
  }
691
692
0
  unsigned opt_width = std::min(max_width+2, 32u + pad_short) + 2;
693
0
  unsigned desc_width = columns - opt_width;
694
695
  /* second pass: write out formatted option and help text.
696
    *  - align start of help text to start at opt_width
697
    *  - if the option text is longer than opt_width, place the help
698
    *    text at opt_width on the next line.
699
    */
700
0
  if( opts.subSections_list.empty())
701
0
  {
702
0
    for (const auto& opt: opts.opt_list)
703
0
    {
704
0
      doPrintHelpEntry( out, *opt, desc_width, opt_width, pad_short );
705
0
    }
706
0
    return;
707
0
  }
708
709
0
  for (const auto& section: opts.subSections_list)
710
0
  {
711
0
    if( section != "__$PLACEHOLDER$__")  // print sub section name (if not dummy section)
712
0
    {
713
0
      out << std::endl << "#======== " << section << " ================" << std::endl;
714
0
    }
715
716
0
    Options::SubSectionNamesListMap::const_iterator itSectionMap = opts.sub_section_namelist_map.find(section);  // get list of options in subsection
717
0
    if (itSectionMap != opts.sub_section_namelist_map.end())
718
0
    {
719
0
      for( auto & s : itSectionMap->second ) // iterate over options in subsections and find/print entry in opts list
720
0
      {
721
0
        for(Options::NamesPtrList::const_iterator itopt = opts.opt_list.begin(); itopt != opts.opt_list.end(); itopt++)
722
0
        {
723
0
          if( (*itopt)->opt->opt_string == s )  // names are equal
724
0
          {
725
0
            doPrintHelpEntry( out, **itopt, desc_width, opt_width, pad_short );
726
0
            break;
727
0
            }
728
0
        }
729
0
      }
730
0
    }
731
0
  }
732
0
}
733
734
/* format the help text */
735
inline void doAdditionalOptList(std::ostream& out, Options& opts, unsigned columns  = 80)
736
0
{
737
0
  const unsigned pad_short = 3;
738
  /* first pass: work out the longest option name */
739
0
  unsigned max_width = 0;
740
0
  for(Options::NamesPtrList::iterator it = opts.opt_list.begin(); it != opts.opt_list.end(); it++)
741
0
  {
742
0
    std::ostringstream line(std::ios_base::out);
743
0
    doAdditionalOpt(line, **it, pad_short);
744
0
    max_width = std::max(max_width, (unsigned) line.tellp());
745
0
  }
746
747
0
  unsigned opt_width = std::min(max_width+2, 32u + pad_short) + 2;
748
0
  unsigned desc_width = columns - opt_width;
749
750
  /* second pass: write out formatted option and help text.
751
    *  - align start of help text to start at opt_width
752
    *  - if the option text is longer than opt_width, place the help
753
    *    text at opt_width on the next line.
754
    */
755
0
  if( opts.subSections_list.empty())
756
0
  {
757
0
    for (const auto& opt: opts.opt_list)
758
0
    {
759
0
      doPrintHelpEntry( out, *opt, desc_width, opt_width, pad_short, true );
760
0
    }
761
0
    return;
762
0
  }
763
764
0
  for (const auto& section: opts.subSections_list)
765
0
  {
766
0
    if( section != "__$PLACEHOLDER$__")  // print sub section name (if not dummy section)
767
0
    {
768
0
      out << std::endl << "#======== " << section << " ================" << std::endl;
769
0
    }
770
771
0
    Options::SubSectionNamesListMap::const_iterator itSectionMap = opts.sub_section_namelist_map.find(section);  // get list of options in subsection
772
0
    if (itSectionMap != opts.sub_section_namelist_map.end())
773
0
    {
774
0
      for( auto & s : itSectionMap->second ) // iterate over options in subsections and find/print entry in opts list
775
0
      {
776
0
        for(Options::NamesPtrList::const_iterator itopt = opts.opt_list.begin(); itopt != opts.opt_list.end(); itopt++)
777
0
        {
778
0
          if( (*itopt)->opt->opt_string == s )  // names are equal
779
0
          {
780
0
            doPrintHelpEntry( out, **itopt, desc_width, opt_width, pad_short, true );
781
0
            break;
782
0
            }
783
0
        }
784
0
      }
785
0
    }
786
0
  }
787
0
}
788
789
/* prints a formated configuration of Options into a ostream */
790
inline void saveConfig(std::ostream& out, Options& opts, std::list<std::string> ignoreParamLst, unsigned columns = 240 )
791
0
{
792
  /* first pass: work out the longest option name */
793
0
  unsigned max_width_optname = 0;
794
0
  for(Options::NamesPtrList::iterator it = opts.opt_list.begin(); it != opts.opt_list.end(); it++)
795
0
  {
796
0
    if (!(**it).opt_long.empty())
797
0
    {
798
0
      unsigned w = (unsigned)(**it).opt_long.front().size();
799
0
      max_width_optname = std::max(max_width_optname, w);
800
0
    }
801
0
  }
802
803
  /* second pass: work out the longest value*/
804
0
  unsigned max_width_value = 0;
805
0
  for(Options::NamesPtrList::iterator it = opts.opt_list.begin(); it != opts.opt_list.end(); it++)
806
0
  {
807
0
    std::string value = (**it).opt->getValue();
808
0
    max_width_value = std::max(max_width_value, (unsigned) value.length() );
809
0
  }
810
811
0
  unsigned max_width_opt_value = max_width_optname + max_width_value +3; // max size of option + " : " + value
812
0
  unsigned desc_width = columns - max_width_opt_value;                   // max. size for description
813
814
  /* 3rd pass: write out formatted option + current value +  help text + default value.
815
    * format is:
816
    * option       : vaue        # help  [default]
817
    *  - if the option text is longer than opt_width, place the help
818
    *    text at opt_width on the next line.
819
    */
820
0
  if( opts.subSections_list.empty())
821
0
  {
822
0
    for (const auto& opt: opts.opt_list)
823
0
    {
824
0
      bool ignore = ignoreParamLst.end() != std::find(ignoreParamLst.begin(), ignoreParamLst.end(), opt->opt->opt_string);
825
0
      if( !ignore)
826
0
      {
827
0
        printFormattedConfigEntry( out, *opt, desc_width, max_width_optname, max_width_opt_value );
828
0
      }
829
0
    }
830
0
    return;
831
0
  }
832
833
  // iterate over all subsections and print all entries for each subsection
834
0
  for (const auto& section: opts.subSections_list)
835
0
  {
836
0
    if( section != "__$PLACEHOLDER$__")  // print sub section name (if not dummy section)
837
0
    {
838
0
      out << std::endl << "#======== " << section << " ================" << std::endl;
839
0
    }
840
841
0
    Options::SubSectionNamesListMap::const_iterator itSectionMap = opts.sub_section_namelist_map.find(section);  // get list of options in subsection
842
0
    if (itSectionMap != opts.sub_section_namelist_map.end())
843
0
    {
844
0
      for( auto & s : itSectionMap->second ) // iterate over options in subsections and find/print entry in opts list
845
0
      {
846
0
        for(Options::NamesPtrList::const_iterator itopt = opts.opt_list.begin(); itopt != opts.opt_list.end(); itopt++)
847
0
        {
848
0
          if( (*itopt)->opt->opt_string == s )  // names are equal
849
0
          {
850
0
            bool ignore = ignoreParamLst.end() != std::find(ignoreParamLst.begin(), ignoreParamLst.end(), (*itopt)->opt->opt_string);
851
0
            if( !ignore)
852
0
            {
853
0
              printFormattedConfigEntry( out, **itopt, desc_width, max_width_optname, max_width_opt_value );
854
0
            }
855
856
0
            break;
857
0
          }
858
0
        }
859
0
      }
860
0
    }
861
0
  }
862
0
}
863
864
865
// OptionWriter
866
struct OptionWriter
867
{
868
  OptionWriter(Options& rOpts, ErrorReporter& err)
869
0
  : opts(rOpts), error_reporter(err)
870
0
  {}
871
0
  virtual ~OptionWriter() {}
872
873
  virtual const std::string where() = 0;
874
875
  bool storePair(bool allow_long, bool allow_short, const std::string& name, const std::string& value)
876
0
  {
877
0
    bool found = false;
878
0
    Options::NamesMap::iterator opt_it;
879
0
    if (allow_long)
880
0
    {
881
0
      std::string optLongLower = name;
882
0
      std::transform( optLongLower.begin(), optLongLower.end(), optLongLower.begin(), ::tolower );
883
884
0
      opt_it = opts.opt_long_map.find(optLongLower);
885
0
      if (opt_it != opts.opt_long_map.end())
886
0
      {
887
0
        found = true;
888
0
      }
889
0
    }
890
891
    /* check for the short list */
892
0
    if (allow_short && !(found && allow_long))
893
0
    {
894
0
      opt_it = opts.opt_short_map.find(name);
895
0
      if (opt_it != opts.opt_short_map.end())
896
0
      {
897
0
        found = true;
898
0
      }
899
0
    }
900
901
0
    if (!found)
902
0
    {
903
0
      error_reporter.error(where())
904
0
        << "Unknown option `" << name << "' (value:`" << value << "')\n";
905
0
      return false;
906
0
    }
907
908
0
    setOptions((*opt_it).second, value, error_reporter);
909
0
    return true;
910
0
  }
911
912
  bool storePair(const std::string& name, const std::string& value)
913
0
  {
914
0
    return storePair(true, true, name, value);
915
0
  }
916
917
  Options& opts;
918
  ErrorReporter& error_reporter;
919
};
920
921
922
struct ArgvParser : public OptionWriter
923
{
924
  ArgvParser(Options& rOpts, ErrorReporter& rError_reporter)
925
0
  : OptionWriter(rOpts, rError_reporter)
926
0
  {}
927
928
0
  const std::string where() { return "command line"; }
929
930
  /**
931
   * returns number of extra arguments consumed
932
   */
933
  unsigned parseGNU(unsigned argc, const char* argv[])
934
0
  {
935
    /* gnu style long options can take the forms:
936
    *  --option=arg
937
    *  --option arg
938
    */
939
0
    std::string arg(argv[0]);
940
0
    size_t arg_opt_start = arg.find_first_not_of('-');
941
0
    size_t arg_opt_sep = arg.find_first_of('=');
942
0
    std::string option = arg.substr(arg_opt_start, arg_opt_sep - arg_opt_start);
943
944
0
    std::transform( option.begin(), option.end(), option.begin(), ::tolower ); // compare option always in lower case
945
946
0
    unsigned extra_argc_consumed = 0;
947
0
    if (arg_opt_sep == std::string::npos)
948
0
    {
949
      // check if we have an argument 
950
0
      if( argc > 1)
951
0
      {
952
0
        std::string val(argv[1]);
953
0
        size_t val_sep = val.find_first_of('-');
954
        //check if either have no - or the parameter is a number 
955
0
        if( 0 != val_sep || std::regex_match( val, std::regex( ( "((\\+|-)?[[:digit:]]+)(\\.(([[:digit:]]+)?))?" ) ) ) ) 
956
0
        {
957
0
          extra_argc_consumed++;
958
          /* argument occurs after option_sep */
959
0
          storePair(true, false, option, val);
960
0
          return extra_argc_consumed;
961
0
        }
962
0
        else if( val_sep == 0 && val.size() == 1 )
963
0
        {
964
0
          extra_argc_consumed++;
965
          /* argument occurs after option_sep */
966
0
          storePair(true, false, option, val);
967
0
          return extra_argc_consumed;
968
0
        }
969
0
      }
970
971
      /* no argument found => argument in argv[1] (maybe) */
972
      /* xxx, need to handle case where option isn't required */
973
0
      if(!storePair(true, false, option, ""))
974
0
      {
975
0
        return 0;
976
0
      }
977
0
    }
978
0
    else
979
0
    {
980
      /* argument occurs after option_sep */
981
0
      std::string val = arg.substr(arg_opt_sep + 1);
982
0
      storePair(true, false, option, val);
983
0
    }
984
985
0
    return extra_argc_consumed;
986
0
  }
987
988
989
  unsigned parseSHORT(unsigned argc, const char* argv[])
990
0
  {
991
    /* short options can take the forms:
992
    *  --option arg
993
    *  -option arg
994
    */
995
0
    std::string arg(argv[0]);
996
0
    size_t arg_opt_start = arg.find_first_not_of('-');
997
0
    std::string option = arg.substr(arg_opt_start);
998
    /* lookup option */
999
1000
    /* argument in argv[1] */
1001
    /* xxx, need to handle case where option isn't required */
1002
0
    if (argc == 1)
1003
0
    {
1004
0
      storePair(false, true, option, std::string(""));
1005
0
      return 1;
1006
0
    }
1007
1008
0
    std::string argNext = argv[1];
1009
0
    if( !argNext.empty() && argNext[0] == '-' )
1010
0
    {
1011
      // check if bool switch and check if next param is not an option
1012
0
      if( argNext.size() > 1 )
1013
0
      {
1014
0
        if( argNext[1] == '-' ) // is long option --
1015
0
        {
1016
0
          storePair(false, true, option, std::string(""));
1017
0
          return 0;
1018
0
        }
1019
1020
        // check if argv is an digit number
1021
0
        if( !std::isdigit(argNext[1]) )
1022
0
        {
1023
0
          storePair(false, true, option, std::string(""));
1024
0
          return 0;
1025
0
        }
1026
0
      }
1027
0
    }
1028
1029
0
    storePair(false, true, option, std::string(argv[1]));
1030
1031
0
    return 1;
1032
0
  }
1033
};
1034
1035
struct CfgStreamParser : public OptionWriter
1036
{
1037
  CfgStreamParser(const std::string& rName, Options& rOpts, ErrorReporter& rError_reporter)
1038
0
  : OptionWriter(rOpts, rError_reporter)
1039
0
  , name(rName)
1040
0
  , linenum(0)
1041
0
  {}
1042
1043
  const std::string name;
1044
  int linenum;
1045
  const std::string where()
1046
0
  {
1047
0
    std::ostringstream os;
1048
0
    os << name << ":" << linenum;
1049
0
    return os.str();
1050
0
  }
1051
1052
  void scanLine(std::string& line)
1053
0
  {
1054
    /* strip any leading whitespace */
1055
0
    size_t start = line.find_first_not_of(" \t\n\r");
1056
0
    if (start == std::string::npos)
1057
0
    {
1058
      /* blank line */
1059
0
      return;
1060
0
    }
1061
0
    if (line[start] == '#')
1062
0
    {
1063
      /* comment line */
1064
0
      return;
1065
0
    }
1066
    /* look for first whitespace or ':' after the option end */
1067
0
    size_t option_end = line.find_first_of(": \t\n\r",start);
1068
0
    std::string option = line.substr(start, option_end - start);
1069
1070
    /* look for ':', eat up any whitespace first */
1071
0
    start = line.find_first_not_of(" \t\n\r", option_end);
1072
0
    if (start == std::string::npos)
1073
0
    {
1074
      /* error: badly formatted line */
1075
0
      error_reporter.warn(where()) << "line formatting error\n";
1076
0
      return;
1077
0
    }
1078
0
    if (line[start] != ':')
1079
0
    {
1080
      /* error: badly formatted line */
1081
0
      error_reporter.warn(where()) << "line formatting error\n";
1082
0
      return;
1083
0
    }
1084
1085
    /* look for start of value std::string -- eat up any leading whitespace */
1086
0
    start = line.find_first_not_of(" \t\n\r", ++start);
1087
0
    if (start == std::string::npos)
1088
0
    {
1089
      /* error: badly formatted line */
1090
0
      error_reporter.warn(where()) << "line formatting error\n";
1091
0
      return;
1092
0
    }
1093
1094
    /* extract the value part, which may contain embedded spaces
1095
    * by searching for a word at a time, until we hit a comment or end of line */
1096
0
    size_t value_end = start;
1097
0
    do
1098
0
    {
1099
0
      if (line[value_end] == '#')
1100
0
      {
1101
        /* rest of line is a comment */
1102
0
        value_end--;
1103
0
        break;
1104
0
      }
1105
0
      value_end = line.find_first_of(" \t\n\r", value_end);
1106
      /* consume any white space, incase there is another word.
1107
      * any trailing whitespace will be removed shortly */
1108
0
      value_end = line.find_first_not_of(" \t\n\r", value_end);
1109
0
    } while (value_end != std::string::npos);
1110
    /* strip any trailing space from value*/
1111
0
    value_end = line.find_last_not_of(" \t\n\r", value_end);
1112
1113
0
    std::string value;
1114
0
    if (value_end >= start)
1115
0
    {
1116
0
      value = line.substr(start, value_end +1 - start);
1117
0
    }
1118
0
    else
1119
0
    {
1120
      /* error: no value */
1121
0
      error_reporter.warn(where()) << "no value found for option " << option << "\n";
1122
0
      return;
1123
0
    }
1124
1125
    // reset empty strings
1126
0
    if( value == "\"\"" || value == "''")
1127
0
    {
1128
0
      value.clear();
1129
0
    }
1130
1131
    /* store the value in option */
1132
0
    storePair(true, false, option, value);
1133
0
  }
1134
1135
  void scanStream(std::istream& in)
1136
0
  {
1137
0
    do
1138
0
    {
1139
0
      linenum++;
1140
0
      std::string line;
1141
0
      getline(in, line);
1142
0
      scanLine(line);
1143
0
    } while(!!in);
1144
0
  }
1145
1146
};  
1147
1148
1149
1150
inline std::list<const char*> scanArgv(Options& opts, unsigned argc, const char* argv[], ErrorReporter& error_reporter = default_error_reporter)
1151
0
{
1152
0
  ArgvParser avp(opts, error_reporter);
1153
1154
  /* a list for anything that didn't get handled as an option */
1155
0
  std::list<const char*> non_option_arguments;
1156
1157
0
  for(unsigned i = 0; i < argc; i++)
1158
0
  {
1159
0
    if (argv[i][0] != '-')
1160
0
    {
1161
0
      non_option_arguments.push_back(argv[i]);
1162
0
      continue;
1163
0
    }
1164
1165
0
    if (argv[i][1] == 0)
1166
0
    {
1167
      /* a lone single dash is an argument (usually signifying stdin) */
1168
0
      non_option_arguments.push_back(argv[i]);
1169
0
      continue;
1170
0
    }
1171
1172
0
    if (argv[i][1] != '-')
1173
0
    {
1174
      /* handle short (single dash) options */
1175
0
      i += avp.parseSHORT(argc - i, &argv[i]);
1176
0
      continue;
1177
0
    }
1178
1179
0
    if (argv[i][2] == 0)
1180
0
    {
1181
      /* a lone double dash ends option processing */
1182
0
      while (++i < argc)
1183
0
      {
1184
0
        non_option_arguments.push_back(argv[i]);
1185
0
      }
1186
0
      break;
1187
0
    }
1188
1189
    /* handle long (double dash) options */
1190
0
    i += avp.parseGNU(argc - i, &argv[i]);
1191
0
  }
1192
1193
0
  return non_option_arguments;
1194
0
}
1195
1196
1197
/* for all options in opts, set their storage to their specified
1198
  * default value */
1199
inline void setDefaults(Options& opts)
1200
0
{
1201
0
  for(Options::NamesPtrList::iterator it = opts.opt_list.begin(); it != opts.opt_list.end(); it++)
1202
0
  {
1203
0
    (*it)->opt->setDefault();
1204
0
  }
1205
0
}
1206
1207
inline void parseConfigFile(Options& opts, const std::string& filename, ErrorReporter& error_reporter = default_error_reporter)
1208
0
{
1209
0
  std::ifstream cfgstream(filename.c_str(), std::ifstream::in);
1210
0
  if (!cfgstream)
1211
0
  {
1212
0
    error_reporter.error(filename) << "Failed to open config file\n";
1213
0
    return;
1214
0
  }
1215
0
  CfgStreamParser csp(filename, opts, error_reporter);
1216
0
  csp.scanStream(cfgstream);
1217
0
}
1218
1219
OptionSpecific Options::addOptions()
1220
0
{
1221
0
  if( subSections_list.empty()){ subSections_list.push_back( "__$PLACEHOLDER$__" ); } // add dummy section if nothing is given
1222
0
  return OptionSpecific(*this);
1223
0
}
1224
1225
} /* namespace: df */
1226
1227
} // namespace
1228
1229
//! \}
1230