gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-252-gf9a3f78
a Global And Modular Bsm Inference Tool
logger.hpp
Go to the documentation of this file.
1 // GAMBIT: Global and Modular BSM Inference Tool
2 // *********************************************
25 
26 #ifndef __logger_hpp__
27 #define __logger_hpp__
28 
29 #include <sstream>
30 #include <string>
31 #include <map>
32 #include <set>
33 #include "gambit/Logs/log_tags.hpp"
35 
36 namespace Gambit
37 {
39  namespace Logging
40  {
41  class LogMaster;
43  struct endofmessage {};
44 
45  // Function to do the reverse search of tag map (brute force)
46  int str2tag(const std::string&);
47 
48  // Function to retrieve the 'tag2str' map outside of this compilation unit
49  // (needed by module and backend macros so they can add to it)
50  std::map<int,std::string>& tag2str();
51 
52  // Function to retrieve the 'components' set (needed by module and backend macros so they can add to it)
53  std::set<int>& components();
54 
55  // Typedefs for standard stream manpulators. We need stream operator overloads for all of them.
56  typedef std::ostream& (*manip1)( std::ostream& );
57  typedef std::basic_ios< std::ostream::char_type, std::ostream::traits_type > ios_type;
58  typedef ios_type& (*manip2)( ios_type& );
59  typedef std::ios_base& (*manip3)( std::ios_base& );
60 
62  LogMaster& operator<<(LogMaster&, const std::string&);
65  // Overloads for stream manipulators (typedefs above)
69 
70  // Stream function to convert everything else to strings before
71  // feeding into LogMaster (this way no-one needs to have the full
72  // declaration of the LogMaster class; I think the overhead
73  // should be negligible and is worth the segregation).
74  // Use 'ostringstream' so that any type with an ostream operator defined
75  // will be able to stream into the loggers.
76  template <typename TYPE>
77  LogMaster& operator << (LogMaster& logobj, const TYPE& input)
78  {
79  using ::Gambit::operator<<; // Unhide operator overloads in Gambit scope
80  std::stringstream ss;
81  ss << input;
82  logobj << ss.str();
83  return logobj;
84  }
85  // Non-const copy
86  template <typename TYPE>
87  LogMaster& operator << (LogMaster& logobj, TYPE& input)
88  {
89  using ::Gambit::operator<<; // Unhide operator overloads in Gambit scope
90  std::stringstream ss;
91  ss << input;
92  logobj << ss.str();
93  return logobj;
94  }
96  }
97 
100 
103 
104 }
105 
106 #endif /* defined(__logger_hpp__) */
Define overloadings of the stream operator for various containers.
std::basic_ios< std::ostream::char_type, std::ostream::traits_type > ios_type
Definition: logger.hpp:57
std::map< int, std::string > & tag2str()
Definition: logging.cpp:130
LogMaster & operator<<(LogMaster &, const std::string &)
Stream functions for use with LogMaster.
Definition: logger.cpp:52
int str2tag(const std::string &)
Definition: logging.cpp:152
std::set< int > & components()
Definition: logging.cpp:81
Headeer for logging classes.
std::ostream &(* manip1)(std::ostream &)
Definition: logger.hpp:56
const Logging::endofmessage EOM
Explicit const instance of the end of message struct in Gambit namespace.
Definition: logger.hpp:99
Logging::LogMaster & logger()
Function to retrieve a reference to the Gambit global log object.
Definition: logger.cpp:95
Logging "controller" object Keeps track of the various "Logger" objects.
Definition: logmaster.hpp:49
Special (empty) struct for signalling end of message to LogMaster stream.
Definition: logger.hpp:43
TODO: see if we can use this one:
Definition: Analysis.hpp:33
std::ios_base &(* manip3)(std::ios_base &)
Definition: logger.hpp:59
ios_type &(* manip2)(ios_type &)
Definition: logger.hpp:58