gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-2191-ga4742ac
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"
36 
37 namespace Gambit
38 {
40  namespace Logging
41  {
42  class LogMaster;
44  struct endofmessage {};
45 
46  // Function to do the reverse search of tag map (brute force)
47  int str2tag(const std::string&);
48 
49  // Function to retrieve the 'tag2str' map outside of this compilation unit
50  // (needed by module and backend macros so they can add to it)
51  std::map<int,std::string>& tag2str();
52 
53  // Function to retrieve the 'components' set (needed by module and backend macros so they can add to it)
54  std::set<int>& components();
55 
56  // Typedefs for standard stream manpulators. We need stream operator overloads for all of them.
57  typedef std::ostream& (*manip1)( std::ostream& );
58  typedef std::basic_ios< std::ostream::char_type, std::ostream::traits_type > ios_type;
59  typedef ios_type& (*manip2)( ios_type& );
60  typedef std::ios_base& (*manip3)( std::ios_base& );
61 
63  EXPORT_SYMBOLS LogMaster& operator<<(LogMaster&, const std::string&);
66  // Overloads for stream manipulators (typedefs above)
70 
71  // Stream function to convert everything else to strings before
72  // feeding into LogMaster (this way no-one needs to have the full
73  // declaration of the LogMaster class; I think the overhead
74  // should be negligible and is worth the segregation).
75  // Use 'ostringstream' so that any type with an ostream operator defined
76  // will be able to stream into the loggers.
77  template <typename TYPE>
78  LogMaster& operator << (LogMaster& logobj, const TYPE& input)
79  {
80  using ::Gambit::operator<<; // Unhide operator overloads in Gambit scope
81  std::stringstream ss;
82  ss << input;
83  logobj << ss.str();
84  return logobj;
85  }
86  // Non-const copy
87  template <typename TYPE>
88  LogMaster& operator << (LogMaster& logobj, TYPE& input)
89  {
90  using ::Gambit::operator<<; // Unhide operator overloads in Gambit scope
91  std::stringstream ss;
92  ss << input;
93  logobj << ss.str();
94  return logobj;
95  }
97  }
98 
101 
104 
105 }
106 
107 #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:58
std::map< int, std::string > & tag2str()
Definition: logging.cpp:130
#define EXPORT_SYMBOLS
EXPORT_SYMBOLS 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:57
const Logging::endofmessage EOM
Explicit const instance of the end of message struct in Gambit namespace.
Definition: logger.hpp:100
EXPORT_SYMBOLS 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:44
Helper macro for controlling symbol visibility in shared libraries.
TODO: see if we can use this one:
Definition: Analysis.hpp:33
std::ios_base &(* manip3)(std::ios_base &)
Definition: logger.hpp:60
ios_type &(* manip2)(ios_type &)
Definition: logger.hpp:59