dsrc isn't necessary for this repo
[client-tools.git] / src / external / 3rd / application / UiBuilder / UIBuilderHistory.cpp
blob95d6155ad1b9cb7c2cb985747eacbb00c658a23b
1 // ======================================================================
2 //
3 // UIBuilderHistory.cpp
4 // copyright (c) 2001 Sony Online Entertainment
5 //
6 // ======================================================================
8 #include "FirstUiBuilder.h"
9 #include "UIBuilderHistory.h"
11 #include <vector>
13 //-----------------------------------------------------------------
14 namespace
16 typedef std::vector<std::string> HistoryVector;
17 HistoryVector * ms_history;
18 size_t ms_index;
19 bool ms_installed;
21 //-----------------------------------------------------------------
23 void UIBuilderHistory::install ()
25 assert (!ms_installed);
26 ms_history = new HistoryVector;
27 ms_index = 0;
28 ms_installed = true;
31 //-----------------------------------------------------------------
33 void UIBuilderHistory::remove ()
35 assert (ms_installed);
36 delete ms_history;
37 ms_history = 0;
38 ms_installed = false;
41 //-----------------------------------------------------------------
43 bool UIBuilderHistory::back (std::string & path )
45 if (!backValid ())
46 return false;
48 path = (*ms_history) [--ms_index];
50 return true;
53 //-----------------------------------------------------------------
55 bool UIBuilderHistory::forward (std::string & path)
57 if (!forwardValid ())
58 return false;
60 path = (*ms_history) [++ms_index];
61 return true;
64 //-----------------------------------------------------------------
66 void UIBuilderHistory::pushNode (const std::string & path)
68 assert (ms_installed);
69 if (!ms_history->empty () && ms_index < ms_history->size () - 1)
71 HistoryVector::iterator it = ms_history->begin ();
72 std::advance (it, ms_index + 1);
73 ms_history->erase (it, ms_history->end ());
76 if (!ms_history->empty ())
77 ++ms_index;
79 ms_history->push_back (path);
82 //-----------------------------------------------------------------
84 bool UIBuilderHistory::backValid ()
86 assert (ms_installed);
87 return (ms_index > 0);
90 //-----------------------------------------------------------------
92 bool UIBuilderHistory::forwardValid ()
94 assert (ms_installed);
95 return (ms_index < ms_history->size () - 1);
98 //----------------------------------------------------------------------
100 bool UIBuilderHistory::isInstalled()
102 return ms_installed;
105 // ======================================================================