retdec
archive_wrapper.h
Go to the documentation of this file.
1 
7 #ifndef RETDEC_AR_EXTRACTOR_ARCHIVE_WRAPPER_H
8 #define RETDEC_AR_EXTRACTOR_ARCHIVE_WRAPPER_H
9 
10 #include <memory>
11 #include <string>
12 #include <vector>
13 
14 #include <llvm/Object/Archive.h>
15 #include <llvm/Support/Error.h>
16 
18 
19 namespace retdec {
20 namespace ar_extractor {
21 
26 {
27  public:
28  ArchiveWrapper(const std::string &archivePath, bool &succes,
29  std::string &errorMessage);
30 
33  std::size_t getNumberOfObjects() const;
35 
38  bool isThinArchive() const;
39  bool isEmptyArchive() const;
41 
44  bool getPlainTextList(std::string &result, std::string &errorMessage,
45  bool niceNames = false, bool numbers = true) const;
46  bool getJsonList(std::string &result, std::string &errorMessage,
47  bool niceNames = false, bool numbers = true) const;
49 
52  bool extract(std::string &errorMessage,
53  const std::string &directory = "") const;
54  bool extractByName(const std::string &name, std::string &errorMessage,
55  const std::string &outputPath = "") const;
56  bool extractByIndex(const std::size_t index, std::string &errorMessage,
57  const std::string &outputPath = "") const;
59 
60  private:
62  std::unique_ptr<llvm::object::Archive> archive;
64  llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> buffer;
65 
68  bool getNames(std::vector<std::string> &result,
69  std::string &errorMessage) const;
70  bool getCount(std::size_t &count, std::string &errorMessage) const;
72 
73  std::size_t objectCount = 0;
74 };
75 
76 } // namespace ar_extractor
77 } // namespace retdec
78 
79 #endif
Definition: archive_wrapper.h:26
bool extract(std::string &errorMessage, const std::string &directory="") const
Extraction methods.
Definition: archive_wrapper.cpp:250
ArchiveWrapper(const std::string &archivePath, bool &succes, std::string &errorMessage)
Definition: archive_wrapper.cpp:107
bool extractByName(const std::string &name, std::string &errorMessage, const std::string &outputPath="") const
Definition: archive_wrapper.cpp:311
bool getCount(std::size_t &count, std::string &errorMessage) const
Definition: archive_wrapper.cpp:451
bool getNames(std::vector< std::string > &result, std::string &errorMessage) const
Auxiliary methods.
Definition: archive_wrapper.cpp:421
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > buffer
Buffer storing content of whole archive.
Definition: archive_wrapper.h:64
std::size_t getNumberOfObjects() const
Getters.
Definition: archive_wrapper.cpp:135
bool getPlainTextList(std::string &result, std::string &errorMessage, bool niceNames=false, bool numbers=true) const
Display methods.
Definition: archive_wrapper.cpp:170
std::unique_ptr< llvm::object::Archive > archive
LLVM archive parser.
Definition: archive_wrapper.h:62
bool extractByIndex(const std::size_t index, std::string &errorMessage, const std::string &outputPath="") const
Definition: archive_wrapper.cpp:365
bool isEmptyArchive() const
Definition: archive_wrapper.cpp:155
bool isThinArchive() const
Query methods.
Definition: archive_wrapper.cpp:145
std::size_t objectCount
Number of object files in archive.
Definition: archive_wrapper.h:73
bool getJsonList(std::string &result, std::string &errorMessage, bool niceNames=false, bool numbers=true) const
Definition: archive_wrapper.cpp:202
A mixin to make classes non-copyable.
Definition: non_copyable.h:27
Definition: archive_wrapper.h:19
A mixin to make classes non-copyable.