Skip to content

Commit

Permalink
Add displayed_value method to the OutputString
Browse files Browse the repository at this point in the history
Add a helper function to the OutputString which will return
the value of the referenced variable (if set) otherwise the
value of the OutputString directly.
  • Loading branch information
martonmiklos authored and ad3154 committed Nov 12, 2024
1 parent 4a243de commit 4282fda
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

namespace isobus
{
class VirtualTerminalServerManagedWorkingSet;

/// @brief The types of objects in an object pool by object type byte value
enum class VirtualTerminalObjectType : std::uint8_t
{
Expand Down Expand Up @@ -1784,6 +1786,10 @@ namespace isobus
/// @returns The value of the string
std::string get_value() const;

/// @brief Returns the value of the variable (if referenced) otherwise the set value
/// @returns The displayed value of the string
std::string displayed_value(std::shared_ptr<isobus::VirtualTerminalServerManagedWorkingSet> parentWorkingSet) const;

/// @brief Sets the value of the string (only matters if it has no child string variable)
/// @param[in] value The new value for the string
void set_value(const std::string &value);
Expand Down
15 changes: 15 additions & 0 deletions isobus/src/isobus_virtual_terminal_objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/// @copyright 2023 The Open-Agriculture Developers
//================================================================================================
#include "isobus/isobus/isobus_virtual_terminal_objects.hpp"
#include "isobus/isobus/isobus_virtual_terminal_server_managed_working_set.hpp"

namespace isobus
{
Expand Down Expand Up @@ -3331,6 +3332,20 @@ namespace isobus
return stringValue;
}

std::string OutputString::displayed_value(std::shared_ptr<isobus::VirtualTerminalServerManagedWorkingSet> parentWorkingSet) const
{
if (isobus::NULL_OBJECT_ID != get_variable_reference())
{
auto child = get_object_by_id(get_variable_reference(), parentWorkingSet->get_object_tree());

if ((nullptr != child) && (isobus::VirtualTerminalObjectType::StringVariable == child->get_object_type()))
{
return std::static_pointer_cast<isobus::StringVariable>(child)->get_value();
}
}
return get_value();
}

void OutputString::set_value(const std::string &value)
{
stringValue = value;
Expand Down

0 comments on commit 4282fda

Please sign in to comment.