Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_FancyOStream.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Teuchos: Common Tools Package
4 //
5 // Copyright 2004 NTESS and the Teuchos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef TEUCHOS_FANCY_O_STREAM_HPP
11 #define TEUCHOS_FANCY_O_STREAM_HPP
12 
13 #include "Teuchos_RCP.hpp"
16 #include "Teuchos_as.hpp"
17 #include <deque>
18 
19 namespace Teuchos {
20 
21 
30 template<typename CharT, typename Traits>
31 class basic_FancyOStream_buf : public std::basic_streambuf<CharT,Traits>
32 {
33 public:
34 
36  typedef CharT char_type;
38  typedef Traits traits_type;
40  typedef typename traits_type::int_type int_type;
42  typedef typename traits_type::pos_type pos_type;
44  typedef typename traits_type::off_type off_type;
45 
48  const RCP<std::basic_ostream<char_type,traits_type> > &oStream
49  ,const std::basic_string<char_type,traits_type> &tabIndentStr
50  ,const int startingTab
51  ,const bool showLinePrefix
52  ,const int maxLenLinePrefix
53  ,const bool showTabCount
54  ,const bool showProcRank
55  );
56 
58  void initialize(
59  const RCP<std::basic_ostream<char_type,traits_type> > &oStream
60  ,const std::basic_string<char_type,traits_type> &tabIndentStr
61  ,const int startingTab
62  ,const bool showLinePrefix
63  ,const int maxLenLinePrefix
64  ,const bool showTabCount
65  ,const bool showProcRank
66  );
67 
70 
72  void setTabIndentStr(const std::basic_string<char_type,traits_type> &tabIndentStr);
73 
75  const std::basic_string<char_type,traits_type>& getTabIndentStr() const;
76 
78  void setShowLinePrefix(const bool showLinePrefix);
79 
81  bool getShowLinePrefix() const;
82 
84  void setMaxLenLinePrefix(const int maxLenLinePrefix);
85 
87  int getMaxLenLinePrefix() const;
88 
90  void setShowTabCount(const bool showTabCount);
91 
93  bool getShowTabCount() const;
94 
96  void setShowProcRank(const bool showProcRank);
97 
99  bool getShowProcRank() const;
100 
107  void setProcRankAndSize( const int procRank, const int numProcs );
108 
113  int getProcRank() const;
114 
119  int getNumProcs() const;
120 
135  void setOutputToRootOnly( const int rootRank );
136 
138  int getOutputToRootOnly() const;
139 
148  void pushTab(const int tabs);
149 
151  int getNumCurrTabs() const;
152 
160  void popTab();
161 
163  void pushLinePrefix(
164  const std::basic_string<char_type,traits_type> &linePrefix
165  );
166 
168  void popLinePrefix();
169 
171  const std::basic_string<char_type,traits_type>& getTopLinePrefix() const;
172 
174  void pushDisableTabbing();
175 
177  void popDisableTabbing();
178 
179 protected:
180 
182 
183 
185  std::streamsize xsputn(const char_type* s, std::streamsize n);
186 
189 
190 #ifdef TEUCHOS_FANCY_OSTREAM_SHOW_ALL_CALLS
191 
192  void imbue(const locale& l)
193  {
194  std::cerr << "\ncalled imbue()\n";
195  std::basic_streambuf<CharT,Traits>::imbue(l);
196  }
197 
198  basic_streambuf<char_type,Traits>*
199  setbuf(char_type* s, streamsize n)
200  {
201  std::cerr << "\ncalled setbuf()\n";
202  return std::basic_streambuf<CharT,Traits>::setbuf(s,n);
203  }
204 
205  pos_type
206  seekoff(off_type a, ios_base::seekdir b,ios_base::openmode c)
207  {
208  std::cerr << "\ncalled seekoff()\n";
209  return std::basic_streambuf<CharT,Traits>::seekoff(a,b,c);
210  }
211 
212  pos_type
213  seekpos(pos_type a, ios_base::openmode b)
214  {
215  std::cerr << "\ncalled seekpos()\n";
216  return std::basic_streambuf<CharT,Traits>::seekpos(a,b);
217  }
218 
219  int
220  sync()
221  {
222  std::cerr << "\ncalled sync()\n";
223  return std::basic_streambuf<CharT,Traits>::sync();
224  }
225 
226  streamsize
227  showmanyc()
228  {
229  std::cerr << "\ncalled showmanyc()\n";
230  return std::basic_streambuf<CharT,Traits>::showmanyc();
231  }
232 
233  streamsize
234  xsgetn(char_type* s, streamsize n)
235  {
236  std::cerr << "\ncalled xsgetn()\n";
237  return std::basic_streambuf<CharT,Traits>::xsgetn(s,n);
238  }
239 
240  int_type
241  underflow()
242  {
243  std::cerr << "\ncalled underflow()\n";
244  return std::basic_streambuf<CharT,Traits>::underflow();
245  }
246 
247  int_type
248  uflow()
249  {
250  std::cerr << "\ncalled uflow()\n";
251  return std::basic_streambuf<CharT,Traits>::uflow();
252  }
253 
254  int_type
255  pbackfail(int_type c = traits_type::eof())
256  {
257  std::cerr << "\ncalled pbackfail()\n";
258  return std::basic_streambuf<CharT,Traits>::pbackfail(c);
259  }
260 
261 #endif // TEUCHOS_FANCY_OSTREAM_SHOW_ALL_CALLS
262 
264 
265 private:
266 
267  // ////////////////////////
268  // Private types
269 
270  typedef std::basic_string<char_type,traits_type> string_t;
271  typedef std::deque<int> tabIndentStack_t;
272  typedef std::deque<string_t> linePrefixStack_t;
273 
274  // ////////////////////////
275  // Private data members
276 
279  std::basic_string<char_type,traits_type> tabIndentStr_;
288 
290 
295 
297 
298  // ////////////////////////
299  // Private member functions
300 
301  std::ostream& out();
302 
303  void writeChars( const char_type s[], std::streamsize n );
304 
305  void writeFrontMatter();
306 
307  // Not defined and not to be called
312  );
313 
314 };
315 
316 
348 template <typename CharT, typename Traits = std::char_traits<CharT> >
349 class basic_FancyOStream : public std::basic_ostream<CharT, Traits>
350 {
351 public:
352 
354 
355 
357  typedef CharT char_type;
359  typedef Traits traits_type;
361  typedef typename traits_type::int_type int_type;
363  typedef typename traits_type::pos_type pos_type;
365  typedef typename traits_type::off_type off_type;
371  typedef std::basic_ostream<char_type, traits_type> ostream_t;
372 
374 
376 
377 
407  explicit
409  const RCP< std::basic_ostream<char_type,traits_type> > &oStream
410  ,const std::basic_string<char_type,traits_type> &tabIndentStr = " "
411  ,const int startingTab = 0
412  ,const bool showLinePrefix = false
413  ,const int maxLenLinePrefix = 10
414  ,const bool showTabCount = false
415  ,const bool showProcRank = false
416  );
417 
421  void initialize(
422  const RCP< std::basic_ostream<char_type,traits_type> > &oStream
423  ,const std::basic_string<char_type,traits_type> &tabIndentStr = " "
424  ,const int startingTab = 0
425  ,const bool showLinePrefix = false
426  ,const int maxLenLinePrefix = 10
427  ,const bool showTabCount = false
428  ,const bool showProcRank = false
429  );
430 
433 
436  const std::basic_string<char_type,traits_type> &tabIndentStr
437  );
438 
440  const std::basic_string<char_type,traits_type>& getTabIndentStr() const;
441 
456  basic_FancyOStream& setShowAllFrontMatter(const bool showAllFrontMatter);
457 
459  basic_FancyOStream& setShowLinePrefix(const bool showLinePrefix);
460 
462  basic_FancyOStream& setMaxLenLinePrefix(const int maxLenLinePrefix);
463 
465  basic_FancyOStream& setShowTabCount(const bool showTabCount);
466 
468  basic_FancyOStream& setShowProcRank(const bool showProcRank);
469 
476  basic_FancyOStream& setProcRankAndSize( const int procRank, const int numProcs );
477 
492  basic_FancyOStream& setOutputToRootOnly( const int rootRank );
493 
495  int getOutputToRootOnly() const;
496 
499 
501 
503 
504 
513  void pushTab(const int tabs = 1);
514 
516  int getNumCurrTabs() const;
517 
525  void popTab();
526 
528  void pushLinePrefix(const std::basic_string<char_type,traits_type> &linePrefix);
529 
531  void popLinePrefix();
532 
534  const std::basic_string<char_type,traits_type>& getTopLinePrefix() const;
535 
537  void pushDisableTabbing();
538 
540  void popDisableTabbing();
541 
543 
544 private:
545 
547 
548  // Not defined and not to be called
552 
553 };
554 
555 
563 inline
566  const RCP< std::basic_ostream<char> >& oStream,
567  const std::basic_string<char>& tabIndentStr = " ",
568  const int startingTab = 0,
569  const bool showLinePrefix = false,
570  const int maxLenLinePrefix = 10,
571  const bool showTabCount = false,
572  const bool showProcRank = false
573  )
574 {
575  if (nonnull(oStream)) {
576  return rcp(
578  oStream,tabIndentStr,startingTab,showLinePrefix,
579  maxLenLinePrefix,showTabCount,showProcRank
580  )
581  );
582  }
583  return null;
584 }
585 
586 
595 inline
597 getFancyOStream( const RCP<std::basic_ostream<char> > &out )
598 {
599  if (is_null(out))
600  return Teuchos::null;
602  fancyOut = rcp_dynamic_cast<basic_FancyOStream<char> >(out);
603  if(nonnull(fancyOut))
604  return fancyOut;
605  return rcp(new basic_FancyOStream<char>(out));
606 }
607 
608 
620 template <typename CharT, typename Traits = std::char_traits<CharT> >
622 {
623 public:
624 
626  static const int DISABLE_TABBING = -99999; // This magic number should be just fine!
629  const RCP<basic_FancyOStream<CharT,Traits> > &fancyOStream
630  ,const int tabs = 1
631  ,const std::basic_string<CharT,Traits> linePrefix = ""
632  )
633  :fancyOStream_(fancyOStream)
634  ,tabs_(tabs)
635  ,linePrefix_(linePrefix)
636  {
637  updateState();
638  }
641  const RCP<std::basic_ostream<CharT,Traits> > &oStream
642  ,const int tabs = 1
643  ,const std::basic_string<CharT,Traits> linePrefix = ""
644  )
645  :fancyOStream_(getFancyOStream(oStream))
646  ,tabs_(tabs)
647  ,linePrefix_(linePrefix)
648  {
649  updateState();
650  }
654  ,const int tabs = 1
655  ,const std::basic_string<CharT,Traits> linePrefix = ""
656  )
657  :fancyOStream_(rcp(&fancyOStream,false))
658  ,tabs_(tabs)
659  ,linePrefix_(linePrefix)
660  {
661  updateState();
662  }
665  std::basic_ostream<CharT,Traits> &oStream
666  ,const int tabs = 1
667  ,const std::basic_string<CharT,Traits> linePrefix = ""
668  )
669  :fancyOStream_(getFancyOStream(rcp(&oStream, false)))
670  ,tabs_(tabs)
671  ,linePrefix_(linePrefix)
672  {
673  updateState();
674  }
676  basic_OSTab( const basic_OSTab &osTab )
678  ,tabs_(osTab.tabs_)
679  {
680  updateState();
681  }
684  {
685  if(fancyOStream_.get()) {
687  fancyOStream_->popDisableTabbing();
688  else
689  fancyOStream_->popTab();
690  if(linePrefix_.length()) fancyOStream_->popLinePrefix();
691  }
692  }
695  {
697  tabs_ = osTab.tabs_;
698  updateState();
699  return *this;
700  }
702  basic_OSTab<CharT,Traits>& incrTab(const int tabs = 1)
703  {
704  tabs_ += tabs;
705  if(fancyOStream_.get()) {
706  fancyOStream_->popTab();
707  fancyOStream_->pushTab(tabs_);
708  }
709  return *this;
710  }
713  {
714  return *fancyOStream_;
715  }
718  {
719  return fancyOStream_.get();
720  }
721 
722 private:
723 
725  int tabs_;
726  std::basic_string<CharT,Traits> linePrefix_;
727 
728  void updateState()
729  {
730  if(fancyOStream_.get()) {
732  fancyOStream_->pushDisableTabbing();
733  else
734  fancyOStream_->pushTab(tabs_);
735  if(linePrefix_.length()) fancyOStream_->pushLinePrefix(linePrefix_);
736  }
737  }
738 
739 };
740 
741 
757 template <typename CharT, typename Traits>
758 RCP<basic_FancyOStream<CharT,Traits> >
761  const int tabs = 1,
762  const std::basic_string<CharT,Traits> linePrefix = ""
763  )
764 {
765  if(out.get()==NULL)
766  return Teuchos::null;
767  RCP<basic_FancyOStream<CharT,Traits> > fancyOut = out;
768  set_extra_data(
769  rcp(new basic_OSTab<CharT,Traits>(out,tabs,linePrefix)),
770  "OSTab",
771  inOutArg(fancyOut),
772  PRE_DESTROY,
773  false
774  );
775  return fancyOut;
776 }
777 
778 
794 template <typename CharT, typename Traits>
797  const RCP<std::basic_ostream<CharT,Traits> > &out
798  ,const int tabs = 1
799  ,const std::basic_string<CharT,Traits> linePrefix = ""
800  )
801 {
802  return tab(getFancyOStream(out),tabs,linePrefix);
803 }
804 
805 
806 // ///////////////////////////////
807 // Typedefs
808 
809 
814 
815 
820 
821 
825 #define TEUCHOS_OSTAB ::Teuchos::OSTab __localThisTab = this->getOSTab()
826 
830 #define TEUCHOS_OSTAB_DIFF( DIFF ) ::Teuchos::OSTab DIFF ## __localThisTab = this->getOSTab()
831 
832 
833 // ////////////////////////////////
834 // Defintions
835 
836 
837 //
838 // basic_FancyOStream_buf
839 //
840 
841 
842 template<typename CharT, typename Traits>
844  const RCP<std::basic_ostream<char_type,traits_type> > &oStream
845  ,const std::basic_string<char_type,traits_type> &tabIndentStr
846  ,const int startingTab
847  ,const bool showLinePrefix
848  ,const int maxLenLinePrefix
849  ,const bool showTabCount
850  ,const bool showProcRank
851  )
852 {
853  this->initialize(oStream,tabIndentStr,startingTab,showLinePrefix,
854  maxLenLinePrefix,showTabCount,showProcRank);
855 }
856 
857 
858 template<typename CharT, typename Traits>
860  const RCP<std::basic_ostream<char_type,traits_type> > &oStream
861  ,const std::basic_string<char_type,traits_type> &tabIndentStr
862  ,const int startingTab
863  ,const bool showLinePrefix
864  ,const int maxLenLinePrefix
865  ,const bool showTabCount
866  ,const bool showProcRank
867  )
868 {
869  oStreamSet_ = oStream;
870  oStream_ = oStream;
871  tabIndentStr_ = tabIndentStr;
872  showLinePrefix_ = showLinePrefix;
873  maxLenLinePrefix_ = maxLenLinePrefix;
874  showTabCount_ = showTabCount;
875  showProcRank_ = showProcRank;
876  rootRank_ = -1;
877  procRank_ = GlobalMPISession::getRank();
878  numProcs_ = GlobalMPISession::getNProc();
879  rankPrintWidth_ = int(std::log10(float(numProcs_)))+1;
880  tabIndent_ = startingTab;
881  tabIndentStack_.clear();
882  linePrefixStack_.clear();
883  wroteNewline_ = true;
884  enableTabbingStack_ = 0;
885 }
886 
887 
888 template<typename CharT, typename Traits>
891 {
892  return oStreamSet_;
893 }
894 
895 
896 template<typename CharT, typename Traits>
898  const std::basic_string<char_type,traits_type> &tabIndentStr
899  )
900 {
901  tabIndentStr_ = tabIndentStr;
902 }
903 
904 
905 template<typename CharT, typename Traits>
906 const std::basic_string<CharT,Traits>&
908 {
909  return tabIndentStr_;
910 }
911 
912 
913 template<typename CharT, typename Traits>
915 {
916  showLinePrefix_ = showLinePrefix;
917 }
918 
919 
920 template<typename CharT, typename Traits>
922 {
923  return showLinePrefix_;
924 }
925 
926 
927 template<typename CharT, typename Traits>
929 {
930  TEUCHOS_TEST_FOR_EXCEPT( !(maxLenLinePrefix>=5) );
931  maxLenLinePrefix_ = maxLenLinePrefix;
932 }
933 
934 
935 template<typename CharT, typename Traits>
937 {
938  return maxLenLinePrefix_;
939 }
940 
941 
942 template<typename CharT, typename Traits>
944 {
945  showTabCount_ = showTabCount;
946 }
947 
948 
949 template<typename CharT, typename Traits>
951 {
952  return showTabCount_;
953 }
954 
955 
956 template<typename CharT, typename Traits>
958 {
959  showProcRank_ = showProcRank;
960 }
961 
962 
963 template<typename CharT, typename Traits>
965 {
966  return showProcRank_;
967 }
968 
969 
970 template<typename CharT, typename Traits>
972  const int procRank, const int numProcs
973  )
974 {
975  procRank_ = procRank;
976  numProcs_ = numProcs;
977 }
978 
979 
980 template<typename CharT, typename Traits>
982 {
983  return procRank_;
984 }
985 
986 
987 template<typename CharT, typename Traits>
989 {
990  return numProcs_;
991 }
992 
993 
994 template<typename CharT, typename Traits>
996  const int rootRank
997  )
998 {
999  rootRank_ = rootRank;
1000  if(rootRank >= 0) {
1001  if(rootRank == procRank_)
1002  oStream_ = oStreamSet_;
1003  else
1004  oStream_ = rcp(new oblackholestream());
1005  // Only processor is being output to so there is no need for line
1006  // batching!
1007  lineOut_ = null;
1008  }
1009  else {
1010  oStream_ = oStreamSet_;
1011  // Output is being sent to all processors so we need line batching to
1012  // insure that each line will be printed all together!
1013  lineOut_ = rcp(new std::ostringstream());
1014  }
1015 }
1016 
1017 
1018 template<typename CharT, typename Traits>
1020 {
1021  return rootRank_;
1022 }
1023 
1024 
1025 template<typename CharT, typename Traits>
1027 {
1028  if( tabIndent_ + tabs < 0 ) {
1029  tabIndentStack_.push_back(-tabIndent_);
1030  tabIndent_ = 0;
1031  }
1032  else {
1033  tabIndentStack_.push_back(tabs);
1034  tabIndent_ += tabs;
1035  }
1036 }
1037 
1038 
1039 template<typename CharT, typename Traits>
1041 {
1042  return tabIndent_;
1043 }
1044 
1045 
1046 template<typename CharT, typename Traits>
1048 {
1049  tabIndent_ -= tabIndentStack_.back();
1050  tabIndentStack_.pop_back();
1051 }
1052 
1053 
1054 template<typename CharT, typename Traits>
1056  const std::basic_string<char_type,traits_type> &linePrefix
1057  )
1058 {
1059  linePrefixStack_.push_back(linePrefix);
1060 }
1061 
1062 
1063 template<typename CharT, typename Traits>
1065 {
1066  linePrefixStack_.pop_back();
1067 }
1068 
1069 
1070 template<typename CharT, typename Traits>
1071 const std::basic_string<CharT,Traits>&
1073 {
1074  return linePrefixStack_.back();
1075 }
1076 
1077 
1078 template<typename CharT, typename Traits>
1080 {
1081  ++enableTabbingStack_;
1082 }
1083 
1084 
1085 template<typename CharT, typename Traits>
1087 {
1088  --enableTabbingStack_;
1089 }
1090 
1091 
1092 // protected
1093 
1094 
1095 template<typename CharT, typename Traits>
1097  const char_type* s, std::streamsize n
1098  )
1099 {
1100 #ifdef TEUCHOS_FANCY_OSTREAM_SHOW_ALL_CALLS
1101  std::cerr << "\ncalled xsputn()\n";
1102 #endif
1103  writeChars(s,n);
1104  return n;
1105 }
1106 
1107 
1108 template<typename CharT, typename Traits>
1111 {
1112 #ifdef TEUCHOS_FANCY_OSTREAM_SHOW_ALL_CALLS
1113  std::cerr << "\ncalled overflow()\n";
1114 #endif
1115  if(c != traits_type::eof()) {
1116  const char_type cc[] = { traits_type::to_char_type(c) };
1117  this->writeChars(cc,1);
1118  }
1119  return traits_type::not_eof(c);
1120  //return std::basic_streambuf<CharT,Traits>::overflow(c);
1121 }
1122 
1123 
1124 // private
1125 
1126 
1127 template<typename CharT, typename Traits>
1129 {
1130  if(lineOut_.get())
1131  return *lineOut_;
1132  return *oStream_;
1133 }
1134 
1135 
1136 template<typename CharT, typename Traits>
1138  const char_type s[], std::streamsize n
1139  )
1140 {
1141  if(n == 0) return;
1142  std::streamsize p = 0, first_p = 0;
1143  bool done_outputting = false;
1144  const char_type newline = '\n';
1145  while( !done_outputting ) {
1146  // Find the next newline
1147  for( p = first_p; p < n; ++p ) {
1148  if(s[p] == newline) {
1149  break;
1150  }
1151  }
1152  if(p == n) {
1153  // We did not find a newline at the end!
1154  --p;
1155  done_outputting = true;
1156  }
1157  else if( p == n-1 && s[p] == newline ) {
1158  // The last character in the std::string is a newline
1159  done_outputting = true;
1160  }
1161  // Write the beginning of the line if we need to
1162  if(wroteNewline_) {
1163  writeFrontMatter();
1164  wroteNewline_ = false;
1165  }
1166  // Write up to the newline or the end of the std::string
1167  out().write(s+first_p,p-first_p+1);
1168  if(s[p] == newline) {
1169  wroteNewline_ = true;
1170  if(lineOut_.get()) {
1171  *oStream_ << lineOut_->str() << std::flush;
1172  lineOut_->str("");
1173  }
1174  }
1175  // Update for next search
1176  if(!done_outputting)
1177  first_p = p+1;
1178  }
1179 }
1180 
1181 
1182 template<typename CharT, typename Traits>
1184 {
1185  bool didOutput = false;
1186  std::ostream &o = this->out();
1187  if(showProcRank_) {
1188  o << "p=" << std::right << std::setw(rankPrintWidth_) << procRank_;
1189  didOutput = true;
1190  }
1191  if(showLinePrefix_) {
1192  if(didOutput)
1193  o << ", ";
1194  std::string currLinePrefix = "";
1195  if ( linePrefixStack_.size() )
1196  currLinePrefix = this->getTopLinePrefix();
1197  const int localMaxLenLinePrefix =
1198  TEUCHOS_MAX( as<int>(currLinePrefix.length()), maxLenLinePrefix_ );
1199  o << std::left << std::setw(localMaxLenLinePrefix);
1200  o << currLinePrefix;
1201  didOutput = true;
1202  }
1203  if(showTabCount_) {
1204  if(didOutput)
1205  o << ", ";
1206  o << "tabs=" << std::right << std::setw(2) << tabIndent_;
1207  didOutput = true;
1208  }
1209  // ToDo: Add the Prefix name if asked
1210  // ToDo: Add the processor number if asked
1211  // ToDo: Add the number of indents if asked
1212  if(didOutput) {
1213  o << " |" << tabIndentStr_;
1214  }
1215  if(enableTabbingStack_==0) {
1216  for( int i = 0; i < tabIndent_; ++i )
1217  o << tabIndentStr_;
1218  }
1219 }
1220 
1221 
1222 //
1223 // basic_FancyOStream
1224 //
1225 
1226 
1227 template<typename CharT, typename Traits>
1229  const RCP< std::basic_ostream<char_type,traits_type> > &oStream
1230  ,const std::basic_string<char_type,traits_type> &tabIndentStr
1231  ,const int startingTab
1232  ,const bool showLinePrefix
1233  ,const int maxLenLinePrefix
1234  ,const bool showTabCount
1235  ,const bool showProcRank
1236  )
1237  :ostream_t(NULL),
1238  streambuf_(oStream,tabIndentStr,startingTab,showLinePrefix,
1239  maxLenLinePrefix,showTabCount,showProcRank)
1240 {
1241  this->init(&streambuf_);
1242 }
1243 
1244 
1245 template<typename CharT, typename Traits>
1247  const RCP< std::basic_ostream<char_type,traits_type> > &oStream
1248  ,const std::basic_string<char_type,traits_type> &tabIndentStr
1249  ,const int startingTab
1250  ,const bool showLinePrefix
1251  ,const int maxLenLinePrefix
1252  ,const bool showTabCount
1253  ,const bool showProcRank
1254  )
1255 {
1256  streambuf_.initialize(oStream,tabIndentStr,startingTab,
1257  showLinePrefix,maxLenLinePrefix,showTabCount,showProcRank);
1258  this->init(&streambuf_);
1259 }
1260 
1261 
1262 template<typename CharT, typename Traits>
1265 {
1266  return streambuf_.getOStream();
1267 }
1268 
1269 
1270 template<typename CharT, typename Traits>
1273  const std::basic_string<char_type,traits_type> &tabIndentStr
1274  )
1275 {
1276  streambuf_.setTabIndentStr(tabIndentStr);
1277  return *this;
1278 }
1279 
1280 
1281 template<typename CharT, typename Traits>
1282 const std::basic_string<CharT,Traits>&
1284 {
1285  return streambuf_.getTabIndentStr();
1286 }
1287 
1288 
1289 template<typename CharT, typename Traits>
1292  const bool showAllFrontMatter
1293  )
1294 {
1295  streambuf_.setShowLinePrefix(showAllFrontMatter);
1296  streambuf_.setShowTabCount(showAllFrontMatter);
1297  streambuf_.setShowProcRank(showAllFrontMatter);
1298  return *this;
1299 }
1300 
1301 
1302 template<typename CharT, typename Traits>
1305 {
1306  streambuf_.setShowLinePrefix(showLinePrefix);
1307  return *this;
1308 }
1309 
1310 
1311 template<typename CharT, typename Traits>
1314 {
1315  streambuf_.setMaxLenLinePrefix(maxLenLinePrefix);
1316  return *this;
1317 }
1318 
1319 
1320 template<typename CharT, typename Traits>
1323 {
1324  streambuf_.setShowTabCount(showTabCount);
1325  return *this;
1326 }
1327 
1328 
1329 template<typename CharT, typename Traits>
1332 {
1333  streambuf_.setShowProcRank(showProcRank);
1334  return *this;
1335 }
1336 
1337 
1338 template<typename CharT, typename Traits>
1340 basic_FancyOStream<CharT,Traits>::setProcRankAndSize( const int procRank, const int numProcs )
1341 {
1342  streambuf_.setProcRankAndSize(procRank,numProcs);
1343  return *this;
1344 }
1345 
1346 
1347 template<typename CharT, typename Traits>
1350 {
1351  streambuf_.setOutputToRootOnly(rootRank);
1352  return *this;
1353 }
1354 
1355 
1356 template<typename CharT, typename Traits>
1358 {
1359  return streambuf_.getOutputToRootOnly();
1360 }
1361 
1362 
1363 template<typename CharT, typename Traits>
1365  const basic_FancyOStream<CharT,Traits> &oStream )
1366 {
1367  //streambuf_.setTabIndentStr(oStream.streambuf_.getTabIndentStr());
1368  streambuf_.setShowLinePrefix(oStream.streambuf_.getShowLinePrefix());
1369  streambuf_.setMaxLenLinePrefix(oStream.streambuf_.getMaxLenLinePrefix());
1370  streambuf_.setShowTabCount(oStream.streambuf_.getShowTabCount());
1371  streambuf_.setShowProcRank(oStream.streambuf_.getShowProcRank());
1372  streambuf_.setProcRankAndSize(oStream.streambuf_.getProcRank(),
1373  oStream.streambuf_.getNumProcs());
1374  streambuf_.setOutputToRootOnly(oStream.streambuf_.getOutputToRootOnly());
1375 }
1376 
1377 
1378 template<typename CharT, typename Traits>
1380 {
1381  streambuf_.pushTab(tabs);
1382 }
1383 
1384 
1385 template<typename CharT, typename Traits>
1387 {
1388  return streambuf_.getNumCurrTabs();
1389 }
1390 
1391 
1392 template<typename CharT, typename Traits>
1394 {
1395  streambuf_.popTab();
1396 }
1397 
1398 
1399 template<typename CharT, typename Traits>
1401  const std::basic_string<char_type,traits_type> &linePrefix
1402  )
1403 {
1404  streambuf_.pushLinePrefix(linePrefix);
1405 }
1406 
1407 
1408 template<typename CharT, typename Traits>
1410 {
1411  streambuf_.popLinePrefix();
1412 }
1413 
1414 
1415 template<typename CharT, typename Traits>
1416 const std::basic_string<CharT,Traits>&
1418 {
1419  return streambuf_.getTopLinePrefix();
1420 }
1421 
1422 
1423 template<typename CharT, typename Traits>
1425 {
1426  streambuf_.pushDisableTabbing();
1427 }
1428 
1429 
1430 template<typename CharT, typename Traits>
1432 {
1433  return streambuf_.popDisableTabbing();
1434 }
1435 
1436 
1437 } // namespace Teuchos
1438 
1439 
1440 #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.
RCP< std::ostringstream > lineOut_
static int getNProc()
The number of processes in MPI_COMM_WORLD.
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
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)
basic_FancyOStream & setShowTabCount(const bool showTabCount)
const std::basic_string< char_type, traits_type > & getTabIndentStr() const
Get the tab indent string.
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 ...
basic_OSTab< CharT, Traits > & operator=(const basic_OSTab &osTab)
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 &quot;front matter.&quot;.
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.
RCP< std::basic_ostream< char_type, traits_type > > getOStream()
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.
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)
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...
basic_OSTab(const basic_OSTab &osTab)