Changeset 11387
- Timestamp:
- 07/13/11 22:44:03 (13 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/Configuration.cc
r11256 r11387 335 335 #include <boost/filesystem.hpp> 336 336 #include <boost/program_options.hpp> 337 #include <boost/lexical_cast.hpp> 337 338 338 339 #define HAS_SQL … … 602 603 } 603 604 604 // -------------------------------------------------------------------------- 605 // 606 //! 607 // 608 void Configuration::PrintOptions() 605 template<class T> 606 string Configuration::VecAsStr(const po::variable_value &v) const 607 { 608 ostringstream str; 609 610 const vector<T> vec = v.as<vector<T>>(); 611 for (typename std::vector<T>::const_iterator s=vec.begin(); s<vec.end(); s++) 612 str << " " << *s; 613 614 return str.str().substr(1); 615 } 616 617 string Configuration::VarAsStr(const po::variable_value &v) const 618 { 619 if (v.value().type()==typeid(bool)) 620 return v.as<bool>() ? "yes ": "no"; 621 622 if (v.value().type()==typeid(string)) 623 return v.as<string>(); 624 625 if (v.value().type()==typeid(int16_t)) 626 return boost::lexical_cast<string>(v.as<int16_t>()); 627 628 if (v.value().type()==typeid(int32_t)) 629 return boost::lexical_cast<string>(v.as<int32_t>()); 630 631 if (v.value().type()==typeid(int64_t)) 632 return boost::lexical_cast<string>(v.as<int64_t>()); 633 634 if (v.value().type()==typeid(uint16_t)) 635 return boost::lexical_cast<string>(v.as<uint16_t>()); 636 637 if (v.value().type()==typeid(uint32_t)) 638 return boost::lexical_cast<string>(v.as<uint32_t>()); 639 640 if (v.value().type()==typeid(uint64_t)) 641 return boost::lexical_cast<string>(v.as<uint64_t>()); 642 643 if (v.value().type()==typeid(float)) 644 return boost::lexical_cast<string>(v.as<float>()); 645 646 if (v.value().type()==typeid(double)) 647 return boost::lexical_cast<string>(v.as<double>()); 648 649 if (v.value().type()==typeid(vector<string>)) 650 return VecAsStr<string>(v); 651 652 if (v.value().type()==typeid(vector<int16_t>)) 653 return VecAsStr<int16_t>(v); 654 655 if (v.value().type()==typeid(vector<int32_t>)) 656 return VecAsStr<int32_t>(v); 657 658 if (v.value().type()==typeid(vector<int64_t>)) 659 return VecAsStr<int64_t>(v); 660 661 if (v.value().type()==typeid(vector<uint16_t>)) 662 return VecAsStr<uint16_t>(v); 663 664 if (v.value().type()==typeid(vector<uint32_t>)) 665 return VecAsStr<uint32_t>(v); 666 667 if (v.value().type()==typeid(vector<uint64_t>)) 668 return VecAsStr<uint64_t>(v); 669 670 if (v.value().type()==typeid(vector<float>)) 671 return VecAsStr<float>(v); 672 673 if (v.value().type()==typeid(vector<double>)) 674 return VecAsStr<double>(v); 675 676 ostringstream str; 677 str << hex << setfill('0') << "0x"; 678 if (v.value().type()==typeid(Hex<uint16_t>)) 679 str << setw(4) << v.as<Hex<uint16_t>>(); 680 681 if (v.value().type()==typeid(Hex<uint32_t>)) 682 str << setw(8) << v.as<Hex<uint32_t>>(); 683 684 if (v.value().type()==typeid(Hex<uint64_t>)) 685 str << setw(16) << v.as<Hex<uint64_t>>(); 686 687 return str.str(); 688 } 689 690 // -------------------------------------------------------------------------- 691 // 692 //! 693 // 694 void Configuration::PrintOptions() const 609 695 { 610 696 cout << "Options propagated to program:" << endl; 611 697 612 698 int maxlen = 0; 613 for (map<string,po::variable_value>:: iterator m=fVariables.begin();699 for (map<string,po::variable_value>::const_iterator m=fVariables.begin(); 614 700 m!=fVariables.end(); m++) 615 701 Max(maxlen, m->first.length()); … … 618 704 619 705 // =============> Implement prining of options in use 620 for (map<string,po::variable_value>:: iterator m=fVariables.begin();706 for (map<string,po::variable_value>::const_iterator m=fVariables.begin(); 621 707 m!=fVariables.end(); m++) 622 708 { 623 cout << setw(maxlen) << m->first << " = ";624 625 709 const po::variable_value &v = m->second; 626 710 711 ostringstream str; 712 627 713 if (v.value().type()==typeid(bool)) 628 cout << (v.as<bool>()?"true":"false") << " # bool"; 629 714 str << " bool"; 630 715 if (v.value().type()==typeid(string)) 631 cout << v.as<string>() << " # string"; 632 633 if (v.value().type()==typeid(int)) 634 cout << v.as<int>() << " # int"; 635 716 str << " string"; 717 if (v.value().type()==typeid(int16_t)) 718 str << " int16_t"; 719 if (v.value().type()==typeid(int32_t)) 720 str << " int32_t"; 721 if (v.value().type()==typeid(int64_t)) 722 str << " int64_t"; 723 if (v.value().type()==typeid(uint16_t)) 724 str << " uint16_t"; 725 if (v.value().type()==typeid(uint32_t)) 726 str << " uint32_t"; 727 if (v.value().type()==typeid(uint64_t)) 728 str << " uint64_t"; 729 if (v.value().type()==typeid(float)) 730 str << " float"; 636 731 if (v.value().type()==typeid(double)) 637 cout << v.as<double>() << " # double"; 638 639 if (v.value().type()==typeid(float)) 640 cout << v.as<float>() << " # float"; 641 732 str << " double"; 733 if (v.value().type()==typeid(Hex<uint16_t>)) 734 str << " Hex<uint16_t>"; 735 if (v.value().type()==typeid(Hex<uint32_t>)) 736 str << " Hex<uint32_t>"; 737 if (v.value().type()==typeid(Hex<uint64_t>)) 738 str << " Hex<uint64_t>"; 642 739 if (v.value().type()==typeid(vector<string>)) 643 { 644 vector<string> vec = v.as<vector<string>>(); 645 for (vector<string>::iterator s=vec.begin(); s<vec.end(); s++) 646 cout << *s << " "; 647 cout << " # strings"; 648 } 740 str << " vector<string>"; 741 if (v.value().type()==typeid(vector<int16_t>)) 742 str << " vector<int16_t>"; 743 if (v.value().type()==typeid(vector<int32_t>)) 744 str << " vector<int32_t>"; 745 if (v.value().type()==typeid(vector<int64_t>)) 746 str << " vector<int64_t>"; 747 if (v.value().type()==typeid(vector<uint16_t>)) 748 str << " vector<uint16_t>"; 749 if (v.value().type()==typeid(vector<uint32_t>)) 750 str << " vector<uint32_t>"; 751 if (v.value().type()==typeid(vector<uint64_t>)) 752 str << " vector<uint64_t>"; 753 if (v.value().type()==typeid(vector<float>)) 754 str << " vector<float>"; 649 755 if (v.value().type()==typeid(vector<double>)) 650 { 651 vector<double> vec = v.as<vector<double>>(); 652 for (vector<double>::iterator s=vec.begin(); s<vec.end(); s++) 653 cout << *s << " "; 654 cout << " # doubles"; 655 } 756 str << " vector<double>"; 757 758 if (str.str().empty()) 759 str << " unknown[" << v.value().type().name() << "]"; 760 761 cout << setw(maxlen) << m->first << " = " << VarAsStr(v); 762 cout << " #" << str.str(); 656 763 657 764 if (v.defaulted()) 658 cout << " # default value";765 cout << " [default]"; 659 766 if (v.empty()) 660 cout << " # empty value";767 cout << " [empty]"; 661 768 662 769 cout << endl; … … 670 777 //! 671 778 // 672 void Configuration::PrintUnknown( vector<string> &vec, int steps)673 { 674 for (vector<string>:: iterator v=vec.begin(); v<vec.end(); v+=steps)779 void Configuration::PrintUnknown(const vector<string> &vec, int steps) const 780 { 781 for (vector<string>::const_iterator v=vec.begin(); v<vec.end(); v+=steps) 675 782 cout << " " << *v << endl; 676 783 cout << endl; 677 784 } 678 785 679 // -------------------------------------------------------------------------- 680 // 681 //! 682 // 683 void Configuration::PrintUnknown() 786 multimap<string, string> Configuration::GetOptions() const 787 { 788 multimap<string,string> rc; 789 790 for (map<string,po::variable_value>::const_iterator m=fVariables.begin(); 791 m!=fVariables.end(); m++) 792 rc.insert(make_pair(m->first, VarAsStr(m->second))); 793 794 return rc; 795 } 796 797 // -------------------------------------------------------------------------- 798 // 799 //! 800 // 801 void Configuration::PrintUnknown() const 684 802 { 685 803 if (fUnknownCommandline.size()) … … 954 1072 if (getfiles.count("print-default") || getfiles.count("print-all")) 955 1073 { 956 if (!indef && defaulted)1074 if (!indef.is_open() && defaulted) 957 1075 cout << "No configuration file by --default option specified." << endl; 958 1076 else -
trunk/FACT++/src/Configuration.h
r11345 r11387 57 57 } 58 58 59 // Helper functions for PrintOptions and GetOptions 60 template<class T> 61 std::string VecAsStr(const po::variable_value &v) const; 62 std::string VarAsStr(const po::variable_value &v) const; 63 59 64 /// Print all options from a list of already parsed options 60 65 void PrintParsed(const po::parsed_options &parsed) const; 61 66 /// Print a list of all unkown options within the given vector 62 void PrintUnknown( std::vector<std::string> &vec, int steps=1);67 void PrintUnknown(const std::vector<std::string> &vec, int steps=1) const; 63 68 64 69 virtual void PrintUsage() const { } … … 105 110 106 111 // Output 107 void PrintOptions(); 108 void PrintUnknown(); 112 void PrintOptions() const; 113 void PrintUnknown() const; 114 115 std::multimap<std::string, std::string> GetOptions() const; 109 116 110 117 // Process command line arguments
Note:
See TracChangeset
for help on using the changeset viewer.