Huskinu
Topic Author
Posts: 8
Joined: 15 Mar 2021, 05:40

How to declare the reflection for a template cpp class

01 Apr 2021, 09:45

Hi Noesis,
So supposing I have a template class like this:
static constexpr const char sControlTypeName[] = "CustomControlType";
template <class Type, const char* Param = sControlTypeName>
class FCustomControl : public Noesis::UserControl
{};
How should I fill in for say
FCustomControl<float, sControlTypeName>
class type in this macro?
NS_DECLARE_REFLECTION(<?>, UserControl)
and
NS_IMPLEMENT_REFLECTION(<?>, "CustomControl")
These are what I have tried but just no success:
NS_DECLARE_REFLECTION(FCustomControl, UserControl)
NS_IMPLEMENT_REFLECTION(FCustomControl<float, sControlTypeName>, "CustomControl"){}
I'm not sure it is even allowed though.
Thanks.

Tags:
 
Huskinu
Topic Author
Posts: 8
Joined: 15 Mar 2021, 05:40

Re: How to declare the reflection for a template cpp class

01 Apr 2021, 10:13

Oh I tried:
NS_IMPLEMENT_INLINE_REFLECTION_(FCustomControl, UserControl, Noesis::IdOf("CustomControl<", Noesis::IdOf<Type>(), ">"))
and it compiles.
 
User avatar
sfernandez
Site Admin
Posts: 2109
Joined: 22 Dec 2011, 19:20

Re: How to declare the reflection for a template cpp class

01 Apr 2021, 13:15

As you found the reflection for templated classes should be defined inside the class definition using NS_IMPLEMENT_INLINE_REFLECTION macro.
If you want to use those custom controls in xaml I suggest you use a name that doesn't contain '<' '>' characters, something more like:
NS_IMPLEMENT_INLINE_REFLECTION_(FCustomControl, UserControl, Noesis::IdOf(Noesis::IdOf<T>(), "CustomControl"))
 
Huskinu
Topic Author
Posts: 8
Joined: 15 Mar 2021, 05:40

Re: How to declare the reflection for a template cpp class

04 Apr 2021, 17:05

Yeap, thanks for your confirmation! Indeed, if I use say "CustomControl<float>", there will be an error about some invalid token.

Who is online

Users browsing this forum: psydeus and 4 guests