Simple and fast tracking and iteration of c++ object instances.
- Simple integration with source code (2 lines required in user class to enable all functionality).
- Fast adding and removal of instances to the list (no memory allocation).
- Fast iteration (List nodes exist with object instances to reduce cache misses).
- Supports standard iterator syntax.
- Threadsafe (optional, see
INST_TRACKING_THREAD_TESTdefine in source). - Supports sorting of instance list using custom sort functions (undocumented, see
List::Sort()in source).
-
Add the header file to your project
-
Add an
RTM::Instance::Trackerto the class you wish to track and initialize it in the constructorusing namespace RTM::Instance; ... class TrackableClass{ public: TrackableClass(int value = 0) : InstanceTracker(this) // init tracker with 'this' pointer , IntegerValue(value) {} private: Tracker<TrackableClass> InstanceTracker; // Tracker member variable int IntegerValue; };
-
Instances will be added to an
RTM::Instance::Liston construction and removed on destruction:using namespace RTM::Instance; ... int numInstances = List<TrackableClass>::GetNum();
-
The list can be easily iterated:
using namespace RTM::Instance; ... for (auto&& itr : List<TestClass>()) cout << itr->IntegerValue << endl; // alternatively: for (auto itr = List<TestClass>::begin(); itr != List<TestClass>::end(); ++itr) cout << itr->IntegerValue << endl;
- Use of static
begin()andend()functions inRTM::Instance::Listcauses a warning in Visual Studio with warning level of /W4 or higher. See https://connect.microsoft.com/VisualStudio/feedback/details/1322808/warning-w4-with-compiler-generated-local-variable