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

Protean Charm or Binding Objects in C++

Rate me:
Please Sign up or sign in to vote.
4.85/5 (16 votes)
22 Mar 2009CPOL5 min read 29.7K   83   18  
The article describes a smart binding of C++ objects.
#ifndef	__Conversion_Helper_H
#define	__Conversion_Helper_H

#include	"Conversion.h"
#include	"Destroyer.h"

#include	<string>
#include	<vector>
using namespace std;

#ifndef	null
#define	null	0
#endif

class	IConversion;

class	ConversionHelper
{
//	Methods
public:
	static ConversionHelper* Instance()
	{
	//	Uses "Lazy initialization"
		if (!instance_)
		{
			instance_ = new ConversionHelper();
			destroyer_.SetObject(instance_);
		}
		return instance_;
	}

	int			ObjectsNumber	()	{ return static_cast<int>(conversionObjects_.size());	}
	void		Add				(IConversion* conversion);
	void		Remove			(IConversion* conversion);
IConversion*	Get				(int index);
IConversion*	Get				(const string& name);
	bool		Exist			(const string& name);

//	Constructor
protected:
	ConversionHelper			() {}

private:
	static	ConversionHelper*			instance_;
	static	Destroyer<ConversionHelper>	destroyer_;
	vector<IConversion*>				conversionObjects_;
};

#endif

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
Software Developer (Senior)
Israel Israel
MSc in System Engineering from Tallinn Technical University, Estonia. Currently, I work in a hitech enterprise in Israel.

Comments and Discussions