We have built an example solution for the project. The example doesn't implement all of the optional features, and doesn't necessarily provide exemplary implementations of all the functions. But it should be good enough for you to figure out what is going on.
We also are providing you with some of the source code. You are free to use it for your own project. We explicitly designed the implementation so that it is easy to add new commands to it. So, all you need to do is to take the example project and start adding new commands to implement the ones we didn't give to you!
A zip file containing everything you need to get started adding to the sample code is (coming soon). We've even included the visual studio project and solution files.
It should be possible to complete the project only by adding code to the example code. You don't need to edit the example code files. If you do make changes, please explain it in your project documentation.
In fact, you are better off avoiding making changes to the provided files. That way if there are updates, you can simply plug them in.
Note: the example solution reads commands until it gets to an end of file. For the console under windows, and end of file is created by hitting CTRL-Z.
You can download the whole thing here as a single 21K zip file.
The example code provides the interpreter for the scripting language, and a few example commands (including reading and writing images).
The files are:
PictureProcessor.H
-
this header describes the functionality that we provide for parsing and
executing commands. Its the primary thing you want to look at to understand
the code.
PictureProcessor.cpp
-
this implements what is described in PictureProcessor.H
.
It also provides 2 example commands (test and info).
main.cpp
- this is the
main entry point of the program. It has a loop that reads commands (either
from a file or from stdin) and executes them.
ReadWrite.cpp
- this
file implements the commands read, write and blank. Looking at this file is
useful since it will show you how to implement other commands.
Darken.cpp
- this file
implements the darken command. Looking at this will be a good example of how
to implement an image processing command.The project also includes the files for LibTarga and TargaImage (as documented in Main.Tutorial5).
libtarga.h
- header file
for the targa i/o library
libtarga.c
-
implementation of the targa i/o library
TargaImage.h
- header
for the C++ wrapper for the targa i/o library
TargaImage.cpp
- implementation of the C++ wrapper for the targa i/o
libraryFor completeness, we've also given you the Visual Studio 2005 files for building the project (the same files you need to turn in)
PictureProcessor.sln
-
solution file (double click on this)
PictureProcessor.vcproj
-
project fileThese files were built by following the directions in Tutorial1.
Download the whole thing here as a single 21K zip file.
As provided, the example solution only implements 6 commands (info, test, blank, write, read, darken). You will need to add a whole bunch more.
You should be able to add new commands without modifying the existing files.
To add a new
command, define a new class that is a subclass of Command
(which
is defined inPictureProcessor.H
),
and create a global instance of that class. Using a bit of C++ trickery, the
command will install itself at run time. Basically, the constructors of all of
the global variables are called before main
.
The constructor of the base class Command
adds
each instantiated object to a linked list, so they are all available to main.
Main doesn't need to know anything about the commands - it just calls the
methods as appropriate. There is no long list of all the command in the program.
To make the example code, we just leave out a bunch of files that implement the
commands.
A warning: sometimes, when you add a new global variable, visual studio gets confused and doesn't call the constructor in the right order. If you've added a new command and it isn't showing up (the program prints a list when it starts), you might need to do a "Rebuild All" in VS2005.
The "guts" of
your implementation will be in the doit
methods
of the commands that you implement. This is where the work actually gets done.
The doit
method
takes the command (as a vector of words) and a Context
(which
contains the active set of variables that store the images), and "does it"
(where "it" is whatever the command is supposed to do).
From the six example commands you should be able to figure out enough of the mechanics so that you can spend your time writing the image processing operations, not the parsing.