-
Notifications
You must be signed in to change notification settings - Fork 144
/
Copy pathopennurbs_testclass.cpp
131 lines (113 loc) · 3.04 KB
/
opennurbs_testclass.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include "opennurbs.h"
#include "opennurbs_testclass.h"
#if !defined(OPENNURBS_NO_STD_MUTEX)
ON__UINT64 ON_TestClass::CurrentCount()
{
ON__UINT64 constructed_count = 0;
ON__UINT64 current_count = 0;
ON_TestClass::GetCurrentAndConstructedCount(constructed_count, current_count);
return current_count;
}
ON__UINT64 ON_TestClass::ConstructedCount()
{
ON__UINT64 constructed_count = 0;
ON__UINT64 current_count = 0;
ON_TestClass::GetCurrentAndConstructedCount(constructed_count, current_count);
return constructed_count;
}
ON__UINT64 ON_TestClass::DestructedCount()
{
ON__UINT64 constructed_count = 0;
ON__UINT64 current_count = 0;
ON_TestClass::GetCurrentAndConstructedCount(constructed_count, current_count);
return constructed_count - current_count;
}
ON__UINT64 ON_TestClass::Internal_CounterHelper(
int task, // 0 = construct, 1 = destruct, 2 = query
ON__UINT64* constructed_count,
ON__UINT64* current_count
)
{
std::lock_guard<std::mutex> lock(ON_TestClass::internal_counter_mutex);
ON__UINT64 rc = 0;
if (0 == task)
{
++ON_TestClass::internal_PopulationCounter;
rc = ++ON_TestClass::internal_CtorSerialNumberGenerator;
}
else if (1 == task)
{
--ON_TestClass::internal_PopulationCounter;
}
else
{
*constructed_count = ON_TestClass::internal_CtorSerialNumberGenerator;
*current_count = ON_TestClass::internal_PopulationCounter;
}
return rc;
}
void ON_TestClass::GetCurrentAndConstructedCount(
ON__UINT64& constructed_count,
ON__UINT64& current_count
)
{
ON_TestClass::Internal_CounterHelper(2, &constructed_count, ¤t_count);
}
ON_TestClass::ON_TestClass()
: SerialNumber(ON_TestClass::Internal_CounterHelper(0,nullptr,nullptr))
, CopiedFrom(0)
, ConstructedAt((ON__UINT64)time(nullptr))
{}
ON_TestClass::~ON_TestClass()
{
ON_TestClass::Internal_CounterHelper(1, nullptr, nullptr);
}
ON_TestClass::ON_TestClass(const ON_TestClass& src)
: SerialNumber(ON_TestClass::Internal_CounterHelper(0,nullptr,nullptr))
, CopiedFrom(src.SerialNumber)
, ConstructedAt((ON__UINT64)time(nullptr))
, m_string(src.Value())
{}
ON_TestClass& ON_TestClass::operator=(const ON_TestClass& src)
{
if (this != &src)
{
SetValue(src.Value());
}
return *this;
}
const ON_wString ON_TestClass::Value() const
{
std::lock_guard<std::mutex> lock(m_local_mutex);
return m_string;
}
void ON_TestClass::SetValue(
const ON_wString s
)
{
std::lock_guard<std::mutex> lock(m_local_mutex);
m_string = s;
}
void ON_TestClass::Dump(class ON_TextLog& text_log) const
{
const ON_wString s(ToString());
text_log.PrintString(s);
text_log.PrintNewLine();
}
const ON_wString ON_TestClass::ToString() const
{
const ON_wString v = Value();
const ON_wString ymdhms = ON_wString::FromSecondsSinceJanuaryFirst1970(
ConstructedAt,
ON_DateFormat::YearMonthDay,
ON_TimeFormat::HourMinuteSecond24,
0,0,0
);
return ON_wString::FormatToString(
L"ON_TestClass[%llu] @ %s \"%ls\"",
SerialNumber,
static_cast<const wchar_t*>(ymdhms),
static_cast<const wchar_t*>(v)
);
}
#endif