Reorganize some MPL and Utility classes and files

This commit is contained in:
Vinnie Falco
2013-09-19 21:37:47 -07:00
parent 69c26a180e
commit 7efb6a3ab8
16 changed files with 456 additions and 347 deletions

View File

@@ -53,6 +53,9 @@
# define BEAST_SOCKET_VIRTUAL
#endif
#include "../../beast/MPL.h"
#include "../../beast/Utility.h"
namespace beast
{

View File

@@ -51,12 +51,6 @@ namespace detail
namespace SocketWrapperMemberChecks
{
template <bool Enable>
struct EnableIf : boost::false_type { };
template <>
struct EnableIf <true> : boost::true_type { };
BEAST_DEFINE_IS_CALL_POSSIBLE(has_get_io_service, get_io_service);
BEAST_DEFINE_IS_CALL_POSSIBLE(has_lowest_layer, lowest_layer);
@@ -133,6 +127,12 @@ class SocketWrapper
, public Uncopyable
{
public:
// Converts a static bool constexpr member named 'value' into
// an IntegralConstant for SFINAE overload resolution.
//
template <class Cond>
struct Enabled : public IntegralConstant <bool, Cond::value> { };
template <typename Arg>
explicit SocketWrapper (Arg& arg)
: m_object (arg)
@@ -232,11 +232,11 @@ public:
{
using namespace detail::SocketWrapperMemberChecks;
return native_handle (type_name, dest,
EnableIf <has_type_native_handle_type <this_layer_type>::value> ());
Enabled <has_type_native_handle_type <this_layer_type> > ());
}
bool native_handle (char const* type_name, void* dest,
boost::true_type)
TrueType)
{
char const* const name (typeid (typename this_layer_type::native_handle_type).name ());
if (strcmp (name, type_name) == 0)
@@ -249,7 +249,7 @@ public:
}
bool native_handle (char const*, void*,
boost::false_type)
FalseType)
{
pure_virtual_called (__FILE__, __LINE__);
return false;
@@ -266,21 +266,21 @@ public:
// Apparently has_get_io_service always results in false
using namespace detail::SocketWrapperMemberChecks;
return get_io_service (
EnableIf <has_get_io_service <this_layer_type,
boost::asio::io_service&()>::value> ());
Enabled <has_get_io_service <this_layer_type,
boost::asio::io_service&()> > ());
#else
return get_io_service (boost::true_type ());
return get_io_service (TrueType ());
#endif
}
boost::asio::io_service& get_io_service (
boost::true_type)
TrueType)
{
return m_object.get_io_service ();
}
boost::asio::io_service& get_io_service (
boost::false_type)
FalseType)
{
pure_virtual_called (__FILE__, __LINE__);
return *static_cast <boost::asio::io_service*>(nullptr);
@@ -334,11 +334,11 @@ public:
{
using namespace detail::SocketWrapperMemberChecks;
return lowest_layer_ptr (type_name,
EnableIf <has_type_lowest_layer_type <this_layer_type>::value> ());
Enabled <has_type_lowest_layer_type <this_layer_type> > ());
}
void* lowest_layer_ptr (char const* type_name,
boost::true_type) const
TrueType) const
{
char const* const name (typeid (typename this_layer_type::lowest_layer_type).name ());
if (strcmp (name, type_name) == 0)
@@ -347,7 +347,7 @@ public:
}
void* lowest_layer_ptr (char const*,
boost::false_type) const
FalseType) const
{
pure_virtual_called (__FILE__, __LINE__);
return nullptr;
@@ -359,18 +359,18 @@ public:
{
using namespace detail::SocketWrapperMemberChecks;
return cancel (ec,
EnableIf <has_cancel <this_layer_type,
error_code (error_code&)>::value> ());
Enabled <has_cancel <this_layer_type,
error_code (error_code&)> > ());
}
error_code cancel (error_code& ec,
boost::true_type)
TrueType)
{
return m_object.cancel (ec);
}
error_code cancel (error_code& ec,
boost::false_type)
FalseType)
{
return pure_virtual_error (ec, __FILE__, __LINE__);
}
@@ -381,19 +381,19 @@ public:
{
using namespace detail::SocketWrapperMemberChecks;
return shutdown (what, ec,
EnableIf <has_shutdown <this_layer_type,
error_code (shutdown_type, error_code&)>::value> ());
Enabled <has_shutdown <this_layer_type,
error_code (shutdown_type, error_code&)> > ());
}
error_code shutdown (shutdown_type what, error_code& ec,
boost::true_type)
TrueType)
{
return m_object.shutdown (what, ec);
}
error_code shutdown (shutdown_type, error_code& ec,
boost::false_type)
FalseType)
{
return pure_virtual_error (ec, __FILE__, __LINE__);
}
@@ -404,18 +404,18 @@ public:
{
using namespace detail::SocketWrapperMemberChecks;
return close (ec,
EnableIf <has_close <this_layer_type,
error_code (error_code&)>::value> ());
Enabled <has_close <this_layer_type,
error_code (error_code&)> > ());
}
error_code close (error_code& ec,
boost::true_type)
TrueType)
{
return m_object.close (ec);
}
error_code close (error_code& ec,
boost::false_type)
FalseType)
{
return pure_virtual_error (ec, __FILE__, __LINE__);
}
@@ -430,12 +430,12 @@ public:
using namespace detail::SocketWrapperMemberChecks;
typedef typename native_socket <this_layer_type>::socket_type socket_type;
return accept (peer, ec,
EnableIf <has_accept <this_layer_type,
error_code (socket_type&, error_code&)>::value> ());
Enabled <has_accept <this_layer_type,
error_code (socket_type&, error_code&)> > ());
}
error_code accept (Socket& peer, error_code& ec,
boost::true_type)
TrueType)
{
using namespace detail::SocketWrapperMemberChecks;
return m_object.accept (
@@ -443,7 +443,7 @@ public:
}
error_code accept (Socket&, error_code& ec,
boost::false_type)
FalseType)
{
return pure_virtual_error (ec, __FILE__, __LINE__);
}
@@ -455,12 +455,12 @@ public:
using namespace detail::SocketWrapperMemberChecks;
typedef typename native_socket <this_layer_type>::socket_type socket_type;
async_accept (peer, BOOST_ASIO_MOVE_CAST(SharedHandlerPtr)(handler),
EnableIf <has_async_accept <this_layer_type,
void (socket_type&, BOOST_ASIO_MOVE_ARG(SharedHandlerPtr))>::value> ());
Enabled <has_async_accept <this_layer_type,
void (socket_type&, BOOST_ASIO_MOVE_ARG(SharedHandlerPtr))> > ());
}
void async_accept (Socket& peer, BOOST_ASIO_MOVE_ARG(SharedHandlerPtr) handler,
boost::true_type)
TrueType)
{
using namespace detail::SocketWrapperMemberChecks;
m_object.async_accept (
@@ -469,7 +469,7 @@ public:
}
void async_accept (Socket&, BOOST_ASIO_MOVE_ARG(SharedHandlerPtr) handler,
boost::false_type)
FalseType)
{
get_io_service ().wrap (
BOOST_ASIO_MOVE_CAST(SharedHandlerPtr)(handler))
@@ -485,20 +485,20 @@ public:
{
using namespace detail::SocketWrapperMemberChecks;
return read_some (buffers, ec,
EnableIf <has_read_some <this_layer_type,
std::size_t (MutableBuffers const&, error_code&)>::value> ());
Enabled <has_read_some <this_layer_type,
std::size_t (MutableBuffers const&, error_code&)> > ());
}
template <typename MutableBufferSequence>
std::size_t read_some (MutableBufferSequence const& buffers, error_code& ec,
boost::true_type)
TrueType)
{
return m_object.read_some (buffers, ec);
}
template <typename MutableBufferSequence>
std::size_t read_some (MutableBufferSequence const&, error_code& ec,
boost::false_type)
FalseType)
{
pure_virtual_called (__FILE__, __LINE__);
ec = pure_virtual_error ();
@@ -511,20 +511,20 @@ public:
{
using namespace detail::SocketWrapperMemberChecks;
return write_some (buffers, ec,
EnableIf <has_write_some <this_layer_type,
std::size_t (ConstBuffers const&, error_code&)>::value> ());
Enabled <has_write_some <this_layer_type,
std::size_t (ConstBuffers const&, error_code&)> > ());
}
template <typename ConstBufferSequence>
std::size_t write_some (ConstBufferSequence const& buffers, error_code& ec,
boost::true_type)
TrueType)
{
return m_object.write_some (buffers, ec);
}
template <typename ConstBufferSequence>
std::size_t write_some (ConstBufferSequence const&, error_code& ec,
boost::false_type)
FalseType)
{
pure_virtual_called (__FILE__, __LINE__);
ec = pure_virtual_error ();
@@ -537,13 +537,13 @@ public:
{
using namespace detail::SocketWrapperMemberChecks;
async_read_some (buffers, BOOST_ASIO_MOVE_CAST(SharedHandlerPtr)(handler),
EnableIf <has_async_read_some <this_layer_type,
void (MutableBuffers const&, BOOST_ASIO_MOVE_ARG(SharedHandlerPtr))>::value> ());
Enabled <has_async_read_some <this_layer_type,
void (MutableBuffers const&, BOOST_ASIO_MOVE_ARG(SharedHandlerPtr))> > ());
}
void async_read_some (MutableBuffers const& buffers,
BOOST_ASIO_MOVE_ARG(SharedHandlerPtr) handler,
boost::true_type)
TrueType)
{
m_object.async_read_some (buffers,
BOOST_ASIO_MOVE_CAST(SharedHandlerPtr)(handler));
@@ -551,7 +551,7 @@ public:
void async_read_some (MutableBuffers const&,
BOOST_ASIO_MOVE_ARG(SharedHandlerPtr) handler,
boost::false_type)
FalseType)
{
get_io_service ().wrap (
BOOST_ASIO_MOVE_CAST(SharedHandlerPtr)(handler))
@@ -564,13 +564,13 @@ public:
{
using namespace detail::SocketWrapperMemberChecks;
async_write_some (buffers, BOOST_ASIO_MOVE_CAST(SharedHandlerPtr)(handler),
EnableIf <has_async_write_some <this_layer_type,
void (ConstBuffers const&, BOOST_ASIO_MOVE_ARG(SharedHandlerPtr))>::value> ());
Enabled <has_async_write_some <this_layer_type,
void (ConstBuffers const&, BOOST_ASIO_MOVE_ARG(SharedHandlerPtr))> > ());
}
void async_write_some (ConstBuffers const& buffers,
BOOST_ASIO_MOVE_ARG(SharedHandlerPtr) handler,
boost::true_type)
TrueType)
{
m_object.async_write_some (buffers,
BOOST_ASIO_MOVE_CAST(SharedHandlerPtr)(handler));
@@ -578,7 +578,7 @@ public:
void async_write_some (ConstBuffers const&,
BOOST_ASIO_MOVE_ARG(SharedHandlerPtr) handler,
boost::false_type)
FalseType)
{
get_io_service ().wrap (
BOOST_ASIO_MOVE_CAST(SharedHandlerPtr)(handler))
@@ -624,11 +624,11 @@ public:
{
using namespace detail::SocketWrapperMemberChecks;
return next_layer_ptr (type_name,
EnableIf <has_type_next_layer_type <this_layer_type>::value> ());
Enabled <has_type_next_layer_type <this_layer_type> > ());
}
void* next_layer_ptr (char const* type_name,
boost::true_type) const
TrueType) const
{
char const* const name (typeid (typename this_layer_type::next_layer_type).name ());
if (strcmp (name, type_name) == 0)
@@ -637,7 +637,7 @@ public:
}
void* next_layer_ptr (char const*,
boost::false_type) const
FalseType) const
{
pure_virtual_called (__FILE__, __LINE__);
return nullptr;
@@ -661,19 +661,19 @@ public:
{
using namespace detail::SocketWrapperMemberChecks;
set_verify_mode (verify_mode,
EnableIf <has_set_verify_mode <this_layer_type,
void (int)>::value> ());
Enabled <has_set_verify_mode <this_layer_type,
void (int)> > ());
}
void set_verify_mode (int verify_mode,
boost::true_type)
TrueType)
{
m_object.set_verify_mode (verify_mode);
}
void set_verify_mode (int,
boost::false_type)
FalseType)
{
pure_virtual_called (__FILE__, __LINE__);
}
@@ -684,18 +684,18 @@ public:
{
using namespace detail::SocketWrapperMemberChecks;
return handshake (type, ec,
EnableIf <has_handshake <this_layer_type,
error_code (handshake_type, error_code&)>::value> ());
Enabled <has_handshake <this_layer_type,
error_code (handshake_type, error_code&)> > ());
}
error_code handshake (handshake_type type, error_code& ec,
boost::true_type)
TrueType)
{
return m_object.handshake (type, ec);
}
error_code handshake (handshake_type, error_code& ec,
boost::false_type)
FalseType)
{
return pure_virtual_error (ec, __FILE__, __LINE__);
}
@@ -706,20 +706,20 @@ public:
{
using namespace detail::SocketWrapperMemberChecks;
async_handshake (type, BOOST_ASIO_MOVE_CAST(SharedHandlerPtr)(handler),
EnableIf <has_async_handshake <this_layer_type,
void (handshake_type, BOOST_ASIO_MOVE_ARG(SharedHandlerPtr))>::value> ());
Enabled <has_async_handshake <this_layer_type,
void (handshake_type, BOOST_ASIO_MOVE_ARG(SharedHandlerPtr))> > ());
}
void async_handshake (handshake_type type,
BOOST_ASIO_MOVE_ARG(SharedHandlerPtr) handler,
boost::true_type)
TrueType)
{
m_object.async_handshake (type,
BOOST_ASIO_MOVE_CAST(SharedHandlerPtr)(handler));
}
void async_handshake (handshake_type, BOOST_ASIO_MOVE_ARG(SharedHandlerPtr) handler,
boost::false_type)
FalseType)
{
get_io_service ().wrap (
BOOST_ASIO_MOVE_CAST(SharedHandlerPtr)(handler))
@@ -735,19 +735,19 @@ public:
{
using namespace detail::SocketWrapperMemberChecks;
return handshake (type, buffers, ec,
EnableIf <has_handshake <this_layer_type,
error_code (handshake_type, ConstBuffers const&, error_code&)>::value> ());
Enabled <has_handshake <this_layer_type,
error_code (handshake_type, ConstBuffers const&, error_code&)> > ());
}
error_code handshake (handshake_type type,
ConstBuffers const& buffers, error_code& ec,
boost::true_type)
TrueType)
{
return m_object.handshake (type, buffers, ec);
}
error_code handshake (handshake_type, ConstBuffers const&, error_code& ec,
boost::false_type)
FalseType)
{
return pure_virtual_error (ec, __FILE__, __LINE__);
}
@@ -760,14 +760,14 @@ public:
using namespace detail::SocketWrapperMemberChecks;
async_handshake (type, buffers,
BOOST_ASIO_MOVE_CAST(SharedHandlerPtr)(handler),
EnableIf <has_async_handshake <this_layer_type,
Enabled <has_async_handshake <this_layer_type,
void (handshake_type, ConstBuffers const&,
BOOST_ASIO_MOVE_ARG(SharedHandlerPtr))>::value> ());
BOOST_ASIO_MOVE_ARG(SharedHandlerPtr))> > ());
}
void async_handshake (handshake_type type, ConstBuffers const& buffers,
BOOST_ASIO_MOVE_ARG(SharedHandlerPtr) handler,
boost::true_type)
TrueType)
{
m_object.async_handshake (type, buffers,
BOOST_ASIO_MOVE_CAST(SharedHandlerPtr)(handler));
@@ -775,7 +775,7 @@ public:
void async_handshake (handshake_type, ConstBuffers const&,
BOOST_ASIO_MOVE_ARG(SharedHandlerPtr) handler,
boost::false_type)
FalseType)
{
get_io_service ().wrap (
BOOST_ASIO_MOVE_CAST(SharedHandlerPtr)(handler))
@@ -790,18 +790,18 @@ public:
{
using namespace detail::SocketWrapperMemberChecks;
return shutdown (ec,
EnableIf <has_shutdown <this_layer_type,
error_code (error_code&)>::value> ());
Enabled <has_shutdown <this_layer_type,
error_code (error_code&)> > ());
}
error_code shutdown (error_code& ec,
boost::true_type)
TrueType)
{
return m_object.shutdown (ec);
}
error_code shutdown (error_code& ec,
boost::false_type)
FalseType)
{
return pure_virtual_error (ec, __FILE__, __LINE__);
}
@@ -812,19 +812,19 @@ public:
{
using namespace detail::SocketWrapperMemberChecks;
async_shutdown (BOOST_ASIO_MOVE_CAST(SharedHandlerPtr)(handler),
EnableIf <has_async_shutdown <this_layer_type,
void (BOOST_ASIO_MOVE_ARG(SharedHandlerPtr))>::value> ());
Enabled <has_async_shutdown <this_layer_type,
void (BOOST_ASIO_MOVE_ARG(SharedHandlerPtr))> > ());
}
void async_shutdown (BOOST_ASIO_MOVE_ARG(SharedHandlerPtr) handler,
boost::true_type)
TrueType)
{
m_object.async_shutdown (
BOOST_ASIO_MOVE_CAST(SharedHandlerPtr)(handler));
}
void async_shutdown (BOOST_ASIO_MOVE_ARG(SharedHandlerPtr) handler,
boost::false_type)
FalseType)
{
get_io_service ().wrap (
BOOST_ASIO_MOVE_CAST(SharedHandlerPtr)(handler))

View File

@@ -147,7 +147,6 @@ namespace beast
#include "diagnostic/SemanticVersion.cpp"
#include "diagnostic/UnitTest.cpp"
#include "diagnostic/UnitTestUtilities.cpp"
#include "diagnostic/Journal.cpp"
#include "files/DirectoryIterator.cpp"
#include "files/File.cpp"

View File

@@ -144,7 +144,6 @@ namespace beast
#include "text/String.h"
#include "time/AtExitHook.h"
#include "diagnostic/LeakChecked.h"
#include "diagnostic/Journal.h"
#include "time/RelativeTime.h"
#include "time/Time.h"
#include "memory/HeapBlock.h"

View File

@@ -1,183 +0,0 @@
//------------------------------------------------------------------------------
/*
This file is part of Beast: https://github.com/vinniefalco/Beast
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
bool Journal::Sink::active (Severity)
{
return true;
}
//------------------------------------------------------------------------------
Journal::Sink& Journal::getNullSink ()
{
// A Sink that does nothing.
class NullSink : public Sink
{
public:
void write (Severity, std::string const&)
{
}
bool active (Severity)
{
return false;
}
};
return *SharedSingleton <NullSink>::get (
SingletonLifetime::neverDestroyed);
}
//------------------------------------------------------------------------------
Journal::ScopedStream::ScopedStream (Stream const& stream)
: m_sink (stream.sink())
, m_severity (stream.severity())
{
}
Journal::ScopedStream::ScopedStream (ScopedStream const& other)
: m_sink (other.m_sink)
, m_severity (other.m_severity)
{
}
Journal::ScopedStream::ScopedStream (Stream const& stream, std::ostream& manip (std::ostream&))
: m_sink (stream.sink())
, m_severity (stream.severity())
{
m_ostream << manip;
}
Journal::ScopedStream::~ScopedStream ()
{
if (m_sink.active (m_severity))
{
if (! m_ostream.str().empty())
m_sink.write (m_severity, m_ostream.str());
}
}
std::ostream& Journal::ScopedStream::operator<< (std::ostream& manip (std::ostream&)) const
{
return m_ostream << manip;
}
std::ostringstream& Journal::ScopedStream::ostream () const
{
return m_ostream;
}
//------------------------------------------------------------------------------
Journal::Stream::Stream ()
: m_sink (&getNullSink ())
, m_severity (kFatal)
{
}
Journal::Stream::Stream (Sink& sink, Severity severity)
: m_sink (&sink)
, m_severity (severity)
{
}
Journal::Stream::Stream (Stream const& other)
: m_sink (other.m_sink)
, m_severity (other.m_severity)
{
}
bool Journal::Stream::active () const
{
return m_sink->active (m_severity);
}
Journal::Sink& Journal::Stream::sink () const
{
return *m_sink;
}
Journal::Severity Journal::Stream::severity () const
{
return m_severity;
}
Journal::Stream& Journal::Stream::operator= (Stream const& other)
{
m_sink = other.m_sink;
m_severity = other.m_severity;
return *this;
}
Journal::ScopedStream Journal::Stream::operator<< (std::ostream& manip (std::ostream&)) const
{
return ScopedStream (*this, manip);
}
//------------------------------------------------------------------------------
Journal::Journal ()
: m_sink (&getNullSink())
, trace (stream (kTrace))
, debug (stream (kDebug))
, info (stream (kInfo))
, warning (stream (kWarning))
, error (stream (kError))
, fatal (stream (kFatal))
{
}
Journal::Journal (Sink& sink)
: m_sink (&sink)
, trace (stream (kTrace))
, debug (stream (kDebug))
, info (stream (kInfo))
, warning (stream (kWarning))
, error (stream (kError))
, fatal (stream (kFatal))
{
}
Journal::Journal (Journal const& other)
: m_sink (other.m_sink)
, trace (stream (kTrace))
, debug (stream (kDebug))
, info (stream (kInfo))
, warning (stream (kWarning))
, error (stream (kError))
, fatal (stream (kFatal))
{
}
Journal::~Journal ()
{
}
Journal::Stream Journal::stream (Severity severity) const
{
return Stream (*m_sink, severity);
}
/** Returns `true` if the sink logs messages at that severity. */
bool Journal::active (Severity severity) const
{
return m_sink->active (severity);
}

View File

@@ -1,161 +0,0 @@
//------------------------------------------------------------------------------
/*
This file is part of Beast: https://github.com/vinniefalco/Beast
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef BEAST_CORE_JOURNAL_H_INCLUDED
#define BEAST_CORE_JOURNAL_H_INCLUDED
/** A generic endpoint for log messages. */
class Journal
{
public:
class Sink;
private:
Sink* m_sink;
public:
/** Severity level of the message. */
enum Severity
{
kTrace,
kDebug,
kInfo,
kWarning,
kError,
kFatal
};
//--------------------------------------------------------------------------
/** Abstraction for the underlying message destination. */
class Sink
{
public:
virtual ~Sink () { }
/** Write text to the sink at the specified severity. */
virtual void write (Severity severity, std::string const& text) = 0;
/** Returns `true` if text at the passed severity produces output.
The default implementation always returns `true`.
*/
virtual bool active (Severity);
};
/** Returns a Sink which does nothing. */
static Sink& getNullSink ();
//--------------------------------------------------------------------------
class Stream;
/** Scoped ostream-based container for writing messages to a Journal. */
class ScopedStream
{
public:
explicit ScopedStream (Stream const& stream);
ScopedStream (ScopedStream const& other);
template <typename T>
ScopedStream (Stream const& stream, T const& t)
: m_sink (stream.sink())
, m_severity (stream.severity())
{
m_ostream << t;
}
ScopedStream (Stream const& stream, std::ostream& manip (std::ostream&));
~ScopedStream ();
std::ostringstream& ostream () const;
std::ostream& operator<< (std::ostream& manip (std::ostream&)) const;
template <typename T>
std::ostream& operator<< (T const& t) const
{
return m_ostream << t;
}
private:
ScopedStream& operator= (ScopedStream const&); // disallowed
Sink& m_sink;
Severity const m_severity;
std::ostringstream mutable m_ostream;
};
//--------------------------------------------------------------------------
class Stream
{
public:
/** Construct a stream which produces no logging output. */
Stream ();
Stream (Sink& sink, Severity severity);
Stream (Stream const& other);
Stream& operator= (Stream const& other);
/** Returns `true` if the sink logs messages at the severity of this stream. */
bool active() const;
Sink& sink() const;
Severity severity() const;
ScopedStream operator<< (std::ostream& manip (std::ostream&)) const;
template <typename T>
ScopedStream operator<< (T const& t) const
{
return ScopedStream (*this, t);
}
private:
Sink* m_sink;
Severity m_severity;
};
//--------------------------------------------------------------------------
Journal ();
explicit Journal (Sink& sink);
Journal (Journal const& other);
~Journal ();
/** Returns a stream for this sink, with the specified severity. */
Stream stream (Severity severity) const;
/** Returns `true` if the sink logs messages at that severity. */
bool active (Severity severity) const;
/** Convenience sink streams for each severity level. */
Stream const trace;
Stream const debug;
Stream const info;
Stream const warning;
Stream const error;
Stream const fatal;
private:
Journal& operator= (Journal const& other); // disallowed
};
#endif

View File

@@ -22,248 +22,6 @@
//------------------------------------------------------------------------------
// inspired by Roman Perepelitsa's presentation from comp.lang.c++.moderated
// based on the implementation here: http://www.rsdn.ru/forum/cpp/2759773.1.aspx
//
namespace is_call_possible_detail
{
template<typename T>
struct add_reference
{
typedef T& type;
};
template<typename T>
struct add_reference<T&>
{
typedef T& type;
};
template <typename T> class void_exp_result {};
template <typename T, typename U>
U const& operator,(U const&, void_exp_result<T>);
template <typename T, typename U>
U& operator,(U&, void_exp_result<T>);
template <typename src_type, typename dest_type>
struct clone_constness
{
typedef dest_type type;
};
template <typename src_type, typename dest_type>
struct clone_constness<const src_type, dest_type>
{
typedef const dest_type type;
};
}
#define BEAST_DEFINE_HAS_MEMBER_FUNCTION(trait_name, member_function_name) \
template<typename T, typename Signature> class trait_name; \
\
template<typename T, typename Result> \
class trait_name<T, Result(void)> \
{ \
class yes { char m; }; \
class no { yes m[2]; }; \
struct base_mixin \
{ \
Result member_function_name(); \
}; \
struct base : public T, public base_mixin { private: base(); }; \
template <typename U, U t> class helper{}; \
template <typename U> \
static no deduce(U*, helper<Result (base_mixin::*)(), &U::member_function_name>* = 0); \
static yes deduce(...); \
public: \
static const bool value = sizeof(yes) == sizeof(deduce(static_cast<base*>(0))); \
}; \
\
template<typename T, typename Result, typename Arg> \
class trait_name<T, Result(Arg)> \
{ \
class yes { char m; }; \
class no { yes m[2]; }; \
struct base_mixin \
{ \
Result member_function_name(Arg); \
}; \
struct base : public T, public base_mixin { private: base(); }; \
template <typename U, U t> class helper{}; \
template <typename U> \
static no deduce(U*, helper<Result (base_mixin::*)(Arg), &U::member_function_name>* = 0); \
static yes deduce(...); \
public: \
static const bool value = sizeof(yes) == sizeof(deduce(static_cast<base*>(0))); \
}; \
\
template<typename T, typename Result, typename Arg1, typename Arg2> \
class trait_name<T, Result(Arg1,Arg2)> \
{ \
class yes { char m; }; \
class no { yes m[2]; }; \
struct base_mixin \
{ \
Result member_function_name(Arg1,Arg2); \
}; \
struct base : public T, public base_mixin { private: base(); }; \
template <typename U, U t> class helper{}; \
template <typename U> \
static no deduce(U*, helper<Result (base_mixin::*)(Arg1,Arg2), &U::member_function_name>* = 0); \
static yes deduce(...); \
public: \
static const bool value = sizeof(yes) == sizeof(deduce(static_cast<base*>(0))); \
}; \
\
template<typename T, typename Result, typename Arg1, typename Arg2, typename Arg3> \
class trait_name<T, Result(Arg1,Arg2,Arg3)> \
{ \
class yes { char m; }; \
class no { yes m[2]; }; \
struct base_mixin \
{ \
Result member_function_name(Arg1,Arg2,Arg3); \
}; \
struct base : public T, public base_mixin { private: base(); }; \
template <typename U, U t> class helper{}; \
template <typename U> \
static no deduce(U*, helper<Result (base_mixin::*)(Arg1,Arg2,Arg3), &U::member_function_name>* = 0); \
static yes deduce(...); \
public: \
static const bool value = sizeof(yes) == sizeof(deduce(static_cast<base*>(0))); \
}; \
\
template<typename T, typename Result, typename Arg1, typename Arg2, typename Arg3, typename Arg4> \
class trait_name<T, Result(Arg1,Arg2,Arg3,Arg4)> \
{ \
class yes { char m; }; \
class no { yes m[2]; }; \
struct base_mixin \
{ \
Result member_function_name(Arg1,Arg2,Arg3,Arg4); \
}; \
struct base : public T, public base_mixin { private: base(); }; \
template <typename U, U t> class helper{}; \
template <typename U> \
static no deduce(U*, helper<Result (base_mixin::*)(Arg1,Arg2,Arg3,Arg4), &U::member_function_name>* = 0); \
static yes deduce(...); \
public: \
static const bool value = sizeof(yes) == sizeof(deduce(static_cast<base*>(0))); \
}
#define BEAST_DEFINE_IS_CALL_POSSIBLE(trait_name, member_function_name) \
struct trait_name##_detail \
{ \
BEAST_DEFINE_HAS_MEMBER_FUNCTION(has_member, member_function_name); \
}; \
\
template <typename T, typename Signature> \
struct trait_name \
{ \
private: \
class yes {}; \
class no { yes m[2]; }; \
struct derived : public T \
{ \
using T::member_function_name; \
no member_function_name(...) const; \
private: derived (); \
}; \
\
typedef typename is_call_possible_detail::clone_constness<T, derived>::type derived_type; \
\
template <typename U, typename Result> \
struct return_value_check \
{ \
static yes deduce(Result); \
static no deduce(...); \
static no deduce(no); \
static no deduce(is_call_possible_detail::void_exp_result<T>); \
}; \
\
template <typename U> \
struct return_value_check<U, void> \
{ \
static yes deduce(...); \
static no deduce(no); \
}; \
\
template <bool has_the_member_of_interest, typename F> \
struct impl \
{ \
static const bool value = false; \
}; \
\
template <typename Result, typename Arg> \
struct impl<true, Result(Arg)> \
{ \
static typename is_call_possible_detail::add_reference<derived_type>::type test_me; \
static typename is_call_possible_detail::add_reference<Arg>::type arg; \
\
static const bool value = \
sizeof( \
return_value_check<T, Result>::deduce( \
(test_me.member_function_name(arg), is_call_possible_detail::void_exp_result<T>()) \
) \
) == sizeof(yes); \
}; \
\
template <typename Result, typename Arg1, typename Arg2> \
struct impl<true, Result(Arg1,Arg2)> \
{ \
static typename is_call_possible_detail::add_reference<derived_type>::type test_me; \
static typename is_call_possible_detail::add_reference<Arg1>::type arg1; \
static typename is_call_possible_detail::add_reference<Arg2>::type arg2; \
\
static const bool value = \
sizeof( \
return_value_check<T, Result>::deduce( \
(test_me.member_function_name(arg1,arg2), is_call_possible_detail::void_exp_result<T>()) \
) \
) == sizeof(yes); \
}; \
\
template <typename Result, typename Arg1, typename Arg2, typename Arg3> \
struct impl<true, Result(Arg1,Arg2,Arg3)> \
{ \
static typename is_call_possible_detail::add_reference<derived_type>::type test_me; \
static typename is_call_possible_detail::add_reference<Arg1>::type arg1; \
static typename is_call_possible_detail::add_reference<Arg2>::type arg2; \
static typename is_call_possible_detail::add_reference<Arg3>::type arg3; \
\
static const bool value = \
sizeof( \
return_value_check<T, Result>::deduce( \
(test_me.member_function_name(arg1,arg2,arg3), is_call_possible_detail::void_exp_result<T>()) \
) \
) == sizeof(yes); \
}; \
\
template <typename Result, typename Arg1, typename Arg2, typename Arg3, typename Arg4> \
struct impl<true, Result(Arg1,Arg2,Arg3,Arg4)> \
{ \
static typename is_call_possible_detail::add_reference<derived_type>::type test_me; \
static typename is_call_possible_detail::add_reference<Arg1>::type arg1; \
static typename is_call_possible_detail::add_reference<Arg2>::type arg2; \
static typename is_call_possible_detail::add_reference<Arg3>::type arg3; \
static typename is_call_possible_detail::add_reference<Arg4>::type arg4; \
\
static const bool value = \
sizeof( \
return_value_check<T, Result>::deduce( \
(test_me.member_function_name(arg1,arg2,arg3,arg4), is_call_possible_detail::void_exp_result<T>()) \
) \
) == sizeof(yes); \
}; \
\
public: \
static const bool value = impl<trait_name##_detail::has_member<T,Signature>::value, Signature>::value; \
}
//------------------------------------------------------------------------------
/* Brings functional support into our namespace, based on environment.
Notes on bind