Home | History | Annotate | Download | only in Object
      1 //===- Archive.h - ar archive file format -----------------------*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // This file declares the ar archive file format class.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #ifndef LLVM_OBJECT_ARCHIVE_H
     15 #define LLVM_OBJECT_ARCHIVE_H
     16 
     17 #include "llvm/Object/Binary.h"
     18 #include "llvm/ADT/StringRef.h"
     19 #include "llvm/Support/DataTypes.h"
     20 
     21 namespace llvm {
     22 namespace object {
     23 
     24 class Archive : public Binary {
     25 public:
     26   class Child {
     27     const Archive *Parent;
     28     StringRef Data;
     29 
     30   public:
     31     Child(const Archive *p, StringRef d) : Parent(p), Data(d) {}
     32 
     33     bool operator ==(const Child &other) const {
     34       return (Parent == other.Parent) && (Data.begin() == other.Data.begin());
     35     }
     36 
     37     Child getNext() const;
     38     error_code getName(StringRef &Result) const;
     39     int getLastModified() const;
     40     int getUID() const;
     41     int getGID() const;
     42     int getAccessMode() const;
     43     ///! Return the size of the archive member without the header or padding.
     44     uint64_t getSize() const;
     45 
     46     MemoryBuffer *getBuffer() const;
     47     error_code getAsBinary(OwningPtr<Binary> &Result) const;
     48   };
     49 
     50   class child_iterator {
     51     Child child;
     52   public:
     53     child_iterator(const Child &c) : child(c) {}
     54     const Child* operator->() const {
     55       return &child;
     56     }
     57 
     58     bool operator==(const child_iterator &other) const {
     59       return child == other.child;
     60     }
     61 
     62     bool operator!=(const child_iterator &other) const {
     63       return !(*this == other);
     64     }
     65 
     66     child_iterator& operator++() {  // Preincrement
     67       child = child.getNext();
     68       return *this;
     69     }
     70   };
     71 
     72   Archive(MemoryBuffer *source, error_code &ec);
     73 
     74   child_iterator begin_children() const;
     75   child_iterator end_children() const;
     76 
     77   // Cast methods.
     78   static inline bool classof(Archive const *v) { return true; }
     79   static inline bool classof(Binary const *v) {
     80     return v->getType() == Binary::isArchive;
     81   }
     82 
     83 private:
     84   child_iterator StringTable;
     85 };
     86 
     87 }
     88 }
     89 
     90 #endif
     91