Shows how to create own data types.
#include "stdafx.h"
#include <adtf_base.h>
struct cPoint2D
{
cPoint2D()
{
m_x = 0;
m_y = 0;
}
public:
int32_t m_x;
int32_t m_y;
};
struct cConvertPoint2D
{
static tResult ToString(
const cPoint2D& oFromValue, adtf_util::cString& strToString)
{
strToString.Append(adtf_util::cString::FromType(oFromValue.m_x));
strToString.Append(" ; ");
strToString.Append(adtf_util::cString::FromType(oFromValue.m_y));
}
static tResult FromString(
const adtf_util::cString& strFromString, cPoint2D& oToValue)
{
adtf_util::cStringList vecStrings;
strFromString.Split(vecStrings, ";");
if (vecStrings.GetItemCount() == 2)
{
adtf_util::cStringUtil::ToType(vecStrings[0], oToValue.m_x);
adtf_util::cStringUtil::ToType(vecStrings[1], oToValue.m_y);
}
}
static tResult ToRaw(
const void* pData,
const size_t szDataSize, adtf::base::IRawMemory& oToMem)
{
return oToMem.
Set(pData, szDataSize);
}
static tResult FromRaw(
const adtf::base::ant::IRawMemory& oFromMem,
void* pData,
const size_t szDataSize)
{
if (oFromMem.
GetSize() == szDataSize)
{
adtf_util::cMemoryBlock::MemCopy(pData, oFromMem.
Get(), szDataSize);
}
}
static tResult Convert(
const adtf::base::IPropertyValue& oProperty, cPoint2D& oToValue)
{
adtf_util::cString strTypeOfValue;
if (!strTypeOfValue.Compare("cString",0,7))
{
adtf_util::cString strValue;
RETURN_IF_FAILED(cConvertPoint2D::FromString(strValue, oToValue));
}
}
};
{
{
{
template < >
{
static constexpr const tChar* TYPE_NAME = "cPoint2D";
typedef cConvertPoint2D con_type;
};
}}}
int main(int , char * [])
{
cPoint2D oNewPoint2D;
oMyProps.SetProperty(propertyNewPoint2D);
{
oMyProps.GetProperty("TheNameOfTheProperty", oProperty);
std::cout << std::endl << "Old Point2D: x=" << oProperty.GetValueT().m_x << " / y=" << oProperty.GetValueT().m_y << std::endl;
}
{
oMyProps.GetProperty("TheNameOfTheProperty", oStringProperty);
std::cout << std::endl << "Point2D as cString: \"" << oStringProperty.GetValueT() <<"\"" << std::endl;
oStringProperty = " 23;42 ";
std::cout << std::endl << "Modified cString: \"" << oStringProperty.GetValueT() << "\"" << std::endl ;
oMyProps.SetProperty(oStringProperty);
}
{
oMyProps.GetProperty("TheNameOfTheProperty", oProperty);
std::cout << std::endl << "New Point2D: x=" << oProperty.GetValueT().m_x << " / y=" << oProperty.GetValueT().m_y << std::endl;
}
return 0;
}
A_UTILS_NS::cResult tResult
For backwards compatibility and to bring latest version into scope.
Definition result.h:736
#define RETURN_NOERROR
Return status ERR_NOERROR, which requires the calling function's return type to be tResult.
Definition result.h:29
#define RETURN_ERROR(code)
Return specific error code, which requires the calling function's return type to be tResult.
Definition result.h:42
virtual tResult ToString(IString &&strIToString) const =0
virtual tResult GetType(IString &&strType) const =0
virtual size_t GetSize() const =0
virtual tResult Set(const void *pValue, size_t szSize)=0
virtual const void * Get() const =0
Definition properties_v2.h:397
Definition properties_v2.h:283
Namespace for all functionality of the ADTF Base SDK provided since v3.0.
Definition adtf_class_version.h:16
Namespace for the ADTF Base SDK.
Definition adtf_base_type_traits.h:13
Namespace for all functionality provided by ADTF and its SDKs.
Definition adtf_client_connector.h:14
#define adtf_string_intf(__string__)
Definition string_intf.h:465
Definition property_type_definitions.h:38