|
// attribute_uint.cpp: implementation of the Unsigned Integer Attribute
#include "stdafx.h"
#include "attribute_uint.h"
// Construction/Destruction
CAttribute_uint::CAttribute_uint(unsigned int ivalue,int index) : CAttribute_Generic(index)
{
m_size = sizeof(unsigned int);
value = NULL;
value_tmp = NULL;
value = new( unsigned int );
value_tmp = new( unsigned int );
if ( !value || !value_tmp )
{
throw;
}
*value = ivalue;
*value_tmp = 0;
ClassName = _T("CAttribute_uint");
Kind = IDC_ATTR_UINT;
}
CAttribute_uint::~CAttribute_uint()
{
try
{
if (value)
delete value;
if (value_tmp)
delete value_tmp;
}
catch (...)
{
// nothing
}
}
void CAttribute_uint::Get_uint(unsigned int& nDummy)
{
try
{
nDummy = (*value);
}
catch (...)
{
nDummy = 0;
}
}
void CAttribute_uint::Get_tmp_uint(unsigned int& nDummy)
{
try
{
nDummy = (*value_tmp);
}
catch (...)
{
nDummy = 0;
}
}
void CAttribute_uint::Set_uint(unsigned int& nDummy)
{
if( !value )
return;
try
{
(*value) = nDummy;
}
catch (...) {
if(value)
(*value) = 0;
}
}
void CAttribute_uint::Set_tmp_uint(unsigned int& nDummy)
{
if( !value_tmp )
return;
try
{
(*value_tmp) = nDummy;
}
catch (...) {
if(value_tmp)
(*value_tmp) = 0;
}
}
void CAttribute_uint::SetAttributeCast(CString& szDummy)
{
try
{
if (!szDummy.IsEmpty())
{
size_t nLen = szDummy.GetLength();
*value = _tstol(szDummy.GetBuffer((int) nLen+1));
szDummy.ReleaseBuffer();
}
}
catch (...)
{
szDummy.ReleaseBuffer();
if(value)
(*value) = 0;
}
}
void CAttribute_uint::SetTmpAttributeCast(CString& szDummy)
{
try
{
if (!szDummy.IsEmpty())
{
size_t nLen = szDummy.GetLength();
*value_tmp = _tstol(szDummy.GetBuffer((int) nLen+1));
szDummy.ReleaseBuffer();
}
}
catch (...)
{
szDummy.ReleaseBuffer();
if(value_tmp)
(*value_tmp) = 0;
}
}
void CAttribute_uint::Get_Value_Str(CString& szDummy)
{
try
{
szDummy.Format(_T("%u"),(*value));
}
catch (...) {
}
}
void CAttribute_uint::Get_Value_Str_tmp(CString& szDummy)
{
try
{
szDummy.Format(_T("%u"),(*value_tmp));
}
catch (...) {
}
}
bool CAttribute_uint::IsValueTmpIdentical()
{
if( value && value_tmp )
return ((*value) == (*value_tmp));
return false;
}
BOOL CAttribute_uint::IsValueTmpIdenticalMFC()
{
if (IsValueTmpIdentical())
return TRUE;
return FALSE;
}
void CAttribute_uint::Empty_Value(bool ori)
{
if( !value || !value_tmp )
return;
if (ori)
(*value) = 0;
else
(*value_tmp) = 0;
}
void CAttribute_uint::GetAttributeBinData(BIN_KIND_TYPE& bType,BIN_KIND_SIZE& bSize,void*& pAttribute)
{
try
{
bType = BIN_KIND_UINT;
bSize = (BIN_KIND_SIZE) m_size;
pAttribute = (void*) (value);
}
catch (...)
{
bType = BIN_KIND_NULL;
bSize = 0;
pAttribute = NULL;
LTRACE(LOG_TRLVL_ERROR,_T("CAttribute_uint::GetAttributeBinData - error: could not get the value pointer."));
}
}
void CAttribute_uint::SetAttributeBinData(BIN_KIND_TYPE bType,BIN_KIND_SIZE bSize,void* pAttribute)
{
if ( bType != BIN_KIND_UINT )
return;
m_size = (size_t) (bSize);
try
{
*(value) = *((unsigned int*) pAttribute);
}
catch (...)
{
LTRACE(LOG_TRLVL_ERROR,_T("CAttribute_uint::SetAttributeBinData - error: could not set the value."));
}
}
|
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.
Senior Software Developer in C/C++ and Oracle.
Ex-physicist holding a Ph.D. on x-ray lasers.