arkhipenko / TaskScheduler

Cooperative multitasking for Arduino, ESPx, STM32, nRF and other microcontrollers
http://playground.arduino.cc/Code/TaskScheduler
BSD 3-Clause "New" or "Revised" License
1.32k stars 243 forks source link

wrapper namespace to avoid class names clash #147

Closed vortigont closed 2 years ago

vortigont commented 2 years ago

suggesting a feasible workaround for #145 a simple wrapper namespace and class aliases to be used with frameworks having clashing class names. This could also be done in user code, but better to have an example available in the library.

Closes #145

arkhipenko commented 2 years ago

Tried this approach - does not work...

Scheduler_example00_Blink:46:1: error: 'Scheduler' does not name a type
   46 | Scheduler ts;
      | ^~~~~~~~~
Scheduler_example00_Blink:54:76: error: 'ts' was not declared in this scope
   54 | Task tBlink1 ( PERIOD1 * TASK_MILLISECOND, DURATION / PERIOD1, &blink1CB, &ts, true );
      |                                                                            ^~
Scheduler_example00_Blink:62:79: error: 'ts' was not declared in this scope
   62 | Task tBlink2 ( PERIOD2 * TASK_MILLISECOND, DURATION / PERIOD2, &blink2CB_ON, &ts, false );
arkhipenko commented 2 years ago

Well, take it back: Declaring scheduler like this:

// Scheduler
TS::Scheduler ts;

works actually.

arkhipenko commented 2 years ago

So yes, this is a good workaround - thank you @vortigont !

arkhipenko commented 2 years ago

Pushed my version 3.6.2 with this update to the testing branch. Thanks again.

arkhipenko commented 2 years ago

The question is - should I go for even more safe: tsScheduler tsTask tsStatusRequest ?

vortigont commented 2 years ago

The question is - should I go for even more safe: tsScheduler tsTask tsStatusRequest

IMO - I do not like it, class names are usually starts with capital. Better provide an example to use full namespace prefix TS::Task, it gives the idea where the alias comes from.