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+ Serial.printf (" Point::operator= of %x\n " , this );
57+ this ->_data = other._data ;
58+ }
59+ return *this ;
4160}
4261
4362void 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;
63+ if (_data-> tags .length () > 0 ) {
64+ _data-> tags += ' ,' ;
65+ }
66+ char *s = escapeKey (name);
67+ _data-> tags += s;
68+ delete [] s;
69+ _data-> tags += ' =' ;
70+ s = escapeKey (value);
71+ _data-> tags += s;
72+ delete [] s;
5473}
5574
5675void Point::addField (const String &name, long long value) {
@@ -114,14 +133,14 @@ void Point::addField(const String &name, const String &value) {
114133}
115134
116135void Point::putField (const String &name, const String &value) {
117- if (_fields .length () > 0 ) {
118- _fields += ' ,' ;
136+ if (_data-> fields .length () > 0 ) {
137+ _data-> fields += ' ,' ;
119138 }
120139 char *s = escapeKey (name);
121- _fields += s;
140+ _data-> fields += s;
122141 delete [] s;
123- _fields += ' =' ;
124- _fields += value;
142+ _data-> fields += ' =' ;
143+ _data-> fields += value;
125144}
126145
127146String Point::toLineProtocol (const String &includeTags) const {
@@ -130,23 +149,23 @@ String Point::toLineProtocol(const String &includeTags) const {
130149
131150String Point::createLineProtocol (const String &incTags) const {
132151 String line;
133- line.reserve (strLen (_measurement ) + 1 + incTags.length () + 1 + _tags .length () + 1 + _fields .length () + 1 + strLen (_timestamp ));
134- line += _measurement ;
152+ line.reserve (strLen (_data-> measurement ) + 1 + incTags.length () + 1 + _data-> tags .length () + 1 + _data-> fields .length () + 1 + strLen (_data-> timestamp ));
153+ line += _data-> measurement ;
135154 if (incTags.length ()>0 ) {
136155 line += " ," ;
137156 line += incTags;
138157 }
139158 if (hasTags ()) {
140159 line += " ," ;
141- line += _tags ;
160+ line += _data-> tags ;
142161 }
143162 if (hasFields ()) {
144163 line += " " ;
145- line += _fields ;
164+ line += _data-> fields ;
146165 }
147166 if (hasTime ()) {
148167 line += " " ;
149- line += _timestamp ;
168+ line += _data-> timestamp ;
150169 }
151170 return line;
152171 }
@@ -172,7 +191,7 @@ void Point::setTime(WritePrecision precision) {
172191 setTime ((char *)nullptr );
173192 break ;
174193 }
175- _tsWritePrecision = precision;
194+ _data-> tsWritePrecision = precision;
176195}
177196
178197void Point::setTime (unsigned long long timestamp) {
@@ -188,16 +207,16 @@ void Point::setTime(const char *timestamp) {
188207}
189208
190209void Point::setTime (char *timestamp) {
191- delete [] _timestamp ;
192- _timestamp = timestamp;
210+ delete [] _data-> timestamp ;
211+ _data-> timestamp = timestamp;
193212}
194213
195214void Point::clearFields () {
196- _fields = (char *)nullptr ;
197- delete [] _timestamp ;
198- _timestamp = nullptr ;
215+ _data-> fields = (char *)nullptr ;
216+ delete [] _data-> timestamp ;
217+ _data-> timestamp = nullptr ;
199218}
200219
201220void Point:: clearTags() {
202- _tags = (char *)nullptr ;
221+ _data-> tags = (char *)nullptr ;
203222}
0 commit comments