/work/vvenc/source/Lib/apputils/IStreamIO.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 <string> |
47 | | #include <list> |
48 | | #include <map> |
49 | | #include <vector> |
50 | | #include <algorithm> |
51 | | #include <cstdint> |
52 | | #include <cmath> |
53 | | #include <limits> |
54 | | |
55 | | #include "VVEncAppCfg.h" |
56 | | #include <vvenc/vvencCfg.h> |
57 | | |
58 | | //! \ingroup Interface |
59 | | //! \{ |
60 | | |
61 | | namespace apputils { |
62 | | |
63 | | template<typename E> |
64 | | struct SVPair |
65 | | { |
66 | | const char* str; |
67 | | E value; |
68 | | }; |
69 | | |
70 | | // reads one list token; fails unless the whole token is the value ("1920y" is not 1920) |
71 | | template<typename T> |
72 | | inline bool readWholeToken( const std::string& token, T& val ) |
73 | 0 | { |
74 | 0 | std::stringstream convStream( token ); |
75 | 0 | convStream >> val; |
76 | 0 | return !convStream.fail() && convStream.eof(); |
77 | 0 | } Unexecuted instantiation: bool apputils::readWholeToken<int>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int&) Unexecuted instantiation: bool apputils::readWholeToken<double>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, double&) Unexecuted instantiation: bool apputils::readWholeToken<unsigned int>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned int&) |
78 | | |
79 | | // ==================================================================================================================== |
80 | | // string <-> vector |
81 | | // ==================================================================================================================== |
82 | | |
83 | | template<typename T> |
84 | | class IStreamToRefVec |
85 | | { |
86 | | public: |
87 | | IStreamToRefVec( std::vector<T*> v, bool _allRequired, char _sep = 'x' ) |
88 | 0 | : valVec( v ) |
89 | 0 | , sep( _sep) |
90 | 0 | , allRequired( _allRequired) |
91 | 0 | { |
92 | 0 | } Unexecuted instantiation: apputils::IStreamToRefVec<int>::IStreamToRefVec(std::__1::vector<int*, std::__1::allocator<int*> >, bool, char) Unexecuted instantiation: apputils::IStreamToRefVec<double>::IStreamToRefVec(std::__1::vector<double*, std::__1::allocator<double*> >, bool, char) |
93 | | |
94 | | ~IStreamToRefVec() |
95 | 0 | { |
96 | 0 | } Unexecuted instantiation: apputils::IStreamToRefVec<double>::~IStreamToRefVec() Unexecuted instantiation: apputils::IStreamToRefVec<int>::~IStreamToRefVec() |
97 | | |
98 | | template<typename F> |
99 | | friend std::istream& operator >> ( std::istream& in, IStreamToRefVec<F>& toVec ); |
100 | | |
101 | | template<typename F> |
102 | | friend std::ostream& operator << ( std::ostream& os, const IStreamToRefVec<F>& toVec ); |
103 | | |
104 | | private: |
105 | | std::vector<T*> valVec; |
106 | | char sep; |
107 | | bool allRequired; |
108 | | }; |
109 | | |
110 | | template<typename T> |
111 | | inline std::istream& operator >> ( std::istream& in, IStreamToRefVec<T>& toVec ) |
112 | 0 | { |
113 | 0 | const size_t maxSize = toVec.valVec.size(); |
114 | 0 | size_t idx = 0; |
115 | 0 | bool fail = false; |
116 | | // split into multiple lines if any |
117 | 0 | while ( ! in.eof() ) |
118 | 0 | { |
119 | 0 | std::string line; |
120 | 0 | std::getline( in, line ); |
121 | | // treat all whitespaces and commas as valid separators |
122 | 0 | if( toVec.sep == 'x') |
123 | 0 | replace_if( line.begin(), line.end(), []( int c ){ return isspace( c ) || c == 'x'; }, ' ' );Unexecuted instantiation: apputils::operator>><int>(std::__1::basic_istream<char, std::__1::char_traits<char> >&, apputils::IStreamToRefVec<int>&)::{lambda(int)#1}::operator()(int) constUnexecuted instantiation: apputils::operator>><double>(std::__1::basic_istream<char, std::__1::char_traits<char> >&, apputils::IStreamToRefVec<double>&)::{lambda(int)#1}::operator()(int) const |
124 | 0 | else if( toVec.sep == '/') |
125 | 0 | replace_if( line.begin(), line.end(), []( int c ){ return isspace( c ) || c == '/'; }, ' ' );Unexecuted instantiation: apputils::operator>><int>(std::__1::basic_istream<char, std::__1::char_traits<char> >&, apputils::IStreamToRefVec<int>&)::{lambda(int)#2}::operator()(int) constUnexecuted instantiation: apputils::operator>><double>(std::__1::basic_istream<char, std::__1::char_traits<char> >&, apputils::IStreamToRefVec<double>&)::{lambda(int)#2}::operator()(int) const |
126 | 0 | else |
127 | 0 | replace_if( line.begin(), line.end(), []( int c ){ return isspace( c ) || c == ','; }, ' ' );Unexecuted instantiation: apputils::operator>><int>(std::__1::basic_istream<char, std::__1::char_traits<char> >&, apputils::IStreamToRefVec<int>&)::{lambda(int)#3}::operator()(int) constUnexecuted instantiation: apputils::operator>><double>(std::__1::basic_istream<char, std::__1::char_traits<char> >&, apputils::IStreamToRefVec<double>&)::{lambda(int)#3}::operator()(int) const |
128 | 0 | std::stringstream tokenStream( line ); |
129 | 0 | std::string token; |
130 | | // split into multiple tokens if any |
131 | 0 | while( std::getline( tokenStream, token, ' ' ) ) |
132 | 0 | { |
133 | 0 | if ( ! token.length() ) |
134 | 0 | continue; |
135 | | // convert to value |
136 | 0 | T val; |
137 | 0 | fail |= !readWholeToken( token, val ); |
138 | 0 | if( idx >= maxSize ) |
139 | 0 | { |
140 | 0 | fail = true;//try to write behind buffer |
141 | 0 | } |
142 | 0 | else |
143 | 0 | { |
144 | 0 | *toVec.valVec[idx++] = val; |
145 | 0 | } |
146 | 0 | } |
147 | 0 | } |
148 | |
|
149 | 0 | if ( fail || (toVec.allRequired && idx != maxSize) ) |
150 | 0 | { |
151 | 0 | in.setstate( std::ios::failbit ); |
152 | 0 | } |
153 | |
|
154 | 0 | return in; |
155 | 0 | } Unexecuted instantiation: std::__1::basic_istream<char, std::__1::char_traits<char> >& apputils::operator>><int>(std::__1::basic_istream<char, std::__1::char_traits<char> >&, apputils::IStreamToRefVec<int>&) Unexecuted instantiation: std::__1::basic_istream<char, std::__1::char_traits<char> >& apputils::operator>><double>(std::__1::basic_istream<char, std::__1::char_traits<char> >&, apputils::IStreamToRefVec<double>&) |
156 | | |
157 | | template<typename T> |
158 | | inline std::ostream& operator << ( std::ostream& os, const IStreamToRefVec<T>& toVec ) |
159 | 0 | { |
160 | 0 | bool bfirst = true; |
161 | 0 | for( auto& e: toVec.valVec ) |
162 | 0 | { |
163 | 0 | if( bfirst ) |
164 | 0 | { |
165 | 0 | bfirst = false; |
166 | 0 | } |
167 | 0 | else |
168 | 0 | { |
169 | 0 | os << toVec.sep; |
170 | 0 | } |
171 | 0 | os << *e; |
172 | 0 | } |
173 | 0 | return os; |
174 | 0 | } Unexecuted instantiation: std::__1::basic_ostream<char, std::__1::char_traits<char> >& apputils::operator<< <int>(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, apputils::IStreamToRefVec<int> const&) Unexecuted instantiation: std::__1::basic_ostream<char, std::__1::char_traits<char> >& apputils::operator<< <double>(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, apputils::IStreamToRefVec<double> const&) |
175 | | |
176 | | |
177 | | // ==================================================================================================================== |
178 | | // string <-> enum |
179 | | // ==================================================================================================================== |
180 | | |
181 | | template<typename E> |
182 | | class IStreamToEnum |
183 | | { |
184 | | public: |
185 | | IStreamToEnum( E* d, const std::vector<SVPair<E>>* m ) |
186 | 0 | : dstVal ( d ) |
187 | 0 | , toMap( m ) |
188 | 0 | { |
189 | 0 | } Unexecuted instantiation: apputils::IStreamToEnum<vvencMsgLevel>::IStreamToEnum(vvencMsgLevel*, std::__1::vector<apputils::SVPair<vvencMsgLevel>, std::__1::allocator<apputils::SVPair<vvencMsgLevel> > > const*) Unexecuted instantiation: apputils::IStreamToEnum<vvencProfile>::IStreamToEnum(vvencProfile*, std::__1::vector<apputils::SVPair<vvencProfile>, std::__1::allocator<apputils::SVPair<vvencProfile> > > const*) Unexecuted instantiation: apputils::IStreamToEnum<vvencTier>::IStreamToEnum(vvencTier*, std::__1::vector<apputils::SVPair<vvencTier>, std::__1::allocator<apputils::SVPair<vvencTier> > > const*) Unexecuted instantiation: apputils::IStreamToEnum<vvencLevel>::IStreamToEnum(vvencLevel*, std::__1::vector<apputils::SVPair<vvencLevel>, std::__1::allocator<apputils::SVPair<vvencLevel> > > const*) Unexecuted instantiation: apputils::IStreamToEnum<vvencSegmentMode>::IStreamToEnum(vvencSegmentMode*, std::__1::vector<apputils::SVPair<vvencSegmentMode>, std::__1::allocator<apputils::SVPair<vvencSegmentMode> > > const*) Unexecuted instantiation: apputils::IStreamToEnum<vvencHDRMode>::IStreamToEnum(vvencHDRMode*, std::__1::vector<apputils::SVPair<vvencHDRMode>, std::__1::allocator<apputils::SVPair<vvencHDRMode> > > const*) Unexecuted instantiation: apputils::IStreamToEnum<vvencDecodingRefreshType>::IStreamToEnum(vvencDecodingRefreshType*, std::__1::vector<apputils::SVPair<vvencDecodingRefreshType>, std::__1::allocator<apputils::SVPair<vvencDecodingRefreshType> > > const*) Unexecuted instantiation: apputils::IStreamToEnum<int>::IStreamToEnum(int*, std::__1::vector<apputils::SVPair<int>, std::__1::allocator<apputils::SVPair<int> > > const*) Unexecuted instantiation: apputils::IStreamToEnum<signed char>::IStreamToEnum(signed char*, std::__1::vector<apputils::SVPair<signed char>, std::__1::allocator<apputils::SVPair<signed char> > > const*) Unexecuted instantiation: apputils::IStreamToEnum<bool>::IStreamToEnum(bool*, std::__1::vector<apputils::SVPair<bool>, std::__1::allocator<apputils::SVPair<bool> > > const*) Unexecuted instantiation: apputils::IStreamToEnum<vvencCostMode>::IStreamToEnum(vvencCostMode*, std::__1::vector<apputils::SVPair<vvencCostMode>, std::__1::allocator<apputils::SVPair<vvencCostMode> > > const*) Unexecuted instantiation: apputils::IStreamToEnum<vvencChromaFormat>::IStreamToEnum(vvencChromaFormat*, std::__1::vector<apputils::SVPair<vvencChromaFormat>, std::__1::allocator<apputils::SVPair<vvencChromaFormat> > > const*) Unexecuted instantiation: apputils::IStreamToEnum<vvencHashType>::IStreamToEnum(vvencHashType*, std::__1::vector<apputils::SVPair<vvencHashType>, std::__1::allocator<apputils::SVPair<vvencHashType> > > const*) |
190 | | |
191 | | ~IStreamToEnum() |
192 | 0 | { |
193 | 0 | } Unexecuted instantiation: apputils::IStreamToEnum<signed char>::~IStreamToEnum() Unexecuted instantiation: apputils::IStreamToEnum<int>::~IStreamToEnum() Unexecuted instantiation: apputils::IStreamToEnum<vvencHashType>::~IStreamToEnum() Unexecuted instantiation: apputils::IStreamToEnum<vvencChromaFormat>::~IStreamToEnum() Unexecuted instantiation: apputils::IStreamToEnum<vvencCostMode>::~IStreamToEnum() Unexecuted instantiation: apputils::IStreamToEnum<bool>::~IStreamToEnum() Unexecuted instantiation: apputils::IStreamToEnum<vvencDecodingRefreshType>::~IStreamToEnum() Unexecuted instantiation: apputils::IStreamToEnum<vvencHDRMode>::~IStreamToEnum() Unexecuted instantiation: apputils::IStreamToEnum<vvencSegmentMode>::~IStreamToEnum() Unexecuted instantiation: apputils::IStreamToEnum<vvencLevel>::~IStreamToEnum() Unexecuted instantiation: apputils::IStreamToEnum<vvencTier>::~IStreamToEnum() Unexecuted instantiation: apputils::IStreamToEnum<vvencProfile>::~IStreamToEnum() Unexecuted instantiation: apputils::IStreamToEnum<vvencMsgLevel>::~IStreamToEnum() |
194 | | |
195 | | template<typename F> |
196 | | friend std::ostream& operator << ( std::ostream& os, const IStreamToEnum<F>& toEnum ); |
197 | | |
198 | | template<typename F> |
199 | | friend std::istream& operator >> ( std::istream& in, IStreamToEnum<F>& toEnum ); |
200 | | |
201 | | private: |
202 | | E* dstVal; |
203 | | const std::vector<SVPair<E>>* toMap; |
204 | | }; |
205 | | |
206 | | template<typename E> |
207 | | inline std::istream& operator >> ( std::istream& in, IStreamToEnum<E>& toEnum ) |
208 | 0 | { |
209 | 0 | std::string str; |
210 | 0 | in >> str; |
211 | |
|
212 | 0 | for ( const auto& map : *toEnum.toMap ) |
213 | 0 | { |
214 | 0 | if ( str == map.str ) |
215 | 0 | { |
216 | 0 | *toEnum.dstVal = map.value; |
217 | 0 | return in; |
218 | 0 | } |
219 | 0 | } |
220 | | |
221 | | /* not found */ |
222 | 0 | in.setstate( std::ios::failbit ); |
223 | 0 | return in; |
224 | 0 | } Unexecuted instantiation: std::__1::basic_istream<char, std::__1::char_traits<char> >& apputils::operator>><vvencMsgLevel>(std::__1::basic_istream<char, std::__1::char_traits<char> >&, apputils::IStreamToEnum<vvencMsgLevel>&) Unexecuted instantiation: std::__1::basic_istream<char, std::__1::char_traits<char> >& apputils::operator>><bool>(std::__1::basic_istream<char, std::__1::char_traits<char> >&, apputils::IStreamToEnum<bool>&) Unexecuted instantiation: std::__1::basic_istream<char, std::__1::char_traits<char> >& apputils::operator>><signed char>(std::__1::basic_istream<char, std::__1::char_traits<char> >&, apputils::IStreamToEnum<signed char>&) Unexecuted instantiation: std::__1::basic_istream<char, std::__1::char_traits<char> >& apputils::operator>><vvencDecodingRefreshType>(std::__1::basic_istream<char, std::__1::char_traits<char> >&, apputils::IStreamToEnum<vvencDecodingRefreshType>&) Unexecuted instantiation: std::__1::basic_istream<char, std::__1::char_traits<char> >& apputils::operator>><vvencProfile>(std::__1::basic_istream<char, std::__1::char_traits<char> >&, apputils::IStreamToEnum<vvencProfile>&) Unexecuted instantiation: std::__1::basic_istream<char, std::__1::char_traits<char> >& apputils::operator>><vvencLevel>(std::__1::basic_istream<char, std::__1::char_traits<char> >&, apputils::IStreamToEnum<vvencLevel>&) Unexecuted instantiation: std::__1::basic_istream<char, std::__1::char_traits<char> >& apputils::operator>><vvencTier>(std::__1::basic_istream<char, std::__1::char_traits<char> >&, apputils::IStreamToEnum<vvencTier>&) Unexecuted instantiation: std::__1::basic_istream<char, std::__1::char_traits<char> >& apputils::operator>><vvencHDRMode>(std::__1::basic_istream<char, std::__1::char_traits<char> >&, apputils::IStreamToEnum<vvencHDRMode>&) Unexecuted instantiation: std::__1::basic_istream<char, std::__1::char_traits<char> >& apputils::operator>><int>(std::__1::basic_istream<char, std::__1::char_traits<char> >&, apputils::IStreamToEnum<int>&) Unexecuted instantiation: std::__1::basic_istream<char, std::__1::char_traits<char> >& apputils::operator>><vvencHashType>(std::__1::basic_istream<char, std::__1::char_traits<char> >&, apputils::IStreamToEnum<vvencHashType>&) Unexecuted instantiation: std::__1::basic_istream<char, std::__1::char_traits<char> >& apputils::operator>><vvencSegmentMode>(std::__1::basic_istream<char, std::__1::char_traits<char> >&, apputils::IStreamToEnum<vvencSegmentMode>&) Unexecuted instantiation: std::__1::basic_istream<char, std::__1::char_traits<char> >& apputils::operator>><vvencChromaFormat>(std::__1::basic_istream<char, std::__1::char_traits<char> >&, apputils::IStreamToEnum<vvencChromaFormat>&) Unexecuted instantiation: std::__1::basic_istream<char, std::__1::char_traits<char> >& apputils::operator>><vvencCostMode>(std::__1::basic_istream<char, std::__1::char_traits<char> >&, apputils::IStreamToEnum<vvencCostMode>&) |
225 | | |
226 | | template<typename E> |
227 | | inline std::ostream& operator << ( std::ostream& os, const IStreamToEnum<E>& toEnum ) |
228 | 0 | { |
229 | 0 | for ( const auto& map : *toEnum.toMap ) |
230 | 0 | { |
231 | 0 | if ( *toEnum.dstVal == map.value ) |
232 | 0 | { |
233 | 0 | os << map.str; |
234 | 0 | return os; |
235 | 0 | } |
236 | 0 | } |
237 | | |
238 | | /* not found */ |
239 | 0 | os.setstate( std::ios::failbit ); |
240 | 0 | return os; |
241 | 0 | } Unexecuted instantiation: std::__1::basic_ostream<char, std::__1::char_traits<char> >& apputils::operator<< <vvencMsgLevel>(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, apputils::IStreamToEnum<vvencMsgLevel> const&) Unexecuted instantiation: std::__1::basic_ostream<char, std::__1::char_traits<char> >& apputils::operator<< <bool>(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, apputils::IStreamToEnum<bool> const&) Unexecuted instantiation: std::__1::basic_ostream<char, std::__1::char_traits<char> >& apputils::operator<< <signed char>(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, apputils::IStreamToEnum<signed char> const&) Unexecuted instantiation: std::__1::basic_ostream<char, std::__1::char_traits<char> >& apputils::operator<< <vvencDecodingRefreshType>(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, apputils::IStreamToEnum<vvencDecodingRefreshType> const&) Unexecuted instantiation: std::__1::basic_ostream<char, std::__1::char_traits<char> >& apputils::operator<< <vvencProfile>(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, apputils::IStreamToEnum<vvencProfile> const&) Unexecuted instantiation: std::__1::basic_ostream<char, std::__1::char_traits<char> >& apputils::operator<< <vvencLevel>(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, apputils::IStreamToEnum<vvencLevel> const&) Unexecuted instantiation: std::__1::basic_ostream<char, std::__1::char_traits<char> >& apputils::operator<< <vvencTier>(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, apputils::IStreamToEnum<vvencTier> const&) Unexecuted instantiation: std::__1::basic_ostream<char, std::__1::char_traits<char> >& apputils::operator<< <vvencHDRMode>(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, apputils::IStreamToEnum<vvencHDRMode> const&) Unexecuted instantiation: std::__1::basic_ostream<char, std::__1::char_traits<char> >& apputils::operator<< <int>(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, apputils::IStreamToEnum<int> const&) Unexecuted instantiation: std::__1::basic_ostream<char, std::__1::char_traits<char> >& apputils::operator<< <vvencHashType>(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, apputils::IStreamToEnum<vvencHashType> const&) Unexecuted instantiation: std::__1::basic_ostream<char, std::__1::char_traits<char> >& apputils::operator<< <vvencSegmentMode>(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, apputils::IStreamToEnum<vvencSegmentMode> const&) Unexecuted instantiation: std::__1::basic_ostream<char, std::__1::char_traits<char> >& apputils::operator<< <vvencChromaFormat>(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, apputils::IStreamToEnum<vvencChromaFormat> const&) Unexecuted instantiation: std::__1::basic_ostream<char, std::__1::char_traits<char> >& apputils::operator<< <vvencCostMode>(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, apputils::IStreamToEnum<vvencCostMode> const&) |
242 | | |
243 | | // ==================================================================================================================== |
244 | | // string <-> int8_t |
245 | | // ==================================================================================================================== |
246 | | |
247 | | class IStreamToInt8 |
248 | | { |
249 | | public: |
250 | | IStreamToInt8( int8_t * d ) |
251 | 0 | : dstVal ( d ) |
252 | 0 | { |
253 | 0 | } |
254 | | |
255 | | ~IStreamToInt8() |
256 | 0 | { |
257 | 0 | } |
258 | | |
259 | | friend std::ostream& operator << ( std::ostream& os, const IStreamToInt8& toInt8 ); |
260 | | |
261 | | friend std::istream& operator >> ( std::istream& in, IStreamToInt8& toInt8 ); |
262 | | |
263 | | private: |
264 | | int8_t* dstVal; |
265 | | }; |
266 | | |
267 | | inline std::istream& operator >> ( std::istream& in, IStreamToInt8& toInt8 ) |
268 | 0 | { |
269 | 0 | std::string str; |
270 | 0 | in >> str; |
271 | 0 | size_t used = 0; |
272 | 0 | int ret = std::stoi( str, &used ); |
273 | 0 | if( used != str.size() || ret < std::numeric_limits<int8_t>::min() || ret > std::numeric_limits<int8_t>::max() ) |
274 | 0 | { |
275 | 0 | in.setstate( std::ios::failbit ); |
276 | 0 | } |
277 | 0 | *toInt8.dstVal = (int8_t)ret; |
278 | 0 | return in; |
279 | 0 | } |
280 | | |
281 | | inline std::ostream& operator << ( std::ostream& os, const IStreamToInt8& toInt8 ) |
282 | 0 | { |
283 | 0 | os << (int)(*toInt8.dstVal); |
284 | 0 | return os; |
285 | 0 | } |
286 | | |
287 | | // ==================================================================================================================== |
288 | | // string (decimal number) <-> uint8_t fixed point value |
289 | | // ==================================================================================================================== |
290 | | |
291 | | // Lets the apps take a decimal value for a config field that stores it with a few fractional bits, |
292 | | // so the field needs only one byte of the config struct. |
293 | | class IStreamToFixedPointU8 |
294 | | { |
295 | | public: |
296 | | IStreamToFixedPointU8( uint8_t* d, int fracBits ) |
297 | 0 | : dstVal ( d ) |
298 | 0 | , fracBits( fracBits ) |
299 | 0 | { |
300 | 0 | } |
301 | | |
302 | | friend std::ostream& operator << ( std::ostream& os, const IStreamToFixedPointU8& toFixed ); |
303 | | |
304 | | friend std::istream& operator >> ( std::istream& in, IStreamToFixedPointU8& toFixed ); |
305 | | |
306 | | private: |
307 | | uint8_t* dstVal; |
308 | | int fracBits; |
309 | | }; |
310 | | |
311 | | inline std::istream& operator >> ( std::istream& in, IStreamToFixedPointU8& toFixed ) |
312 | 0 | { |
313 | 0 | std::string str; |
314 | 0 | in >> str; |
315 | |
|
316 | 0 | size_t parsedChars = 0; |
317 | 0 | double value = 0.0; |
318 | 0 | try |
319 | 0 | { |
320 | 0 | value = std::stod( str, &parsedChars ); |
321 | 0 | } |
322 | 0 | catch( ... ) |
323 | 0 | { |
324 | 0 | parsedChars = 0; |
325 | 0 | } |
326 | |
|
327 | 0 | double fixed = ( value * ( 1 << toFixed.fracBits ) + 0.5 ); |
328 | 0 | if( fixed > 255.0 && fixed <= 256.5 ) |
329 | 0 | { |
330 | 0 | fixed = 255.0; |
331 | 0 | } |
332 | | // written so that NaN fails as well |
333 | 0 | if( parsedChars == 0 || parsedChars != str.size() || !( value >= 0.0 && fixed < 256 ) ) |
334 | 0 | { |
335 | 0 | in.setstate( std::ios::failbit ); |
336 | 0 | return in; |
337 | 0 | } |
338 | 0 | *toFixed.dstVal = (uint8_t)fixed; |
339 | 0 | return in; |
340 | 0 | } |
341 | | |
342 | | inline std::ostream& operator << ( std::ostream& os, const IStreamToFixedPointU8& toFixed ) |
343 | 0 | { |
344 | 0 | os << *toFixed.dstVal / double( 1 << toFixed.fracBits ); |
345 | 0 | return os; |
346 | 0 | } |
347 | | |
348 | | // ==================================================================================================================== |
349 | | // string <-> QP with an optional fractional part |
350 | | // ==================================================================================================================== |
351 | | |
352 | | // Reads a QP such as "27" or "27.5" into its integer part (m_QP) and its fractional part in 1/256 steps (m_QPFraction). |
353 | | class IStreamToQP |
354 | | { |
355 | | public: |
356 | | IStreamToQP( int* qp, uint8_t* qpFraction ) |
357 | 0 | : dstQP ( qp ) |
358 | 0 | , dstFraction( qpFraction ) |
359 | 0 | { |
360 | 0 | } |
361 | | |
362 | | ~IStreamToQP() |
363 | 0 | { |
364 | 0 | } |
365 | | |
366 | | friend std::ostream& operator << ( std::ostream& os, const IStreamToQP& toQP ); |
367 | | |
368 | | friend std::istream& operator >> ( std::istream& in, IStreamToQP& toQP ); |
369 | | |
370 | | private: |
371 | | int* dstQP; |
372 | | uint8_t* dstFraction; |
373 | | }; |
374 | | |
375 | | inline std::istream& operator >> ( std::istream& in, IStreamToQP& toQP ) |
376 | 0 | { |
377 | 0 | std::string str; |
378 | 0 | in >> str; |
379 | |
|
380 | 0 | size_t parsedChars = 0; |
381 | 0 | double value = 0.0; |
382 | 0 | try |
383 | 0 | { |
384 | 0 | value = std::stod( str, &parsedChars ); |
385 | 0 | } |
386 | 0 | catch( ... ) |
387 | 0 | { |
388 | 0 | parsedChars = 0; |
389 | 0 | } |
390 | |
|
391 | 0 | const double intPart = std::floor( value ); |
392 | | // A negative QP with a fraction would turn into an integer part of -1 or less, which collides with |
393 | | // VVENC_AUTO_QP, so fractions are only accepted for QPs of 0 and above. |
394 | 0 | const bool isFractional = value != intPart; |
395 | 0 | if( parsedChars == 0 || parsedChars != str.size() || std::abs( value ) > 1000.0 || ( isFractional && value < 0.0 ) ) |
396 | 0 | { |
397 | 0 | in.setstate( std::ios::failbit ); |
398 | 0 | return in; |
399 | 0 | } |
400 | | |
401 | | // The fraction is rounded to the nearest 1/256 step; a fraction that rounds up to a whole QP moves to the next integer. |
402 | 0 | int qp = (int) intPart; |
403 | 0 | int fractionSteps = (int) std::floor( ( value - intPart ) * 256.0 + 0.5 ); |
404 | 0 | if( fractionSteps == 256 ) |
405 | 0 | { |
406 | 0 | qp++; |
407 | 0 | fractionSteps = 0; |
408 | 0 | } |
409 | 0 | *toQP.dstQP = qp; |
410 | 0 | *toQP.dstFraction = (uint8_t) fractionSteps; |
411 | 0 | return in; |
412 | 0 | } |
413 | | |
414 | | inline std::ostream& operator << ( std::ostream& os, const IStreamToQP& toQP ) |
415 | 0 | { |
416 | 0 | os << *toQP.dstQP + *toQP.dstFraction / 256.0; |
417 | 0 | return os; |
418 | 0 | } |
419 | | |
420 | | // ==================================================================================================================== |
421 | | // string <-> function |
422 | | // ==================================================================================================================== |
423 | | |
424 | | class VVEncAppCfg; |
425 | | typedef void (*setParamFunc) (VVEncAppCfg*, vvenc_config*, int); |
426 | | |
427 | | template<typename E> |
428 | | class IStreamToFunc |
429 | | { |
430 | | public: |
431 | | IStreamToFunc( setParamFunc func, VVEncAppCfg* appCfg, vvenc_config* encCfg, const std::vector<SVPair<E>>* m, const E _default ) |
432 | 0 | : mfunc( func ) |
433 | 0 | , mappCfg ( appCfg ) |
434 | 0 | , mencCfg( encCfg ) |
435 | 0 | , toMap( m ) |
436 | 0 | , dstVal( _default ) |
437 | 0 | { |
438 | 0 | } Unexecuted instantiation: apputils::IStreamToFunc<vvencPresetMode>::IStreamToFunc(void (*)(apputils::VVEncAppCfg*, vvenc_config*, int), apputils::VVEncAppCfg*, vvenc_config*, std::__1::vector<apputils::SVPair<vvencPresetMode>, std::__1::allocator<apputils::SVPair<vvencPresetMode> > > const*, vvencPresetMode) Unexecuted instantiation: apputils::IStreamToFunc<int>::IStreamToFunc(void (*)(apputils::VVEncAppCfg*, vvenc_config*, int), apputils::VVEncAppCfg*, vvenc_config*, std::__1::vector<apputils::SVPair<int>, std::__1::allocator<apputils::SVPair<int> > > const*, int) Unexecuted instantiation: apputils::IStreamToFunc<apputils::BitDepthAndColorSpace>::IStreamToFunc(void (*)(apputils::VVEncAppCfg*, vvenc_config*, int), apputils::VVEncAppCfg*, vvenc_config*, std::__1::vector<apputils::SVPair<apputils::BitDepthAndColorSpace>, std::__1::allocator<apputils::SVPair<apputils::BitDepthAndColorSpace> > > const*, apputils::BitDepthAndColorSpace) |
439 | | |
440 | | ~IStreamToFunc() |
441 | 0 | { |
442 | 0 | } Unexecuted instantiation: apputils::IStreamToFunc<int>::~IStreamToFunc() Unexecuted instantiation: apputils::IStreamToFunc<apputils::BitDepthAndColorSpace>::~IStreamToFunc() Unexecuted instantiation: apputils::IStreamToFunc<vvencPresetMode>::~IStreamToFunc() |
443 | | |
444 | | template<typename F> |
445 | | friend std::istream& operator >> ( std::istream& in, IStreamToFunc<F>& toEnum ); |
446 | | |
447 | | template<typename F> |
448 | | friend std::ostream& operator << ( std::ostream& in, const IStreamToFunc<F>& toEnum ); |
449 | | |
450 | | private: |
451 | | setParamFunc mfunc; |
452 | | VVEncAppCfg* mappCfg; |
453 | | vvenc_config* mencCfg; |
454 | | const std::vector<SVPair<E>>* toMap; |
455 | | E dstVal; |
456 | | }; |
457 | | |
458 | | template<typename E> |
459 | | inline std::istream& operator >> ( std::istream& in, IStreamToFunc<E>& toEnum ) |
460 | 0 | { |
461 | 0 | std::string str; |
462 | 0 | in >> str; |
463 | |
|
464 | 0 | for ( const auto& map : *toEnum.toMap ) |
465 | 0 | { |
466 | 0 | if ( str == map.str ) |
467 | 0 | { |
468 | 0 | toEnum.dstVal = map.value; |
469 | 0 | toEnum.mfunc( toEnum.mappCfg, toEnum.mencCfg, map.value); |
470 | 0 | return in; |
471 | 0 | } |
472 | 0 | } |
473 | | |
474 | | /* not found */ |
475 | 0 | in.setstate( std::ios::failbit ); |
476 | 0 | return in; |
477 | 0 | } Unexecuted instantiation: std::__1::basic_istream<char, std::__1::char_traits<char> >& apputils::operator>><apputils::BitDepthAndColorSpace>(std::__1::basic_istream<char, std::__1::char_traits<char> >&, apputils::IStreamToFunc<apputils::BitDepthAndColorSpace>&) Unexecuted instantiation: std::__1::basic_istream<char, std::__1::char_traits<char> >& apputils::operator>><vvencPresetMode>(std::__1::basic_istream<char, std::__1::char_traits<char> >&, apputils::IStreamToFunc<vvencPresetMode>&) Unexecuted instantiation: std::__1::basic_istream<char, std::__1::char_traits<char> >& apputils::operator>><int>(std::__1::basic_istream<char, std::__1::char_traits<char> >&, apputils::IStreamToFunc<int>&) |
478 | | |
479 | | template<typename F> |
480 | | inline std::ostream& operator << ( std::ostream& os, const IStreamToFunc<F>& toEnum ) |
481 | 0 | { |
482 | 0 | for ( const auto& map : *toEnum.toMap ) |
483 | 0 | { |
484 | 0 | if ( toEnum.dstVal == map.value ) |
485 | 0 | { |
486 | 0 | os << map.str; |
487 | 0 | return os; |
488 | 0 | } |
489 | 0 | } |
490 | | |
491 | | /* not found */ |
492 | 0 | os.setstate( std::ios::failbit ); |
493 | 0 | return os; |
494 | 0 | } Unexecuted instantiation: std::__1::basic_ostream<char, std::__1::char_traits<char> >& apputils::operator<< <apputils::BitDepthAndColorSpace>(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, apputils::IStreamToFunc<apputils::BitDepthAndColorSpace> const&) Unexecuted instantiation: std::__1::basic_ostream<char, std::__1::char_traits<char> >& apputils::operator<< <vvencPresetMode>(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, apputils::IStreamToFunc<vvencPresetMode> const&) Unexecuted instantiation: std::__1::basic_ostream<char, std::__1::char_traits<char> >& apputils::operator<< <int>(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, apputils::IStreamToFunc<int> const&) |
495 | | |
496 | | // ==================================================================================================================== |
497 | | // string -> list |
498 | | // ==================================================================================================================== |
499 | | |
500 | | template<typename T> |
501 | | class IStreamToVec |
502 | | { |
503 | | public: |
504 | | IStreamToVec( std::vector<T>* v ) |
505 | | : valVec( v ) |
506 | | { |
507 | | } |
508 | | |
509 | | ~IStreamToVec() |
510 | | { |
511 | | } |
512 | | |
513 | | template<typename F> |
514 | | friend std::istream& operator >> ( std::istream& in, IStreamToVec<F>& toVec ); |
515 | | |
516 | | template<typename F> |
517 | | friend std::ostream& operator << ( std::ostream& in, const IStreamToVec<F>& toVec ); |
518 | | |
519 | | private: |
520 | | std::vector<T>* valVec; |
521 | | }; |
522 | | |
523 | | template<typename T> |
524 | | inline std::istream& operator >> ( std::istream& in, IStreamToVec<T>& toVec ) |
525 | | { |
526 | | std::vector<T>* valVec = toVec.valVec; |
527 | | valVec->clear(); |
528 | | |
529 | | bool fail = false; |
530 | | // split into multiple lines if any |
531 | | while ( ! in.eof() ) |
532 | | { |
533 | | std::string line; |
534 | | std::getline( in, line ); |
535 | | |
536 | | if( line == "[]" || line == "empty" ) |
537 | | { |
538 | | return in; // forcing empty entry |
539 | | } |
540 | | else |
541 | | { |
542 | | // treat all whitespaces and commas as valid separators |
543 | | replace_if( line.begin(), line.end(), []( int c ){ return isspace( c ) || c == ','; }, ' ' ); |
544 | | std::stringstream tokenStream( line ); |
545 | | std::string token; |
546 | | // split into multiple tokens if any |
547 | | while( std::getline( tokenStream, token, ' ' ) ) |
548 | | { |
549 | | if ( ! token.length() ) |
550 | | continue; |
551 | | // convert to value |
552 | | T val; |
553 | | fail |= !readWholeToken( token, val ); |
554 | | valVec->push_back( val ); |
555 | | } |
556 | | } |
557 | | } |
558 | | |
559 | | if ( fail || (! valVec->size() ) ) |
560 | | { |
561 | | in.setstate( std::ios::failbit ); |
562 | | } |
563 | | |
564 | | return in; |
565 | | } |
566 | | |
567 | | template<typename T> |
568 | | inline std::ostream& operator << ( std::ostream& os, const IStreamToVec<T>& toVec ) |
569 | | { |
570 | | if( (*(toVec.valVec)).empty() ) |
571 | | { |
572 | | os << "[]"; |
573 | | return os; |
574 | | } |
575 | | |
576 | | bool bfirst = true; |
577 | | for( auto& e : (*(toVec.valVec))) |
578 | | { |
579 | | if( bfirst ) |
580 | | { |
581 | | bfirst = false; |
582 | | } |
583 | | else |
584 | | { |
585 | | os << ","; |
586 | | } |
587 | | os << e; |
588 | | } |
589 | | |
590 | | return os; |
591 | | } |
592 | | |
593 | | |
594 | | // ==================================================================================================================== |
595 | | // string -> array |
596 | | // ==================================================================================================================== |
597 | | |
598 | | template<typename T> |
599 | | class IStreamToArr |
600 | | { |
601 | | public: |
602 | | IStreamToArr( T* v, size_t maxSize ) |
603 | 0 | : _valVec ( v ) |
604 | 0 | , _maxSize ( maxSize ) |
605 | 0 | , _curSize ( nullptr ) |
606 | 0 | { |
607 | 0 | } Unexecuted instantiation: apputils::IStreamToArr<int>::IStreamToArr(int*, unsigned long) Unexecuted instantiation: apputils::IStreamToArr<double>::IStreamToArr(double*, unsigned long) Unexecuted instantiation: apputils::IStreamToArr<unsigned int>::IStreamToArr(unsigned int*, unsigned long) Unexecuted instantiation: apputils::IStreamToArr<char>::IStreamToArr(char*, unsigned long) |
608 | | |
609 | | IStreamToArr( T* v, size_t maxSize, int* curSize ) |
610 | 0 | : _valVec ( v ) |
611 | 0 | , _maxSize ( maxSize ) |
612 | 0 | , _curSize ( curSize ) |
613 | 0 | { |
614 | 0 | } Unexecuted instantiation: apputils::IStreamToArr<int>::IStreamToArr(int*, unsigned long, int*) Unexecuted instantiation: apputils::IStreamToArr<double>::IStreamToArr(double*, unsigned long, int*) |
615 | | |
616 | | ~IStreamToArr() |
617 | 0 | { |
618 | 0 | } Unexecuted instantiation: apputils::IStreamToArr<char>::~IStreamToArr() Unexecuted instantiation: apputils::IStreamToArr<unsigned int>::~IStreamToArr() Unexecuted instantiation: apputils::IStreamToArr<double>::~IStreamToArr() Unexecuted instantiation: apputils::IStreamToArr<int>::~IStreamToArr() |
619 | | |
620 | | template<typename F> |
621 | | friend std::istream& operator >> ( std::istream& in, IStreamToArr<F>& toArr ); |
622 | | |
623 | | template<typename F> |
624 | | friend std::ostream& operator << ( std::ostream& in, const IStreamToArr<F>& toArr ); |
625 | | |
626 | | private: |
627 | | T* _valVec; |
628 | | size_t _maxSize; |
629 | | int* _curSize; |
630 | | }; |
631 | | |
632 | | template<typename T> |
633 | | inline std::istream& operator >> ( std::istream& in, IStreamToArr<T>& toArr ) |
634 | 0 | { |
635 | 0 | for( size_t i = 0; i < toArr._maxSize; i++ ) memset(&toArr._valVec[i],0, sizeof(T)); |
636 | |
|
637 | 0 | bool fail = false; |
638 | 0 | size_t pos = 0; |
639 | 0 | if ( toArr._curSize ) *toArr._curSize = 0; |
640 | | // split into multiple lines if any |
641 | 0 | while ( ! in.eof() ) |
642 | 0 | { |
643 | 0 | std::string line; |
644 | 0 | std::getline( in, line ); |
645 | |
|
646 | 0 | if( line == "[]" || line == "empty" ) |
647 | 0 | { |
648 | 0 | return in; // forcing empty entry |
649 | 0 | } |
650 | 0 | else |
651 | 0 | { |
652 | | // treat all whitespaces and commas as valid separators |
653 | 0 | replace_if( line.begin(), line.end(), []( int c ){ return isspace( c ) || c == ','; }, ' ' );Unexecuted instantiation: apputils::operator>><double>(std::__1::basic_istream<char, std::__1::char_traits<char> >&, apputils::IStreamToArr<double>&)::{lambda(int)#1}::operator()(int) constUnexecuted instantiation: apputils::operator>><int>(std::__1::basic_istream<char, std::__1::char_traits<char> >&, apputils::IStreamToArr<int>&)::{lambda(int)#1}::operator()(int) constUnexecuted instantiation: apputils::operator>><unsigned int>(std::__1::basic_istream<char, std::__1::char_traits<char> >&, apputils::IStreamToArr<unsigned int>&)::{lambda(int)#1}::operator()(int) const |
654 | 0 | std::stringstream tokenStream( line ); |
655 | 0 | std::string token; |
656 | | // split into multiple tokens if any |
657 | 0 | while( std::getline( tokenStream, token, ' ' ) ) |
658 | 0 | { |
659 | 0 | if ( ! token.length() ) |
660 | 0 | continue; |
661 | | // convert to value |
662 | 0 | T val; |
663 | 0 | fail |= !readWholeToken( token, val ); |
664 | |
|
665 | 0 | if ( pos < toArr._maxSize ) |
666 | 0 | { |
667 | 0 | toArr._valVec[pos] = val; |
668 | 0 | } |
669 | 0 | pos++; |
670 | 0 | } |
671 | 0 | } |
672 | 0 | } |
673 | | |
674 | 0 | if ( fail || ( 0 == pos ) || (pos > toArr._maxSize) ) |
675 | 0 | { |
676 | 0 | in.setstate( std::ios::failbit ); |
677 | 0 | } |
678 | |
|
679 | 0 | if ( toArr._curSize ) *toArr._curSize = static_cast<int>( std::min<size_t>( pos, toArr._maxSize ) ); |
680 | |
|
681 | 0 | return in; |
682 | 0 | } Unexecuted instantiation: std::__1::basic_istream<char, std::__1::char_traits<char> >& apputils::operator>><double>(std::__1::basic_istream<char, std::__1::char_traits<char> >&, apputils::IStreamToArr<double>&) Unexecuted instantiation: std::__1::basic_istream<char, std::__1::char_traits<char> >& apputils::operator>><int>(std::__1::basic_istream<char, std::__1::char_traits<char> >&, apputils::IStreamToArr<int>&) Unexecuted instantiation: std::__1::basic_istream<char, std::__1::char_traits<char> >& apputils::operator>><unsigned int>(std::__1::basic_istream<char, std::__1::char_traits<char> >&, apputils::IStreamToArr<unsigned int>&) |
683 | | |
684 | | template<> |
685 | | inline std::istream& operator >> ( std::istream& in, IStreamToArr<char>& toArr ) |
686 | 0 | { |
687 | 0 | for( size_t i = 0; i < toArr._maxSize; i++ ) memset(&toArr._valVec[i],0, sizeof(char)); |
688 | |
|
689 | 0 | bool fail = false; |
690 | 0 | size_t size = 0; |
691 | | // split into multiple lines if any |
692 | 0 | while ( ! in.eof() ) |
693 | 0 | { |
694 | 0 | std::string line; |
695 | 0 | std::getline( in, line ); |
696 | |
|
697 | 0 | if( line == "" || line == "\"\"" || line == "[]" || line == "empty" || line == "''" ) |
698 | 0 | { |
699 | 0 | return in; // forcing empty entry |
700 | 0 | } |
701 | 0 | else |
702 | 0 | { |
703 | 0 | if( line.size() >= toArr._maxSize ) |
704 | 0 | { |
705 | 0 | line.copy( toArr._valVec , toArr._maxSize-1 ); |
706 | 0 | toArr._valVec[toArr._maxSize-1] = '\0'; |
707 | 0 | fail = true; |
708 | 0 | } |
709 | 0 | else |
710 | 0 | { |
711 | 0 | line.copy( toArr._valVec , line.size()+1 ); |
712 | 0 | toArr._valVec[line.size()] = '\0'; |
713 | 0 | size = line.size(); |
714 | 0 | } |
715 | 0 | } |
716 | 0 | } |
717 | | |
718 | 0 | if ( fail || ( 0 == size ) ) |
719 | 0 | { |
720 | 0 | in.setstate( std::ios::failbit ); |
721 | 0 | } |
722 | |
|
723 | 0 | return in; |
724 | 0 | } |
725 | | |
726 | | template<typename T> |
727 | | inline std::ostream& operator << ( std::ostream& os, const IStreamToArr<T>& toArr ) |
728 | 0 | { |
729 | 0 | int size=0; |
730 | 0 | for ( size_t i = 0; i < toArr._maxSize; i++ ) |
731 | 0 | { |
732 | 0 | if( toArr._valVec[i] != 0 ) size++; |
733 | 0 | else break; |
734 | 0 | } |
735 | |
|
736 | 0 | if( 0 == size ) |
737 | 0 | { |
738 | 0 | os << "[]"; |
739 | 0 | return os; |
740 | 0 | } |
741 | | |
742 | 0 | bool bfirst = true; |
743 | 0 | for ( int i = 0; i < size; i++ ) |
744 | 0 | { |
745 | 0 | if( bfirst ) |
746 | 0 | { |
747 | 0 | bfirst = false; |
748 | 0 | } |
749 | 0 | else |
750 | 0 | { |
751 | 0 | os << ","; |
752 | 0 | } |
753 | 0 | os << toArr._valVec[i]; |
754 | 0 | } |
755 | |
|
756 | 0 | return os; |
757 | 0 | } Unexecuted instantiation: std::__1::basic_ostream<char, std::__1::char_traits<char> >& apputils::operator<< <double>(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, apputils::IStreamToArr<double> const&) Unexecuted instantiation: std::__1::basic_ostream<char, std::__1::char_traits<char> >& apputils::operator<< <int>(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, apputils::IStreamToArr<int> const&) Unexecuted instantiation: std::__1::basic_ostream<char, std::__1::char_traits<char> >& apputils::operator<< <unsigned int>(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, apputils::IStreamToArr<unsigned int> const&) |
758 | | |
759 | | template<> |
760 | | inline std::ostream& operator << ( std::ostream& os, const IStreamToArr<char>& toArr ) |
761 | 0 | { |
762 | 0 | int size=0; |
763 | 0 | for ( size_t i = 0; i < toArr._maxSize; i++ ) |
764 | 0 | { |
765 | 0 | if( toArr._valVec[i] != '\0' ) size++; |
766 | 0 | else break; |
767 | 0 | } |
768 | |
|
769 | 0 | if( 0 == size ) |
770 | 0 | { |
771 | 0 | os << "''"; |
772 | 0 | return os; |
773 | 0 | } |
774 | | |
775 | 0 | for ( int i = 0; i < size; i++ ) |
776 | 0 | { |
777 | 0 | os << toArr._valVec[i]; |
778 | 0 | } |
779 | |
|
780 | 0 | return os; |
781 | 0 | } |
782 | | |
783 | | |
784 | | // ==================================================================================================================== |
785 | | // string -> abbreviated value |
786 | | // ==================================================================================================================== |
787 | | |
788 | | // T: value type, A abbreviation value type |
789 | | template<typename T, typename A> |
790 | | class IStreamToAbbr |
791 | | { |
792 | | public: |
793 | | IStreamToAbbr( T* v, const std::vector<SVPair<A>>* m ) |
794 | 0 | : dstVal ( v ) |
795 | 0 | , toMap ( m ) |
796 | 0 | { |
797 | 0 | } |
798 | | |
799 | | ~IStreamToAbbr() |
800 | 0 | { |
801 | 0 | } |
802 | | |
803 | | template<typename F, typename G> |
804 | | friend std::istream& operator >> ( std::istream& in, IStreamToAbbr<F,G>& toValue ); |
805 | | |
806 | | template<typename F, typename G> |
807 | | friend std::ostream& operator << ( std::ostream& in, const IStreamToAbbr<F,G>& toValue ); |
808 | | |
809 | | private: |
810 | | T* dstVal; |
811 | | const std::vector<SVPair<A>>* toMap; |
812 | | }; |
813 | | |
814 | | template<typename T, typename A> |
815 | | inline std::istream& operator >> ( std::istream& in, IStreamToAbbr<T,A>& toValue ) |
816 | 0 | { |
817 | 0 | std::string str; |
818 | 0 | in >> str; |
819 | | |
820 | | // search map for a used abbreviation |
821 | 0 | for ( const auto& map : *toValue.toMap ) |
822 | 0 | { |
823 | 0 | std::string key(map.str); |
824 | 0 | std::size_t n = str.rfind( key ); |
825 | 0 | if( n != std::string::npos && n + key.length() == str.size() ) // a unit only as the suffix: "1M5" is not 1.5M |
826 | 0 | { |
827 | 0 | str.erase(n, key.length()); // remove the scaling unit, e.g. 1.5M -> 1.5 |
828 | 0 | replace_if( str.begin(), str.end(), []( int c ){ return c == ','; }, '.' ); // use correct comma syntax for double representaion |
829 | |
|
830 | 0 | bool isNumber = strspn( str.c_str(), "-.0123456789" ) == str.size(); // check if valid double value |
831 | 0 | if( !isNumber) |
832 | 0 | { |
833 | 0 | in.setstate( std::ios::failbit ); |
834 | 0 | return in; |
835 | 0 | } |
836 | | |
837 | 0 | double value = strtod(str.c_str(), NULL); // convert input string to double |
838 | 0 | value *= map.value; // scale depending on given abbreviation/scaling factor |
839 | 0 | double roundDir = value < 0 ? -1 : ( value > 0 ? 1 : 0 ); |
840 | 0 | double roundOffset = std::is_floating_point<T>::value ? 0.0 : 0.5; |
841 | 0 | value += roundDir * roundOffset; |
842 | 0 | *toValue.dstVal = ( T ) value; |
843 | 0 | return in; |
844 | 0 | } |
845 | 0 | } |
846 | | |
847 | | // read value in original format |
848 | 0 | std::string::size_type posAfter; |
849 | 0 | *toValue.dstVal = std::stoi( str, &posAfter ); |
850 | |
|
851 | 0 | if( posAfter && !str.substr(posAfter).empty() ) // check if value is valid int |
852 | 0 | { |
853 | 0 | in.setstate( std::ios::failbit ); |
854 | 0 | } |
855 | |
|
856 | 0 | return in; |
857 | 0 | } |
858 | | |
859 | | template<typename T, typename A> |
860 | | inline std::ostream& operator << ( std::ostream& os, const IStreamToAbbr<T,A>& toValue ) |
861 | 0 | { |
862 | 0 | os << *toValue.dstVal; |
863 | 0 | return os; |
864 | 0 | } |
865 | | |
866 | | |
867 | | // ==================================================================================================================== |
868 | | // vvencGOPEntry |
869 | | // ==================================================================================================================== |
870 | | |
871 | | |
872 | | inline std::ostream& operator<< ( std::ostream& os, const vvencGOPEntry& entry ) |
873 | 0 | { |
874 | 0 | os << entry.m_sliceType; |
875 | 0 | os << entry.m_POC; |
876 | 0 | os << entry.m_QPOffset; |
877 | 0 | os << entry.m_QPOffsetModelOffset; |
878 | 0 | os << entry.m_QPOffsetModelScale; |
879 | 0 | os << entry.m_CbQPoffset; |
880 | 0 | os << entry.m_CrQPoffset; |
881 | 0 | os << entry.m_QPFactor; |
882 | 0 | os << entry.m_tcOffsetDiv2; |
883 | 0 | os << entry.m_betaOffsetDiv2; |
884 | 0 | os << entry.m_cfgUnused1; |
885 | 0 | os << entry.m_cfgUnused2; |
886 | 0 | os << entry.m_cfgUnused3; |
887 | 0 | os << entry.m_cfgUnused4; |
888 | 0 | os << entry.m_temporalId; |
889 | |
|
890 | 0 | for( int l = 0; l < 2; l++) |
891 | 0 | { |
892 | 0 | os << entry.m_numRefPicsActive[l]; |
893 | 0 | os << entry.m_numRefPics[l]; |
894 | 0 | for ( int i = 0; i < entry.m_numRefPics[l]; i++ ) |
895 | 0 | { |
896 | 0 | os << entry.m_deltaRefPics[l][i]; |
897 | 0 | } |
898 | 0 | } |
899 | |
|
900 | 0 | return os; |
901 | 0 | } |
902 | | |
903 | | inline std::istream& operator>> ( std::istream& in, vvencGOPEntry& entry ) |
904 | 0 | { |
905 | 0 | in >> entry.m_sliceType; |
906 | 0 | in >> entry.m_POC; |
907 | 0 | in >> entry.m_QPOffset; |
908 | 0 | in >> entry.m_QPOffsetModelOffset; |
909 | 0 | in >> entry.m_QPOffsetModelScale; |
910 | 0 | in >> entry.m_CbQPoffset; |
911 | 0 | in >> entry.m_CrQPoffset; |
912 | 0 | in >> entry.m_QPFactor; |
913 | 0 | in >> entry.m_tcOffsetDiv2; |
914 | 0 | in >> entry.m_betaOffsetDiv2; |
915 | 0 | in >> entry.m_cfgUnused1; |
916 | 0 | in >> entry.m_cfgUnused2; |
917 | 0 | in >> entry.m_cfgUnused3; |
918 | 0 | in >> entry.m_cfgUnused4; |
919 | 0 | in >> entry.m_temporalId; |
920 | |
|
921 | 0 | for( int l = 0; l < 2; l++) |
922 | 0 | { |
923 | 0 | in >> entry.m_numRefPicsActive[l]; |
924 | 0 | in >> entry.m_numRefPics[l]; |
925 | 0 | for ( int i = 0; i < entry.m_numRefPics[l]; i++ ) |
926 | 0 | { |
927 | 0 | in >> entry.m_deltaRefPics[l][i]; |
928 | 0 | } |
929 | 0 | } |
930 | |
|
931 | 0 | return in; |
932 | 0 | } |
933 | | |
934 | | |
935 | | } // namespace |
936 | | |
937 | | //! \} |
938 | | |