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