Stroika Library 3.0d18
 
Loading...
Searching...
No Matches
ArchtypeClasses.cpp
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4
5#include "Stroika/Foundation/StroikaPreComp.h"
6
7#include "Stroika/Foundation/Containers/Common.h"
9#include "Stroika/Foundation/Debug/Debugger.h"
10
11#include "TestHarness.h"
12
13#include "ArchtypeClasses.h"
14
16
17/*
18 ********************************************************************************
19 ******************** OnlyCopyableMoveableAndTotallyOrdered *********************
20 ********************************************************************************
21 */
22namespace {
23 constexpr int kKnownGoodBitPatternValue_ = 0x0BADBEEF;
24}
25
26OnlyCopyableMoveableAndTotallyOrdered::OnlyCopyableMoveableAndTotallyOrdered (size_t v)
27 : fValue_{v}
28 , fConstructed_{kKnownGoodBitPatternValue_}
29{
30 ++sTotalLiveObjects_;
31}
32
33OnlyCopyableMoveableAndTotallyOrdered::OnlyCopyableMoveableAndTotallyOrdered (OnlyCopyableMoveableAndTotallyOrdered&& src) noexcept
34 : fValue_{src.fValue_}
35 , fConstructed_{kKnownGoodBitPatternValue_}
36{
37 ++sTotalLiveObjects_;
38 VerifyTestResult (src.fConstructed_ == kKnownGoodBitPatternValue_);
39}
40
41OnlyCopyableMoveableAndTotallyOrdered::OnlyCopyableMoveableAndTotallyOrdered (const OnlyCopyableMoveableAndTotallyOrdered& src) noexcept
42 : fValue_{src.fValue_}
43 , fConstructed_{kKnownGoodBitPatternValue_}
44{
45 ++sTotalLiveObjects_;
46 VerifyTestResult (src.fConstructed_ == kKnownGoodBitPatternValue_);
47}
48
49OnlyCopyableMoveableAndTotallyOrdered::~OnlyCopyableMoveableAndTotallyOrdered ()
50{
51 VerifyTestResult (fConstructed_ == kKnownGoodBitPatternValue_);
52 VerifyTestResult (sTotalLiveObjects_ != 0);
53 --sTotalLiveObjects_;
54 fConstructed_ = ~kKnownGoodBitPatternValue_;
55 VerifyTestResult (fConstructed_ != kKnownGoodBitPatternValue_);
56}
57
58size_t OnlyCopyableMoveableAndTotallyOrdered::GetTotalLiveCount ()
59{
60 return sTotalLiveObjects_;
61}
62
63OnlyCopyableMoveableAndTotallyOrdered OnlyCopyableMoveableAndTotallyOrdered::operator+ (const OnlyCopyableMoveableAndTotallyOrdered& rhs) const
64{
65 return OnlyCopyableMoveableAndTotallyOrdered (fValue_ + rhs.fValue_);
66}
67
68OnlyCopyableMoveableAndTotallyOrdered::operator size_t () const
69{
70 VerifyTestResult (fConstructed_ == kKnownGoodBitPatternValue_);
71 return fValue_;
72}
73
74bool OnlyCopyableMoveableAndTotallyOrdered::operator== (const OnlyCopyableMoveableAndTotallyOrdered& rhs) const
75{
76 VerifyTestResult (fConstructed_ == kKnownGoodBitPatternValue_);
77 VerifyTestResult (rhs.fConstructed_ == kKnownGoodBitPatternValue_);
78 return fValue_ == rhs.fValue_;
79}
80
81auto OnlyCopyableMoveableAndTotallyOrdered::operator<=> (const OnlyCopyableMoveableAndTotallyOrdered& rhs) const -> strong_ordering
82{
83 VerifyTestResult (fConstructed_ == kKnownGoodBitPatternValue_);
84 VerifyTestResult (rhs.fConstructed_ == kKnownGoodBitPatternValue_);
85 return fValue_ <=> rhs.fValue_;
86}
87
88/*
89 ********************************************************************************
90 ************************* OnlyCopyableMoveable *********************************
91 ********************************************************************************
92 */
93OnlyCopyableMoveable::OnlyCopyableMoveable (size_t v)
94 : fValue_{v}
95 , fConstructed_{kKnownGoodBitPatternValue_}
96{
97 ++sTotalLiveObjects_;
98}
99
100OnlyCopyableMoveable::OnlyCopyableMoveable (OnlyCopyableMoveable&& src) noexcept
101 : fValue_{src.fValue_}
102 , fConstructed_{kKnownGoodBitPatternValue_}
103{
104 ++sTotalLiveObjects_;
105 VerifyTestResult (src.fConstructed_ == kKnownGoodBitPatternValue_);
106}
107
108OnlyCopyableMoveable::OnlyCopyableMoveable (const OnlyCopyableMoveable& src) noexcept
109 : fValue_{src.fValue_}
110 , fConstructed_{kKnownGoodBitPatternValue_}
111{
112 ++sTotalLiveObjects_;
113 VerifyTestResult (src.fConstructed_ == kKnownGoodBitPatternValue_);
114}
115
116OnlyCopyableMoveable::~OnlyCopyableMoveable ()
117{
118 VerifyTestResult (fConstructed_ == kKnownGoodBitPatternValue_);
119 VerifyTestResult (sTotalLiveObjects_ != 0);
120 --sTotalLiveObjects_;
121 fConstructed_ = ~kKnownGoodBitPatternValue_;
122 VerifyTestResult (fConstructed_ != kKnownGoodBitPatternValue_);
123}
124
125OnlyCopyableMoveable::operator size_t () const
126{
127 VerifyTestResult (fConstructed_ == kKnownGoodBitPatternValue_);
128 return fValue_;
129}
130
131size_t OnlyCopyableMoveable::GetTotalLiveCount ()
132{
133 return sTotalLiveObjects_;
134}
135
136OnlyCopyableMoveable OnlyCopyableMoveable::operator+ (const OnlyCopyableMoveable& rhs) const
137{
138 return OnlyCopyableMoveable{fValue_ + rhs.fValue_};
139}