https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ConsoleStream.h
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#pragma once
11
12// MOOSE includes
13class OutputWarehouse;
14
15// C++ includes
16#include <iostream>
17#include <sstream>
18#include <memory>
19#include <mutex>
20
21// this is the type of s t d :: c o u t
22typedef std::basic_ostream<char, std::char_traits<char>> CoutType;
23
24// this is the function signature of std::endl
25typedef CoutType & (*StandardEndLine)(CoutType &);
26
31{
32public:
41 ConsoleStream(OutputWarehouse & output_warehouse);
42
50 template <typename StreamType>
51 const ConsoleStream & operator<<(const StreamType & s) const;
52
56 const ConsoleStream & operator<<(const StandardEndLine & manip) const;
57
61 void unsetf(std::ios_base::fmtflags mask) const;
62
63 std::streampos tellp() const { return _oss->tellp(); }
64
68 std::streamsize precision() const;
69
73 std::streamsize precision(std::streamsize new_precision) const;
74
78 std::ios_base::fmtflags flags() const;
79
83 std::ios_base::fmtflags flags(std::ios_base::fmtflags new_flags) const;
84
88 unsigned long long int numPrinted() const;
89
90private:
93
98 mutable std::shared_ptr<std::ostringstream> _oss;
99
101 static std::mutex _stream_mutex;
102};
103
104template <typename StreamType>
106ConsoleStream::operator<<(const StreamType & s) const
107{
108 std::lock_guard<std::mutex> lock(_stream_mutex);
109
110 (*_oss) << s;
111 return *this;
112}
std::basic_ostream< char, std::char_traits< char > > CoutType
CoutType &(* StandardEndLine)(CoutType &)
A helper class for re-directing output streams to Console output objects form MooseObjects.
const ConsoleStream & operator<<(const StreamType &s) const
The output stream operator.
unsigned long long int numPrinted() const
The number of times something has been printed.
static std::mutex _stream_mutex
Mutex to prevent concurrent read/writes, write/writes.
std::ios_base::fmtflags flags() const
Return the current flags.
std::streamsize precision() const
Return the current precision.
OutputWarehouse & _output_warehouse
Reference to the OutputWarhouse that contains the Console output objects.
std::streampos tellp() const
std::shared_ptr< std::ostringstream > _oss
The stream for buffering the message This stupidly has to be a shared pointer because of something in...
void unsetf(std::ios_base::fmtflags mask) const
Unset format flags.
Class for storing and utilizing output objects.