splititvmap_shell.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*-----------------------------------------------------------------------------+
  2. Copyright (c) 2007-2009: Joachim Faulhaber
  3. +------------------------------------------------------------------------------+
  4. Copyright (c) 1999-2006: Cortex Software GmbH, Kantstrasse 57, Berlin
  5. +------------------------------------------------------------------------------+
  6. Distributed under the Boost Software License, Version 1.0.
  7. (See accompanying file LICENCE.txt or copy at
  8. http://www.boost.org/LICENSE_1_0.txt)
  9. +-----------------------------------------------------------------------------*/
  10. /*-----------------------------------------------------------------------------+
  11. splititvmap_shell.cpp provides a simple test shell for splitting interval maps.
  12. The shell also gives you a good idea how interval container are working.
  13. +-----------------------------------------------------------------------------*/
  14. #include <iostream>
  15. #include <boost/icl/split_interval_set.hpp>
  16. #include <boost/icl/split_interval_map.hpp>
  17. #include <boost/icl/interval_map.hpp>
  18. using namespace std;
  19. using namespace boost;
  20. using namespace boost::icl;
  21. void instructions()
  22. {
  23. cout << "+++++ Test shell for split interval map +++++\n";
  24. cout << "Type: q e or 0 to quit\n";
  25. cout << "Type: + for insertions\n";
  26. cout << "Type: - for subtraction of ([a,b],value)\n";
  27. cout << "Type: _ for subtraction of [a,b]\n";
  28. cout << "Type: j to join contiguous intervals\n";
  29. cout << "Type: s to compute total size\n";
  30. }
  31. void wrongInput()
  32. {
  33. cout << "Wrong Input ------------------\n";
  34. instructions();
  35. }
  36. template <class MapTV>
  37. void mapTestShell()
  38. {
  39. MapTV m1;
  40. try {
  41. char cmd = 'b';
  42. typename MapTV::domain_type
  43. lwb = typename MapTV::domain_type(),
  44. upb = typename MapTV::domain_type();
  45. typename MapTV::codomain_type
  46. val = typename MapTV::codomain_type();
  47. instructions();
  48. for(;;)
  49. {
  50. cout << "> ";
  51. cin >> cmd ;
  52. switch(cmd)
  53. {
  54. case 'q':
  55. case 'e':
  56. case '0': cout << "good bye\n"; return;
  57. case '+':
  58. {
  59. cout << "input: lwb upb val >> ";
  60. cin >> lwb >> upb >> val;
  61. typename MapTV::interval_type
  62. itv = typename MapTV::interval_type(lwb,upb);
  63. m1 += make_pair(itv,val);
  64. cout << "+" << itv << " " << val << " =" << endl;
  65. cout << "{" << m1 << "}" << endl;
  66. }
  67. break;
  68. case '-':
  69. {
  70. cout << "input: lwb upb val >> ";
  71. cin >> lwb >> upb >> val;
  72. typename MapTV::interval_type
  73. itv = typename MapTV::interval_type(lwb,upb);
  74. m1 -= make_pair(itv,val);
  75. cout << "-" << itv << " " << val << " =" << endl;
  76. cout << "{" << m1 << "}" << endl;
  77. }
  78. break;
  79. case 'j':
  80. {
  81. icl::join(m1);
  82. cout << "{" << m1 << "}" << endl;
  83. }
  84. break;
  85. case 's':
  86. {
  87. cout << "size = " << m1.size() << endl;
  88. }
  89. break;
  90. default: wrongInput();
  91. }
  92. } // end while
  93. }
  94. catch (exception& e)
  95. {
  96. cout << "splititvmap_shell: exception caught: " << endl
  97. << e.what() << endl;
  98. }
  99. catch (...)
  100. {
  101. cout << "splititvmap_shell: unknown exception caught" << endl;
  102. }
  103. }
  104. int main()
  105. {
  106. cout << ">>Interval Container Library: Test splititvmap_shell.cpp <<\n";
  107. cout << "-----------------------------------------------------------\n";
  108. mapTestShell< interval_map<int, int> >();
  109. return 0;
  110. }