1 /* $XConsortium: CmdList.C /main/3 1995/11/06 15:59:50 rswiston $ */
5 * RESTRICTED CONFIDENTIAL INFORMATION:
7 * The information in this document is subject to special
8 * restrictions in a confidential disclosure agreement bertween
9 * HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
10 * document outside HP, IBM, Sun, USL, SCO, or Univel wihtout
11 * Sun's specific written approval. This documment and all copies
12 * and derivative works thereof must be returned or destroyed at
15 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
19 ///////////////////////////////////////////////////////////////////////////////
20 //////////////////////////////////////////////////////////////////////////////
21 // This example code is from the book:
23 // Object-Oriented Programming with C++ and OSF/Motif
26 // Prentice Hall, 1992
29 // Copyright 1991 by Prentice Hall
30 // All Rights Reserved
32 // Permission to use, copy, modify, and distribute this software for
33 // any purpose except publication and without fee is hereby granted, provided
34 // that the above copyright notice appear in all copies of the software.
35 ///////////////////////////////////////////////////////////////////////////////
36 //////////////////////////////////////////////////////////////////////////////
39 ////////////////////////////////////////////////////////////
40 // CmdList.C: Maintain a list of Cmd objects
41 ////////////////////////////////////////////////////////////
43 ////////////////////////////////////////////////////////////
44 // MODIFIED TO INHERIT FROM CMD - not described in Book
45 ///////////////////////////////////////////////////////////
50 CmdList::CmdList() : Cmd("CmdList", "CmdList", 1)
57 CmdList::CmdList(char *name, char *label ) : Cmd(name, label, 1)
59 // The list is initially empty
72 void CmdList::add ( Cmd *cmd )
77 // CmdList can only be undone if all Cmds it contains can be undone
82 // Allocate a list large enough for one more element
84 newList = new Cmd*[_numElements + 1];
86 // Copy the contents of the previous list to
89 for( i = 0; i < _numElements; i++)
90 newList[i] = _contents[i];
97 // Make the new list the current list
101 // Add the command to the list and update the list size.
103 _contents[_numElements] = cmd;
108 Cmd *CmdList::operator[] ( int index )
110 // Return the indexed element
112 return _contents[index];
118 for( int i = 0; i < _numElements; i++)
119 _contents[i]->execute();
122 void CmdList::undoit()
125 for( int i = _numElements - 1; i >=0; i--)
126 _contents[i]->undo();