3030
3131Point::Point (const String & measurement)
3232{
33- _measurement = escapeKey (measurement, false );
34- _timestamp = nullptr ;
35- _tsWritePrecision = WritePrecision::NoTime;
33+ _data = std::make_shared<Data>(escapeKey (measurement, false ));
3634}
3735
3836Point::~Point () {
39- delete [] _measurement;
40- delete [] _timestamp;
37+ }
38+
39+ Point::Data::Data (char * measurement) {
40+ this ->measurement = measurement;
41+ timestamp = nullptr ;
42+ tsWritePrecision = WritePrecision::NoTime;
43+ }
44+
45+ Point::Data::~Data () {
46+ delete [] measurement;
47+ delete [] timestamp;
48+ }
49+
50+ Point::Point (const Point &other) {
51+ *this = other;
52+ }
53+
54+ Point& Point::operator =(const Point &other) {
55+ if (this != &other) {
56+ this ->_data = other._data ;
57+ }
58+ return *this ;
4159}
4260
4361void Point::addTag (const String &name, String value) {
44- if (_tags .length () > 0 ) {
45- _tags += ' ,' ;
46- }
47- char *s = escapeKey (name);
48- _tags += s;
49- delete [] s;
50- _tags += ' =' ;
51- s = escapeKey (value);
52- _tags += s;
53- delete [] s;
62+ if (_data-> tags .length () > 0 ) {
63+ _data-> tags += ' ,' ;
64+ }
65+ char *s = escapeKey (name);
66+ _data-> tags += s;
67+ delete [] s;
68+ _data-> tags += ' =' ;
69+ s = escapeKey (value);
70+ _data-> tags += s;
71+ delete [] s;
5472}
5573
5674void Point::addField (const String &name, long long value) {
@@ -114,14 +132,14 @@ void Point::addField(const String &name, const String &value) {
114132}
115133
116134void Point::putField (const String &name, const String &value) {
117- if (_fields .length () > 0 ) {
118- _fields += ' ,' ;
135+ if (_data-> fields .length () > 0 ) {
136+ _data-> fields += ' ,' ;
119137 }
120138 char *s = escapeKey (name);
121- _fields += s;
139+ _data-> fields += s;
122140 delete [] s;
123- _fields += ' =' ;
124- _fields += value;
141+ _data-> fields += ' =' ;
142+ _data-> fields += value;
125143}
126144
127145String Point::toLineProtocol (const String &includeTags) const {
@@ -130,23 +148,23 @@ String Point::toLineProtocol(const String &includeTags) const {
130148
131149String Point::createLineProtocol (const String &incTags) const {
132150 String line;
133- line.reserve (strLen (_measurement ) + 1 + incTags.length () + 1 + _tags .length () + 1 + _fields .length () + 1 + strLen (_timestamp ));
134- line += _measurement ;
151+ line.reserve (strLen (_data-> measurement ) + 1 + incTags.length () + 1 + _data-> tags .length () + 1 + _data-> fields .length () + 1 + strLen (_data-> timestamp ));
152+ line += _data-> measurement ;
135153 if (incTags.length ()>0 ) {
136154 line += " ," ;
137155 line += incTags;
138156 }
139157 if (hasTags ()) {
140158 line += " ," ;
141- line += _tags ;
159+ line += _data-> tags ;
142160 }
143161 if (hasFields ()) {
144162 line += " " ;
145- line += _fields ;
163+ line += _data-> fields ;
146164 }
147165 if (hasTime ()) {
148166 line += " " ;
149- line += _timestamp ;
167+ line += _data-> timestamp ;
150168 }
151169 return line;
152170 }
@@ -172,7 +190,7 @@ void Point::setTime(WritePrecision precision) {
172190 setTime ((char *)nullptr );
173191 break ;
174192 }
175- _tsWritePrecision = precision;
193+ _data-> tsWritePrecision = precision;
176194}
177195
178196void Point::setTime (unsigned long long timestamp) {
@@ -188,16 +206,16 @@ void Point::setTime(const char *timestamp) {
188206}
189207
190208void Point::setTime (char *timestamp) {
191- delete [] _timestamp ;
192- _timestamp = timestamp;
209+ delete [] _data-> timestamp ;
210+ _data-> timestamp = timestamp;
193211}
194212
195213void Point::clearFields () {
196- _fields = (char *)nullptr ;
197- delete [] _timestamp ;
198- _timestamp = nullptr ;
214+ _data-> fields = (char *)nullptr ;
215+ delete [] _data-> timestamp ;
216+ _data-> timestamp = nullptr ;
199217}
200218
201219void Point:: clearTags() {
202- _tags = (char *)nullptr ;
220+ _data-> tags = (char *)nullptr ;
203221}
0 commit comments