conversion.cpp

来自「The article describes a smart binding of」· C++ 代码 · 共 142 行

CPP
142
字号
#include	"Conversion.h"
#include	"ConversionHelper.h"

#pragma warning(disable : 4996)

//	Constructor
IConversion::IConversion(const string& name) : name_(name)
{
	conversionHelper_ = ConversionHelper::Instance();
	conversionHelper_->Add(this);
}

IConversion::~IConversion()
{
	conversionHelper_->Remove(this);
}

bool	String2Object(Double* object, string& value)
{
	bool	result	= false;
	if (!object
	)	return	result
	;
	object->Object() = atof(value.c_str())
	;
	result	= true
	;
	return	result;
}

bool	String2Object(Int* object, string& value)
{
	bool	result	= false;
	if (!object
	)	return	result
	;
	object->Object() = atoi(value.c_str())
	;
	result	= true
	;
	return	result;
}

bool	String2Object(Long* object, string& value)
{
	bool	result	= false;
	if (!object
	)	return	result
	;
	object->Object() = atoi(value.c_str())
	;
	result	= true
	;
	return	result;
}

bool	String2Object(String* object, string& value)
{
	bool	result	= false;
	if (!object
	)	return	result
	;
	object->Object() = value
	;
	result	= true
	;
	return	result;
}

bool	String2Object(Bool* object, string& value)
{
	bool	result	= false;
	if (!object
	)	return	result
	;
	object->Object() = (!stricmp(value.c_str(),"true")) ? true : false;
	;
	result	= true
	;
	return	result;
}

string	Object2String(Double* object)
{
	char	textBuffer	[256];
	string	result	= "";
	if (!object
	)	return	result
	;
	sprintf	(textBuffer,"%g",object->Object())
	;
	result	= textBuffer;
	return	result;
}

string	Object2String(Int* object)
{
	char	textBuffer	[256];
	string	result	= "";
	if (!object
	)	return	result
	;
	result	= itoa(object->Object(),textBuffer,10)
	;
	return	result;
}

string	Object2String	(Long* object)
{
	char	textBuffer	[256];
	string	result	= "";
	if (!object
	)	return	result
	;
	result	= itoa(object->Object(),textBuffer,10)
	;
	return	result;
}

string	Object2String(Bool* object)
{
	string	result	= "";
	if (!object
	)	return	result
	;
	result	= object->Object() ? "true" : "false"
	;
	return	result;
}

string	Object2String	(String* object)
{
	string	result	= "";
	if (!object
	)	return	result
	;
	result	= object->Object()
	;
	return	result;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?