1 //===- Archive.h - ar archive file format -----------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the ar archive file format class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_OBJECT_ARCHIVE_H
15 #define LLVM_OBJECT_ARCHIVE_H
17 #include "llvm/Object/Binary.h"
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/Support/DataTypes.h"
24 class Archive : public Binary {
25 virtual void anchor();
28 const Archive *Parent;
32 Child(const Archive *p, StringRef d) : Parent(p), Data(d) {}
34 bool operator ==(const Child &other) const {
35 return (Parent == other.Parent) && (Data.begin() == other.Data.begin());
38 bool operator <(const Child &other) const {
39 return Data.begin() < other.Data.begin();
42 Child getNext() const;
43 error_code getName(StringRef &Result) const;
44 int getLastModified() const;
47 int getAccessMode() const;
48 ///! Return the size of the archive member without the header or padding.
49 uint64_t getSize() const;
51 MemoryBuffer *getBuffer() const;
52 error_code getAsBinary(OwningPtr<Binary> &Result) const;
55 class child_iterator {
58 child_iterator() : child(Child(0, StringRef())) {}
59 child_iterator(const Child &c) : child(c) {}
60 const Child* operator->() const {
64 bool operator==(const child_iterator &other) const {
65 return child == other.child;
68 bool operator!=(const child_iterator &other) const {
69 return !(*this == other);
72 bool operator <(const child_iterator &other) const {
73 return child < other.child;
76 child_iterator& operator++() { // Preincrement
77 child = child.getNext();
83 const Archive *Parent;
85 uint32_t StringIndex; // Extra index to the string.
88 bool operator ==(const Symbol &other) const {
89 return (Parent == other.Parent) && (SymbolIndex == other.SymbolIndex);
92 Symbol(const Archive *p, uint32_t symi, uint32_t stri)
95 , StringIndex(stri) {}
96 error_code getName(StringRef &Result) const;
97 error_code getMember(child_iterator &Result) const;
98 Symbol getNext() const;
101 class symbol_iterator {
104 symbol_iterator(const Symbol &s) : symbol(s) {}
105 const Symbol *operator->() const {
109 bool operator==(const symbol_iterator &other) const {
110 return symbol == other.symbol;
113 bool operator!=(const symbol_iterator &other) const {
114 return !(*this == other);
117 symbol_iterator& operator++() { // Preincrement
118 symbol = symbol.getNext();
123 Archive(MemoryBuffer *source, error_code &ec);
125 child_iterator begin_children(bool skip_internal = true) const;
126 child_iterator end_children() const;
128 symbol_iterator begin_symbols() const;
129 symbol_iterator end_symbols() const;
132 static inline bool classof(Binary const *v) {
133 return v->isArchive();
137 child_iterator SymbolTable;
138 child_iterator StringTable;