Commit 75fe4f60c3f59af30cb1d8f2b5902d866c05550a

Authored by Jay Berkenbilt
1 parent 38edca82

Use anonymous namespaces for file-private classes

ChangeLog
@@ -6,7 +6,8 @@ @@ -6,7 +6,8 @@
6 qpdf 11. 6 qpdf 11.
7 7
8 * Perform code cleanup including some source-compatible but not 8 * Perform code cleanup including some source-compatible but not
9 - binary compatible changes to function signatures. 9 + binary compatible changes to function signatures, use of anonymous
  10 + namespaces, and use of "= default" and "= delete" in declarations.
10 11
11 2022-04-09 Jay Berkenbilt <ejb@ql.org> 12 2022-04-09 Jay Berkenbilt <ejb@ql.org>
12 13
@@ -479,8 +479,6 @@ This is a list of changes to make next time there is an ABI change. @@ -479,8 +479,6 @@ This is a list of changes to make next time there is an ABI change.
479 Comments appear in the code prefixed by "ABI". Always Search for ABI 479 Comments appear in the code prefixed by "ABI". Always Search for ABI
480 in source and header files to find items not listed here. 480 in source and header files to find items not listed here.
481 481
482 -* See where anonymous namespaces can be used to keep things private to  
483 - a source file. Search for `(class|struct)` in **/*.cc.  
484 * Having QPDFObjectHandle setters return Class& to allow for 482 * Having QPDFObjectHandle setters return Class& to allow for
485 use of fluent interfaces. This includes array and dictionary 483 use of fluent interfaces. This includes array and dictionary
486 mutators. 484 mutators.
libqpdf/Pl_DCT.cc
@@ -14,12 +14,15 @@ @@ -14,12 +14,15 @@
14 # error "qpdf does not support libjpeg built with BITS_IN_JSAMPLE != 8" 14 # error "qpdf does not support libjpeg built with BITS_IN_JSAMPLE != 8"
15 #endif 15 #endif
16 16
17 -struct qpdf_jpeg_error_mgr 17 +namespace
18 { 18 {
19 - struct jpeg_error_mgr pub;  
20 - jmp_buf jmpbuf;  
21 - std::string msg;  
22 -}; 19 + struct qpdf_jpeg_error_mgr
  20 + {
  21 + struct jpeg_error_mgr pub;
  22 + jmp_buf jmpbuf;
  23 + std::string msg;
  24 + };
  25 +} // namespace
23 26
24 static void 27 static void
25 error_handler(j_common_ptr cinfo) 28 error_handler(j_common_ptr cinfo)
@@ -147,13 +150,16 @@ Pl_DCT::finish() @@ -147,13 +150,16 @@ Pl_DCT::finish()
147 } 150 }
148 } 151 }
149 152
150 -struct dct_pipeline_dest 153 +namespace
151 { 154 {
152 - struct jpeg_destination_mgr pub; /* public fields */  
153 - unsigned char* buffer;  
154 - size_t size;  
155 - Pipeline* next;  
156 -}; 155 + struct dct_pipeline_dest
  156 + {
  157 + struct jpeg_destination_mgr pub; /* public fields */
  158 + unsigned char* buffer;
  159 + size_t size;
  160 + Pipeline* next;
  161 + };
  162 +} // namespace
157 163
158 static void 164 static void
159 init_pipeline_destination(j_compress_ptr) 165 init_pipeline_destination(j_compress_ptr)
libqpdf/QPDF.cc
@@ -50,60 +50,64 @@ static char const* EMPTY_PDF = ( @@ -50,60 +50,64 @@ static char const* EMPTY_PDF = (
50 "110\n" 50 "110\n"
51 "%%EOF\n"); 51 "%%EOF\n");
52 52
53 -class InvalidInputSource: public InputSource 53 +namespace
54 { 54 {
55 - public:  
56 - virtual ~InvalidInputSource() = default;  
57 - virtual qpdf_offset_t  
58 - findAndSkipNextEOL() override 55 + class InvalidInputSource: public InputSource
59 { 56 {
60 - throwException();  
61 - return 0;  
62 - }  
63 - virtual std::string const&  
64 - getName() const override  
65 - {  
66 - static std::string name("closed input source");  
67 - return name;  
68 - }  
69 - virtual qpdf_offset_t  
70 - tell() override  
71 - {  
72 - throwException();  
73 - return 0;  
74 - }  
75 - virtual void  
76 - seek(qpdf_offset_t offset, int whence) override  
77 - {  
78 - throwException();  
79 - }  
80 - virtual void  
81 - rewind() override  
82 - {  
83 - throwException();  
84 - }  
85 - virtual size_t  
86 - read(char* buffer, size_t length) override  
87 - {  
88 - throwException();  
89 - return 0;  
90 - }  
91 - virtual void  
92 - unreadCh(char ch) override  
93 - {  
94 - throwException();  
95 - }  
96 -  
97 - private:  
98 - void  
99 - throwException()  
100 - {  
101 - throw std::logic_error(  
102 - "QPDF operation attempted on a QPDF object with no input source."  
103 - " QPDF operations are invalid before processFile (or another"  
104 - " process method) or after closeInputSource");  
105 - }  
106 -}; 57 + public:
  58 + virtual ~InvalidInputSource() = default;
  59 + virtual qpdf_offset_t
  60 + findAndSkipNextEOL() override
  61 + {
  62 + throwException();
  63 + return 0;
  64 + }
  65 + virtual std::string const&
  66 + getName() const override
  67 + {
  68 + static std::string name("closed input source");
  69 + return name;
  70 + }
  71 + virtual qpdf_offset_t
  72 + tell() override
  73 + {
  74 + throwException();
  75 + return 0;
  76 + }
  77 + virtual void
  78 + seek(qpdf_offset_t offset, int whence) override
  79 + {
  80 + throwException();
  81 + }
  82 + virtual void
  83 + rewind() override
  84 + {
  85 + throwException();
  86 + }
  87 + virtual size_t
  88 + read(char* buffer, size_t length) override
  89 + {
  90 + throwException();
  91 + return 0;
  92 + }
  93 + virtual void
  94 + unreadCh(char ch) override
  95 + {
  96 + throwException();
  97 + }
  98 +
  99 + private:
  100 + void
  101 + throwException()
  102 + {
  103 + throw std::logic_error(
  104 + "QPDF operation attempted on a QPDF object with no input "
  105 + "source."
  106 + " QPDF operations are invalid before processFile (or another"
  107 + " process method) or after closeInputSource");
  108 + }
  109 + };
  110 +} // namespace
107 111
108 QPDF::ForeignStreamData::ForeignStreamData( 112 QPDF::ForeignStreamData::ForeignStreamData(
109 std::shared_ptr<EncryptionParameters> encp, 113 std::shared_ptr<EncryptionParameters> encp,
libqpdf/QPDFAcroFormDocumentHelper.cc
@@ -543,20 +543,25 @@ QPDFAcroFormDocumentHelper::adjustInheritedFields( @@ -543,20 +543,25 @@ QPDFAcroFormDocumentHelper::adjustInheritedFields(
543 } 543 }
544 } 544 }
545 545
546 -class ResourceReplacer: public QPDFObjectHandle::TokenFilter 546 +namespace
547 { 547 {
548 - public:  
549 - ResourceReplacer(  
550 - std::map<std::string, std::map<std::string, std::string>> const& dr_map,  
551 - std::map<std::string, std::map<std::string, std::set<size_t>>> const&  
552 - rnames);  
553 - virtual ~ResourceReplacer() = default;  
554 - virtual void handleToken(QPDFTokenizer::Token const&) override;  
555 -  
556 - private:  
557 - size_t offset;  
558 - std::map<std::string, std::map<size_t, std::string>> to_replace;  
559 -}; 548 + class ResourceReplacer: public QPDFObjectHandle::TokenFilter
  549 + {
  550 + public:
  551 + ResourceReplacer(
  552 + std::map<std::string, std::map<std::string, std::string>> const&
  553 + dr_map,
  554 + std::map<
  555 + std::string,
  556 + std::map<std::string, std::set<size_t>>> const& rnames);
  557 + virtual ~ResourceReplacer() = default;
  558 + virtual void handleToken(QPDFTokenizer::Token const&) override;
  559 +
  560 + private:
  561 + size_t offset;
  562 + std::map<std::string, std::map<size_t, std::string>> to_replace;
  563 + };
  564 +} // namespace
560 565
561 ResourceReplacer::ResourceReplacer( 566 ResourceReplacer::ResourceReplacer(
562 std::map<std::string, std::map<std::string, std::string>> const& dr_map, 567 std::map<std::string, std::map<std::string, std::string>> const& dr_map,
libqpdf/QPDFFormFieldObjectHelper.cc
@@ -508,29 +508,32 @@ QPDFFormFieldObjectHelper::generateAppearance(QPDFAnnotationObjectHelper&amp; aoh) @@ -508,29 +508,32 @@ QPDFFormFieldObjectHelper::generateAppearance(QPDFAnnotationObjectHelper&amp; aoh)
508 } 508 }
509 } 509 }
510 510
511 -class ValueSetter: public QPDFObjectHandle::TokenFilter  
512 -{  
513 - public:  
514 - ValueSetter(  
515 - std::string const& DA,  
516 - std::string const& V,  
517 - std::vector<std::string> const& opt,  
518 - double tf,  
519 - QPDFObjectHandle::Rectangle const& bbox);  
520 - virtual ~ValueSetter() = default;  
521 - virtual void handleToken(QPDFTokenizer::Token const&);  
522 - virtual void handleEOF();  
523 - void writeAppearance();  
524 -  
525 - private:  
526 - std::string DA;  
527 - std::string V;  
528 - std::vector<std::string> opt;  
529 - double tf;  
530 - QPDFObjectHandle::Rectangle bbox;  
531 - enum { st_top, st_bmc, st_emc, st_end } state;  
532 - bool replaced;  
533 -}; 511 +namespace
  512 +{
  513 + class ValueSetter: public QPDFObjectHandle::TokenFilter
  514 + {
  515 + public:
  516 + ValueSetter(
  517 + std::string const& DA,
  518 + std::string const& V,
  519 + std::vector<std::string> const& opt,
  520 + double tf,
  521 + QPDFObjectHandle::Rectangle const& bbox);
  522 + virtual ~ValueSetter() = default;
  523 + virtual void handleToken(QPDFTokenizer::Token const&);
  524 + virtual void handleEOF();
  525 + void writeAppearance();
  526 +
  527 + private:
  528 + std::string DA;
  529 + std::string V;
  530 + std::vector<std::string> opt;
  531 + double tf;
  532 + QPDFObjectHandle::Rectangle bbox;
  533 + enum { st_top, st_bmc, st_emc, st_end } state;
  534 + bool replaced;
  535 + };
  536 +} // namespace
534 537
535 ValueSetter::ValueSetter( 538 ValueSetter::ValueSetter(
536 std::string const& DA, 539 std::string const& DA,
@@ -701,27 +704,30 @@ ValueSetter::writeAppearance() @@ -701,27 +704,30 @@ ValueSetter::writeAppearance()
701 write("ET\nQ\nEMC"); 704 write("ET\nQ\nEMC");
702 } 705 }
703 706
704 -class TfFinder: public QPDFObjectHandle::TokenFilter 707 +namespace
705 { 708 {
706 - public:  
707 - TfFinder();  
708 - virtual ~TfFinder() 709 + class TfFinder: public QPDFObjectHandle::TokenFilter
709 { 710 {
710 - }  
711 - virtual void handleToken(QPDFTokenizer::Token const&);  
712 - double getTf();  
713 - std::string getFontName();  
714 - std::string getDA();  
715 -  
716 - private:  
717 - double tf;  
718 - int tf_idx;  
719 - std::string font_name;  
720 - double last_num;  
721 - int last_num_idx;  
722 - std::string last_name;  
723 - std::vector<std::string> DA;  
724 -}; 711 + public:
  712 + TfFinder();
  713 + virtual ~TfFinder()
  714 + {
  715 + }
  716 + virtual void handleToken(QPDFTokenizer::Token const&);
  717 + double getTf();
  718 + std::string getFontName();
  719 + std::string getDA();
  720 +
  721 + private:
  722 + double tf;
  723 + int tf_idx;
  724 + std::string font_name;
  725 + double last_num;
  726 + int last_num_idx;
  727 + std::string last_name;
  728 + std::vector<std::string> DA;
  729 + };
  730 +} // namespace
725 731
726 TfFinder::TfFinder() : 732 TfFinder::TfFinder() :
727 tf(11.0), 733 tf(11.0),
libqpdf/QPDFNameTreeObjectHelper.cc
@@ -2,32 +2,35 @@ @@ -2,32 +2,35 @@
2 2
3 #include <qpdf/NNTree.hh> 3 #include <qpdf/NNTree.hh>
4 4
5 -class NameTreeDetails: public NNTreeDetails 5 +namespace
6 { 6 {
7 - public:  
8 - virtual std::string const&  
9 - itemsKey() const override 7 + class NameTreeDetails: public NNTreeDetails
10 { 8 {
11 - static std::string k("/Names");  
12 - return k;  
13 - }  
14 - virtual bool  
15 - keyValid(QPDFObjectHandle oh) const override  
16 - {  
17 - return oh.isString();  
18 - }  
19 - virtual int  
20 - compareKeys(QPDFObjectHandle a, QPDFObjectHandle b) const override  
21 - {  
22 - if (!(keyValid(a) && keyValid(b))) {  
23 - // We don't call this without calling keyValid first  
24 - throw std::logic_error("comparing invalid keys"); 9 + public:
  10 + virtual std::string const&
  11 + itemsKey() const override
  12 + {
  13 + static std::string k("/Names");
  14 + return k;
25 } 15 }
26 - auto as = a.getUTF8Value();  
27 - auto bs = b.getUTF8Value();  
28 - return ((as < bs) ? -1 : (as > bs) ? 1 : 0);  
29 - }  
30 -}; 16 + virtual bool
  17 + keyValid(QPDFObjectHandle oh) const override
  18 + {
  19 + return oh.isString();
  20 + }
  21 + virtual int
  22 + compareKeys(QPDFObjectHandle a, QPDFObjectHandle b) const override
  23 + {
  24 + if (!(keyValid(a) && keyValid(b))) {
  25 + // We don't call this without calling keyValid first
  26 + throw std::logic_error("comparing invalid keys");
  27 + }
  28 + auto as = a.getUTF8Value();
  29 + auto bs = b.getUTF8Value();
  30 + return ((as < bs) ? -1 : (as > bs) ? 1 : 0);
  31 + }
  32 + };
  33 +} // namespace
31 34
32 static NameTreeDetails name_tree_details; 35 static NameTreeDetails name_tree_details;
33 36
libqpdf/QPDFNumberTreeObjectHelper.cc
@@ -3,32 +3,35 @@ @@ -3,32 +3,35 @@
3 #include <qpdf/NNTree.hh> 3 #include <qpdf/NNTree.hh>
4 #include <qpdf/QIntC.hh> 4 #include <qpdf/QIntC.hh>
5 5
6 -class NumberTreeDetails: public NNTreeDetails 6 +namespace
7 { 7 {
8 - public:  
9 - virtual std::string const&  
10 - itemsKey() const override 8 + class NumberTreeDetails: public NNTreeDetails
11 { 9 {
12 - static std::string k("/Nums");  
13 - return k;  
14 - }  
15 - virtual bool  
16 - keyValid(QPDFObjectHandle oh) const override  
17 - {  
18 - return oh.isInteger();  
19 - }  
20 - virtual int  
21 - compareKeys(QPDFObjectHandle a, QPDFObjectHandle b) const override  
22 - {  
23 - if (!(keyValid(a) && keyValid(b))) {  
24 - // We don't call this without calling keyValid first  
25 - throw std::logic_error("comparing invalid keys"); 10 + public:
  11 + virtual std::string const&
  12 + itemsKey() const override
  13 + {
  14 + static std::string k("/Nums");
  15 + return k;
26 } 16 }
27 - auto as = a.getIntValue();  
28 - auto bs = b.getIntValue();  
29 - return ((as < bs) ? -1 : (as > bs) ? 1 : 0);  
30 - }  
31 -}; 17 + virtual bool
  18 + keyValid(QPDFObjectHandle oh) const override
  19 + {
  20 + return oh.isInteger();
  21 + }
  22 + virtual int
  23 + compareKeys(QPDFObjectHandle a, QPDFObjectHandle b) const override
  24 + {
  25 + if (!(keyValid(a) && keyValid(b))) {
  26 + // We don't call this without calling keyValid first
  27 + throw std::logic_error("comparing invalid keys");
  28 + }
  29 + auto as = a.getIntValue();
  30 + auto bs = b.getIntValue();
  31 + return ((as < bs) ? -1 : (as > bs) ? 1 : 0);
  32 + }
  33 + };
  34 +} // namespace
32 35
33 static NumberTreeDetails number_tree_details; 36 static NumberTreeDetails number_tree_details;
34 37
libqpdf/QPDFObjectHandle.cc
@@ -32,9 +32,12 @@ @@ -32,9 +32,12 @@
32 #include <stdexcept> 32 #include <stdexcept>
33 #include <stdlib.h> 33 #include <stdlib.h>
34 34
35 -class TerminateParsing 35 +namespace
36 { 36 {
37 -}; 37 + class TerminateParsing
  38 + {
  39 + };
  40 +} // namespace
38 41
39 QPDFObjectHandle::StreamDataProvider::StreamDataProvider(bool supports_retry) : 42 QPDFObjectHandle::StreamDataProvider::StreamDataProvider(bool supports_retry) :
40 supports_retry(supports_retry) 43 supports_retry(supports_retry)
@@ -74,23 +77,26 @@ QPDFObjectHandle::StreamDataProvider::supportsRetry() @@ -74,23 +77,26 @@ QPDFObjectHandle::StreamDataProvider::supportsRetry()
74 return this->supports_retry; 77 return this->supports_retry;
75 } 78 }
76 79
77 -class CoalesceProvider: public QPDFObjectHandle::StreamDataProvider 80 +namespace
78 { 81 {
79 - public:  
80 - CoalesceProvider(  
81 - QPDFObjectHandle containing_page, QPDFObjectHandle old_contents) :  
82 - containing_page(containing_page),  
83 - old_contents(old_contents) 82 + class CoalesceProvider: public QPDFObjectHandle::StreamDataProvider
84 { 83 {
85 - }  
86 - virtual ~CoalesceProvider() = default;  
87 - virtual void  
88 - provideStreamData(int objid, int generation, Pipeline* pipeline); 84 + public:
  85 + CoalesceProvider(
  86 + QPDFObjectHandle containing_page, QPDFObjectHandle old_contents) :
  87 + containing_page(containing_page),
  88 + old_contents(old_contents)
  89 + {
  90 + }
  91 + virtual ~CoalesceProvider() = default;
  92 + virtual void
  93 + provideStreamData(int objid, int generation, Pipeline* pipeline);
89 94
90 - private:  
91 - QPDFObjectHandle containing_page;  
92 - QPDFObjectHandle old_contents;  
93 -}; 95 + private:
  96 + QPDFObjectHandle containing_page;
  97 + QPDFObjectHandle old_contents;
  98 + };
  99 +} // namespace
94 100
95 void 101 void
96 CoalesceProvider::provideStreamData(int, int, Pipeline* p) 102 CoalesceProvider::provideStreamData(int, int, Pipeline* p)
@@ -167,18 +173,21 @@ QPDFObjectHandle::ParserCallbacks::terminateParsing() @@ -167,18 +173,21 @@ QPDFObjectHandle::ParserCallbacks::terminateParsing()
167 throw TerminateParsing(); 173 throw TerminateParsing();
168 } 174 }
169 175
170 -class LastChar: public Pipeline 176 +namespace
171 { 177 {
172 - public:  
173 - LastChar(Pipeline* next);  
174 - virtual ~LastChar() = default;  
175 - virtual void write(unsigned char* data, size_t len);  
176 - virtual void finish();  
177 - unsigned char getLastChar();  
178 -  
179 - private:  
180 - unsigned char last_char;  
181 -}; 178 + class LastChar: public Pipeline
  179 + {
  180 + public:
  181 + LastChar(Pipeline* next);
  182 + virtual ~LastChar() = default;
  183 + virtual void write(unsigned char* data, size_t len);
  184 + virtual void finish();
  185 + unsigned char getLastChar();
  186 +
  187 + private:
  188 + unsigned char last_char;
  189 + };
  190 +} // namespace
182 191
183 LastChar::LastChar(Pipeline* next) : 192 LastChar::LastChar(Pipeline* next) :
184 Pipeline("lastchar", next), 193 Pipeline("lastchar", next),
@@ -293,21 +302,24 @@ QPDFObjectHandle::getTypeName() @@ -293,21 +302,24 @@ QPDFObjectHandle::getTypeName()
293 } 302 }
294 } 303 }
295 304
296 -template <class T>  
297 -class QPDFObjectTypeAccessor 305 +namespace
298 { 306 {
299 - public:  
300 - static bool  
301 - check(QPDFObject* o)  
302 - {  
303 - return (o && dynamic_cast<T*>(o));  
304 - }  
305 - static bool  
306 - check(QPDFObject const* o) 307 + template <class T>
  308 + class QPDFObjectTypeAccessor
307 { 309 {
308 - return (o && dynamic_cast<T const*>(o));  
309 - }  
310 -}; 310 + public:
  311 + static bool
  312 + check(QPDFObject* o)
  313 + {
  314 + return (o && dynamic_cast<T*>(o));
  315 + }
  316 + static bool
  317 + check(QPDFObject const* o)
  318 + {
  319 + return (o && dynamic_cast<T const*>(o));
  320 + }
  321 + };
  322 +} // namespace
311 323
312 bool 324 bool
313 QPDFObjectHandle::isBool() 325 QPDFObjectHandle::isBool()
@@ -1435,40 +1447,46 @@ QPDFObjectHandle::replaceStreamData( @@ -1435,40 +1447,46 @@ QPDFObjectHandle::replaceStreamData(
1435 provider, filter, decode_parms); 1447 provider, filter, decode_parms);
1436 } 1448 }
1437 1449
1438 -class FunctionProvider: public QPDFObjectHandle::StreamDataProvider 1450 +namespace
1439 { 1451 {
1440 - public:  
1441 - FunctionProvider(std::function<void(Pipeline*)> provider) :  
1442 - StreamDataProvider(false),  
1443 - p1(provider),  
1444 - p2(nullptr)  
1445 - {  
1446 - }  
1447 - FunctionProvider(std::function<bool(Pipeline*, bool, bool)> provider) :  
1448 - StreamDataProvider(true),  
1449 - p1(nullptr),  
1450 - p2(provider) 1452 + class FunctionProvider: public QPDFObjectHandle::StreamDataProvider
1451 { 1453 {
1452 - } 1454 + public:
  1455 + FunctionProvider(std::function<void(Pipeline*)> provider) :
  1456 + StreamDataProvider(false),
  1457 + p1(provider),
  1458 + p2(nullptr)
  1459 + {
  1460 + }
  1461 + FunctionProvider(std::function<bool(Pipeline*, bool, bool)> provider) :
  1462 + StreamDataProvider(true),
  1463 + p1(nullptr),
  1464 + p2(provider)
  1465 + {
  1466 + }
1453 1467
1454 - virtual void  
1455 - provideStreamData(int, int, Pipeline* pipeline) override  
1456 - {  
1457 - p1(pipeline);  
1458 - } 1468 + virtual void
  1469 + provideStreamData(int, int, Pipeline* pipeline) override
  1470 + {
  1471 + p1(pipeline);
  1472 + }
1459 1473
1460 - virtual bool  
1461 - provideStreamData(  
1462 - int, int, Pipeline* pipeline, bool suppress_warnings, bool will_retry)  
1463 - override  
1464 - {  
1465 - return p2(pipeline, suppress_warnings, will_retry);  
1466 - } 1474 + virtual bool
  1475 + provideStreamData(
  1476 + int,
  1477 + int,
  1478 + Pipeline* pipeline,
  1479 + bool suppress_warnings,
  1480 + bool will_retry) override
  1481 + {
  1482 + return p2(pipeline, suppress_warnings, will_retry);
  1483 + }
1467 1484
1468 - private:  
1469 - std::function<void(Pipeline*)> p1;  
1470 - std::function<bool(Pipeline*, bool, bool)> p2;  
1471 -}; 1485 + private:
  1486 + std::function<void(Pipeline*)> p1;
  1487 + std::function<bool(Pipeline*, bool, bool)> p2;
  1488 + };
  1489 +} // namespace
1472 1490
1473 void 1491 void
1474 QPDFObjectHandle::replaceStreamData( 1492 QPDFObjectHandle::replaceStreamData(
libqpdf/QPDFPageObjectHelper.cc
@@ -11,20 +11,23 @@ @@ -11,20 +11,23 @@
11 #include <qpdf/QUtil.hh> 11 #include <qpdf/QUtil.hh>
12 #include <qpdf/ResourceFinder.hh> 12 #include <qpdf/ResourceFinder.hh>
13 13
14 -class ContentProvider: public QPDFObjectHandle::StreamDataProvider 14 +namespace
15 { 15 {
16 - public:  
17 - ContentProvider(QPDFObjectHandle from_page) :  
18 - from_page(from_page) 16 + class ContentProvider: public QPDFObjectHandle::StreamDataProvider
19 { 17 {
20 - }  
21 - virtual ~ContentProvider() = default;  
22 - virtual void  
23 - provideStreamData(int objid, int generation, Pipeline* pipeline); 18 + public:
  19 + ContentProvider(QPDFObjectHandle from_page) :
  20 + from_page(from_page)
  21 + {
  22 + }
  23 + virtual ~ContentProvider() = default;
  24 + virtual void
  25 + provideStreamData(int objid, int generation, Pipeline* pipeline);
24 26
25 - private:  
26 - QPDFObjectHandle from_page;  
27 -}; 27 + private:
  28 + QPDFObjectHandle from_page;
  29 + };
  30 +} // namespace
28 31
29 void 32 void
30 ContentProvider::provideStreamData(int, int, Pipeline* p) 33 ContentProvider::provideStreamData(int, int, Pipeline* p)
@@ -39,23 +42,26 @@ ContentProvider::provideStreamData(int, int, Pipeline* p) @@ -39,23 +42,26 @@ ContentProvider::provideStreamData(int, int, Pipeline* p)
39 concat.manualFinish(); 42 concat.manualFinish();
40 } 43 }
41 44
42 -class InlineImageTracker: public QPDFObjectHandle::TokenFilter 45 +namespace
43 { 46 {
44 - public:  
45 - InlineImageTracker(QPDF*, size_t min_size, QPDFObjectHandle resources);  
46 - virtual ~InlineImageTracker() = default;  
47 - virtual void handleToken(QPDFTokenizer::Token const&);  
48 - QPDFObjectHandle convertIIDict(QPDFObjectHandle odict);  
49 -  
50 - QPDF* qpdf;  
51 - size_t min_size;  
52 - QPDFObjectHandle resources;  
53 - std::string dict_str;  
54 - std::string bi_str;  
55 - int min_suffix;  
56 - bool any_images;  
57 - enum { st_top, st_bi } state;  
58 -}; 47 + class InlineImageTracker: public QPDFObjectHandle::TokenFilter
  48 + {
  49 + public:
  50 + InlineImageTracker(QPDF*, size_t min_size, QPDFObjectHandle resources);
  51 + virtual ~InlineImageTracker() = default;
  52 + virtual void handleToken(QPDFTokenizer::Token const&);
  53 + QPDFObjectHandle convertIIDict(QPDFObjectHandle odict);
  54 +
  55 + QPDF* qpdf;
  56 + size_t min_size;
  57 + QPDFObjectHandle resources;
  58 + std::string dict_str;
  59 + std::string bi_str;
  60 + int min_suffix;
  61 + bool any_images;
  62 + enum { st_top, st_bi } state;
  63 + };
  64 +} // namespace
59 65
60 InlineImageTracker::InlineImageTracker( 66 InlineImageTracker::InlineImageTracker(
61 QPDF* qpdf, size_t min_size, QPDFObjectHandle resources) : 67 QPDF* qpdf, size_t min_size, QPDFObjectHandle resources) :
libqpdf/QPDFTokenizer.cc
@@ -20,22 +20,25 @@ is_delimiter(char ch) @@ -20,22 +20,25 @@ is_delimiter(char ch)
20 return (strchr(" \t\n\v\f\r()<>[]{}/%", ch) != 0); 20 return (strchr(" \t\n\v\f\r()<>[]{}/%", ch) != 0);
21 } 21 }
22 22
23 -class QPDFWordTokenFinder: public InputSource::Finder 23 +namespace
24 { 24 {
25 - public:  
26 - QPDFWordTokenFinder(  
27 - std::shared_ptr<InputSource> is, std::string const& str) :  
28 - is(is),  
29 - str(str) 25 + class QPDFWordTokenFinder: public InputSource::Finder
30 { 26 {
31 - }  
32 - virtual ~QPDFWordTokenFinder() = default;  
33 - virtual bool check();  
34 -  
35 - private:  
36 - std::shared_ptr<InputSource> is;  
37 - std::string str;  
38 -}; 27 + public:
  28 + QPDFWordTokenFinder(
  29 + std::shared_ptr<InputSource> is, std::string const& str) :
  30 + is(is),
  31 + str(str)
  32 + {
  33 + }
  34 + virtual ~QPDFWordTokenFinder() = default;
  35 + virtual bool check();
  36 +
  37 + private:
  38 + std::shared_ptr<InputSource> is;
  39 + std::string str;
  40 + };
  41 +} // namespace
39 42
40 bool 43 bool
41 QPDFWordTokenFinder::check() 44 QPDFWordTokenFinder::check()
libqpdf/QPDF_Stream.cc
@@ -19,38 +19,42 @@ @@ -19,38 +19,42 @@
19 19
20 #include <stdexcept> 20 #include <stdexcept>
21 21
22 -class SF_Crypt: public QPDFStreamFilter 22 +namespace
23 { 23 {
24 - public:  
25 - SF_Crypt() = default;  
26 - virtual ~SF_Crypt() = default;  
27 -  
28 - virtual bool  
29 - setDecodeParms(QPDFObjectHandle decode_parms) 24 + class SF_Crypt: public QPDFStreamFilter
30 { 25 {
31 - if (decode_parms.isNull()) {  
32 - return true;  
33 - }  
34 - bool filterable = true;  
35 - for (auto const& key : decode_parms.getKeys()) {  
36 - if (((key == "/Type") || (key == "/Name")) &&  
37 - ((!decode_parms.hasKey("/Type")) ||  
38 - decode_parms.isDictionaryOfType("/CryptFilterDecodeParms"))) {  
39 - // we handle this in decryptStream  
40 - } else {  
41 - filterable = false; 26 + public:
  27 + SF_Crypt() = default;
  28 + virtual ~SF_Crypt() = default;
  29 +
  30 + virtual bool
  31 + setDecodeParms(QPDFObjectHandle decode_parms)
  32 + {
  33 + if (decode_parms.isNull()) {
  34 + return true;
42 } 35 }
  36 + bool filterable = true;
  37 + for (auto const& key : decode_parms.getKeys()) {
  38 + if (((key == "/Type") || (key == "/Name")) &&
  39 + ((!decode_parms.hasKey("/Type")) ||
  40 + decode_parms.isDictionaryOfType(
  41 + "/CryptFilterDecodeParms"))) {
  42 + // we handle this in decryptStream
  43 + } else {
  44 + filterable = false;
  45 + }
  46 + }
  47 + return filterable;
43 } 48 }
44 - return filterable;  
45 - }  
46 49
47 - virtual Pipeline*  
48 - getDecodePipeline(Pipeline*)  
49 - {  
50 - // Not used -- handled by pipeStreamData  
51 - return nullptr;  
52 - }  
53 -}; 50 + virtual Pipeline*
  51 + getDecodePipeline(Pipeline*)
  52 + {
  53 + // Not used -- handled by pipeStreamData
  54 + return nullptr;
  55 + }
  56 + };
  57 +} // namespace
54 58
55 std::map<std::string, std::string> QPDF_Stream::filter_abbreviations = { 59 std::map<std::string, std::string> QPDF_Stream::filter_abbreviations = {
56 // The PDF specification provides these filter abbreviations for 60 // The PDF specification provides these filter abbreviations for
libqpdf/QUtil.cc
@@ -251,22 +251,25 @@ static unsigned short mac_roman_to_unicode[] = { @@ -251,22 +251,25 @@ static unsigned short mac_roman_to_unicode[] = {
251 0x02c7, // 0xff 251 0x02c7, // 0xff
252 }; 252 };
253 253
254 -class FileCloser 254 +namespace
255 { 255 {
256 - public:  
257 - FileCloser(FILE* f) :  
258 - f(f) 256 + class FileCloser
259 { 257 {
260 - } 258 + public:
  259 + FileCloser(FILE* f) :
  260 + f(f)
  261 + {
  262 + }
261 263
262 - ~FileCloser()  
263 - {  
264 - fclose(f);  
265 - } 264 + ~FileCloser()
  265 + {
  266 + fclose(f);
  267 + }
266 268
267 - private:  
268 - FILE* f;  
269 -}; 269 + private:
  270 + FILE* f;
  271 + };
  272 +} // namespace
270 273
271 template <typename T> 274 template <typename T>
272 static std::string 275 static std::string
@@ -1052,17 +1055,20 @@ QUtil::toUTF16(unsigned long uval) @@ -1052,17 +1055,20 @@ QUtil::toUTF16(unsigned long uval)
1052 1055
1053 // Random data support 1056 // Random data support
1054 1057
1055 -class RandomDataProviderProvider 1058 +namespace
1056 { 1059 {
1057 - public:  
1058 - RandomDataProviderProvider();  
1059 - void setProvider(RandomDataProvider*);  
1060 - RandomDataProvider* getProvider();  
1061 -  
1062 - private:  
1063 - RandomDataProvider* default_provider;  
1064 - RandomDataProvider* current_provider;  
1065 -}; 1060 + class RandomDataProviderProvider
  1061 + {
  1062 + public:
  1063 + RandomDataProviderProvider();
  1064 + void setProvider(RandomDataProvider*);
  1065 + RandomDataProvider* getProvider();
  1066 +
  1067 + private:
  1068 + RandomDataProvider* default_provider;
  1069 + RandomDataProvider* current_provider;
  1070 + };
  1071 +} // namespace
1066 1072
1067 RandomDataProviderProvider::RandomDataProviderProvider() : 1073 RandomDataProviderProvider::RandomDataProviderProvider() :
1068 default_provider(CryptoRandomDataProvider::getInstance()), 1074 default_provider(CryptoRandomDataProvider::getInstance()),
libqpdf/SecureRandomDataProvider.cc
@@ -31,47 +31,54 @@ SecureRandomDataProvider::getInstance() @@ -31,47 +31,54 @@ SecureRandomDataProvider::getInstance()
31 31
32 # ifdef _WIN32 32 # ifdef _WIN32
33 33
34 -class WindowsCryptProvider 34 +namespace
35 { 35 {
36 - public:  
37 - WindowsCryptProvider() 36 + class WindowsCryptProvider
38 { 37 {
39 - if (!CryptAcquireContextW(  
40 - &crypt_prov, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) {  
41 - throw std::runtime_error(  
42 - "unable to acquire crypt context: " + getErrorMessage()); 38 + public:
  39 + WindowsCryptProvider()
  40 + {
  41 + if (!CryptAcquireContextW(
  42 + &crypt_prov,
  43 + NULL,
  44 + NULL,
  45 + PROV_RSA_FULL,
  46 + CRYPT_VERIFYCONTEXT)) {
  47 + throw std::runtime_error(
  48 + "unable to acquire crypt context: " + getErrorMessage());
  49 + }
  50 + }
  51 + ~WindowsCryptProvider()
  52 + {
  53 + // Ignore error
  54 + CryptReleaseContext(crypt_prov, 0);
43 } 55 }
44 - }  
45 - ~WindowsCryptProvider()  
46 - {  
47 - // Ignore error  
48 - CryptReleaseContext(crypt_prov, 0);  
49 - }  
50 -  
51 - HCRYPTPROV crypt_prov;  
52 56
53 - private:  
54 - std::string  
55 - getErrorMessage()  
56 - {  
57 - DWORD errorMessageID = ::GetLastError();  
58 - LPSTR messageBuffer = nullptr;  
59 - size_t size = FormatMessageA(  
60 - FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |  
61 - FORMAT_MESSAGE_IGNORE_INSERTS,  
62 - NULL,  
63 - errorMessageID,  
64 - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),  
65 - reinterpret_cast<LPSTR>(&messageBuffer),  
66 - 0,  
67 - NULL);  
68 - std::string message(messageBuffer, size);  
69 - LocalFree(messageBuffer);  
70 - return (  
71 - "error number " + QUtil::int_to_string_base(errorMessageID, 16) +  
72 - ": " + message);  
73 - }  
74 -}; 57 + HCRYPTPROV crypt_prov;
  58 +
  59 + private:
  60 + std::string
  61 + getErrorMessage()
  62 + {
  63 + DWORD errorMessageID = ::GetLastError();
  64 + LPSTR messageBuffer = nullptr;
  65 + size_t size = FormatMessageA(
  66 + FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
  67 + FORMAT_MESSAGE_IGNORE_INSERTS,
  68 + NULL,
  69 + errorMessageID,
  70 + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  71 + reinterpret_cast<LPSTR>(&messageBuffer),
  72 + 0,
  73 + NULL);
  74 + std::string message(messageBuffer, size);
  75 + LocalFree(messageBuffer);
  76 + return (
  77 + "error number " +
  78 + QUtil::int_to_string_base(errorMessageID, 16) + ": " + message);
  79 + }
  80 + };
  81 +} // namespace
75 # endif 82 # endif
76 83
77 void 84 void
libqpdf/qpdf-c.cc
@@ -60,17 +60,20 @@ _qpdf_data::_qpdf_data() : @@ -60,17 +60,20 @@ _qpdf_data::_qpdf_data() :
60 { 60 {
61 } 61 }
62 62
63 -class ProgressReporter: public QPDFWriter::ProgressReporter  
64 -{  
65 - public:  
66 - ProgressReporter(void (*handler)(int, void*), void* data);  
67 - virtual ~ProgressReporter() = default;  
68 - virtual void reportProgress(int);  
69 -  
70 - private:  
71 - void (*handler)(int, void*);  
72 - void* data;  
73 -}; 63 +namespace
  64 +{
  65 + class ProgressReporter: public QPDFWriter::ProgressReporter
  66 + {
  67 + public:
  68 + ProgressReporter(void (*handler)(int, void*), void* data);
  69 + virtual ~ProgressReporter() = default;
  70 + virtual void reportProgress(int);
  71 +
  72 + private:
  73 + void (*handler)(int, void*);
  74 + void* data;
  75 + };
  76 +} // namespace
74 77
75 ProgressReporter::ProgressReporter(void (*handler)(int, void*), void* data) : 78 ProgressReporter::ProgressReporter(void (*handler)(int, void*), void* data) :
76 handler(handler), 79 handler(handler),