• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /*-----------------------------------------------------------------------------+
12 itvset_shell.cpp provides  a simple test shells for interval sets.
13 The shell also gives you a good idea how interval container are working.
14 +-----------------------------------------------------------------------------*/
15 #include <iostream>
16 
17 #include <boost/icl/split_interval_set.hpp>
18 #include <boost/icl/split_interval_map.hpp>
19 
20 using namespace std;
21 using namespace boost;
22 using namespace boost::icl;
23 
instructions()24 void instructions()
25 {
26     cout << "+++++ Test shell for interval set +++++\n";
27     cout << "Type: q e or 0  to quit\n";
28     cout << "Type: +         for insertions\n";
29     cout << "Type: -         for subtraction\n";
30     cout << "Type: j         to join contiguous intervals\n";
31     cout << "Type: s         to compute total size\n";
32 }
33 
wrongInput()34 void wrongInput()
35 {
36     cout << "Wrong Input ------------------\n";
37     instructions();
38 }
39 
40 
41 template <class SetTV>
setTestShell()42 void setTestShell()
43 {
44     SetTV m1;
45 
46     try {
47         char cmd = 'b';
48         typename SetTV::domain_type lwb = typename SetTV::domain_type();
49         typename SetTV::domain_type upb = typename SetTV::domain_type();
50 
51         instructions();
52 
53         for(;;)
54         {
55             cout << "> ";
56             cin >> cmd ;
57 
58             switch(cmd)
59             {
60             case 'q':
61             case 'e':
62             case '0': cout << "good bye\n"; return;
63             case '+':
64                 {
65                     cout << "input: lwb upb >> ";
66                     cin >> lwb >> upb;
67                     typename SetTV::interval_type itv
68                         = typename SetTV::interval_type(lwb,upb);
69                     // SetTV::IntervalTD itv = rightOpenInterval(lwb,upb);
70                     m1.insert(itv);
71 
72                     cout << "+" << itv << " =" << endl;
73                     cout << "{" << m1 << "}" << endl;
74 
75                 }
76                 break;
77             case '-':
78                 {
79                     cout << "input: lwb upb >> ";
80                     cin >> lwb >> upb;
81                     typename SetTV::interval_type itv
82                         = typename SetTV::interval_type(lwb,upb);
83                     // m1.subtract(itv);
84                     SetTV tmp;
85                     tmp.insert(itv);
86                     m1 -= tmp;
87 
88                     cout << "-" << itv << " =" << endl;
89                     cout << "{" << m1 << "}" << endl;
90 
91                 }
92                 break;
93             case 'j':
94                 {
95                     icl::join(m1);
96                     cout << "{" << m1 << "}" << endl;
97                 }
98                 break;
99             case 's':
100                 {
101                     cout << "size = " << m1.size() << endl;
102                 }
103                 break;
104 
105             default: wrongInput();
106             }
107         }
108 
109     }
110     catch (exception& e)
111     {
112         cout << "itvset_shell: exception caught: " << endl
113              << e.what() << endl;
114     }
115     catch (...)
116     {
117         cout << "itvset_shell: unknown exception caught" << endl;
118     }
119 }
120 
121 
122 
123 
main()124 int main()
125 {
126     cout << ">>Interval Container Library: Test itvset_shell.cpp <<\n";
127     cout << "------------------------------------------------------\n";
128     setTestShell< interval_set<int> >();
129 
130     return 0;
131 }
132 
133