P2: Collaborations. CSE 335, Spring 2009

Similar documents
Lab 8: Ordered Search Results

Programming Assignment IV Due Thursday, June 1, 2017 at 11:59pm

Project 1: Scheme Pretty-Printer

Short Notes of CS201

Creational. Structural

CS201 - Introduction to Programming Glossary By

CS 330 Homework Comma-Separated Expression

Programming Tips for CS758/858

CIS 121 Data Structures and Algorithms with Java Spring 2018

Project #1: Tracing, System Calls, and Processes

EECS 311: Data Structures and Data Management Program 1 Assigned: 10/21/10 Checkpoint: 11/2/10; Due: 11/9/10

Modellistica Medica. Maria Grazia Pia, INFN Genova. Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico

Project #1 rev 2 Computer Science 2334 Fall 2013 This project is individual work. Each student must complete this assignment independently.

Project 1 Computer Science 2334 Spring 2016 This project is individual work. Each student must complete this assignment independently.

CSE 333 Midterm Exam 2/14/14

Laboratory Assignment #4 Debugging in Eclipse CDT 1

Note: This is a miniassignment and the grading is automated. If you do not submit it correctly, you will receive at most half credit.

Design Patterns. SE3A04 Tutorial. Jason Jaskolka

Due: 9 February 2017 at 1159pm (2359, Pacific Standard Time)

Project. C++: Inheritance III. Plan. Project. Before we begin. The final exam. Advanced Topics. Project. This week in the home stretch

QUIZ on Ch.5. Why is it sometimes not a good idea to place the private part of the interface in a header file?

Project #1 Exceptions and Simple System Calls

Project 1: Remote Method Invocation CSE 291 Spring 2016

Data Structures (list, dictionary, tuples, sets, strings)

HW 1: Shell. Contents CS 162. Due: September 18, Getting started 2. 2 Add support for cd and pwd 2. 3 Program execution 2. 4 Path resolution 3

EINDHOVEN UNIVERSITY OF TECHNOLOGY

CS Exam 1 Review Suggestions

EPL 603 TOPICS IN SOFTWARE ENGINEERING. Lab 6: Design Patterns

This homework has an opportunity for substantial extra credit, which is described at the end of this document.

Getting started with VSTGUI4 and RackAFX! Will Pirkle! Copyright 2015 Will Pirkle

Midterm 2. 7] Explain in your own words the concept of a handle class and how it s implemented in C++: What s wrong with this answer?

CSE351 Winter 2016, Final Examination March 16, 2016

SERIOUS ABOUT SOFTWARE. Qt Core features. Timo Strömmer, May 26,

CSE 333 Midterm Exam 7/29/13

Programming Languages and Techniques (CIS120)

CSE P 501 Compilers. Implementing ASTs (in Java) Hal Perkins Winter /22/ Hal Perkins & UW CSE H-1

CS 3331 Advanced Object-Oriented Programming. Final Exam

CSSE 304 Assignment #13 (interpreter milestone #1) Updated for Fall, 2018

PIC 10B Lecture 1 Winter 2014 Homework Assignment #3

Object-Oriented Programming

Java Programming Lecture 7

DESIGN PATTERN - INTERVIEW QUESTIONS

CS 1653: Applied Cryptography and Network Security Fall Term Project, Phase 2

1. Overview This project will help you understand address spaces and virtual memory management.

What is an algorithm?

Review sheet for Final Exam (List of objectives for this course)

CSE 401/M501 Compilers

Structure of Programming Languages Lecture 10

CMPSCI 187 / Spring 2015 Implementing Sets Using Linked Lists

CSE P 501 Compilers. Implementing ASTs (in Java) Hal Perkins Autumn /20/ Hal Perkins & UW CSE H-1

(In columns, of course.)

Event-driven Programming: GUIs

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012

PIC 10B Lecture 1 Winter 2014 Homework Assignment #1

CSCI 201L Midterm Programming. Fall % of course grade

CS 11 java track: lecture 3

The undo stack and reusing the memento pattern

Chapter 6 Introduction to Defining Classes

CSE 333 Midterm Exam July 24, Name UW ID#

CSE 143: Computer Programming II Spring 2015 HW2: HTMLManager (due Thursday, April 16, :30pm)

CSE115 Lab 9 Fall 2016

Practicum 5 Maps and Closures

Summary. Recursion. Overall Assignment Description. Part 1: Recursively Searching Files and Directories

Compilers Project 3: Semantic Analyzer

OBJECT ORİENTATİON ENCAPSULATİON

COP Programming Assignment #7

CSE 100: C++ TEMPLATES AND ITERATORS

Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring Topic Notes: C and Unix Overview

Programming Assignment 0

Tips from the experts: How to waste a lot of time on this assignment

CS 161 Computer Security

CMPSCI 187 / Spring 2015 Postfix Expression Evaluator

1: Introduction to Object (1)

Lecture 2, September 4

The GoF Design Patterns Reference

CS11 Introduction to C++ Fall Lecture 7

Ch. 11: References & the Copy-Constructor. - continued -

Compiler construction 2009

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich

Software Design Patterns. Background 1. Background 2. Jonathan I. Maletic, Ph.D.

As a programmer, you know how easy it can be to get lost in the details

Programming Assignments

Analysis Tool Project

Web API Lab. The next two deliverables you shall write yourself.

Homework 1: Programming Component Routing Packets Within a Structured Peer-to-Peer (P2P) Network Overlay VERSION 1.1

Browser: Simple HTML Rendering

CS143 Handout 25 Summer 2012 August 6 th, 2011 Programming Project 4: TAC Generation

377 Student Guide to C++

We will talk about Alt-Tab from the usability perspective. Think about: - Is it learnable? - Is it efficient? - What about errors and safety?

CreateASite Beginner s Guide

CPSC 233: Assignment 4 (Due March 26 at 4 PM)

CMSC 201 Fall 2016 Homework 6 Functions

Project 4: Implementing Malloc Introduction & Problem statement

EECE.2160: ECE Application Programming

CS2383 Programming Assignment 3

Programming Style and Optimisations - An Overview

Class 16: The Swing Event Model

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

CE221 Programming in C++ Part 1 Introduction

Advanced Software Engineering

Transcription:

P2: Collaborations CSE 335, Spring 2009 Milestone #1 due by Thursday, March 19 at 11:59 p.m. Completed project due by Thursday, April 2 at 11:59 p.m. Objectives Develop an application with a graphical user interface. Gain experience using the observer, adapter, and mediator patterns. Gain experience adding significant new features to an existing program. Description In the previous project, you developed an application for displaying the contents of a C++ source file. This made it possible to apply a consistent format to the program source code, but it did not really provide any new information. It also required the use of a command line to operate, and it could only work on one source file at a time. In this project, you will take the libraries that you wrote for P1 and extend them to perform an actual static analysis task. Specifically, you will make it possible to produce a flattened view of a C++ class, where all of the class s inherited members are displayed alongside its own members. You will also rewrite the application to present a graphical user interface (GUI), replacing the use of the command line. The user will be able to interact with your program exclusively through this interface. Furthermore, the interface should make it possible for your program to load classes from multiple files and let the user choose which of them they would like to view. An example of what your interface might look like is provided in Figure 1. The development of your GUI will involve the application of the observer, adapter, and mediator patterns. You are to build the application with FLTK, the GUI toolkit used in all of the past homework assignments. While you can use the homework code to get yourself started, you will very likely want to refer to the online documentation at http://fltk.org/doc-1.1/toc.html at some point. In addition to the GUI work, you will be continuing to make use of the visitor structure that you set up in P1. This will make it easier to add the new static analysis operations. Tasks 1. Create a class for the model that will keep track of the application s data. This means it will need some way to maintain a pointer to each of the currently-loaded classes. It should be possible to look up how many classes are loaded in the model, and to access each of the available class pointers. There also should be a way to add new classes to the model s collection, as well as to have all of the classes removed from the model and their memory freed. 1

Figure 1: Mockup of the desired project interface 2. Write a new concrete visitor class that can traverse the contents of a given Cpp Entity and locate all of the Classes it contains. This visitor class should store pointers to each of the Classes in some internal data structure (perhaps a vector). When the visitor has finished traversing the Cpp Entity, it should be possible to query the visitor and retrieve all of the Class pointers that were found. 3. Create a new visitor that prints classes in a flattened form. It will basically function like your pretty print visitor, but will need some added logic to support the printing of the superclass members. 4. You now can move on to building the application GUI. First, to make it possible for interested parties to learn about menu selections, create an abstract observer class named Menu Listener. This class s notification method should accept two parameters: a pointer to the Fl Menu 1 object that triggered the notification, and the integer index of the menu item that was selected. 5. Adapt the FLTK classes Fl Menu Bar and Fl Choice so that they can register interested Menu Listeners and notify them when a menu item has been selected. This will provide you with a typical bar-style main menu and a drop-down list box that you can use in creating your GUI. Note that your goal when designing these two menu classes and the Menu Listener interface should be to make their collaboration as reusable as possible. That is, the only information that should be communicated between a menu and its listeners should be the address of the 1 Don t forget to include the underscore at the end of Fl Menu! 2

menu and the index of the selected item. Do not attempt to add anything project-specific to this relationship. 6. Develop a director class that will manage the creation and interaction of the application window and its widgets. To do this, you should follow the mediator pattern. You may simplify your implementation slightly by omitting the abstract mediator class. You can then have your concrete mediator class receive notifications from its member widgets by making it inherit from Menu Listener. In addition to displaying the application window, the director class will also need to create the following widgets, as shown in Figure 1: A menu bar along the top, that gives the user a way to open and close files. A drop-down box just below this, that lets the user choose which of the loaded classes they would like to view. An output box that fills the rest of the window. The contents of the currently-selected class should be displayed here. The menu bar at the top of the window should expose the following options, grouped into two menu headings. File/Load: Prompts the user to select one or more C++ source files. Reads the files contents and adds the names of any classes found therein to the drop-down box. It should then be possible to view the contents of these classes by selecting them from the drop-down. File/Load and Replace: Works the same as the Load option, but has all of the existing classes removed from the drop-down before the file is read. File/Close All: Removes all of the classes from the drop-down box and frees any associated memory. File/Quit: Closes the window and exits the application. View/Flatten: Switches between a regular printout of the current class and a flattened version, where all of the class s inherited members are displayed. An example of how the final menu bar should look is given in Figure 2. Figure 2: Example contents of the two menu bar headings 7. Implement the necessary logic in the director class such that all of the controls and menu entries perform their intended functions. 3

Additional Constraints 1. Non-flattened classes should be output in the same format that they were in the previous project. The easiest way to ensure that this happens is to modify your pretty print visitor so that the target output stream can be set in the constructor. This will let you use an ostringstream object to buffer the pretty print visitor s output. The string buffer then can be set as the contents of the text box. 2. Flattened classes should have the same general format as non-flattened classes, though the way in which the members are listed will naturally be a little different. The members from each class (whether the actual class or one of its parent classes) should be set off by comments, so you can tell from where a given member came. Figure 1 demonstrates how this will look. For more detail on what is required: All of the superclasses members must be printed, including those that are overrided in a subclass. Your flattening visitor must be able to print out inner classes just as well as any other member. Moreover, it should also be able to flatten out inner classes while it is flattening the class that contains them. Extra credit opportunity: If your flattening visitor can print the effective access level for inherited members, you will receive up to 5 points extra credit. This means that, for an example, if a subclass inherits privately from its parent class, then all of the parent class s members will be shown as private. Important: While you will not be penalized if your flattening visitor does not support this functionality, you may be penalized if attempting to add this feature creates errors in your program s output that otherwise would not have been present. 3. If the user selects the, Load and Replace, menu option, but then changes their mind and cancels the file chooser prompt, none of the existing classes should be freed. Wait until the user has selected a file and confirmed their decision. 4. Your program must not incur any memory leaks that do not stem from ordinary usage of the FLTK library. Any entity objects that you allocate must be freed, and you must make sure to free as much memory from FLTK as you can control. 2 Because memory management will be much more complicated in this project than in the last, it is required that you have your Cpp Entity class hierarchy make use of reference counting. 5. You should provide a separate.h and.cpp file for every concrete class that you create. 6. You must include a makefile for building your project. It is suggested that you start with the makefile developed for the last project. You are also required to provide a driver file that instantiates your director class and launches the application window. Note that because of the GUI that you have developed, it is no longer necessary for your program to handle any command line arguments. 2 Some implementations of FLTK leak a constant amount of memory for every font that they use. You are not expected to resolve this yourself, but you should ensure that your program does not suffer from any other leaks. 4

Hints 1. The Cpp Parser class has been updated to include a new constructor that accepts a single filename rather than the argc and argv values passed to main(). You may find this easier to use in some cases. 2. As you may notice in the homework assignments, the usual way to adapt an FLTK widget class into a subject class is to subclass it, then have the subclass set its own callback function. When a widget is activated, this callback function will be called with a pointer to the widget that triggered the event. The callback function can then use this pointer to send out the proper notifications. Look at the Ival Slider class from H5 as an example of this. The Fl Menu Bar and Fl Choice classes support callback functions that can be used in this way. However, the callback functions will only be triggered for menu items that do not define their own individual callbacks. Therefore, when you add items to your menu and drop-down box, you should make sure to set each item s callback to NULL. See the FLTK documentation for Fl Menu and Fl Menu Item for more details. 3. There is a sample application using the mediator pattern available for your examination in /user/cse335/s09/mediator-example. If you are having trouble getting started, take a look at this. Your director class should have the same general format. 4. While FLTK provides several classes that can be used to display text, the obvious choices like Fl Multiline Output do not include a scroll bar. A class called Scrollbar Output has been provided for you that will automatically create vertical and/or horizontal scrollbars when necessary. It is suggested that you use this class for your output box. You can set its contents by calling its value() method, just like the regular FLTK output classes. 5. FLTK provides a class with which users can browse for files, called Fl File Chooser. The online documentation provides a decent description of how the constructor works, but it does not explain how to bring up the window. The following code sample will display an Fl File Chooser object named file prompt and wait for the user to select a file: file_prompt.show(); while (file_prompt.visible() == 1) { Fl::wait(); } The file(s) can then be looked up with the directory(), value(), and count() methods. 6. When adding the menu bar to your director class, be careful in deciding which menu index you associate with each item. Each submenu is given its own index, and this may cause the indices of your menu entries to differ from what you might initially expect. You may find it helpful to have your director s notification handler print the index of each menu event to the console, so that you can determine the true indices at runtime. 7. FLTK does some behind-the-scenes memory management. When an Fl Window is closed, the FLTK library automatically frees it and any widgets that it contained. Therefore, you do 5

not need to explicitly delete any Fl Window objects or widgets that you create. Additionally, you should allocate widgets on the heap, using pointers and new rather than allocating them on the stack. Note that this does not apply to the Fl Chooser class, which you are responsible for freeing yourself after the chooser window has been closed. Procedure Preparing the Project Repository This project will build off of the code that you wrote for P1. You can continue working in your project repository s trunk. However, you will want to obtain the Scrollbar Output class, as well the updated copy of the Cpp Parser class. The new files are located in /user/cse335/s09/p2-src on the CSE servers. You may copy them directly from there into your working copy. Be sure to add the new files for Scrollbar Output to your repository and commit the changes after the copy. Also, because this project uses FLTK, you will need to update your makefile so that the necessary FLTK files are included when building. To do this, open your makefile in a text editor. Append fltk-config --cxxflags to the list of CXXFLAGS and fltk-config --ldflags to the existing LDFLAGS. Note that the new features in this project depend on most of the functionality from P1 having been completed. You will likely need to repair any outstanding bugs before moving on. Reaching Milestone #1 For milestone #1, you need to complete all of the functionality not related to the GUI. This involves creating your model class and implementing the two new visitor classes. It also means that you will need to set up reference counting in your entity classes. To demonstrate that these features are working, create a temporary driver file that does the following four things: 1. Parses the file specified on the command prompt (like you did in the last project). 2. Locates all of the Class objects that were created (using your class-locating visitor). 3. Prints a flattened view of each class (using your visitor for printing flattened classes). 4. Cleans up after the previous steps such that all memory is freed. (Your C++ entity objects should be freed via the reference-counting mechanism.) It is required that your milestone terminates without leaking memory. To submit milestone #1, add and commit your files to your repository, and then tag the files as milestone-p2. Reminder: The completed milestone is worth 5% of your project grade! Completing the Project As in the last project, you will find it easiest to complete all of the requirements if you tackle them one at a time. Focus on the milestone requirements first. Once you have thoroughly tested the milestone and you are confident that it is working, you can go on to develop the GUI components. When you complete the project, make sure that you have added and committed all of your files, and then tag the submission as submission-p2. 6