~ubuntu-branches/ubuntu/maverick/aspectc++/maverick

« back to all changes in this revision

Viewing changes to Puma/gen-release/step1/inc/Puma/SB_WholeFile.h

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2008-04-10 17:40:52 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080410174052-xdnsm7oi8hauyyf1
Tags: 1.0pre4~svn.20080409+dfsg-3
Fix another missing include, this time in Ag++/StdSystem.cc

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// This file is part of PUMA.
2
 
// Copyright (C) 1999-2003  The PUMA developer team.
3
 
//                                                                
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.            
8
 
//                                                                
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.                   
13
 
//                                                                
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, 
17
 
// MA  02111-1307  USA                                            
18
 
 
19
 
#ifndef __sb_whole_file_h__
20
 
#define __sb_whole_file_h__
21
 
 
22
 
#include "Puma/SB_String.h"
23
 
#include "Puma/ErrorStream.h"
24
 
#include "Puma/Source.h"
25
 
 
26
 
namespace Puma {
27
 
 
28
 
 
29
 
class SB_WholeFile : public SB_String {
30
 
  char* buffer;
31
 
  bool error;
32
 
 
33
 
public:
34
 
  SB_WholeFile () : SB_String (), buffer (0) {}
35
 
  virtual ~SB_WholeFile () { if (buffer) delete[] buffer; }
36
 
 
37
 
  void init (ErrorSink &err, Source &src) { 
38
 
    if (buffer) delete[] buffer;
39
 
 
40
 
    error = false;
41
 
    int buffer_size = src.size ();
42
 
    if (buffer_size < 0) {
43
 
      err << sev_error << "can't determine size of input file" 
44
 
          << endMessage;
45
 
      error = true;
46
 
      return;
47
 
    }
48
 
 
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;
52
 
      error = true;
53
 
      return;
54
 
    }
55
 
         
56
 
    if (src.read (buffer, src.size ()) != src.size ()) {
57
 
      err << sev_error << "can't load input file" << endMessage;
58
 
      error = true;
59
 
      return;
60
 
    }
61
 
 
62
 
    SB_String::init (buffer, buffer_size);
63
 
  }
64
 
 
65
 
  State state () const { return error ? STATE_ERROR : SB_String::state (); }
66
 
};
67
 
 
68
 
 
69
 
} // namespace Puma
70
 
 
71
 
#endif /* __sb_whole_file_h__ */