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
|
#include "FWCore/Utilities/interface/OftenEmptyCString.h"
#include <cstring>
#include <utility>
namespace edm {
OftenEmptyCString::OftenEmptyCString(const char* iValue) {
if (iValue == nullptr or iValue[0] == '\0') {
m_value = emptyString();
} else {
auto l = strlen(iValue);
auto temp = new char[l + 1];
strncpy(temp, iValue, l + 1);
m_value = temp;
}
}
void OftenEmptyCString::deleteIfNotEmpty() {
if (m_value != emptyString()) {
delete[] m_value;
}
}
OftenEmptyCString::~OftenEmptyCString() { deleteIfNotEmpty(); }
OftenEmptyCString::OftenEmptyCString(OftenEmptyCString const& iOther) : OftenEmptyCString(iOther.m_value) {}
OftenEmptyCString::OftenEmptyCString(OftenEmptyCString&& iOther) noexcept : m_value(iOther.m_value) {
iOther.m_value = nullptr;
}
OftenEmptyCString& OftenEmptyCString::operator=(OftenEmptyCString const& iOther) {
if (iOther.m_value != m_value) {
OftenEmptyCString temp{iOther};
*this = std::move(temp);
}
return *this;
}
OftenEmptyCString& OftenEmptyCString::operator=(OftenEmptyCString&& iOther) noexcept {
if (iOther.m_value != m_value) {
deleteIfNotEmpty();
m_value = iOther.m_value;
iOther.m_value = nullptr;
}
return *this;
}
const char* OftenEmptyCString::emptyString() {
constexpr static const char* s_empty = "";
return s_empty;
}
} // namespace edm
|