// baseballMaster.cc  P. Conrad for CISC220, 06J
// Class for Lahman Baseball Database (www.baseball1.com), version 5.3

// See license and copyright statement at bottom of file



#include "date.h"
#include "event.h"
#include "baseballMaster.h"
#include <cstring>
#include <iostream>
#include <cstdlib>
#include "strtokWithQuotedStrings.h"


  // construct one object from a line in the Master.csv file

BaseballMaster_C::BaseballMaster_C( char * const inputLine)
{
  char * lahmanIDPtr = strtokWithQuotedStrings(inputLine,',','"');
  lahmanID = atoi(lahmanIDPtr);



  char * playerIDPtr = strtokWithQuotedStrings(NULL,',','"');
  playerID = new char [strlen(playerIDPtr) + 1];
  strcpy(playerID, playerIDPtr);

  char * managerIDPtr = strtokWithQuotedStrings(NULL,',','"');
  managerID = new char [strlen(managerIDPtr) + 1];
  strcpy(managerID, managerIDPtr);

  char * hofIDPtr = strtokWithQuotedStrings(NULL,',','"');
  hofID = new char [strlen(hofIDPtr) + 1];
  strcpy(hofID, hofIDPtr);

  char * birthYearPtr = strtokWithQuotedStrings(NULL,',','"');
  char * birthMonthPtr = strtokWithQuotedStrings(NULL,',','"');
  char * birthDayPtr = strtokWithQuotedStrings(NULL,',','"');
  char * birthCountryPtr = strtokWithQuotedStrings(NULL,',','"');
  char * birthStatePtr = strtokWithQuotedStrings(NULL,',','"');
  char * birthCityPtr = strtokWithQuotedStrings(NULL,',','"');

  birth = new Event_C( Date_C(atoi(birthYearPtr),
			      atoi(birthMonthPtr),
			      atoi(birthDayPtr)),
		       birthCountryPtr,
		       birthStatePtr,
		       birthCityPtr);
  
  char * deathYearPtr = strtokWithQuotedStrings(NULL,',','"');
  char * deathMonthPtr = strtokWithQuotedStrings(NULL,',','"');
  char * deathDayPtr = strtokWithQuotedStrings(NULL,',','"');
  char * deathCountryPtr = strtokWithQuotedStrings(NULL,',','"');
  char * deathStatePtr = strtokWithQuotedStrings(NULL,',','"');
  char * deathCityPtr = strtokWithQuotedStrings(NULL,',','"');

  if ( strcmp(deathYearPtr,"") == 0 )
    death = NULL;
  else
    death = new Event_C( Date_C(atoi(deathYearPtr),
				atoi(deathMonthPtr),
				atoi(deathDayPtr)),
			 deathCountryPtr,
			 deathStatePtr,
			 deathCityPtr);

  char * firstNamePtr = strtokWithQuotedStrings(NULL,',','"');
  nameFirst = new char [strlen(firstNamePtr) + 1];
  strcpy(nameFirst, firstNamePtr);

  char * lastNamePtr = strtokWithQuotedStrings(NULL,',','"');
  nameLast = new char [strlen(lastNamePtr) + 1];
  strcpy(nameLast, lastNamePtr);

  char * noteNamePtr = strtokWithQuotedStrings(NULL,',','"');
  nameNote = new char [strlen(noteNamePtr) + 1];
  strcpy(nameNote, noteNamePtr);

  char * givenNamePtr = strtokWithQuotedStrings(NULL,',','"');
  nameGiven = new char [strlen(givenNamePtr) + 1];
  strcpy(nameGiven, givenNamePtr);

  char * nickNamePtr = strtokWithQuotedStrings(NULL,',','"');
  nameNick = new char [strlen(nickNamePtr) + 1];
  strcpy(nameNick, nickNamePtr);

  
}
  

// print just a few key fields
void BaseballMaster_C::print(std::ostream & out) const 
{
  out << "@@@ NOT IMPLEMENTED YET: " 
      << __FILE__ << ", line" << __LINE__ << std::endl;
}


// COPYRIGHT NOTICE:

// This code corresponds to the data layout of the Lahmann Database,
// which is copyrighted by Sean Lahmann.  The data and formats here
// are used by special permission of Sean Lahmann, granted to Phill 
// Conrad for use in Computer Science courses at the University of 
// Delaware.  You must obtain permission from Sean Lahmann to use this
// data and/or data format for any other purpose.  For more details,
// visit www.baseball1.com

