mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
appConfigurator.cpp
Go to the documentation of this file.
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 
36 {
37  m_targets.clear();
38  clOnlyTargets.clear();
39  nonOptions.clear();
40  m_unusedConfigs.clear();
41 }
42 
44 {
45 
46  //First check for duplicate name and command line only
47  if(m_targets.count(tgt.name) > 0 && tgt.section == "" && tgt.keyword == "")
48  {
49  clOnlyTargets.push_back(tgt);
50  clOnlyTargets.back().orderAdded = nAdded;
51  }
52  else
53  {
54  std::pair<targetIterator, bool> res = m_targets.insert({tgt.name, tgt});
55  res.first->second.orderAdded = nAdded;
56  }
57 
58  ++nAdded;
59 
60 }
61 
62 void appConfigurator::add( const std::string &n,
63  const std::string &so,
64  const std::string &lo,
65  int clt,
66  const std::string & s,
67  const std::string & kw,
68  bool isReq,
69  const std::string & ht,
70  const std::string & he )
71 {
72  add( configTarget(n,so,lo,clt, s, kw, isReq, ht, he) );
73 }
74 
76  char ** argv,
77  const std::string & oneTarget
78  )
79 {
80  if(argc == 0) return;
81 
82  clOptions clOpts;
83 
84  //First load the options into the clOptions parser
85  targetIterator it;
86  for(it = m_targets.begin(); it != m_targets.end(); ++it)
87  {
88  if(it->second.shortOpt == "" && it->second.longOpt == "") continue; //No command line opts specified.
89 
90  clOpts.add(it->second.name,it->second.shortOpt.c_str(),it->second.longOpt.c_str(), it->second.clType);
91  }
92 
93  //Then load the command-line-only options.
95  for(cloit = clOnlyTargets.begin(); cloit != clOnlyTargets.end(); ++cloit)
96  {
97  if(cloit->shortOpt == "" && cloit->longOpt == "") continue; //Nothing to add?
98 
99  clOpts.add(cloit->name,cloit->shortOpt.c_str(),cloit->longOpt.c_str(), cloit->clType);
100  }
101 
102  //Now we parse
103  clOpts.parse(argc, argv, &nonOptions);
104 
105  if(clOpts.numUnknown() > 0)
106  {
107  std::vector<std::string> unk;
108  clOpts.unknown(unk);
109 
110  for (size_t n=0;n<unk.size();++n)
111  {
112  //Insert or update existing
113  m_unusedConfigs[unk[n]].name = unk[n];
114  if(m_sources) m_unusedConfigs[unk[n]].sources.push_back("command line");
115  m_unusedConfigs[unk[n]].set = true;
116  }
117  }
118 
119  //If nothing more to do, get out
120  if(clOpts.nOpts == 0)
121  {
122  return;
123  }
124  //And then load the results in the config target map.
125  for(it = m_targets.begin(); it != m_targets.end(); ++it)
126  {
127  if(oneTarget != "" && it->second.name != oneTarget) continue;
128 
129  if(clOpts.optSet(it->second.name))
130  {
131  std::vector<std::string> args;
132 
133  clOpts.getAll(args, it->second.name);
134 
135  it->second.values.insert( it->second.values.end(), args.begin(), args.end());
136  if(m_sources)
137  {
138  for(size_t n=0; n < args.size(); ++n) it->second.sources.push_back("command line");
139  }
140 
141  it->second.verbosity = clOpts.count(it->second.name);
142  it->second.set = true;
143  }
144  }
145 
146 
147 }
148 
149 int appConfigurator::readConfig( const std::string & fname,
150  bool reportFileNotFound
151  )
152 {
153  //Handle empty string quietly
154  if(fname == "") return 0;
155 
156  iniFile iF;
157 
158  ///\todo update error handling to include >0 (line numer of parse error) and -2 memory allocation error.
159  int prv = iF.parse(fname);
160 
161  if( prv == -1)
162  {
163  if(!reportFileNotFound) return -1;
164 
165  mxError("appConfigurator: ", MXE_FILENOTFOUND, "The file " + fname + " was not found");
166  return -1;
167  }
168 
169  if( prv == -2)
170  {
171  mxError("appConfigurator: ", MXE_ALLOCERR, "Memory allocation error in config file parser");
172  return -1;
173  }
174 
175  if( prv > 0)
176  {
177  mxError("appConfigurator: ", MXE_PARSEERR, "Parsing error in " + fname + " at line " + std::to_string(prv));
178  return -1;
179  }
180 
181  targetIterator it;
182 
183  for(it = m_targets.begin(); it != m_targets.end(); ++it)
184  {
185  if(iF.count(it->second.section, it->second.keyword) > 0)
186  {
187  it->second.values.push_back(iF(it->second.section, it->second.keyword));
188  if(m_sources)
189  {
190  it->second.sources.push_back(fname);
191  }
192  it->second.set = true;
193 
194  iF.erase(it->second.section, it->second.keyword); //Erase it from the iniFile map.
195  }
196  }
197 
198  //here set aside non-deleted iF entries
199  for( auto iFit = iF.names.begin(); iFit != iF.names.end(); ++iFit)
200  {
201  //Insert or update existing
202  m_unusedConfigs[iFit->first].name = iFit->first;
203 
204  std::string sect, nam;
205  iniFile::parseKey(sect, nam, iFit->first);
206  m_unusedConfigs[iFit->first].section = sect;
207  m_unusedConfigs[iFit->first].keyword = nam;
208 
209  m_unusedConfigs[iFit->first].values.push_back(iFit->second);
210 
211  if(m_sources) m_unusedConfigs[iFit->first].sources.push_back(fname);
212 
213  m_unusedConfigs[iFit->first].set = true;
214  }
215 
216  return 0;
217 }
218 
219 bool appConfigurator::isSet( const std::string & name,
220  std::unordered_map<std::string, configTarget> & targets
221  )
222 {
223  if(targets.count(name) == 0) return false;
224 
225  targets[name].used = true;
226 
227  return targets[name].set;
228 }
229 
230 bool appConfigurator::isSet( const std::string & name )
231 {
232  return isSet(name, m_targets);
233 }
234 
235 int appConfigurator::count( const std::string & name,
236  std::unordered_map<std::string, configTarget> & targets
237  )
238 {
239  targets[name].used = true;
240  return targets[name].values.size();
241 }
242 
243 int appConfigurator::count( const std::string & name )
244 {
245  return count(name, m_targets);
246 }
247 
248 int appConfigurator::verbosity( const std::string & name,
249  std::unordered_map<std::string, configTarget> & targets
250  )
251 {
252  targets[name].used = true;
253  return targets[name].verbosity;
254 }
255 
256 int appConfigurator::verbosity( const std::string & name )
257 {
258  return verbosity(name, m_targets);
259 }
260 
261 //+++++++++++++++++++++++++++++++++++++
262 // Explicit instants:
263 //+++++++++++++++++++++++++++++++++++++
264 
265 template
266 int appConfigurator::get<char>( char & v, const std::string & name, size_t i, std::unordered_map<std::string, configTarget> & targets);
267 
268 template
269 int appConfigurator::get<char16_t>( char16_t & v, const std::string & name, size_t i, std::unordered_map<std::string, configTarget> & targets);
270 
271 template
272 int appConfigurator::get<char32_t>( char32_t & v, const std::string & name, size_t i, std::unordered_map<std::string, configTarget> & targets);
273 
274 template
275 int appConfigurator::get<wchar_t>( wchar_t & v, const std::string & name, size_t i, std::unordered_map<std::string, configTarget> & targets);
276 
277 template
278 int appConfigurator::get<signed char>( signed char & v, const std::string & name, size_t i, std::unordered_map<std::string, configTarget> & targets);
279 
280 template
281 int appConfigurator::get<short>( short & v, const std::string & name, size_t i, std::unordered_map<std::string, configTarget> & targets);
282 
283 template
284 int appConfigurator::get<int>( int & v, const std::string & name, size_t i, std::unordered_map<std::string, configTarget> & targets);
285 
286 template
287 int appConfigurator::get<long>( long & v, const std::string & name, size_t i, std::unordered_map<std::string, configTarget> & targets);
288 
289 template
290 int appConfigurator::get<long long>( long long & v, const std::string & name, size_t i, std::unordered_map<std::string, configTarget> & targets);
291 
292 template
293 int appConfigurator::get<unsigned char>( unsigned char & v, const std::string & name, size_t i, std::unordered_map<std::string, configTarget> & targets);
294 
295 template
296 int appConfigurator::get<unsigned short>( unsigned short & v, const std::string & name, size_t i, std::unordered_map<std::string, configTarget> & targets);
297 
298 template
299 int appConfigurator::get<unsigned int>( unsigned int & v, const std::string & name, size_t i, std::unordered_map<std::string, configTarget> & targets);
300 
301 template
302 int appConfigurator::get<unsigned long>( unsigned long & v, const std::string & name, size_t i, std::unordered_map<std::string, configTarget> & targets);
303 
304 template
305 int appConfigurator::get<unsigned long long>( unsigned long long & v, const std::string & name, size_t i, std::unordered_map<std::string, configTarget> & targets);
306 
307 template
308 int appConfigurator::get<float>( float & v, const std::string & name, size_t i, std::unordered_map<std::string, configTarget> & targets);
309 
310 template
311 int appConfigurator::get<double>( double & v, const std::string & name, size_t i, std::unordered_map<std::string, configTarget> & targets);
312 
313 template
314 int appConfigurator::get<long double>( long double & v, const std::string & name, size_t i, std::unordered_map<std::string, configTarget> & targets);
315 
316 #ifdef HASQUAD
317 template
318 int appConfigurator::get<__float128>( __float128 & v, const std::string & name, size_t i, std::unordered_map<std::string, configTarget> & targets);
319 #endif
320 
321 template
322 int appConfigurator::get<bool>( bool & v, const std::string & name, size_t i, std::unordered_map<std::string, configTarget> & targets);
323 
324 template
325 int appConfigurator::get<std::string>( std::string & v, const std::string & name, size_t i, std::unordered_map<std::string, configTarget> & targets);
326 
327 //+++++++++++++++++++++++++++++++++++++
328 
329 template
330 int appConfigurator::get<char>( char & v, const std::string & name, size_t i);
331 
332 template
333 int appConfigurator::get<char16_t>( char16_t & v, const std::string & name, size_t i);
334 
335 template
336 int appConfigurator::get<char32_t>( char32_t & v, const std::string & name, size_t i);
337 
338 template
339 int appConfigurator::get<wchar_t>( wchar_t & v, const std::string & name, size_t i);
340 
341 template
342 int appConfigurator::get<signed char>( signed char & v, const std::string & name, size_t i);
343 
344 template
345 int appConfigurator::get<short>( short & v, const std::string & name, size_t i);
346 
347 template
348 int appConfigurator::get<int>( int & v, const std::string & name, size_t i);
349 
350 template
351 int appConfigurator::get<long>( long & v, const std::string & name, size_t i);
352 
353 template
354 int appConfigurator::get<long long>( long long & v, const std::string & name, size_t i);
355 
356 template
357 int appConfigurator::get<unsigned char>( unsigned char & v, const std::string & name, size_t i);
358 
359 template
360 int appConfigurator::get<unsigned short>( unsigned short & v, const std::string & name, size_t i);
361 
362 template
363 int appConfigurator::get<unsigned int>( unsigned int & v, const std::string & name, size_t i);
364 
365 template
366 int appConfigurator::get<unsigned long>( unsigned long & v, const std::string & name, size_t i);
367 
368 template
369 int appConfigurator::get<unsigned long long>( unsigned long long & v, const std::string & name, size_t i);
370 
371 template
372 int appConfigurator::get<float>( float & v, const std::string & name, size_t i);
373 
374 template
375 int appConfigurator::get<double>( double & v, const std::string & name, size_t i);
376 
377 template
378 int appConfigurator::get<long double>( long double & v, const std::string & name, size_t i);
379 
380 #ifdef HASQUAD
381 template
382 int appConfigurator::get<__float128>( __float128 & v, const std::string & name, size_t i);
383 #endif
384 
385 template
386 int appConfigurator::get<bool>( bool & v, const std::string & name, size_t i);
387 
388 template
389 int appConfigurator::get<std::string>( std::string & v, const std::string & name, size_t i);
390 
391 //+++++++++++++++++++++++++++++++++++++
392 
393 template
394 int appConfigurator::get<char>( char & v, const std::string & name, std::unordered_map<std::string, configTarget> & targets);
395 
396 template
397 int appConfigurator::get<char16_t>( char16_t & v, const std::string & name, std::unordered_map<std::string, configTarget> & targets);
398 
399 template
400 int appConfigurator::get<char32_t>( char32_t & v, const std::string & name, std::unordered_map<std::string, configTarget> & targets);
401 
402 template
403 int appConfigurator::get<wchar_t>( wchar_t & v, const std::string & name, std::unordered_map<std::string, configTarget> & targets);
404 
405 template
406 int appConfigurator::get<signed char>( signed char & v, const std::string & name, std::unordered_map<std::string, configTarget> & targets);
407 
408 template
409 int appConfigurator::get<short>( short & v, const std::string & name, std::unordered_map<std::string, configTarget> & targets);
410 
411 template
412 int appConfigurator::get<int>( int & v, const std::string & name, std::unordered_map<std::string, configTarget> & targets);
413 
414 template
415 int appConfigurator::get<long>( long & v, const std::string & name, std::unordered_map<std::string, configTarget> & targets);
416 
417 template
418 int appConfigurator::get<long long>( long long & v, const std::string & name, std::unordered_map<std::string, configTarget> & targets);
419 
420 template
421 int appConfigurator::get<unsigned char>( unsigned char & v, const std::string & name, std::unordered_map<std::string, configTarget> & targets);
422 
423 template
424 int appConfigurator::get<unsigned short>( unsigned short & v, const std::string & name, std::unordered_map<std::string, configTarget> & targets);
425 
426 template
427 int appConfigurator::get<unsigned int>( unsigned int & v, const std::string & name, std::unordered_map<std::string, configTarget> & targets);
428 
429 template
430 int appConfigurator::get<unsigned long>( unsigned long & v, const std::string & name, std::unordered_map<std::string, configTarget> & targets);
431 
432 template
433 int appConfigurator::get<unsigned long long>( unsigned long long & v, const std::string & name, std::unordered_map<std::string, configTarget> & targets);
434 
435 template
436 int appConfigurator::get<float>( float & v, const std::string & name, std::unordered_map<std::string, configTarget> & targets);
437 
438 template
439 int appConfigurator::get<double>( double & v, const std::string & name, std::unordered_map<std::string, configTarget> & targets);
440 
441 template
442 int appConfigurator::get<long double>( long double & v, const std::string & name, std::unordered_map<std::string, configTarget> & targets);
443 
444 #ifdef HASQUAD
445 template
446 int appConfigurator::get<__float128>( __float128 & v, const std::string & name, std::unordered_map<std::string, configTarget> & targets);
447 #endif
448 
449 template
450 int appConfigurator::get<bool>( bool & v, const std::string & name, std::unordered_map<std::string, configTarget> & targets);
451 
452 template
453 int appConfigurator::get<std::string>( std::string & v, const std::string & name, std::unordered_map<std::string, configTarget> & targets);
454 
455 //+++++++++++++++++++++++++++++++++++++
456 
457 template
458 int appConfigurator::get<char>( char & v, const std::string & name);
459 
460 template
461 int appConfigurator::get<char16_t>( char16_t & v, const std::string & name);
462 
463 template
464 int appConfigurator::get<char32_t>( char32_t & v, const std::string & name);
465 
466 template
467 int appConfigurator::get<wchar_t>( wchar_t & v, const std::string & name);
468 
469 template
470 int appConfigurator::get<signed char>( signed char & v, const std::string & name);
471 
472 template
473 int appConfigurator::get<short>( short & v, const std::string & name);
474 
475 template
476 int appConfigurator::get<int>( int & v, const std::string & name);
477 
478 template
479 int appConfigurator::get<long>( long & v, const std::string & name);
480 
481 template
482 int appConfigurator::get<long long>( long long & v, const std::string & name);
483 
484 template
485 int appConfigurator::get<unsigned char>( unsigned char & v, const std::string & name);
486 
487 template
488 int appConfigurator::get<unsigned short>( unsigned short & v, const std::string & name);
489 
490 template
491 int appConfigurator::get<unsigned int>( unsigned int & v, const std::string & name);
492 
493 template
494 int appConfigurator::get<unsigned long>( unsigned long & v, const std::string & name);
495 
496 template
497 int appConfigurator::get<unsigned long long>( unsigned long long & v, const std::string & name);
498 
499 template
500 int appConfigurator::get<float>( float & v, const std::string & name);
501 
502 template
503 int appConfigurator::get<double>( double & v, const std::string & name);
504 
505 template
506 int appConfigurator::get<long double>( long double & v, const std::string & name);
507 
508 #ifdef HASQUAD
509 template
510 int appConfigurator::get<__float128>( __float128 & v, const std::string & name);
511 #endif
512 
513 template
514 int appConfigurator::get<bool>( bool & v, const std::string & name);
515 
516 template
517 int appConfigurator::get<std::string>( std::string & v, const std::string & name);
518 
519 //++++++++++++++++++++++++++++++++++++++++++++++
520 
521 template
522 int appConfigurator::get<char>( std::vector<char> & v, const std::string & name, size_t i, std::unordered_map<std::string, configTarget> & targets);
523 
524 template
525 int appConfigurator::get<char16_t>( std::vector<char16_t> & v, const std::string & name, size_t i, std::unordered_map<std::string, configTarget> & targets);
526 
527 template
528 int appConfigurator::get<char32_t>( std::vector<char32_t> & v, const std::string & name, size_t i, std::unordered_map<std::string, configTarget> & targets);
529 
530 template
531 int appConfigurator::get<wchar_t>( std::vector<wchar_t> & v, const std::string & name, size_t i, std::unordered_map<std::string, configTarget> & targets);
532 
533 template
534 int appConfigurator::get<signed char>( std::vector<signed char> & v, const std::string & name, size_t i, std::unordered_map<std::string, configTarget> & targets);
535 
536 template
537 int appConfigurator::get<short>( std::vector<short> & v, const std::string & name, size_t i, std::unordered_map<std::string, configTarget> & targets);
538 
539 template
540 int appConfigurator::get<int>( std::vector<int> & v, const std::string & name, size_t i, std::unordered_map<std::string, configTarget> & targets);
541 
542 template
543 int appConfigurator::get<long>( std::vector<long> & v, const std::string & name, size_t i, std::unordered_map<std::string, configTarget> & targets);
544 
545 template
546 int appConfigurator::get<long long>( std::vector<long long> & v, const std::string & name, size_t i, std::unordered_map<std::string, configTarget> & targets);
547 
548 template
549 int appConfigurator::get<unsigned char>( std::vector<unsigned char> & v, const std::string & name, size_t i, std::unordered_map<std::string, configTarget> & targets);
550 
551 template
552 int appConfigurator::get<unsigned short>( std::vector<unsigned short> & v, const std::string & name, size_t i, std::unordered_map<std::string, configTarget> & targets);
553 
554 template
555 int appConfigurator::get<unsigned int>( std::vector<unsigned int> & v, const std::string & name, size_t i, std::unordered_map<std::string, configTarget> & targets);
556 
557 template
558 int appConfigurator::get<unsigned long>( std::vector<unsigned long> & v, const std::string & name, size_t i, std::unordered_map<std::string, configTarget> & targets);
559 
560 template
561 int appConfigurator::get<unsigned long long>( std::vector<unsigned long long> & v, const std::string & name, size_t i, std::unordered_map<std::string, configTarget> & targets);
562 
563 template
564 int appConfigurator::get<float>( std::vector<float> & v, const std::string & name, size_t i, std::unordered_map<std::string, configTarget> & targets);
565 
566 template
567 int appConfigurator::get<double>( std::vector<double> & v, const std::string & name, size_t i, std::unordered_map<std::string, configTarget> & targets);
568 
569 template
570 int appConfigurator::get<long double>( std::vector<long double> & v, const std::string & name, size_t i, std::unordered_map<std::string, configTarget> & targets);
571 
572 #ifdef HASQUAD
573 template
574 int appConfigurator::get<__float128>( std::vector<__float128> & v, const std::string & name, size_t i, std::unordered_map<std::string, configTarget> & targets);
575 #endif
576 
577 template
578 int appConfigurator::get<bool>( std::vector<bool> & v, const std::string & name, size_t i, std::unordered_map<std::string, configTarget> & targets);
579 
580 template
581 int appConfigurator::get<std::string>( std::vector<std::string> & v, const std::string & name, size_t i, std::unordered_map<std::string, configTarget> & targets);
582 
583 //+++++++++++++++++++++++++++++++++++++
584 
585 template
586 int appConfigurator::get<char>( std::vector<char> & v, const std::string & name, size_t i);
587 
588 template
589 int appConfigurator::get<char16_t>( std::vector<char16_t> & v, const std::string & name, size_t i);
590 
591 template
592 int appConfigurator::get<char32_t>( std::vector<char32_t> & v, const std::string & name, size_t i);
593 
594 template
595 int appConfigurator::get<wchar_t>( std::vector<wchar_t> & v, const std::string & name, size_t i);
596 
597 template
598 int appConfigurator::get<signed char>( std::vector<signed char> & v, const std::string & name, size_t i);
599 
600 template
601 int appConfigurator::get<short>( std::vector<short> & v, const std::string & name, size_t i);
602 
603 template
604 int appConfigurator::get<int>( std::vector<int> & v, const std::string & name, size_t i);
605 
606 template
607 int appConfigurator::get<long>( std::vector<long> & v, const std::string & name, size_t i);
608 
609 template
610 int appConfigurator::get<long long>( std::vector<long long> & v, const std::string & name, size_t i);
611 
612 template
613 int appConfigurator::get<unsigned char>( std::vector<unsigned char> & v, const std::string & name, size_t i);
614 
615 template
616 int appConfigurator::get<unsigned short>( std::vector<unsigned short> & v, const std::string & name, size_t i);
617 
618 template
619 int appConfigurator::get<unsigned int>( std::vector<unsigned int> & v, const std::string & name, size_t i);
620 
621 template
622 int appConfigurator::get<unsigned long>( std::vector<unsigned long> & v, const std::string & name, size_t i);
623 
624 template
625 int appConfigurator::get<unsigned long long>( std::vector<unsigned long long> & v, const std::string & name, size_t i);
626 
627 template
628 int appConfigurator::get<float>( std::vector<float> & v, const std::string & name, size_t i);
629 
630 template
631 int appConfigurator::get<double>( std::vector<double> & v, const std::string & name, size_t i);
632 
633 template
634 int appConfigurator::get<long double>( std::vector<long double> & v, const std::string & name, size_t i);
635 
636 #ifdef HASQUAD
637 template
638 int appConfigurator::get<__float128>( std::vector<__float128> & v, const std::string & name, size_t i);
639 #endif
640 
641 template
642 int appConfigurator::get<bool>( std::vector<bool> & v, const std::string & name, size_t i);
643 
644 template
645 int appConfigurator::get<std::string>( std::vector<std::string> & v, const std::string & name, size_t i);
646 
647 //+++++++++++++++++++++++++++++++++++++++++++++++
648 template
649 int appConfigurator::get<char>( std::vector<char> & v, const std::string & name, std::unordered_map<std::string, configTarget> & targets);
650 
651 template
652 int appConfigurator::get<char16_t>( std::vector<char16_t> & v, const std::string & name, std::unordered_map<std::string, configTarget> & targets);
653 
654 template
655 int appConfigurator::get<char32_t>( std::vector<char32_t> & v, const std::string & name, std::unordered_map<std::string, configTarget> & targets);
656 
657 template
658 int appConfigurator::get<wchar_t>( std::vector<wchar_t> & v, const std::string & name, std::unordered_map<std::string, configTarget> & targets);
659 
660 template
661 int appConfigurator::get<signed char>( std::vector<signed char> & v, const std::string & name, std::unordered_map<std::string, configTarget> & targets);
662 
663 template
664 int appConfigurator::get<short>( std::vector<short> & v, const std::string & name, std::unordered_map<std::string, configTarget> & targets);
665 
666 template
667 int appConfigurator::get<int>( std::vector<int> & v, const std::string & name, std::unordered_map<std::string, configTarget> & targets);
668 
669 template
670 int appConfigurator::get<long>( std::vector<long> & v, const std::string & name, std::unordered_map<std::string, configTarget> & targets);
671 
672 template
673 int appConfigurator::get<long long>( std::vector<long long> & v, const std::string & name, std::unordered_map<std::string, configTarget> & targets);
674 
675 template
676 int appConfigurator::get<unsigned char>( std::vector<unsigned char> & v, const std::string & name, std::unordered_map<std::string, configTarget> & targets);
677 
678 template
679 int appConfigurator::get<unsigned short>( std::vector<unsigned short> & v, const std::string & name, std::unordered_map<std::string, configTarget> & targets);
680 
681 template
682 int appConfigurator::get<unsigned int>( std::vector<unsigned int> & v, const std::string & name, std::unordered_map<std::string, configTarget> & targets);
683 
684 template
685 int appConfigurator::get<unsigned long>( std::vector<unsigned long> & v, const std::string & name, std::unordered_map<std::string, configTarget> & targets);
686 
687 template
688 int appConfigurator::get<unsigned long long>( std::vector<unsigned long long> & v, const std::string & name, std::unordered_map<std::string, configTarget> & targets);
689 
690 template
691 int appConfigurator::get<float>( std::vector<float> & v, const std::string & name, std::unordered_map<std::string, configTarget> & targets);
692 
693 template
694 int appConfigurator::get<double>( std::vector<double> & v, const std::string & name, std::unordered_map<std::string, configTarget> & targets);
695 
696 template
697 int appConfigurator::get<long double>( std::vector<long double> & v, const std::string & name, std::unordered_map<std::string, configTarget> & targets);
698 
699 #ifdef HASQUAD
700 template
701 int appConfigurator::get<__float128>( std::vector<__float128> & v, const std::string & name, std::unordered_map<std::string, configTarget> & targets);
702 #endif
703 
704 template
705 int appConfigurator::get<bool>( std::vector<bool> & v, const std::string & name, std::unordered_map<std::string, configTarget> & targets);
706 
707 template
708 int appConfigurator::get<std::string>( std::vector<std::string> & v, const std::string & name, std::unordered_map<std::string, configTarget> & targets);
709 //+++++++++++++++++++++++++++++++++++++
710 
711 template
712 int appConfigurator::get<char>( std::vector<char> & v, const std::string & name);
713 
714 template
715 int appConfigurator::get<char16_t>( std::vector<char16_t> & v, const std::string & name);
716 
717 template
718 int appConfigurator::get<char32_t>( std::vector<char32_t> & v, const std::string & name);
719 
720 template
721 int appConfigurator::get<wchar_t>( std::vector<wchar_t> & v, const std::string & name);
722 
723 template
724 int appConfigurator::get<signed char>( std::vector<signed char> & v, const std::string & name);
725 
726 template
727 int appConfigurator::get<short>( std::vector<short> & v, const std::string & name);
728 
729 template
730 int appConfigurator::get<int>( std::vector<int> & v, const std::string & name);
731 
732 template
733 int appConfigurator::get<long>( std::vector<long> & v, const std::string & name);
734 
735 template
736 int appConfigurator::get<long long>( std::vector<long long> & v, const std::string & name);
737 
738 template
739 int appConfigurator::get<unsigned char>( std::vector<unsigned char> & v, const std::string & name);
740 
741 template
742 int appConfigurator::get<unsigned short>( std::vector<unsigned short> & v, const std::string & name);
743 
744 template
745 int appConfigurator::get<unsigned int>( std::vector<unsigned int> & v, const std::string & name);
746 
747 template
748 int appConfigurator::get<unsigned long>( std::vector<unsigned long> & v, const std::string & name);
749 
750 template
751 int appConfigurator::get<unsigned long long>( std::vector<unsigned long long> & v, const std::string & name);
752 
753 template
754 int appConfigurator::get<float>( std::vector<float> & v, const std::string & name);
755 
756 template
757 int appConfigurator::get<double>( std::vector<double> & v, const std::string & name);
758 
759 template
760 int appConfigurator::get<long double>( std::vector<long double> & v, const std::string & name);
761 
762 #ifdef HASQUAD
763 template
764 int appConfigurator::get<__float128>( std::vector<__float128> & v, const std::string & name);
765 #endif
766 
767 template
768 int appConfigurator::get<bool>( std::vector<bool> & v, const std::string & name);
769 
770 template
771 int appConfigurator::get<std::string>( std::vector<std::string> & v, const std::string & name);
772 
773 //+++++++++++++++++++++++++++++++++++++++
774 
775 template
776 int appConfigurator::operator()<char>( char & v, const std::string & name);
777 
778 template
779 int appConfigurator::operator()<char16_t>( char16_t & v, const std::string & name);
780 
781 template
782 int appConfigurator::operator()<char32_t>( char32_t & v, const std::string & name);
783 
784 template
785 int appConfigurator::operator()<wchar_t>( wchar_t & v, const std::string & name);
786 
787 template
788 int appConfigurator::operator()<signed char>( signed char & v, const std::string & name);
789 
790 template
791 int appConfigurator::operator()<short>( short & v, const std::string & name);
792 
793 template
794 int appConfigurator::operator()<int>( int & v, const std::string & name);
795 
796 template
797 int appConfigurator::operator()<long>( long & v, const std::string & name);
798 
799 template
800 int appConfigurator::operator()<long long>( long long & v, const std::string & name);
801 
802 template
803 int appConfigurator::operator()<unsigned char>( unsigned char & v, const std::string & name);
804 
805 template
806 int appConfigurator::operator()<unsigned short>( unsigned short & v, const std::string & name);
807 
808 template
809 int appConfigurator::operator()<unsigned int>( unsigned int & v, const std::string & name);
810 
811 template
812 int appConfigurator::operator()<unsigned long>( unsigned long & v, const std::string & name);
813 
814 template
815 int appConfigurator::operator()<unsigned long long>( unsigned long long & v, const std::string & name);
816 
817 template
818 int appConfigurator::operator()<float>( float & v, const std::string & name);
819 
820 template
821 int appConfigurator::operator()<double>( double & v, const std::string & name);
822 
823 template
824 int appConfigurator::operator()<long double>( long double & v, const std::string & name);
825 
826 #ifdef HASQUAD
827 template
828 int appConfigurator::operator()<__float128>( __float128 & v, const std::string & name);
829 #endif
830 
831 template
832 int appConfigurator::operator()<bool>( bool & v, const std::string & name);
833 
834 template
835 int appConfigurator::operator()<std::string>( std::string & v, const std::string & name);
836 
837 //++++++++++++++++++++++++++++++++++++++++++++++
838 
839 template
840 int appConfigurator::configUnused<char>( char & v, const std::string & key);
841 
842 template
843 int appConfigurator::configUnused<char16_t>( char16_t & v, const std::string & key);
844 
845 template
846 int appConfigurator::configUnused<char32_t>( char32_t & v, const std::string & key);
847 
848 template
849 int appConfigurator::configUnused<wchar_t>( wchar_t & v, const std::string & key);
850 
851 template
852 int appConfigurator::configUnused<signed char>( signed char & v, const std::string & key);
853 
854 template
855 int appConfigurator::configUnused<short>( short & v, const std::string & key);
856 
857 template
858 int appConfigurator::configUnused<int>( int & v, const std::string & key);
859 
860 template
861 int appConfigurator::configUnused<long>( long & v, const std::string & key);
862 
863 template
864 int appConfigurator::configUnused<long long>( long long & v, const std::string & key);
865 
866 template
867 int appConfigurator::configUnused<unsigned char>( unsigned char & v, const std::string & key);
868 
869 template
870 int appConfigurator::configUnused<unsigned short>( unsigned short & v, const std::string & key);
871 
872 template
873 int appConfigurator::configUnused<unsigned int>( unsigned int & v, const std::string & key);
874 
875 template
876 int appConfigurator::configUnused<unsigned long>( unsigned long & v, const std::string & key);
877 
878 template
879 int appConfigurator::configUnused<unsigned long long>( unsigned long long & v, const std::string & key);
880 
881 template
882 int appConfigurator::configUnused<float>( float & v, const std::string & key);
883 
884 template
885 int appConfigurator::configUnused<double>( double & v, const std::string & key);
886 
887 template
888 int appConfigurator::configUnused<long double>( long double & v, const std::string & key);
889 
890 #ifdef HASQUAD
891 template
892 int appConfigurator::configUnused<__float128>( __float128 & v, const std::string & key);
893 #endif
894 
895 template
896 int appConfigurator::configUnused<bool>( bool & v, const std::string & key);
897 
898 template
899 int appConfigurator::configUnused<std::string>( std::string & v, const std::string & key);
900 
901 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
902 
903 template
904 int appConfigurator::configUnused<char>( char & v, const std::string & section, const std::string & keyword);
905 
906 template
907 int appConfigurator::configUnused<char16_t>( char16_t & v, const std::string & section, const std::string & keyword);
908 
909 template
910 int appConfigurator::configUnused<char32_t>( char32_t & v, const std::string & section, const std::string & keyword);
911 
912 template
913 int appConfigurator::configUnused<wchar_t>( wchar_t & v, const std::string & section, const std::string & keyword);
914 
915 template
916 int appConfigurator::configUnused<signed char>( signed char & v, const std::string & section, const std::string & keyword);
917 
918 template
919 int appConfigurator::configUnused<short>( short & v, const std::string & section, const std::string & keyword);
920 
921 template
922 int appConfigurator::configUnused<int>( int & v, const std::string & section, const std::string & keyword);
923 
924 template
925 int appConfigurator::configUnused<long>( long & v, const std::string & section, const std::string & keyword);
926 
927 template
928 int appConfigurator::configUnused<long long>( long long & v, const std::string & section, const std::string & keyword);
929 
930 template
931 int appConfigurator::configUnused<unsigned char>( unsigned char & v, const std::string & section, const std::string & keyword);
932 
933 template
934 int appConfigurator::configUnused<unsigned short>( unsigned short & v, const std::string & section, const std::string & keyword);
935 
936 template
937 int appConfigurator::configUnused<unsigned int>( unsigned int & v, const std::string & section, const std::string & keyword);
938 
939 template
940 int appConfigurator::configUnused<unsigned long>( unsigned long & v, const std::string & section, const std::string & keyword);
941 
942 template
943 int appConfigurator::configUnused<unsigned long long>( unsigned long long & v, const std::string & section, const std::string & keyword);
944 
945 template
946 int appConfigurator::configUnused<float>( float & v, const std::string & section, const std::string & keyword);
947 
948 template
949 int appConfigurator::configUnused<double>( double & v, const std::string & section, const std::string & keyword);
950 
951 template
952 int appConfigurator::configUnused<long double>( long double & v, const std::string & section, const std::string & keyword);
953 
954 #ifdef HASQUAD
955 template
956 int appConfigurator::configUnused<__float128>( __float128 & v, const std::string & section, const std::string & keyword);
957 #endif
958 
959 template
960 int appConfigurator::configUnused<bool>( bool & v, const std::string & section, const std::string & keyword);
961 
962 template
963 int appConfigurator::configUnused<std::string>( std::string & v, const std::string & section, const std::string & keyword);
964 
965 //+++++++++++++++++++++++++++++++++++++
966 
967 int appConfigurator::unusedSections( std::vector<std::string> & sections )
968 {
969  sections.clear();
970 
971  //Wind through all the targets
972  for(auto it = m_unusedConfigs.begin(); it != m_unusedConfigs.end(); ++it)
973  {
974  std::string sect = it->second.section;
975 
976  bool add = true;
977 
978  //Check if this section is already in the vector -- is there a std::algorithms way to do this?
979  for(size_t i=0;i < sections.size(); ++i)
980  {
981  if(sections[i] == sect)
982  {
983  add = false;
984  break;
985  }
986  }
987 
988  //Add it if it wasn't found.
989  if(add) sections.push_back(sect);
990  }
991 
992  return 0;
993 }
994 
995 int appConfigurator::isSetUnused( const std::string & name )
996 {
997  return isSet( name, m_unusedConfigs);
998 }
999 
1000 void writeConfigFile( const std::string & fname,
1001  const std::vector<std::string> & sections,
1002  const std::vector<std::string> & keywords,
1003  const std::vector<std::string> & values
1004  )
1005 {
1006  std::ofstream fout;
1007 
1008  fout.open(fname);
1009 
1010  std::string lastSection;
1011  for(size_t i=0; i< sections.size(); ++i)
1012  {
1013  std::string currSection = sections[i];
1014 
1015  if( currSection != lastSection && currSection != "")
1016  {
1017  fout << "\n[" << currSection << "]\n";
1018  }
1019 
1020  fout << keywords[i] << "=" << values[i] << "\n";
1021 
1022  lastSection = currSection;
1023  }
1024 
1025  fout.close();
1026 
1027  return;
1028 }
1029 
1030 } //namespace app
1031 } //namespace mx
1032 
An application configuration manager.
void writeConfigFile(const std::string &fname, const std::vector< std::string > &sections, const std::vector< std::string > &keywords, const std::vector< std::string > &values)
A simple config file writing function, useful for testing.
The mxlib c++ namespace.
Definition: mxError.hpp:107
std::unordered_map< std::string, configTarget > m_targets
The targets are stored in an unordered_map for fast access by key.
int readConfig(const std::string &fname, bool reportFileNotFound=true)
Read and parse a config/ini file, updating the targets.
void add(const configTarget &tgt)
Add a configTarget.
bool m_sources
Flag controlling whether or not to record config sources.
std::vector< std::string > nonOptions
Non-option arguments from the command line.
int verbosity(const std::string &name, std::unordered_map< std::string, configTarget > &targets)
Get the command line verbosity count for this option.
int isSetUnused(const std::string &name)
Check if a target has been set in the unused configuration.
bool isSet(const std::string &name, std::unordered_map< std::string, configTarget > &targets)
Check if a target has been set by the configuration.
void clear()
Clear the containers and free up the associated memory.
int unusedSections(std::vector< std::string > &sections)
Get the unique sections in the unused config targets.
std::list< configTarget > clOnlyTargets
Targets which are only for the command line are stored separately in a list.
int count(const std::string &name, std::unordered_map< std::string, configTarget > &targets)
Get the number of different values set for the specified config target.
void parseCommandLine(int argc, char **argv, const std::string &oneTarget="")
Parse the command line, updating the targets.
std::unordered_map< std::string, configTarget >::iterator targetIterator
Iterator for the targets unordered_map.
int nAdded
Running count of options added, used to track order.
std::unordered_map< std::string, configTarget > m_unusedConfigs
Config file entries present in the file(s), but not corresponding to a target when parsed....
std::list< configTarget >::iterator clOnlyTargetIterator
Iterator for the clOnlyTargets list.
Command line options parser.
Definition: clOptions.hpp:59
void parse(int argc, char **argv, std::vector< std::string > *nonOptions=0)
Parse the command line.
Definition: clOptions.cpp:104
int numUnknown()
Get the number of unknown options found by the parser.
Definition: clOptions.cpp:252
void add(const std::string &optName, const char *const shortOpt, const char *const longOpt, int argT)
Add a command line option target.
Definition: clOptions.cpp:71
int count(const std::string &key)
Get the number of times the option was set on the command line.
Definition: clOptions.cpp:167
unsigned int nOpts
The number of options added.
Definition: clOptions.hpp:70
void getAll(std::vector< std::string > &args, const std::string &key)
Fill a vector of strings with the arguments supplied for key, last to first.
Definition: clOptions.cpp:176
int unknown(std::vector< std::string > &unk)
Get a vector of the unknown options found by the parser.
Definition: clOptions.cpp:258
bool optSet(const std::string &key)
Test whether this option was set.
Definition: clOptions.cpp:242
A configuration target.
std::string keyword
The config file keyword, read in a "keyword=value" pair.
std::string section
The config file section name, can be empty "".
std::string name
The name of the target.
A wrapper for the ini functions.
Definition: iniFile.hpp:47
size_t count(const std::string &section, const std::string &name)
Get the number of entries for the given section and name.
Definition: iniFile.hpp:141
int erase(const std::string &section, const std::string &name)
Erase the entry for the given section and name.
Definition: iniFile.hpp:153
nameMapT names
The map of section=name keys to values.
Definition: iniFile.hpp:50
static int parseKey(std::string &section, std::string &name, const std::string &key)
Parse a key into its section and name consituents.
Definition: iniFile.hpp:70
int parse(const std::string &fname)
Calls the inih parse function with this->handler.
Definition: iniFile.hpp:94