24 #ifndef Om_Macro_Precompilation_
26 #include "boost/test/unit_test.hpp"
32 BOOST_AUTO_TEST_SUITE(OwnerTest)
37 public DefaultCopyable<TestValue>,
42 explicit TestValue(
int const theNumber):
43 thisNumber(theNumber) {}
45 bool operator ==(TestValue
const theTestValue)
const {
46 return this->thisNumber == theTestValue.thisNumber;
55 BOOST_AUTO_TEST_CASE(LazinessTest) {
56 Owner<TestValue> theFirst(
57 std::auto_ptr<TestValue>(
63 Owner<TestValue>
const & theConstFirst = theFirst;
64 TestValue
const & theFirstValue = *theConstFirst;
66 Owner<TestValue> theSecond(theFirst);
68 Owner<TestValue>
const & theConstSecond = theSecond;
69 TestValue
const & theSecondValue = *theConstSecond;
77 BOOST_AUTO_TEST_CASE(CopyTest) {
78 Owner<TestValue> theFirst(
79 std::auto_ptr<TestValue>(
85 TestValue & theFirstValue = *theFirst;
88 theFirstValue.thisNumber
90 theFirstValue.thisNumber = 2;
93 theFirstValue.thisNumber
96 Owner<TestValue> theSecond(theFirst);
98 TestValue & theSecondValue = *theSecond;
101 theFirstValue.thisNumber
105 theSecondValue.thisNumber
108 theSecondValue.thisNumber = 3;
109 theFirstValue.thisNumber = 4;
111 Owner<TestValue> theThird(theFirst);
112 Owner<TestValue> theFourth(theThird);
114 TestValue & theThirdValue = *theThird;
115 Owner<TestValue>
const & theConstFourth = theFourth;
116 TestValue
const & theFourthValue = *theConstFourth;
119 theFirstValue.thisNumber
123 theSecondValue.thisNumber
127 theThirdValue.thisNumber
131 theFourthValue.thisNumber
134 theThirdValue.thisNumber = 5;
137 theFirstValue.thisNumber
141 theSecondValue.thisNumber
145 theThirdValue.thisNumber
149 theFourthValue.thisNumber
153 BOOST_AUTO_TEST_SUITE_END()
161 #ifndef Om_Macro_Precompilation_
163 #include "boost/swap.hpp"
170 template <typename ThisValue>
178 inline Type_::Owner():
183 inline Type_::Owner(Owner
const & theOwner):
186 if (theOwner.thisWasExposed) {
187 assert(theOwner.thisValue);
188 this->thisValue.reset(
189 Copy(*theOwner.thisValue).release()
192 this->thisValue = theOwner.thisValue;
197 template <
typename TheValue>
199 std::auto_ptr<TheValue> theValue
207 inline Type_ & Type_::operator =(Owner theOwner) {
208 this->Swap(theOwner);
213 inline ThisValue & Type_::operator *() {
214 assert(this->thisValue);
216 1 < this->thisValue->GetOwnerCount()
218 this->thisValue.reset(
219 Copy(*this->thisValue).release()
221 assert(this->thisValue);
223 this->thisWasExposed =
true;
224 return *this->thisValue;
228 inline ThisValue
const & Type_::operator *()
const {
229 assert(this->thisValue);
230 return *this->thisValue;
234 inline ThisValue * Type_::operator ->() {
239 inline ThisValue
const * Type_::operator ->()
const {
244 inline bool Type_::operator !()
const {
245 return !this->thisValue;
249 inline Type_::operator Boolean()
const {
252 &Owner::UncomparableBoolean :
258 inline void Type_::Clear() {
259 this->thisValue.reset();
260 this->thisWasExposed =
false;
264 ThisValue * Type_::GetValue() {
273 ThisValue
const * Type_::GetValue()
const {
274 return this->thisValue.get();
278 bool Type_::IsEmpty()
const {
279 return !this->thisValue;
283 template <
typename TheValue>
284 inline void Type_::SetValue(
285 std::auto_ptr<TheValue> theValue
287 this->thisValue.reset(
290 this->thisWasExposed =
false;
294 inline void Type_::Swap(Owner & theOwner) {
295 this->thisValue.swap(theOwner.thisValue);
297 this->thisWasExposed,
298 theOwner.thisWasExposed
305 inline void Type_::UncomparableBoolean()
const {}
312 template <
typename TheValue>
317 theFirst.
Swap(theSecond);
A polymorphic object with value semantics.
bool operator==(Source::Source< TheItem > const &, Source::Source< TheItem > const &)
std::auto_ptr< TheCopyable > Copy(TheCopyable const &)
void swap(Om::Language::Expression &, Om::Language::Expression &)