Book a Demo

Author Topic: Namespaces and C++ code generation  (Read 5043 times)

clearwa

  • EA Novice
  • *
  • Posts: 13
  • Karma: +0/-0
    • View Profile
Namespaces and C++ code generation
« on: April 26, 2008, 10:41:08 pm »
I am attempting to generate C++ source from a class model.  I have a set of packages that looks like this:

Root
-Package1
--Package2
--Package3

I've set Package1 as a namespace root; I want the classes generated in packages 1&2 to be in their appropriate namespaces, ie. I'd expect to see code of the form

namespace Package2 {
...
};

I've set C++ options to generate namespaces.  I've had a look at the templates but I really don't want to fiddle around in that area.  Does anyone have some insight for me here?

Thanx in advance,
Allan Clearwaters

Falconne

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Namespaces and C++ code generation
« Reply #1 on: April 27, 2008, 02:22:53 pm »
I have the same problem. Anyone know how to solve this?

Kevin G. Watson

  • EA User
  • **
  • Posts: 217
  • Karma: +0/-0
  • I love EVERYTHING including Microsoft
    • View Profile
Re: Namespaces and C++ code generation
« Reply #2 on: April 27, 2008, 04:34:51 pm »
 [smiley=2vrolijk_08.gif] Hi ya

Eerm... what are you getting?

namespace-1 {
        namespace-2 {
                  .....
                             }
        }

?

Kevin

Falconne

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Namespaces and C++ code generation
« Reply #3 on: April 27, 2008, 08:41:15 pm »
No, I am getting nothing. I have created packages at various levels and set them as "Namespace Roots" but they don't get generated to namespace { ... } the class definitions just get generated without a namespace.

Even if I reverse engineer simple code with namespace definitions, they don't get resolved into packages (and regenerating code from that immediately afterwards just creates flat definitions without namespaces).

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Namespaces and C++ code generation
« Reply #4 on: April 28, 2008, 12:36:49 pm »
Packages set as namespace root are not generated as namespace.  In the example from the first post, Package1 should be a namespace root (it represents the root level namespace) and Package2 and Package3 should not (they need to be generated).

That sounds like what the first poster is doing, and it should work.  If you want to reverse engineer namespaces into packages you'll need to use import source directory.

Falconne

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Namespaces and C++ code generation
« Reply #5 on: April 28, 2008, 01:00:05 pm »
Thanks Simon. I misunderstood the documentation.

The namespaces topic was only talking about Java and it seemed to imply that a package had to be set as a namespace root for a "package" keyword to be added to the top of classes defined inside that package (I may have misunderstood that as well). I assumed it was the same theory for c++ namespaces.

DanG83616

  • EA User
  • **
  • Posts: 180
  • Karma: +0/-0
    • View Profile
Re: Namespaces and C++ code generation
« Reply #6 on: May 02, 2008, 04:17:22 am »
The Select Property Type dialog is irritating me. My C++ namespace is

namespace Insitu
{
   namespace Component
   {
   };
};

My model for the component has Class Model and under that imported source for the component.

MyModel
- ComponentPackage <- version controlled
---Class Model <- marked as root to get the correctly generated code
-----Insitu
-------Component

Select Property Type dialog presents Class Model in the In Namespace pulldown. All of my components are structured as above. Thus, when working on a composition involving more than one component the In Namespace lets me select from n Class Model options. I'm glad they are all listed but I'd rather see Insitu.ComponentA, Insitu.ComponentB, etc. As it is I have to click and see. It's not horrible but could be nicer. Any suggestions?

thx