1 // Aseprite 2 // Copyright (C) 2001-2015 David Capello 3 // 4 // This program is distributed under the terms of 5 // the End-User License Agreement for Aseprite. 6 7 #ifdef HAVE_CONFIG_H 8 #include "config.h" 9 #endif 10 11 #include "app/cmd_sequence.h" 12 13 namespace app { 14 CmdSequence()15CmdSequence::CmdSequence() 16 { 17 } 18 ~CmdSequence()19CmdSequence::~CmdSequence() 20 { 21 for (Cmd* cmd : m_cmds) 22 delete cmd; 23 } 24 add(Cmd * cmd)25void CmdSequence::add(Cmd* cmd) 26 { 27 m_cmds.push_back(cmd); 28 } 29 onExecute()30void CmdSequence::onExecute() 31 { 32 for (auto it = m_cmds.begin(), end=m_cmds.end(); it!=end; ++it) 33 (*it)->execute(context()); 34 } 35 onUndo()36void CmdSequence::onUndo() 37 { 38 for (auto it = m_cmds.rbegin(), end=m_cmds.rend(); it!=end; ++it) 39 (*it)->undo(); 40 } 41 onRedo()42void CmdSequence::onRedo() 43 { 44 for (auto it = m_cmds.begin(), end=m_cmds.end(); it!=end; ++it) 45 (*it)->redo(); 46 } 47 onMemSize() const48size_t CmdSequence::onMemSize() const 49 { 50 size_t size = sizeof(*this); 51 52 for (auto it = m_cmds.begin(), end=m_cmds.end(); it!=end; ++it) 53 size += (*it)->memSize(); 54 55 return size; 56 } 57 executeAndAdd(Cmd * cmd)58void CmdSequence::executeAndAdd(Cmd* cmd) 59 { 60 cmd->execute(context()); 61 add(cmd); 62 } 63 64 } // namespace app 65