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/ui/editor/editor_states_history.h"
12 
13 namespace app {
14 
EditorStatesHistory()15 EditorStatesHistory::EditorStatesHistory()
16 {
17 }
18 
~EditorStatesHistory()19 EditorStatesHistory::~EditorStatesHistory()
20 {
21   clear();
22 }
23 
top()24 EditorStatePtr EditorStatesHistory::top()
25 {
26   return (!m_states.empty() ? m_states.back(): EditorStatePtr(NULL));
27 }
28 
push(const EditorStatePtr & state)29 void EditorStatesHistory::push(const EditorStatePtr& state)
30 {
31   ASSERT(state);
32   m_states.push_back(state);
33 }
34 
pop()35 void EditorStatesHistory::pop()
36 {
37   ASSERT(!m_states.empty());
38   m_states.pop_back();
39 }
40 
clear()41 void EditorStatesHistory::clear()
42 {
43   // Free shared pointers in reverse order
44   std::vector<EditorStatePtr>::reverse_iterator it = m_states.rbegin();
45   std::vector<EditorStatePtr>::reverse_iterator end = m_states.rend();
46   for (; it != end; ++it)
47     (*it).reset();
48 
49   m_states.clear();
50 }
51 
52 } // namespace app
53