Custom namespace

Ideasman wrote in another post he uses his own namespace GDA::

I find that fascinating, but I'm wondering what all is involved in making your own namespace. Do you have to make a class? If so what is in the class...
I would like to see how you go about this... (please and thank you)
It's actually quite simple; just name one and put things in it with the syntax described here:
http://www.cplusplus.com/doc/tutorial/namespaces/#namespace

Post again if you have any questions.
@pearlyman


Have a read of this, only if you have lots & lots of time ! It's complicated (normally a 4th year subject)

http://www.icsm.gov.au/gda/gdatm/gdav2.3.pdf


Edit: GDA stands for Geocentric Datum Australia

I am doing chapters 4 to 6 Vincenty Inverse & Direct, Redfearn's formulae.

Redfearn is a real ripper, have to apply all of those formulae to potentially 5 million points in a file !!

So with the namespace, I have this (short and rough)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
namespace GDA {

class VIncentyInverse {
   private:
      calcSinSqOmega()
   public:
       CalcAllValues();

}; // end class VIncentyInverse


} // end ns GDA

//else where

GDA::VIncentyInverse VincentyTemp;

VincentyTemp.CalcAllValues();

	



For a real good look at namespaces check out the Boost libraries. They have lots of nested namespaces For example boost::geometry

http://www.boost.org/doc/libs/1_55_0/libs/geometry/doc/html/geometry/spatial_indexes/rtree_examples/quick_start.html

Only 5 million points? Here I was starting to get impressed by you.... LOL

Man, that stuff is way over my head, Kinda like trying to hit Jupiter with a sling shot.

I'm staying away from boost and others... I want to learn pure C++... I view boost like a shortcut. kinda like cheating. Like when I hire a new helper and they ask me for "Tips and shortcuts"... I have the same answer, "Tip one, forget the shortcuts, learn the trade", "Shortcut #1, think it through before you cut the board."
:)

Last edited on
Only 5 million points?


Well, the goal is to write efficient code, so it will still work well with 100 million or even 1 billion.

Those formulae look complicated, actually it's not that hard to write code for them - it's easy to plug in code when the formula is in front of you. The slightly trickier part is looking for things that might be calc'd multiple times, but don't need to be. As in sin(omega) appears multiple times in a group of equations to be iterated (in the math sense) over, but the value only needs to be calc'd once at the start, or maybe once per iteration, as opposed to once for each equation.

With the namespace thing, as Zhuge says it is very simple.

Kinda like trying to hit Jupiter with a sling shot.


No worries, I'll put my steel caps on, and give a previous colleague a boot up the ass - sending him into orbit around Jupiter !
closed account (E0p9LyTq)
pearlyman wrote:
I'm staying away from boost and others... I want to learn pure C++... I view boost like a shortcut


Several boost ideas were added to C++11, apparently.

http://meetingcpp.com/index.php/br/items/c11-and-boost.html

Some parts of the Standard Library in C++11 are predated in boost. When playing around with C++11, you get used to using some parts in the Standard Library that are used in C++03 with their boost counterpart.

*snip*

And as C++ moves forward, especially the library features are available to a certain extend in boost. boost::filesystem is the most obvious library which already exists today and has made its way through standardization, soon being a TS and most likely part of C++1y. boost::thread already offers future::then, maybe the TS for concurrency also will lead to an executor and taskbased parallelism library in boost.
@FurryGuy

That's fine. Learning C++ will keep me busy for a while... If they can do it in boost, I can be done in C++, just a longer method to get there. As they add it to c++, I'll consider it.
For my purposes, I don't think I need it.

@TheIdeasMan
No worries, I'll put my steel caps on, and give a previous colleague a boot up the ass - sending him into orbit around Jupiter !
Remind me not to piss you off... lol

What I'm looking to do, is say for example... import cout into a namespace, and redefine it.
Maybe... i dunno, have it print red instead of white. Then I can do something like

std :: cout << "You straighten the shield, and hear a faint click.";
erh::cout1 << "The door behinds you slams shut"<<std :: endl; (prints in red)
erh::cout2 << "You are trapped." << std :: endl; (Prints in cyan)

I know I can do it with functions, but making a call every time you want a new color text sucks. It'd be easier to call another namespace.. Just messin around... Any ideas?
I deal a lot with DLLs. I find it useful to create a namespace for each DLL. That way I always know which DLL some is getting pulled from and I have no worries about names colliding when using multiple DLLs.

pearlyman wrote:
I know I can do it with functions, but making a call every time you want a new color text sucks.

Why not create io manipulators to change colors?
 
std::cout << erh::red << "The door behinds you slams shut"<<std :: endl;

closed account (E0p9LyTq)
pearlyman wrote:
making a call every time you want a new color text sucks.


Why not use a custom library already created?

http://www.cplusplus.com/articles/Eyhv0pDG/

I've used it before and it makes changing colors in a Win Console very easy.
The answer FurryGuy is "Then, I learn nothing."
It's easy to slap someone elses code in your program and proclaim "Look what I've made"... when I say it, I like to mean it. :) Guess I'm kinda hard headed that way, but I do appreciate your advice, and thank you all for your ideas. I'll look into each of them I assure you.
Last edited on
pearlyman wrote:
"Look what I've made"... when I say it, I like to mean it.


While at school teachers get their students to write their own programs for sorting, linked lists, queues, trees, graphs and many other things, so that they get an appreciation for how things work behind the scenes and teach them how to program at the same time.

But once one is past that stage, then it makes sense to use whatever facilities are available, so using the STL or other libraries / frameworks for example becomes the learning focus.


Also, in terms of one person being impressed by another: although nice to get that feedback, the thing is that it is all relative. I think it's important to have a realistic view of where one sits in the scheme of things, or at least not have others think that I am much better than I actually am.

Imagine an absolute beginner who started c++ literally 5 min ago, they might be given a "score" of 1. Now I might subjectively give myself a "score" of 1,000. The beginner thinks I am a genius, some one else with "score" of 200 is really impressed. But the hard truth is that there is a whole spectrum of others, a substantial number who might have a "score" of 100,000 or even 1,000,000.

I spend a lot time helping beginners, and I might subjectively put myself at the lower end of "Intermediate" - there is still plenty of new things to learn, and the learning never stops.
Topic archived. No new replies allowed.