Problem with juce namespace


#1

Hi Jules,

I’ve a little problem while compiling with juce when both DONT_SET_USING_JUCE_NAMESPACE and JUCE_NAMESPACE are set.

I’m using other namespaces where some symbols are redefined compared to Juce. For example, the tchar, uint8, uint32 and so on are not typedef the same way.

So, the compiler reject the object because of “ambiguous symbol” (uint8, tchar, etc…)

I think the typedefs Juce is using should be in Juce namespace too, and the jucer should allow to prefix all the type by “juce::” if an option is set to use juce in its own namespace.

So, for people who don’t care about juce namespace, they will be no change, but for other, it’s possible to use juce in its own private namespace (no global types, no global macro (T ?) which mess template definition) and so on.

For information the offending types are in :
juce\src\juce_core\text\juce_CharacterFunctions.h
juce\src\juce_core\basics\juce_MathsFunctions.h

Please notify if you are going to fix this or if I should modify in my local copy.


#2

Good point - yes, those should also be in the namespace, and it’s just an oversight that they’re not. I’ll certainly move them over for the next version.


#3

…no, hang on, they are in the juce namespace… As you can see, there’s a namespace declared around the inclusion of juce_MathsFunctions.h in juce_StandardHeader.h

?


#4

Right, my mistake. I’ve written code like :

#define JUCE_NAMESPACE
#define DONT_SET_USING_JUCE_NAMESPACE
#define JUCE_DONT_DEFINE_MACROS 1
#include "../../juce/juce.h"

where the first line was wrong (further down the road, it defined namespace { } which is the global namespace hence the conflict).

However, about the jucer, it should have an option to write juce:: in front of each juce specific name (or made it the default value, as it won’t hurt).
Similarly, using JUCE_T instead of T will be better


#5

Yes, good point about the jucer, though it’d involve a lot of typing!


#6

Well another point :

Please define the START_JUCE_APPLICATION macro to be using the juce namespace for Strings and so on…


#7

I’ve made this change in juce.h:

#if defined (JUCE_GCC) || defined (__MWERKS__)

  #define START_JUCE_APPLICATION(AppClass) \
    int main (int argc, char* argv[]) \
    { \
        return JUCE_NAMESPACE::JUCEApplication::main (argc, argv, new AppClass()); \
    }

#elif JUCE_WIN32

  #ifdef _CONSOLE
    #define START_JUCE_APPLICATION(AppClass) \
        int main (int argc, char* argv[]) \
        { \
            return JUCE_NAMESPACE::JUCEApplication::main (argc, argv, new AppClass()); \
        }
  #elif ! defined (_AFXDLL)
    #ifdef _WINDOWS_
      #define START_JUCE_APPLICATION(AppClass) \
          int WINAPI WinMain (HINSTANCE, HINSTANCE, LPSTR commandLine, int) \
          { \
              JUCE_NAMESPACE::String commandLineString (commandLine); \
              return JUCE_NAMESPACE::JUCEApplication::main (commandLineString, new AppClass()); \
          }
    #else
      #define START_JUCE_APPLICATION(AppClass) \
          int __stdcall WinMain (int, int, const char* commandLine, int) \
          { \
              JUCE_NAMESPACE::String commandLineString (commandLine); \
              return JUCE_NAMESPACE::JUCEApplication::main (commandLineString, new AppClass()); \
          }
    #endif
  #endif

#endif

#8

Right. Good idea, thanks!


#9