Menu

[r217]: / trunk / libs / network / doc / message.qbk  Maximize  Restore  History

Download this file

104 lines (77 with data), 3.3 kB

[/
  (C) Copyright 2008, 2009 Glyn Matthews.
  Distributed under the Boost Software License, Version 1.0.
  (See accompanying file LICENSE_1_0.txt or copy at
  http://www.boost.org/LICENSE_1_0.txt).
]


[section:message The Message]
The initial concept behind the __cnl__ is the __message__ template. The advantage of this is that __message__ can be specialized for different protocol implementations.

__message__ is presented below:
[import message.cpp]
[boost_network_message]

__message__ is the bare minimum for a class to model the Message concept.  It is intended to be extended and customized according to the requirements of different protocols.  

[section:tag_dispatching Tag Dispatching]
The __message__ template has a single argument (Tag).  Tags are useful because:

# It's possible to specialize the message for different storage requirements;
# It's possible to extend the message to support different network protocols.

The storage requirements for each of these can differ depending on factors such as the string encoding type or memory usage.  For different reasons, its possible to assume a string implementation might be:

# [^std::string]
# [^std::wstring]
# [^std::vector<boost::uint32_t>]
# [@http://msdn.microsoft.com/en-us/library/ms174288.aspx [^CString]]
# [@http://doc.trolltech.com/qstring.html [^QString]]

The __cnl__ uses tag dispatching to specialize the message interface at compile time.

 namespace boost {
 namespace network {
 typedef void tag_specialization_is_not_provided;

 template <
     class Tag
     >
 struct string {
     typedef tag_specialization_is_not_provided type;
 };

 namespace tags {
 struct default_ { };
 } // namespace tags
 
 template <>
 struct string<tags::default_> {
     typedef std::string type;
 };
 } // namespace network
 } // namespace boost

This technique is extended to two more metafunctions that are used by __message__:

 namespace boost {
 namespace network {
 template <
     class Tag
     >
 struct ostringstream {
     typedef tag_specialization_is_not_provided type;
 };

 template <
     class Tag
     >
 struct headers_container {
     typedef tag_specialization_is_not_provided type;
 };
 } // namespace network
 } // namespace boost

[endsect]

[section:message_concepts Concepts]
__message__ is [@http://www.boost.org/doc/html/DefaultConstructible.html DefaultConstructible], [@http://www.boost.org/doc/html/CopyConstructible.html CopyConstructible] and [@http://www.boost.org/doc/html/Assignable.html Assignable].

[endsect]

[section:transformation_layer Transformation layer]
The transformation layer defines the algorithms that can be applied on messages to transform parts or whole messages into different forms or representations. Transformations should apply to any type that models the Message concept.  Functions in the transform layer take the form:

 template <
     class Tag
     >
 basic_message<Tag> &transform(basic_message<Tag> &, ...);

[endsect]

[section:rendering_layer Rendering layer]
The rendering layer defines the algorithms used to render a message into different formats or types. Rendering functions should apply to any type that models the Message Concept.  Functions in the rendering layer take the form:

 template <
     class Tag
     >
 unspecified &render(const basic_message<Tag> &, ...);

[endsect]

[endsect]