Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit65f35a5

Browse files
committed
Refactored XML element outside XMPP.
1 parent770d7eb commit65f35a5

File tree

17 files changed

+339
-285
lines changed

17 files changed

+339
-285
lines changed
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
// Copyright (c) Glyn Matthews 2010.
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// (See accompanying file LICENSE_1_0.txt or copy at
4+
// http://www.boost.org/LICENSE_1_0.txt)
5+
6+
7+
#ifndef __BOOST_NETWORK_DETAIL_XML_WRAPPERS_ELEMENT_INC__
8+
#define__BOOST_NETWORK_DETAIL_XML_WRAPPERS_ELEMENT_INC__
9+
10+
11+
#include<boost/network/traits/string.hpp>
12+
#include<boost/network/traits/headers_container.hpp>
13+
#include<boost/network/detail/xml_wrappers/traits/element_children.hpp>
14+
#include<boost/network/detail/xml_wrappers/traits/parser_backend.hpp>
15+
#include<boost/network/tags.hpp>
16+
#include<boost/optional.hpp>
17+
#include<boost/range/iterator_range.hpp>
18+
#include<algorithm>
19+
#include<cassert>
20+
21+
22+
namespaceboost {
23+
namespacenetwork {
24+
namespacedetail {
25+
template<
26+
classTag
27+
>
28+
classbasic_element {
29+
30+
public:
31+
32+
structtag {};
33+
structtext {};
34+
35+
typedeftypename string<Tag>::type string_type;
36+
typedeftypename headers_container<Tag>::type headers_container_type;
37+
typedeftypename element_children<Tag>::type element_children_type;
38+
39+
basic_element() {
40+
41+
}
42+
43+
basic_element(tag,const string_type &name)
44+
: name_(name) {
45+
46+
}
47+
48+
basic_element(text,const string_type &text)
49+
: text_(text) {
50+
51+
}
52+
53+
basic_element(const basic_element &other)
54+
: name_(other.name_),
55+
attributes_(other.attributes_),
56+
children_(other.children_),
57+
text_(other.text_) {
58+
59+
}
60+
61+
basic_element &operator = (const basic_element &other) {
62+
basic_elementtmp(other);
63+
swap(tmp);
64+
return *this;
65+
}
66+
67+
~basic_element() {
68+
69+
}
70+
71+
voidswap(basic_element &other) {
72+
std::swap(name_, other.name_);
73+
std::swap(attributes_, other.attributes_);
74+
std::swap(children_, other.children_);
75+
std::swap(text_, other.text_);
76+
}
77+
78+
voidset_name(const string_type &name) {
79+
assert(!is_text());
80+
name_ = name;
81+
}
82+
83+
string_typeget_name()const {
84+
assert(is_tag());
85+
return name_;
86+
}
87+
88+
voidset_text(const string_type &text) {
89+
assert(!is_tag());
90+
text_ = text;
91+
}
92+
93+
boost::optional<string_type>get_text()const {
94+
assert(is_text());
95+
return text_.get();
96+
}
97+
98+
boolis_tag()const {
99+
return !name_.empty();
100+
}
101+
102+
boolis_text()const {
103+
returnstatic_cast<bool>(text_);
104+
}
105+
106+
voidset_attribute(const string_type &name,const string_type &value) {
107+
assert(is_tag());
108+
attributes_.insert(typenameheaders_container_type::value_type(name, value));
109+
}
110+
111+
boost::optional<string_type>get_attribute(const string_type &name)const {
112+
typename headers_container_type::const_iterator it = attributes_.find(name);
113+
if (it != attributes_.end()) {
114+
return it->second;
115+
}
116+
return boost::none;
117+
}
118+
119+
boost::iterator_range<typename headers_container_type::const_iterator>
120+
get_attributes()const {
121+
returnboost::make_iterator_range(boost::begin(attributes_),
122+
boost::end(attributes_));
123+
}
124+
125+
boost::optional<string_type>get_namespace()const {
126+
returnget_attribute("xmlns");
127+
}
128+
129+
boost::optional<string_type>get_type()const {
130+
returnget_attribute("type");
131+
}
132+
133+
boost::optional<string_type>get_lang()const {
134+
returnget_attribute("xml:lang");
135+
}
136+
137+
boost::optional<string_type>get_id()const {
138+
returnget_attribute("id");
139+
}
140+
141+
voidadd_child(basic_element<Tag> *element) {
142+
assert(is_tag());
143+
boost::shared_ptr<basic_element<Tag> >shared_element(element);
144+
children_.push_back(shared_element);
145+
}
146+
147+
boost::iterator_range<typename element_children_type::const_iterator>
148+
get_children()const {
149+
returnboost::make_iterator_range(boost::begin(children_),
150+
boost::end(children_));
151+
}
152+
153+
private:
154+
155+
// if it's a tag node
156+
string_type name_;
157+
headers_container_type attributes_;
158+
element_children_type children_;
159+
160+
// if it's a text node
161+
boost::optional<string_type> text_;
162+
163+
};
164+
165+
166+
typedef basic_element<boost::network::tags::default_> element;
167+
}// namespace detail
168+
}// namespace network
169+
}// namespace boost
170+
171+
172+
#endif// __BOOST_NETWORK_DETAIL_XML_WRAPPERS_ELEMENT_INC__
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright (c) Glyn Matthews 2010.
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// (See accompanying file LICENSE_1_0.txt or copy at
4+
// http://www.boost.org/LICENSE_1_0.txt)
5+
6+
7+
#ifndef __BOOST_NETWORK_DETAIL_XML_WRAPPERS_ELEMENT_IO_INC__
8+
#define__BOOST_NETWORK_DETAIL_XML_WRAPPERS_ELEMENT_IO_INC__
9+
10+
11+
#include<boost/network/detail/xml_wrappers/element.hpp>
12+
#include<ostream>
13+
14+
15+
namespaceboost {
16+
namespacenetwork {
17+
namespacedetail {
18+
template<
19+
classTag
20+
>
21+
std::ostream &operator << (std::ostream &os,
22+
const basic_element<Tag> &element) {
23+
if (element.is_tag()) {
24+
os <<"<" << element.get_name();
25+
boost::iterator_range<typename basic_element<Tag>::headers_container_type::const_iterator>
26+
attributes(element.get_attributes());
27+
28+
typename basic_element<Tag>::headers_container_type::const_iterator
29+
attr_it(boost::begin(attributes)),
30+
attr_end(boost::end(attributes));
31+
for (; attr_it != attr_end; ++attr_it) {
32+
os <<"" << attr_it->first <<"=\"" << attr_it->second <<"\"";
33+
}
34+
os <<">";
35+
36+
boost::iterator_range<typename basic_element<Tag>::element_children_type::const_iterator>
37+
children(element.get_children());
38+
39+
typename basic_element<Tag>::element_children_type::const_iterator
40+
child_it(boost::begin(children)),
41+
child_end(boost::end(children));
42+
for (; child_it != child_end; ++child_it) {
43+
os << **child_it;
44+
}
45+
os <<"</" << element.get_name() <<">";
46+
}
47+
else {
48+
os << element.get_text().get();
49+
}
50+
return os;
51+
}
52+
}// namespace detail
53+
}// namespace network
54+
}// namespace boost
55+
56+
57+
#endif// __BOOST_NETWORK_DETAIL_XML_WRAPPERS_ELEMENT_IO_INC__

‎boost/network/protocol/xmpp/parser_backends/expat/element_parser.hpp‎renamed to ‎boost/network/detail/xml_wrappers/parser_backends/expat/element_parser.hpp‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
// http://www.boost.org/LICENSE_1_0.txt)
55

66

7-
#ifndef__BOOST_NETWORK_PROTOCOL_XMPP_PARSER_BACKENDS_EXPAT_ELEMENT_PARSER_INC__
8-
#define__BOOST_NETWORK_PROTOCOL_XMPP_PARSER_BACKENDS_EXPAT_ELEMENT_PARSER_INC__
7+
#ifndef__BOOST_NETWORK_DETAIL_XML_WRAPPERS_PARSER_BACKENDS_EXPAT_ELEMENT_PARSER_INC__
8+
#define__BOOST_NETWORK_DETAIL_XML_WRAPPERS_PARSER_BACKENDS_EXPAT_ELEMENT_PARSER_INC__
99

1010

1111
#include<boost/network/traits/string.hpp>
12-
#include<boost/network/protocol/xmpp/element.hpp>
12+
#include<boost/network/detail/xml_wrappers/element.hpp>
1313
#include<expat.h>
1414
#include<cstring>
1515

1616

1717
namespaceboost {
1818
namespacenetwork {
19-
namespacexmpp {
19+
namespacedetail {
2020
template<
2121
classTag
2222
>
@@ -118,9 +118,9 @@ class basic_expat_element_parser {
118118
int depth_;
119119

120120
};
121-
}// namespacexmpp
121+
}// namespacedetail
122122
}// namespace network
123123
}// namespace boost
124124

125125

126-
#endif//__BOOST_NETWORK_PROTOCOL_XMPP_PARSER_BACKENDS_EXPAT_ELEMENT_PARSER_INC__
126+
#endif//__BOOST_NETWORK_DETAIL_XML_WRAPPERS_PARSER_BACKENDS_EXPAT_ELEMENT_PARSER_INC__

‎boost/network/protocol/xmpp/parser_backends/expat/stanza_parser.hpp‎renamed to ‎boost/network/detail/xml_wrappers/parser_backends/expat/stanza_parser.hpp‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
// http://www.boost.org/LICENSE_1_0.txt)
55

66

7-
#ifndef__BOOST_NETWORK_PROTOCOL_XMPP_PARSER_BACKENDS_EXPAT_STANZA_PARSER_INC__
8-
#define__BOOST_NETWORK_PROTOCOL_XMPP_PARSER_BACKENDS_EXPAT_STANZA_PARSER_INC__
7+
#ifndef__BOOST_NETWORK_DETAIL_XML_WRAPPERS_PARSER_BACKENDS_EXPAT_STANZA_PARSER_INC__
8+
#define__BOOST_NETWORK_DETAIL_XML_WRAPPERS_PARSER_BACKENDS_EXPAT_STANZA_PARSER_INC__
99

1010

1111
#include<boost/network/traits/string.hpp>
@@ -16,7 +16,7 @@
1616

1717
namespaceboost {
1818
namespacenetwork {
19-
namespacexmpp {
19+
namespacedetail {
2020
template<
2121
classTag
2222
>
@@ -116,9 +116,9 @@ class basic_expat_stanza_parser {
116116
int depth_;
117117

118118
};
119-
}// namespacexmpp
119+
}// namespacedetail
120120
}// namespace network
121121
}// namespace boost
122122

123123

124-
#endif//__BOOST_NETWORK_PROTOCOL_XMPP_PARSER_BACKENDS_EXPAT_STANZA_PARSER_INC__
124+
#endif//__BOOST_NETWORK_DETAIL_XML_WRAPPERS_PARSER_BACKENDS_EXPAT_STANZA_PARSER_INC__

‎boost/network/protocol/xmpp/parser_backends/expat_parser.hpp‎renamed to ‎boost/network/detail/xml_wrappers/parser_backends/expat_parser.hpp‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
// http://www.boost.org/LICENSE_1_0.txt)
55

66

7-
#ifndef__BOOST_NETWORK_PROTOCOL_XMPP_PARSER_BACKENDS_EXPAT_PARSER_INC__
8-
#define__BOOST_NETWORK_PROTOCOL_XMPP_PARSER_BACKENDS_EXPAT_PARSER_INC__
7+
#ifndef__BOOST_NETWORK_DETAIL_XML_WRAPPERS_PARSER_BACKENDS_EXPAT_PARSER_INC__
8+
#define__BOOST_NETWORK_DETAIL_XML_WRAPPERS_PARSER_BACKENDS_EXPAT_PARSER_INC__
99

1010

11-
#include<boost/network/protocol/xmpp/parser_backends/expat/element_parser.hpp>
11+
#include<boost/network/detail/xml_wrappers/parser_backends/expat/element_parser.hpp>
1212

1313

1414
namespaceboost {
1515
namespacenetwork {
16-
namespacexmpp {
16+
namespacedetail {
1717
template<
1818
classTag
1919
>
@@ -23,9 +23,9 @@ class basic_expat_parser
2323
public:
2424

2525
};
26-
}// namespacexmpp
26+
}// namespacedetail
2727
}// namespace network
2828
}// namespace boost
2929

3030

31-
#endif//__BOOST_NETWORK_PROTOCOL_XMPP_PARSER_BACKENDS_EXPAT_PARSER_INC__
31+
#endif//__BOOST_NETWORK_DETAIL_XML_WRAPPERS_PARSER_BACKENDS_EXPAT_PARSER_INC__

‎boost/network/protocol/xmpp/parser_backends/libxml2/element_parser.hpp‎renamed to ‎boost/network/detail/xml_wrappers/parser_backends/libxml2/element_parser.hpp‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
// http://www.boost.org/LICENSE_1_0.txt)
55

66

7-
#ifndef__BOOST_NETWORK_PROTOCOL_XMPP_PARSER_BACKENDS_LIBXML2_ELEMENT_PARSER_INC__
8-
#define__BOOST_NETWORK_PROTOCOL_XMPP_PARSER_BACKENDS_LIBXML2_ELEMENT_PARSER_INC__
7+
#ifndef__BOOST_NETWORK_DETAIL_XML_WRAPPERS_PARSER_BACKENDS_LIBXML2_ELEMENT_PARSER_INC__
8+
#define__BOOST_NETWORK_DETAIL_XML_WRAPPERS_PARSER_BACKENDS_LIBXML2_ELEMENT_PARSER_INC__
99

1010

1111
#include<boost/network/traits/string.hpp>
12-
#include<boost/network/protocol/xmpp/element.hpp>
12+
#include<boost/network/detail/xml_wrappers/element.hpp>
1313
#include<libxml/parser.h>
1414
#include<libxml/tree.h>
1515

1616

1717
namespaceboost {
1818
namespacenetwork {
19-
namespacexmpp {
19+
namespacedetail {
2020
template<
2121
classTag
2222
>
@@ -121,9 +121,9 @@ class basic_libxml2_element_parser {
121121
int depth_;
122122

123123
};
124-
}// namespacexmpp
124+
}// namespacedetail
125125
}// namespace network
126126
}// namespace boost
127127

128128

129-
#endif//__BOOST_NETWORK_PROTOCOL_XMPP_PARSER_BACKENDS_LIBXML2_ELEMENT_PARSER_INC__
129+
#endif//__BOOST_NETWORK_DETAIL_XML_WRAPPERS_PARSER_BACKENDS_LIBXML2_ELEMENT_PARSER_INC__

‎boost/network/protocol/xmpp/parser_backends/libxml2/stanza_parser.hpp‎renamed to ‎boost/network/detail/xml_wrappers/parser_backends/libxml2/stanza_parser.hpp‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
// http://www.boost.org/LICENSE_1_0.txt)
55

66

7-
#ifndef__BOOST_NETWORK_PROTOCOL_XMPP_PARSER_BACKENDS_LIBXML2_STANZA_PARSER_INC__
8-
#define__BOOST_NETWORK_PROTOCOL_XMPP_PARSER_BACKENDS_LIBXML2_STANZA_PARSER_INC__
7+
#ifndef__BOOST_NETWORK_DETAIL_XML_WRAPPERS_PARSER_BACKENDS_LIBXML2_STANZA_PARSER_INC__
8+
#define__BOOST_NETWORK_DETAIL_XML_WRAPPERS_PARSER_BACKENDS_LIBXML2_STANZA_PARSER_INC__
99

1010

1111
#include<boost/network/traits/string.hpp>
@@ -16,7 +16,7 @@
1616

1717
namespaceboost {
1818
namespacenetwork {
19-
namespacexmpp {
19+
namespacedetail {
2020
template<
2121
classTag
2222
>
@@ -119,9 +119,9 @@ class basic_libxml2_stanza_parser {
119119
int depth_;
120120

121121
};
122-
}// namespacexmpp
122+
}// namespacedetail
123123
}// namespace network
124124
}// namespace boost
125125

126126

127-
#endif//__BOOST_NETWORK_PROTOCOL_XMPP_PARSER_BACKENDS_LIBXML2_STANZA_PARSER_INC__
127+
#endif//__BOOST_NETWORK_DETAIL_XML_WRAPPERS_PARSER_BACKENDS_LIBXML2_STANZA_PARSER_INC__

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp