hzEmaddr* pEma ; // Cast pEma = (hzEmaddr*) &m_Data ; *pEma = S ; if (*pEma) { m_eType = eType ; m_eStatus = ATOM_SET ; return E_OK ; }
| Return Type | Function name | Arguments |
|---|---|---|
| hzEcode | hzAtom::SetValue | (hdbBasetype,const hzString&,) |
Declared in file: hzDatabase.h
Defined in file : hzAtom.cpp
Function Logic:
Function body:
hzEcode hzAtom::SetValue (hdbBasetype eType, const hzString& S)
{
_hzfunc("hzAtom::SetValue(hzString)") ;
const char* j ;
uint64_t x ;
hzXDate xd ;
hzSDate sd ;
hzTime ti ;
hzIpaddr ipa ;
bool bMinus = false ;
hzEcode rc = E_BADVALUE ;
Clear() ;
if (!S)
return E_OK ;
m_eType = eType ;
/*
** ** HadronZoo string-like types
** */
if (m_eType == BASETYPE_DIGEST)
{
hzMD5 Md5 ;
Md5 = S ;
if (!Md5.IsNull())
{
m_Data.m_pVoid = new uchar[sizeof(hzMD5)] ;
memcpy(m_Data.m_pVoid, Md5.Value(), sizeof(hzMD5)) ;
m_eStatus = ATOM_SET ;
return E_OK ;
}
m_eType = BASETYPE_UNDEF ;
m_eStatus = ATOM_ERROR ;
return E_BADVALUE ;
}
if (m_eType == BASETYPE_STRING)
{
hzString tmp ;
tmp = S ; m_Data.m_uInt32 = tmp._int_addr() ; tmp._int_clr() ;
m_eType = eType ;
m_eStatus = ATOM_SET ;
return E_OK ;
}
if (m_eType == BASETYPE_DOMAIN)
{
hzDomain tmp ;
tmp = S ;
if (tmp)
{
m_Data.m_uInt32 = tmp._int_addr() ;
tmp._inc_copy() ;
m_eType = eType ;
m_eStatus = ATOM_SET ;
return E_OK ;
}
m_eType = BASETYPE_UNDEF ;
m_eStatus = ATOM_ERROR ;
return E_BADVALUE ;
}
if (m_eType == BASETYPE_EMADDR)
{
/*
** hzEmaddr* pEma ; // Cast
**
** pEma = (hzEmaddr*) &m_Data ;
** *pEma = S ;
** if (*pEma)
** {
** m_eType = eType ;
** m_eStatus = ATOM_SET ;
** return E_OK ;
** }
** */
hzEmaddr tmp ;
tmp = S ;
if (tmp)
{
m_Data.m_uInt32 = tmp._int_addr() ;
tmp._inc_copy() ;
m_eType = eType ;
m_eStatus = ATOM_SET ;
return E_OK ;
}
m_eType = BASETYPE_UNDEF ;
m_eStatus = ATOM_ERROR ;
return E_BADVALUE ;
}
if (m_eType == BASETYPE_URL)
{
hzUrl tmp ;
tmp = S ;
if (tmp)
{
m_Data.m_uInt32 = tmp._int_addr() ;
tmp._inc_copy() ;
m_eType = eType ;
m_eStatus = ATOM_SET ;
return E_OK ;
}
m_eType = BASETYPE_UNDEF ;
m_eStatus = ATOM_ERROR ;
return E_BADVALUE ;
}
/*
** ** HadronZoo types without smart pointers
** */
if (m_eType == BASETYPE_IPADDR)
{
ipa = *S ;
if (ipa)
{ m_eStatus = ATOM_SET ; m_Data.m_uInt32 = (uint32_t) ipa ; return E_OK ; }
return E_BADVALUE ;
}
if (m_eType == BASETYPE_XDATE)
{
rc = xd.SetDateTime(S) ;
if (rc == E_OK && xd.AsVal())
{ m_eStatus = ATOM_SET ; m_Data.m_uInt64 = xd.AsVal() ; return E_OK ; }
m_eStatus = ATOM_ERROR ;
return E_BADVALUE ;
}
if (m_eType == BASETYPE_SDATE)
{
rc = sd.SetDate(S) ;
if (rc == E_OK)
{ m_eStatus = ATOM_SET ; m_Data.m_uInt32 = sd.NoDays() ; return E_OK ; }
m_eStatus = ATOM_ERROR ;
return E_BADVALUE ;
}
if (m_eType == BASETYPE_TIME)
{
rc = ti.SetTime(S) ;
if (rc == E_OK)
{ m_eStatus = ATOM_SET ; m_Data.m_uInt32 = ti.NoSecs() ; return E_OK ; }
m_eStatus = ATOM_ERROR ;
return E_BADVALUE ;
}
/*
** ** Numeric types (no smart pointers)
** */
if (m_eType == BASETYPE_DOUBLE)
{
if (IsDouble(m_Data.m_Double, *S))
{ m_eStatus = ATOM_SET ; return E_OK ; }
m_eStatus = ATOM_ERROR ;
return E_BADVALUE ;
}
if (m_eType == BASETYPE_BOOL)
{
if (S == "TRUE" || S == "true" || S == "yes" || S == "y" || S == "1") { m_Data.m_Bool = true ; m_eStatus = ATOM_SET ; return E_OK ; }
if (S == "FALSE" || S == "false" || S == "no" || S == "n" || S == "0") { m_Data.m_Bool = false ; m_eStatus = ATOM_SET ; return E_OK ; }
m_eStatus = ATOM_ERROR ;
return E_BADVALUE ;
}
j = *S ;
if (*j == CHAR_MINUS)
{ j++ ; bMinus = true ; }
for (x = 0; IsDigit(*j) ; j++)
{ x *= 10;x += (*j - ''0'');}
if (*j)
return E_BADVALUE ;
switch (m_eType)
{
case BASETYPE_BYTE: if (x > 0x7f)
return E_BADVALUE ;
m_Data.m_sByte = x & 0x7f;
if (bMinus)
m_Data.m_sByte *= -1;
break ;
case BASETYPE_INT16: if (x > 0x7fff)
return E_BADVALUE ;
m_Data.m_sInt16 = x & 0x7fff;
if (bMinus)
m_Data.m_sInt16 *= -1;
break ;
case BASETYPE_INT32: if (x > 0x7fffffff)
return E_BADVALUE ;
m_Data.m_sInt32 = x & 0x7fffffff;
if (bMinus)
m_Data.m_sInt32 *= -1;
break ;
case BASETYPE_INT64: m_Data.m_sInt64 = x ;
if (bMinus)
m_Data.m_sInt64 *= -1;
break ;
case BASETYPE_UBYTE: if (x & 0xffffffffffffff00)
return E_BADVALUE ;
m_Data.m_uByte = (x & 0xff);
break ;
case BASETYPE_UINT16: if (x & 0xffffffffffff0000)
return E_BADVALUE ;
m_Data.m_uInt16 = (x & 0xffff);
break ;
case BASETYPE_UINT32: if (x & 0xffffffff00000000)
return E_BADVALUE ;
m_Data.m_uInt32 = (x & 0xffffffff);
break ;
case BASETYPE_UINT64: m_Data.m_uInt64 = x ;
break ;
}
m_eStatus = ATOM_SET ;
return E_OK ;
}