Skip to content

Commit 0eff9f8

Browse files
committed
Refactor PixelDmx to use PixelOutputType by value
Replaces the output_type_ pointer with a PixelOutputType instance, removing dynamic allocation and manual deletion. Updates all member accesses to use the object directly, simplifying memory management and improving code safety.
1 parent 36c6eae commit 0eff9f8

File tree

1 file changed

+20
-31
lines changed

1 file changed

+20
-31
lines changed

lib-pixeldmx/include/pixeldmx.h

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,6 @@ class PixelDmx final : public PixelDmxConfiguration
8585
{
8686
DEBUG_ENTRY
8787

88-
delete output_type_;
89-
output_type_ = nullptr;
90-
9188
DEBUG_EXIT
9289
}
9390

@@ -100,15 +97,8 @@ class PixelDmx final : public PixelDmxConfiguration
10097
PixelDmxConfiguration::Print();
10198
#endif
10299

103-
if (output_type_ != nullptr)
104-
{
105-
delete output_type_;
106-
output_type_ = nullptr;
107-
}
108-
109-
output_type_ = new PixelOutputType();
110-
assert(output_type_ != nullptr);
111-
output_type_->Blackout();
100+
output_type_.ApplyConfiguration();
101+
output_type_.Blackout();
112102

113103
DEBUG_EXIT
114104
}
@@ -154,9 +144,9 @@ class PixelDmx final : public PixelDmxConfiguration
154144
assert(data != nullptr);
155145
assert(length <= dmxnode::kUniverseSize);
156146

157-
if (output_type_->IsUpdating())
147+
if (output_type_.IsUpdating())
158148
{
159-
puts("output_type_->IsUpdating()");
149+
puts("output_type_.IsUpdating()");
160150
return;
161151
}
162152

@@ -195,7 +185,7 @@ class PixelDmx final : public PixelDmxConfiguration
195185
auto const kPixelIndexStart = (j * kGroupingCount);
196186
for (uint32_t k = 0; k < kGroupingCount; k++)
197187
{
198-
output_type_->SetPixel(kPixelIndexStart + k, data[d + 0], data[d + 1], data[d + 2]);
188+
output_type_.SetPixel(kPixelIndexStart + k, data[d + 0], data[d + 1], data[d + 2]);
199189
}
200190
d = d + 3;
201191
}
@@ -206,7 +196,7 @@ class PixelDmx final : public PixelDmxConfiguration
206196
auto const kPixelIndexStart = (j * kGroupingCount);
207197
for (uint32_t k = 0; k < kGroupingCount; k++)
208198
{
209-
output_type_->SetPixel(kPixelIndexStart + k, data[d + 0], data[d + 2], data[d + 1]);
199+
output_type_.SetPixel(kPixelIndexStart + k, data[d + 0], data[d + 2], data[d + 1]);
210200
}
211201
d = d + 3;
212202
}
@@ -217,7 +207,7 @@ class PixelDmx final : public PixelDmxConfiguration
217207
auto const kPixelIndexStart = (j * kGroupingCount);
218208
for (uint32_t k = 0; k < kGroupingCount; k++)
219209
{
220-
output_type_->SetPixel(kPixelIndexStart + k, data[d + 1], data[d + 0], data[d + 2]);
210+
output_type_.SetPixel(kPixelIndexStart + k, data[d + 1], data[d + 0], data[d + 2]);
221211
}
222212
d = d + 3;
223213
}
@@ -228,7 +218,7 @@ class PixelDmx final : public PixelDmxConfiguration
228218
auto const kPixelIndexStart = (j * kGroupingCount);
229219
for (uint32_t k = 0; k < kGroupingCount; k++)
230220
{
231-
output_type_->SetPixel(kPixelIndexStart + k, data[d + 2], data[d + 0], data[d + 1]);
221+
output_type_.SetPixel(kPixelIndexStart + k, data[d + 2], data[d + 0], data[d + 1]);
232222
}
233223
d = d + 3;
234224
}
@@ -239,7 +229,7 @@ class PixelDmx final : public PixelDmxConfiguration
239229
auto const kPixelIndexStart = (j * kGroupingCount);
240230
for (uint32_t k = 0; k < kGroupingCount; k++)
241231
{
242-
output_type_->SetPixel(kPixelIndexStart + k, data[d + 1], data[d + 2], data[d + 0]);
232+
output_type_.SetPixel(kPixelIndexStart + k, data[d + 1], data[d + 2], data[d + 0]);
243233
}
244234
d = d + 3;
245235
}
@@ -250,7 +240,7 @@ class PixelDmx final : public PixelDmxConfiguration
250240
auto const kPixelIndexStart = (j * kGroupingCount);
251241
for (uint32_t k = 0; k < kGroupingCount; k++)
252242
{
253-
output_type_->SetPixel(kPixelIndexStart + k, data[d + 2], data[d + 1], data[d + 0]);
243+
output_type_.SetPixel(kPixelIndexStart + k, data[d + 2], data[d + 1], data[d + 0]);
254244
}
255245
d = d + 3;
256246
}
@@ -269,7 +259,7 @@ class PixelDmx final : public PixelDmxConfiguration
269259
auto const kPixelIndexStart = (j * kGroupingCount);
270260
for (uint32_t k = 0; k < kGroupingCount; k++)
271261
{
272-
output_type_->SetPixel(kPixelIndexStart + k, data[d], data[d + 1], data[d + 2], data[d + 3]);
262+
output_type_.SetPixel(kPixelIndexStart + k, data[d], data[d + 1], data[d + 2], data[d + 3]);
273263
}
274264
d = d + 4;
275265
}
@@ -282,7 +272,7 @@ class PixelDmx final : public PixelDmxConfiguration
282272
{
283273
return;
284274
}
285-
output_type_->Update();
275+
output_type_.Update();
286276
}
287277
#else
288278
#if !defined(SETDATA)
@@ -296,7 +286,7 @@ class PixelDmx final : public PixelDmxConfiguration
296286
{
297287
return;
298288
}
299-
output_type_->Update();
289+
output_type_.Update();
300290
}
301291
}
302292
#endif
@@ -306,8 +296,7 @@ class PixelDmx final : public PixelDmxConfiguration
306296

307297
void Sync()
308298
{
309-
assert(output_type_ != nullptr);
310-
output_type_->Update();
299+
output_type_.Update();
311300
}
312301

313302
#if defined(OUTPUT_HAVE_STYLESWITCH)
@@ -319,29 +308,29 @@ class PixelDmx final : public PixelDmxConfiguration
319308
{
320309
blackout_ = blackout;
321310

322-
while (output_type_->IsUpdating())
311+
while (output_type_.IsUpdating())
323312
{
324313
// wait for completion
325314
}
326315

327316
if (blackout)
328317
{
329-
output_type_->Blackout();
318+
output_type_.Blackout();
330319
}
331320
else
332321
{
333-
output_type_->Update();
322+
output_type_.Update();
334323
}
335324
}
336325

337326
void FullOn()
338327
{
339-
while (output_type_->IsUpdating())
328+
while (output_type_.IsUpdating())
340329
{
341330
// wait for completion
342331
}
343332

344-
output_type_->FullOn();
333+
output_type_.FullOn();
345334
}
346335

347336
void Print() OVERRIDE { PixelDmxConfiguration::Get().Print(); }
@@ -419,7 +408,7 @@ class PixelDmx final : public PixelDmxConfiguration
419408
}
420409

421410
private:
422-
PixelOutputType* output_type_{nullptr};
411+
PixelOutputType output_type_;
423412

424413
bool started_{false};
425414
bool blackout_{false};

0 commit comments

Comments
 (0)