28 user_frames.push(
new UserFrame(frameLevel));
33 if (user_frames.empty()) {
38 if (frameLevel<=wanted->get_level()) {
56 if (currFrame) frames.push(currFrame);
61 #if defined(CHECK_ROOT_POPS)
62 currFrame->root_at_create =
DOWNCAST(AP_tree_nlen*, get_tree_root()->get_root_node());
72 bool rootPopped =
false;
75 while ((node = currFrame->pop())) {
76 if (frameLevel != node->last_remembered_frame()) {
77 cerr <<
"Main frame level=" << frameLevel <<
" node frame level=" << node->last_remembered_frame() << endl;
78 GBK_terminate(
"AP_main::pop: main/node frame-level inconsistency");
80 node->revertToPreviousState(frameLevel, rootPopped);
84 ap_assert(rootPopped == frameData->root_pushed);
85 #if defined(CHECK_ROOT_POPS)
86 ap_assert(currFrame->root_at_create == get_tree_root()->get_root_node());
89 currFrame->revert_resources(frameData);
91 frameData = currFrame->take_previous_frame_data();
94 currFrame = frames.pop();
104 void AP_main::push_nodes_changed_since(
Level wanted_frameLevel) {
106 Level frame_level = frameLevel-1;
107 ap_assert(frame_level == frames.count_elements());
109 typedef map<AP_tree_nlen*,int> NodeCounter;
110 NodeCounter pops2skip;
112 AP_tree_nlen *oldRoot = get_root_node();
114 push_node(oldRoot,
ROOT);
117 if (frame_level == wanted_frameLevel)
break;
118 ap_assert(frame_level>wanted_frameLevel);
124 AP_tree_nlen *
node = *n;
125 if (node == oldRoot)
continue;
127 NodeCounter::iterator skipCounter = pops2skip.find(node);
128 int skip = skipCounter == pops2skip.end() ? 0 : skipCounter->second;
129 const StateStack& states = node->get_states();
132 if (skip>0) advance(toPush, skip);
141 if (mode ==
ROOT || node->is_root_node()) {
144 #if defined(ASSERTION_USED)
147 int pushed = push_node(node, mode);
151 pops2skip[node] = skip+1+pushed;
156 void AP_main::rollback_to(
Level wanted_frameLevel) {
159 Level frame_level = frameLevel-1;
160 ap_assert(frame_level == frames.count_elements());
162 typedef map<AP_tree_nlen*,int> NodeCounter;
163 NodeCounter pops2skip;
167 AP_tree_nlen *node = *n;
172 if (frame_level == wanted_frameLevel)
break;
173 ap_assert(frame_level>wanted_frameLevel);
176 #if defined(ASSERTION_USED)
181 AP_tree_nlen *node = *n;
182 NodeCounter::iterator skipCounter = pops2skip.find(node);
183 int skip = skipCounter == pops2skip.end() ? 0 : skipCounter->second;
184 const StateStack& states = node->get_states();
187 if (skip>0) advance(toRestore, skip);
194 node->restore_nondestructive(*prevState);
196 pops2skip[node] = skip+1;
199 #if defined(CHECK_ROOT_POPS)
210 if (!currFrame)
GBK_terminate(
"AP_main::accept on empty stack");
221 frameData->extract_common_to(*common);
224 while ((node = currFrame->pop())) {
225 if (node->acceptCurrentState(frameLevel) !=
true) {
235 prev_frame->
push(node);
241 currFrame->accept_resources(frameData, common);
243 frameData = currFrame->take_previous_frame_data();
246 currFrame = prev_frame;
260 if (mode &
SEQUENCE) node->unhash_sequence();
263 if (frameLevel < node->last_remembered_frame()) {
264 cerr <<
"Main frame level=" << frameLevel <<
" node frame level=" << node->last_remembered_frame() << endl;
265 GBK_terminate(
"AP_main::push_node: main/node frame-level inconsistency");
273 if (frameData->root_pushed) {
278 frameData->root_pushed =
true;
279 #if defined(CHECK_ROOT_POPS)
280 ap_assert(node == currFrame->root_at_create);
285 if (node->rememberState(mode, frameLevel)) {
286 currFrame->push(node);
292 currFrame->remove(node);
293 currFrame->shift(node);
305 return get_tree_root()->get_aliview()->get_aliname();
308 #if defined(UNIT_TESTS)
309 void AP_main::remember_whole_tree() {
311 AP_tree_nlen *root = get_root_node();
312 push_node(root,
ROOT);
314 root->get_leftson()->remember_subtree(
this);
315 root->get_rightson()->remember_subtree(
this);
GBDATA * GB_open(const char *path, const char *opent)
AP_tree_nlen * root_at_create
size_t count_elements() const
#define ASSERT_RESULT(Type, Expected, Expr)
void remember_user_state()
#define DOWNCAST(totype, expr)
BASE::const_iterator const_iterator
bool push_node(AP_tree_nlen *node, AP_STACK_MODE)
GB_ERROR GB_await_error()
void GBK_terminate(const char *error) __ATTR__NORETURN
static void error(const char *msg)
GB_ERROR open(const char *db_server)
HasLevelSmallerThan(Level level_)
bool operator()(const NodeState *state) const
bool has_node(AP_tree_nlen *node) const
void aw_message(const char *msg)
void set_tree_root(AWT_graphic_parsimony *agt_)
const char * get_aliname() const