#ifndef GHOST_ABSTRACT_H #define GHOST_ABSTRACT_H template class Map { public: Link > a; Link > b; enum { none, b_out, b_out_a_in, a_out, a_out_b_in } state; Map(A& a, B& b) : a(a, this, &Map::push_a, &Map::pull_a), b(b, this, &Map::push_b, &Map::pull_b), state(none) {} virtual void a_to_b() = 0; virtual void b_to_a() = 0; void _a_to_b() { a_to_b(); state = b_out; b.push(); a.pull(); } void _b_to_a() { b_to_a(); state = a_out; a.push(); b.pull(); } // TODO - I could make this class a template over M for efficiency? // Doubtful that it would help any - can try later. void push_a() { assert(state == none || state == b_out); if (state == none) _a_to_b(); else state = b_out_a_in; } void push_b() { assert(state == none || state == a_out); if (state == none) _b_to_a(); else state = a_out_b_in; } void pull_a() { assert(state == a_out || state == a_out_b_in); if (state == a_out) state = none; else _b_to_a(); } void pull_b() { assert(state == b_out || state == b_out_a_in); if (state == b_out) state = none; else _a_to_b(); } }; #endif