Sierra Toolkit  Version of the Day
WriterExt.hpp
1 /*------------------------------------------------------------------------*/
2 /* Copyright 2010 Sandia Corporation. */
3 /* Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive */
4 /* license for use of this work by or on behalf of the U.S. Government. */
5 /* Export of this program may require a license from the */
6 /* United States Government. */
7 /*------------------------------------------------------------------------*/
8 
9 #ifndef STK_UTIL_DIAG_WRITEREXT_HPP
10 #define STK_UTIL_DIAG_WRITEREXT_HPP
11 
12 #include <bitset>
13 #include <iostream>
14 #include <list>
15 #include <map>
16 #include <set>
17 #include <memory>
18 #include <stack>
19 #include <string>
20 #include <typeinfo>
21 #include <vector>
22 #include <stk_util/stk_config.h>
23 #include <stk_util/util/VecMap.hpp>
24 #include <stk_util/util/VecSet.hpp>
25 
26 #include <stk_util/diag/Writer.hpp>
27 
28 
29 #include <stk_util/diag/String.hpp>
30 #include <stk_util/diag/StringUtil.hpp>
31 
32 #include <stk_util/util/FeatureTest.hpp>
33 #include <stk_util/util/Array.hpp>
34 #include <stk_util/util/FArrayPrint.hpp>
35 #include <stk_util/parallel/MPI.hpp>
36 #include <stk_util/diag/Mapv.hpp>
37 #include <stk_util/diag/Option.hpp>
38 
39 
40 namespace stk_classic {
41 namespace diag {
42 
47 
60 Writer &operator<<(Writer &dout, const std::type_info &t);
61 
73 template <class T>
74 Writer &operator<<(Writer &dout, const std::auto_ptr<T> &t) {
75  if (t.get())
76  dout << " " << typeid(t) << ", " << t.get() << ", " << *t;
77  else
78  dout << " " << typeid(t) << ", <not created or not owner>";
79 
80  return dout;
81 }
82 
94 template <class T, class U>
95 Writer &operator<<(Writer & dout, const std::pair<T, U> &pair) {
96 // dout << typeid(pair) << "(" << pair.first << ":" << pair.second << ")";
97  dout << "(" << pair.first << ":" << pair.second << ")";
98 
99  return dout;
100 }
101 
113 template <class T>
114 Writer &
116  Writer & dout,
117  const std::vector<T> & t)
118 {
119  if (dout.shouldPrint()) {
120  dout << typeid(t) << ", size " << t.size() << push << dendl;
121 
122  if (t.size() <= 10) {
123  for (typename std::vector<T>::const_iterator it = t.begin(); it != t.end(); ++it)
124  dout << (*it) << " ";
125  dout << dendl;
126  }
127  else {
128  int i = 0;
129  for (typename std::vector<T>::const_iterator it = t.begin(); it != t.end(); ++it, ++i)
130  dout << "[" << i << "] " << (*it) << dendl;
131  }
132 
133  dout << pop;
134  }
135 
136  return dout;
137 }
138 
150 template <class T>
151 Writer &
153  Writer & dout,
154  const std::vector<T *> & t)
155 {
156  if (dout.shouldPrint()) {
157  dout << typeid(t) << ", size " << t.size() << push << dendl;
158 
159  int i = 0;
160  for (typename std::vector<T *>::const_iterator it = t.begin(); it != t.end(); ++it, ++i)
161  dout << "[" << i << "] " << c_ptr_<T>(*it) << dendl;
162 
163  dout << pop;
164  }
165 
166  return dout;
167 }
168 
180 template <class T>
181 Writer &
183  Writer & dout,
184  const std::list<T> & t)
185 {
186  if (dout.shouldPrint()) {
187  dout << typeid(t) << ", size " << t.size() << push << dendl;
188 
189  int i = 0;
190  for (typename std::list<T>::const_iterator it = t.begin(); it != t.end(); ++it, ++i)
191  dout << "[" << i << "] " << (*it) << dendl;
192 
193  dout << pop;
194  }
195 
196  return dout;
197 }
198 
210 template <class T>
211 Writer &
213  Writer & dout,
214  const std::list<T *> & t)
215 {
216  if (dout.shouldPrint()) {
217  dout << typeid(t) << ", size " << t.size() << push << dendl;
218 
219  int i = 0;
220  for (typename std::list<T *>::const_iterator it = t.begin(); it != t.end(); ++it, ++i)
221  dout << "[" << i << "] " << c_ptr_<T>(*it) << dendl;
222 
223  dout << pop;
224  }
225 
226  return dout;
227 }
228 
240 template <class Key, class T, class L>
241 Writer &
243  Writer & dout,
244  const std::map<Key, T, L> & t)
245 {
246  if (dout.shouldPrint()) {
247  dout << typeid(t) << ", size " << t.size() << push << dendl;
248 
249  for (typename std::map<Key, T, L>::const_iterator it = t.begin(); it != t.end(); ++it)
250  dout << "[" << (*it).first << "] " << (*it).second << dendl;
251 
252  dout << pop;
253  }
254 
255  return dout;
256 }
257 
269 template <class Key, class T, class L>
270 Writer &
272  Writer & dout,
273  const std::map<Key, T *, L> & t)
274 {
275  if (dout.shouldPrint()) {
276  dout << typeid(t) << ", size " << t.size() << push << dendl;
277 
278  for (typename std::map<Key, T *, L>::const_iterator it = t.begin(); it != t.end(); ++it)
279  dout << "[" << (*it).first << "] " << c_ptr_<T>((*it).second) << std::endl;
280 
281  dout << pop;
282  }
283 
284  return dout;
285 }
286 
298 template <class Key, class T, class L>
299 Writer &
301  Writer & dout,
302  const std::multimap<Key, T, L> & t)
303 {
304  if (dout.shouldPrint()) {
305  dout << typeid(t) << ", size " << t.size() << push << dendl;
306 
307  for (typename std::multimap<Key, T, L>::const_iterator it = t.begin(); it != t.end(); ++it)
308  dout << "[" << (*it).first << "] " << (*it).second << dendl;
309 
310  dout << pop;
311  }
312 
313  return dout;
314 }
315 
327 template <class Key, class T, class L>
328 Writer &
330  Writer & dout,
331  const std::multimap<Key, T *, L> & t)
332 {
333  if (dout.shouldPrint()) {
334  dout << typeid(t) << ", size " << t.size() << push << dendl;
335 
336  for (typename std::multimap<Key, T *, L>::const_iterator it = t.begin(); it != t.end(); ++it)
337  dout << "[" << (*it).first << "] " << c_ptr_<T>((*it).second) << std::endl;
338 
339  dout << pop;
340  }
341 
342  return dout;
343 }
344 
356 template <class Key, class L>
357 Writer &
359  Writer & dout,
360  const std::set<Key, L> & t)
361 {
362  if (dout.shouldPrint()) {
363  dout << typeid(t) << ", size " << t.size() << push << dendl;
364 
365  for (typename std::set<Key, L>::const_iterator it = t.begin(); it != t.end(); ++it)
366  dout << (*it) << dendl;
367 
368  dout << pop;
369  }
370 
371  return dout;
372 }
373 
385 template <class Key, class L>
386 Writer &
388  Writer & dout,
389  const std::set<Key *, L> & t)
390 {
391  if (dout.shouldPrint()) {
392  dout << typeid(t) << ", size " << t.size() << push << dendl;
393 
394  for (typename std::set<Key *, L>::const_iterator it = t.begin(); it != t.end(); ++it)
395  dout << c_ptr_<Key>((*it)) << dendl;
396 
397  dout << pop;
398  }
399 
400  return dout;
401 }
402 
414 template <class Key, class L>
415 Writer &
417  Writer & dout,
418  const std::multiset<Key, L> & t)
419 {
420  if (dout.shouldPrint()) {
421  dout << typeid(t) << ", size " << t.size() << push << dendl;
422 
423  for (typename std::multiset<Key, L>::const_iterator it = t.begin(); it != t.end(); ++it)
424  dout << (*it) << dendl;
425 
426  dout << pop;
427  }
428 
429  return dout;
430 }
431 
443 template <class Key, class L>
444 Writer &
446  Writer & dout,
447  const std::multiset<Key *, L> & t)
448 {
449  if (dout.shouldPrint()) {
450  dout << typeid(t) << ", size " << t.size() << push << dendl;
451 
452  for (typename std::multiset<Key *, L>::const_iterator it = t.begin(); it != t.end(); ++it)
453  dout << c_ptr_<Key>((*it)) << dendl;
454 
455  dout << pop;
456  }
457 
458  return dout;
459 }
460 
461 // /**
462 // * @brief Template <b>dump</b> prints the object contained within a
463 // * hash_map to the diagnostic writer.
464 // *
465 // * @param dout a <b>Writer</b> reference to the diagnostic writer to
466 // * write the hash_map to.
467 // *
468 // * @param t a <b>hash_map</b> of objects.
469 // *
470 // * @return a <b>Writer</b> reference to this object
471 // */
472 // template <class Key, class T>
473 // Writer &
474 // dump(
475 // Writer & dout,
476 // const hash_map<Key, T> & t)
477 // {
478 // if (dout.shouldPrint()) {
479 // dout << typeid(t) << ", size " << t.size() << push << dendl;
480 
481 // for (typename hash_map<Key, T>::const_iterator it = t.begin(); it != t.end(); ++it)
482 // dout << "[" << (*it).first << "] " << (*it).second << dendl;
483 
484 // dout << pop;
485 // }
486 
487 // return dout;
488 // }
489 
490 // /**
491 // * @brief Template <b>dump</b> prints the object pointed to that are
492 // * contained within a hash_map to the diagnostic writer.
493 // *
494 // * @param dout a <b>Writer</b> reference to the diagnostic writer to
495 // * write the hash_map to.
496 // *
497 // * @param t a <b>hash_map</b> of objects.
498 // *
499 // * @return a <b>Writer</b> reference to this object
500 // */
501 // template <class Key, class T>
502 // Writer &
503 // dump(
504 // Writer & dout,
505 
506 // const hash_map<Key, T *> & t)
507 // {
508 // if (dout.shouldPrint()) {
509 // dout << typeid(t) << ", size " << t.size() << push << dendl;
510 
511 // for (typename hash_map<Key, T *>::const_iterator it = t.begin(); it != t.end(); ++it)
512 // dout << "[" << (*it).first << "] " << (*it)->second << dendl;
513 
514 // dout << pop;
515 // }
516 
517 // return dout;
518 // }
519 
520 
521 template <size_t n>
522 Writer &operator<<(Writer &dout, const std::bitset<n> &t) {
523  if (dout.shouldPrint())
524  dout.getStream() << t;
525 
526  return dout;
527 }
528 
529 
541 template <class T>
542 Writer &operator<<(Writer &dout, const std::vector<T> &t) {
543  return dump(dout, t);
544 }
545 
557 template <class T>
558 Writer &operator<<(Writer &dout, const std::list<T> &t) {
559  return dump(dout, t);
560 }
561 
573 template <class Key, class T, class L>
574 Writer &operator<<(Writer &dout, const std::map<Key, T, L> &t) {
575  return dump(dout, t);
576 }
577 
589 template <class Key, class T, class L>
590 Writer &operator<<(Writer &dout, const std::multimap<Key, T, L> &t) {
591  return dump(dout, t);
592 }
593 
605 template <class Key, class L>
606 Writer &operator<<(Writer &dout, const std::set<Key, L> &t) {
607  return dump(dout, t);
608 }
609 
621 template <class Key, class L>
622 Writer &operator<<(Writer &dout, const std::multiset<Key, L> &t) {
623  return dump(dout, t);
624 }
625 
626 
638 Writer &operator<<(Writer &dout, const sierra::String &s);
639 
651 Writer &operator<<(Writer &dout, const sierra::Identifier &s);
652 
653 #if defined( STK_HAS_MPI )
654 
665 Writer &operator<<(Writer &dout, const sierra::MPI::Loc<int> &loc);
666 
678 Writer &operator<<(Writer &dout, const sierra::MPI::Loc<double> &loc);
679 
691 Writer &operator<<(Writer &dout, const sierra::MPI::Loc<float> &loc);
692 
704 Writer &operator<<(Writer &dout, const sierra::MPI::TempLoc &loc);
705 
706 #endif // if defined( STK_HAS_MPI )
707 
718 template <class T>
720  return c_ptr_func_<T, const sierra::String &>(t, &T::name);
721 }
722 
723 template< class ElementType,
724  class Tag0,
725  class Tag1,
726  class Tag2,
727  class Tag3,
728  class Tag4,
729  class Tag5,
730  class Tag6,
731  class Tag7 >
732 Writer &
733 operator<<(Writer &dout, const sierra::Array<ElementType, Tag0, Tag1, Tag2, Tag3, Tag4, Tag5, Tag6, Tag7 > &array)
734 {
736 
737  if (dout.shouldPrint()) {
738  std::string type = sierra::demangle(typeid(X).name());
739  dout << type.substr(0, type.find(", sierra::TypeListEnd")) << ">" << push << dendl;
740  dout.getStream() << array; // ArrayVerbosePrint<X::NumDim>::dump(dout, array.dimension(), array.ptr(), array.stride());
741  dout << pop << dendl;
742  }
743  return dout;
744 }
745 
746 
747 template< class ElementType,
748  class Tag0,
749  class Tag1,
750  class Tag2,
751  class Tag3,
752  class Tag4,
753  class Tag5,
754  class Tag6,
755  class Tag7 >
756 Writer &
757 operator<<(Writer &dout, const sierra::ArrayContainer<ElementType, Tag0, Tag1, Tag2, Tag3, Tag4, Tag5, Tag6, Tag7 > &array)
758 {
760 
761  if (dout.shouldPrint()) {
762  std::string type = sierra::demangle(typeid(X).name());
763  dout << type.substr(0, type.find(", sierra::TypeListEnd")) << ">" << push << dendl;
764  dout.getStream() << array; // ArrayVerbosePrint<X::NumDim>::dump(dout, array.dimension(), array.ptr(), array.stride());
765  dout << pop << dendl;
766  }
767  return dout;
768 }
769 
770 
771 template< class ElementType, int Dimension>
772 Writer &
773 operator<<(Writer &dout, const sierra::FArray<ElementType, Dimension> &array)
774 {
776 
777  if (dout.shouldPrint()) {
778  dout << sierra::demangle(typeid(X).name()) << push << dendl;
779  dout.getStream() << array; // ArrayVerbosePrint<X::NumDim>::dump(dout, array.dimension(), array.ptr(), array.stride());
780  dout << pop << dendl;
781  }
782  return dout;
783 }
784 
785 template< class ElementType, int Dimension>
786 Writer &
787 operator<<(Writer &dout, const sierra::FArrayContainer<ElementType, Dimension> &array)
788 {
790 
791  if (dout.shouldPrint()) {
792  dout << sierra::demangle(typeid(X).name()) << push << dendl;
793  dout.getStream() << array; // ArrayVerbosePrint<X::NumDim>::dump(dout, array.dimension(), array.ptr(), array.stride());
794  dout << pop << dendl;
795  }
796  return dout;
797 }
798 
810 template <class T>
811 Writer &
813  Writer & dout,
814  const sierra::Mapv_no_delete<T> & t)
815 {
816  if (dout.shouldPrint()) {
817  dout << typeid(t) << ", size " << t.size() << push << dendl;
818 
819  for (typename sierra::Mapv_no_delete<T>::const_iterator it = t.begin(); it != t.end(); ++it) {
820  dout << "[" << (*it).mapv_key() << "] " << (*it) << dendl;
821  }
822 
823  dout << pop;
824  }
825 
826  return dout;
827 }
828 
840 template <class Key, class T, class U>
841 Writer &
843  Writer & dout,
844  const sierra::vecmap<Key, T, U> & t)
845 {
846  if (dout.shouldPrint()) {
847  dout << typeid(t) << ", size " << t.size() << push << dendl;
848 
849  for (typename sierra::vecmap<Key, T, U>::const_iterator it = t.begin(); it != t.end(); ++it)
850  dout << "[" << (*it).first << "] " << (*it).second << dendl;
851 
852  dout << pop;
853  }
854 
855  return dout;
856 }
857 
869 template <class Key, class T, class U>
870 Writer &
872  Writer & dout,
873  const sierra::vecmap<Key, T *, U> & t)
874 {
875  if (dout.shouldPrint()) {
876  dout << typeid(t) << ", size " << t.size() << push << dendl;
877 
878  for (typename sierra::vecmap<Key, T *, U>::const_iterator it = t.begin(); it != t.end(); ++it)
879  dout << "[" << (*it).first << "] " << *(*it).second << dendl;
880 
881  dout << pop;
882  }
883 
884  return dout;
885 }
886 
898 template <class Key, class T, class U>
899 Writer &
901  Writer & dout,
903 {
904  if (dout.shouldPrint()) {
905  dout << typeid(t) << ", size " << t.size() << push << dendl;
906 
907  for (typename sierra::vecmap<Key *, T *, U>::const_iterator it = t.begin(); it != t.end(); ++it)
908  dout << "[" << (*it).first << "] " << *(*it).second << dendl;
909 
910  dout << pop;
911  }
912 
913  return dout;
914 }
915 
927 template <class T, class U>
928 Writer &
930  Writer & dout,
931  const sierra::vecset<T, U> & t)
932 {
933  if (dout.shouldPrint()) {
934  dout << typeid(t) << ", size " << t.size() << push << dendl;
935 
936  int i = 0;
937  for (typename sierra::vecset<T, U>::const_iterator it = t.begin(); it != t.end(); ++it, ++i)
938  dout << "[" << i << "] " << (*it) << dendl;
939 
940  dout << pop;
941  }
942 
943  return dout;
944 }
945 
957 template <class T, class U>
958 Writer &
960  Writer & dout,
961  const sierra::vecset<T *, U> & t)
962 {
963  if (dout.shouldPrint()) {
964  dout << typeid(t) << ", size " << t.size() << push << dendl;
965 
966  int i = 0;
967  for (typename sierra:: vecset<T *, U>::const_iterator it = t.begin(); it != t.end(); ++it, ++i)
968  dout << "[" << i << "] " << *(*it) << dendl;
969 
970  dout << pop;
971  }
972 
973  return dout;
974 }
975 
986 template <class T, class U>
987 Writer &
989  Writer & dout,
990  const sierra::MapvNode<T, U> & t)
991 {
992  if (dout.shouldPrint()) {
993  dout << typeid(t) << ", " << t.mapv_key();
994  }
995 
996  return dout;
997 }
998 
1009 template <class T, class U>
1010 Writer &
1012  Writer & dout,
1013  const sierra::Mapv<T, U> & t)
1014 {
1015  if (dout.shouldPrint()) {
1016  dout << typeid(t) << ", size " << t.size() << push << dendl;
1017 
1018  for (typename sierra::Mapv<T, U>::const_iterator it = t.begin(); it != t.end(); ++it) {
1019  dout << "[" << (*it).mapv_key() << "] " << (*it) << dendl;
1020  }
1021 
1022  dout << pop;
1023  }
1024 
1025  return dout;
1026 }
1027 
1039 template <class T, class U>
1040 Writer &operator<<(Writer &dout, const sierra::vecset<T, U> &t) {
1041  return dump(dout, t);
1042 }
1043 
1055 template <class Key, class T, class U>
1056 Writer &operator<<(Writer &dout, const sierra::vecmap<Key, T, U> &t) {
1057  return dump(dout, t);
1058 }
1059 
1071 template <class T, class U>
1072 Writer &operator<<(Writer &dout, const sierra::vecset<T *, U> &t) {
1073  return dump(dout, t);
1074 }
1075 
1087 template <class Key, class T, class U>
1088 Writer &operator<<(Writer &dout, const sierra::vecmap<Key *, T *, U> &t) {
1089  return dump(dout, t);
1090 }
1091 
1103 template <class T>
1104 Writer &operator<<(Writer &dout, const sierra::Mapv_no_delete<T> &t) {
1105  return dump(dout, t);
1106 }
1107 
1119 template <class T, class U>
1120 Writer &operator<<(Writer &dout, const sierra::Mapv<T, U> &t) {
1121  return dump(dout, t);
1122 }
1123 
1135 template <class T, class U>
1136 Writer &operator<<(Writer &dout, const sierra::MapvNode<T, U> &t) {
1137  return dump(dout, t);
1138 }
1139 
1151 template <class Key, class T, class U>
1152 Writer &operator<<(Writer &dout, const sierra::vecmap<Key, T *, U> &t) {
1153  return dump(dout, t);
1154 }
1155 
1156 
1160 
1161 } // namespace diag
1162 } // namespace stk_classic
1163 
1164 #endif // STK_UTIL_DIAG_WRITEREXT_HPP
std::ostream & dout()
Diagnostic output stream.
Definition: OutputLog.cpp:674
const key_type & mapv_key() const
Definition: Mapv.hpp:178
const char * demangle(const char *symbol)
Function demangle returns the demangled C++ symbol from the mangled C++ symbol. The mangled named is ...
Definition: Platform.cpp:210
Extend Array with deep copy assignment and resize operations.
Definition: Array.hpp:101
Class c_ptr_func_ simply stores a pointer to an object of type T. This allows pointers which want to ...
Definition: Writer.hpp:686
std::ostream & operator<<(std::ostream &s, const Bucket &k)
Print the part names for which this bucket is a subset.
Definition: Bucket.cpp:239
Multidimensional array of contiguous memory. The memory is not owned by the array, but container access semantics are enforced, i.e. const Array<> elements cannot be assigned to.
Definition: FArray.hpp:78
Vector-based std::map functionality.
Definition: VecMap.hpp:60
Extend FArray with deep copy assignment and resize operations.
Definition: FArray.hpp:86
Writer & dendl(Writer &dout)
Writer function dendl calls the Writer::dendl manipulator.
Definition: Writer.hpp:520
c_ptr_func_< T, const sierra::String & > c_ptr_name(const T *t)
Template function c_ptr_name implements c_ptr_func with the function &#39;name&#39;.
Definition: WriterExt.hpp:719
Class c_ptr_ simply stores a pointer to an object of type T. This allows pointers which want to be de...
Definition: Writer.hpp:651
Sierra Toolkit.
Class Writer implements a runtime selectable diagnostic output writer to aid in the development and d...
Definition: Writer.hpp:49
Writer & dump(Writer &dout, const sierra::Mapv< T, U > &t)
Template function dump writes a Mapv object to the diagnostic writer.
Definition: WriterExt.hpp:1011
Vector-based std::set functionality.
Definition: VecSet.hpp:59
Multidimensional array view of contiguous memory.
Definition: Array.hpp:82