Line data Source code
1 : /** \file appConfigurator.cpp
2 : * \author Jared R. Males
3 : * \brief Implementation of An application configuration manager
4 : *
5 : * \ingroup mxApp_files
6 : *
7 : */
8 :
9 : //***********************************************************************//
10 : // Copyright 2021 Jared R. Males (jaredmales@gmail.com)
11 : //
12 : // This file is part of mxlib.
13 : //
14 : // mxlib is free software: you can redistribute it and/or modify
15 : // it under the terms of the GNU General Public License as published by
16 : // the Free Software Foundation, either version 3 of the License, or
17 : // (at your option) any later version.
18 : //
19 : // mxlib is distributed in the hope that it will be useful,
20 : // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 : // GNU General Public License for more details.
23 : //
24 : // You should have received a copy of the GNU General Public License
25 : // along with mxlib. If not, see <http://www.gnu.org/licenses/>.
26 : //***********************************************************************//
27 :
28 : #include "app/appConfigurator.hpp"
29 :
30 : namespace mx
31 : {
32 : namespace app
33 : {
34 :
35 3 : void appConfigurator::clear()
36 : {
37 3 : m_targets.clear();
38 3 : clOnlyTargets.clear();
39 3 : nonOptions.clear();
40 3 : m_unusedConfigs.clear();
41 3 : }
42 :
43 774 : void appConfigurator::add( const configTarget &tgt )
44 : {
45 :
46 : // First check for duplicate name and command line only
47 774 : if( m_targets.count( tgt.name ) > 0 && tgt.section == "" && tgt.keyword == "" )
48 : {
49 1 : clOnlyTargets.push_back( tgt );
50 1 : clOnlyTargets.back().orderAdded = nAdded;
51 : }
52 : else
53 : {
54 773 : std::pair<targetIterator, bool> res = m_targets.insert( { tgt.name, tgt } );
55 773 : res.first->second.orderAdded = nAdded;
56 : }
57 :
58 774 : ++nAdded;
59 774 : }
60 :
61 774 : void appConfigurator::add( const std::string &n,
62 : const std::string &so,
63 : const std::string &lo,
64 : int clt,
65 : const std::string &s,
66 : const std::string &kw,
67 : bool isReq,
68 : const std::string &ht,
69 : const std::string &he )
70 : {
71 774 : add( configTarget( n, so, lo, clt, s, kw, isReq, ht, he ) );
72 774 : }
73 :
74 24 : void appConfigurator::parseCommandLine( int argc, char **argv, const std::string &oneTarget )
75 : {
76 24 : if( argc == 0 )
77 0 : return;
78 :
79 24 : clOptions clOpts;
80 :
81 : // First load the options into the clOptions parser
82 24 : targetIterator it;
83 122 : for( it = m_targets.begin(); it != m_targets.end(); ++it )
84 : {
85 98 : if( it->second.shortOpt == "" && it->second.longOpt == "" )
86 0 : continue; // No command line opts specified.
87 :
88 98 : clOpts.add( it->second.name, it->second.shortOpt.c_str(), it->second.longOpt.c_str(), it->second.clType );
89 : }
90 :
91 : // Then load the command-line-only options.
92 24 : clOnlyTargetIterator cloit;
93 24 : for( cloit = clOnlyTargets.begin(); cloit != clOnlyTargets.end(); ++cloit )
94 : {
95 0 : if( cloit->shortOpt == "" && cloit->longOpt == "" )
96 0 : continue; // Nothing to add?
97 :
98 0 : clOpts.add( cloit->name, cloit->shortOpt.c_str(), cloit->longOpt.c_str(), cloit->clType );
99 : }
100 :
101 : // Now we parse
102 24 : clOpts.parse( argc, argv, &nonOptions );
103 :
104 24 : if( clOpts.numUnknown() > 0 )
105 : {
106 2 : std::vector<std::string> unk;
107 2 : clOpts.unknown( unk );
108 :
109 4 : for( size_t n = 0; n < unk.size(); ++n )
110 : {
111 : // Insert or update existing
112 2 : m_unusedConfigs[unk[n]].name = unk[n];
113 2 : if( m_sources )
114 6 : m_unusedConfigs[unk[n]].sources.push_back( "command line" );
115 2 : m_unusedConfigs[unk[n]].set = true;
116 : }
117 2 : }
118 :
119 : // If nothing more to do, get out
120 24 : if( clOpts.nOpts == 0 )
121 : {
122 0 : return;
123 : }
124 : // And then load the results in the config target map.
125 122 : for( it = m_targets.begin(); it != m_targets.end(); ++it )
126 : {
127 98 : if( oneTarget != "" && it->second.name != oneTarget )
128 27 : continue;
129 :
130 71 : if( clOpts.optSet( it->second.name ) )
131 : {
132 19 : std::vector<std::string> args;
133 :
134 19 : clOpts.getAll( args, it->second.name );
135 :
136 38 : it->second.values.insert( it->second.values.end(), args.begin(), args.end() );
137 19 : if( m_sources )
138 : {
139 6 : for( size_t n = 0; n < args.size(); ++n )
140 9 : it->second.sources.push_back( "command line" );
141 : }
142 :
143 19 : it->second.verbosity = clOpts.count( it->second.name );
144 19 : it->second.set = true;
145 19 : }
146 : }
147 24 : }
148 :
149 60 : int appConfigurator::readConfig( const std::string &fname, bool reportFileNotFound )
150 : {
151 : // Handle empty string quietly
152 60 : if( fname == "" )
153 22 : return 0;
154 :
155 38 : iniFile iF;
156 :
157 : ///\todo update error handling to include >0 (line numer of parse error) and -2 memory allocation error.
158 38 : int prv = detail::appConfiguratorParser ? detail::appConfiguratorParser( iF, fname ) : iF.parse( fname );
159 :
160 38 : if( prv == -1 )
161 : {
162 3 : if( !reportFileNotFound )
163 1 : return -1;
164 :
165 2 : internal::mxlib_error_report( error_t::filenotfound, "The file " + fname + " was not found" );
166 2 : return -1;
167 : }
168 :
169 35 : if( prv == -2 )
170 : {
171 2 : internal::mxlib_error_report( error_t::allocerr, "Memory allocation error in config file parser" );
172 1 : return -1;
173 : }
174 :
175 34 : if( prv > 0 )
176 : {
177 1 : internal::mxlib_error_report( error_t::parseerr,
178 2 : "Parsing error in " + fname + " at line " + std::to_string( prv ) );
179 1 : return -1;
180 : }
181 :
182 33 : targetIterator it;
183 :
184 640 : for( it = m_targets.begin(); it != m_targets.end(); ++it )
185 : {
186 607 : if( iF.count( it->second.section, it->second.keyword ) > 0 )
187 : {
188 115 : it->second.values.push_back( iF( it->second.section, it->second.keyword ) );
189 115 : if( m_sources )
190 : {
191 1 : it->second.sources.push_back( fname );
192 : }
193 115 : it->second.set = true;
194 :
195 115 : iF.erase( it->second.section, it->second.keyword ); // Erase it from the iniFile map.
196 : }
197 : }
198 :
199 : // here set aside non-deleted iF entries
200 38 : for( auto iFit = iF.names.begin(); iFit != iF.names.end(); ++iFit )
201 : {
202 : // Insert or update existing
203 5 : m_unusedConfigs[iFit->first].name = iFit->first;
204 :
205 5 : std::string sect, nam;
206 5 : iniFile::parseKey( sect, nam, iFit->first );
207 5 : m_unusedConfigs[iFit->first].section = sect;
208 5 : m_unusedConfigs[iFit->first].keyword = nam;
209 :
210 5 : m_unusedConfigs[iFit->first].values.push_back( iFit->second );
211 :
212 5 : if( m_sources )
213 1 : m_unusedConfigs[iFit->first].sources.push_back( fname );
214 :
215 5 : m_unusedConfigs[iFit->first].set = true;
216 5 : }
217 :
218 33 : return 0;
219 38 : }
220 :
221 1294 : bool appConfigurator::isSet( const std::string &name, std::unordered_map<std::string, configTarget> &targets )
222 : {
223 1294 : if( targets.count( name ) == 0 )
224 2 : return false;
225 :
226 1292 : targets[name].used = true;
227 :
228 1292 : return targets[name].set;
229 : }
230 :
231 432 : bool appConfigurator::isSet( const std::string &name )
232 : {
233 432 : return isSet( name, m_targets );
234 : }
235 :
236 3 : int appConfigurator::count( const std::string &name, std::unordered_map<std::string, configTarget> &targets )
237 : {
238 3 : targets[name].used = true;
239 3 : return targets[name].values.size();
240 : }
241 :
242 3 : int appConfigurator::count( const std::string &name )
243 : {
244 3 : return count( name, m_targets );
245 : }
246 :
247 1 : int appConfigurator::verbosity( const std::string &name, std::unordered_map<std::string, configTarget> &targets )
248 : {
249 1 : targets[name].used = true;
250 1 : return targets[name].verbosity;
251 : }
252 :
253 1 : int appConfigurator::verbosity( const std::string &name )
254 : {
255 1 : return verbosity( name, m_targets );
256 : }
257 :
258 : //+++++++++++++++++++++++++++++++++++++
259 : // Explicit instants:
260 : //+++++++++++++++++++++++++++++++++++++
261 :
262 : template int appConfigurator::get<char>( char &v,
263 : const std::string &name,
264 : size_t i,
265 : std::unordered_map<std::string, configTarget> &targets );
266 :
267 : template int appConfigurator::get<signed char>( signed char &v,
268 : const std::string &name,
269 : size_t i,
270 : std::unordered_map<std::string, configTarget> &targets );
271 :
272 : template int appConfigurator::get<short>( short &v,
273 : const std::string &name,
274 : size_t i,
275 : std::unordered_map<std::string, configTarget> &targets );
276 :
277 : template int appConfigurator::get<int>( int &v,
278 : const std::string &name,
279 : size_t i,
280 : std::unordered_map<std::string, configTarget> &targets );
281 :
282 : template int appConfigurator::get<long>( long &v,
283 : const std::string &name,
284 : size_t i,
285 : std::unordered_map<std::string, configTarget> &targets );
286 :
287 : template int appConfigurator::get<long long>( long long &v,
288 : const std::string &name,
289 : size_t i,
290 : std::unordered_map<std::string, configTarget> &targets );
291 :
292 : template int appConfigurator::get<unsigned char>( unsigned char &v,
293 : const std::string &name,
294 : size_t i,
295 : std::unordered_map<std::string, configTarget> &targets );
296 :
297 : template int appConfigurator::get<unsigned short>( unsigned short &v,
298 : const std::string &name,
299 : size_t i,
300 : std::unordered_map<std::string, configTarget> &targets );
301 :
302 : template int appConfigurator::get<unsigned int>( unsigned int &v,
303 : const std::string &name,
304 : size_t i,
305 : std::unordered_map<std::string, configTarget> &targets );
306 :
307 : template int appConfigurator::get<unsigned long>( unsigned long &v,
308 : const std::string &name,
309 : size_t i,
310 : std::unordered_map<std::string, configTarget> &targets );
311 :
312 : template int appConfigurator::get<unsigned long long>( unsigned long long &v,
313 : const std::string &name,
314 : size_t i,
315 : std::unordered_map<std::string, configTarget> &targets );
316 :
317 : template int appConfigurator::get<float>( float &v,
318 : const std::string &name,
319 : size_t i,
320 : std::unordered_map<std::string, configTarget> &targets );
321 :
322 : template int appConfigurator::get<double>( double &v,
323 : const std::string &name,
324 : size_t i,
325 : std::unordered_map<std::string, configTarget> &targets );
326 :
327 : template int appConfigurator::get<long double>( long double &v,
328 : const std::string &name,
329 : size_t i,
330 : std::unordered_map<std::string, configTarget> &targets );
331 :
332 : #ifdef HASQUAD
333 : template int appConfigurator::get<__float128>( __float128 &v,
334 : const std::string &name,
335 : size_t i,
336 : std::unordered_map<std::string, configTarget> &targets );
337 : #endif
338 :
339 : template int appConfigurator::get<bool>( bool &v,
340 : const std::string &name,
341 : size_t i,
342 : std::unordered_map<std::string, configTarget> &targets );
343 :
344 : template int appConfigurator::get<std::string>( std::string &v,
345 : const std::string &name,
346 : size_t i,
347 : std::unordered_map<std::string, configTarget> &targets );
348 :
349 : //+++++++++++++++++++++++++++++++++++++
350 :
351 : template int appConfigurator::get<char>( char &v, const std::string &name, size_t i );
352 :
353 : template int appConfigurator::get<signed char>( signed char &v, const std::string &name, size_t i );
354 :
355 : template int appConfigurator::get<short>( short &v, const std::string &name, size_t i );
356 :
357 : template int appConfigurator::get<int>( int &v, const std::string &name, size_t i );
358 :
359 : template int appConfigurator::get<long>( long &v, const std::string &name, size_t i );
360 :
361 : template int appConfigurator::get<long long>( long long &v, const std::string &name, size_t i );
362 :
363 : template int appConfigurator::get<unsigned char>( unsigned char &v, const std::string &name, size_t i );
364 :
365 : template int appConfigurator::get<unsigned short>( unsigned short &v, const std::string &name, size_t i );
366 :
367 : template int appConfigurator::get<unsigned int>( unsigned int &v, const std::string &name, size_t i );
368 :
369 : template int appConfigurator::get<unsigned long>( unsigned long &v, const std::string &name, size_t i );
370 :
371 : template int appConfigurator::get<unsigned long long>( unsigned long long &v, const std::string &name, size_t i );
372 :
373 : template int appConfigurator::get<float>( float &v, const std::string &name, size_t i );
374 :
375 : template int appConfigurator::get<double>( double &v, const std::string &name, size_t i );
376 :
377 : template int appConfigurator::get<long double>( long double &v, const std::string &name, size_t i );
378 :
379 : #ifdef HASQUAD
380 : template int appConfigurator::get<__float128>( __float128 &v, const std::string &name, size_t i );
381 : #endif
382 :
383 : template int appConfigurator::get<bool>( bool &v, const std::string &name, size_t i );
384 :
385 : template int appConfigurator::get<std::string>( std::string &v, const std::string &name, size_t i );
386 :
387 : //+++++++++++++++++++++++++++++++++++++
388 :
389 : template int
390 : appConfigurator::get<char>( char &v, const std::string &name, std::unordered_map<std::string, configTarget> &targets );
391 :
392 : template int appConfigurator::get<signed char>( signed char &v,
393 : const std::string &name,
394 : std::unordered_map<std::string, configTarget> &targets );
395 :
396 : template int appConfigurator::get<short>( short &v,
397 : const std::string &name,
398 : std::unordered_map<std::string, configTarget> &targets );
399 :
400 : template int
401 : appConfigurator::get<int>( int &v, const std::string &name, std::unordered_map<std::string, configTarget> &targets );
402 :
403 : template int
404 : appConfigurator::get<long>( long &v, const std::string &name, std::unordered_map<std::string, configTarget> &targets );
405 :
406 : template int appConfigurator::get<long long>( long long &v,
407 : const std::string &name,
408 : std::unordered_map<std::string, configTarget> &targets );
409 :
410 : template int appConfigurator::get<unsigned char>( unsigned char &v,
411 : const std::string &name,
412 : std::unordered_map<std::string, configTarget> &targets );
413 :
414 : template int appConfigurator::get<unsigned short>( unsigned short &v,
415 : const std::string &name,
416 : std::unordered_map<std::string, configTarget> &targets );
417 :
418 : template int appConfigurator::get<unsigned int>( unsigned int &v,
419 : const std::string &name,
420 : std::unordered_map<std::string, configTarget> &targets );
421 :
422 : template int appConfigurator::get<unsigned long>( unsigned long &v,
423 : const std::string &name,
424 : std::unordered_map<std::string, configTarget> &targets );
425 :
426 : template int appConfigurator::get<unsigned long long>( unsigned long long &v,
427 : const std::string &name,
428 : std::unordered_map<std::string, configTarget> &targets );
429 :
430 : template int appConfigurator::get<float>( float &v,
431 : const std::string &name,
432 : std::unordered_map<std::string, configTarget> &targets );
433 :
434 : template int appConfigurator::get<double>( double &v,
435 : const std::string &name,
436 : std::unordered_map<std::string, configTarget> &targets );
437 :
438 : template int appConfigurator::get<long double>( long double &v,
439 : const std::string &name,
440 : std::unordered_map<std::string, configTarget> &targets );
441 :
442 : #ifdef HASQUAD
443 : template int appConfigurator::get<__float128>( __float128 &v,
444 : const std::string &name,
445 : std::unordered_map<std::string, configTarget> &targets );
446 : #endif
447 :
448 : template int
449 : appConfigurator::get<bool>( bool &v, const std::string &name, std::unordered_map<std::string, configTarget> &targets );
450 :
451 : template int appConfigurator::get<std::string>( std::string &v,
452 : const std::string &name,
453 : std::unordered_map<std::string, configTarget> &targets );
454 :
455 : //+++++++++++++++++++++++++++++++++++++
456 :
457 : template int appConfigurator::get<char>( char &v, const std::string &name );
458 :
459 : template int appConfigurator::get<signed char>( signed char &v, const std::string &name );
460 :
461 : template int appConfigurator::get<short>( short &v, const std::string &name );
462 :
463 : template int appConfigurator::get<int>( int &v, const std::string &name );
464 :
465 : template int appConfigurator::get<long>( long &v, const std::string &name );
466 :
467 : template int appConfigurator::get<long long>( long long &v, const std::string &name );
468 :
469 : template int appConfigurator::get<unsigned char>( unsigned char &v, const std::string &name );
470 :
471 : template int appConfigurator::get<unsigned short>( unsigned short &v, const std::string &name );
472 :
473 : template int appConfigurator::get<unsigned int>( unsigned int &v, const std::string &name );
474 :
475 : template int appConfigurator::get<unsigned long>( unsigned long &v, const std::string &name );
476 :
477 : template int appConfigurator::get<unsigned long long>( unsigned long long &v, const std::string &name );
478 :
479 : template int appConfigurator::get<float>( float &v, const std::string &name );
480 :
481 : template int appConfigurator::get<double>( double &v, const std::string &name );
482 :
483 : template int appConfigurator::get<long double>( long double &v, const std::string &name );
484 :
485 : #ifdef HASQUAD
486 : template int appConfigurator::get<__float128>( __float128 &v, const std::string &name );
487 : #endif
488 :
489 : template int appConfigurator::get<bool>( bool &v, const std::string &name );
490 :
491 : template int appConfigurator::get<std::string>( std::string &v, const std::string &name );
492 :
493 : //++++++++++++++++++++++++++++++++++++++++++++++
494 :
495 : template int appConfigurator::get<char>( std::vector<char> &v,
496 : const std::string &name,
497 : size_t i,
498 : std::unordered_map<std::string, configTarget> &targets );
499 :
500 : template int appConfigurator::get<signed char>( std::vector<signed char> &v,
501 : const std::string &name,
502 : size_t i,
503 : std::unordered_map<std::string, configTarget> &targets );
504 :
505 : template int appConfigurator::get<short>( std::vector<short> &v,
506 : const std::string &name,
507 : size_t i,
508 : std::unordered_map<std::string, configTarget> &targets );
509 :
510 : template int appConfigurator::get<int>( std::vector<int> &v,
511 : const std::string &name,
512 : size_t i,
513 : std::unordered_map<std::string, configTarget> &targets );
514 :
515 : template int appConfigurator::get<long>( std::vector<long> &v,
516 : const std::string &name,
517 : size_t i,
518 : std::unordered_map<std::string, configTarget> &targets );
519 :
520 : template int appConfigurator::get<long long>( std::vector<long long> &v,
521 : const std::string &name,
522 : size_t i,
523 : std::unordered_map<std::string, configTarget> &targets );
524 :
525 : template int appConfigurator::get<unsigned char>( std::vector<unsigned char> &v,
526 : const std::string &name,
527 : size_t i,
528 : std::unordered_map<std::string, configTarget> &targets );
529 :
530 : template int appConfigurator::get<unsigned short>( std::vector<unsigned short> &v,
531 : const std::string &name,
532 : size_t i,
533 : std::unordered_map<std::string, configTarget> &targets );
534 :
535 : template int appConfigurator::get<unsigned int>( std::vector<unsigned int> &v,
536 : const std::string &name,
537 : size_t i,
538 : std::unordered_map<std::string, configTarget> &targets );
539 :
540 : template int appConfigurator::get<unsigned long>( std::vector<unsigned long> &v,
541 : const std::string &name,
542 : size_t i,
543 : std::unordered_map<std::string, configTarget> &targets );
544 :
545 : template int appConfigurator::get<unsigned long long>( std::vector<unsigned long long> &v,
546 : const std::string &name,
547 : size_t i,
548 : std::unordered_map<std::string, configTarget> &targets );
549 :
550 : template int appConfigurator::get<float>( std::vector<float> &v,
551 : const std::string &name,
552 : size_t i,
553 : std::unordered_map<std::string, configTarget> &targets );
554 :
555 : template int appConfigurator::get<double>( std::vector<double> &v,
556 : const std::string &name,
557 : size_t i,
558 : std::unordered_map<std::string, configTarget> &targets );
559 :
560 : template int appConfigurator::get<long double>( std::vector<long double> &v,
561 : const std::string &name,
562 : size_t i,
563 : std::unordered_map<std::string, configTarget> &targets );
564 :
565 : #ifdef HASQUAD
566 : template int appConfigurator::get<__float128>( std::vector<__float128> &v,
567 : const std::string &name,
568 : size_t i,
569 : std::unordered_map<std::string, configTarget> &targets );
570 : #endif
571 :
572 : template int appConfigurator::get<bool>( std::vector<bool> &v,
573 : const std::string &name,
574 : size_t i,
575 : std::unordered_map<std::string, configTarget> &targets );
576 :
577 : template int appConfigurator::get<std::string>( std::vector<std::string> &v,
578 : const std::string &name,
579 : size_t i,
580 : std::unordered_map<std::string, configTarget> &targets );
581 :
582 : //+++++++++++++++++++++++++++++++++++++
583 :
584 : template int appConfigurator::get<char>( std::vector<char> &v, const std::string &name, size_t i );
585 :
586 : template int appConfigurator::get<signed char>( std::vector<signed char> &v, const std::string &name, size_t i );
587 :
588 : template int appConfigurator::get<short>( std::vector<short> &v, const std::string &name, size_t i );
589 :
590 : template int appConfigurator::get<int>( std::vector<int> &v, const std::string &name, size_t i );
591 :
592 : template int appConfigurator::get<long>( std::vector<long> &v, const std::string &name, size_t i );
593 :
594 : template int appConfigurator::get<long long>( std::vector<long long> &v, const std::string &name, size_t i );
595 :
596 : template int appConfigurator::get<unsigned char>( std::vector<unsigned char> &v, const std::string &name, size_t i );
597 :
598 : template int appConfigurator::get<unsigned short>( std::vector<unsigned short> &v, const std::string &name, size_t i );
599 :
600 : template int appConfigurator::get<unsigned int>( std::vector<unsigned int> &v, const std::string &name, size_t i );
601 :
602 : template int appConfigurator::get<unsigned long>( std::vector<unsigned long> &v, const std::string &name, size_t i );
603 :
604 : template int
605 : appConfigurator::get<unsigned long long>( std::vector<unsigned long long> &v, const std::string &name, size_t i );
606 :
607 : template int appConfigurator::get<float>( std::vector<float> &v, const std::string &name, size_t i );
608 :
609 : template int appConfigurator::get<double>( std::vector<double> &v, const std::string &name, size_t i );
610 :
611 : template int appConfigurator::get<long double>( std::vector<long double> &v, const std::string &name, size_t i );
612 :
613 : #ifdef HASQUAD
614 : template int appConfigurator::get<__float128>( std::vector<__float128> &v, const std::string &name, size_t i );
615 : #endif
616 :
617 : template int appConfigurator::get<bool>( std::vector<bool> &v, const std::string &name, size_t i );
618 :
619 : template int appConfigurator::get<std::string>( std::vector<std::string> &v, const std::string &name, size_t i );
620 :
621 : //+++++++++++++++++++++++++++++++++++++++++++++++
622 : template int appConfigurator::get<char>( std::vector<char> &v,
623 : const std::string &name,
624 : std::unordered_map<std::string, configTarget> &targets );
625 :
626 : template int appConfigurator::get<signed char>( std::vector<signed char> &v,
627 : const std::string &name,
628 : std::unordered_map<std::string, configTarget> &targets );
629 :
630 : template int appConfigurator::get<short>( std::vector<short> &v,
631 : const std::string &name,
632 : std::unordered_map<std::string, configTarget> &targets );
633 :
634 : template int appConfigurator::get<int>( std::vector<int> &v,
635 : const std::string &name,
636 : std::unordered_map<std::string, configTarget> &targets );
637 :
638 : template int appConfigurator::get<long>( std::vector<long> &v,
639 : const std::string &name,
640 : std::unordered_map<std::string, configTarget> &targets );
641 :
642 : template int appConfigurator::get<long long>( std::vector<long long> &v,
643 : const std::string &name,
644 : std::unordered_map<std::string, configTarget> &targets );
645 :
646 : template int appConfigurator::get<unsigned char>( std::vector<unsigned char> &v,
647 : const std::string &name,
648 : std::unordered_map<std::string, configTarget> &targets );
649 :
650 : template int appConfigurator::get<unsigned short>( std::vector<unsigned short> &v,
651 : const std::string &name,
652 : std::unordered_map<std::string, configTarget> &targets );
653 :
654 : template int appConfigurator::get<unsigned int>( std::vector<unsigned int> &v,
655 : const std::string &name,
656 : std::unordered_map<std::string, configTarget> &targets );
657 :
658 : template int appConfigurator::get<unsigned long>( std::vector<unsigned long> &v,
659 : const std::string &name,
660 : std::unordered_map<std::string, configTarget> &targets );
661 :
662 : template int appConfigurator::get<unsigned long long>( std::vector<unsigned long long> &v,
663 : const std::string &name,
664 : std::unordered_map<std::string, configTarget> &targets );
665 :
666 : template int appConfigurator::get<float>( std::vector<float> &v,
667 : const std::string &name,
668 : std::unordered_map<std::string, configTarget> &targets );
669 :
670 : template int appConfigurator::get<double>( std::vector<double> &v,
671 : const std::string &name,
672 : std::unordered_map<std::string, configTarget> &targets );
673 :
674 : template int appConfigurator::get<long double>( std::vector<long double> &v,
675 : const std::string &name,
676 : std::unordered_map<std::string, configTarget> &targets );
677 :
678 : #ifdef HASQUAD
679 : template int appConfigurator::get<__float128>( std::vector<__float128> &v,
680 : const std::string &name,
681 : std::unordered_map<std::string, configTarget> &targets );
682 : #endif
683 :
684 : template int appConfigurator::get<bool>( std::vector<bool> &v,
685 : const std::string &name,
686 : std::unordered_map<std::string, configTarget> &targets );
687 :
688 : template int appConfigurator::get<std::string>( std::vector<std::string> &v,
689 : const std::string &name,
690 : std::unordered_map<std::string, configTarget> &targets );
691 : //+++++++++++++++++++++++++++++++++++++
692 :
693 : template int appConfigurator::get<char>( std::vector<char> &v, const std::string &name );
694 :
695 : template int appConfigurator::get<signed char>( std::vector<signed char> &v, const std::string &name );
696 :
697 : template int appConfigurator::get<short>( std::vector<short> &v, const std::string &name );
698 :
699 : template int appConfigurator::get<int>( std::vector<int> &v, const std::string &name );
700 :
701 : template int appConfigurator::get<long>( std::vector<long> &v, const std::string &name );
702 :
703 : template int appConfigurator::get<long long>( std::vector<long long> &v, const std::string &name );
704 :
705 : template int appConfigurator::get<unsigned char>( std::vector<unsigned char> &v, const std::string &name );
706 :
707 : template int appConfigurator::get<unsigned short>( std::vector<unsigned short> &v, const std::string &name );
708 :
709 : template int appConfigurator::get<unsigned int>( std::vector<unsigned int> &v, const std::string &name );
710 :
711 : template int appConfigurator::get<unsigned long>( std::vector<unsigned long> &v, const std::string &name );
712 :
713 : template int appConfigurator::get<unsigned long long>( std::vector<unsigned long long> &v, const std::string &name );
714 :
715 : template int appConfigurator::get<float>( std::vector<float> &v, const std::string &name );
716 :
717 : template int appConfigurator::get<double>( std::vector<double> &v, const std::string &name );
718 :
719 : template int appConfigurator::get<long double>( std::vector<long double> &v, const std::string &name );
720 :
721 : #ifdef HASQUAD
722 : template int appConfigurator::get<__float128>( std::vector<__float128> &v, const std::string &name );
723 : #endif
724 :
725 : template int appConfigurator::get<bool>( std::vector<bool> &v, const std::string &name );
726 :
727 : template int appConfigurator::get<std::string>( std::vector<std::string> &v, const std::string &name );
728 :
729 : //+++++++++++++++++++++++++++++++++++++++
730 :
731 : template int appConfigurator::operator()<char>( char &v, const std::string &name );
732 :
733 : template int appConfigurator::operator()<signed char>( signed char &v, const std::string &name );
734 :
735 : template int appConfigurator::operator()<short>( short &v, const std::string &name );
736 :
737 : template int appConfigurator::operator()<int>( int &v, const std::string &name );
738 :
739 : template int appConfigurator::operator()<long>( long &v, const std::string &name );
740 :
741 : template int appConfigurator::operator()<long long>( long long &v, const std::string &name );
742 :
743 : template int appConfigurator::operator()<unsigned char>( unsigned char &v, const std::string &name );
744 :
745 : template int appConfigurator::operator()<unsigned short>( unsigned short &v, const std::string &name );
746 :
747 : template int appConfigurator::operator()<unsigned int>( unsigned int &v, const std::string &name );
748 :
749 : template int appConfigurator::operator()<unsigned long>( unsigned long &v, const std::string &name );
750 :
751 : template int appConfigurator::operator()<unsigned long long>( unsigned long long &v, const std::string &name );
752 :
753 : template int appConfigurator::operator()<float>( float &v, const std::string &name );
754 :
755 : template int appConfigurator::operator()<double>( double &v, const std::string &name );
756 :
757 : template int appConfigurator::operator()<long double>( long double &v, const std::string &name );
758 :
759 : #ifdef HASQUAD
760 : template int appConfigurator::operator()<__float128>( __float128 &v, const std::string &name );
761 : #endif
762 :
763 : template int appConfigurator::operator()<bool>( bool &v, const std::string &name );
764 :
765 : template int appConfigurator::operator()<std::string>( std::string &v, const std::string &name );
766 :
767 : //++++++++++++++++++++++++++++++++++++++++++++++
768 :
769 : template int appConfigurator::configUnused<char>( char &v, const std::string &key );
770 :
771 : template int appConfigurator::configUnused<signed char>( signed char &v, const std::string &key );
772 :
773 : template int appConfigurator::configUnused<short>( short &v, const std::string &key );
774 :
775 : template int appConfigurator::configUnused<int>( int &v, const std::string &key );
776 :
777 : template int appConfigurator::configUnused<long>( long &v, const std::string &key );
778 :
779 : template int appConfigurator::configUnused<long long>( long long &v, const std::string &key );
780 :
781 : template int appConfigurator::configUnused<unsigned char>( unsigned char &v, const std::string &key );
782 :
783 : template int appConfigurator::configUnused<unsigned short>( unsigned short &v, const std::string &key );
784 :
785 : template int appConfigurator::configUnused<unsigned int>( unsigned int &v, const std::string &key );
786 :
787 : template int appConfigurator::configUnused<unsigned long>( unsigned long &v, const std::string &key );
788 :
789 : template int appConfigurator::configUnused<unsigned long long>( unsigned long long &v, const std::string &key );
790 :
791 : template int appConfigurator::configUnused<float>( float &v, const std::string &key );
792 :
793 : template int appConfigurator::configUnused<double>( double &v, const std::string &key );
794 :
795 : template int appConfigurator::configUnused<long double>( long double &v, const std::string &key );
796 :
797 : #ifdef HASQUAD
798 : template int appConfigurator::configUnused<__float128>( __float128 &v, const std::string &key );
799 : #endif
800 :
801 : template int appConfigurator::configUnused<bool>( bool &v, const std::string &key );
802 :
803 : template int appConfigurator::configUnused<std::string>( std::string &v, const std::string &key );
804 :
805 : //+++++++++++++++++++++++++++++++++++++++++++++++++++++
806 :
807 : template int appConfigurator::configUnused<char>( char &v, const std::string §ion, const std::string &keyword );
808 :
809 : template int
810 : appConfigurator::configUnused<signed char>( signed char &v, const std::string §ion, const std::string &keyword );
811 :
812 : template int appConfigurator::configUnused<short>( short &v, const std::string §ion, const std::string &keyword );
813 :
814 : template int appConfigurator::configUnused<int>( int &v, const std::string §ion, const std::string &keyword );
815 :
816 : template int appConfigurator::configUnused<long>( long &v, const std::string §ion, const std::string &keyword );
817 :
818 : template int
819 : appConfigurator::configUnused<long long>( long long &v, const std::string §ion, const std::string &keyword );
820 :
821 : template int appConfigurator::configUnused<unsigned char>( unsigned char &v,
822 : const std::string §ion,
823 : const std::string &keyword );
824 :
825 : template int appConfigurator::configUnused<unsigned short>( unsigned short &v,
826 : const std::string §ion,
827 : const std::string &keyword );
828 :
829 : template int
830 : appConfigurator::configUnused<unsigned int>( unsigned int &v, const std::string §ion, const std::string &keyword );
831 :
832 : template int appConfigurator::configUnused<unsigned long>( unsigned long &v,
833 : const std::string §ion,
834 : const std::string &keyword );
835 :
836 : template int appConfigurator::configUnused<unsigned long long>( unsigned long long &v,
837 : const std::string §ion,
838 : const std::string &keyword );
839 :
840 : template int appConfigurator::configUnused<float>( float &v, const std::string §ion, const std::string &keyword );
841 :
842 : template int appConfigurator::configUnused<double>( double &v, const std::string §ion, const std::string &keyword );
843 :
844 : template int
845 : appConfigurator::configUnused<long double>( long double &v, const std::string §ion, const std::string &keyword );
846 :
847 : #ifdef HASQUAD
848 : template int
849 : appConfigurator::configUnused<__float128>( __float128 &v, const std::string §ion, const std::string &keyword );
850 : #endif
851 :
852 : template int appConfigurator::configUnused<bool>( bool &v, const std::string §ion, const std::string &keyword );
853 :
854 : template int
855 : appConfigurator::configUnused<std::string>( std::string &v, const std::string §ion, const std::string &keyword );
856 :
857 : //+++++++++++++++++++++++++++++++++++++
858 :
859 1 : int appConfigurator::unusedSections( std::vector<std::string> §ions )
860 : {
861 1 : sections.clear();
862 :
863 : // Wind through all the targets
864 4 : for( auto it = m_unusedConfigs.begin(); it != m_unusedConfigs.end(); ++it )
865 : {
866 3 : std::string sect = it->second.section;
867 :
868 3 : bool add = true;
869 :
870 : // Check if this section is already in the vector -- is there a std::algorithms way to do this?
871 4 : for( size_t i = 0; i < sections.size(); ++i )
872 : {
873 2 : if( sections[i] == sect )
874 : {
875 1 : add = false;
876 1 : break;
877 : }
878 : }
879 :
880 : // Add it if it wasn't found.
881 3 : if( add )
882 2 : sections.push_back( sect );
883 3 : }
884 :
885 1 : return 0;
886 : }
887 :
888 0 : int appConfigurator::isSetUnused( const std::string &name )
889 : {
890 0 : return isSet( name, m_unusedConfigs );
891 : }
892 :
893 29 : void writeConfigFile( const std::string &fname,
894 : const std::vector<std::string> §ions,
895 : const std::vector<std::string> &keywords,
896 : const std::vector<std::string> &values )
897 : {
898 29 : std::ofstream fout;
899 :
900 29 : fout.open( fname );
901 :
902 29 : std::string lastSection;
903 152 : for( size_t i = 0; i < sections.size(); ++i )
904 : {
905 123 : std::string currSection = sections[i];
906 :
907 123 : if( currSection != lastSection && currSection != "" )
908 : {
909 38 : fout << "\n[" << currSection << "]\n";
910 : }
911 :
912 123 : if( keywords.size() >= i && values.size() >= i )
913 : {
914 123 : if( keywords[i] != "" )
915 : {
916 123 : fout << keywords[i] << "=" << values[i] << "\n";
917 : }
918 : }
919 123 : lastSection = currSection;
920 123 : }
921 :
922 29 : fout.close();
923 :
924 58 : return;
925 29 : }
926 :
927 : } // namespace app
928 : } // namespace mx
|