Structure of the code (files, dir's, namespaces, makefiles)

D

db

Hey group

I'm rewriting a small program called lockdown and need a little help
structuring the code. In the past I didn't use nested namespaces and I
placed all my files in one directory. This time I tried to change this,
but ran into some beginner problems. I have:
namespace lockdown;
namespace lockdown::io;
namespace lockdown::io::in;
namespace lockdown::io::eek:ut;
namespace lockdown::modifiers;
I've made a dir to every namepace, so I have:
io
io/in
io/out
modifiers
btw I'm using FreeBSD and gcc.
The lockdown::io::in namespace is defined in io/in.hpp, but first
mentioned in io.hpp. All the code (classed and functions) for that
namespace is placed in the io/in dir.
Let's look at io.hpp:
#ifndef LOCKDOWN_IO_HPP
#define LOCKDOWN_IO_HPP
#include "lockdown.hpp" //Here lockdown::io is mentioned for the first time
namespace lockdown { namespace io {
//nested namespace where the definition is in the dir
lockdown/io/out.hpp namespace out {}
namespace in {}
class IOException;
//Class definition is in lockdown/io/File.hpp
class File;
}}

Is that the right way of doing it? Or should I #include the definition
of the namespaces and classes/functions?

Next question is about Makefile's. In every dir I have a Makefile that
compiles every file and dir in that dir and makes a "dir".o file and
place it in the above dir. Let's take a look at some Makefile's:
The Makefile in lockdown/io/out
CXX ?= g++
CFLAGS += -Wall

all: Output.o
cp Output.o ../out.o

Output.o: Output.hpp
$(CXX) $(CFLAGS) -c Output.cpp -o $@

clean:
rm -f *.o

In lockdown/io/Makefile I have:
CXX ?= g++
CFLAGS += -Wall

all: out.o File.o
$(CXX) $(CFLAGS) -shared File.o out.o -o ../io.o

out.o:
make -C out all

File.o: File.hpp
$(CXX) $(CFLAGS) -c File.cpp -o $@

clean:
rm -f *.o
make -C out clean

Is that how it is done? The problem here is that I don't want to use
shared objects, but I can't see how to avoid it (don't want to include
very .o file in the entire project then linking the final lockdown
executable).

br
db

Btw: I can send you the code if you wanna see it...just don't download
it from lockdown.trunet.dk as it is an old version.
 
B

Bill Seurer

db said:
Hey group

I'm rewriting a small program called lockdown and need a little help
structuring the code. In the past I didn't use nested namespaces and I
placed all my files in one directory. This time I tried to change this,
but ran into some beginner problems. I have:
namespace lockdown;
namespace lockdown::io;
namespace lockdown::io::in;
namespace lockdown::io::eek:ut;
namespace lockdown::modifiers;
I've made a dir to every namepace, so I have:

Whoa! Slow down there. Why do you think you need all these namespaces
with separate directories for each for this small program? If you can't
answer this question then you have gone too far.
 
D

db

Whoa! Slow down there. Why do you think you need all these
namespaces with separate directories for each for this small program?
If you can't answer this question then you have gone too far.

Since it is much a small program and I'll end up having just one huge
executable file, I could survice with just one namespace and all files
in one dir. I know it is overhead , but surly this doesn't matter?
I find the above structering of the code logical and I find it naturally
to relect this in the psysical world (with files and dir's)!?!?!

br
db
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top