Mirror reflection library 0.5.13

mirror/stream/base.hpp

Go to the documentation of this file.
00001 
00010 #ifndef MIRROR_STREAM_BASE_1011291729_HPP
00011 #define MIRROR_STREAM_BASE_1011291729_HPP
00012 
00013 #include <mirror/config.hpp>
00014 #include <mirror/mirror_fwd.hpp>
00015 #include <iostream>
00016 #include <functional>
00017 
00018 MIRROR_NAMESPACE_BEGIN
00019 namespace stream {
00020 
00021 template <typename T, typename OutputTag>
00022 class _writer;
00023 
00024 template <typename OutputTag>
00025 struct _target;
00026 
00027 typedef std::function<void (std::ostream&)> name_proc;
00028 
00029 template <typename T, typename OutputTag>
00030 class _wrap
00031 {
00032 private:
00033     const T& value;
00034     name_proc namer;
00035     int level;
00036 
00037     _wrap(const _wrap& other)
00038      : value(other.value)
00039      , level(other.level)
00040     { }
00041 public:
00042     _wrap(const T& src)
00043      : value(src)
00044      , level(0)
00045     { }
00046 
00047     _wrap(const T& src, const name_proc& src_namer)
00048      : value(src)
00049      , namer(src_namer)
00050      , level(0)
00051     { }
00052 
00053     template <typename X>
00054     _wrap(const T& src, const _wrap<X, OutputTag>& parent)
00055      : value(src)
00056      , level(parent.depth() + 1)
00057     { }
00058 
00059     friend class _target<OutputTag>;
00060 
00061     friend class _writer<T, OutputTag>;
00062 
00063     int depth(void) const
00064     {
00065         return level;
00066     }
00067 
00068     friend inline std::ostream& operator << (std::ostream& out, const _wrap& obj)
00069     {
00070         _writer<T, OutputTag> to_stream;
00071         return obj.namer ?
00072             to_stream(out, obj, obj.namer) :
00073             to_stream(out, obj) ;
00074     }
00075 };
00076 
00077 template <typename OutputTag>
00078 struct _target
00079 {
00080     template <typename T>
00081     static inline _wrap<T, OutputTag> from(const T& src)
00082     {
00083         return _wrap<T, OutputTag>(src);
00084     }
00085 
00086     template <typename T>
00087     static inline _wrap<T, OutputTag> from(
00088         const T& src,
00089         const name_proc& name
00090     )
00091     {
00092         return _wrap<T, OutputTag>(src, name);
00093     }
00094 
00095     template <typename T, typename X>
00096     static inline _wrap<T, OutputTag> from(
00097         const T& src,
00098         const _wrap<X, OutputTag>& parent
00099     )
00100     {
00101         return _wrap<T, OutputTag>(src, parent);
00102     }
00103 };
00104 
00105 } // namespace stream
00106 MIRROR_NAMESPACE_END
00107 
00108 #endif //include guard
00109 

Copyright © 2006-2011 Matus Chochlik, University of Zilina, Zilina, Slovakia.
<matus.chochlik -at- fri.uniza.sk>
<chochlik -at -gmail.com>
Documentation generated on Fri Dec 16 2011 by Doxygen (version 1.7.3).
Important note: Although the 'boostified' version of Mirror uses the Boost C++ libraries Coding Guidelines and is implemented inside of the boost namespace, it IS NOT an officially reviewed and accepted Boost library. Mirror is being developed with the intention to be submitted for review for inclusion to the Boost C++ libraries.