10#ifndef TEUCHOS_FANCY_O_STREAM_DEF_HPP
11#define TEUCHOS_FANCY_O_STREAM_DEF_HPP
13#include "Teuchos_FancyOStream.hpp"
19 const RCP< std::basic_ostream<char> >& oStream,
20 const std::basic_string<char>& tabIndentStr,
21 const int startingTab,
22 const bool showLinePrefix,
23 const int maxLenLinePrefix,
24 const bool showTabCount,
25 const bool showProcRank
31 oStream,tabIndentStr,startingTab,showLinePrefix,
32 maxLenLinePrefix,showTabCount,showProcRank
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
82 return tab(getFancyOStream(out),tabs,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
99 ,
const int startingTab
100 ,
const bool showLinePrefix
101 ,
const int maxLenLinePrefix
102 ,
const bool showTabCount
103 ,
const bool showProcRank
106 this->
initialize(oStream,tabIndentStr,startingTab,showLinePrefix,
107 maxLenLinePrefix,showTabCount,showProcRank);
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
115 ,
const int startingTab
116 ,
const bool showLinePrefix
117 ,
const int maxLenLinePrefix
118 ,
const bool showTabCount
119 ,
const bool showProcRank
122 oStreamSet_ = oStream;
124 tabIndentStr_ = tabIndentStr;
125 showLinePrefix_ = showLinePrefix;
126 maxLenLinePrefix_ = maxLenLinePrefix;
127 showTabCount_ = showTabCount;
128 showProcRank_ = showProcRank;
132 rankPrintWidth_ = int(std::log10(
float(numProcs_)))+1;
133 tabIndent_ = startingTab;
134 tabIndentStack_.clear();
135 linePrefixStack_.clear();
136 wroteNewline_ =
true;
137 enableTabbingStack_ = 0;
141template<
typename CharT,
typename Traits>
149template<
typename CharT,
typename Traits>
151 const std::basic_string<char_type,traits_type> &tabIndentStr
154 tabIndentStr_ = tabIndentStr;
158template<
typename CharT,
typename Traits>
159const std::basic_string<CharT,Traits>&
162 return tabIndentStr_;
166template<
typename CharT,
typename Traits>
169 showLinePrefix_ = showLinePrefix;
173template<
typename CharT,
typename Traits>
176 return showLinePrefix_;
180template<
typename CharT,
typename Traits>
184 maxLenLinePrefix_ = maxLenLinePrefix;
188template<
typename CharT,
typename Traits>
191 return maxLenLinePrefix_;
195template<
typename CharT,
typename Traits>
198 showTabCount_ = showTabCount;
202template<
typename CharT,
typename Traits>
205 return showTabCount_;
209template<
typename CharT,
typename Traits>
212 showProcRank_ = showProcRank;
216template<
typename CharT,
typename Traits>
219 return showProcRank_;
223template<
typename CharT,
typename Traits>
225 const int procRank,
const int numProcs
228 procRank_ = procRank;
229 numProcs_ = numProcs;
233template<
typename CharT,
typename Traits>
240template<
typename CharT,
typename Traits>
247template<
typename CharT,
typename Traits>
252 rootRank_ = rootRank;
254 if(rootRank == procRank_)
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
312 linePrefixStack_.push_back(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>
381std::ostream& basic_FancyOStream_buf<CharT,Traits>::out()
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) {
408 done_outputting =
true;
410 else if( p == n-1 && s[p] == newline ) {
412 done_outputting =
true;
417 wroteNewline_ =
false;
420 out().write(s+first_p,p-first_p+1);
421 if(s[p] == newline) {
422 wroteNewline_ =
true;
424 *oStream_ << lineOut_->str() << std::flush;
435template<
typename CharT,
typename Traits>
436void basic_FancyOStream_buf<CharT,Traits>::writeFrontMatter()
438 bool didOutput =
false;
439 std::ostream &o = this->out();
441 o <<
"p=" << std::right << std::setw(rankPrintWidth_) << procRank_;
444 if(showLinePrefix_) {
447 std::string currLinePrefix =
"";
448 if ( linePrefixStack_.size() )
449 currLinePrefix = this->getTopLinePrefix();
450 const int localMaxLenLinePrefix =
451 TEUCHOS_MAX(
as<int>(currLinePrefix.length()), maxLenLinePrefix_ );
452 o << std::left << std::setw(localMaxLenLinePrefix);
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
484 ,
const int startingTab
485 ,
const bool showLinePrefix
486 ,
const int maxLenLinePrefix
487 ,
const bool showTabCount
488 ,
const bool showProcRank
491 streambuf_(oStream,tabIndentStr,startingTab,showLinePrefix,
492 maxLenLinePrefix,showTabCount,showProcRank)
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
502 ,
const int startingTab
503 ,
const bool showLinePrefix
504 ,
const int maxLenLinePrefix
505 ,
const bool showTabCount
506 ,
const bool showProcRank
509 streambuf_.initialize(oStream,tabIndentStr,startingTab,
510 showLinePrefix,maxLenLinePrefix,showTabCount,showProcRank);
511 this->init(&streambuf_);
515template<
typename CharT,
typename Traits>
519 return streambuf_.getOStream();
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>
545 const bool showAllFrontMatter
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>
625 streambuf_.setProcRankAndSize(oStream.streambuf_.
getProcRank(),
631template<
typename CharT,
typename Traits>
634 streambuf_.pushTab(tabs);
638template<
typename CharT,
typename Traits>
641 return streambuf_.getNumCurrTabs();
645template<
typename CharT,
typename Traits>
652template<
typename CharT,
typename Traits>
654 const std::basic_string<char_type,traits_type> &linePrefix
657 streambuf_.pushLinePrefix(linePrefix);
661template<
typename CharT,
typename Traits>
664 streambuf_.popLinePrefix();
668template<
typename CharT,
typename Traits>
669const std::basic_string<CharT,Traits>&
672 return streambuf_.getTopLinePrefix();
676template<
typename CharT,
typename Traits>
679 streambuf_.pushDisableTabbing();
683template<
typename CharT,
typename Traits>
686 return streambuf_.popDisableTabbing();
void set_extra_data(const T1 &extra_data, const std::string &name, const Ptr< ArrayRCP< T2 > > &p, EPrePostDestruction destroy_when=POST_DESTROY, bool force_unique=true)
Set extra data associated with a ArrayRCP object.
static int getRank()
The rank of the calling process in MPI_COMM_WORLD.
static int getNProc()
The number of processes in MPI_COMM_WORLD.
Ptr< T > inOutArg(T &arg)
create a non-persisting (required or optional) input/output argument for a function call.
Smart reference counting pointer class for automatic garbage collection.
RCP< T2 > rcp_dynamic_cast(const RCP< T1 > &p1, bool throw_on_fail=false)
Dynamic cast of underlying RCP type from T1* to T2*.
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
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 ...
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.
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
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
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.
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.
#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.
TypeTo as(const TypeFrom &t)
Convert from one value type to another.
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.