Remove dynamic exceptions
[anna.git] / source / io / TextReader.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 <stdio.h>
10
11 #include <anna/config/defines.hpp>
12
13 #include <anna/io/TextReader.hpp>
14 #include <anna/io/internal/sccs.hpp>
15
16 using namespace std;
17 using namespace anna;
18
19 io::TextReader::TextReader(const int maxLength) :
20   AbstractReader(),
21   a_maxLength(maxLength) {
22   a_buffer = new char [maxLength];
23   sccs::activate();
24 }
25
26 io::TextReader::TextReader(const char* filename, const int maxLength) :
27   AbstractReader(filename),
28   a_maxLength(maxLength) {
29   a_buffer = new char [maxLength];
30   sccs::activate();
31 }
32
33 io::TextReader::TextReader(const std::string& filename, const int maxLength) :
34   AbstractReader(filename),
35   a_maxLength(maxLength) {
36   a_buffer = new char [maxLength];
37   sccs::activate();
38 }
39
40 /* virtual */
41 io::TextReader::~TextReader() {
42   delete [] a_buffer;
43 }
44
45 const char* io::TextReader::fetch()
46 noexcept(false) {
47   verify();
48   char* result = fgets(a_buffer, a_maxLength - 1, a_file);
49
50   if(result != NULL) {
51     char* w = anna_strchr(result, '\n');
52
53     if(w != NULL)
54       *w = 0;
55   }
56
57   return result;
58 }