TR 9:15 - 10:30 am (CAS) 136
Week 10 Class 19 Thu Mar 20 Posted: Mar 20
After Class
Announcements
Exercise 54: Memory Due Date extended.
I gave a score and any feedback to those who successfully completed the exercise so they can then work on Memory II.
If you did not get a score, then one of the following applies:
valgrind
does not show a clean run with no memory leaksconsumer()
Whatever the reason above, I will allow you to fix it.
Producer/Consumer
Some of you treated the function consumer()
as a function for deleting memory. That is not the entire purpose of consumer()
. This is indicated by the:
which is the universal (code example) symbol for "Other processing will occur, but we are ignoring for now to make a point". Some example of what could occur in producer/consumer, in addition to memory allocation/deallocation:
Scenario | Producer Action | Consumer Action |
---|---|---|
Image Processing | Load an image from disk | Process the image (apply filters, resize, save output) |
Logging | Create a log entry with explanation, severity, and timestamp | Write the log entry to a file |
Database Connection | Initialize a database connection | Use the connection to execute a query or transaction |
Asynchronous Task Processing | Produce work items (e.g., tasks) | Retrieve a task from a shared queue and process |
Agenda
Exercise 58: Memory II
Note that Exercise 54: Memory is a prerequisite.
Replace the raw pointers (e.g., int* p
) with std::unique_ptr<int>
. Ensure it runs successfully and you have a clean Valgrind run. The include file for std::unique_ptr
is <memory>
. Once done, tag this in Git as smartpointer
Unless otherwise noted, exercises are due by 4:30 pm on Mon Mar 31
The main problem with the design for the srcFacts project is the complicated section of code (the large while loop with the main nested-if) surrounding the srcFacts concerns. We have moved much of the low-level parsing details out of srcfacts.cpp (and into XMLParser), but that overall code structure remains.
Change the design of XMLParser to use full IoC (Inversion of Control). IoC lets you move the large while loop with nested-if entirely into an XMLParser method parse()
. The only things that srcFacts will have to do (and the only public methods of the new XMLParser) are the parse()
method and (depending on your implementation) methods to register handlers.
Your XML parser needs to provide access to all parts of XML, even if srcFacts does not use it, via the following extension points from XML notes slide 34
XML Extension Point | Attributes |
---|---|
Start Document | |
XML Declaration | version, encoding, standalone |
Element Start Tag | qName, prefix, localName |
Element End Tag | qName, prefix, localName |
Characters | characters |
Attribute | qName, prefix, localName, value |
XML Namespace | prefix, uri |
XML Comment | value |
CDATA | characters |
Processing Instruction | target, data |
End Document |
There is no explicit part or tag to fix the code from the Project 2 feedback. Fix any style issues in XMLParser or any issues that will cause a problem with Project 3.
Tag v3a: Redesign XMLParser to use IoC with lambda handlers for the extension points. For srcFacts, this means that the lambda functions in srcFacts.cpp contains all the processing of the XML data results, e.g., tag names with none of the XML parsing. Update your Class Diagram and Sequence Diagram to reflect this new design. Rules apply:
Tag v3xmlstats: Create the application xmlstats that produces a markdown report (similar to what srcFacts does) that indicates the number of each part of XML. E.g., the number of start tags, end tags, attributes, character sections, etc.
Tag v3identity: Create the application identity which is an identity transformation. A transformation is a program that converts data in one format to data in a related format, typically the same format. In this case, it converts from XML to XML. It is an identity transformation because the output XML should be the same (as much as possible) as the input XML. The XMLParser will parse the input, and your callbacks will output the XML format. You can assume that there are no CDATA parts, but you must escape all >
, <
, and &
in Character and CDATA content.
Note: Any changes to XMLParser must work with srcfacts, xmlstats, and identity:
All tags for Project 3 are due Tuesday, Apr 2.
Keep in mind:
TA: Ms. Afia Asante aa998@uakron.edu
TA: Mr. Isaiah Ekundayo ioe2@uakron.edu