Click here to Skip to main content
15,894,180 members
Articles / Programming Languages / C++

A policy based reference counting implementation for compound objects

Rate me:
Please Sign up or sign in to vote.
4.77/5 (13 votes)
26 May 2005CPOL16 min read 33.3K   274   30  
Reference counting smart pointers and handles of various flavours.
/////////////////////////////////
// msgrouter.hpp.hpp
//	generic message routing
//

#pragma once
#include "graphs.hpp"
#pragma message ("Compiling " __FILE__)

//define a model for routing of messages into a graph

namespace GE_ { namespace stdx { namespace graph {


	template<class Data, class Node, class Fn> //void Fn(Arc*, Data&): can be mem_fun(void(Arc::*)(Data&))
	void route_arcs(Data& d, Node& node, Fn fn)
	{
		for(typename Node::arc_iterator i = node.begin_arcto(); i!=node.end_arcto(); i++)
			Fn(i, d);
	}


	template<class Data, class Node, class Fn> //void Fn(Node*, Data&): can be mem_fun(void(Node::*)(Data&))
	void route_linked(Data& d, Node& node, Fn fn)
	{
		for(typename Node::arc_iterator i = node.begin_arcto(); i!=node.end_arcto(); i++)
		{
			Node* p(i->get_to());
			if(p) fn(p, d);
		}
	}

	template<class Data, class Node, class Fn> //void Fn(Arc*, Data&): can be mem_fun(void(Arc::*)(Data&))
	void backroute_arcs(Data& d, Node& node, Fn fn)
	{
		for(typename Node::arc_iterator i = node.begin_arcfrom(); i!=node.end_arcfrom(); i++)
			Fn(i, d);
	}


	template<class Data, class Node, class Fn> //void Fn(Node*, Data&): can be mem_fun(void(Node::*)(Data&))
	void backroute_linked(Data& d, Node& node, Fn fn)
	{
		for(typename Node::arc_iterator i = node.begin_arcfrom(); i!=node.end_arcfrom(); i++)
		{
			Node* p(i->get_to());
			if(p) fn(p, d);
		}
	}

}}}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Italy Italy
Born and living in Milan (Italy), I'm an engineer in electronics actually working in the ICT department of an important oil/gas & energy company as responsible for planning and engineering of ICT infrastructures.
Interested in programming since the '70s, today I still define architectures for the ICT, deploying dedicated specific client application for engineering purposes, working with C++, MFC, STL, and recently also C# and D.

Comments and Discussions