OPAL (Object Oriented Parallel Accelerator Library) 2022.1
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
28
29class CoutSink : public TraceComponent {
30
31public:
32
33
34 CoutSink(std::string prefix = "")
35 : TraceComponent("CoutSink")
36 , prefix_(prefix) {
37
38 clear_color_ = "\e[0m";
39 }
40
42 {}
43
44
45 void setColor(std::string color) { color_ = color; }
46 void setClearColor(std::string color) { clear_color_ = color; }
47
48
49 void execute(std::ostringstream &dump) {
50 std::cout << color_ << prefix_
51 << dump.str()
52 << clear_color_ << std::flush;
53 }
54
55private:
56
57 std::string prefix_;
58 std::string color_;
59 std::string clear_color_;
60
61};
62
63#endif
void execute(std::ostringstream &dump)
Definition: CoutSink.h:49
CoutSink(std::string prefix="")
Definition: CoutSink.h:34
~CoutSink()
Definition: CoutSink.h:41
std::string clear_color_
Definition: CoutSink.h:59
std::string prefix_
Definition: CoutSink.h:57
void setClearColor(std::string color)
Definition: CoutSink.h:46
void setColor(std::string color)
Definition: CoutSink.h:45
std::string color_
Definition: CoutSink.h:58