Remove dynamic exceptions
[anna.git] / example / io / reader / reader.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 <anna/core/core.hpp>
12 #include <anna/io/io.hpp>
13
14 #include <anna/app/Application.hpp>
15
16 class Test : public anna::app::Application {
17 public:
18    Test ();
19    
20    void initialize () noexcept(false);
21    
22 private:
23    void run () noexcept(false);      
24 };
25
26 using namespace std;
27
28 int main (int argc, const char** argv)
29 {
30    CommandLine& commandLine (CommandLine::instantiate ());
31    Test test;
32
33    try {
34       commandLine.initialize (argv, argc);
35       commandLine.verify ();
36
37       Logger::setLevel (Logger::Debug); 
38       Logger::initialize ("testfunctions", new TraceWriter ("file.trace", 2048000));
39  
40       test.start ();
41    }
42    catch (Exception& ex) {
43       cout << ex.asString () << endl;
44    }
45    
46    return 0;
47 }
48
49 Test::Test () : 
50    app::Application ("testfunctions", "Comprobacion del sistema io", "1.0") 
51 {
52    CommandLine& commandLine (CommandLine::instantiate ());
53       
54    commandLine.add ("file", CommandLine::Argument::Mandatory, "Nombre del fichero a procesar");
55    commandLine.add ("mode", CommandLine::Argument::Mandatory, "Modo (binary|text)");
56    commandLine.add ("size", CommandLine::Argument::Mandatory, "Tamano del buffer de entrada");
57 }
58
59 void Test::initialize () 
60    noexcept(false)
61 {
62 }
63
64 void Test::run () 
65    noexcept(false)
66 {
67    CommandLine& commandLine (CommandLine::instantiate ());
68
69    const char* mode = commandLine.getValue ("mode");
70    int size = commandLine.getIntegerValue ("size");
71    const char* file = commandLine.getValue ("file");
72
73    if (anna_strcmp (mode, "binary") == 0) {
74       BinaryReader reader (file, size);
75       const DataBlock* dataBlock;
76
77       while ((dataBlock = reader.fetch ()) != NULL) 
78          cout << anna::functions::asString (*dataBlock, 24) << endl << endl;
79    }
80    else if (anna_strcmp (mode, "text") == 0) {
81       TextReader reader (file, size);
82       const char* line;
83       while ((line = reader.fetch ()) != NULL) 
84          cout << line << endl << endl;
85    }
86 }
87