~ubuntu-branches/ubuntu/saucy/clamav/saucy

« back to all changes in this revision

Viewing changes to libclamav/c++/llvm/include/llvm/Support/MemoryBuffer.h

  • Committer: Bazaar Package Importer
  • Author(s): Leonel Nunez
  • Date: 2008-02-11 22:52:13 UTC
  • mfrom: (1.1.6 upstream)
  • mto: This revision was merged to the branch mainline in revision 38.
  • Revision ID: james.westby@ubuntu.com-20080211225213-p2uwj4czso1w2f8h
Tags: upstream-0.92~dfsg
ImportĀ upstreamĀ versionĀ 0.92~dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//===--- MemoryBuffer.h - Memory Buffer Interface ---------------*- C++ -*-===//
2
 
//
3
 
//                     The LLVM Compiler Infrastructure
4
 
//
5
 
// This file is distributed under the University of Illinois Open Source
6
 
// License. See LICENSE.TXT for details.
7
 
//
8
 
//===----------------------------------------------------------------------===//
9
 
//
10
 
//  This file defines the MemoryBuffer interface.
11
 
//
12
 
//===----------------------------------------------------------------------===//
13
 
 
14
 
#ifndef LLVM_SUPPORT_MEMORYBUFFER_H
15
 
#define LLVM_SUPPORT_MEMORYBUFFER_H
16
 
 
17
 
#include "llvm/ADT/StringRef.h"
18
 
#include "llvm/System/DataTypes.h"
19
 
#include <string>
20
 
#include <sys/stat.h>
21
 
 
22
 
namespace llvm {
23
 
 
24
 
/// MemoryBuffer - This interface provides simple read-only access to a block
25
 
/// of memory, and provides simple methods for reading files and standard input
26
 
/// into a memory buffer.  In addition to basic access to the characters in the
27
 
/// file, this interface guarantees you can read one character past the end of
28
 
/// the file, and that this character will read as '\0'.
29
 
///
30
 
/// The '\0' guarantee is needed to support an optimization -- it's intended to
31
 
/// be more efficient for clients which are reading all the data to stop
32
 
/// reading when they encounter a '\0' than to continually check the file
33
 
/// position to see if it has reached the end of the file.
34
 
class MemoryBuffer {
35
 
  const char *BufferStart; // Start of the buffer.
36
 
  const char *BufferEnd;   // End of the buffer.
37
 
 
38
 
  MemoryBuffer(const MemoryBuffer &); // DO NOT IMPLEMENT
39
 
  MemoryBuffer &operator=(const MemoryBuffer &); // DO NOT IMPLEMENT
40
 
protected:
41
 
  MemoryBuffer() {}
42
 
  void init(const char *BufStart, const char *BufEnd);
43
 
public:
44
 
  virtual ~MemoryBuffer();
45
 
 
46
 
  const char *getBufferStart() const { return BufferStart; }
47
 
  const char *getBufferEnd() const   { return BufferEnd; }
48
 
  size_t getBufferSize() const { return BufferEnd-BufferStart; }
49
 
 
50
 
  StringRef getBuffer() const { 
51
 
    return StringRef(BufferStart, getBufferSize()); 
52
 
  }
53
 
 
54
 
  /// getBufferIdentifier - Return an identifier for this buffer, typically the
55
 
  /// filename it was read from.
56
 
  virtual const char *getBufferIdentifier() const {
57
 
    return "Unknown buffer";
58
 
  }
59
 
 
60
 
  /// getFile - Open the specified file as a MemoryBuffer, returning a new
61
 
  /// MemoryBuffer if successful, otherwise returning null.  If FileSize is
62
 
  /// specified, this means that the client knows that the file exists and that
63
 
  /// it has the specified size.
64
 
  static MemoryBuffer *getFile(StringRef Filename,
65
 
                               std::string *ErrStr = 0,
66
 
                               int64_t FileSize = -1,
67
 
                               struct stat *FileInfo = 0);
68
 
  static MemoryBuffer *getFile(const char *Filename,
69
 
                               std::string *ErrStr = 0,
70
 
                               int64_t FileSize = -1,
71
 
                               struct stat *FileInfo = 0);
72
 
 
73
 
  /// getMemBuffer - Open the specified memory range as a MemoryBuffer.  Note
74
 
  /// that EndPtr[0] must be a null byte and be accessible!
75
 
  static MemoryBuffer *getMemBuffer(StringRef InputData,
76
 
                                    StringRef BufferName = "");
77
 
 
78
 
  /// getMemBufferCopy - Open the specified memory range as a MemoryBuffer,
79
 
  /// copying the contents and taking ownership of it.  This has no requirements
80
 
  /// on EndPtr[0].
81
 
  static MemoryBuffer *getMemBufferCopy(StringRef InputData,
82
 
                                        StringRef BufferName = "");
83
 
 
84
 
  /// getNewMemBuffer - Allocate a new MemoryBuffer of the specified size that
85
 
  /// is completely initialized to zeros.  Note that the caller should
86
 
  /// initialize the memory allocated by this method.  The memory is owned by
87
 
  /// the MemoryBuffer object.
88
 
  static MemoryBuffer *getNewMemBuffer(size_t Size, StringRef BufferName = "");
89
 
 
90
 
  /// getNewUninitMemBuffer - Allocate a new MemoryBuffer of the specified size
91
 
  /// that is not initialized.  Note that the caller should initialize the
92
 
  /// memory allocated by this method.  The memory is owned by the MemoryBuffer
93
 
  /// object.
94
 
  static MemoryBuffer *getNewUninitMemBuffer(size_t Size,
95
 
                                             StringRef BufferName = "");
96
 
 
97
 
  /// getSTDIN - Read all of stdin into a file buffer, and return it.
98
 
  /// If an error occurs, this returns null and fills in *ErrStr with a reason.
99
 
  static MemoryBuffer *getSTDIN(std::string *ErrStr = 0);
100
 
 
101
 
 
102
 
  /// getFileOrSTDIN - Open the specified file as a MemoryBuffer, or open stdin
103
 
  /// if the Filename is "-".  If an error occurs, this returns null and fills
104
 
  /// in *ErrStr with a reason.
105
 
  static MemoryBuffer *getFileOrSTDIN(StringRef Filename,
106
 
                                      std::string *ErrStr = 0,
107
 
                                      int64_t FileSize = -1,
108
 
                                      struct stat *FileInfo = 0);
109
 
  static MemoryBuffer *getFileOrSTDIN(const char *Filename,
110
 
                                      std::string *ErrStr = 0,
111
 
                                      int64_t FileSize = -1,
112
 
                                      struct stat *FileInfo = 0);
113
 
};
114
 
 
115
 
} // end namespace llvm
116
 
 
117
 
#endif