From 4643106be4fab4f9a88e17ff88ea63a789d7a47d Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Fri, 15 Mar 2019 11:23:27 +0100 Subject: [PATCH] Zipper made universally usable and documented. --- src/libslic3r/Zipper.hpp | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/libslic3r/Zipper.hpp b/src/libslic3r/Zipper.hpp index d83e33e6b..685303955 100644 --- a/src/libslic3r/Zipper.hpp +++ b/src/libslic3r/Zipper.hpp @@ -6,8 +6,10 @@ namespace Slic3r { +// Class for creating zip archives. class Zipper { public: + // Three compression levels supported enum e_compression { NO_COMPRESSION, FAST_COMPRESSION, @@ -29,23 +31,47 @@ public: e_compression level = NO_COMPRESSION); ~Zipper(); + // No copies allwed, this is a file resource... Zipper(const Zipper&) = delete; Zipper& operator=(const Zipper&) = delete; + // Moving is fine. Zipper(Zipper&&) = default; Zipper& operator=(Zipper&&) = default; + /// Adding an entry means a file inside the new archive. Name param is the + /// name of the new file. To create directories, append a forward slash. void add_entry(const std::string& name); - void finish_entry(); - inline Zipper& operator<<(const std::string& content) { - std::copy(content.begin(), content.end(), std::back_inserter(m_data)); + // Writing data to the archive works like with standard streams. The target + // within the zip file is the entry created with the add_entry method. + + // Template taking only arithmetic values, that std::to_string can handle. + template inline + typename std::enable_if::value, Zipper&>::type + operator<<(T &&val) { + return this->operator<<(std::to_string(std::forward(val))); + } + + // Template applied only for types that std::string can handle for append + // and copy. This includes c style strings... + template inline + typename std::enable_if::value, Zipper&>::type + operator<<(T &&val) { + if(m_data.empty()) m_data = std::forward(val); + else m_data.append(val); return *this; } + /// Finishing an entry means that subsequent writes will no longer be + /// appended to the previous entry. + void finish_entry(); + + /// Gets the name of the archive without the path or extension. std::string get_name() const; }; + } #endif // ZIPPER_HPP