Main Page   Compound List   File List   Compound Members   File Members  

Building the overall structure

We start by writing a rough outline of the main loop.

But even before that, we set up the Makefile in such a way that it will be easy to add new source files etc. All we ever want to type is ``make'' or, perhaps, ``make check''.

For the ``check'' target we execute the command

        httpstats httpstats.config access_log 
where
  1. access_log is a part of the supplied log file. We only take a part, i.e. the first 10000 lines, because we want to be able to test quickly.
                    head -10000 access_log >my_access_log
    and then used scp to copy it to our development directory.

  2. httpstats.config is the default configuration file as in the project description.
Once these 3 files (Makefile, access_log, httpstats.config) are up, we start a new file, called httpstats.C to contain the main program.

The main program should do the following.

  1. Check whether the arguments are ok (configuration file name, log file name).
  2. Parse the configuration file, resulting in some object X representing the criteria etc. We call the class of X ``Configuration'' and we will have a boolean function Configuration::parse(istream&) that will do the parsing. It returns false if there are any errors in the configuration file.
  3. Process the log file, line by line, and process each line, using X. The processing will update another object Y that will contain the results. Processing the line involves:

  4. Print the results from Y.

All this results in the following draft file httpstats.C. Unfortunately, this file cannot be compiled ``as is'' since the following types are unknown to the compiler: Configuration, LogRecord, and Stats. So we quickly create the following files that define ``stub'' implementations of these classes:

We will also put the parse_line function in logrecord.h (and logrecord.C) since the function is intimately linked to LogRecord (it will probably be a friend).

After removing syntax errors, the compiled sources can be found in the stage00 directory. We added sensible CXXFLAGS to the Makefile and made the ``make check'' target output the time it takes to execute the command.

Here's the current Makefile:

# Makefile for project2000
#
CXXFLAGS = -g -Wall
#
# CCFILES will contain all C++ source files
# HFILES will contain all header files
# OBJECTS will contain all compiled C++ source files
CCFILES= httpstats.C configuration.C logrecord.C stats.C
HFILES= configuration.h logrecord.h stats.h
OBJECTS=$(CCFILES:%.C=%.o)

httpstats: $(OBJECTS)
        g++ -o $@ $^

clean:
        rm $(OBJECTS) httpstats

check: httpstats
        time httpstats access_log httpstats.config
include make.depend

make.depend: $(CCFILES) 
        g++ -M $^ >$@
Here is the cerr output of ``make check'' at this stage:
        10000 lines processed, 0 lines had errors
        0.84user 0.00system 0:00.90elapsed 93%CPU (0avgtext+0avgdata 0maxresident)k
        0inputs+0outputs (164major+12minor)pagefaults 0swaps
So, just reading the lot takes less than a second.


httpstats-stage00 [ 7 April, 2001]