OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
CoutSink.h
Go to the documentation of this file.
1//
2// Class CoutSink
3//
4// Copyright (c) 2010 - 2013, Yves Ineichen, ETH Zürich
5// All rights reserved
6//
7// Implemented as part of the PhD thesis
8// "Toward massively parallel multi-objective optimization with application to
9// particle accelerators" (https://doi.org/10.3929/ethz-a-009792359)
10//
11// This file is part of OPAL.
12//
13// OPAL is free software: you can redistribute it and/or modify
14// it under the terms of the GNU General Public License as published by
15// the Free Software Foundation, either version 3 of the License, or
16// (at your option) any later version.
17//
18// You should have received a copy of the GNU General Public License
19// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
20//
21#ifndef __TRACE_COUT_SINK_H__
22#define __TRACE_COUT_SINK_H__
23
24#include <iostream>
25#include <string>
26
27#include "Util/AnsiColors.h"
29
30class CoutSink : public TraceComponent {
31
32public:
33
34
35 CoutSink(std::string prefix = "")
36 : TraceComponent("CoutSink")
37 , prefix_(prefix) {
38
40 }
41
43 {}
44
45
46 void setColor(std::string color) { color_ = color; }
47 void setClearColor(std::string color) { clear_color_ = color; }
48
49
50 void execute(std::ostringstream &dump) {
51 std::cout << color_ << prefix_
52 << dump.str()
53 << clear_color_ << std::flush;
54 }
55
56private:
57
58 std::string prefix_;
59 std::string color_;
60 std::string clear_color_;
61
62};
63
64#endif
constexpr char Reset[]
Definition AnsiColors.h:5
void execute(std::ostringstream &dump)
Definition CoutSink.h:50
CoutSink(std::string prefix="")
Definition CoutSink.h:35
~CoutSink()
Definition CoutSink.h:42
std::string clear_color_
Definition CoutSink.h:60
std::string prefix_
Definition CoutSink.h:58
void setClearColor(std::string color)
Definition CoutSink.h:47
void setColor(std::string color)
Definition CoutSink.h:46
std::string color_
Definition CoutSink.h:59