Valid
	XHTML 1.1! Valid CSS!
Created 2009-02-18   Modified 2009-04-11
Chelton Evans

proj Creating a Project home

To get a feel for this development space here is a program added to the workspace.

The directory structure is flat. There is a main proj directory where programs created in this IDE need their own directory.

$ proj
$ mkdir bsptrees
$ cd bsptrees

Write the program with a main.cpp file.

Linking the libraries: write a "libraries" file with the following -lGL -lGLU -lglut. This appends the text at the end of the compiler call.

To generate the makefile
$ mkupdate

The Makefile is printed in the terminal. The last line includes prints an error messages for included files. For example if a header file is misspelt then the compiler can not find the file under proj directory.
mymakegerror= GL/glut.h GL/gl.h

Ignore references to header files not under the proj directory. This is fine as these are third party libraries accessed by the main PATH variable, e.g. /usr/include

Compile and debug the program
$ make or $ mkerrors

If I run into runtime errors, for example if the program hangs then I could use gdb to get a stack trace.
$ make clean
$ mkerrors gdb
$ gdb
file ./main
r prog=5
Code stops because of error
bt
Fix code with this information, can be iterative.

Write some unit test code, sometimes I am lazy and write code that outputs to the screen only. Here is some code which reads the file format in and write it out again.

int treeindexedtest::unittest01(int argc, char** argv)
{
  commandline cmd(argc,argv);

  string in;
  cmd.mapvar(in,"in");
  if ( in.empty() )
  {
    cout << "error: in=filename expected" << endl;
    return 1;
  }

  ifstream filein(in.c_str());
  assert(filein.good()==true);
  if (filein.good()==false)
  {
    cout << "error: " << in << " file can not be opened." << endl;
    return 1;
  }

  treeindexed<uint> t1;
  filein >> t1;

  cout << (stringc)t1 << endl;

  string s1;
  assertevalreturn(tokenizermisc::readfile(s1,in.c_str()));

  string s2( (stringc)t1 );

  assertevalreturn(tokenizermisc::comparewithoutspace(s1,s2));

  return 0;
}

Within main.cpp I use command line arguments to run different programs in the workspace.

#include <commandline.h>
#include <treeindexedtest.h>

int main(int argc, char** argv)
{
  commandline cmd(argc,argv);
  uint prog(0);
  cmd.mapvar(prog,"prog");

  switch (prog)
  {
    case 0:
      cout << "./main prog=1   - Basic printing and inserting." << endl;
      cout << "./main prog=2   - Building and printing a simple tree." << endl;
      cout << "./main prog=3 in=treeindexed01.txt" << endl;
      cout << "                - Reading a tree from a text file." << endl;
      cout << "./main prog=4   - Build a bsp tree in 2D. Test 5 points in their 5 regions." << endl;
      cout << "./main prog=5   - Visually see and interact with a bsp tree." << endl;
      cout << "./main prog=6   - Testing move(T const bpath,T const nsteps)." << endl;
      cout << "./main prog=7   - Testing treeindexediter.h classes. " << endl;
      cout << "./main prog=8 in=map01.txt  - BSP Tree Demo" << endl;
      break;

    case 1: treeindexedtest::test01(); break;
    case 2: treeindexedtest::test02(); break;
    case 3: return treeindexedtest::unittest01(argc,argv);
    ...

The unit test code is a text file which I called testscript01.txt
./main prog=3 in=treeindexed01.txt
./main prog=2
./main prog=4
To run the script
$ testunit testscript01.txt

Generated the following report.

...
Report  testscript01.txt  Success
./main prog=3 in=treeindexed01.txt
  Success
./main prog=2
  Success
./main prog=4
  Success