itvset_shell.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. itvset_shell.cpp provides a simple test shells for interval sets.
  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. using namespace std;
  18. using namespace boost;
  19. using namespace boost::icl;
  20. void instructions()
  21. {
  22. cout << "+++++ Test shell for interval set +++++\n";
  23. cout << "Type: q e or 0 to quit\n";
  24. cout << "Type: + for insertions\n";
  25. cout << "Type: - for subtraction\n";
  26. cout << "Type: j to join contiguous intervals\n";
  27. cout << "Type: s to compute total size\n";
  28. }
  29. void wrongInput()
  30. {
  31. cout << "Wrong Input ------------------\n";
  32. instructions();
  33. }
  34. template <class SetTV>
  35. void setTestShell()
  36. {
  37. SetTV m1;
  38. try {
  39. char cmd = 'b';
  40. typename SetTV::domain_type lwb = typename SetTV::domain_type();
  41. typename SetTV::domain_type upb = typename SetTV::domain_type();
  42. instructions();
  43. for(;;)
  44. {
  45. cout << "> ";
  46. cin >> cmd ;
  47. switch(cmd)
  48. {
  49. case 'q':
  50. case 'e':
  51. case '0': cout << "good bye\n"; return;
  52. case '+':
  53. {
  54. cout << "input: lwb upb >> ";
  55. cin >> lwb >> upb;
  56. typename SetTV::interval_type itv
  57. = typename SetTV::interval_type(lwb,upb);
  58. // SetTV::IntervalTD itv = rightOpenInterval(lwb,upb);
  59. m1.insert(itv);
  60. cout << "+" << itv << " =" << endl;
  61. cout << "{" << m1 << "}" << endl;
  62. }
  63. break;
  64. case '-':
  65. {
  66. cout << "input: lwb upb >> ";
  67. cin >> lwb >> upb;
  68. typename SetTV::interval_type itv
  69. = typename SetTV::interval_type(lwb,upb);
  70. // m1.subtract(itv);
  71. SetTV tmp;
  72. tmp.insert(itv);
  73. m1 -= tmp;
  74. cout << "-" << itv << " =" << endl;
  75. cout << "{" << m1 << "}" << endl;
  76. }
  77. break;
  78. case 'j':
  79. {
  80. icl::join(m1);
  81. cout << "{" << m1 << "}" << endl;
  82. }
  83. break;
  84. case 's':
  85. {
  86. cout << "size = " << m1.size() << endl;
  87. }
  88. break;
  89. default: wrongInput();
  90. }
  91. }
  92. }
  93. catch (exception& e)
  94. {
  95. cout << "itvset_shell: exception caught: " << endl
  96. << e.what() << endl;
  97. }
  98. catch (...)
  99. {
  100. cout << "itvset_shell: unknown exception caught" << endl;
  101. }
  102. }
  103. int main()
  104. {
  105. cout << ">>Interval Container Library: Test itvset_shell.cpp <<\n";
  106. cout << "------------------------------------------------------\n";
  107. setTestShell< interval_set<int> >();
  108. return 0;
  109. }