PrevUpHome

utx::cb_track


utx::cb_track is the callback tracker, to track how one api is calling back another.

It will display information with color highlighting.

Utxcpp track and utxcpp core doesn't depend on each other.

class track

class cb_track {
class cb_track {
private:
	class Printer;

Constructors and Methods

Removed Constructors and methods

cb_track() = delete;
cb_track(const cb_track &) = delete;
cb_track & operator=(const cb_track &) = delete;

Constructors

Create an utx::cb_track object and reset the underlying track_target and optional_string value.

cb_track(const std::string & target) noexcept;				// (1)

cb_track(const std::string & target, const std::string & optional) noexcept;	// (2)

cb_track(const std::string & target, const T & optional) noexcept;		// (3)
[Note] Note
  • track_target
    • All the underlying value track_target will be reset to target.
  • optional_string
    • (1). The underlying value optional_string will be reset to empty.
    • (2) (3). The underlying value optional_string will be reset to optional.

Method reset

Reset the underlying track_target and optional_string value.

void reset(const std::string & target) noexcept;			// (1)

void reset(const std::string & target, const std::string & optional) noexcept;	// (2)

void reset(const std::string & target, const T & optional) noexcept;		// (3)
[Note] Note
  • track_target
    • All the underlying value track_target will be reset to target.
  • optional_string
    • (1). The underlying value optional_string will be reset to empty.
    • (2) (3). The underlying value optional_string will be reset to optional.

Method operator()

Printer & operator()();									// (1)

Printer & operator()(const std::string & target);				// (2)

Printer & operator()(const std::string & target, const std::string & optional);		// (3)

Printer & operator()(const std::string & target, const T & optional);			// (4)
[Note] Note
  • (1)
    • There is no reset calling, so the underlying track_target and optional_string will keep untouched.
  • (2) (3) (4):
    • All the underlying value track_target will be reset to target.
  • optional_string
    • (2). The underlying value optional_string will be reset to empty.
    • (3) (4). The underlying value optional_string will be reset to optional.

Example

#include <utxcpp/track.hpp>

class Hello {
public:
	Hello() {utx::cb_track{"Hello"}() << '\n';}
	~Hello() {utx::cb_track{"~Hello", '\n'}();}
	void fn() {utx::cb_track{"fn", "\n"}();}
};

class World {
private:
	utx::cb_track track{"World", "\n"};
public:
	World() {track();}
	~World() {track.reset("~World", '\n'); track();}
	void fn() {track.reset("fn", "\n"); track();}
};

class Fizz {
private:
	utx::cb_track track{"class-Fizz"};
public:
	Fizz() {
		track() << "Constructor.\n";
	}
	~Fizz() {
		track.reset("~Fizz");
		track() << "Destructor.\n";
	}
	void fn() {
		track.reset("Fizz::fn()", "Fizz::fn() is a useful method.\n");
		track();
	}
	void func() {
		track("Fizz::func()", "another method.\n");
		track.reset("Fizz::func");
		track() << "--------\n";
	}
};

int main() {
	std::clog << "------------------------------------------------------------------------\n";
	{Hello{}.fn();}
	std::clog << "------------------------------------------------------------------------\n";
	{World{}.fn();}
	std::clog << "------------------------------------------------------------------------\n";
	{Fizz().fn();}
	std::clog << "------------------------------------------------------------------------\n";
	{Fizz().func();}
}

Output Result:

------------------------------------------------------------------------
[utx::cb_track *** Hello]
[utx::cb_track *** fn]
[utx::cb_track *** ~Hello]
------------------------------------------------------------------------
[utx::cb_track *** World]
[utx::cb_track *** fn]
[utx::cb_track *** ~World]
------------------------------------------------------------------------
[utx::cb_track *** class-Fizz] Constructor.
[utx::cb_track *** Fizz::fn()] Fizz::fn() is a useful method.
[utx::cb_track *** ~Fizz] Destructor.
------------------------------------------------------------------------
[utx::cb_track *** class-Fizz] Constructor.
[utx::cb_track *** Fizz::func()] another method.
[utx::cb_track *** Fizz::func] --------
[utx::cb_track *** ~Fizz] Destructor.

Last revised: November 24, 2022 at 11:26:05 GMT


PrevUpHome