Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-06-18 07:06:22

0001 ///////////////////////////////////////////////////////////////////////////
0002 //
0003 //    Copyright 2010
0004 //
0005 //    This file is part of starlight.
0006 //
0007 //    starlight is free software: you can redistribute it and/or modify
0008 //    it under the terms of the GNU General Public License as published by
0009 //    the Free Software Foundation, either version 3 of the License, or
0010 //    (at your option) any later version.
0011 //    
0012 //    starlight is distributed in the hope that it will be useful,
0013 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
0014 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0015 //    GNU General Public License for more details.
0016 //    
0017 //    You should have received a copy of the GNU General Public License
0018 //    along with starlight. If not, see <http://www.gnu.org/licenses/>.
0019 //
0020 ///////////////////////////////////////////////////////////////////////////
0021 //
0022 // File and Version Information:
0023 // $Rev:: 272                         $: revision of last commit
0024 // $Author:: jnystrand                $: author of last commit
0025 // $Date:: 2016-07-08 17:47:36 +0100 #$: date of last commit
0026 //
0027 // Description:
0028 //      some simple streams for reporting plus some stream operators
0029 //      for common STL classes
0030 //
0031 //
0032 ///////////////////////////////////////////////////////////////////////////
0033 
0034 
0035 #ifndef REPORTINGUTILS_H
0036 #define REPORTINGUTILS_H
0037 
0038 
0039 #include <iostream>
0040 #include <iomanip>
0041 #include <string>
0042 #include <vector>
0043 
0044 
0045 //////////////////////////////////////////////////////////////////////////////
0046 // macros for printing errors, warnings, and infos
0047 
0048 // cuts out block "className::methodName" from __PRETTY_FUNCTION__ output
0049 inline
0050 std::string
0051 getClassMethod__(std::string prettyFunction)
0052 {
0053     size_t pos = prettyFunction.find("(");
0054     if (pos == std::string::npos)
0055         return prettyFunction;           // something is not right
0056     prettyFunction.erase(pos);         // cut away signature
0057     pos = prettyFunction.rfind(" ");
0058     if (pos == std::string::npos)
0059         return prettyFunction;           // something is not right
0060     prettyFunction.erase(0, pos + 1);  // cut away return type
0061     return prettyFunction;
0062 }
0063 
0064 #define printErr  std::cerr << "!!! " << __PRETTY_FUNCTION__ << " [" << __FILE__ << ":" << __LINE__ << "]: ERROR: "   << std::flush
0065 #define printWarn std::cerr << ">>> " << __PRETTY_FUNCTION__ << " [" << __FILE__ << ":" << __LINE__ << "]: "<<std::endl<<"Warning: " << std::flush 
0066 #define printInfo std::cout << ">>> " << getClassMethod__(__PRETTY_FUNCTION__) << "(): Info: "  << std::flush
0067 
0068 
0069 //////////////////////////////////////////////////////////////////////////////
0070 // functions to print version and compilation info
0071 
0072 #ifndef SVN_VERSION  // SVN_VERSION set by Makefile
0073 #define SVN_VERSION "undefined"
0074 #endif
0075 inline std::string svnVersion() { return SVN_VERSION; }
0076 
0077 inline
0078 void
0079 printSvnVersion()
0080 {
0081     const std::string ver = svnVersion();
0082     if (ver == "")
0083         printInfo << "subversion repository revision is unknown." << std::endl;
0084     else
0085       printInfo << "subversion repository revision is '" << ver << "'" << std::endl;
0086 }
0087 
0088 
0089 #ifndef CMAKE_SOURCE_DIR  // CMAKE_SOURCE_DIR set by Makefile
0090 #define CMAKE_SOURCE_DIR "undefined"
0091 #endif
0092 inline std::string compileDir() { return CMAKE_SOURCE_DIR; }
0093 
0094 inline
0095 void
0096 printCompilerInfo()
0097 {
0098     const std::string date = __DATE__;
0099     const std::string time = __TIME__;
0100     const std::string ver  = __VERSION__;
0101     const std::string dir  = compileDir();
0102     printInfo << "this executable was compiled in ";
0103     if (dir != "")
0104         std::cout << "'" << dir << "'";
0105     else
0106         std::cout << "unknown directory";
0107     std::cout << " on " << date << " " << time << " by compiler " << ver << std::endl;
0108 }
0109 
0110 
0111 //////////////////////////////////////////////////////////////////////////////
0112 // simple stream operators for some STL classes
0113 
0114 template<typename T1, typename T2>
0115 inline
0116 std::ostream&
0117 operator << (std::ostream&            out,
0118              const std::pair<T1, T2>& pair)
0119 {
0120     return out << "(" << pair.first << ", " << pair.second << ")";
0121 }
0122     
0123     
0124 template<typename T>
0125 inline
0126 std::ostream&
0127 operator << (std::ostream&         out,
0128              const std::vector<T>& vec)
0129 {
0130     out << "{";
0131     for (unsigned int i = 0; i < (vec.size() - 1); ++i)
0132         out << "[" << i << "] = " << vec[i] << ", ";
0133     return out << "[" << vec.size() - 1 << "] = " << vec[vec.size() - 1] << "}";
0134 }
0135 
0136 
0137 //////////////////////////////////////////////////////////////////////////////
0138 // indicates progess by printing relative or absolute progress in regular intervals
0139 inline
0140 std::ostream&
0141 progressIndicator(const unsigned int currentPos,
0142                   const unsigned int nmbTotal,
0143                   const bool         absolute   = false,
0144                   const unsigned int fieldWidth = 3,
0145                   const unsigned int nmbSteps   = 10,
0146                   std::ostream&      out        = std::cout)
0147 {
0148     const double step = nmbTotal / (double)nmbSteps;
0149     if ((int)(currentPos / step) - (int)((currentPos - 1) / step) != 0) {
0150         if (absolute)
0151             out << "    " << std::setw(fieldWidth) << currentPos << " of " << nmbTotal << std::endl;
0152         else
0153             out << "    " << std::setw(fieldWidth) << (int)(currentPos / step) * nmbSteps << " %" << std::endl;
0154     }
0155     return out;
0156 } 
0157 
0158 
0159 // converts bool to "true"/"false" string
0160 inline
0161 std::string trueFalse(const bool val)
0162 {
0163     if (val)
0164         return "true";
0165     else
0166         return "false";
0167 }
0168 
0169 // converts bool to "yes"/"no" string
0170 inline
0171 std::string yesNo(const bool val)
0172 {
0173     if (val)
0174         return "yes";
0175     else
0176         return "no";
0177 }
0178 
0179 // converts bool to "on"/"off" string
0180 inline
0181 std::string onOff(const bool val)
0182 {
0183     if (val)
0184         return "on";
0185     else
0186         return "off";
0187 }
0188 
0189 // converts bool to "enabled"/"disabled" string
0190 inline
0191 std::string enDisabled(const bool val)
0192 {
0193     if (val)
0194         return "enabled";
0195     else
0196         return "disabled";
0197 }
0198 
0199 
0200 #endif  // REPORTINGUTILS_H