diff options
author | Jay Berkenbilt <ejb@ql.org> | 2019-06-22 03:32:47 +0200 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2019-06-22 16:13:27 +0200 |
commit | 79f6b4823b95b65290a045a59fdd4a8d9b302708 (patch) | |
tree | b94d273dd51e64a7144b669cf5ed91d826cc1387 /include | |
parent | 864a546af6e1c17e0de2dc2be6da105f454b6e54 (diff) | |
download | qpdf-79f6b4823b95b65290a045a59fdd4a8d9b302708.tar.zst |
Convert remaining public classes to use Members pattern
Have classes contain only a single private member of type
PointerHolder<Members>. This makes it safe to change the structure of
the Members class without breaking binary compatibility. Many of the
classes already follow this pattern quite successfully. This brings in
the rest of the class that are part of the public API.
Diffstat (limited to 'include')
-rw-r--r-- | include/qpdf/Buffer.hh | 28 | ||||
-rw-r--r-- | include/qpdf/BufferInputSource.hh | 23 | ||||
-rw-r--r-- | include/qpdf/FileInputSource.hh | 21 | ||||
-rw-r--r-- | include/qpdf/InputSource.hh | 17 | ||||
-rw-r--r-- | include/qpdf/Pipeline.hh | 18 | ||||
-rw-r--r-- | include/qpdf/Pl_Buffer.hh | 22 | ||||
-rw-r--r-- | include/qpdf/Pl_Concatenate.hh | 16 | ||||
-rw-r--r-- | include/qpdf/Pl_Count.hh | 23 | ||||
-rw-r--r-- | include/qpdf/Pl_DCT.hh | 36 | ||||
-rw-r--r-- | include/qpdf/Pl_Discard.hh | 16 | ||||
-rw-r--r-- | include/qpdf/Pl_Flate.hh | 25 | ||||
-rw-r--r-- | include/qpdf/Pl_RunLength.hh | 23 | ||||
-rw-r--r-- | include/qpdf/Pl_StdioFile.hh | 17 | ||||
-rw-r--r-- | include/qpdf/QPDFExc.hh | 5 | ||||
-rw-r--r-- | include/qpdf/QPDFObjGen.hh | 3 | ||||
-rw-r--r-- | include/qpdf/QPDFSystemError.hh | 5 | ||||
-rw-r--r-- | include/qpdf/QPDFXRefEntry.hh | 2 |
17 files changed, 255 insertions, 45 deletions
diff --git a/include/qpdf/Buffer.hh b/include/qpdf/Buffer.hh index bb9a3eb9..8145f41a 100644 --- a/include/qpdf/Buffer.hh +++ b/include/qpdf/Buffer.hh @@ -23,7 +23,8 @@ #define BUFFER_HH #include <qpdf/DLL.h> -#include <cstring> // for size_t +#include <qpdf/PointerHolder.hh> +#include <stddef.h> class Buffer { @@ -46,8 +47,6 @@ class Buffer QPDF_DLL Buffer& operator=(Buffer const&); QPDF_DLL - ~Buffer(); - QPDF_DLL size_t getSize() const; QPDF_DLL unsigned char const* getBuffer() const; @@ -55,13 +54,26 @@ class Buffer unsigned char* getBuffer(); private: - void init(size_t size, unsigned char* buf, bool own_memory); + class Members + { + friend class Buffer; + + public: + QPDF_DLL + ~Members(); + + private: + Members(size_t size, unsigned char* buf, bool own_memory); + Members(Members const&); + + bool own_memory; + size_t size; + unsigned char* buf; + }; + void copy(Buffer const&); - void destroy(); - bool own_memory; - size_t size; - unsigned char* buf; + PointerHolder<Members> m; }; #endif // BUFFER_HH diff --git a/include/qpdf/BufferInputSource.hh b/include/qpdf/BufferInputSource.hh index 51bb98f9..90263335 100644 --- a/include/qpdf/BufferInputSource.hh +++ b/include/qpdf/BufferInputSource.hh @@ -56,10 +56,25 @@ class BufferInputSource: public InputSource private: qpdf_offset_t const bufSizeAsOffset() const; - bool own_memory; - std::string description; - Buffer* buf; - qpdf_offset_t cur_offset; + class Members + { + friend class BufferInputSource; + + public: + QPDF_DLL + ~Members(); + + private: + Members(bool own_memory, std::string const& description, Buffer* buf); + Members(Members const&); + + bool own_memory; + std::string description; + Buffer* buf; + qpdf_offset_t cur_offset; + }; + + PointerHolder<Members> m; }; #endif // QPDF_BUFFERINPUTSOURCE_HH diff --git a/include/qpdf/FileInputSource.hh b/include/qpdf/FileInputSource.hh index 0845f241..1bf2a2de 100644 --- a/include/qpdf/FileInputSource.hh +++ b/include/qpdf/FileInputSource.hh @@ -54,11 +54,24 @@ class FileInputSource: public InputSource FileInputSource(FileInputSource const&); FileInputSource& operator=(FileInputSource const&); - void destroy(); + class Members + { + friend class FileInputSource; - bool close_file; - std::string filename; - FILE* file; + public: + QPDF_DLL + ~Members(); + + private: + Members(bool close_file); + Members(Members const&); + + bool close_file; + std::string filename; + FILE* file; + }; + + PointerHolder<Members> m; }; #endif // QPDF_FILEINPUTSOURCE_HH diff --git a/include/qpdf/InputSource.hh b/include/qpdf/InputSource.hh index 3d0d9aaf..db48fcba 100644 --- a/include/qpdf/InputSource.hh +++ b/include/qpdf/InputSource.hh @@ -24,6 +24,7 @@ #include <qpdf/DLL.h> #include <qpdf/Types.h> +#include <qpdf/PointerHolder.hh> #include <stdio.h> #include <string> @@ -86,6 +87,22 @@ class QPDF_DLL_CLASS InputSource protected: qpdf_offset_t last_offset; + + private: + class Members + { + friend class InputSource; + + public: + QPDF_DLL + ~Members(); + + private: + Members(); + Members(Members const&); + }; + + PointerHolder<Members> m; }; #endif // QPDF_INPUTSOURCE_HH diff --git a/include/qpdf/Pipeline.hh b/include/qpdf/Pipeline.hh index a5440a27..36a25df0 100644 --- a/include/qpdf/Pipeline.hh +++ b/include/qpdf/Pipeline.hh @@ -45,6 +45,7 @@ #define PIPELINE_HH #include <qpdf/DLL.h> +#include <qpdf/PointerHolder.hh> #include <string> class QPDF_DLL_CLASS Pipeline @@ -79,7 +80,22 @@ class QPDF_DLL_CLASS Pipeline Pipeline(Pipeline const&); Pipeline& operator=(Pipeline const&); - Pipeline* next; + class Members + { + friend class Pipeline; + + public: + QPDF_DLL + ~Members(); + + private: + Members(Pipeline* next); + Members(Members const&); + + Pipeline* next; + }; + + PointerHolder<Members> m; }; #endif // PIPELINE_HH diff --git a/include/qpdf/Pl_Buffer.hh b/include/qpdf/Pl_Buffer.hh index 5eb143b2..0afa6c69 100644 --- a/include/qpdf/Pl_Buffer.hh +++ b/include/qpdf/Pl_Buffer.hh @@ -36,7 +36,6 @@ #include <qpdf/Pipeline.hh> #include <qpdf/PointerHolder.hh> #include <qpdf/Buffer.hh> -#include <list> class Pl_Buffer: public Pipeline { @@ -57,9 +56,24 @@ class Pl_Buffer: public Pipeline Buffer* getBuffer(); private: - bool ready; - std::list<PointerHolder<Buffer> > data; - size_t total_size; + class Members + { + friend class Pl_Buffer; + + public: + QPDF_DLL + ~Members(); + + private: + Members(); + Members(Members const&); + + bool ready; + PointerHolder<Buffer> data; + size_t total_size; + }; + + PointerHolder<Members> m; }; #endif // PL_BUFFER_HH diff --git a/include/qpdf/Pl_Concatenate.hh b/include/qpdf/Pl_Concatenate.hh index 26e5849e..135a9899 100644 --- a/include/qpdf/Pl_Concatenate.hh +++ b/include/qpdf/Pl_Concatenate.hh @@ -48,6 +48,22 @@ class Pl_Concatenate: public Pipeline // the pipeline. QPDF_DLL void manualFinish(); + + private: + class Members + { + friend class Pl_Concatenate; + + public: + QPDF_DLL + ~Members(); + + private: + Members(); + Members(Members const&); + }; + + PointerHolder<Members> m; }; #endif // PL_CONCATENATE_HH diff --git a/include/qpdf/Pl_Count.hh b/include/qpdf/Pl_Count.hh index 0b021d9a..aa281c5c 100644 --- a/include/qpdf/Pl_Count.hh +++ b/include/qpdf/Pl_Count.hh @@ -48,10 +48,25 @@ class Pl_Count: public Pipeline unsigned char getLastChar() const; private: - // Must be qpdf_offset_t, not size_t, to handle writing more than - // size_t can handle. - qpdf_offset_t count; - unsigned char last_char; + class Members + { + friend class Pl_Count; + + public: + QPDF_DLL + ~Members(); + + private: + Members(); + Members(Members const&); + + // Must be qpdf_offset_t, not size_t, to handle writing more than + // size_t can handle. + qpdf_offset_t count; + unsigned char last_char; + }; + + PointerHolder<Members> m; }; #endif // PL_COUNT_HH diff --git a/include/qpdf/Pl_DCT.hh b/include/qpdf/Pl_DCT.hh index 1827fa80..57a52cb4 100644 --- a/include/qpdf/Pl_DCT.hh +++ b/include/qpdf/Pl_DCT.hh @@ -68,17 +68,37 @@ class Pl_DCT: public Pipeline enum action_e { a_compress, a_decompress }; - action_e action; - Pl_Buffer buf; + class Members + { + friend class Pl_DCT; + + public: + QPDF_DLL + ~Members(); - // Used for compression - JDIMENSION image_width; - JDIMENSION image_height; - int components; - J_COLOR_SPACE color_space; + private: + Members(action_e action, + char const* buf_description, + JDIMENSION image_width = 0, + JDIMENSION image_height = 0, + int components = 1, + J_COLOR_SPACE color_space = JCS_GRAYSCALE, + CompressConfig* config_callback = 0); + Members(Members const&); - CompressConfig* config_callback; + action_e action; + Pl_Buffer buf; + + // Used for compression + JDIMENSION image_width; + JDIMENSION image_height; + int components; + J_COLOR_SPACE color_space; + + CompressConfig* config_callback; + }; + PointerHolder<Members> m; }; #endif // PL_DCT_HH diff --git a/include/qpdf/Pl_Discard.hh b/include/qpdf/Pl_Discard.hh index 129431b2..3130ef45 100644 --- a/include/qpdf/Pl_Discard.hh +++ b/include/qpdf/Pl_Discard.hh @@ -41,6 +41,22 @@ class Pl_Discard: public Pipeline virtual void write(unsigned char*, size_t); QPDF_DLL virtual void finish(); + + private: + class Members + { + friend class Pl_Discard; + + public: + QPDF_DLL + ~Members(); + + private: + Members(); + Members(Members const&); + }; + + PointerHolder<Members> m; }; #endif // PL_DISCARD_HH diff --git a/include/qpdf/Pl_Flate.hh b/include/qpdf/Pl_Flate.hh index 923b33a8..2884ecc5 100644 --- a/include/qpdf/Pl_Flate.hh +++ b/include/qpdf/Pl_Flate.hh @@ -46,11 +46,26 @@ class Pl_Flate: public Pipeline void handleData(unsigned char* data, size_t len, int flush); void checkError(char const* prefix, int error_code); - unsigned char* outbuf; - size_t out_bufsize; - action_e action; - bool initialized; - void* zdata; + class Members + { + friend class Pl_Flate; + + public: + QPDF_DLL + ~Members(); + + private: + Members(size_t out_bufsize, action_e action); + Members(Members const&); + + unsigned char* outbuf; + size_t out_bufsize; + action_e action; + bool initialized; + void* zdata; + }; + + PointerHolder<Members> m; }; #endif // PL_FLATE_HH diff --git a/include/qpdf/Pl_RunLength.hh b/include/qpdf/Pl_RunLength.hh index b8e696b6..a579ceea 100644 --- a/include/qpdf/Pl_RunLength.hh +++ b/include/qpdf/Pl_RunLength.hh @@ -47,10 +47,25 @@ class Pl_RunLength: public Pipeline enum state_e { st_top, st_copying, st_run }; - action_e action; - state_e state; - unsigned char buf[128]; - unsigned int length; + class Members + { + friend class Pl_RunLength; + + public: + QPDF_DLL + ~Members(); + + private: + Members(action_e); + Members(Members const&); + + action_e action; + state_e state; + unsigned char buf[128]; + unsigned int length; + }; + + PointerHolder<Members> m; }; #endif // PL_RUNLENGTH_HH diff --git a/include/qpdf/Pl_StdioFile.hh b/include/qpdf/Pl_StdioFile.hh index fd228333..83d7faf2 100644 --- a/include/qpdf/Pl_StdioFile.hh +++ b/include/qpdf/Pl_StdioFile.hh @@ -48,7 +48,22 @@ class Pl_StdioFile: public Pipeline virtual void finish(); private: - FILE* file; + class Members + { + friend class Pl_StdioFile; + + public: + QPDF_DLL + ~Members(); + + private: + Members(FILE*); + Members(Members const&); + + FILE* file; + }; + + PointerHolder<Members> m; }; #endif // PL_STDIOFILE_HH diff --git a/include/qpdf/QPDFExc.hh b/include/qpdf/QPDFExc.hh index 188ede29..4cabd7a9 100644 --- a/include/qpdf/QPDFExc.hh +++ b/include/qpdf/QPDFExc.hh @@ -24,8 +24,8 @@ #include <qpdf/DLL.h> #include <qpdf/Types.h> - #include <qpdf/Constants.h> + #include <string> #include <stdexcept> @@ -70,6 +70,9 @@ class QPDF_DLL_CLASS QPDFExc: public std::runtime_error qpdf_offset_t offset, std::string const& message); + // This class does not use the Members pattern to avoid needless + // memory allocations during exception handling. + qpdf_error_code_e error_code; std::string filename; std::string object; diff --git a/include/qpdf/QPDFObjGen.hh b/include/qpdf/QPDFObjGen.hh index 81c45d9f..9b61c78d 100644 --- a/include/qpdf/QPDFObjGen.hh +++ b/include/qpdf/QPDFObjGen.hh @@ -44,6 +44,9 @@ class QPDFObjGen int getGen() const; private: + // This class does not use the Members pattern to avoid a memory + // allocation for every one of these. A lot of these get created + // and destroyed. int obj; int gen; }; diff --git a/include/qpdf/QPDFSystemError.hh b/include/qpdf/QPDFSystemError.hh index e8ea09eb..4ecd01d6 100644 --- a/include/qpdf/QPDFSystemError.hh +++ b/include/qpdf/QPDFSystemError.hh @@ -24,8 +24,8 @@ #include <qpdf/DLL.h> #include <qpdf/Types.h> - #include <qpdf/Constants.h> + #include <string> #include <stdexcept> @@ -51,6 +51,9 @@ class QPDF_DLL_CLASS QPDFSystemError: public std::runtime_error static std::string createWhat(std::string const& description, int system_errno); + // This class does not use the Members pattern to avoid needless + // memory allocations during exception handling. + std::string description; int system_errno; }; diff --git a/include/qpdf/QPDFXRefEntry.hh b/include/qpdf/QPDFXRefEntry.hh index ee3cf746..59b6a23f 100644 --- a/include/qpdf/QPDFXRefEntry.hh +++ b/include/qpdf/QPDFXRefEntry.hh @@ -49,6 +49,8 @@ class QPDFXRefEntry int getObjStreamIndex() const; // only for type 2 private: + // This class does not use the Members pattern to avoid a memory + // allocation for every one of these. A lot of these get created. int type; qpdf_offset_t field1; int field2; |