#ifndef TRACER_H_ #define TRACER_H_ #include #include #include // Allows readers to track the operations applied to STL container elements. // // Tracer assigns a unique and immutable ID to each default-constructed // instance. Each instance also contains a list of its ancestors, which can // be copied from one Tracer to another Tracer. A Tracer may have a // // These Tracers print messages whenever important events happen, including // default construction, copy construction, destruction, assignment, and // "less than" operator invocation. class Tracer { public: // Constructors/Destructors. Tracer(); // Tracer(Tracer&&) = delete; ~Tracer(); Tracer(const Tracer &rhs); // Assignment operator. Tracer &operator=(const Tracer &rhs); // Less-than comparison operator. This is used for things like sorting // or inserting into a map. bool operator<(const Tracer &rhs) const; // << operator friend std::ostream &operator<<(std::ostream &out, const Tracer &rhs); private: // Returns "(id_,[parents])" as a string. std::string PrintID() const; // Adds the passed-in list of ancestors to our own. void AppendAncestors(const Tracer &t); // Return the ID of the original Tracer (ie, the "root" of our ancestry). int GetRoot() const; // This static (class member) tracks the next id_ to hand out. static int nextid_; const int id_; std::vector ancestors_; }; #endif // TRACER_H_