Presentation is loading. Please wait.

Presentation is loading. Please wait.

Duke CPS 108 13. 1 Problem: commands with state and undo support l How do applications with “undo” options (e.g., formatting in word processors) support.

Similar presentations


Presentation on theme: "Duke CPS 108 13. 1 Problem: commands with state and undo support l How do applications with “undo” options (e.g., formatting in word processors) support."— Presentation transcript:

1 Duke CPS 108 13. 1 Problem: commands with state and undo support l How do applications with “undo” options (e.g., formatting in word processors) support the undo? l How can a command, e.g., load files, find line numbers, be encapsulated into a class/object? l 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 myCommands; ä This is a command that contains commands: Composite

2 Duke CPS 108 13. 2 Lots of command classes, what to do? Store command classes in a subdirectory (for the project), then use #include “commands/readcommand.h” l Use templated commands when possible to factor out common, simple commands, e.g., that invoke certain member functions l 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

3 Duke CPS 108 13. 3 What about libraries? l 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.

4 Duke CPS 108 13. 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 l If you have trouble, remove all.o files, especially MOC*.o files and recompile examples in ~ola/cps108/qtlink/examples on acpub


Download ppt "Duke CPS 108 13. 1 Problem: commands with state and undo support l How do applications with “undo” options (e.g., formatting in word processors) support."

Similar presentations


Ads by Google