Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:29:46

0001 //  boost/chrono/utility/manip_base.hpp  ------------------------------------------------------------//
0002 
0003 //  Copyright 2011 Vicente J. Botet Escriba
0004 
0005 //  Distributed under the Boost Software License, Version 1.0. (See accompanying
0006 //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0007 
0008 //  See http://www.boost.org/libs/chrono for documentation.
0009 
0010 #ifndef BOOST_CHRONO_UTILITY_MANIP_BASE_PTR_HPP
0011 #define BOOST_CHRONO_UTILITY_MANIP_BASE_PTR_HPP
0012 
0013 #include <ios>
0014 
0015 /**
0016  *
0017 
0018  */
0019 
0020 namespace boost
0021 {
0022   namespace chrono
0023   {
0024 
0025     /**
0026      * manip is a manipulator mixin class following the CRTP.
0027      * @tparam Final the derived from manip and final type
0028      *
0029      * @Example
0030      * @code
0031 
0032     class mendl: public manip<mendl>
0033     {
0034     public:
0035       explicit mendl(size_t how_many) :
0036         count(how_many) {}
0037       template <typename out_stream>
0038       void operator()(out_stream &out) const
0039       {
0040         for (size_t line = 0; line < count; ++line)
0041         {
0042           out.put(out.widen('\n'));
0043         }
0044         out.flush();
0045       }
0046     private:
0047       size_t count;
0048     };
0049 
0050      * @codeend
0051      */
0052     template <typename Final>
0053     class manip
0054     {
0055     public:
0056       /**
0057        *
0058        * @param ios the io stream or ios_base.
0059        * @Effects calls to the manipulator final functor.
0060        */
0061       //template <typename out_stream>
0062       void operator()(std::ios_base &ios) const
0063       {
0064         (*static_cast<const Final *> (this))(ios);
0065       }
0066     };
0067 
0068     /**
0069      * @c manip stream inserter
0070      * @param out the io stream or ios_base.
0071      * @param op the manipulator instance.
0072      * @Effects if @c out is good calls to the manipulator functor @op.
0073      * @return @c out
0074      */
0075     template <typename out_stream, typename manip_type>
0076     out_stream &operator<<(out_stream &out, const manip<manip_type> &op)
0077     {
0078       if (out.good())
0079         op(out);
0080       return out;
0081     }
0082 
0083     /**
0084      * @c manip stream extractor
0085      * @param in the io stream or ios_base.
0086      * @param op  the manipulator instance.
0087      * @Effects if @c in is good calls to the manipulator functor @op.
0088      * @return @c in
0089      */
0090     template <typename in_stream, typename manip_type>
0091     in_stream &operator>>(in_stream &in, const manip<manip_type> &op)
0092     {
0093       if (in.good())
0094         op(in);
0095       return in;
0096     }
0097 
0098   } // namespace chrono
0099 } // namespace boost
0100 
0101 #endif // header