Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lab2 Diagrams Cop 4232 Fall 2005. Lab2 Cop42322 IOMgmt InMgrIOError OutMgr Tokenizer TokenError StringTokenizer pgmInMgr pgmOutMgr.

Similar presentations


Presentation on theme: "Lab2 Diagrams Cop 4232 Fall 2005. Lab2 Cop42322 IOMgmt InMgrIOError OutMgr Tokenizer TokenError StringTokenizer pgmInMgr pgmOutMgr."— Presentation transcript:

1 Lab2 Diagrams Cop 4232 Fall 2005

2 Lab2 Cop42322 IOMgmt InMgrIOError OutMgr Tokenizer TokenError StringTokenizer pgmInMgr pgmOutMgr

3 Fall 2005Lab2 Cop42323 SimMgmt & SimModels SimMgmtSimModels Agent #InMgr& finMgr //class #OutMgr& foutMgr //class -string name //instance +Agent() +Agent(Tokenizer& ) +Agent(string ) +Insert() +Extract() +Extract(Tokenizer&) +Extract(string) +operator>>(ifstream&, Agent&) +operator string +InMgrOf()=>InMgr& +OutMgrOf()=>OutMgr& +setInMgr(InMgr&) +setOutMgr(OutMgr&) #Put() #Get(Tokenizer&) #Get(StringTokenizer&) Customer -Money cash -string paymethod -CreditCard bankcard +Customer() +Customer(Tokenizer& ) +Customer(string ) +Extract() +Extract(Tokenizer&) +Extract(string) +Insert() #Get() #Get(Tokenizer&) #Get(StringTokenizer&) #Put() PumpStation -Money pricepergal[3] -Money purchaselimit -Money purchaseamt -double purchasegal -double pumprate -Grade gradeselected + PumpStation() + PumpStation(Tokenizer& ) + PumpStation(string ) +Extract() +Extract(Tokenizer&) +Extract(string) +Insert() #Get() #Get(Tokenizer&) #Get(StringTokenizer&) #Put()

4 Fall 2005Lab2 Cop42324 SimMgmt & SimModels Agent -string name //instance +Agent() +Agent( ifstream& ) +Agent(Tokenizer& ) +Agent(string ) +Insert( ostream& ) +Extract( ifstream& ) +Extract( Tokenizer& ) +Extract( string ) +operator>>(ifstream&, Agent&) +operator string #Put( ostream& ) #Get( ifstream& ) #Get( Tokenizer& ) #Get( StringTokenizer& ) Customer -Money cash -string paymethod -CreditCard bankcard PumpStation -Money pricepergal[3] -Money purchaselimit -Money purchaseamt -double purchasegal -double pumprate -Grade gradeselected Version #1 +Customer() +Customer( ifstream& ) +Customer(Tokenizer& ) +Customer(string ) +Insert( ostream& ) +Extract( ifstream& ) +Extract( Tokenizer& ) +Extract( string ) #Put( ostream& ) #Get( ifstream& ) #Get( Tokenizer& ) #Get( StringTokenizer& ) +PumpStation() +PumpStation( ifstream& ) +PumpStation(Tokenizer& ) +PumpStation(string ) +Insert( ostream& ) +Extract( ifstream& ) +Extract( Tokenizer& ) +Extract( string ) #Put( ostream& ) #Get( ifstream& ) #Get( Tokenizer& ) #Get( StringTokenizer& ) InMgr and OutMgr are NOT USED!

5 Fall 2005Lab2 Cop42325 Client A for Version #1 int main() { ifstream fin; ostream fout; string finName, foutName; cout << “Enter input file name: “; cin >> finName; cout << “Enter output file name: “; cin >> foutName; fin.open( finName.c_str()); fout.open( foutName.c_str()); Agent alpha, beta(fin), gamma; fin >> gamma; alpha.Extract(fin); fout << alpha << endl; beta.Insert(fout); fout << gamma << endl; } Agent{ name: BETA }Agent Agent{ name: GAMMA }Agent Agent{ name: ALPHA }Agent Input File Agent{ name: ALPHA }Agent Agent{ name: BETA }Agent Agent{ name: GAMMA }Agent Output File Agent{ name: ALPHA }Agent Agent{ name: BETA }Agent Agent{ name: GAMMA }Agent Output Style 1 Output Style 2 Problem Formatting the output image is limited. To achieve the indented style, each instance must begin on a new line of the output stream.

6 Fall 2005Lab2 Cop42326 Client B for Version #1 int main() { Tokenizer T; //Tokenizer encapsulates input stream Agent alpha, beta(T), gamma(T); alpha.Extract(T); string Image = “ Agent{ name: DELTA }Agent “; Agent delta( Image ); //Hidden use of StringTokenizer fout << alpha << endl; beta.Insert(fout); fout << gamma << endl; fout << delta << endl; } Agent{ name: BETA }Agent Agent{ name: GAMMA }Agent Agent{ name: ALPHA }Agent Input File Agent{ name: ALPHA }Agent Agent{ name: BETA }Agent Agent{ name: GAMMA }Agent Agent{ name: DELTA }Agent Output File Agent{ name: ALPHA }Agent Agent{ name: BETA }Agent Agent{ name: GAMMA }Agent Agent{ name: DELTA }Agent Output Style 1 Output Style 2 Problem Formatting the output image is limited. To achieve the indented style, each instance must begin on a new line of the output stream. or

7 Fall 2005Lab2 Cop42327 SimMgmt & SimModels Agent -string name //instance +Agent() +Agent( InMgr& ) +Agent( Tokenizer& ) +Agent( string ) +Insert( OutMgr& ) +Extract( InMgr& ) +Extract( Tokenizer& ) +Extract( string ) +operator>>(ifstream&, Agent&) +operator string #Put( OutMgr& ) #Get( InMgr& ) #Get( Tokenizer& ) #Get( StringTokenizer& ) Customer -Money cash -string paymethod -CreditCard bankcard PumpStation -Money pricepergal[3] -Money purchaselimit -Money purchaseamt -double purchasegal -double pumprate -Grade gradeselected Version #2 +Customer() +Customer( InMgr& ) +Customer( Tokenizer& ) +Customer( string ) +Insert( OutMgr& ) +Extract( InMgr& ) +Extract( Tokenizer& ) +Extract( string ) #Put( OutMgr& ) #Get( InMgr& ) #Get( Tokenizer& ) #Get( StringTokenizer& ) +PumpStation() +PumpStation( InMgr& ) +PumpStation( Tokenizer& ) +PumpStation( string ) +Insert( OutMgr& ) +Extract( InMgr& ) +Extract( Tokenizer& ) +Extract( string ) #Put( OutMgr& ) #Get( InMgr& ) #Get( Tokenizer& ) #Get( StringTokenizer& ) InMgr and OutMgr are USED!

8 Fall 2005Lab2 Cop42328 Client A for Version #2 int main() { InMgr finMgr; InMgr& fin = finMgr.getStream(); OutMgr foutMgr; OutMgr& fout = foutMgr.getStream(); Agent alpha, beta(finMgr), gamma; fin >> gamma; alpha.Extract(finMgr); fout << alpha << endl; //<< cannot use foutMgr beta.Insert(foutMgr); //previous line compromises foutMgr fout << gamma << endl; //invalidates state of foutMgr } Agent{ name: BETA }Agent Agent{ name: GAMMA }Agent Agent{ name: ALPHA }Agent Input File Agent{ name: ALPHA }Agent Agent{ name: BETA }Agent Agent{ name: GAMMA }Agent Output File Agent{ name: ALPHA }Agent Agent{ name: BETA }Agent Agent{ name: GAMMA }Agent Output Style 1 Output Style 2 Problem Use of insertion operators in client may corrupt or invalidate the state of OutMgr. The implementation of << cannot know the associated OutMgr (and there may not be one)! If the client inserts its own formatting operations (e.g. endl) then the state of the associated OutMgr becomes invalid and subsequent output may not be formatted correctly. To correct this, operator<< should not be defined as a friend. Defining operator>> is permitted as a friend. In fact, Extract() and Get() can be defined to take ifstream& as a parameter – it is not necessary to use InMgr&

9 Fall 2005Lab2 Cop42329 SimMgmt & SimModels Agent #InMgr& finMgr //class #OutMgr& foutMgr //class -string name //instance +Agent() +Agent(Tokenizer& ) +Agent(string ) +Insert() //uses InMgr +Extract() //uses OutMgr +Extract(Tokenizer&) +Extract(string) +operator>>(ifstream&, Agent&) +operator string +InMgrOf()=>InMgr& +OutMgrOf()=>OutMgr& +setInMgr(InMgr&) +setOutMgr(OutMgr&) #Put() //uses OutMgr #Get() //uses InMgr #Get(Tokenizer&) #Get(StringTokenizer&) Customer -Money cash -string paymethod -CreditCard bankcard +Customer() +Customer(Tokenizer& ) +Customer(string ) +Extract() +Extract(Tokenizer&) +Extract(string) +Insert() #Get() #Get(Tokenizer&) #Get(StringTokenizer&) #Put() PumpStation -Money pricepergal[3] -Money purchaselimit -Money purchaseamt -double purchasegal -double pumprate -Grade gradeselected + PumpStation() + PumpStation(Tokenizer& ) + PumpStation(string ) +Extract() +Extract(Tokenizer&) +Extract(string) +Insert() #Get() #Get(Tokenizer&) #Get(StringTokenizer&) #Put() Version #3 InMgr and OutMgr are Encapsulated by Agent!

10 Fall 2005Lab2 Cop423210 Client A for Version #3 int main() { InMgr& finMgr = Agent::InMgrOf(); //access class attributes OutMgr& foutMgr = Agent::OutMgrOf(); //access class attributes ifstream& fin = finMgr.getStream(); ostream& fout = foutMgr.getStream(); Agent alpha, beta, gamma; beta.Extract(); fin >> gamma; alpha.Extract(); fout << alpha; //verifies that fout is associated with foutMgr beta.Insert(); //uses foutMgr fout << gamma; //verifies that fout is associated with foutMgr foutMgr.newLine(); } Agent{ name: BETA }Agent Agent{ name: GAMMA }Agent Agent{ name: ALPHA }Agent Input File Agent{ name: ALPHA }Agent Agent{ name: BETA }Agent Agent{ name: GAMMA }Agent Output File

11 Fall 2005Lab2 Cop423211 Lab2 Fall05 SimMgmt SimModels CustomerPumpStation JiffyStop Agent 1..* MoneyCreditCard IOMgmt InMgrOutMgr TokenErrorIOError AppError pgmInMgrpgmOutMgr StringTokenizerTokenizer

12 Fall 2005Lab2 Cop423212 Lab1 Figures A-1,2,3,4 Line Org Cur pos File Org idx Margin Stack MARGINSIZE Line Org Cur pos File Org Stack (before) Stack (after) idx Method: pushMargin() Line Org Cur pos File Org Stack (before) Stack (after) idx Method: popMargin() Cur fin File Org Method: deltaMargin(input) New fin (delta > 0) New fin (delta < 0) Line Org Curpos (before) File Org Method: newLine() Curpos (after) File Org Line Org

13 Fall 2005Lab2 Cop423213 Figures 3-6,7,8 Line Org Cur pos File Org Method: deltaMargin(output) Cur pos (delta > 0) diff File Org Cur pos (delta < 0) Line Org diff Method: toMargin(output) X{ }X XData1: value1 XData2: value2 XData3: XDatak: valuek Y{ }Y YData1: value1 YData2: value2 Instance of X Embedded instance of Y Cur fout File Org New fout idx blanks


Download ppt "Lab2 Diagrams Cop 4232 Fall 2005. Lab2 Cop42322 IOMgmt InMgrIOError OutMgr Tokenizer TokenError StringTokenizer pgmInMgr pgmOutMgr."

Similar presentations


Ads by Google