From a7a38fa9f4862ed4b9efe240cf7b12ca369adcf3 Mon Sep 17 00:00:00 2001 From: kevin Date: Fri, 26 Apr 2024 16:59:40 -0400 Subject: [PATCH] cwObject.h/cpp : cwObject now detects and properly encodes floats and unsigned integers that are specified with the 'f' and 'u' suffix. --- cwObject.cpp | 10 ++++++++-- cwObjectTemplate.h | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/cwObject.cpp b/cwObject.cpp index 6fabd0b..60682f8 100644 --- a/cwObject.cpp +++ b/cwObject.cpp @@ -869,11 +869,17 @@ cw::rc_t cw::objectFromString( const char* s, object_t*& objRef ) break; case lex::kRealLexTId: - _objCreateValueNode( cnp, lex::tokenDouble(lexH), "real" ); + if( tokenIsSinglePrecision(lexH) ) + _objCreateValueNode( cnp, lex::tokenFloat(lexH),"float" ); + else + _objCreateValueNode( cnp, lex::tokenDouble(lexH), "double" ); break; case lex::kIntLexTId: - _objCreateValueNode( cnp, lex::tokenInt(lexH), "int" ); + if( tokenIsUnsigned(lexH) ) + _objCreateValueNode( cnp, lex::tokenUInt(lexH), "uint" ); + else + _objCreateValueNode( cnp, lex::tokenInt(lexH), "int" ); break; case lex::kHexLexTId: diff --git a/cwObjectTemplate.h b/cwObjectTemplate.h index 81027b4..7fca3ec 100644 --- a/cwObjectTemplate.h +++ b/cwObjectTemplate.h @@ -74,6 +74,12 @@ namespace cw return obj; } + template<> object_t* _objSetLeafValue( object_t* obj, float value ) + { + obj->u.f = value; + obj->type = _objIdToType(kFloatTId); + return obj; + } template<> object_t* _objSetLeafValue( object_t* obj, double value ) {