Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:58:04

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // G4coutDestination
0027 //
0028 // Class description:
0029 //
0030 // Cout/cerr buffer containers
0031 
0032 // Authors: H.Yoshida, M.Nagamatu - November 1998
0033 // --------------------------------------------------------------------
0034 #ifndef G4COUTDESTINATION_HH
0035 #define G4COUTDESTINATION_HH 1
0036 
0037 #include <algorithm>
0038 #include <functional>
0039 #include <iostream>
0040 #include <vector>
0041 
0042 #include "globals.hh"
0043 
0044 class G4coutDestination
0045 {
0046  public:
0047 
0048   G4coutDestination() = default;
0049   virtual ~G4coutDestination() = default;
0050 
0051   // The type of the functions defining a transformation of the message.
0052   // The function manipulates the input message, for example, to add a
0053   // prefix:
0054   //    G4coutDestination::AddCoutTransformer(
0055   //       [](G4String& msg) -> G4bool { msg="PREFIX "+msg; return true; }
0056   //    );
0057   // Function should return false if message should not be processed
0058   // anymore and discarded
0059   //
0060   using Transformer = std::function<G4bool(G4String&)>;
0061 
0062   void AddDebugTransformer(const Transformer& t)
0063   {
0064     transformersDebug.push_back(t);
0065   }
0066   void AddDebugTransformer(Transformer&& t) { transformersDebug.push_back(t); }
0067 
0068   void AddCoutTransformer(const Transformer& t)
0069   {
0070     transformersCout.push_back(t);
0071   }
0072   void AddCoutTransformer(Transformer&& t) { transformersCout.push_back(t); }
0073 
0074   void AddCerrTransformer(const Transformer& t)
0075   {
0076     transformersCerr.push_back(t);
0077   }
0078   void AddCerrTransformer(Transformer&& t) { transformersCerr.push_back(t); }
0079   virtual void ResetTransformers();
0080 
0081   virtual G4int ReceiveG4debug(const G4String& msg);
0082   virtual G4int ReceiveG4cout(const G4String& msg);
0083   virtual G4int ReceiveG4cerr(const G4String& msg);
0084   // Derived class implements here handling of message.
0085   // For example, streaming on std::cout or file.
0086   // Return 0 for success, -1 otherwise
0087 
0088   // Called by G4debug stream to handle log message
0089   G4int ReceiveG4debug_(const G4String& msg);
0090 
0091   G4int ReceiveG4cout_(const G4String& msg);
0092   // Method called by G4strbuf when need to handle a message
0093 
0094   G4int ReceiveG4cerr_(const G4String& msg);
0095   // Transformers cannot remove an error message from stream
0096 
0097  protected:
0098 
0099   G4MTGLOB_DLL static G4coutDestination* masterG4coutDestination;
0100   // For MT: if master G4coutDestination derived class wants to
0101   // intercept the thread outputs, derived class should set this pointer.
0102   // Needed for some G4UIsession like GUIs
0103   std::vector<Transformer> transformersDebug;
0104   std::vector<Transformer> transformersCout;
0105   std::vector<Transformer> transformersCerr;
0106 };
0107 
0108 #endif