• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2012, The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 // Defines utility allowing in-memory buffers for bitcode input wrapping.
18 
19 #ifndef IN_MEMORY_WRAPPER_INPUT_H__
20 #define IN_MEMORY_WRAPPER_INPUT_H__
21 
22 #include <stdio.h>
23 
24 #include "bcinfo/Wrap/support_macros.h"
25 #include "bcinfo/Wrap/wrapper_input.h"
26 
27 // Define a class to wrap named files.
28 class InMemoryWrapperInput : public WrapperInput {
29  public:
30   InMemoryWrapperInput(const char* buffer, size_t size);
31   ~InMemoryWrapperInput();
32   // Tries to read the requested number of bytes into the buffer. Returns the
33   // actual number of bytes read.
34   virtual size_t Read(uint8_t* buffer, size_t wanted);
35   // Returns true if at end of buffer. Note: May return false
36   // until Read is called, and returns 0.
37   virtual bool AtEof();
38   // Returns the size of the buffer (in bytes).
39   virtual off_t Size();
40   // Moves to the given offset within the buffer. Returns
41   // false if unable to move to that position.
42   virtual bool Seek(uint32_t pos);
43  private:
44   // The actual in-memory buffer
45   const char* _buffer;
46   // The position in the buffer
47   size_t _pos;
48   // True once eof has been encountered.
49   bool _at_eof;
50   // The size of the buffer.
51   size_t _size;
52  private:
53   DISALLOW_CLASS_COPY_AND_ASSIGN(InMemoryWrapperInput);
54 };
55 
56 #endif // IN_MEMORY_WRAPPER_INPUT_H__
57