Skip to content

Commit ec2dd88

Browse files
author
mikhail_beris
committed
Initial import.
0 parents  commit ec2dd88

23 files changed

+444
-0
lines changed

Jamroot

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
# Copyright Dean Michael Berris 2007.
3+
# Distributed under the Boost Software License, Version 1.0.
4+
# (See accompanying file LICENSE_1_0.txt or copy at
5+
# http://www.boost.org/LICENSE_1_0.txt)
6+
7+
import modules ;
8+
9+
local BOOST_ROOT = [ modules.peek : BOOST_ROOT ] ;
10+
11+
use-project /boost : $(BOOST_ROOT) ;
12+
13+
using testing ;

LICENSE_1_0.txt

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Boost Software License - Version 1.0 - August 17th, 2003
2+
3+
Permission is hereby granted, free of charge, to any person or organization
4+
obtaining a copy of the software and accompanying documentation covered by
5+
this license (the "Software") to use, reproduce, display, distribute,
6+
execute, and transmit the Software, and to prepare derivative works of the
7+
Software, and to permit third-parties to whom the Software is furnished to
8+
do so, all subject to the following:
9+
10+
The copyright notices in the Software and this entire statement, including
11+
the above license grant, this restriction and the following disclaimer,
12+
must be included in all copies of the Software, in whole or in part, and
13+
all derivative works of the Software, unless such copies or derivative
14+
works are solely in the form of machine-executable object code generated by
15+
a source language processor.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
20+
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
21+
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
22+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23+
DEALINGS IN THE SOFTWARE.

README.txt

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
C++ Network Library
2+
3+
This is a collection of network related routines/implementations
4+
geared towards providing a robust cross-platform networking library.
5+
This offers the following implementations:
6+
7+
o Common Message Type -- A generic message type which can be used
8+
to encapsulate and store message related information, used by all
9+
network implementations as the primary means of data exchange.
10+
o Network protocol message parsers -- A collection of parsers which
11+
generate message objects from strings.
12+
o Adapters and Wrappers -- A collection of Adapters and wrappers aimed
13+
towards making the message type STL friendly.
14+
15+
This library is released under the Boost Software License (please see
16+
http://boost.org/LICENSE_1_0.txt or the accompanying LICENSE_1_0.txt file
17+
for the full text.
18+
19+

boost/network.hpp

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
// Copyright Dean Michael Berris 2007.
3+
// Distributed under the Boost Software License, Version 1.0.
4+
// (See accompanying file LICENSE_1_0.txt or copy at
5+
// http://www.boost.org/LICENSE_1_0.txt)
6+
7+
#ifndef __NETWORK_HPP__
8+
#define __NETWORK_HPP__
9+
10+
// Include all headers in network/
11+
// Author: Dean Michael Berris
12+
// Date: May 20, 2007
13+
14+
#include <boost/network/message.hpp> // message type implementation
15+
16+
#endif // __NETWORK_HPP__
17+

boost/network/.message.hpp.swp

12 KB
Binary file not shown.
12 KB
Binary file not shown.
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
// Copyright Dean Michael Berris 2007.
3+
// Distributed under the Boost Software License, Version 1.0.
4+
// (See accompanying file LICENSE_1_0.txt or copy at
5+
// http://www.boost.org/LICENSE_1_0.txt)
6+
7+
#ifndef __NETWORK_DETAIL_DIRECTIVE_BASE_HPP__
8+
#define __NETWORK_DETAIL_DIRECTIVE_BASE_HPP__
9+
10+
/** Defines the base type from which all directives inherit
11+
* to allow friend access to message and other types' internals.
12+
*/
13+
namespace boost { namespace network { namespace detail {
14+
15+
template <class Tag>
16+
struct directive_base {
17+
typedef Tag tag ;
18+
//explicit directive_base(basic_message<tag> & message_)
19+
// : _message(message_)
20+
protected:
21+
virtual ~directive_base()
22+
{ }; // can only be extended
23+
24+
// mutable basic_message<tag> & _message;
25+
};
26+
27+
}; // namespace detail
28+
29+
}; // namespace network
30+
31+
}; // namespace boost
32+
33+
#endif // __NETWORK_DETAIL_DIRECTIVE_BASE_HPP__
34+

boost/network/detail/wrapper_base.hpp

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
// Copyright Dean Michael Berris 2007.
3+
// Distributed under the Boost Software License, Version 1.0.
4+
// (See accompanying file LICENSE_1_0.txt or copy at
5+
// http://www.boost.org/LICENSE_1_0.txt)
6+
7+
#ifndef __NETWORK_DETAIL_WRAPPER_BASE_HPP__
8+
#define __NETWORK_DETAIL_WRAPPER_BASE_HPP__
9+
10+
namespace boost { namespace network { namespace detail {
11+
12+
template <class Tag>
13+
struct wrapper_base {
14+
typedef Tag tag;
15+
explicit wrapper_base(basic_message<tag> & message_)
16+
: _message(message_)
17+
{ };
18+
19+
protected:
20+
virtual ~wrapper_base()
21+
{ }; // for extending only
22+
23+
mutable basic_message<tag> & _message;
24+
};
25+
26+
}; // namespace detail
27+
28+
}; // namespace network
29+
30+
}; // namespace boost
31+
32+
#endif // __NETWORK_DETAIL_WRAPPER_BASE_HPP__
33+

boost/network/message.hpp

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
2+
// Copyright Dean Michael Berris 2007.
3+
// Distributed under the Boost Software License, Version 1.0.
4+
// (See accompanying file LICENSE_1_0.txt or copy at
5+
// http://www.boost.org/LICENSE_1_0.txt)
6+
7+
#ifndef __NETWORK_MESSAGE_HPP__
8+
#define __NETWORK_MESSAGE_HPP__
9+
10+
#include <map>
11+
#include <string>
12+
13+
// forward declarations
14+
namespace boost { namespace network {
15+
template <class tag>
16+
class basic_message;
17+
}; // namespace network
18+
19+
}; // namespace boost
20+
21+
#include <boost/network/detail/directive_base.hpp>
22+
#include <boost/network/detail/wrapper_base.hpp>
23+
24+
/** message.hpp
25+
*
26+
* This header file implements the common message type which
27+
* all networking implementations under the boost::network
28+
* namespace. The common message type allows for easy message
29+
* construction and manipulation suited for networked
30+
* application development.
31+
*/
32+
namespace boost { namespace network {
33+
34+
struct tags {
35+
struct default_ { };
36+
};
37+
38+
/** The common message type.
39+
*/
40+
template <class tag=tags::default_>
41+
class basic_message {
42+
public:
43+
typedef std::multimap<std::string, std::string> headers_container_type;
44+
45+
headers_container_type & headers() const {
46+
return _headers;
47+
};
48+
49+
private:
50+
51+
friend struct detail::directive_base<tag> ;
52+
friend struct detail::wrapper_base<tag> ;
53+
54+
mutable headers_container_type _headers;
55+
};
56+
57+
typedef basic_message<> message; // default message type
58+
59+
}; // namespace network
60+
}; // namespace boost
61+
62+
#include <boost/network/message/directives.hpp>
63+
// pull in directives header file
64+
65+
#include <boost/network/message/wrappers.hpp>
66+
// pull in wrappers header file
67+
68+
#endif // __NETWORK_MESSAGE_HPP__
69+

boost/network/message/directives.hpp

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
// Copyright Dean Michael Berris 2007.
3+
// Distributed under the Boost Software License, Version 1.0.
4+
// (See accompanying file LICENSE_1_0.txt or copy at
5+
// http://www.boost.org/LICENSE_1_0.txt)
6+
7+
#ifndef __NETWORK_MESSAGE_DIRECTIVES_HPP__
8+
#define __NETWORK_MESSAGE_DIRECTIVES_HPP__
9+
10+
/** Include all the various directive headers.
11+
*/
12+
13+
#include <boost/network/message/directives/header.hpp>
14+
15+
namespace boost { namespace network {
16+
17+
template <class Tag, template <class> class Directive>
18+
inline basic_message<Tag> &
19+
operator<< (basic_message<Tag> & message_, Directive<Tag> const & directive) {
20+
directive(message_);
21+
return message_;
22+
};
23+
24+
}; // namespace network
25+
26+
}; // namespace boost
27+
28+
#endif // __NETWORK_MESSAGE_DIRECTIVES_HPP__
29+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2+
// Copyright Dean Michael Berris 2007.
3+
// Distributed under the Boost Software License, Version 1.0.
4+
// (See accompanying file LICENSE_1_0.txt or copy at
5+
// http://www.boost.org/LICENSE_1_0.txt)
6+
7+
#ifndef __NETWORK_MESSAGE_DIRECTIVES_HEADER_HPP__
8+
#define __NETWORK_MESSAGE_DIRECTIVES_HEADER_HPP__
9+
10+
/** header.hpp
11+
*
12+
* Defines the types involved and the semantics of adding
13+
* header information into message objects.
14+
*
15+
* WARNING: DO NOT INCLUDE THIS HEADER DIRECTLY. THIS REQUIRES
16+
* TYPES TO BE DEFINED FROM EARLIER FILES THAT INCLUDE THIS
17+
* HEADER.
18+
*/
19+
namespace boost { namespace network {
20+
21+
namespace impl {
22+
template <class Tag>
23+
struct header_directive : public detail::directive_base<Tag> {
24+
typedef Tag tag;
25+
26+
explicit header_directive(
27+
std::string const & header_name,
28+
std::string const & header_value
29+
) :
30+
_header_name(header_name),
31+
_header_value(header_value)
32+
{ };
33+
34+
void operator() (basic_message<tag> & msg) const {
35+
msg.headers().insert(
36+
typename basic_message<tag>::headers_container_type::value_type(
37+
_header_name,
38+
_header_value
39+
)
40+
);
41+
};
42+
43+
private:
44+
45+
mutable std::string _header_name;
46+
mutable std::string _header_value;
47+
};
48+
}; // namespace impl
49+
50+
inline impl::header_directive<tags::default_>
51+
header(std::string const & header_name,
52+
std::string const & header_value) {
53+
return impl::header_directive<tags::default_>(header_name,
54+
header_value);
55+
};
56+
57+
};
58+
59+
};
60+
61+
#endif // __NETWORK_MESSAGE_DIRECTIVES_HEADER_HPP__
62+

boost/network/message/wrappers.hpp

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
// Copyright Dean Michael Berris 2007.
3+
// Distributed under the Boost Software License, Version 1.0.
4+
// (See accompanying file LICENSE_1_0.txt or copy at
5+
// http://www.boost.org/LICENSE_1_0.txt)
6+
7+
#ifndef __NETWORK_MESSAGE_WRAPPERS_HPP__
8+
#define __NETWORK_MESSAGE_WRAPPERS_HPP__
9+
10+
/** wrappers.hpp
11+
*
12+
* Pulls in all the wrapper header files.
13+
*/
14+
#include <boost/network/message/wrappers/headers.hpp>
15+
16+
#endif // __NETWORK_MESSAGE_WRAPPERS_HPP__
Binary file not shown.
+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
2+
// Copyright Dean Michael Berris 2007.
3+
// Distributed under the Boost Software License, Version 1.0.
4+
// (See accompanying file LICENSE_1_0.txt or copy at
5+
// http://www.boost.org/LICENSE_1_0.txt)
6+
7+
#ifndef __NETWORK_MESSAGE_WRAPPERS_HEADERS_HPP__
8+
#define __NETWORK_MESSAGE_WRAPPERS_HEADERS_HPP__
9+
10+
namespace boost { namespace network {
11+
12+
// Forward declaration
13+
template <class Message>
14+
struct headers_range ;
15+
16+
/** headers wrapper for messages.
17+
*
18+
* This exposes an interface similar to a map, indexable
19+
* using operator[] taking a string as the index and returns
20+
* a range of iterators (std::pair<iterator, iterator>)
21+
* whose keys are all equal to the index string.
22+
*/
23+
namespace impl {
24+
template <class Tag>
25+
struct headers_wrapper : public detail::wrapper_base<Tag> {
26+
typedef Tag tag;
27+
typedef basic_message<tag> message_type;
28+
typedef typename headers_range<message_type>::type range_type;
29+
30+
explicit headers_wrapper(basic_message<tag> & message_)
31+
: detail::wrapper_base<tag>(message_)
32+
{ };
33+
34+
range_type operator[] (std::string const & key) const {
35+
return _message.headers().equal_range(key);
36+
};
37+
38+
typename message_type::headers_container_type::size_type count(std::string const & key) const {
39+
return _message.headers().count(key);
40+
};
41+
42+
};
43+
}; // namespace impl
44+
45+
/// Factory method to create the right wrapper object
46+
template <class Tag, template <class> class Message>
47+
inline impl::headers_wrapper<Tag>
48+
headers(Message<Tag> & message_) {
49+
return impl::headers_wrapper<Tag>(message_);
50+
};
51+
52+
/// Template metaprogram to get the range type for a message
53+
template <class Message>
54+
struct headers_range {
55+
typedef typename
56+
std::pair<
57+
typename Message::headers_container_type::const_iterator,
58+
typename Message::headers_container_type::const_iterator>
59+
type;
60+
};
61+
62+
}; // namespace network
63+
64+
}; // namespace boost
65+
66+
#endif // __NETWORK_MESSAGE_WRAPPERS_HEADERS_HPP__
67+

0 commit comments

Comments
 (0)