Sierra Toolkit Version of the Day
WriterExt.hpp
00001 /*------------------------------------------------------------------------*/
00002 /*                 Copyright 2010 Sandia Corporation.                     */
00003 /*  Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive   */
00004 /*  license for use of this work by or on behalf of the U.S. Government.  */
00005 /*  Export of this program may require a license from the                 */
00006 /*  United States Government.                                             */
00007 /*------------------------------------------------------------------------*/
00008 
00009 #ifndef STK_UTIL_DIAG_WRITEREXT_HPP
00010 #define STK_UTIL_DIAG_WRITEREXT_HPP
00011 
00012 #include <bitset>
00013 #include <iostream>
00014 #include <list>
00015 #include <map>
00016 #include <set>
00017 #include <memory>
00018 #include <stack>
00019 #include <string>
00020 #include <typeinfo>
00021 #include <vector>
00022 #include <stk_util/stk_config.h>
00023 #include <stk_util/util/VecMap.hpp>
00024 #include <stk_util/util/VecSet.hpp>
00025 
00026 #include <stk_util/diag/Writer.hpp>
00027 
00028 
00029 #include <stk_util/diag/String.hpp>
00030 #include <stk_util/diag/StringUtil.hpp>
00031 
00032 #include <stk_util/util/FeatureTest.hpp>
00033 #include <stk_util/util/Array.hpp>
00034 #include <stk_util/util/FArrayPrint.hpp>
00035 #include <stk_util/parallel/MPI.hpp>
00036 #include <stk_util/diag/Mapv.hpp>
00037 #include <stk_util/diag/Option.hpp>
00038 
00039 
00040 namespace stk {
00041 namespace diag {
00042 
00047 
00060 Writer &operator<<(Writer &dout, const std::type_info &t);
00061 
00073 template <class T>
00074 Writer &operator<<(Writer &dout, const std::auto_ptr<T> &t) {
00075   if (t.get())
00076     dout << " " << typeid(t) << ", " << t.get() << ", " << *t;
00077   else
00078     dout << " " << typeid(t) << ", <not created or not owner>";
00079 
00080   return dout;
00081 }
00082 
00094 template <class T, class U>
00095 Writer &operator<<(Writer & dout, const std::pair<T, U> &pair) {
00096 //  dout << typeid(pair) << "(" << pair.first << ":" << pair.second << ")";
00097   dout << "(" << pair.first << ":" << pair.second << ")";
00098 
00099   return dout;
00100 }
00101 
00113 template <class T>
00114 Writer &
00115 dump(
00116   Writer &      dout,
00117   const std::vector<T> &  t)
00118 {
00119   if (dout.shouldPrint()) {
00120     dout << typeid(t) << ", size " << t.size() << push << dendl;
00121 
00122     if (t.size() <= 10) {
00123       for (typename std::vector<T>::const_iterator it = t.begin(); it != t.end(); ++it)
00124         dout << (*it) << " ";
00125       dout << dendl;
00126     }
00127     else {
00128       int i = 0;
00129       for (typename std::vector<T>::const_iterator it = t.begin(); it != t.end(); ++it, ++i)
00130         dout << "[" << i << "] " << (*it) << dendl;
00131     }
00132 
00133     dout << pop;
00134   }
00135 
00136   return dout;
00137 }
00138 
00150 template <class T>
00151 Writer &
00152 dump(
00153   Writer &      dout,
00154   const std::vector<T *> &  t)
00155 {
00156   if (dout.shouldPrint()) {
00157     dout << typeid(t) << ", size " << t.size() << push << dendl;
00158 
00159     int i = 0;
00160     for (typename std::vector<T *>::const_iterator it = t.begin(); it != t.end(); ++it, ++i)
00161       dout << "[" << i << "] " << c_ptr_<T>(*it) << dendl;
00162 
00163     dout << pop;
00164   }
00165 
00166   return dout;
00167 }
00168 
00180 template <class T>
00181 Writer &
00182 dump(
00183   Writer &      dout,
00184   const std::list<T> &    t)
00185 {
00186   if (dout.shouldPrint()) {
00187     dout << typeid(t) << ", size " << t.size() << push << dendl;
00188 
00189     int i = 0;
00190     for (typename std::list<T>::const_iterator it = t.begin(); it != t.end(); ++it, ++i)
00191       dout << "[" << i << "] " << (*it) << dendl;
00192 
00193     dout << pop;
00194   }
00195 
00196   return dout;
00197 }
00198 
00210 template <class T>
00211 Writer &
00212 dump(
00213   Writer &      dout,
00214   const std::list<T *> &  t)
00215 {
00216   if (dout.shouldPrint()) {
00217     dout << typeid(t) << ", size " << t.size() << push << dendl;
00218 
00219     int i = 0;
00220     for (typename std::list<T *>::const_iterator it = t.begin(); it != t.end(); ++it, ++i)
00221       dout << "[" << i << "] " << c_ptr_<T>(*it) << dendl;
00222 
00223     dout << pop;
00224   }
00225 
00226   return dout;
00227 }
00228 
00240 template <class Key, class T, class L>
00241 Writer &
00242 dump(
00243   Writer &      dout,
00244   const std::map<Key, T, L> &  t)
00245 {
00246   if (dout.shouldPrint()) {
00247     dout << typeid(t) << ", size " << t.size() << push << dendl;
00248 
00249     for (typename std::map<Key, T, L>::const_iterator it = t.begin(); it != t.end(); ++it)
00250       dout << "[" << (*it).first << "] " << (*it).second << dendl;
00251 
00252     dout << pop;
00253   }
00254 
00255   return dout;
00256 }
00257 
00269 template <class Key, class T, class L>
00270 Writer &
00271 dump(
00272   Writer &      dout,
00273   const std::map<Key, T *, L> &  t)
00274 {
00275   if (dout.shouldPrint()) {
00276     dout << typeid(t) << ", size " << t.size() << push << dendl;
00277 
00278     for (typename std::map<Key, T *, L>::const_iterator it = t.begin(); it != t.end(); ++it)
00279       dout << "[" << (*it).first << "] " << c_ptr_<T>((*it).second) << std::endl;
00280 
00281     dout << pop;
00282   }
00283 
00284   return dout;
00285 }
00286 
00298 template <class Key, class T, class L>
00299 Writer &
00300 dump(
00301   Writer &      dout,
00302   const std::multimap<Key, T, L> &  t)
00303 {
00304   if (dout.shouldPrint()) {
00305     dout << typeid(t) << ", size " << t.size() << push << dendl;
00306 
00307     for (typename std::multimap<Key, T, L>::const_iterator it = t.begin(); it != t.end(); ++it)
00308       dout << "[" << (*it).first << "] " << (*it).second << dendl;
00309 
00310     dout << pop;
00311   }
00312 
00313   return dout;
00314 }
00315 
00327 template <class Key, class T, class L>
00328 Writer &
00329 dump(
00330   Writer &      dout,
00331   const std::multimap<Key, T *, L> &  t)
00332 {
00333   if (dout.shouldPrint()) {
00334     dout << typeid(t) << ", size " << t.size() << push << dendl;
00335 
00336     for (typename std::multimap<Key, T *, L>::const_iterator it = t.begin(); it != t.end(); ++it)
00337       dout << "[" << (*it).first << "] " << c_ptr_<T>((*it).second) << std::endl;
00338 
00339     dout << pop;
00340   }
00341 
00342   return dout;
00343 }
00344 
00356 template <class Key, class L>
00357 Writer &
00358 dump(
00359   Writer &      dout,
00360   const std::set<Key, L> &  t)
00361 {
00362   if (dout.shouldPrint()) {
00363     dout << typeid(t) << ", size " << t.size() << push << dendl;
00364 
00365     for (typename std::set<Key, L>::const_iterator it = t.begin(); it != t.end(); ++it)
00366       dout << (*it) << dendl;
00367 
00368     dout << pop;
00369   }
00370 
00371   return dout;
00372 }
00373 
00385 template <class Key, class L>
00386 Writer &
00387 dump(
00388   Writer &      dout,
00389   const std::set<Key *, L> &  t)
00390 {
00391   if (dout.shouldPrint()) {
00392     dout << typeid(t) << ", size " << t.size() << push << dendl;
00393 
00394     for (typename std::set<Key *, L>::const_iterator it = t.begin(); it != t.end(); ++it)
00395       dout << c_ptr_<Key>((*it)) << dendl;
00396 
00397     dout << pop;
00398   }
00399 
00400   return dout;
00401 }
00402 
00414 template <class Key, class L>
00415 Writer &
00416 dump(
00417   Writer &      dout,
00418   const std::multiset<Key, L> &  t)
00419 {
00420   if (dout.shouldPrint()) {
00421     dout << typeid(t) << ", size " << t.size() << push << dendl;
00422 
00423     for (typename std::multiset<Key, L>::const_iterator it = t.begin(); it != t.end(); ++it)
00424       dout << (*it) << dendl;
00425 
00426     dout << pop;
00427   }
00428 
00429   return dout;
00430 }
00431 
00443 template <class Key, class L>
00444 Writer &
00445 dump(
00446   Writer &      dout,
00447   const std::multiset<Key *, L> &  t)
00448 {
00449   if (dout.shouldPrint()) {
00450     dout << typeid(t) << ", size " << t.size() << push << dendl;
00451 
00452     for (typename std::multiset<Key *, L>::const_iterator it = t.begin(); it != t.end(); ++it)
00453       dout << c_ptr_<Key>((*it)) << dendl;
00454 
00455     dout << pop;
00456   }
00457 
00458   return dout;
00459 }
00460 
00461 // /**
00462 //  * @brief Template <b>dump</b> prints the object contained within a
00463 //  * hash_map to the diagnostic writer.
00464 //  *
00465 //  * @param dout    a <b>Writer</b> reference to the diagnostic writer to
00466 //  *      write the hash_map to.
00467 //  *
00468 //  * @param t    a <b>hash_map</b> of objects.
00469 //  *
00470 //  * @return    a <b>Writer</b> reference to this object
00471 //  */
00472 // template <class Key, class T>
00473 // Writer &
00474 // dump(
00475 //   Writer &      dout,
00476 //   const hash_map<Key, T> &  t)
00477 // {
00478 //   if (dout.shouldPrint()) {
00479 //     dout << typeid(t) << ", size " << t.size() << push << dendl;
00480 
00481 //     for (typename hash_map<Key, T>::const_iterator it = t.begin(); it != t.end(); ++it)
00482 //       dout <<  "[" << (*it).first << "] " << (*it).second << dendl;
00483 
00484 //     dout << pop;
00485 //   }
00486 
00487 //   return dout;
00488 // }
00489 
00490 // /**
00491 //  * @brief Template <b>dump</b> prints the object pointed to that are
00492 //  * contained within a hash_map to the diagnostic writer.
00493 //  *
00494 //  * @param dout    a <b>Writer</b> reference to the diagnostic writer to
00495 //  *      write the hash_map to.
00496 //  *
00497 //  * @param t    a <b>hash_map</b> of objects.
00498 //  *
00499 //  * @return    a <b>Writer</b> reference to this object
00500 //  */
00501 // template <class Key, class T>
00502 // Writer &
00503 // dump(
00504 //   Writer &      dout,
00505 
00506 //   const hash_map<Key, T *> &  t)
00507 // {
00508 //   if (dout.shouldPrint()) {
00509 //     dout << typeid(t) << ", size " << t.size() << push << dendl;
00510 
00511 //     for (typename hash_map<Key, T *>::const_iterator it = t.begin(); it != t.end(); ++it)
00512 //       dout << "[" << (*it).first << "] " << (*it)->second << dendl;
00513 
00514 //     dout << pop;
00515 //   }
00516 
00517 //   return dout;
00518 // }
00519 
00520 
00521 template <size_t n>
00522 Writer &operator<<(Writer &dout, const std::bitset<n> &t) {
00523   if (dout.shouldPrint())
00524     dout.getStream() << t;
00525 
00526   return dout;
00527 }
00528 
00529 
00541 template <class T>
00542 Writer &operator<<(Writer &dout, const std::vector<T> &t) {
00543   return dump(dout, t);
00544 }
00545 
00557 template <class T>
00558 Writer &operator<<(Writer &dout, const std::list<T> &t) {
00559   return dump(dout, t);
00560 }
00561 
00573 template <class Key, class T, class L>
00574 Writer &operator<<(Writer &dout, const std::map<Key, T, L> &t) {
00575   return dump(dout, t);
00576 }
00577 
00589 template <class Key, class T, class L>
00590 Writer &operator<<(Writer &dout, const std::multimap<Key, T, L> &t) {
00591   return dump(dout, t);
00592 }
00593 
00605 template <class Key, class L>
00606 Writer &operator<<(Writer &dout, const std::set<Key, L> &t) {
00607   return dump(dout, t);
00608 }
00609 
00621 template <class Key, class L>
00622 Writer &operator<<(Writer &dout, const std::multiset<Key, L> &t) {
00623   return dump(dout, t);
00624 }
00625 
00626 
00638 Writer &operator<<(Writer &dout, const sierra::String &s);
00639 
00651 Writer &operator<<(Writer &dout, const sierra::Identifier &s);
00652 
00653 #if defined( STK_HAS_MPI )
00654 
00665 Writer &operator<<(Writer &dout, const sierra::MPI::Loc<int> &loc);
00666 
00678 Writer &operator<<(Writer &dout, const sierra::MPI::Loc<double> &loc);
00679 
00691 Writer &operator<<(Writer &dout, const sierra::MPI::Loc<float> &loc);
00692 
00704 Writer &operator<<(Writer &dout, const sierra::MPI::TempLoc &loc);
00705 
00706 #endif // if defined( STK_HAS_MPI )
00707 
00718 template <class T>
00719 c_ptr_func_<T, const sierra::String &> c_ptr_name(const T *t) {
00720   return c_ptr_func_<T, const sierra::String &>(t, &T::name);
00721 }
00722 
00723 template< class ElementType,
00724     class Tag0,
00725     class Tag1,
00726     class Tag2,
00727     class Tag3,
00728     class Tag4,
00729     class Tag5,
00730     class Tag6,
00731     class Tag7 >
00732 Writer &
00733 operator<<(Writer &dout, const sierra::Array<ElementType, Tag0, Tag1, Tag2, Tag3, Tag4, Tag5, Tag6, Tag7 > &array)
00734 {
00735   typedef sierra::Array<ElementType, Tag0, Tag1, Tag2, Tag3, Tag4, Tag5, Tag6, Tag7 > X;
00736 
00737   if (dout.shouldPrint()) {
00738     std::string type = sierra::demangle(typeid(X).name());
00739     dout << type.substr(0, type.find(", sierra::TypeListEnd")) << ">" << push << dendl;
00740     dout.getStream() << array; // ArrayVerbosePrint<X::NumDim>::dump(dout, array.dimension(), array.ptr(), array.stride());
00741     dout << pop << dendl;
00742   }
00743   return dout;
00744 }
00745 
00746 
00747 template< class ElementType,
00748     class Tag0,
00749     class Tag1,
00750     class Tag2,
00751     class Tag3,
00752     class Tag4,
00753     class Tag5,
00754     class Tag6,
00755     class Tag7 >
00756 Writer &
00757 operator<<(Writer &dout, const sierra::ArrayContainer<ElementType, Tag0, Tag1, Tag2, Tag3, Tag4, Tag5, Tag6, Tag7 > &array)
00758 {
00759   typedef sierra::ArrayContainer<ElementType, Tag0, Tag1, Tag2, Tag3, Tag4, Tag5, Tag6, Tag7 > X;
00760 
00761   if (dout.shouldPrint()) {
00762     std::string type = sierra::demangle(typeid(X).name());
00763     dout << type.substr(0, type.find(", sierra::TypeListEnd")) << ">" << push << dendl;
00764     dout.getStream() << array; // ArrayVerbosePrint<X::NumDim>::dump(dout, array.dimension(), array.ptr(), array.stride());
00765     dout << pop << dendl;
00766   }
00767   return dout;
00768 }
00769 
00770 
00771 template< class ElementType, int Dimension>
00772 Writer &
00773 operator<<(Writer &dout, const sierra::FArray<ElementType, Dimension> &array)
00774 {
00775   typedef sierra::FArray<ElementType, Dimension> X;
00776 
00777   if (dout.shouldPrint()) {
00778     dout << sierra::demangle(typeid(X).name()) << push << dendl;
00779     dout.getStream() << array; // ArrayVerbosePrint<X::NumDim>::dump(dout, array.dimension(), array.ptr(), array.stride());
00780     dout << pop << dendl;
00781   }
00782   return dout;
00783 }
00784 
00785 template< class ElementType, int Dimension>
00786 Writer &
00787 operator<<(Writer &dout, const sierra::FArrayContainer<ElementType, Dimension> &array)
00788 {
00789   typedef sierra::FArrayContainer<ElementType, Dimension> X;
00790 
00791   if (dout.shouldPrint()) {
00792     dout << sierra::demangle(typeid(X).name()) << push << dendl;
00793     dout.getStream() << array; // ArrayVerbosePrint<X::NumDim>::dump(dout, array.dimension(), array.ptr(), array.stride());
00794     dout << pop << dendl;
00795   }
00796   return dout;
00797 }
00798 
00810 template <class T>
00811 Writer &
00812 dump(
00813   Writer &      dout,
00814   const sierra::Mapv_no_delete<T> & t)
00815 {
00816   if (dout.shouldPrint()) {
00817     dout << typeid(t) << ", size " << t.size() << push << dendl;
00818 
00819     for (typename sierra::Mapv_no_delete<T>::const_iterator it = t.begin(); it != t.end(); ++it) {
00820       dout << "[" << (*it).mapv_key() << "] " << (*it) << dendl;
00821     }
00822 
00823     dout << pop;
00824   }
00825 
00826   return dout;
00827 }
00828 
00840 template <class Key, class T, class U>
00841 Writer &
00842 dump(
00843   Writer &      dout,
00844   const sierra::vecmap<Key, T, U> & t)
00845 {
00846   if (dout.shouldPrint()) {
00847     dout << typeid(t) << ", size " << t.size() << push << dendl;
00848 
00849     for (typename sierra::vecmap<Key, T, U>::const_iterator it = t.begin(); it != t.end(); ++it)
00850       dout << "[" << (*it).first << "] " << (*it).second << dendl;
00851 
00852     dout << pop;
00853   }
00854 
00855   return dout;
00856 }
00857 
00869 template <class Key, class T, class U>
00870 Writer &
00871 dump(
00872   Writer &      dout,
00873   const sierra::vecmap<Key, T *, U> & t)
00874 {
00875   if (dout.shouldPrint()) {
00876     dout << typeid(t) << ", size " << t.size() << push << dendl;
00877 
00878     for (typename sierra::vecmap<Key, T *, U>::const_iterator it = t.begin(); it != t.end(); ++it)
00879       dout << "[" << (*it).first << "] " << *(*it).second << dendl;
00880 
00881     dout << pop;
00882   }
00883 
00884   return dout;
00885 }
00886 
00898 template <class Key, class T, class U>
00899 Writer &
00900 dump(
00901   Writer &        dout,
00902   const sierra::vecmap<Key *, T *, U> & t)
00903 {
00904   if (dout.shouldPrint()) {
00905     dout << typeid(t) << ", size " << t.size() << push << dendl;
00906 
00907     for (typename sierra::vecmap<Key *, T *, U>::const_iterator it = t.begin(); it != t.end(); ++it)
00908       dout << "[" << (*it).first << "] " << *(*it).second << dendl;
00909 
00910     dout << pop;
00911   }
00912 
00913   return dout;
00914 }
00915 
00927 template <class T, class U>
00928 Writer &
00929 dump(
00930   Writer &    dout,
00931   const sierra::vecset<T, U> &  t)
00932 {
00933   if (dout.shouldPrint()) {
00934     dout << typeid(t) << ", size " << t.size() << push << dendl;
00935 
00936     int i = 0;
00937     for (typename sierra::vecset<T, U>::const_iterator it = t.begin(); it != t.end(); ++it, ++i)
00938       dout << "[" << i << "] " << (*it) << dendl;
00939 
00940     dout << pop;
00941   }
00942 
00943   return dout;
00944 }
00945 
00957 template <class T, class U>
00958 Writer &
00959 dump(
00960   Writer &      dout,
00961   const sierra::vecset<T *, U> &  t)
00962 {
00963   if (dout.shouldPrint()) {
00964     dout << typeid(t) << ", size " << t.size() << push << dendl;
00965 
00966     int i = 0;
00967     for (typename sierra:: vecset<T *, U>::const_iterator it = t.begin(); it != t.end(); ++it, ++i)
00968       dout << "[" << i << "] " << *(*it) << dendl;
00969 
00970     dout << pop;
00971   }
00972 
00973   return dout;
00974 }
00975 
00986 template <class T, class U>
00987 Writer &
00988 dump(
00989   Writer &      dout,
00990   const sierra::MapvNode<T, U> &  t)
00991 {
00992   if (dout.shouldPrint()) {
00993     dout << typeid(t) << ", " << t.mapv_key();
00994   }
00995 
00996   return dout;
00997 }
00998 
01009 template <class T, class U>
01010 Writer &
01011 dump(
01012   Writer &    dout,
01013   const sierra::Mapv<T, U> &  t)
01014 {
01015   if (dout.shouldPrint()) {
01016     dout << typeid(t) << ", size " << t.size() << push << dendl;
01017 
01018     for (typename sierra::Mapv<T, U>::const_iterator it = t.begin(); it != t.end(); ++it) {
01019       dout << "[" << (*it).mapv_key() << "] " << (*it) << dendl;
01020     }
01021 
01022     dout << pop;
01023   }
01024 
01025   return dout;
01026 }
01027 
01039 template <class T, class U>
01040 Writer &operator<<(Writer &dout, const sierra::vecset<T, U> &t) {
01041   return dump(dout, t);
01042 }
01043 
01055 template <class Key, class T, class U>
01056 Writer &operator<<(Writer &dout, const sierra::vecmap<Key, T, U> &t) {
01057   return dump(dout, t);
01058 }
01059 
01071 template <class T, class U>
01072 Writer &operator<<(Writer &dout, const sierra::vecset<T *, U> &t) {
01073   return dump(dout, t);
01074 }
01075 
01087 template <class Key, class T, class U>
01088 Writer &operator<<(Writer &dout, const sierra::vecmap<Key *, T *, U> &t) {
01089   return dump(dout, t);
01090 }
01091 
01103 template <class T>
01104 Writer &operator<<(Writer &dout, const sierra::Mapv_no_delete<T> &t) {
01105   return dump(dout, t);
01106 }
01107 
01119 template <class T, class U>
01120 Writer &operator<<(Writer &dout, const sierra::Mapv<T, U> &t) {
01121   return dump(dout, t);
01122 }
01123 
01135 template <class T, class U>
01136 Writer &operator<<(Writer &dout, const sierra::MapvNode<T, U> &t) {
01137   return dump(dout, t);
01138 }
01139 
01151 template <class Key, class T, class U>
01152 Writer &operator<<(Writer &dout, const sierra::vecmap<Key, T *, U> &t) {
01153   return dump(dout, t);
01154 }
01155 
01156 
01160 
01161 } // namespace diag
01162 } // namespace stk
01163 
01164 #endif // STK_UTIL_DIAG_WRITEREXT_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines