Skip to content

Commit

Permalink
Removed using directive in derived message router classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jwellbelove committed Nov 29, 2024
1 parent 27f200e commit e422be6
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -388,3 +388,6 @@ support/time remaining test.xlsx
test/vs2022/Debug MSVC C++20 - Force C++03
test/vs2022/Release MSVC C++20 - No STL - Optimised -O2 - Sanitiser
test/test_file_list.txt
examples/QueuedMessageRouter/vs2022/.vs/QueuedMessageRouter/CopilotIndices
examples/QueuedMessageRouter/vs2022/.vs/QueuedMessageRouter/FileContentIndex
examples/QueuedMessageRouter/vs2022/.vs/QueuedMessageRouter/v17
2 changes: 0 additions & 2 deletions examples/QueuedMessageRouter/QueuedMessageRouter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ class Router : public etl::message_router<Router, Message1, Message2, Message3>

typedef etl::message_router<Router, Message1, Message2, Message3> Base_t;

using Base_t::receive;

//***************************************************************************
Router()
: message_router(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,26 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
Expand Down
93 changes: 93 additions & 0 deletions test/test_message_router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,77 @@ namespace
int sender_id;
};

//***************************************************************************
// Router that handles messages 1, 2, 3.
// 'receive' is overridden.
//***************************************************************************
class Router3 : public etl::message_router<Router3, Message1, Message2, Message3>
{
public:

using base = etl::message_router<Router3, Message1, Message2, Message3>;

Router3()
: message_router(ROUTER3)
, message1_received(false)
, message2_received(false)
, message3_received(false)
, unknown_message_received(false)
{
}

void receive(const etl::imessage& msg) override
{
switch (msg.get_message_id())
{
case MESSAGE1:
{
message1_received = true;
break;
}

case MESSAGE2:
{
message2_received = true;
break;
}

case MESSAGE3:
{
message3_received = true;
break;
}

default:
{
unknown_message_received = true;
break;
}
}
}

void on_receive(const Message1& msg)
{
}

void on_receive(const Message2& msg)
{
}

void on_receive(const Message3& msg)
{
}

void on_receive_unknown(const etl::imessage&)
{
}

bool message1_received;
bool message2_received;
bool message3_received;
bool unknown_message_received;
};

etl::imessage_router* p_router;

SUITE(test_message_router)
Expand Down Expand Up @@ -641,5 +712,27 @@ namespace
CHECK_EQUAL(0, r1.message4_count);
CHECK_EQUAL(0, r1.message_unknown_count);
}

//*************************************************************************
TEST(message_router_with_overloaded_receive)
{
Router3 router;
etl::imessage_router& irouter = router;

Message1 message1(router);
Message2 message2(router);
Message3 message3(router);

router.receive(message1);
CHECK_TRUE(router.message1_received);

router.receive(message2);
CHECK_TRUE(router.message2_received);

router.receive(message3);
CHECK_TRUE(router.message3_received);

CHECK_FALSE(router.unknown_message_received);
}
};
}

0 comments on commit e422be6

Please sign in to comment.