problem commands with state and undo support
play

Problem: commands with state and undo support How do applications - PowerPoint PPT Presentation

Problem: commands with state and undo support How do applications with undo options (e.g., formatting in word processors) support the undo? How can a command, e.g., load files, find line numbers, be encapsulated into a class/object?


  1. Problem: commands with state and undo support ● How do applications with “undo” options (e.g., formatting in word processors) support the undo? ● How can a command, e.g., load files, find line numbers, be encapsulated into a class/object? ● How can commands be combined into macro-commands or command-sequences (e.g., load files, find occurrences of str)? ➤ use the Command pattern: an abstract class with a receiver that knows how to execute the command and, when necessary, has state to support undo operations ReadCommand rc(myController); rc.execute(); ➤ macro command’s execute iterates over all commands in Vector<Command *> myCommands; ➤ This is a command that contains commands: Composite 13. 1 Duke CPS 108

  2. Lots of command classes, what to do? ● Store command classes in a subdirectory (for the project), then use #include “commands/readcommand.h” ● Use templated commands when possible to factor out common, simple commands, e.g., that invoke certain member functions ● In small programs, using the Command pattern may not make sense, but it will pay off in larger programs and when porting code to a new language or environment ➤ often pattern payoff is not immediately apparent, but the rewards wil com 13. 2 Duke CPS 108

  3. What about libraries? ● for both static and dynamic/shared libraries you need to specify where the library is located and what library is used ➤ -L , link/load option, takes directory as “argument” ➤ -L. -L/afs/acpub/users/o/l/ola/cps108/lib ➤ also specify -lscandir , -ltapestry , these refer to either libscandir.a or libscandir.so (similarly libtapestry.*) ➤ on Solaris, shared libraries linked by default if they exist, can override with -static option ➤ what about libiberty.a? ● You can supply both .a and .so libraries, let the user have an option. Header files must be supplied as well, typically these are in path/lib and path/include directories. 13. 3 Duke CPS 108

  4. Some Qt info ● All slot/signal and otherwise Q-able classes must include a macro Q_OBJECT at the top of the class declaration, before public: ➤ macro/preprocessor flag is changed by CPP, the C-pre- processor (e.g., #define) ➤ any foo.h file with Q_OBJECT needs to be run through MOC to generate a MOCfoo.cc file (or fooMOC.cc ), this is in addition to the normal foo.cc file ➤ the mocdepend.perl script automatically generates the MOCfoo.cc files by grepping for Q_OBJECT ● If you have trouble, remove all .o files, especially MOC*.o files and recompile ● examples in ~ola/cps108/qtlink/examples on acpub 13. 4 Duke CPS 108

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend