Click here to Skip to main content
15,897,273 members
Articles / Programming Languages / C++

Napkin

Rate me:
Please Sign up or sign in to vote.
4.38/5 (4 votes)
12 Mar 20063 min read 39.1K   66   11  
A simple logging library using generic object to streams
#pragma once


#include <windows.h>
#include <boost/config.hpp>
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/enum_params.hpp>
#include <boost/preprocessor/enum_params_with_defaults.hpp>
#include <boost/preprocessor/repeat.hpp>
#include <pstade/crtp_cast.hpp>
#include "../config/limit_message_processor_base_size.hpp"
#include "./entry_subset.hpp"
#include "./process_window_message.hpp"

#include "../cmd_ui/detail/handler_entry_set_include.ipp"
#include "../crack/detail/handler_entry_set_declare.ipp"


///////////////////////////////////////////////////////////////////////////////
// Note:
//   message_processor is the ambiguity buster.
//
//   As entry_subset has only classes,
//   multiple inheritance makes no ambiguity:
//
//     struct A { struct X { }; };
//
//   A is just a namespace.
//
#pragma warning(push)
#pragma warning(disable: 4584) // base-class 'meta_unique_base<Base>' is already a base-class
//
//   But handler-entries are class templates,
//   so they makes ambiguity:
//
//     template< class T >
//     struct B { struct X { T x; }; };
//
//   B<int> and B<char> are different namespaces.
//
//   By the way, you need not care about access control
//   of entry_subset thanks to C++ Standard 11.7.
//

namespace pstade { namespace ketchup {


namespace message_processor_detail {


	// prepare for (Sequence == entry_subset)
	template< class Base >
	struct meta_unique_base : Base
	{
		typedef meta_unique_base type;
	};


	#define PSTADE_KETCHUP_DETAIL_MAKE_UNIQUE_BASE(z, n, unused) \
		struct BOOST_PP_CAT(unique_base, n) { }; \
	/**/

	BOOST_PP_REPEAT(PSTADE_KETCHUP_LIMIT_MESSAGE_PROCESSOR_BASE_SIZE, PSTADE_KETCHUP_DETAIL_MAKE_UNIQUE_BASE, ~)


} // namespace message_processor_detail


///////////////////////////////////////////////////////////////////////////////
// message_processor
//
template<
	class Derived,
	BOOST_PP_ENUM_PARAMS_WITH_DEFAULTS(PSTADE_KETCHUP_LIMIT_MESSAGE_PROCESSOR_BASE_SIZE, class BaseT, message_processor_detail::unique_base)
>
struct message_processor :
	message_processor_detail::meta_unique_base<entry_subset>::type,
	BOOST_PP_ENUM_PARAMS(PSTADE_KETCHUP_LIMIT_MESSAGE_PROCESSOR_BASE_SIZE, BaseT)
{
#if !defined(BOOST_NO_POINTER_TO_MEMBER_TEMPLATE_PARAMETERS)
	#include "../win/detail/handler_entry_set.ipp"
	#include "../crack/detail/handler_entry_set.ipp"
	#include "../cmd_ui/detail/handler_entry_set.ipp"
#endif

	typedef Derived _;

	BOOL ProcessWindowMessage(HWND hWnd, UINT uMsg,
		WPARAM wParam, LPARAM lParam, LRESULT& lResult, DWORD dwMsgMapID = 0)
	{
		Derived& d = pstade::auto_derived(this);

		return ketchup::process_window_message(d, hWnd, uMsg,
			wParam, lParam, lResult, dwMsgMapID);
	}
};


} } // namespace pstade::ketchup

#pragma warning(pop)

#include "../crack/detail/handler_entry_set_undef.ipp"

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Japan Japan
I am worried about my poor English...

Comments and Discussions