Om
container_back_sink.cpp
Go to the documentation of this file.
1 
15 #ifndef Om_Sink_ContainerBackSink_
16 
18 
19  #ifdef Om_Macro_Test_
20 
21  #ifndef Om_Macro_Precompilation_
22 
23  #include "boost/test/unit_test.hpp"
24 
25  #endif
26 
27 namespace Om {
28 
29  namespace Sink {
30 
31  BOOST_AUTO_TEST_SUITE(ContainerBackSinkTest)
32 
33  BOOST_AUTO_TEST_CASE(GeneralTest) {
34  std::string theSinkString("01");
35  ContainerBackSink<
36  char const,
37  std::string
38  > theSink(theSinkString);
39 
40  *theSink++ = '2';
41  BOOST_CHECK_EQUAL(
42  "012",
43  theSinkString
44  );
45  *++theSink = '3';
46  BOOST_CHECK_EQUAL(
47  "0123",
48  theSinkString
49  );
50  *theSink = '4';
51  BOOST_CHECK_EQUAL(
52  "01234",
53  theSinkString
54  );
55  }
56 
57  BOOST_AUTO_TEST_SUITE_END()
58 
59  }
60 
61 }
62 
63  #endif
64 
65 #else
66 
67 // MARK: - Om::Sink::ContainerBackSink
68 
69  #define Template_ \
70  template < \
71  typename ThisItem, \
72  typename ThisContainer \
73  >
74 
75  #define Type_ \
76  Om::Sink::ContainerBackSink< \
77  ThisItem, \
78  ThisContainer \
79  >
80 
81 // MARK: public (non-static)
82 
83 Template_
84 inline Type_::ContainerBackSink(ThisContainer & theContainer):
85 thisContainer(theContainer) {}
86 
87 Template_
88 inline Type_ & Type_::operator =(ContainerBackSink theContainerBackSink) {
89  this->Swap(theContainerBackSink);
90  return *this;
91 }
92 
93 Template_
94 inline void Type_::Push(ThisItem & thisItem) {
95  this->thisContainer.push_back(thisItem);
96 }
97 
98 Template_
99 inline void Type_::Swap(ContainerBackSink & theContainerBackSink) {
100  boost::swap(
101  this->thisContainer,
102  theContainerBackSink.thisContainer
103  );
104 }
105 
106  #undef Type_
107  #undef Template_
108 
109 // MARK: - boost::
110 
111 template <
112  typename TheItem,
113  typename TheContainer
114 >
115 inline void boost::swap(
117  TheItem,
118  TheContainer
119  > & theFirst,
121  TheItem,
122  TheContainer
123  > & theSecond
124 ) {
125  theFirst.Swap(theSecond);
126 }
127 
128 #endif
A Sink adapter for a container; pushes items into the back.
The Om library.
Definition: code_point.hpp:26
void swap(Om::Language::Expression &, Om::Language::Expression &)