42 #ifndef TEUCHOS_FANCY_O_STREAM_HPP
43 #define TEUCHOS_FANCY_O_STREAM_HPP
62 template<
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
82 ,
const int startingTab
83 ,
const bool showLinePrefix
84 ,
const int maxLenLinePrefix
85 ,
const bool showTabCount
86 ,
const bool showProcRank
91 const RCP<std::basic_ostream<char_type,traits_type> > &oStream
92 ,
const std::basic_string<char_type,traits_type> &tabIndentStr
93 ,
const int startingTab
94 ,
const bool showLinePrefix
95 ,
const int maxLenLinePrefix
96 ,
const bool showTabCount
97 ,
const bool showProcRank
104 void setTabIndentStr(
const std::basic_string<char_type,traits_type> &tabIndentStr);
107 const std::basic_string<char_type,traits_type>&
getTabIndentStr()
const;
196 const std::basic_string<char_type,traits_type> &linePrefix
222 #ifdef TEUCHOS_FANCY_OSTREAM_SHOW_ALL_CALLS
224 void imbue(
const locale& l)
226 std::cerr <<
"\ncalled imbue()\n";
227 std::basic_streambuf<CharT,Traits>::imbue(l);
230 basic_streambuf<char_type,Traits>*
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();
287 pbackfail(
int_type c = traits_type::eof())
289 std::cerr <<
"\ncalled pbackfail()\n";
290 return std::basic_streambuf<CharT,Traits>::pbackfail(c);
293 #endif // TEUCHOS_FANCY_OSTREAM_SHOW_ALL_CALLS
302 typedef std::basic_string<char_type,traits_type>
string_t;
380 template <
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 =
" "
443 ,
const int startingTab = 0
444 ,
const bool showLinePrefix =
false
445 ,
const int maxLenLinePrefix = 10
446 ,
const bool showTabCount =
false
447 ,
const bool showProcRank =
false
454 const RCP< std::basic_ostream<char_type,traits_type> > &oStream
455 ,
const std::basic_string<char_type,traits_type> &tabIndentStr =
" "
456 ,
const int startingTab = 0
457 ,
const bool showLinePrefix =
false
458 ,
const int maxLenLinePrefix = 10
459 ,
const bool showTabCount =
false
460 ,
const bool showProcRank =
false
468 const std::basic_string<char_type,traits_type> &tabIndentStr
472 const std::basic_string<char_type,traits_type>&
getTabIndentStr()
const;
545 void pushTab(
const int tabs = 1);
560 void pushLinePrefix(
const std::basic_string<char_type,traits_type> &linePrefix);
598 const RCP< std::basic_ostream<char> >& oStream,
599 const std::basic_string<char>& tabIndentStr =
" ",
600 const int startingTab = 0,
601 const bool showLinePrefix =
false,
602 const int maxLenLinePrefix = 10,
603 const bool showTabCount =
false,
604 const bool showProcRank =
false
610 oStream,tabIndentStr,startingTab,showLinePrefix,
611 maxLenLinePrefix,showTabCount,showProcRank
652 template <
typename CharT,
typename Traits = std::
char_traits<CharT> >
663 ,
const std::basic_string<CharT,Traits> linePrefix =
""
673 const RCP<std::basic_ostream<CharT,Traits> > &oStream
675 ,
const std::basic_string<CharT,Traits> linePrefix =
""
687 ,
const std::basic_string<CharT,Traits> linePrefix =
""
697 std::basic_ostream<CharT,Traits> &oStream
699 ,
const std::basic_string<CharT,Traits> linePrefix =
""
789 template <
typename CharT,
typename Traits>
790 RCP<basic_FancyOStream<CharT,Traits> >
794 const std::basic_string<CharT,Traits> linePrefix =
""
826 template <
typename CharT,
typename Traits>
829 const RCP<std::basic_ostream<CharT,Traits> > &out
831 ,
const std::basic_string<CharT,Traits> linePrefix =
""
834 return tab(getFancyOStream(out),tabs,linePrefix);
857 #define TEUCHOS_OSTAB ::Teuchos::OSTab __localThisTab = this->getOSTab()
862 #define TEUCHOS_OSTAB_DIFF( DIFF ) ::Teuchos::OSTab DIFF ## __localThisTab = this->getOSTab()
874 template<
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
878 ,
const int startingTab
879 ,
const bool showLinePrefix
880 ,
const int maxLenLinePrefix
881 ,
const bool showTabCount
882 ,
const bool showProcRank
885 this->initialize(oStream,tabIndentStr,startingTab,showLinePrefix,
886 maxLenLinePrefix,showTabCount,showProcRank);
890 template<
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
894 ,
const int startingTab
895 ,
const bool showLinePrefix
896 ,
const int maxLenLinePrefix
897 ,
const bool showTabCount
898 ,
const bool showProcRank
901 oStreamSet_ = oStream;
903 tabIndentStr_ = tabIndentStr;
904 showLinePrefix_ = showLinePrefix;
905 maxLenLinePrefix_ = maxLenLinePrefix;
906 showTabCount_ = showTabCount;
907 showProcRank_ = showProcRank;
911 rankPrintWidth_ = int(std::log10(
float(numProcs_)))+1;
912 tabIndent_ = startingTab;
913 tabIndentStack_.clear();
914 linePrefixStack_.clear();
915 wroteNewline_ =
true;
916 enableTabbingStack_ = 0;
920 template<
typename CharT,
typename Traits>
928 template<
typename CharT,
typename Traits>
930 const std::basic_string<char_type,traits_type> &tabIndentStr
933 tabIndentStr_ = tabIndentStr;
937 template<
typename CharT,
typename Traits>
938 const std::basic_string<CharT,Traits>&
941 return tabIndentStr_;
945 template<
typename CharT,
typename Traits>
948 showLinePrefix_ = showLinePrefix;
952 template<
typename CharT,
typename Traits>
955 return showLinePrefix_;
959 template<
typename CharT,
typename Traits>
963 maxLenLinePrefix_ = maxLenLinePrefix;
967 template<
typename CharT,
typename Traits>
970 return maxLenLinePrefix_;
974 template<
typename CharT,
typename Traits>
977 showTabCount_ = showTabCount;
981 template<
typename CharT,
typename Traits>
984 return showTabCount_;
988 template<
typename CharT,
typename Traits>
991 showProcRank_ = showProcRank;
995 template<
typename CharT,
typename Traits>
998 return showProcRank_;
1002 template<
typename CharT,
typename Traits>
1004 const int procRank,
const int numProcs
1007 procRank_ = procRank;
1008 numProcs_ = numProcs;
1012 template<
typename CharT,
typename Traits>
1019 template<
typename CharT,
typename Traits>
1026 template<
typename CharT,
typename Traits>
1031 rootRank_ = rootRank;
1033 if(rootRank == procRank_)
1034 oStream_ = oStreamSet_;
1042 oStream_ = oStreamSet_;
1045 lineOut_ =
rcp(
new std::ostringstream());
1050 template<
typename CharT,
typename Traits>
1057 template<
typename CharT,
typename Traits>
1060 if( tabIndent_ + tabs < 0 ) {
1061 tabIndentStack_.push_back(-tabIndent_);
1065 tabIndentStack_.push_back(tabs);
1071 template<
typename CharT,
typename Traits>
1078 template<
typename CharT,
typename Traits>
1081 tabIndent_ -= tabIndentStack_.back();
1082 tabIndentStack_.pop_back();
1086 template<
typename CharT,
typename Traits>
1088 const std::basic_string<char_type,traits_type> &linePrefix
1091 linePrefixStack_.push_back(linePrefix);
1095 template<
typename CharT,
typename Traits>
1098 linePrefixStack_.pop_back();
1102 template<
typename CharT,
typename Traits>
1103 const std::basic_string<CharT,Traits>&
1106 return linePrefixStack_.back();
1110 template<
typename CharT,
typename Traits>
1113 ++enableTabbingStack_;
1117 template<
typename CharT,
typename Traits>
1120 --enableTabbingStack_;
1127 template<
typename CharT,
typename Traits>
1132 #ifdef TEUCHOS_FANCY_OSTREAM_SHOW_ALL_CALLS
1133 std::cerr <<
"\ncalled xsputn()\n";
1140 template<
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);
1159 template<
typename CharT,
typename Traits>
1168 template<
typename CharT,
typename Traits>
1174 std::streamsize p = 0, first_p = 0;
1175 bool done_outputting =
false;
1177 while( !done_outputting ) {
1179 for( p = first_p; p <
n; ++p ) {
1180 if(s[p] == newline) {
1187 done_outputting =
true;
1189 else if( p == n-1 && s[p] == newline ) {
1191 done_outputting =
true;
1196 wroteNewline_ =
false;
1199 out().write(s+first_p,p-first_p+1);
1200 if(s[p] == newline) {
1201 wroteNewline_ =
true;
1202 if(lineOut_.get()) {
1203 *oStream_ << lineOut_->str() << std::flush;
1208 if(!done_outputting)
1214 template<
typename CharT,
typename Traits>
1217 bool didOutput =
false;
1218 std::ostream &o = this->out();
1220 o <<
"p=" << std::right << std::setw(rankPrintWidth_) << procRank_;
1223 if(showLinePrefix_) {
1226 std::string currLinePrefix =
"";
1227 if ( linePrefixStack_.size() )
1228 currLinePrefix = this->getTopLinePrefix();
1229 const int localMaxLenLinePrefix =
1230 TEUCHOS_MAX( as<int>(currLinePrefix.length()), maxLenLinePrefix_ );
1231 o << std::left << std::setw(localMaxLenLinePrefix);
1232 o << currLinePrefix;
1238 o <<
"tabs=" << std::right << std::setw(2) << tabIndent_;
1245 o <<
" |" << tabIndentStr_;
1247 if(enableTabbingStack_==0) {
1248 for(
int i = 0; i < tabIndent_; ++i )
1259 template<
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
1263 ,
const int startingTab
1264 ,
const bool showLinePrefix
1265 ,
const int maxLenLinePrefix
1266 ,
const bool showTabCount
1267 ,
const bool showProcRank
1270 streambuf_(oStream,tabIndentStr,startingTab,showLinePrefix,
1271 maxLenLinePrefix,showTabCount,showProcRank)
1277 template<
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
1281 ,
const int startingTab
1282 ,
const bool showLinePrefix
1283 ,
const int maxLenLinePrefix
1284 ,
const bool showTabCount
1285 ,
const bool showProcRank
1288 streambuf_.initialize(oStream,tabIndentStr,startingTab,
1289 showLinePrefix,maxLenLinePrefix,showTabCount,showProcRank);
1290 this->init(&streambuf_);
1294 template<
typename CharT,
typename Traits>
1298 return streambuf_.getOStream();
1302 template<
typename CharT,
typename Traits>
1305 const std::basic_string<char_type,traits_type> &tabIndentStr
1313 template<
typename CharT,
typename Traits>
1314 const std::basic_string<CharT,Traits>&
1317 return streambuf_.getTabIndentStr();
1321 template<
typename CharT,
typename Traits>
1324 const bool showAllFrontMatter
1334 template<
typename CharT,
typename Traits>
1343 template<
typename CharT,
typename Traits>
1352 template<
typename CharT,
typename Traits>
1361 template<
typename CharT,
typename Traits>
1370 template<
typename CharT,
typename Traits>
1379 template<
typename CharT,
typename Traits>
1388 template<
typename CharT,
typename Traits>
1391 return streambuf_.getOutputToRootOnly();
1395 template<
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(),
1406 streambuf_.setOutputToRootOnly(oStream.
streambuf_.getOutputToRootOnly());
1410 template<
typename CharT,
typename Traits>
1413 streambuf_.pushTab(tabs);
1417 template<
typename CharT,
typename Traits>
1420 return streambuf_.getNumCurrTabs();
1424 template<
typename CharT,
typename Traits>
1427 streambuf_.popTab();
1431 template<
typename CharT,
typename Traits>
1433 const std::basic_string<char_type,traits_type> &linePrefix
1436 streambuf_.pushLinePrefix(linePrefix);
1440 template<
typename CharT,
typename Traits>
1443 streambuf_.popLinePrefix();
1447 template<
typename CharT,
typename Traits>
1448 const std::basic_string<CharT,Traits>&
1451 return streambuf_.getTopLinePrefix();
1455 template<
typename CharT,
typename Traits>
1458 streambuf_.pushDisableTabbing();
1462 template<
typename CharT,
typename Traits>
1465 return streambuf_.popDisableTabbing();
1472 #endif // TEUCHOS_FANCY_O_STREAM_HPP
int getNumProcs() const
Get the number of processes in the communicator.
basic_FancyOStream & setProcRankAndSize(const int procRank, const int numProcs)
Set the (MPI) process rank and the number of processes in the communicator.
void writeChars(const char_type s[], std::streamsize n)
static int getRank()
The rank of the calling process in MPI_COMM_WORLD.
basic_FancyOStream & setShowLinePrefix(const bool showLinePrefix)
int getProcRank() const
Get the rank of the calling (MPI) process.
bool getShowLinePrefix() const
RCP< std::ostringstream > lineOut_
static int getNProc()
The number of processes in MPI_COMM_WORLD.
std::deque< int > tabIndentStack_t
const std::basic_string< char_type, traits_type > & getTabIndentStr() const
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 & setMaxLenLinePrefix(const int maxLenLinePrefix)
basic_OSTab(const RCP< std::basic_ostream< CharT, Traits > > &oStream, const int tabs=1, const std::basic_string< CharT, Traits > linePrefix="")
basic_FancyOStream & setShowProcRank(const bool showProcRank)
Stream buffering class that performs the magic of indenting data sent to an std::ostream object...
const std::basic_string< char_type, traits_type > & getTopLinePrefix() const
basic_FancyOStream< CharT, Traits > & o() const
bool nonnull(const std::shared_ptr< T > &p)
Returns true if p.get()!=NULL.
bool is_null(const std::shared_ptr< T > &p)
Returns true if p.get()==NULL.
std::basic_ostream< char_type, traits_type > ostream_t
linePrefixStack_t linePrefixStack_
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 setOutputToRootOnly(const int rootRank)
Set the stream to print only on the (MPI) process with the given rank.
void setShowProcRank(const bool showProcRank)
static const int DISABLE_TABBING
basic_OSTab< CharT, Traits > & incrTab(const int tabs=1)
void setTabIndentStr(const std::basic_string< char_type, traits_type > &tabIndentStr)
RCP< basic_FancyOStream< CharT, Traits > > fancyOStream_
void pushTab(const int tabs=1)
Push one or more tabs.
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.
Tabbing class for helping to create formated, indented output for a basic_FancyOStream object...
basic_FancyOStream< CharT, Traits > operator=(const basic_FancyOStream< CharT, Traits > &)
basic_OSTab< char > OSTab
std::basic_string< char_type, traits_type > tabIndentStr_
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.
void pushLinePrefix(const std::basic_string< char_type, traits_type > &linePrefix)
traits_type::int_type int_type
basic_FancyOStream & setShowTabCount(const bool showTabCount)
bool getShowProcRank() const
const std::basic_string< char_type, traits_type > & getTabIndentStr() const
Get the tab indent string.
void pushDisableTabbing()
traits_type::off_type off_type
int getNumCurrTabs() const
traits_type::off_type off_type
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
void pushTab(const int tabs)
Push one or more tabs.
std::ostream subclass that performs the magic of indenting data sent to an std::ostream object among ...
int_type overflow(int_type c)
basic_OSTab< CharT, Traits > & operator=(const basic_OSTab &osTab)
traits_type::pos_type pos_type
void popTab()
Pop the current tab.
void setShowTabCount(const bool showTabCount)
void popTab()
Pop the current tab.
void setShowLinePrefix(const bool showLinePrefix)
#define TEUCHOS_MAX(x, y)
basic_FancyOStream & setShowAllFrontMatter(const bool showAllFrontMatter)
Control whether this stream prints "front matter.".
basic_FancyOStream & setOutputToRootOnly(const int rootRank)
Set the stream to print only on the (MPI) process with the given rank.
int getOutputToRootOnly() const
basic_FancyOStream_buf< CharT, Traits > streambuf_t
bool getShowTabCount() const
std::deque< string_t > linePrefixStack_t
int getOutputToRootOnly() const
int getNumCurrTabs() const
basic_FancyOStream & setTabIndentStr(const std::basic_string< char_type, traits_type > &tabIndentStr)
Set the tab indent string.
RCP< std::basic_ostream< char_type, traits_type > > getOStream()
traits_type::pos_type pos_type
basic_FancyOStream< char > FancyOStream
std::streamsize xsputn(const char_type *s, std::streamsize n)
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.
basic_FancyOStream_buf< CharT, Traits > operator=(const basic_FancyOStream_buf< CharT, Traits > &)
RCP< std::basic_ostream< char_type, traits_type > > getOStream()
Get the output stream this object wraps.
int getMaxLenLinePrefix() const
void pushDisableTabbing()
A MPI utilities class, providing methods for initializing, finalizing, and querying the global MPI se...
std::basic_string< char_type, traits_type > string_t
void setMaxLenLinePrefix(const int maxLenLinePrefix)
RCP< std::basic_ostream< char_type, traits_type > > oStreamSet_
RCP< basic_FancyOStream< char > > getFancyOStream(const RCP< std::basic_ostream< char > > &out)
Get a FancyOStream from an std::ostream object.
RCP< std::basic_ostream< char_type, traits_type > > oStream_
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...
basic_OSTab(const RCP< basic_FancyOStream< CharT, Traits > > &fancyOStream, const int tabs=1, const std::basic_string< CharT, Traits > linePrefix="")
std::basic_string< CharT, Traits > linePrefix_
Smart reference counting pointer class for automatic garbage collection.
void copyAllOutputOptions(const basic_FancyOStream< CharT, Traits > &oStream)
traits_type::int_type int_type
void pushLinePrefix(const std::basic_string< char_type, traits_type > &linePrefix)
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...
const std::basic_string< char_type, traits_type > & getTopLinePrefix() const
Reference-counted pointer class and non-member templated function implementations.
Definition of Teuchos::as, for conversions between types.
basic_oblackholestream< char, std::char_traits< char > > oblackholestream
void setProcRankAndSize(const int procRank, const int numProcs)
Set the (MPI) process rank and the number of processes in the communicator.
#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...
tabIndentStack_t tabIndentStack_
basic_OSTab(const basic_OSTab &osTab)