1
// This file is part of PUMA.
2
// Copyright (C) 1999-2003 The PUMA developer team.
4
// This program is free software; you can redistribute it and/or
5
// modify it under the terms of the GNU General Public License as
6
// published by the Free Software Foundation; either version 2 of
7
// the License, or (at your option) any later version.
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU General Public License for more details.
14
// You should have received a copy of the GNU General Public
15
// License along with this program; if not, write to the Free
16
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
19
#ifndef __sb_whole_file_h__
20
#define __sb_whole_file_h__
22
#include "Puma/SB_String.h"
23
#include "Puma/ErrorStream.h"
24
#include "Puma/Source.h"
29
class SB_WholeFile : public SB_String {
34
SB_WholeFile () : SB_String (), buffer (0) {}
35
virtual ~SB_WholeFile () { if (buffer) delete[] buffer; }
37
void init (ErrorSink &err, Source &src) {
38
if (buffer) delete[] buffer;
41
int buffer_size = src.size ();
42
if (buffer_size < 0) {
43
err << sev_error << "can't determine size of input file"
49
buffer = new char[buffer_size];
50
if (! buffer) { // Help, this should not happen, but why not checking
51
err << sev_error << "Out of memory" << endMessage;
56
if (src.read (buffer, src.size ()) != src.size ()) {
57
err << sev_error << "can't load input file" << endMessage;
62
SB_String::init (buffer, buffer_size);
65
State state () const { return error ? STATE_ERROR : SB_String::state (); }
71
#endif /* __sb_whole_file_h__ */