42#ifndef TEUCHOS_FANCY_O_STREAM_HPP
43#define TEUCHOS_FANCY_O_STREAM_HPP
47#include "Teuchos_oblackholestream.hpp"
62template<
typename CharT,
typename Traits>
72 typedef typename traits_type::int_type
int_type;
74 typedef typename traits_type::pos_type
pos_type;
76 typedef typename traits_type::off_type
off_type;
80 const RCP<std::basic_ostream<char_type,traits_type> > &
oStream
81 ,
const std::basic_string<char_type,traits_type> &
tabIndentStr
91 const RCP<std::basic_ostream<char_type,traits_type> > &
oStream
92 ,
const std::basic_string<char_type,traits_type> &
tabIndentStr
196 const std::basic_string<char_type,traits_type> &
linePrefix
222#ifdef TEUCHOS_FANCY_OSTREAM_SHOW_ALL_CALLS
226 std::cerr <<
"\ncalled imbue()\n";
227 std::basic_streambuf<CharT,Traits>::imbue(
l);
233 std::cerr <<
"\ncalled setbuf()\n";
234 return std::basic_streambuf<CharT,Traits>::setbuf(
s,n);
238 seekoff(
off_type a, ios_base::seekdir b,ios_base::openmode c)
240 std::cerr <<
"\ncalled seekoff()\n";
241 return std::basic_streambuf<CharT,Traits>::seekoff(a,b,c);
245 seekpos(
pos_type a, ios_base::openmode b)
247 std::cerr <<
"\ncalled seekpos()\n";
248 return std::basic_streambuf<CharT,Traits>::seekpos(a,b);
254 std::cerr <<
"\ncalled sync()\n";
255 return std::basic_streambuf<CharT,Traits>::sync();
261 std::cerr <<
"\ncalled showmanyc()\n";
262 return std::basic_streambuf<CharT,Traits>::showmanyc();
268 std::cerr <<
"\ncalled xsgetn()\n";
269 return std::basic_streambuf<CharT,Traits>::xsgetn(s,n);
275 std::cerr <<
"\ncalled underflow()\n";
276 return std::basic_streambuf<CharT,Traits>::underflow();
282 std::cerr <<
"\ncalled uflow()\n";
283 return std::basic_streambuf<CharT,Traits>::uflow();
289 std::cerr <<
"\ncalled pbackfail()\n";
290 return std::basic_streambuf<CharT,Traits>::pbackfail(c);
302 typedef std::basic_string<char_type,traits_type> string_t;
303 typedef std::deque<int> tabIndentStack_t;
304 typedef std::deque<string_t> linePrefixStack_t;
309 RCP<std::basic_ostream<char_type,traits_type> > oStreamSet_;
310 RCP<std::basic_ostream<char_type,traits_type> > oStream_;
311 std::basic_string<char_type,traits_type> tabIndentStr_;
312 bool showLinePrefix_;
313 int maxLenLinePrefix_;
321 RCP<std::ostringstream> lineOut_;
324 tabIndentStack_t tabIndentStack_;
325 linePrefixStack_t linePrefixStack_;
326 int enableTabbingStack_;
335 void writeChars(
const char_type s[], std::streamsize n );
337 void writeFrontMatter();
342 basic_FancyOStream_buf<CharT,Traits> operator=(
343 const basic_FancyOStream_buf<CharT,Traits>&
380template <
typename CharT,
typename Traits = std::
char_traits<CharT> >
403 typedef std::basic_ostream<char_type, traits_type>
ostream_t;
441 const RCP< std::basic_ostream<char_type,traits_type> > &
oStream
442 ,
const std::basic_string<char_type,traits_type> &
tabIndentStr =
" "
454 const RCP< std::basic_ostream<char_type,traits_type> > &
oStream
455 ,
const std::basic_string<char_type,traits_type> &
tabIndentStr =
" "
468 const std::basic_string<char_type,traits_type> &
tabIndentStr
598 const RCP< std::basic_ostream<char> >&
oStream,
632 return Teuchos::null;
652template <
typename CharT,
typename Traits = std::
char_traits<CharT> >
663 ,
const std::basic_string<CharT,Traits>
linePrefix =
""
665 :fancyOStream_(fancyOStream)
673 const RCP<std::basic_ostream<CharT,Traits> > &
oStream
675 ,
const std::basic_string<CharT,Traits>
linePrefix =
""
677 :fancyOStream_(getFancyOStream(
oStream))
687 ,
const std::basic_string<CharT,Traits>
linePrefix =
""
689 :fancyOStream_(
rcp(&fancyOStream,
false))
697 std::basic_ostream<CharT,Traits> &
oStream
699 ,
const std::basic_string<CharT,Traits>
linePrefix =
""
709 :fancyOStream_(
osTab.fancyOStream_)
717 if(fancyOStream_.
get()) {
719 fancyOStream_->popDisableTabbing();
721 fancyOStream_->popTab();
722 if(linePrefix_.length()) fancyOStream_->popLinePrefix();
728 fancyOStream_ =
osTab.fancyOStream_;
737 if(fancyOStream_.
get()) {
738 fancyOStream_->popTab();
739 fancyOStream_->pushTab(tabs_);
746 return *fancyOStream_;
751 return fancyOStream_.
get();
758 std::basic_string<CharT,Traits> linePrefix_;
762 if(fancyOStream_.
get()) {
764 fancyOStream_->pushDisableTabbing();
766 fancyOStream_->pushTab(tabs_);
767 if(linePrefix_.length()) fancyOStream_->pushLinePrefix(linePrefix_);
789template <
typename CharT,
typename Traits>
790RCP<basic_FancyOStream<CharT,Traits> >
794 const std::basic_string<CharT,Traits>
linePrefix =
""
798 return Teuchos::null;
826template <
typename CharT,
typename Traits>
829 const RCP<std::basic_ostream<CharT,Traits> > &out
831 ,
const std::basic_string<CharT,Traits>
linePrefix =
""
857#define TEUCHOS_OSTAB ::Teuchos::OSTab __localThisTab = this->getOSTab()
862#define TEUCHOS_OSTAB_DIFF( DIFF ) ::Teuchos::OSTab DIFF ## __localThisTab = this->getOSTab()
874template<
typename CharT,
typename Traits>
876 const RCP<std::basic_ostream<char_type,traits_type> > &
oStream
877 ,
const std::basic_string<char_type,traits_type> &
tabIndentStr
890template<
typename CharT,
typename Traits>
892 const RCP<std::basic_ostream<char_type,traits_type> > &
oStream
893 ,
const std::basic_string<char_type,traits_type> &
tabIndentStr
911 rankPrintWidth_ =
int(std::log10(
float(numProcs_)))+1;
913 tabIndentStack_.clear();
914 linePrefixStack_.clear();
915 wroteNewline_ =
true;
916 enableTabbingStack_ = 0;
920template<
typename CharT,
typename Traits>
928template<
typename CharT,
typename Traits>
930 const std::basic_string<char_type,traits_type> &
tabIndentStr
937template<
typename CharT,
typename Traits>
938const std::basic_string<CharT,Traits>&
941 return tabIndentStr_;
945template<
typename CharT,
typename Traits>
952template<
typename CharT,
typename Traits>
955 return showLinePrefix_;
959template<
typename CharT,
typename Traits>
967template<
typename CharT,
typename Traits>
970 return maxLenLinePrefix_;
974template<
typename CharT,
typename Traits>
981template<
typename CharT,
typename Traits>
984 return showTabCount_;
988template<
typename CharT,
typename Traits>
995template<
typename CharT,
typename Traits>
998 return showProcRank_;
1002template<
typename CharT,
typename Traits>
1012template<
typename CharT,
typename Traits>
1019template<
typename CharT,
typename Traits>
1026template<
typename CharT,
typename Traits>
1034 oStream_ = oStreamSet_;
1042 oStream_ = oStreamSet_;
1045 lineOut_ =
rcp(
new std::ostringstream());
1050template<
typename CharT,
typename Traits>
1057template<
typename CharT,
typename Traits>
1060 if( tabIndent_ +
tabs < 0 ) {
1061 tabIndentStack_.push_back(-tabIndent_);
1065 tabIndentStack_.push_back(
tabs);
1071template<
typename CharT,
typename Traits>
1078template<
typename CharT,
typename Traits>
1081 tabIndent_ -= tabIndentStack_.back();
1082 tabIndentStack_.pop_back();
1086template<
typename CharT,
typename Traits>
1088 const std::basic_string<char_type,traits_type> &
linePrefix
1095template<
typename CharT,
typename Traits>
1098 linePrefixStack_.pop_back();
1102template<
typename CharT,
typename Traits>
1103const std::basic_string<CharT,Traits>&
1106 return linePrefixStack_.back();
1110template<
typename CharT,
typename Traits>
1113 ++enableTabbingStack_;
1117template<
typename CharT,
typename Traits>
1120 --enableTabbingStack_;
1127template<
typename CharT,
typename Traits>
1132#ifdef TEUCHOS_FANCY_OSTREAM_SHOW_ALL_CALLS
1133 std::cerr <<
"\ncalled xsputn()\n";
1140template<
typename CharT,
typename Traits>
1144#ifdef TEUCHOS_FANCY_OSTREAM_SHOW_ALL_CALLS
1145 std::cerr <<
"\ncalled overflow()\n";
1147 if(
c != traits_type::eof()) {
1148 const char_type cc[] = { traits_type::to_char_type(
c) };
1149 this->writeChars(
cc,1);
1151 return traits_type::not_eof(
c);
1159template<
typename CharT,
typename Traits>
1168template<
typename CharT,
typename Traits>
1169void basic_FancyOStream_buf<CharT,Traits>::writeChars(
1170 const char_type s[], std::streamsize n
1174 std::streamsize
p = 0,
first_p = 0;
1176 const char_type
newline =
'\n';
1196 wroteNewline_ =
false;
1201 wroteNewline_ =
true;
1202 if(lineOut_.get()) {
1203 *oStream_ << lineOut_->str() << std::flush;
1214template<
typename CharT,
typename Traits>
1215void basic_FancyOStream_buf<CharT,Traits>::writeFrontMatter()
1218 std::ostream &o = this->out();
1220 o <<
"p=" << std::right << std::setw(rankPrintWidth_) << procRank_;
1223 if(showLinePrefix_) {
1227 if ( linePrefixStack_.size() )
1238 o <<
"tabs=" << std::right << std::setw(2) << tabIndent_;
1245 o <<
" |" << tabIndentStr_;
1247 if(enableTabbingStack_==0) {
1248 for(
int i = 0;
i < tabIndent_; ++
i )
1259template<
typename CharT,
typename Traits>
1261 const RCP< std::basic_ostream<char_type,traits_type> > &
oStream
1262 ,
const std::basic_string<char_type,traits_type> &
tabIndentStr
1273 this->init(&streambuf_);
1277template<
typename CharT,
typename Traits>
1279 const RCP< std::basic_ostream<char_type,traits_type> > &
oStream
1280 ,
const std::basic_string<char_type,traits_type> &
tabIndentStr
1290 this->init(&streambuf_);
1294template<
typename CharT,
typename Traits>
1298 return streambuf_.getOStream();
1302template<
typename CharT,
typename Traits>
1305 const std::basic_string<char_type,traits_type> &
tabIndentStr
1313template<
typename CharT,
typename Traits>
1314const std::basic_string<CharT,Traits>&
1317 return streambuf_.getTabIndentStr();
1321template<
typename CharT,
typename Traits>
1334template<
typename CharT,
typename Traits>
1343template<
typename CharT,
typename Traits>
1352template<
typename CharT,
typename Traits>
1361template<
typename CharT,
typename Traits>
1370template<
typename CharT,
typename Traits>
1379template<
typename CharT,
typename Traits>
1388template<
typename CharT,
typename Traits>
1391 return streambuf_.getOutputToRootOnly();
1395template<
typename CharT,
typename Traits>
1400 streambuf_.setShowLinePrefix(
oStream.streambuf_.getShowLinePrefix());
1401 streambuf_.setMaxLenLinePrefix(
oStream.streambuf_.getMaxLenLinePrefix());
1402 streambuf_.setShowTabCount(
oStream.streambuf_.getShowTabCount());
1403 streambuf_.setShowProcRank(
oStream.streambuf_.getShowProcRank());
1404 streambuf_.setProcRankAndSize(
oStream.streambuf_.getProcRank(),
1405 oStream.streambuf_.getNumProcs());
1406 streambuf_.setOutputToRootOnly(
oStream.streambuf_.getOutputToRootOnly());
1410template<
typename CharT,
typename Traits>
1413 streambuf_.pushTab(
tabs);
1417template<
typename CharT,
typename Traits>
1420 return streambuf_.getNumCurrTabs();
1424template<
typename CharT,
typename Traits>
1427 streambuf_.popTab();
1431template<
typename CharT,
typename Traits>
1433 const std::basic_string<char_type,traits_type> &
linePrefix
1440template<
typename CharT,
typename Traits>
1443 streambuf_.popLinePrefix();
1447template<
typename CharT,
typename Traits>
1448const std::basic_string<CharT,Traits>&
1451 return streambuf_.getTopLinePrefix();
1455template<
typename CharT,
typename Traits>
1458 streambuf_.pushDisableTabbing();
1462template<
typename CharT,
typename Traits>
1465 return streambuf_.popDisableTabbing();
A MPI utilities class, providing methods for initializing, finalizing, and querying the global MPI se...
Reference-counted pointer class and non-member templated function implementations.
Definition of Teuchos::as, for conversions between types.
static int getRank()
The rank of the calling process in MPI_COMM_WORLD.
static int getNProc()
The number of processes in MPI_COMM_WORLD.
Smart reference counting pointer class for automatic garbage collection.
RCP(ENull null_arg=null)
Initialize RCP<T> to NULL.
RCP< T > rcp(const boost::shared_ptr< T > &sptr)
Conversion function that takes in a boost::shared_ptr object and spits out a Teuchos::RCP object.
T * get() const
Get the raw C++ pointer to the underlying object.
Stream buffering class that performs the magic of indenting data sent to an std::ostream object.
int_type overflow(int_type c)
int getNumProcs() const
Get the number of processes in the communicator.
void popTab()
Pop the current tab.
void setShowProcRank(const bool showProcRank)
void setOutputToRootOnly(const int rootRank)
Set the stream to print only on the (MPI) process with the given rank.
int getMaxLenLinePrefix() const
RCP< std::basic_ostream< char_type, traits_type > > getOStream()
const std::basic_string< char_type, traits_type > & getTabIndentStr() const
void setTabIndentStr(const std::basic_string< char_type, traits_type > &tabIndentStr)
void setShowTabCount(const bool showTabCount)
int getNumCurrTabs() const
void pushLinePrefix(const std::basic_string< char_type, traits_type > &linePrefix)
void setProcRankAndSize(const int procRank, const int numProcs)
Set the (MPI) process rank and the number of processes in the communicator.
bool getShowProcRank() const
traits_type::pos_type pos_type
void pushDisableTabbing()
int getProcRank() const
Get the rank of the calling (MPI) process.
void setMaxLenLinePrefix(const int maxLenLinePrefix)
int getOutputToRootOnly() const
void pushTab(const int tabs)
Push one or more tabs.
bool getShowLinePrefix() const
traits_type::off_type off_type
traits_type::int_type int_type
const std::basic_string< char_type, traits_type > & getTopLinePrefix() const
void initialize(const RCP< std::basic_ostream< char_type, traits_type > > &oStream, const std::basic_string< char_type, traits_type > &tabIndentStr, const int startingTab, const bool showLinePrefix, const int maxLenLinePrefix, const bool showTabCount, const bool showProcRank)
void setShowLinePrefix(const bool showLinePrefix)
bool getShowTabCount() const
basic_FancyOStream_buf(const RCP< std::basic_ostream< char_type, traits_type > > &oStream, const std::basic_string< char_type, traits_type > &tabIndentStr, const int startingTab, const bool showLinePrefix, const int maxLenLinePrefix, const bool showTabCount, const bool showProcRank)
std::streamsize xsputn(const char_type *s, std::streamsize n)
std::ostream subclass that performs the magic of indenting data sent to an std::ostream object among ...
traits_type::off_type off_type
void initialize(const RCP< std::basic_ostream< char_type, traits_type > > &oStream, const std::basic_string< char_type, traits_type > &tabIndentStr=" ", const int startingTab=0, const bool showLinePrefix=false, const int maxLenLinePrefix=10, const bool showTabCount=false, const bool showProcRank=false)
Initialize the output stream.
basic_FancyOStream & setTabIndentStr(const std::basic_string< char_type, traits_type > &tabIndentStr)
Set the tab indent string.
basic_FancyOStream & setShowAllFrontMatter(const bool showAllFrontMatter)
Control whether this stream prints "front matter.".
basic_FancyOStream & setProcRankAndSize(const int procRank, const int numProcs)
Set the (MPI) process rank and the number of processes in the communicator.
void popTab()
Pop the current tab.
traits_type::pos_type pos_type
int getNumCurrTabs() const
const std::basic_string< char_type, traits_type > & getTabIndentStr() const
Get the tab indent string.
basic_FancyOStream & setOutputToRootOnly(const int rootRank)
Set the stream to print only on the (MPI) process with the given rank.
RCP< basic_FancyOStream< CharT, Traits > > tab(const RCP< basic_FancyOStream< CharT, Traits > > &out, const int tabs=1, const std::basic_string< CharT, Traits > linePrefix="")
Create a tab for an RCP-wrapped basic_FancyOStream object to cause the indentation of all output auto...
basic_FancyOStream & setMaxLenLinePrefix(const int maxLenLinePrefix)
std::basic_ostream< char_type, traits_type > ostream_t
traits_type::int_type int_type
void pushLinePrefix(const std::basic_string< char_type, traits_type > &linePrefix)
basic_FancyOStream & setShowLinePrefix(const bool showLinePrefix)
RCP< std::basic_ostream< char_type, traits_type > > getOStream()
Get the output stream this object wraps.
basic_FancyOStream(const RCP< std::basic_ostream< char_type, traits_type > > &oStream, const std::basic_string< char_type, traits_type > &tabIndentStr=" ", const int startingTab=0, const bool showLinePrefix=false, const int maxLenLinePrefix=10, const bool showTabCount=false, const bool showProcRank=false)
Constructor.
const std::basic_string< char_type, traits_type > & getTopLinePrefix() const
basic_FancyOStream_buf< CharT, Traits > streambuf_t
void copyAllOutputOptions(const basic_FancyOStream< CharT, Traits > &oStream)
int getOutputToRootOnly() const
basic_FancyOStream & setShowTabCount(const bool showTabCount)
void pushDisableTabbing()
RCP< basic_FancyOStream< char > > fancyOStream(const RCP< std::basic_ostream< char > > &oStream, const std::basic_string< char > &tabIndentStr=" ", const int startingTab=0, const bool showLinePrefix=false, const int maxLenLinePrefix=10, const bool showTabCount=false, const bool showProcRank=false)
Dynamically allocate a FancyOStream and return it wrapped in an RCP object.
basic_FancyOStream & setShowProcRank(const bool showProcRank)
RCP< basic_FancyOStream< char > > getFancyOStream(const RCP< std::basic_ostream< char > > &out)
Get a FancyOStream from an std::ostream object.
RCP< basic_FancyOStream< CharT, Traits > > tab(const RCP< std::basic_ostream< CharT, Traits > > &out, const int tabs=1, const std::basic_string< CharT, Traits > linePrefix="")
Create a tab for an RCP-wrapped std:: std::ostream object to cause the indentation of all output auto...
void pushTab(const int tabs=1)
Push one or more tabs.
Tabbing class for helping to create formated, indented output for a basic_FancyOStream object.
basic_FancyOStream< CharT, Traits > * get() const
basic_OSTab(std::basic_ostream< CharT, Traits > &oStream, const int tabs=1, const std::basic_string< CharT, Traits > linePrefix="")
Warning: Only call this constructor for stack-based object.
static const int DISABLE_TABBING
basic_OSTab(basic_FancyOStream< CharT, Traits > &fancyOStream, const int tabs=1, const std::basic_string< CharT, Traits > linePrefix="")
Warning: Only call this constructor for stack-based object.
basic_OSTab< CharT, Traits > & operator=(const basic_OSTab &osTab)
basic_OSTab(const RCP< basic_FancyOStream< CharT, Traits > > &fancyOStream, const int tabs=1, const std::basic_string< CharT, Traits > linePrefix="")
basic_OSTab< CharT, Traits > & incrTab(const int tabs=1)
basic_FancyOStream< CharT, Traits > & o() const
basic_OSTab(const RCP< std::basic_ostream< CharT, Traits > > &oStream, const int tabs=1, const std::basic_string< CharT, Traits > linePrefix="")
basic_OSTab(const basic_OSTab &osTab)
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
This macro is designed to be a short version of TEUCHOS_TEST_FOR_EXCEPTION() that is easier to call.
bool is_null(const std::shared_ptr< T > &p)
Returns true if p.get()==NULL.
bool nonnull(const std::shared_ptr< T > &p)
Returns true if p.get()!=NULL.
basic_FancyOStream< char > FancyOStream
basic_OSTab< char > OSTab
basic_oblackholestream< char, std::char_traits< char > > oblackholestream
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.