10#ifndef TEUCHOS_FANCY_O_STREAM_DEF_HPP
11#define TEUCHOS_FANCY_O_STREAM_DEF_HPP
13#include "Teuchos_FancyOStream.hpp"
17RCP<basic_FancyOStream<char> >
19 const RCP< std::basic_ostream<char> >&
oStream,
41getFancyOStream(
const RCP<std::basic_ostream<char> > &out )
52template <
typename CharT,
typename Traits>
57 const std::basic_string<CharT,Traits>
linePrefix
74template <
typename CharT,
typename Traits>
77 const RCP<std::basic_ostream<CharT,Traits> > &out
79 ,
const std::basic_string<CharT,Traits>
linePrefix
95template<
typename CharT,
typename Traits>
97 const RCP<std::basic_ostream<char_type,traits_type> > &
oStream
98 ,
const std::basic_string<char_type,traits_type> &
tabIndentStr
111template<
typename CharT,
typename Traits>
113 const RCP<std::basic_ostream<char_type,traits_type> > &
oStream
114 ,
const std::basic_string<char_type,traits_type> &
tabIndentStr
132 rankPrintWidth_ =
int(std::log10(
float(numProcs_)))+1;
134 tabIndentStack_.clear();
135 linePrefixStack_.clear();
136 wroteNewline_ =
true;
137 enableTabbingStack_ = 0;
141template<
typename CharT,
typename Traits>
149template<
typename CharT,
typename Traits>
158template<
typename CharT,
typename Traits>
159const std::basic_string<CharT,Traits>&
162 return tabIndentStr_;
166template<
typename CharT,
typename Traits>
173template<
typename CharT,
typename Traits>
176 return showLinePrefix_;
180template<
typename CharT,
typename Traits>
188template<
typename CharT,
typename Traits>
191 return maxLenLinePrefix_;
195template<
typename CharT,
typename Traits>
202template<
typename CharT,
typename Traits>
205 return showTabCount_;
209template<
typename CharT,
typename Traits>
216template<
typename CharT,
typename Traits>
219 return showProcRank_;
223template<
typename CharT,
typename Traits>
233template<
typename CharT,
typename Traits>
240template<
typename CharT,
typename Traits>
247template<
typename CharT,
typename Traits>
255 oStream_ = oStreamSet_;
263 oStream_ = oStreamSet_;
266 lineOut_ =
rcp(
new std::ostringstream());
271template<
typename CharT,
typename Traits>
278template<
typename CharT,
typename Traits>
281 if( tabIndent_ +
tabs < 0 ) {
282 tabIndentStack_.push_back(-tabIndent_);
286 tabIndentStack_.push_back(
tabs);
292template<
typename CharT,
typename Traits>
299template<
typename CharT,
typename Traits>
302 tabIndent_ -= tabIndentStack_.back();
303 tabIndentStack_.pop_back();
307template<
typename CharT,
typename Traits>
309 const std::basic_string<char_type,traits_type> &
linePrefix
316template<
typename CharT,
typename Traits>
319 linePrefixStack_.pop_back();
323template<
typename CharT,
typename Traits>
324const std::basic_string<CharT,Traits>&
327 return linePrefixStack_.back();
331template<
typename CharT,
typename Traits>
334 ++enableTabbingStack_;
338template<
typename CharT,
typename Traits>
341 --enableTabbingStack_;
348template<
typename CharT,
typename Traits>
353#ifdef TEUCHOS_FANCY_OSTREAM_SHOW_ALL_CALLS
354 std::cerr <<
"\ncalled xsputn()\n";
361template<
typename CharT,
typename Traits>
365#ifdef TEUCHOS_FANCY_OSTREAM_SHOW_ALL_CALLS
366 std::cerr <<
"\ncalled overflow()\n";
368 if(
c != traits_type::eof()) {
369 const char_type cc[] = { traits_type::to_char_type(
c) };
370 this->writeChars(
cc,1);
372 return traits_type::not_eof(
c);
380template<
typename CharT,
typename Traits>
389template<
typename CharT,
typename Traits>
390void basic_FancyOStream_buf<CharT,Traits>::writeChars(
391 const char_type s[], std::streamsize n
395 std::streamsize p = 0, first_p = 0;
396 bool done_outputting =
false;
397 const char_type newline =
'\n';
398 while( !done_outputting ) {
400 for( p = first_p; p < n; ++p ) {
401 if(s[p] == newline) {
417 wroteNewline_ =
false;
420 out().write(s+first_p,p-first_p+1);
422 wroteNewline_ =
true;
424 *oStream_ << lineOut_->str() << std::flush;
435template<
typename CharT,
typename Traits>
439 std::ostream &o = this->out();
441 o <<
"p=" << std::right << std::setw(rankPrintWidth_) << procRank_;
444 if(showLinePrefix_) {
448 if ( linePrefixStack_.size() )
459 o <<
"tabs=" << std::right << std::setw(2) << tabIndent_;
466 o <<
" |" << tabIndentStr_;
468 if(enableTabbingStack_==0) {
469 for(
int i = 0;
i < tabIndent_; ++
i )
480template<
typename CharT,
typename Traits>
482 const RCP< std::basic_ostream<char_type,traits_type> > &
oStream
483 ,
const std::basic_string<char_type,traits_type> &
tabIndentStr
494 this->init(&streambuf_);
498template<
typename CharT,
typename Traits>
500 const RCP< std::basic_ostream<char_type,traits_type> > &
oStream
501 ,
const std::basic_string<char_type,traits_type> &
tabIndentStr
511 this->init(&streambuf_);
515template<
typename CharT,
typename Traits>
523template<
typename CharT,
typename Traits>
526 const std::basic_string<char_type,traits_type> &
tabIndentStr
534template<
typename CharT,
typename Traits>
535const std::basic_string<CharT,Traits>&
542template<
typename CharT,
typename Traits>
555template<
typename CharT,
typename Traits>
564template<
typename CharT,
typename Traits>
573template<
typename CharT,
typename Traits>
582template<
typename CharT,
typename Traits>
591template<
typename CharT,
typename Traits>
600template<
typename CharT,
typename Traits>
609template<
typename CharT,
typename Traits>
616template<
typename CharT,
typename Traits>
626 oStream.streambuf_.getNumProcs());
631template<
typename CharT,
typename Traits>
638template<
typename CharT,
typename Traits>
645template<
typename CharT,
typename Traits>
652template<
typename CharT,
typename Traits>
654 const std::basic_string<char_type,traits_type> &
linePrefix
661template<
typename CharT,
typename Traits>
668template<
typename CharT,
typename Traits>
669const std::basic_string<CharT,Traits>&
676template<
typename CharT,
typename Traits>
683template<
typename CharT,
typename Traits>
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< 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.
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
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::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
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 ...
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 & 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.
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.
basic_FancyOStream & setMaxLenLinePrefix(const int maxLenLinePrefix)
std::basic_ostream< char_type, traits_type > ostream_t
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.
const std::basic_string< char_type, traits_type > & getTopLinePrefix() const
int getOutputToRootOnly() const
basic_FancyOStream & setShowTabCount(const bool showTabCount)
void pushDisableTabbing()
basic_FancyOStream & setShowProcRank(const bool showProcRank)
void pushTab(const int tabs=1)
Push one or more tabs.
#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_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.