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;
159 const std::basic_string<char_type,traits_type> &linePrefix
180 std::streamsize
xsputn(
const char_type* s, std::streamsize
n);
185 #ifdef TEUCHOS_FANCY_OSTREAM_SHOW_ALL_CALLS 187 void imbue(
const locale& l)
189 std::cerr <<
"\ncalled imbue()\n";
190 std::basic_streambuf<CharT,Traits>::imbue(l);
193 basic_streambuf<char_type,Traits>*
194 setbuf(char_type* s, streamsize
n)
196 std::cerr <<
"\ncalled setbuf()\n";
197 return std::basic_streambuf<CharT,Traits>::setbuf(s,n);
201 seekoff(off_type a, ios_base::seekdir b,ios_base::openmode c)
203 std::cerr <<
"\ncalled seekoff()\n";
204 return std::basic_streambuf<CharT,Traits>::seekoff(a,b,c);
208 seekpos(pos_type a, ios_base::openmode b)
210 std::cerr <<
"\ncalled seekpos()\n";
211 return std::basic_streambuf<CharT,Traits>::seekpos(a,b);
217 std::cerr <<
"\ncalled sync()\n";
218 return std::basic_streambuf<CharT,Traits>::sync();
224 std::cerr <<
"\ncalled showmanyc()\n";
225 return std::basic_streambuf<CharT,Traits>::showmanyc();
229 xsgetn(char_type* s, streamsize
n)
231 std::cerr <<
"\ncalled xsgetn()\n";
232 return std::basic_streambuf<CharT,Traits>::xsgetn(s,n);
238 std::cerr <<
"\ncalled underflow()\n";
239 return std::basic_streambuf<CharT,Traits>::underflow();
245 std::cerr <<
"\ncalled uflow()\n";
246 return std::basic_streambuf<CharT,Traits>::uflow();
250 pbackfail(int_type c = traits_type::eof())
252 std::cerr <<
"\ncalled pbackfail()\n";
253 return std::basic_streambuf<CharT,Traits>::pbackfail(c);
256 #endif // TEUCHOS_FANCY_OSTREAM_SHOW_ALL_CALLS 265 typedef std::basic_string<char_type,traits_type>
string_t;
298 void writeChars(
const char_type s[], std::streamsize
n );
333 template <
typename CharT,
typename Traits = std::
char_traits<CharT> >
356 typedef std::basic_ostream<char_type, traits_type>
ostream_t;
366 const RCP< std::basic_ostream<char_type,traits_type> > &oStream
367 ,
const std::basic_string<char_type,traits_type> &tabIndentStr =
" " 368 ,
const int startingTab = 0
369 ,
const bool showLinePrefix =
false 370 ,
const int maxLenLinePrefix = 10
371 ,
const bool showTabCount =
false 372 ,
const bool showProcRank =
false 377 const RCP< std::basic_ostream<char_type,traits_type> > &oStream
378 ,
const std::basic_string<char_type,traits_type> &tabIndentStr =
" " 379 ,
const int startingTab = 0
380 ,
const bool showLinePrefix =
false 381 ,
const int maxLenLinePrefix = 10
382 ,
const bool showTabCount =
false 383 ,
const bool showProcRank =
false 391 const std::basic_string<char_type,traits_type> &tabIndentStr
395 const std::basic_string<char_type,traits_type>&
getTabIndentStr()
const;
430 void pushTab(
const int tabs = 1);
439 void pushLinePrefix(
const std::basic_string<char_type,traits_type> &linePrefix);
477 const RCP< std::basic_ostream<char> >& oStream,
478 const std::basic_string<char>& tabIndentStr =
" ",
479 const int startingTab = 0,
480 const bool showLinePrefix =
false,
481 const int maxLenLinePrefix = 10,
482 const bool showTabCount =
false,
483 const bool showProcRank =
false 489 oStream,tabIndentStr,startingTab,showLinePrefix,
490 maxLenLinePrefix,showTabCount,showProcRank
531 template <
typename CharT,
typename Traits = std::
char_traits<CharT> >
537 static const int DISABLE_TABBING = -99999;
542 ,
const std::basic_string<CharT,Traits> linePrefix =
"" 544 :fancyOStream_(fancyOStream)
546 ,linePrefix_(linePrefix)
552 const RCP<std::basic_ostream<CharT,Traits> > &oStream
554 ,
const std::basic_string<CharT,Traits> linePrefix =
"" 556 :fancyOStream_(getFancyOStream(oStream))
558 ,linePrefix_(linePrefix)
566 ,
const std::basic_string<CharT,Traits> linePrefix =
"" 568 :fancyOStream_(
rcp(&fancyOStream,false))
570 ,linePrefix_(linePrefix)
576 std::basic_ostream<CharT,Traits> &oStream
578 ,
const std::basic_string<CharT,Traits> linePrefix =
"" 580 :fancyOStream_(getFancyOStream(
rcp(&oStream, false)))
582 ,linePrefix_(linePrefix)
588 :fancyOStream_(osTab.fancyOStream_)
596 if(fancyOStream_.get()) {
597 if(tabs_==DISABLE_TABBING)
598 fancyOStream_->popDisableTabbing();
600 fancyOStream_->popTab();
601 if(linePrefix_.length()) fancyOStream_->popLinePrefix();
616 if(fancyOStream_.get()) {
617 fancyOStream_->popTab();
618 fancyOStream_->pushTab(tabs_);
625 return *fancyOStream_;
630 return fancyOStream_.get();
641 if(fancyOStream_.
get()) {
642 if(tabs_==DISABLE_TABBING)
643 fancyOStream_->pushDisableTabbing();
645 fancyOStream_->pushTab(tabs_);
646 if(linePrefix_.length()) fancyOStream_->pushLinePrefix(linePrefix_);
668 template <
typename CharT,
typename Traits>
673 const std::basic_string<CharT,Traits> linePrefix =
"" 705 template <
typename CharT,
typename Traits>
708 const RCP<std::basic_ostream<CharT,Traits> > &
out 710 ,
const std::basic_string<CharT,Traits> linePrefix =
"" 713 return tab(getFancyOStream(
out),tabs,linePrefix);
736 #define TEUCHOS_OSTAB ::Teuchos::OSTab __localThisTab = this->getOSTab() 741 #define TEUCHOS_OSTAB_DIFF( DIFF ) ::Teuchos::OSTab DIFF ## __localThisTab = this->getOSTab() 753 template<
typename CharT,
typename Traits>
755 const RCP<std::basic_ostream<char_type,traits_type> > &oStream
756 ,
const std::basic_string<char_type,traits_type> &tabIndentStr
757 ,
const int startingTab
758 ,
const bool showLinePrefix
759 ,
const int maxLenLinePrefix
760 ,
const bool showTabCount
761 ,
const bool showProcRank
764 this->
initialize(oStream,tabIndentStr,startingTab,showLinePrefix,
765 maxLenLinePrefix,showTabCount,showProcRank);
769 template<
typename CharT,
typename Traits>
771 const RCP<std::basic_ostream<char_type,traits_type> > &oStream
772 ,
const std::basic_string<char_type,traits_type> &tabIndentStr
773 ,
const int startingTab
774 ,
const bool showLinePrefix
775 ,
const int maxLenLinePrefix
776 ,
const bool showTabCount
777 ,
const bool showProcRank
799 template<
typename CharT,
typename Traits>
807 template<
typename CharT,
typename Traits>
809 const std::basic_string<char_type,traits_type> &tabIndentStr
816 template<
typename CharT,
typename Traits>
817 const std::basic_string<CharT,Traits>&
824 template<
typename CharT,
typename Traits>
831 template<
typename CharT,
typename Traits>
838 template<
typename CharT,
typename Traits>
846 template<
typename CharT,
typename Traits>
853 template<
typename CharT,
typename Traits>
860 template<
typename CharT,
typename Traits>
867 template<
typename CharT,
typename Traits>
874 template<
typename CharT,
typename Traits>
881 template<
typename CharT,
typename Traits>
883 const int procRank,
const int numProcs
891 template<
typename CharT,
typename Traits>
898 template<
typename CharT,
typename Traits>
905 template<
typename CharT,
typename Traits>
929 template<
typename CharT,
typename Traits>
936 template<
typename CharT,
typename Traits>
950 template<
typename CharT,
typename Traits>
957 template<
typename CharT,
typename Traits>
965 template<
typename CharT,
typename Traits>
967 const std::basic_string<char_type,traits_type> &linePrefix
974 template<
typename CharT,
typename Traits>
981 template<
typename CharT,
typename Traits>
982 const std::basic_string<CharT,Traits>&
989 template<
typename CharT,
typename Traits>
996 template<
typename CharT,
typename Traits>
1006 template<
typename CharT,
typename Traits>
1008 const char_type* s, std::streamsize
n 1011 #ifdef TEUCHOS_FANCY_OSTREAM_SHOW_ALL_CALLS 1012 std::cerr <<
"\ncalled xsputn()\n";
1019 template<
typename CharT,
typename Traits>
1023 #ifdef TEUCHOS_FANCY_OSTREAM_SHOW_ALL_CALLS 1024 std::cerr <<
"\ncalled overflow()\n";
1026 if(c != traits_type::eof()) {
1027 const char_type cc[] = { traits_type::to_char_type(c) };
1030 return traits_type::not_eof(c);
1038 template<
typename CharT,
typename Traits>
1047 template<
typename CharT,
typename Traits>
1049 const char_type s[], std::streamsize
n 1053 std::streamsize p = 0, first_p = 0;
1054 bool done_outputting =
false;
1055 const char_type newline =
'\n';
1056 while( !done_outputting ) {
1058 for( p = first_p; p <
n; ++p ) {
1059 if(s[p] == newline) {
1066 done_outputting =
true;
1068 else if( p == n-1 && s[p] == newline ) {
1070 done_outputting =
true;
1078 out().write(s+first_p,p-first_p+1);
1079 if(s[p] == newline) {
1087 if(!done_outputting)
1093 template<
typename CharT,
typename Traits>
1096 bool didOutput =
false;
1097 std::ostream &o = this->
out();
1105 std::string currLinePrefix =
"";
1108 const int localMaxLenLinePrefix =
1110 o << std::left << std::setw(localMaxLenLinePrefix);
1111 o << currLinePrefix;
1117 o <<
"tabs=" << std::right << std::setw(2) <<
tabIndent_;
1138 template<
typename CharT,
typename Traits>
1140 const RCP< std::basic_ostream<char_type,traits_type> > &oStream
1141 ,
const std::basic_string<char_type,traits_type> &tabIndentStr
1142 ,
const int startingTab
1143 ,
const bool showLinePrefix
1144 ,
const int maxLenLinePrefix
1145 ,
const bool showTabCount
1146 ,
const bool showProcRank
1149 streambuf_(oStream,tabIndentStr,startingTab,showLinePrefix,
1150 maxLenLinePrefix,showTabCount,showProcRank)
1156 template<
typename CharT,
typename Traits>
1158 const RCP< std::basic_ostream<char_type,traits_type> > &oStream
1159 ,
const std::basic_string<char_type,traits_type> &tabIndentStr
1160 ,
const int startingTab
1161 ,
const bool showLinePrefix
1162 ,
const int maxLenLinePrefix
1163 ,
const bool showTabCount
1164 ,
const bool showProcRank
1168 showLinePrefix,maxLenLinePrefix,showTabCount,showProcRank);
1173 template<
typename CharT,
typename Traits>
1181 template<
typename CharT,
typename Traits>
1184 const std::basic_string<char_type,traits_type> &tabIndentStr
1192 template<
typename CharT,
typename Traits>
1193 const std::basic_string<CharT,Traits>&
1200 template<
typename CharT,
typename Traits>
1203 const bool showAllFrontMatter
1213 template<
typename CharT,
typename Traits>
1222 template<
typename CharT,
typename Traits>
1231 template<
typename CharT,
typename Traits>
1240 template<
typename CharT,
typename Traits>
1249 template<
typename CharT,
typename Traits>
1258 template<
typename CharT,
typename Traits>
1267 template<
typename CharT,
typename Traits>
1274 template<
typename CharT,
typename Traits>
1289 template<
typename CharT,
typename Traits>
1296 template<
typename CharT,
typename Traits>
1303 template<
typename CharT,
typename Traits>
1310 template<
typename CharT,
typename Traits>
1312 const std::basic_string<char_type,traits_type> &linePrefix
1319 template<
typename CharT,
typename Traits>
1326 template<
typename CharT,
typename Traits>
1327 const std::basic_string<CharT,Traits>&
1334 template<
typename CharT,
typename Traits>
1341 template<
typename CharT,
typename Traits>
1351 #endif // TEUCHOS_FANCY_O_STREAM_HPP
basic_FancyOStream & setProcRankAndSize(const int procRank, const int numProcs)
void writeChars(const char_type s[], std::streamsize n)
static int getRank()
Returns the process rank relative to MPI_COMM_WORLD
basic_FancyOStream & setShowLinePrefix(const bool showLinePrefix)
bool getShowLinePrefix() const
RCP< std::ostringstream > lineOut_
bool is_null(const boost::shared_ptr< T > &p)
Returns true if p.get()==NULL.
static int getNProc()
Returns the number of processors relative to 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
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)
void setShowProcRank(const bool showProcRank)
basic_OSTab< CharT, Traits > & incrTab(const int tabs=1)
T * get() const
Get the raw C++ pointer to the underlying object.
void setTabIndentStr(const std::basic_string< char_type, traits_type > &tabIndentStr)
RCP< basic_FancyOStream< CharT, Traits > > fancyOStream_
void pushTab(const int tabs=1)
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)
Tabbing class for helping to create formated, indented output for a basic_FancyOStream object...
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
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)
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 setShowTabCount(const bool showTabCount)
void setShowLinePrefix(const bool showLinePrefix)
#define TEUCHOS_MAX(x, y)
basic_FancyOStream & setShowAllFrontMatter(const bool showAllFrontMatter)
Set if processor rank, line prefixes, and tab counts are shown or not .
basic_FancyOStream & setOutputToRootOnly(const int rootRank)
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)
RCP< std::basic_ostream< char_type, traits_type > > getOStream()
traits_type::pos_type pos_type
bool nonnull(const boost::shared_ptr< T > &p)
Returns true if p.get()!=NULL.
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()
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)
#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)