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

Discussion in 'C++' started by db, Apr 13, 2004.

  1. db

    db Guest

    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.
    db, Apr 13, 2004
    #1
    1. Advertising

  2. db

    Bill Seurer Guest

    db wrote:

    > 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.
    Bill Seurer, Apr 13, 2004
    #2
    1. Advertising

  3. db

    db Guest

    On Tue, 13 Apr 2004 08:04:30 -0500
    Bill Seurer <> wrote:

    > > 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.


    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
    db, Apr 13, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?UnVkeQ==?=

    Sub Dir, Virtual dir, what do I use?

    =?Utf-8?B?UnVkeQ==?=, Jun 12, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    411
    =?Utf-8?B?UnVkeQ==?=
    Jun 12, 2005
  2. Matthew Denner
    Replies:
    1
    Views:
    157
  3. Kga Agk
    Replies:
    2
    Views:
    138
    Kga Agk
    Jun 29, 2009
  4. Dave
    Replies:
    0
    Views:
    108
  5. Nick Gnedin
    Replies:
    2
    Views:
    148
Loading...

Share This Page