• 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 splititvmap_shell.cpp provides  a simple test shell for splitting interval maps.
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 #include <boost/icl/interval_map.hpp>
20 
21 using namespace std;
22 using namespace boost;
23 using namespace boost::icl;
24 
instructions()25 void instructions()
26 {
27     cout << "+++++ Test shell for split interval map +++++\n";
28     cout << "Type: q e or 0  to quit\n";
29     cout << "Type: +         for insertions\n";
30     cout << "Type: -         for subtraction of ([a,b],value)\n";
31     cout << "Type: _         for subtraction of [a,b]\n";
32     cout << "Type: j         to join contiguous intervals\n";
33     cout << "Type: s         to compute total size\n";
34 }
35 
wrongInput()36 void wrongInput()
37 {
38     cout << "Wrong Input ------------------\n";
39     instructions();
40 }
41 
42 
43 template <class MapTV>
mapTestShell()44 void mapTestShell()
45 {
46     MapTV m1;
47 
48     try {
49         char cmd = 'b';
50         typename MapTV::domain_type
51             lwb = typename MapTV::domain_type(),
52             upb = typename MapTV::domain_type();
53 
54         typename MapTV::codomain_type
55             val = typename MapTV::codomain_type();
56 
57         instructions();
58 
59         for(;;)
60         {
61             cout << "> ";
62             cin >> cmd ;
63 
64             switch(cmd)
65             {
66             case 'q':
67             case 'e':
68             case '0': cout << "good bye\n"; return;
69             case '+':
70                 {
71                     cout << "input: lwb upb val >> ";
72                     cin >> lwb >> upb >> val;
73                     typename MapTV::interval_type
74                         itv = typename MapTV::interval_type(lwb,upb);
75                     m1 += make_pair(itv,val);
76 
77                     cout << "+" << itv << " " << val << " =" << endl;
78                     cout << "{" << m1 << "}" << endl;
79 
80                 }
81                 break;
82             case '-':
83                 {
84                     cout << "input: lwb upb val >> ";
85                     cin >> lwb >> upb >> val;
86                     typename MapTV::interval_type
87                         itv = typename MapTV::interval_type(lwb,upb);
88                     m1 -= make_pair(itv,val);
89 
90                     cout << "-" << itv << " " << val << " =" << endl;
91                     cout << "{" << m1 << "}" << endl;
92 
93                 }
94                 break;
95             case 'j':
96                 {
97                     icl::join(m1);
98                     cout << "{" << m1 << "}" << endl;
99                 }
100                 break;
101             case 's':
102                 {
103                     cout << "size = " << m1.size() << endl;
104                 }
105                 break;
106 
107             default: wrongInput();
108             }
109         } // end while
110     }
111     catch (exception& e)
112     {
113         cout << "splititvmap_shell: exception caught: " << endl
114              << e.what() << endl;
115     }
116     catch (...)
117     {
118         cout << "splititvmap_shell: unknown exception caught" << endl;
119     }
120 }
121 
122 
main()123 int main()
124 {
125     cout << ">>Interval Container Library: Test splititvmap_shell.cpp <<\n";
126     cout << "-----------------------------------------------------------\n";
127     mapTestShell< interval_map<int, int> >();
128 
129     return 0;
130 }
131 
132