The Jucer and namespaces

Hi All,

I have a couple of questions and observations about the way that the Jucer deals with namespaces in the code it generates.

When the Jucer generates a new Component class, it would appear that this component is in the global namespace. Or am I missing something? Is there anyway to specifiy that the Jucer wrap generated classes in a namespace? Perhaps this should be a new field in the “Class” tab in Jucer?

It seems that when adding a generic component in the Jucer, there is no way to specify a namespace for that component. Or is there an option I’m not aware of? As a result of this, I’ve found that I need to put my custom component classes in the juce namespace or the global namespace. I’d prefer the option of being able to put custom components in some other namespace, but it is rather inconvenient to do so at this point.

Thanks,
Eric J

It’s not something I’d thought about, really.

If all your components are going into one namespace, you could change the jucer template file to include a namespace declaration for all the things it generates?

Indeed, this method sounds good but it’s not working !
Normally in Jucer generated files, the namespace is “juce”, and all the juce components are refered to without any profix (for example “Slider” instead of “juce::Slider”) which works…until you change the template’s namespace to something else, and then, the compiler rightfully reports juce components as being undeclared.

I know you’re working on the new jucer, so you probably don’t want to touch the old jucer code, however, could you please suggest a simple tweak of the old jucer source, so the components get the juce:: prefix ?

Ah, that’s annoying… Can’t you just add a “using namespace juce;” directive inside your own namespace?

Well I wanted to avoid that but if there’s not easy way to tweak the jucer so it adds “juce::”, then I’ll add a using directive

Ah and also, there’s another problem : if I put a using directive in the template, the problem with juce components disapears, however, if I include the juce file into another jucer file (by using the “new jucer component” option in the context menu), the namespace is not specified in the including file :

my_jucer_component.h :

using namespace juce;

namespace n1
{
	namespace n2
	{

		class myComponent  : public Component, //myComponent belongs to n1::n2 namespace
// bla bla bla
        
       }
}
addAndMakeVisible (component = new myComponent()); // myComponent doesn't belong to the global namespace so it's not found

Of course, we can solve this with another “using” directive, but then we have “using namespace juce” AND “using namespace customNamespace” which doesn’t prevent name clashes at all.

However, there’s a workaround : including the jucer component as a Generic component, instead of a Jucer component. A bit less convenient but it’s working.