Blame view

src/PostProcessing/ArchiveWriter.hh 1.67 KB
fbe3c2bb   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
 * ArchiveWriter.hh
 *
 *  Created on: 26 sept. 2013
 *      Author: CS
 */

#ifndef ARCHIVEWRITER_HH_
#define ARCHIVEWRITER_HH_

#include <string>
#include <vector>
#include <log4cxx/logger.h>

struct archive;
struct archive_entry;

namespace postprocessing {

class ArchiveWriter {

public:

	/**
	 * Archive formats available.
	 */
	enum Formats {
		TAR = 0, ZIP = 1
	};

	ArchiveWriter(const std::string& pArchiveFileName, const Formats& pFormat);
	virtual ~ArchiveWriter();

	/**
	 * Adds a file to the current archive.
	 */
	void addFile(const std::string& pFilePath, const std::string& pEntryName =
			"");

	/**
	 * Closes the current archive.
	 */
	void close();

	/**
	 * Creates an archive with the given format and adds all given files.
	 */
	static std::string createArchive(const Formats& pFormat,
			const std::string& pExtension,
			const std::vector<std::string>& pFiles, const std::string& pPrefix, const std::string& pOutDir =
					std::string());

private:
	void checkError(const int pErrCode, const bool pCloseBeforeThrow = false);

	/**
	 * Opens entry and adds meta-data for a given entry file.
	 */
	void addHeader(const std::string& pFilePath, const std::string& pEntryName =
			"");

	/**
	 * Close current entry.
	 */
	void addFinish();

	/**
	 * Flag to indicate the archive is closed or not.
	 */
	bool _open;

	/**
	 * The current archive to write.
	 */
	archive* _archive;

	/**
	 * The current entry.
	 */
	archive_entry* _entry;

	const std::string _archiveFileName;

	/**
	 * The current archive format (zip, tar etc.)
	 */
	const Formats _format;

	/**
	 * A logger.
	 */
	static log4cxx::LoggerPtr _logger;
};

} /* namespace postprocessing */
#endif /* ARCHIVEWRITER_HH_ */