Skip to content

Commit

Permalink
Refactored Entity op == to equal() method to work around op == in chi…
Browse files Browse the repository at this point in the history
…ldren
  • Loading branch information
wsobel committed Sep 24, 2024
1 parent ac8e44d commit ba01a70
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ set(AGENT_PREFIX "" CACHE STRING "Prefix for the name of the agent and the agent
set(CMAKE_INSTALL_DATADIR "${CMAKE_INSTALL_DATADIR}/mtconnect")

message(INFO " Shared build: ${SHARED_AGENT_LIB}")
set(CMAKE_OSX_DEPLOYMENT_TARGET 13.2)
set(CMAKE_OSX_DEPLOYMENT_TARGET 13.3)

project(cppagent LANGUAGES C CXX)

Expand Down
2 changes: 1 addition & 1 deletion conan/profiles/macos
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ include(default)
[settings]
compiler=apple-clang
compiler.cppstd=20
os.version=14.0
os.version=13.3

[system_tools]
cmake/>3.26.0
2 changes: 1 addition & 1 deletion conan/profiles/xcode
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ include(default)

[settings]
compiler.cppstd=20
os.version=14.0
os.version=13.3

[system_tools]
cmake/>3.23.0
Expand Down
4 changes: 2 additions & 2 deletions src/mtconnect/agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ namespace mtconnect {
return;
}

auto callback = [=](config::AsyncContext &context) {
auto callback = [=, this](config::AsyncContext &context) {
try
{
bool changed = false;
Expand Down Expand Up @@ -573,7 +573,7 @@ namespace mtconnect {
createUniqueIds(device);

LOG(info) << "Checking if device " << *uuid << " has changed";
if (*device != *oldDev)
if (!device->equal(*oldDev))
{
LOG(info) << "Device " << *uuid << " changed, updating model";

Expand Down
4 changes: 2 additions & 2 deletions src/mtconnect/buffer/circular_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ namespace mtconnect::buffer {
mutable std::recursive_mutex m_sequenceLock;

// Sequence number
volatile SequenceNumber_t m_sequence;
volatile SequenceNumber_t m_firstSequence;
SequenceNumber_t m_sequence;
SequenceNumber_t m_firstSequence;

// The sliding/circular buffer to hold all of the events/sample data
unsigned int m_slidingBufferSize;
Expand Down
19 changes: 12 additions & 7 deletions src/mtconnect/entity/entity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,16 +352,21 @@ namespace mtconnect {
/// @brief get the attributes for XML generation
/// @return attribute set
const auto &getAttributes() const { return m_attributes; }

/// @brief compare two entities for equality
/// @param other the other entity
/// @return `true` if they have equal name and properties
bool operator==(const Entity &other) const;
bool equal(const Entity &other) const;

/// @brief cover method for equal
/// @param other the other entity
/// @return `true` if they have equal name and properties
bool operator==(const Entity &other) const { return equal(other); }

/// @brief compare two entities for inequality
/// @param other the other entity
/// @return `true` if they have unequal name and properties
bool operator!=(const Entity &other) const { return !(*this == other); }
bool operator!=(const Entity &other) const { return !equal(other); }

/// @brief update this entity to be the same as other
/// @param other the other entity
Expand Down Expand Up @@ -446,7 +451,7 @@ namespace mtconnect {

bool operator()(const EntityPtr &other)
{
return *std::get<EntityPtr>(m_this) == *(other.get());
return std::get<EntityPtr>(m_this)->equal(*(other.get()));
}

bool operator()(const EntityList &other)
Expand All @@ -463,15 +468,15 @@ namespace mtconnect {
auto id = (*it)->getIdentity();
auto oit =
boost::find_if(other, [&id](const auto &e) { return id == e->getIdentity(); });
if (oit == other.end() || *(it->get()) != *(oit->get()))
if (oit == other.end() || !(it->get())->equal(*(oit->get())))
return false;
}
}
else
{
for (auto oit = other.cbegin(); it != list.cend(); it++, oit++)
{
if (*(it->get()) != *(oit->get()))
if (!(it->get())->equal(*(oit->get())))
return false;
}
}
Expand Down Expand Up @@ -499,7 +504,7 @@ namespace mtconnect {

inline bool operator!=(const Value &v1, const Value &v2) { return !(v1 == v2); }

inline bool Entity::operator==(const Entity &other) const
inline bool Entity::equal(const Entity &other) const
{
if (m_name != other.m_name)
return false;
Expand Down

0 comments on commit ba01a70

Please sign in to comment.