C++ ENUM with stingification

Please use this forum for open discussions about Bouml.
Merci d'utiliser ce forum pour des discussions ouvertes à propos de Bouml.

C++ ENUM with stingification

Postby fredcwbr-GO » Wed 25 Jul 2018 18:03

I'm learning UML , and decided to use BOUML as my tool.

The goal that I'm trying to achieve here is to have a class that behaves like an enum , and also has a method for returning the string of that enum. C++11
already has something on that , but for other reasons I need to stick to C++03 .... , so ....


At this moment, struggling to understand how to express a C++ enum with autogeneration of strings . what I did was using
the X macro substitution trick to generate the enums and associated strings in one code., by
creating a a class with a stereotype of <<enum>> , and edited it with the following declaration:

${comment} enum ${name} {
#define X(ENM) ENM
${items}
#undef X
};


${comment} static const char *s_${name}[] {
#define X(ENM) #ENM
${items}
#undef X
};



It works on generate, but i cannot get it round trip or reverse engineer ...
So think doing it wrong..
Read about the EM , but couldn't figure how to do it.,

So acctually my question is .. -- Whats the right way of doing this?..
fredcwbr-GO
 
Posts: 4
Joined: Wed 25 Jul 2018 15:05
Location: Brasil

Re: C++ ENUM with stingification

Postby Bruno Pagès » Wed 25 Jul 2018 19:20

hello,

The reverse/roundtrip don't manage preprocessor, so #define etc are discarded out of the body of the operations

The array s_xxx will be bypassed by the reverse/roundtrip too because it has no equivalent in UML

However since I added the artifact extra definition I am able to memorize forms like the array s_xxx, and the extra class members allow me to memorize the #define/#undef X into the enum definition, but the C++ reverse/roundrip don't do that today
ImageAuthor of Bouml
Bruno Pagès
 
Posts: 655
Joined: Mon 20 Feb 2012 09:23
Location: France

Re: C++ ENUM with stingification

Postby fredcwbr-GO » Thu 26 Jul 2018 12:21

If I understood you correctly, it would be valid to state that this kind of construction would be represented by a UML stereotype of itself?.
fredcwbr-GO
 
Posts: 4
Joined: Wed 25 Jul 2018 15:05
Location: Brasil

Re: C++ ENUM with stingification

Postby fredcwbr-GO » Thu 26 Jul 2018 12:24

On the same issue, I found the Extra Artifact Dialog,
Gonna try that ..
Thanks in advance.,
fredcwbr-GO
 
Posts: 4
Joined: Wed 25 Jul 2018 15:05
Location: Brasil

Re: C++ ENUM with stingification

Postby Bruno Pagès » Thu 26 Jul 2018 14:21

sorry, visibly I wasn't enough clear in my answer

fredcwbr-GO wrote:If I understood you correctly, it would be valid to state that this kind of construction would be represented by a UML stereotype of itself?.

BoUML is first a UML modeleur, this means the supporting elements in the model are UML ones, there are class, relation etc, and the reverse/roundtrip C++ mainly create/update these standard UML elements.

A #define form for instance has no equivalent into UML, to manage them it is needed to add extensions, and for instance I added the artifact extra definition recently, but the C++ reverse/roundtrip do not use them currently, contrarily to the Php reverse/roundtrip.

Currently I use the extra member definition typically for the friend class forms.

In your specific case you can generate the expected source code without using these extensions, but this is not always possible, and a reverse/roundtrip cannot be so specific and for non standard UML cases it will use extensions or bypass these cases.

fredcwbr-GO wrote:On the same issue, I found the Extra Artifact Dialog,
Gonna try that ..
Thanks in advance.,


Note this will change nothing for a roundtrip (and of course a reverse), I mean it will bypass the #... like before. If I simplify the roundtrip works like a reverse then look at the model to update it, so while the 'reverse part' doesn't manage the #... the fact you use or not extension in your model for them change nothing.
ImageAuthor of Bouml
Bruno Pagès
 
Posts: 655
Joined: Mon 20 Feb 2012 09:23
Location: France

Re: C++ ENUM with stingification

Postby fredcwbr-GO » Thu 26 Jul 2018 15:20

Bruno Pagès wrote:Note this will change nothing


I see what you mean now.
Thanks in advance for your candid replies, and support.

Will continue on with my project, and learning on .. .

Best regards, ...

Fred
fredcwbr-GO
 
Posts: 4
Joined: Wed 25 Jul 2018 15:05
Location: Brasil


Return to Open discussions / Discussions ouvertes

Who is online

Users browsing this forum: No registered users and 2 guests

cron