chipKIT® Development Platform

Inspired by Arduino™

Self tracking library

Created Wed, 20 Nov 2013 12:07:26 +0000 by majenko


majenko

Wed, 20 Nov 2013 12:07:26 +0000

I have just written a little piece on my blog about how a class in a library can be made to keep track of any objects of that class you create in your sketch. It's a very useful trick which can make object management an absolute breeze.

By using a combination of static member functions and variables, and linked lists, you can make a library maintain its own list of defined objects so it is able to perform operations on all those objects, or maybe such things as find an object by some other reference than it's pointer.

As an example I take a small rotary encoder library I wrote last night which keeps track of the encoders you have defined so it can attach itself to change notification interrupts properly.

[url]http://hacking.majenko.co.uk/self-tracking-library[/url]