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;
370 template <
typename CharT,
typename Traits = std::
char_traits<CharT> >
393 typedef std::basic_ostream<char_type, traits_type>
ostream_t;
431 const RCP< std::basic_ostream<char_type,traits_type> > &oStream
432 ,
const std::basic_string<char_type,traits_type> &tabIndentStr =
" " 433 ,
const int startingTab = 0
434 ,
const bool showLinePrefix =
false 435 ,
const int maxLenLinePrefix = 10
436 ,
const bool showTabCount =
false 437 ,
const bool showProcRank =
false 444 const RCP< std::basic_ostream<char_type,traits_type> > &oStream
445 ,
const std::basic_string<char_type,traits_type> &tabIndentStr =
" " 446 ,
const int startingTab = 0
447 ,
const bool showLinePrefix =
false 448 ,
const int maxLenLinePrefix = 10
449 ,
const bool showTabCount =
false 450 ,
const bool showProcRank =
false 458 const std::basic_string<char_type,traits_type> &tabIndentStr
462 const std::basic_string<char_type,traits_type>&
getTabIndentStr()
const;
535 void pushTab(
const int tabs = 1);
550 void pushLinePrefix(
const std::basic_string<char_type,traits_type> &linePrefix);
588 const RCP< std::basic_ostream<char> >& oStream,
589 const std::basic_string<char>& tabIndentStr =
" ",
590 const int startingTab = 0,
591 const bool showLinePrefix =
false,
592 const int maxLenLinePrefix = 10,
593 const bool showTabCount =
false,
594 const bool showProcRank =
false 600 oStream,tabIndentStr,startingTab,showLinePrefix,
601 maxLenLinePrefix,showTabCount,showProcRank
642 template <
typename CharT,
typename Traits = std::
char_traits<CharT> >
653 ,
const std::basic_string<CharT,Traits> linePrefix =
"" 663 const RCP<std::basic_ostream<CharT,Traits> > &oStream
665 ,
const std::basic_string<CharT,Traits> linePrefix =
"" 677 ,
const std::basic_string<CharT,Traits> linePrefix =
"" 687 std::basic_ostream<CharT,Traits> &oStream
689 ,
const std::basic_string<CharT,Traits> linePrefix =
"" 779 template <
typename CharT,
typename Traits>
780 RCP<basic_FancyOStream<CharT,Traits> >
784 const std::basic_string<CharT,Traits> linePrefix =
"" 816 template <
typename CharT,
typename Traits>
819 const RCP<std::basic_ostream<CharT,Traits> > &out
821 ,
const std::basic_string<CharT,Traits> linePrefix =
"" 824 return tab(getFancyOStream(out),tabs,linePrefix);
847 #define TEUCHOS_OSTAB ::Teuchos::OSTab __localThisTab = this->getOSTab() 852 #define TEUCHOS_OSTAB_DIFF( DIFF ) ::Teuchos::OSTab DIFF ## __localThisTab = this->getOSTab() 864 template<
typename CharT,
typename Traits>
866 const RCP<std::basic_ostream<char_type,traits_type> > &oStream
867 ,
const std::basic_string<char_type,traits_type> &tabIndentStr
868 ,
const int startingTab
869 ,
const bool showLinePrefix
870 ,
const int maxLenLinePrefix
871 ,
const bool showTabCount
872 ,
const bool showProcRank
875 this->initialize(oStream,tabIndentStr,startingTab,showLinePrefix,
876 maxLenLinePrefix,showTabCount,showProcRank);
880 template<
typename CharT,
typename Traits>
882 const RCP<std::basic_ostream<char_type,traits_type> > &oStream
883 ,
const std::basic_string<char_type,traits_type> &tabIndentStr
884 ,
const int startingTab
885 ,
const bool showLinePrefix
886 ,
const int maxLenLinePrefix
887 ,
const bool showTabCount
888 ,
const bool showProcRank
891 oStreamSet_ = oStream;
893 tabIndentStr_ = tabIndentStr;
894 showLinePrefix_ = showLinePrefix;
895 maxLenLinePrefix_ = maxLenLinePrefix;
896 showTabCount_ = showTabCount;
897 showProcRank_ = showProcRank;
901 rankPrintWidth_ = int(std::log10(
float(numProcs_)))+1;
902 tabIndent_ = startingTab;
903 tabIndentStack_.clear();
904 linePrefixStack_.clear();
905 wroteNewline_ =
true;
906 enableTabbingStack_ = 0;
910 template<
typename CharT,
typename Traits>
918 template<
typename CharT,
typename Traits>
920 const std::basic_string<char_type,traits_type> &tabIndentStr
923 tabIndentStr_ = tabIndentStr;
927 template<
typename CharT,
typename Traits>
928 const std::basic_string<CharT,Traits>&
931 return tabIndentStr_;
935 template<
typename CharT,
typename Traits>
938 showLinePrefix_ = showLinePrefix;
942 template<
typename CharT,
typename Traits>
945 return showLinePrefix_;
949 template<
typename CharT,
typename Traits>
953 maxLenLinePrefix_ = maxLenLinePrefix;
957 template<
typename CharT,
typename Traits>
960 return maxLenLinePrefix_;
964 template<
typename CharT,
typename Traits>
967 showTabCount_ = showTabCount;
971 template<
typename CharT,
typename Traits>
974 return showTabCount_;
978 template<
typename CharT,
typename Traits>
981 showProcRank_ = showProcRank;
985 template<
typename CharT,
typename Traits>
988 return showProcRank_;
992 template<
typename CharT,
typename Traits>
994 const int procRank,
const int numProcs
997 procRank_ = procRank;
998 numProcs_ = numProcs;
1002 template<
typename CharT,
typename Traits>
1009 template<
typename CharT,
typename Traits>
1016 template<
typename CharT,
typename Traits>
1021 rootRank_ = rootRank;
1023 if(rootRank == procRank_)
1024 oStream_ = oStreamSet_;
1032 oStream_ = oStreamSet_;
1035 lineOut_ =
rcp(
new std::ostringstream());
1040 template<
typename CharT,
typename Traits>
1047 template<
typename CharT,
typename Traits>
1050 if( tabIndent_ + tabs < 0 ) {
1051 tabIndentStack_.push_back(-tabIndent_);
1055 tabIndentStack_.push_back(tabs);
1061 template<
typename CharT,
typename Traits>
1068 template<
typename CharT,
typename Traits>
1071 tabIndent_ -= tabIndentStack_.back();
1072 tabIndentStack_.pop_back();
1076 template<
typename CharT,
typename Traits>
1078 const std::basic_string<char_type,traits_type> &linePrefix
1081 linePrefixStack_.push_back(linePrefix);
1085 template<
typename CharT,
typename Traits>
1088 linePrefixStack_.pop_back();
1092 template<
typename CharT,
typename Traits>
1093 const std::basic_string<CharT,Traits>&
1096 return linePrefixStack_.back();
1100 template<
typename CharT,
typename Traits>
1103 ++enableTabbingStack_;
1107 template<
typename CharT,
typename Traits>
1110 --enableTabbingStack_;
1117 template<
typename CharT,
typename Traits>
1122 #ifdef TEUCHOS_FANCY_OSTREAM_SHOW_ALL_CALLS 1123 std::cerr <<
"\ncalled xsputn()\n";
1130 template<
typename CharT,
typename Traits>
1134 #ifdef TEUCHOS_FANCY_OSTREAM_SHOW_ALL_CALLS 1135 std::cerr <<
"\ncalled overflow()\n";
1137 if(c != traits_type::eof()) {
1138 const char_type cc[] = { traits_type::to_char_type(c) };
1139 this->writeChars(cc,1);
1141 return traits_type::not_eof(c);
1149 template<
typename CharT,
typename Traits>
1158 template<
typename CharT,
typename Traits>
1164 std::streamsize p = 0, first_p = 0;
1165 bool done_outputting =
false;
1167 while( !done_outputting ) {
1169 for( p = first_p; p <
n; ++p ) {
1170 if(s[p] == newline) {
1177 done_outputting =
true;
1179 else if( p ==
n-1 && s[p] == newline ) {
1181 done_outputting =
true;
1186 wroteNewline_ =
false;
1189 out().write(s+first_p,p-first_p+1);
1190 if(s[p] == newline) {
1191 wroteNewline_ =
true;
1192 if(lineOut_.get()) {
1193 *oStream_ << lineOut_->str() << std::flush;
1198 if(!done_outputting)
1204 template<
typename CharT,
typename Traits>
1207 bool didOutput =
false;
1208 std::ostream &o = this->out();
1210 o <<
"p=" << std::right << std::setw(rankPrintWidth_) << procRank_;
1213 if(showLinePrefix_) {
1216 std::string currLinePrefix =
"";
1217 if ( linePrefixStack_.size() )
1218 currLinePrefix = this->getTopLinePrefix();
1219 const int localMaxLenLinePrefix =
1220 TEUCHOS_MAX( as<int>(currLinePrefix.length()), maxLenLinePrefix_ );
1221 o << std::left << std::setw(localMaxLenLinePrefix);
1222 o << currLinePrefix;
1228 o <<
"tabs=" << std::right << std::setw(2) << tabIndent_;
1235 o <<
" |" << tabIndentStr_;
1237 if(enableTabbingStack_==0) {
1238 for(
int i = 0; i < tabIndent_; ++i )
1249 template<
typename CharT,
typename Traits>
1251 const RCP< std::basic_ostream<char_type,traits_type> > &oStream
1252 ,
const std::basic_string<char_type,traits_type> &tabIndentStr
1253 ,
const int startingTab
1254 ,
const bool showLinePrefix
1255 ,
const int maxLenLinePrefix
1256 ,
const bool showTabCount
1257 ,
const bool showProcRank
1260 streambuf_(oStream,tabIndentStr,startingTab,showLinePrefix,
1261 maxLenLinePrefix,showTabCount,showProcRank)
1267 template<
typename CharT,
typename Traits>
1269 const RCP< std::basic_ostream<char_type,traits_type> > &oStream
1270 ,
const std::basic_string<char_type,traits_type> &tabIndentStr
1271 ,
const int startingTab
1272 ,
const bool showLinePrefix
1273 ,
const int maxLenLinePrefix
1274 ,
const bool showTabCount
1275 ,
const bool showProcRank
1278 streambuf_.initialize(oStream,tabIndentStr,startingTab,
1279 showLinePrefix,maxLenLinePrefix,showTabCount,showProcRank);
1280 this->init(&streambuf_);
1284 template<
typename CharT,
typename Traits>
1288 return streambuf_.getOStream();
1292 template<
typename CharT,
typename Traits>
1295 const std::basic_string<char_type,traits_type> &tabIndentStr
1303 template<
typename CharT,
typename Traits>
1304 const std::basic_string<CharT,Traits>&
1307 return streambuf_.getTabIndentStr();
1311 template<
typename CharT,
typename Traits>
1314 const bool showAllFrontMatter
1324 template<
typename CharT,
typename Traits>
1333 template<
typename CharT,
typename Traits>
1342 template<
typename CharT,
typename Traits>
1351 template<
typename CharT,
typename Traits>
1360 template<
typename CharT,
typename Traits>
1369 template<
typename CharT,
typename Traits>
1378 template<
typename CharT,
typename Traits>
1381 return streambuf_.getOutputToRootOnly();
1385 template<
typename CharT,
typename Traits>
1390 streambuf_.setShowLinePrefix(oStream.
streambuf_.getShowLinePrefix());
1391 streambuf_.setMaxLenLinePrefix(oStream.
streambuf_.getMaxLenLinePrefix());
1392 streambuf_.setShowTabCount(oStream.
streambuf_.getShowTabCount());
1393 streambuf_.setShowProcRank(oStream.
streambuf_.getShowProcRank());
1394 streambuf_.setProcRankAndSize(oStream.
streambuf_.getProcRank(),
1396 streambuf_.setOutputToRootOnly(oStream.
streambuf_.getOutputToRootOnly());
1400 template<
typename CharT,
typename Traits>
1403 streambuf_.pushTab(tabs);
1407 template<
typename CharT,
typename Traits>
1410 return streambuf_.getNumCurrTabs();
1414 template<
typename CharT,
typename Traits>
1417 streambuf_.popTab();
1421 template<
typename CharT,
typename Traits>
1423 const std::basic_string<char_type,traits_type> &linePrefix
1426 streambuf_.pushLinePrefix(linePrefix);
1430 template<
typename CharT,
typename Traits>
1433 streambuf_.popLinePrefix();
1437 template<
typename CharT,
typename Traits>
1438 const std::basic_string<CharT,Traits>&
1441 return streambuf_.getTopLinePrefix();
1445 template<
typename CharT,
typename Traits>
1448 streambuf_.pushDisableTabbing();
1452 template<
typename CharT,
typename Traits>
1455 return streambuf_.popDisableTabbing();
1462 #endif // TEUCHOS_FANCY_O_STREAM_HPP
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)
RCP< std::ostringstream > lineOut_
int getProcRank() const
Get the rank of the calling (MPI) process.
bool getShowLinePrefix() const
static int getNProc()
The number of processes in MPI_COMM_WORLD.
std::deque< int > tabIndentStack_t
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...
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)
int getOutputToRootOnly() const
void setTabIndentStr(const std::basic_string< char_type, traits_type > &tabIndentStr)
RCP< basic_FancyOStream< CharT, Traits > > fancyOStream_
bool getShowTabCount() const
void pushTab(const int tabs=1)
Push one or more tabs.
const std::basic_string< char_type, traits_type > & getTabIndentStr() const
Get the tab indent string.
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_
int getOutputToRootOnly() const
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)
int getNumProcs() const
Get the number of processes in the communicator.
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)
const std::basic_string< char_type, traits_type > & getTopLinePrefix() const
#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.
basic_FancyOStream_buf< CharT, Traits > streambuf_t
std::deque< string_t > linePrefixStack_t
basic_FancyOStream & setTabIndentStr(const std::basic_string< char_type, traits_type > &tabIndentStr)
Set the tab indent string.
const std::basic_string< char_type, traits_type > & getTabIndentStr() const
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.
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.
bool getShowProcRank() const
RCP< std::basic_ostream< char_type, traits_type > > oStream_
basic_FancyOStream< CharT, Traits > & o() const
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.
const std::basic_string< char_type, traits_type > & getTopLinePrefix() const
void copyAllOutputOptions(const basic_FancyOStream< CharT, Traits > &oStream)
int getMaxLenLinePrefix() const
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...
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...
int getNumCurrTabs() const
tabIndentStack_t tabIndentStack_
basic_OSTab(const basic_OSTab &osTab)