All pastes #168683 Raw Edit

Something

public text v1 · immutable
·published 2006-09-13 05:46 UTC
rendered paste body
class DataReference
{
private:
	OneTimeData* data;

public:
	
	DataReference (void);
	DataReference (OneTimeData *originalData);
	
	DataReference (DataReference &refToCopy);
	DataReference& operator= (DataReference& rhs);
	
	virtual ~DataReference (void);
	
	void DestroyData (void);
		
	OneTimeData* GetData (void);
	
protected:
	void SetData (OneTimeData* newData);
};


DataReference::DataReference (void)
{
	data = NULL;
}

DataReference::DataReference (DataReference &refToCopy)
{
	 data = refToCopy.data;
}

DataReference::DataReference (OneTimeData *originalData)
{
	data = originalData;
}

DataReference::~DataReference (void)
{
	data = NULL;
}

void
DataReference::DestroyData (void)
{
	// let's not crash the computer just because
	// someone called Destroy() twice

	if ( OneTimeData::DataIsValid( data ) )
		delete data;
	else
		cerr << "error: trying to destroy the same data more than once" << endl;
	
	data = NULL;
}

DataReference&
DataReference::operator= (DataReference& rhs)
{
	data = rhs.data;
	return *this;
}


OneTimeData*
DataReference::GetData (void)
{
	return data;
}


void
DataReference::SetData (OneTimeData* newData)
{
	data = newData;
}