//This file is main.C. #include #include #include #include using namespace std; #include "printable.h" #include "terminal.h" #include "terminal_traits.h" template class terminal_traits > { public: typedef typename terminal::offset_type offset_type; static offset_type rand() { return offset_type::rand(); } static offset_type signum(const offset_type& off) { return offset_type::signum(off); } typedef pair key_t; typedef map keypad_t; static keypad_t keypad(); friend ostream& operator<<(ostream& ost, const key_t& key) { return ost << "('" << key.first << "', " << key.second << ")"; } }; template typename terminal_traits >::keypad_t terminal_traits >::keypad() { #ifdef _MSC_VER keypad_t k; k.insert(key_t('h', offset_type(-1, 0)); //left k.insert(key_t('j', offset_type( 0, -1)); //down k.insert(key_t('k', offset_type( 0, 1)); //up k.insert(key_t('l', offset_type( 1, 0)); //right return k; #else static const key_t a[] = { key_t('h', offset_type(-1, 0)), //left key_t('j', offset_type( 0, -1)), //down key_t('k', offset_type( 0, 1)), //up key_t('l', offset_type( 1, 0)) //right }; static const size_t n = sizeof a / sizeof a[0]; return keypad_t(a, a + n); #endif } template inline typename terminal::value_type background(const terminal& term) { return term.background(); } int main() { typedef vector container1_t; typedef terminal_traits traits1_t; typedef traits1_t::keypad_t keypad1_t; const keypad1_t keypad1 = traits1_t::keypad(); for (keypad1_t::const_iterator it = keypad1.begin(); it != keypad1.end(); ++it) { cout << *it << "\n"; } cout << "\n"; typedef terminal container2_t; typedef terminal_traits traits2_t; typedef traits2_t::keypad_t keypad2_t; const keypad2_t keypad2 = traits2_t::keypad(); for (keypad2_t::const_iterator it = keypad2.begin(); it != keypad2.end(); ++it) { cout << *it << "\n"; } return EXIT_SUCCESS; }