void ConstructAndAddUser(string strLine, TextFileDataSource* tfds) { DataMap* pdmUsers = tfds->getUsersCollection(); vector<string> vecstrLineSplit = StringUtils::splitString(strLine, ','); int nUserID = TypeConverter(vecstrLineSplit[TextFileDataSource::USER_NAME]); string strPassword = vecstrLineSplit[TextFileDataSource::PASSWORD]; int nUserType = TypeConverter(vecstrLineSplit[TextFileDataSource::USER_TYPE]); if (nUserType == User::CUSTOMER) { // TODO ASSERTS HERE string strName = vecstrLineSplit[TextFileDataSource::NAME]; string strAddress = vecstrLineSplit[TextFileDataSource::ADDRESS]; string strPhone = vecstrLineSplit[TextFileDataSource::PHONE_NUMBER]; Customer* pu = new Customer(nUserID, strPassword, strName, strAddress, strPhone); // add accoutn ids vector<string> vecstrAccountIds = StringUtils::splitString(vecstrLineSplit[TextFileDataSource::ACCOUNT_IDS],';'); for (unsigned nId = 0; nId < vecstrAccountIds.size(); nId++) { pu->addAccount(TypeConverter(vecstrAccountIds[nId])); } pdmUsers->Add(pu); } else if (nUserType == User::BANK_CLERK) { pdmUsers->Add ( new BankClerk(nUserID, strPassword) ); } }
void TextFileDataSource::ConstructAndAddCustomer(std::string line) { enum { USER_ID, PASSWORD, NAME, ADDRESS, PHONE_NUMBER, ACCOUNT_IDS, NUM_FIELDS }; vector<std::string> lineSplit = stringUtils::splitstring(line, ','); vector<std::string> accountIds = stringUtils::splitstring(lineSplit[ACCOUNT_IDS], ';'); // create customer Customer* c = new Customer ( TypeConverter(lineSplit[USER_ID]), lineSplit[PASSWORD], lineSplit[NAME], lineSplit[ADDRESS], lineSplit[PHONE_NUMBER] ); // add account ids vector<std::string>::iterator vit; for (vit = accountIds.begin(); vit != accountIds.end(); ++vit) { c->addAccount(TypeConverter(*vit)); } _users.add(c->getUserId(), c); }