Author Topic: Specifying namespace for generated c++ code.  (Read 3347 times)

adutoit

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Specifying namespace for generated c++ code.
« on: October 14, 2003, 08:10:23 am »
Hi.

I would like to know how does one specify the namespace to use for generated c++ headers?

I.e.; if I want all my generated classes to reside in namespace "foo" (sorry for the over-used but ever handy identifier), where and how do I specify this in the project settings?  Is this possible?

I.e. for a vanilla generated class A; which will look like this:

namespace foo
{
class A
{
};
}

How do I get generated classes to be contained in a namespace as above?

It does not seem like the only reference to namespaces I found in EA is what I need.

I am probably missing some obvious detail somewhere.

Greetings,
Andre

benc

  • EA Administrator
  • EA User
  • *****
  • Posts: 200
  • Karma: +0/-0
    • View Profile
Re: Specifying namespace for generated c++ code.
« Reply #1 on: October 16, 2003, 12:35:32 am »
Hi adutoit,

Currently this would only be possible for forward generation of the class.  You would need to modify the "File" and "Namespace" code generation templates for C++. For more details, search the help file under "Code Templates" and use the default C# templates as a guide.  Also make sure the Advanced option is checked in the Code Template Editor to make the namespace templates visible.

Over the coming months we will be enhancing support for namespaces in code engineering.

Hope this helps.

Regards,
Ben

Rob7795

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Re: Specifying namespace for generated c++ code.
« Reply #2 on: December 02, 2003, 06:35:13 pm »
Hi Ben, using your instructions I've just tried to implement a C++ namespace environment that follows Java where each directory represents a new namepace and thus can be nested.

I'm now at a point where I don't think it is possible with the current release of EA.  In C# and Java you can introduce a namespace such as:

// c#
namespace a.b {
                               class x
                               {
                               };
}

or simply:

// java
package a.b;
class x
{
};

Unfortunately, you can't do this in C++ - yet.  You have to name the nestings each their own block:

//c++
namespace a {
   namespace b {
                               class x
                               {
                               };
   }
}

A reference to "x" would be qualified "a::b::x" (btw: the macro $packagePath only uses "." instead of "::").  There are work in the C++ standards community to be able to use the following sytax:

// (c++)++
namespace a::b {
                               class x
                               {
                               };
}
//note the continued use of "::" though!

Anyway, Ben, if there is any possible way of getting around this issue with the current implementation, macros, and templates, could you please post a solution.  Failing that, I guess we have to wait for the enhanced namespae support (is there a date for its availability yet?).

Cheers, Rob.

benc

  • EA Administrator
  • EA User
  • *****
  • Posts: 200
  • Karma: +0/-0
    • View Profile
Re: Specifying namespace for generated c++ code.
« Reply #3 on: February 24, 2004, 06:45:41 pm »
Hi Rob and Andre,

EA 4.0 should address this limitation for C++. This version is currently available to registered users as a beta release.

I hope this helps.

Regards,
Ben