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 Child getNext() const;
38 error_code getName(StringRef &Result) const;
39 int getLastModified() const;
42 int getAccessMode() const;
43 ///! Return the size of the archive member without the header or padding.
44 uint64_t getSize() const;
46 MemoryBuffer *getBuffer() const;
47 error_code getAsBinary(OwningPtr<Binary> &Result) const;
50 class child_iterator {
53 child_iterator() : child(Child(0, StringRef())) {}
54 child_iterator(const Child &c) : child(c) {}
55 const Child* operator->() const {
59 bool operator==(const child_iterator &other) const {
60 return child == other.child;
63 bool operator!=(const child_iterator &other) const {
64 return !(*this == other);
67 child_iterator& operator++() { // Preincrement
68 child = child.getNext();
74 const Archive *Parent;
76 uint32_t StringIndex; // Extra index to the string.
79 bool operator ==(const Symbol &other) const {
80 return (Parent == other.Parent) && (SymbolIndex == other.SymbolIndex);
83 Symbol(const Archive *p, uint32_t symi, uint32_t stri)
86 , StringIndex(stri) {}
87 error_code getName(StringRef &Result) const;
88 error_code getMember(child_iterator &Result) const;
89 Symbol getNext() const;
92 class symbol_iterator {
95 symbol_iterator(const Symbol &s) : symbol(s) {}
96 const Symbol *operator->() const {
100 bool operator==(const symbol_iterator &other) const {
101 return symbol == other.symbol;
104 bool operator!=(const symbol_iterator &other) const {
105 return !(*this == other);
108 symbol_iterator& operator++() { // Preincrement
109 symbol = symbol.getNext();
114 Archive(MemoryBuffer *source, error_code &ec);
116 child_iterator begin_children(bool skip_internal = true) const;
117 child_iterator end_children() const;
119 symbol_iterator begin_symbols() const;
120 symbol_iterator end_symbols() const;
123 static inline bool classof(Archive const *v) { return true; }
124 static inline bool classof(Binary const *v) {
125 return v->getType() == Binary::isArchive;
129 child_iterator SymbolTable;
130 child_iterator StringTable;