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 {
27 const Archive *Parent;
31 Child(const Archive *p, StringRef d) : Parent(p), Data(d) {}
33 bool operator ==(const Child &other) const {
34 return (Parent == other.Parent) && (Data.begin() == other.Data.begin());
37 bool operator <(const Child &other) const {
38 return Data.begin() < other.Data.begin();
41 Child getNext() const;
42 error_code getName(StringRef &Result) const;
43 int getLastModified() const;
46 int getAccessMode() const;
47 ///! Return the size of the archive member without the header or padding.
48 uint64_t getSize() const;
50 MemoryBuffer *getBuffer() const;
51 error_code getAsBinary(OwningPtr<Binary> &Result) const;
54 class child_iterator {
57 child_iterator() : child(Child(0, StringRef())) {}
58 child_iterator(const Child &c) : child(c) {}
59 const Child* operator->() const {
63 bool operator==(const child_iterator &other) const {
64 return child == other.child;
67 bool operator!=(const child_iterator &other) const {
68 return !(*this == other);
71 bool operator <(const child_iterator &other) const {
72 return child < other.child;
75 child_iterator& operator++() { // Preincrement
76 child = child.getNext();
82 const Archive *Parent;
84 uint32_t StringIndex; // Extra index to the string.
87 bool operator ==(const Symbol &other) const {
88 return (Parent == other.Parent) && (SymbolIndex == other.SymbolIndex);
91 Symbol(const Archive *p, uint32_t symi, uint32_t stri)
94 , StringIndex(stri) {}
95 error_code getName(StringRef &Result) const;
96 error_code getMember(child_iterator &Result) const;
97 Symbol getNext() const;
100 class symbol_iterator {
103 symbol_iterator(const Symbol &s) : symbol(s) {}
104 const Symbol *operator->() const {
108 bool operator==(const symbol_iterator &other) const {
109 return symbol == other.symbol;
112 bool operator!=(const symbol_iterator &other) const {
113 return !(*this == other);
116 symbol_iterator& operator++() { // Preincrement
117 symbol = symbol.getNext();
122 Archive(MemoryBuffer *source, error_code &ec);
124 child_iterator begin_children(bool skip_internal = true) const;
125 child_iterator end_children() const;
127 symbol_iterator begin_symbols() const;
128 symbol_iterator end_symbols() const;
131 static inline bool classof(Archive const *v) { return true; }
132 static inline bool classof(Binary const *v) {
133 return v->getType() == Binary::isArchive;
137 child_iterator SymbolTable;
138 child_iterator StringTable;