Ok so here's my problem now....
Code:
#include "App.h"
#include "Movie.h"
#include "Actor.h"
#include "ActorDB.h"
#include "MovieDB.h"
#include <string>
#include <fstream>
#include <iostream>
using namespace std;
App::App()
{
}
App::~App()
{
}
void App::read_file(const std::string& fname)
{
ifstream infile(fname.c_str());
if (!infile)
return;
string actor_name;
while (getline(infile, actor_name, '\t')) {
//cout << "Actor: " << actor_name << endl;
Actor current_actor(actor_name);
ActorDB::tag current_ref = adb.add_actor(current_actor);
input_roles(current_ref, infile);
}
}
void App::get_path() const
{
while (true) {
Movie m;
cout << "Enter an actor's or actresse's name (q to quit): ";
string name;
getline(cin, name);
if (name == "q")
break;
cout << "\nEnter another actor or actress's name (q to quit): ";
string name2;
getline(cin, name2);
if (name2 == "q")
break;
m.printPath(name, name2);
}
}
void App::kevin_bacon() const
{
}
void trim(string& s)
{
int pos = 0;
while (s[pos] == '\t' || s[pos] == ' ')
++pos;
int pos2 = s.size()-1;
while (s[pos2] == '\t' || s[pos2] == ' ')
--pos2;
s = s.substr(pos, pos2-pos+1);
}
string find_year(string& mtxt)
{
int pos1 = mtxt.size();
do {
pos1 = mtxt.rfind('(', pos1-1);
} while (mtxt[pos1+1] != '1' && mtxt[pos1+1] != '2' && mtxt[pos1+1] != '?');
int pos2 = mtxt.find(')', pos1+1);
string year = mtxt.substr(pos1+1, pos2-pos1-1);
mtxt = mtxt.substr(0, pos1);
trim(mtxt);
return year;
}
void App::input_roles(ActorDB::tag a, std::istream& in) {
while (true) {
string movie_txt;
if (!getline(in, movie_txt))
break;
if (movie_txt == "")
break;
trim(movie_txt);
if (movie_txt[0] == '"')
continue;
// we have a real movie. Find the year.
//cout << " Movie txt: " << movie_txt << endl;
string year = find_year(movie_txt);
//cout << " Movie name: " << movie_txt << endl
// << " Movie year: " << year << endl;
Movie m(movie_txt, year, &adb);
MovieDB::tag t = mdb.add_movie(m);
const Movie& movie = mdb.get_movie(t);
movie.add_actor(a);
movie.actorConnections(a);
}
}
I don't believe my vertices are being created. I think my problem lies where I call the printPath function with object m, but I'm calling actorConnections at the bottom to create the vertices with a different object (movie). Or does this not matter? Or is it some other problem?