This section of the archives stores flipcode's complete Developer Toolbox collection, featuring a variety of mini-articles and source code contributions from our readers.

 

  Using Classwizard To Browse Namespaces
  Submitted by



Hello, this is my first TOTD. I've grown quite fond of using the ClassWizard to organize and quickly locate my code. However, when using namespaces to organize code, they disappear. So, we can fool ClassWizard into thinking our namespaces are classes. Here is an example:

#ifdef NEVER
class Math
#else
namespace Math
#endif
{
	void CalcSomething();
}; 



ClassWizard reads the first "class Math" and puts the namespace in the ClassWizard pane. Since the function definition would be "void Math::CalcSomething()", you can actually double-click to go to the function. If you use some clever naming, you don't have to worry about knowing what is a class and what is a namespace, either.



There is an "extension" to this tip I use with this, but less frequently, because it's less convenient. In the above example, the members will all appear private. Say you have some internal function that is used only by members of that namespace. This is what I would do in that case:



#ifdef NEVER
#define MATH_FUNC( x ) Math::x
class Math
{
public:
#else
#define MATH_FUNC( x ) x
namespace Math
{
#endif
	void CalcSomething();
#ifdef NEVER
private:
	void InternalFunction();
#endif
}; 



and each function is defined in the .cpp like this:

void MATH_FUNC( InternalFunction )()
{
} 



As I said, I use this second part of the tip less frequently, because personally I feel it's more ugliness than worth. But in the second example the members that are accessible outside the namespace are shown as public, and the "internal" functions are shown private, but you can still use ClassWizard to navigate to them.

Enjoy.

crazy166


The zip file viewer built into the Developer Toolbox made use of the zlib library, as well as the zlibdll source additions.

 

Copyright 1999-2008 (C) FLIPCODE.COM and/or the original content author(s). All rights reserved.
Please read our Terms, Conditions, and Privacy information.