c++ vector etc

c++ vector etc

Postby Dan » Wed 23 May 2018 17:10

Hi all,

What do I change in the code generation panel such that

Code: Select all
#include <vector>
using namespace std;

class Test {
  private:
    vector<int> m_vector;
... };


becomes

Code: Select all
#include <vector>
// using namespace std;

class Test {
  private:
    std::vector<int> m_vector;
... };


As it is not a good idea to put "using namespace std" in a header,

Thanks
Dan
 
Posts: 33
Joined: Sat 12 May 2018 13:55
Location: England

Re: c++ vector etc

Postby Bruno Pagès » Wed 23 May 2018 17:40

Edit the generation settings, go in the tab C++5 and modify the definitions as you want, adding '//' before the forms using or removing the second line to not have the forms using

Warning, if you use the stereotype 'vector' the code generation will replace '${stereotype}' by 'vector', not 'std::vector', if you want 'std::vector' you have to use the stereotype 'std::vector' etc
ImageAuthor of Bouml
Bruno Pagès
 
Posts: 596
Joined: Mon 20 Feb 2012 09:23
Location: France

Re: c++ vector etc

Postby Dan » Thu 24 May 2018 12:17

Bruno Pagès wrote:Edit the generation settings, go in the tab C++5 and modify the definitions as you want, adding '//' before the forms using or removing the second line to not have the forms using


Ok, got that.

Warning, if you use the stereotype 'vector' the code generation will replace '${stereotype}' by 'vector', not 'std::vector', if you want 'std::vector' you have to use the stereotype 'std::vector' etc


This is what I did - not sure if all these steps are needed.

#1 Edit default stereotypes - > class - >added 'std::vector' to attribute stereotypes line.
#2 Edit generations settings -> stereotypes -> added uml = std::vector , c++ = std::vector to attributes and relations...
#3 Edit generations settings -> c++[5] -> added std:vector as external type, and #include <vector> types

Test: on a class add attributes
m_vector, stereotype: vector, type: double, multiplicity *
m_stdvec, stereotype: std::vector, type: double, multiplicity *

Running generate c++, I get:

Code: Select all
#include <vector>
// using namespace std;

class Test {
  private:
    vector<double> m_vector;
    std::vector<float> m_stdvec;
};



So seems to work as expected.

But in the project browser I notice that the attribute lines look like:

Code: Select all
a- <<vector>> m_vector
a- <<:vector>> m_stdvec


So, a visual bug as it does not show std::vector ?

Thanks.
Dan
 
Posts: 33
Joined: Sat 12 May 2018 13:55
Location: England

Re: c++ vector etc

Postby Bruno Pagès » Thu 24 May 2018 16:34

Hello

When an element is stereotyped by a stereotype part of a profile the stereotype is memorized as 'profileName:stereotypeName', to show only 'stereotypeName' I search if there is a ':' in a stereotype and when it is the case I write only the text after that ':', both in the browser and in the diagrams. This is why 'std::vector' becomes ':vector'

I forgot that when I proposed you to use the stereotype std::vector, so the right way to not have that problem is :
  • optionally "edit default stereotypes" through the menu shown when you do a right mouse click on the project (first package) in the browser, go in 'class' tab and for instance add 'stdvector' in the lists, this allows to have 'stdvector' proposed in the stereotype list when you edit an attribute etc, but this is not mandatory because you can enter the stereotype you want when you edit an element
  • do "edit generation settings" through the menu shown when you do a right mouse click on the project (first package) in the browser, go in 'stereotypes' tab and on the first table add 'stdvector' as UML name and 'std::vector' for C++ (you can let the other columns empty). Now when the '${stereotype}' is 'stdvector' it will be replaced by 'std::vector' for C++

If you prefer in case there is a '::' I can write all rather than remove the prefix
ImageAuthor of Bouml
Bruno Pagès
 
Posts: 596
Joined: Mon 20 Feb 2012 09:23
Location: France

Re: c++ vector etc

Postby Dan » Fri 25 May 2018 10:08

Hi,

OK I amended as you suggested and that works, both the class diagram and generated class show std::vector, while the attributes line on the project browser shows stdvector - which is a stereotype so is just fine,

Thanks.
Dan
 
Posts: 33
Joined: Sat 12 May 2018 13:55
Location: England


Return to Examples - How to do / Exemples - Comment faire

Who is online

Users browsing this forum: No registered users and 1 guest

cron