From ad80c2c4d75687c3b3bb1a6cd2bb22e1e5a614d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Tue, 13 Oct 2020 09:54:41 +0200 Subject: [PATCH] [ion/keyboard] Do not define constexpr arrays in headers They are duplicated in each compilation unit where they are called --- ion/Makefile | 2 ++ ion/include/ion/keyboard/layout_events.h | 24 +++++++++++++++++++ .../keyboard/layout_B2/layout_events.cpp} | 16 +++---------- .../keyboard/layout_B3/layout_events.cpp} | 16 +++---------- 4 files changed, 32 insertions(+), 26 deletions(-) create mode 100644 ion/include/ion/keyboard/layout_events.h rename ion/{include/ion/keyboard/layout_B2/layout_events.h => src/shared/keyboard/layout_B2/layout_events.cpp} (91%) rename ion/{include/ion/keyboard/layout_B3/layout_events.h => src/shared/keyboard/layout_B3/layout_events.cpp} (91%) diff --git a/ion/Makefile b/ion/Makefile index 6efea82b8..c49f13277 100644 --- a/ion/Makefile +++ b/ion/Makefile @@ -10,6 +10,8 @@ ifndef ION_KEYBOARD_LAYOUT $(error platform.mak should define ION_KEYBOARD_LAYOUT) endif SFLAGS += -Iion/include/ion/keyboard/$(ION_KEYBOARD_LAYOUT) +SFLAGS += -Iion/include/ion/keyboard/ +ion_src += ion/src/shared/keyboard/$(ION_KEYBOARD_LAYOUT)/layout_events.cpp include ion/src/$(PLATFORM)/Makefile -include ion/test/$(PLATFORM)/Makefile diff --git a/ion/include/ion/keyboard/layout_events.h b/ion/include/ion/keyboard/layout_events.h new file mode 100644 index 000000000..21cdaeed0 --- /dev/null +++ b/ion/include/ion/keyboard/layout_events.h @@ -0,0 +1,24 @@ +#ifndef ION_KEYBOARD_LAYOUT_EVENTS_H +#define ION_KEYBOARD_LAYOUT_EVENTS_H + +#include +#include +#include "event_data.h" + +namespace Ion { +namespace Events { + +extern const EventData s_dataForEvent[4*Event::PageSize]; + +#ifndef NDEBUG +extern const const char * s_nameForEvent[255]; + +inline const char * Event::name() const { + return s_nameForEvent[m_id]; +} +#endif + +} +} + +#endif diff --git a/ion/include/ion/keyboard/layout_B2/layout_events.h b/ion/src/shared/keyboard/layout_B2/layout_events.cpp similarity index 91% rename from ion/include/ion/keyboard/layout_B2/layout_events.h rename to ion/src/shared/keyboard/layout_B2/layout_events.cpp index d0621d3d6..24518533e 100644 --- a/ion/include/ion/keyboard/layout_B2/layout_events.h +++ b/ion/src/shared/keyboard/layout_B2/layout_events.cpp @@ -1,14 +1,10 @@ -#ifndef ION_KEYBOARD_LAYOUT_B2_EVENTS_H -#define ION_KEYBOARD_LAYOUT_B2_EVENTS_H - -#include -#include "../event_data.h" +#include namespace Ion { namespace Events { static_assert('\x11' == UCodePointEmpty, "Unicode error"); -static constexpr EventData s_dataForEvent[4*Event::PageSize] = { +const EventData s_dataForEvent[4 * Event::PageSize] = { // Plain TL(), TL(), TL(), TL(), TL(), TL(), TL(), TL(), U(), U(), U(), U(), @@ -53,7 +49,7 @@ static constexpr EventData s_dataForEvent[4*Event::PageSize] = { #ifndef NDEBUG -static constexpr const char * s_nameForEvent[255] = { +const char * s_nameForEvent[255] = { // Plain "Left", "Up", "Down", "Right", "OK", "Back", "Home", "OnOff", nullptr, nullptr, nullptr, nullptr, @@ -97,13 +93,7 @@ static constexpr const char * s_nameForEvent[255] = { "None", "Termination", nullptr, nullptr, nullptr, nullptr, }; -inline const char * Event::name() const { - return s_nameForEvent[m_id]; -} - #endif } } - -#endif diff --git a/ion/include/ion/keyboard/layout_B3/layout_events.h b/ion/src/shared/keyboard/layout_B3/layout_events.cpp similarity index 91% rename from ion/include/ion/keyboard/layout_B3/layout_events.h rename to ion/src/shared/keyboard/layout_B3/layout_events.cpp index 0bdd59e56..6133c5787 100644 --- a/ion/include/ion/keyboard/layout_B3/layout_events.h +++ b/ion/src/shared/keyboard/layout_B3/layout_events.cpp @@ -1,14 +1,10 @@ -#ifndef ION_KEYBOARD_LAYOUT_B3_EVENTS_H -#define ION_KEYBOARD_LAYOUT_B3_EVENTS_H - -#include -#include "../event_data.h" +#include namespace Ion { namespace Events { static_assert('\x11' == UCodePointEmpty, "Unicode error"); -static constexpr EventData s_dataForEvent[4*Event::PageSize] = { +const EventData s_dataForEvent[4 * Event::PageSize] = { // Plain TL(), TL(), TL(), TL(), TL(), TL(), TL(), U(), TL(), U(), U(), U(), @@ -53,7 +49,7 @@ static constexpr EventData s_dataForEvent[4*Event::PageSize] = { #ifndef NDEBUG -static constexpr const char * s_nameForEvent[255] = { +const char * s_nameForEvent[255] = { // Plain "Left", "Up", "Down", "Right", "OK", "Back", "Home", "nullptr", "OnOff", nullptr, nullptr, nullptr, @@ -97,13 +93,7 @@ static constexpr const char * s_nameForEvent[255] = { "None", "Termination", nullptr, nullptr, nullptr, nullptr, }; -inline const char * Event::name() const { - return s_nameForEvent[m_id]; -} - #endif } } - -#endif