Remove dynamic exceptions
[anna.git] / example / core / sort / main.cpp
1 // ANNA - Anna is Not Nothingness Anymore                                                         //
2 //                                                                                                //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
4 //                                                                                                //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite                           //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
7
8
9 #include <iostream>
10
11 #include <functional>
12
13 #include <anna/core/core.hpp>
14
15 using namespace std;
16
17 struct Accesor {
18    static int value (int* i) { return *i; }
19    static int value (const int* i) { return *i; }
20 };
21
22 void run () 
23    noexcept(false)
24 {
25
26    int values [] = { 
27       49800, 49801, 49802, 57000, 49804, 49805, 49806, 62000, 102400, 49806, 62001, 49808,
28       102401, 67400, 49809, 71100, 49700, 63900,  49810, 67420, 67300, -1
29    };
30
31    SortedVector <int, Accesor> sorted;
32    typedef SortedVector <int, Accesor>::iterator iterator;
33
34    for (int i = 0; values [i] != -1; i ++) 
35       sorted.add (&values [i]);
36
37    for (iterator ii = sorted.begin (), maxii = sorted.end (); ii != maxii; ii ++) 
38        cout << functions::asString (Accesor::value (SortedVector <int, Accesor>::data (ii))) << " ";
39    cout << endl << endl;
40
41    bool found;
42    string msg;
43    int value;
44
45    for (int i = 0; values [i] != -1; i ++) {
46      value = values [i] - 1;
47      found = sorted.contains (&value);
48      msg = functions::asText ("Number-: ", value);
49      msg += functions::asText (" | Exists: ", found);
50      Logger::debug (msg, ANNA_FILE_LOCATION);
51    
52      found = sorted.contains (&values [i]);
53      msg = functions::asText ("Key: ", values [i]);
54      msg += functions::asText (" | Exists: ", found);
55      Logger::debug (msg, ANNA_FILE_LOCATION);
56   
57      value = values [i] + 1;
58      found = sorted.contains (&value);
59      msg = functions::asText ("Number+: ", value);
60      msg += functions::asText (" | Exists: ", found);
61      Logger::debug (msg, ANNA_FILE_LOCATION);
62    }
63    
64    for (int loop = 0; loop < 500; loop ++) {
65       for (int i = 0; values [i] != -1; i ++) {
66         value = values [i] - 1;
67         found = sorted.contains (&value);
68    
69         found = sorted.contains (&values [i]);
70    
71         value = values [i] + 1;
72         found = sorted.contains (&value);
73       }
74    }
75 }
76
77 int main (int argc, const char** argv)
78 {
79    try {
80       Logger::setLevel (Logger::Debug); 
81       Logger::initialize ("testfunctions", new TraceWriter ("file.trace", 2048000));
82   
83       run ();
84    }
85    catch (Exception& ex) {
86       cout << ex.asString () << endl;
87    }
88    
89    return 0;
90 }
91