Developers.Code.CNeighbours

From Shareaza Wiki
Jump to navigation Jump to search

CNeighbours

CNeighbours is the top of the inheritance chain. Here's the code at the top of Neighbours.cpp:

<source lang="c"> // Create the single global Neighbours object that holds the list of neighbour computers we ... CNeighbours Neighbours; // When Shareaza starts running, this line creates a single global ...

////////////////////////////////////////////////////////////////////// // CNeighbours construction

// The line above creates the one CNeighbours object named Neighbours // Creating that object calls this constructor, then the CNeighboursWithConnect constructor, ... // CNeighbours doesn't add anything to the inheritance column that needs to be set up CNeighbours::CNeighbours() { }

// Delete the CNeighbours object CNeighbours::~CNeighbours() { // Call close on each neighbour in the list, reset member variables to 0, and clear ... Close(); } </source>

Above and outside all the methods is the line CNeighbours Neighbours;. The computer runs this line of code when Shareaza starts. It creates a single global object from the CNeighbours class, named Neighbours. That object has all the code of the entire CNeighbours inheritance column at its disposal. This is the only way that the code of the CNeighbours inheritance column is used - in this one global object.

When Shareaza exits, the global Neighbours object goes out of scope. Right before the computer stops running the program, it calls the destructors of the CNeighbours column. This calls close on each neighbour in the list, resets member variables to 0, and clears the ping route and pong caches.