// Copyright 2000
// College of Computer Science
// Northeastern University Boston MA 02115

// This software may be used for educational purposes as long as this copyright
// notice is retained at the top of all files

// Should this software be modified, the words "Modified from Original" must be
// included as a comment below this notice

// All publication rights are retained.  This software or its documentation may
// not be published in any media either in whole or in part.

///////////////////////////////////////////////////////////////////////////////

// Shell.cpp ...  Test flexible database example: PersonInfoList

///////////////////////////////////////////////////////////////////////////////

// The standard include files that include traditional C and C++ headers and
// many other Core Tools headers ... see CHeaders.h for additional details

#include "IOTools.h"
#include "Graphics.h"
#include "Random.h"
#include "FileTool.h"

#include "StringList.h"
#include "PersonInfo.h"


void StringListTest() {
	StringList SL;

	while (SL.Reading("Enter string: ")) {
		cout << endl;

		cout << SL.ValidSize() << " strings entered so far" << endl << endl;
		cout << SL.TotalSize() << " string cells allocated" << endl << endl;

		SL.Print(cout, "String: ");

		cout << endl;
	}

	cout << endl;

} // StringListTest


void PersonInfoTest() {
	PersonInfo Person;

	while (Person.Reading())
		Person.Print();

	cout << endl;

} // PersonInfoTest


void EchoPersonInfoList(const PersonInfoList& List) {

	if (Confirm("Echo Person Info List to File?", true)) {

		cout << endl;

		string filename;

		if (SelectNewFileName(filename, "PersonInfoList.txt")) {

			ofstream os;

			if (OpenFile(os, filename, textwrite)) {
				
				List.Print(os);

				os.close();
			}
		}
	}
	else
		List.Print();

} // EchoPersonInfoList


void PersonInfoListTest() {

	PersonInfoList List;

	cout << "Enter PersonInfo Data for Several Persons" << endl << endl;

	int count = List.Reading();

	cout << endl << count << " Persons Entered" << endl << endl;

	EchoPersonInfoList(List);

} // PersonInfoTest


int main(int argc, char* argv[]) {

	// Use the following line if you choose NOT to open any graphics windows

	InitializeConsole();

//////////

	// Enter the main program here

	if (Confirm("Test StringList?", true))
		StringListTest();

	if (Confirm("Test PersonInfo?", true))
		PersonInfoTest();

	if (Confirm("Test PersonInfoList?", true))
		PersonInfoListTest();

//////////

	// The lines below make sure that the graphics windows remain open just
	// before the program terminates

	PressReturn("\nThe main program is about to terminate\n");

	return 0;

} // main
