Commit e6200bbcc516aa34d74cd92be56eb88c918629fa

Authored by m-holger
1 parent 81510829

Refactor `QPDFAcroFormDocumentHelper::Members` to use `std::make_shared`, improv…

…e memory management, and streamline class definition.
include/qpdf/QPDFAcroFormDocumentHelper.hh
@@ -241,23 +241,7 @@ class QPDFAcroFormDocumentHelper: public QPDFDocumentHelper @@ -241,23 +241,7 @@ class QPDFAcroFormDocumentHelper: public QPDFDocumentHelper
241 void adjustAppearanceStream( 241 void adjustAppearanceStream(
242 QPDFObjectHandle stream, std::map<std::string, std::map<std::string, std::string>> dr_map); 242 QPDFObjectHandle stream, std::map<std::string, std::map<std::string, std::string>> dr_map);
243 243
244 - class Members  
245 - {  
246 - friend class QPDFAcroFormDocumentHelper;  
247 -  
248 - public:  
249 - ~Members() = default;  
250 -  
251 - private:  
252 - Members() = default;  
253 - Members(Members const&) = delete;  
254 -  
255 - bool cache_valid{false};  
256 - std::map<QPDFObjGen, std::vector<QPDFAnnotationObjectHelper>> field_to_annotations;  
257 - std::map<QPDFObjGen, QPDFFormFieldObjectHelper> annotation_to_field;  
258 - std::map<QPDFObjGen, std::string> field_to_name;  
259 - std::map<std::string, std::set<QPDFObjGen>> name_to_fields;  
260 - }; 244 + class Members;
261 245
262 std::shared_ptr<Members> m; 246 std::shared_ptr<Members> m;
263 }; 247 };
libqpdf/QPDFAcroFormDocumentHelper.cc
@@ -13,9 +13,23 @@ @@ -13,9 +13,23 @@
13 using namespace qpdf; 13 using namespace qpdf;
14 using namespace std::literals; 14 using namespace std::literals;
15 15
  16 +class QPDFAcroFormDocumentHelper::Members
  17 +{
  18 + public:
  19 + Members() = default;
  20 + Members(Members const&) = delete;
  21 + ~Members() = default;
  22 +
  23 + bool cache_valid{false};
  24 + std::map<QPDFObjGen, std::vector<QPDFAnnotationObjectHelper>> field_to_annotations;
  25 + std::map<QPDFObjGen, QPDFFormFieldObjectHelper> annotation_to_field;
  26 + std::map<QPDFObjGen, std::string> field_to_name;
  27 + std::map<std::string, std::set<QPDFObjGen>> name_to_fields;
  28 +};
  29 +
16 QPDFAcroFormDocumentHelper::QPDFAcroFormDocumentHelper(QPDF& qpdf) : 30 QPDFAcroFormDocumentHelper::QPDFAcroFormDocumentHelper(QPDF& qpdf) :
17 QPDFDocumentHelper(qpdf), 31 QPDFDocumentHelper(qpdf),
18 - m(new Members()) 32 + m(std::make_shared<Members>())
19 { 33 {
20 // We have to analyze up front. Otherwise, when we are adding annotations and fields, we are in 34 // We have to analyze up front. Otherwise, when we are adding annotations and fields, we are in
21 // a temporarily unstable configuration where some widget annotations are not reachable. 35 // a temporarily unstable configuration where some widget annotations are not reachable.