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