MCPcopy Create free account
hub / github.com/OpenZWave/open-zwave / GetValueAsString

Method GetValueAsString

cpp/src/Manager.cpp:2369–2534  ·  view source on GitHub ↗

----------------------------------------------------------------------------- Creates a string representation of the value, regardless of type -----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

2367// Creates a string representation of the value, regardless of type
2368//-----------------------------------------------------------------------------
2369bool Manager::GetValueAsString
2370(
2371 ValueID const& _id,
2372 string* o_value
2373)
2374{
2375 bool res = false;
2376 char str[256] = {0};
2377
2378 if( o_value )
2379 {
2380 if( Driver* driver = GetDriver( _id.GetHomeId() ) )
2381 {
2382 LockGuard LG(driver->m_nodeMutex);
2383
2384 switch( _id.GetType() )
2385 {
2386 case ValueID::ValueType_BitSet:
2387 {
2388 if( ValueBitSet* value = static_cast<ValueBitSet*>( driver->GetValue( _id ) ) )
2389 {
2390 *o_value = value->GetAsString();
2391 value->Release();
2392 res = true;
2393 } else {
2394 OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to GetValueAsString");
2395 }
2396 break;
2397 }
2398 case ValueID::ValueType_Bool:
2399 {
2400 if( ValueBool* value = static_cast<ValueBool*>( driver->GetValue( _id ) ) )
2401 {
2402 *o_value = value->GetValue() ? "True" : "False";
2403 value->Release();
2404 res = true;
2405 } else {
2406 OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to GetValueAsString");
2407 }
2408 break;
2409 }
2410 case ValueID::ValueType_Byte:
2411 {
2412 if( ValueByte* value = static_cast<ValueByte*>( driver->GetValue( _id ) ) )
2413 {
2414 snprintf( str, sizeof(str), "%u", value->GetValue() );
2415 *o_value = str;
2416 value->Release();
2417 res = true;
2418 } else {
2419 OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to GetValueAsString");
2420 }
2421 break;
2422 }
2423 case ValueID::ValueType_Decimal:
2424 {
2425 if( ValueDecimal* value = static_cast<ValueDecimal*>( driver->GetValue( _id ) ) )
2426 {

Callers

nothing calls this directly

Calls 5

GetItemMethod · 0.80
IsPressedMethod · 0.80
GetValueMethod · 0.45
GetAsStringMethod · 0.45
ReleaseMethod · 0.45

Tested by

no test coverage detected