ViennaGrid - The Vienna Grid Library
2.1.0
|
00001 #ifndef VIENNAGRID_STORAGE_IO_HPP 00002 #define VIENNAGRID_STORAGE_IO_HPP 00003 00004 /* ======================================================================= 00005 Copyright (c) 2011-2014, Institute for Microelectronics, 00006 Institute for Analysis and Scientific Computing, 00007 TU Wien. 00008 00009 ----------------- 00010 ViennaGrid - The Vienna Grid Library 00011 ----------------- 00012 00013 License: MIT (X11), see file LICENSE in the base directory 00014 ======================================================================= */ 00015 00016 #include <ostream> 00017 #include <iterator> 00018 #include <typeinfo> 00019 #include <iostream> 00020 00021 #include "viennagrid/forwards.hpp" 00022 #include "viennagrid/storage/container_collection.hpp" 00023 #include "viennagrid/storage/algorithm.hpp" 00024 00029 namespace viennagrid 00030 { 00031 namespace detail 00032 { 00033 00034 class container_output_functor 00035 { 00036 public: 00037 container_output_functor(std::ostream & stream, 00038 const std::string & container_delimiter = "\n", 00039 const std::string & element_delimiter = " ") : 00040 container_delimiter_(container_delimiter), element_delimiter_(element_delimiter), stream_(stream) {} 00041 00042 template<typename container_type> 00043 void operator() (const container_type & container) 00044 { 00045 stream_ << typeid(container).name() << " [size=" << container.size() << "] "; 00046 std::copy( container.begin(), container.end(), std::ostream_iterator<typename container_type::value_type>(stream_, element_delimiter_.c_str()) ); 00047 stream_ << container_delimiter_; 00048 } 00049 00050 private: 00051 std::string container_delimiter_; 00052 std::string element_delimiter_; 00053 std::ostream & stream_; 00054 }; 00055 00056 00057 template <typename container_typemap> 00058 std::ostream & operator<<(std::ostream & os, const viennagrid::collection<container_typemap> & container_collection) 00059 { 00060 container_output_functor f(os); 00061 00062 viennagrid::detail::for_each( container_collection, f ); 00063 00064 return os; 00065 } 00066 00067 00068 } 00069 00070 } 00071 00072 #endif