SOM_Scope long SOMLINK Open(Bank *somSelf, Environment *ev, string name, long acct_type, long pin, long amount) { BankData *somThis = BankGetData(somSelf); BankMethodDebug("Bank","Open"); Account *temp; somf_TSetIterator *itr; trans_info *Tr; somf_TSet *set; somf_TPrimitiveLinkedList *llist; char *user_name; /* first check if the account already exists */ /* we create an iterator and walk through the account list */ itr = new somf_TSetIterator; switch (acct_type) { case Account_CHECKING: itr->somfTSetIteratorInit(ev, somSelf->_get_check_acct_set(ev)); break; case Account_SAVINGS: itr->somfTSetIteratorInit(ev, somSelf->_get_save_acct_set(ev)); break; case Account_MF: itr->somfTSetIteratorInit(ev, somSelf->_get_mf_acct_set(ev)); break; default: somPrintf (" bad account type\n"); return 9; } temp = (Account *)itr->somfFirst(ev); while (temp != SOMF_NIL ) { user_name = temp->_get_user_name(ev); if (strcmp(name, user_name) == 0) { /* acct already exists ? */ somPrintf("<%s> exists\n", name); return Account_ACCT_EXISTS; } else temp = (Account *)itr->somfNext(ev); } /* if we are here then we need to add the account * initialize all values (hardwire interest and min_balance) * allocate space for the new account */ user_name = (char *) malloc (strlen(name) + 1); strcpy (user_name, name); temp = new Account; temp->_set_user_name (ev, user_name); temp->_set_min_balance (ev, 0); temp->_set_act_balance (ev, amount); temp->_set_interest (ev, 5); temp->_set_pin (ev, pin); llist = new somf_TPrimitiveLinkedList; /* initialize the transaction list also */ Tr = new trans_info; Tr->_set_amount (ev, amount); Tr->_set_transaction (ev, Account_OPEN); Tr->_set_date (ev, time(0)); Tr->_set_curr_bal (ev, amount); llist->somfAddFirst(ev, Tr); /* now set up all the information to point correctly */ temp->_set_trans_list (ev, llist); /* now add the account to the appropriate set */ if (acct_type == Account_CHECKING) { set = somSelf->_get_check_acct_set(ev); set->somfAdd(ev, temp); } else if (acct_type == Account_SAVINGS) { set = somSelf->_get_save_acct_set(ev); set->somfAdd(ev, temp); } else if (acct_type == Account_MF) { set = somSelf->_get_mf_acct_set(ev); set->somfAdd(ev, temp); } itr->somFree(); return Account_OK; }