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 
00023 #include <stk_util/diag/Writer.hpp>
00024 
00025 namespace stk {
00026 namespace diag {
00027 
00032 
00045 Writer &operator<<(Writer &dout, const std::type_info &t);
00046 
00058 template <class T>
00059 Writer &operator<<(Writer &dout, const std::auto_ptr<T> &t) {
00060   if (t.get())
00061     dout << " " << typeid(t) << ", " << t.get() << ", " << *t;
00062   else
00063     dout << " " << typeid(t) << ", <not created or not owner>";
00064 
00065   return dout;
00066 }
00067 
00079 template <class T, class U>
00080 Writer &operator<<(Writer & dout, const std::pair<T, U> &pair) {
00081 //  dout << typeid(pair) << "(" << pair.first << ":" << pair.second << ")";
00082   dout << "(" << pair.first << ":" << pair.second << ")";
00083 
00084   return dout;
00085 }
00086 
00098 template <class T>
00099 Writer &
00100 dump(
00101   Writer &      dout,
00102   const std::vector<T> &  t)
00103 {
00104   if (dout.shouldPrint()) {
00105     dout << typeid(t) << ", size " << t.size() << push << dendl;
00106 
00107     if (t.size() <= 10) {
00108       for (typename std::vector<T>::const_iterator it = t.begin(); it != t.end(); ++it)
00109         dout << (*it) << " ";
00110       dout << dendl;
00111     }
00112     else {
00113       int i = 0;
00114       for (typename std::vector<T>::const_iterator it = t.begin(); it != t.end(); ++it, ++i)
00115         dout << "[" << i << "] " << (*it) << dendl;
00116     }
00117 
00118     dout << pop;
00119   }
00120 
00121   return dout;
00122 }
00123 
00135 template <class T>
00136 Writer &
00137 dump(
00138   Writer &      dout,
00139   const std::vector<T *> &  t)
00140 {
00141   if (dout.shouldPrint()) {
00142     dout << typeid(t) << ", size " << t.size() << push << dendl;
00143 
00144     int i = 0;
00145     for (typename std::vector<T *>::const_iterator it = t.begin(); it != t.end(); ++it, ++i)
00146       dout << "[" << i << "] " << c_ptr_<T>(*it) << dendl;
00147 
00148     dout << pop;
00149   }
00150 
00151   return dout;
00152 }
00153 
00165 template <class T>
00166 Writer &
00167 dump(
00168   Writer &      dout,
00169   const std::list<T> &    t)
00170 {
00171   if (dout.shouldPrint()) {
00172     dout << typeid(t) << ", size " << t.size() << push << dendl;
00173 
00174     int i = 0;
00175     for (typename std::list<T>::const_iterator it = t.begin(); it != t.end(); ++it, ++i)
00176       dout << "[" << i << "] " << (*it) << dendl;
00177 
00178     dout << pop;
00179   }
00180 
00181   return dout;
00182 }
00183 
00195 template <class T>
00196 Writer &
00197 dump(
00198   Writer &      dout,
00199   const std::list<T *> &  t)
00200 {
00201   if (dout.shouldPrint()) {
00202     dout << typeid(t) << ", size " << t.size() << push << dendl;
00203 
00204     int i = 0;
00205     for (typename std::list<T *>::const_iterator it = t.begin(); it != t.end(); ++it, ++i)
00206       dout << "[" << i << "] " << c_ptr_<T>(*it) << dendl;
00207 
00208     dout << pop;
00209   }
00210 
00211   return dout;
00212 }
00213 
00225 template <class Key, class T, class L>
00226 Writer &
00227 dump(
00228   Writer &      dout,
00229   const std::map<Key, T, L> &  t)
00230 {
00231   if (dout.shouldPrint()) {
00232     dout << typeid(t) << ", size " << t.size() << push << dendl;
00233 
00234     for (typename std::map<Key, T, L>::const_iterator it = t.begin(); it != t.end(); ++it)
00235       dout << "[" << (*it).first << "] " << (*it).second << dendl;
00236 
00237     dout << pop;
00238   }
00239 
00240   return dout;
00241 }
00242 
00254 template <class Key, class T, class L>
00255 Writer &
00256 dump(
00257   Writer &      dout,
00258   const std::map<Key, T *, L> &  t)
00259 {
00260   if (dout.shouldPrint()) {
00261     dout << typeid(t) << ", size " << t.size() << push << dendl;
00262 
00263     for (typename std::map<Key, T *, L>::const_iterator it = t.begin(); it != t.end(); ++it)
00264       dout << "[" << (*it).first << "] " << c_ptr_<T>((*it)->second) << std::endl;
00265 
00266     dout << pop;
00267   }
00268 
00269   return dout;
00270 }
00271 
00283 template <class Key, class T, class L>
00284 Writer &
00285 dump(
00286   Writer &      dout,
00287   const std::multimap<Key, T, L> &  t)
00288 {
00289   if (dout.shouldPrint()) {
00290     dout << typeid(t) << ", size " << t.size() << push << dendl;
00291 
00292     for (typename std::multimap<Key, T, L>::const_iterator it = t.begin(); it != t.end(); ++it)
00293       dout << "[" << (*it).first << "] " << (*it).second << dendl;
00294 
00295     dout << pop;
00296   }
00297 
00298   return dout;
00299 }
00300 
00312 template <class Key, class T, class L>
00313 Writer &
00314 dump(
00315   Writer &      dout,
00316   const std::multimap<Key, T *, L> &  t)
00317 {
00318   if (dout.shouldPrint()) {
00319     dout << typeid(t) << ", size " << t.size() << push << dendl;
00320 
00321     for (typename std::multimap<Key, T *, L>::const_iterator it = t.begin(); it != t.end(); ++it)
00322       dout << "[" << (*it).first << "] " << c_ptr_<T>((*it)->second) << std::endl;
00323 
00324     dout << pop;
00325   }
00326 
00327   return dout;
00328 }
00329 
00341 template <class Key, class L>
00342 Writer &
00343 dump(
00344   Writer &      dout,
00345   const std::set<Key, L> &  t)
00346 {
00347   if (dout.shouldPrint()) {
00348     dout << typeid(t) << ", size " << t.size() << push << dendl;
00349 
00350     for (typename std::set<Key, L>::const_iterator it = t.begin(); it != t.end(); ++it)
00351       dout << (*it) << dendl;
00352 
00353     dout << pop;
00354   }
00355 
00356   return dout;
00357 }
00358 
00370 template <class Key, class L>
00371 Writer &
00372 dump(
00373   Writer &      dout,
00374   const std::set<Key *, L> &  t)
00375 {
00376   if (dout.shouldPrint()) {
00377     dout << typeid(t) << ", size " << t.size() << push << dendl;
00378 
00379     for (typename std::set<Key *, L>::const_iterator it = t.begin(); it != t.end(); ++it)
00380       dout << c_ptr_<Key>((*it)) << dendl;
00381 
00382     dout << pop;
00383   }
00384 
00385   return dout;
00386 }
00387 
00399 template <class Key, class L>
00400 Writer &
00401 dump(
00402   Writer &      dout,
00403   const std::multiset<Key, L> &  t)
00404 {
00405   if (dout.shouldPrint()) {
00406     dout << typeid(t) << ", size " << t.size() << push << dendl;
00407 
00408     for (typename std::multiset<Key, L>::const_iterator it = t.begin(); it != t.end(); ++it)
00409       dout << (*it) << dendl;
00410 
00411     dout << pop;
00412   }
00413 
00414   return dout;
00415 }
00416 
00428 template <class Key, class L>
00429 Writer &
00430 dump(
00431   Writer &      dout,
00432   const std::multiset<Key *, L> &  t)
00433 {
00434   if (dout.shouldPrint()) {
00435     dout << typeid(t) << ", size " << t.size() << push << dendl;
00436 
00437     for (typename std::multiset<Key *, L>::const_iterator it = t.begin(); it != t.end(); ++it)
00438       dout << c_ptr_<Key>((*it)) << dendl;
00439 
00440     dout << pop;
00441   }
00442 
00443   return dout;
00444 }
00445 
00446 // /**
00447 //  * @brief Template <b>dump</b> prints the object contained within a
00448 //  * hash_map to the diagnostic writer.
00449 //  *
00450 //  * @param dout    a <b>Writer</b> reference to the diagnostic writer to
00451 //  *      write the hash_map to.
00452 //  *
00453 //  * @param t    a <b>hash_map</b> of objects.
00454 //  *
00455 //  * @return    a <b>Writer</b> reference to this object
00456 //  */
00457 // template <class Key, class T>
00458 // Writer &
00459 // dump(
00460 //   Writer &      dout,
00461 //   const hash_map<Key, T> &  t)
00462 // {
00463 //   if (dout.shouldPrint()) {
00464 //     dout << typeid(t) << ", size " << t.size() << push << dendl;
00465 
00466 //     for (typename hash_map<Key, T>::const_iterator it = t.begin(); it != t.end(); ++it)
00467 //       dout <<  "[" << (*it).first << "] " << (*it).second << dendl;
00468 
00469 //     dout << pop;
00470 //   }
00471 
00472 //   return dout;
00473 // }
00474 
00475 // /**
00476 //  * @brief Template <b>dump</b> prints the object pointed to that are
00477 //  * contained within a hash_map to the diagnostic writer.
00478 //  *
00479 //  * @param dout    a <b>Writer</b> reference to the diagnostic writer to
00480 //  *      write the hash_map to.
00481 //  *
00482 //  * @param t    a <b>hash_map</b> of objects.
00483 //  *
00484 //  * @return    a <b>Writer</b> reference to this object
00485 //  */
00486 // template <class Key, class T>
00487 // Writer &
00488 // dump(
00489 //   Writer &      dout,
00490 
00491 //   const hash_map<Key, T *> &  t)
00492 // {
00493 //   if (dout.shouldPrint()) {
00494 //     dout << typeid(t) << ", size " << t.size() << push << dendl;
00495 
00496 //     for (typename hash_map<Key, T *>::const_iterator it = t.begin(); it != t.end(); ++it)
00497 //       dout << "[" << (*it).first << "] " << (*it)->second << dendl;
00498 
00499 //     dout << pop;
00500 //   }
00501 
00502 //   return dout;
00503 // }
00504 
00505 
00506 template <size_t n>
00507 Writer &operator<<(Writer &dout, const std::bitset<n> &t) {
00508   if (dout.shouldPrint())
00509     dout.getStream() << t;
00510 
00511   return dout;
00512 }
00513 
00514 
00526 template <class T>
00527 Writer &operator<<(Writer &dout, const std::vector<T> &t) {
00528   return dump(dout, t);
00529 }
00530 
00542 template <class T>
00543 Writer &operator<<(Writer &dout, const std::list<T> &t) {
00544   return dump(dout, t);
00545 }
00546 
00558 template <class Key, class T, class L>
00559 Writer &operator<<(Writer &dout, const std::map<Key, T, L> &t) {
00560   return dump<Key, T, L>(dout, t);
00561 }
00562 
00574 template <class Key, class T, class L>
00575 Writer &operator<<(Writer &dout, const std::multimap<Key, T, L> &t) {
00576   return dump<Key, T, L>(dout, t);
00577 }
00578 
00590 template <class Key, class L>
00591 Writer &operator<<(Writer &dout, const std::set<Key, L> &t) {
00592   return dump<Key, L>(dout, t);
00593 }
00594 
00606 template <class Key, class L>
00607 Writer &operator<<(Writer &dout, const std::multiset<Key, L> &t) {
00608   return dump<Key, L>(dout, t);
00609 }
00610 
00614 
00615 } // namespace diag
00616 } // namespace stk
00617 
00618 #endif // STK_UTIL_DIAG_WRITEREXT_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends