1 : // Copyright 2012 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 : //
15 : // Declares a PDB file, which is an in-memory representation of a PDB file.
16 : // A PDB file consists of a collection of numbered PDB streams. The streams
17 : // themselves obey certain formats and conventions but these are not enforced
18 : // by this naive representation.
19 :
20 : #ifndef SYZYGY_PDB_PDB_FILE_H_
21 : #define SYZYGY_PDB_PDB_FILE_H_
22 :
23 : #include <vector>
24 :
25 : #include "syzygy/pdb/pdb_stream.h"
26 :
27 : namespace pdb {
28 :
29 : // A simple representation of a PDB file as a collection of numbered streams.
30 : // This object owns all of the streams referred to by it and maintains
31 : // responsibility for cleaning them up on destruction.
32 : class PdbFile {
33 : public:
34 : PdbFile();
35 : ~PdbFile();
36 :
37 : // Clears all streams. After calling this the PdbFile is in the same state as
38 : // after construction.
39 : void Clear();
40 :
41 : // Accesses the nth stream.
42 : // @param index the index of the nth stream.
43 : // @returns a pointer to the stream, NULL if it does not exist.
44 : scoped_refptr<PdbStream> GetStream(uint32 index) const;
45 :
46 : // Adds a new stream to this PDB file, returning the index of the newly
47 : // generated stream.
48 : // @param pdb_stream a pointer to a heap allocated stream object This may be
49 : // NULL, indicating that the nth stream exists but is empty.
50 : // @returns the index of the added stream.
51 : size_t AppendStream(PdbStream* pdb_stream);
52 :
53 : // Sets the nth stream. Overwrites an existing stream if there is one.
54 : // @param index the index of the stream. This must be >= 0, and must be
55 : // a stream index that already exists.
56 : // @param pdb_stream a pointer to the heap allocated stream to be placed at
57 : // the given position. This may be NULL, which is equivalent to erasing
58 : // the given stream.
59 : void ReplaceStream(uint32 index, PdbStream* pdb_stream);
60 :
61 : // Sets the nth stream. Overwrites an existing stream if there is one.
62 : // @param index the index of the stream.
63 : // @param pdb_stream a pointer to the heap allocated stream to be placed at
64 : // the given position. This may be NULL, which is equivalent to erasing
65 : // the given stream.
66 : void SetStream(uint32 index, PdbStream* pdb_stream);
67 :
68 : // Returns the number of streams in the PDB file. There are streams with
69 : // IDs 0 through StreamCount() - 1.
70 : // @returns the number of streams in the PDB file.
71 E : size_t StreamCount() const { return streams_.size(); }
72 :
73 : private:
74 : // The streams are implicitly numbered simply by their position in this
75 : // vector.
76 : std::vector<scoped_refptr<PdbStream>> streams_;
77 : };
78 :
79 : } // namespace pdb
80 :
81 : #endif // SYZYGY_PDB_PDB_FILE_H_
|