@@ -62,28 +62,40 @@ template<typename OUTPUT_STREAM,
6262 template <typename , typename , typename , typename , unsigned > class JSON_WRITER = rapidjson::Writer>
6363class CRapidJsonWriterBase : public JSON_WRITER <OUTPUT_STREAM, SOURCE_ENCODING, TARGET_ENCODING, STACK_ALLOCATOR, WRITE_FLAGS> {
6464public:
65- using TTimeVec = std::vector<core_t ::TTime>;
66- using TStrVec = std::vector<std::string>;
67- using TDoubleVec = std::vector<double >;
68- using TDoubleDoublePr = std::pair<double , double >;
69- using TDoubleDoublePrVec = std::vector<TDoubleDoublePr>;
70- using TDoubleDoubleDoublePrPr = std::pair<double , TDoubleDoublePr>;
71- using TDoubleDoubleDoublePrPrVec = std::vector<TDoubleDoubleDoublePrPr>;
72- using TStrUSet = boost::unordered_set<std::string>;
73- using TDocument = rapidjson::Document;
74- using TValue = rapidjson::Value;
75- using TDocumentWeakPtr = boost::weak_ptr<TDocument>;
76- using TValuePtr = boost::shared_ptr<TValue>;
77-
78- using TPoolAllocatorPtr = boost::shared_ptr<CRapidJsonPoolAllocator>;
79- using TPoolAllocatorPtrStack = std::stack<TPoolAllocatorPtr>;
80- using TStrPoolAllocatorPtrMap = boost::unordered_map<std::string, TPoolAllocatorPtr>;
81- using TStrPoolAllocatorPtrMapItr = TStrPoolAllocatorPtrMap::iterator;
82- using TStrPoolAllocatorPtrMapItrBoolPr = std::pair<TStrPoolAllocatorPtrMapItr, bool >;
65+ typedef std::vector<core_t ::TTime> TTimeVec ;
66+ typedef std::vector<std::string> TStrVec ;
67+ typedef std::vector<double > TDoubleVec ;
68+ typedef std::pair<double , double > TDoubleDoublePr ;
69+ typedef std::vector<TDoubleDoublePr> TDoubleDoublePrVec ;
70+ typedef std::pair<double , TDoubleDoublePr> TDoubleDoubleDoublePrPr ;
71+ typedef std::vector<TDoubleDoubleDoublePrPr> TDoubleDoubleDoublePrPrVec ;
72+ typedef boost::unordered_set<std::string> TStrUSet ;
73+ typedef rapidjson::Document TDocument ;
74+ typedef rapidjson::Value TValue ;
75+ typedef boost::weak_ptr<TDocument> TDocumentWeakPtr ;
76+ typedef boost::shared_ptr<TValue> TValuePtr ;
77+
78+ typedef boost::shared_ptr<CRapidJsonPoolAllocator> TPoolAllocatorPtr ;
79+ typedef std::stack<TPoolAllocatorPtr> TPoolAllocatorPtrStack ;
80+ typedef boost::unordered_map<std::string, TPoolAllocatorPtr> TStrPoolAllocatorPtrMap ;
81+ typedef TStrPoolAllocatorPtrMap::iterator TStrPoolAllocatorPtrMapItr ;
82+ typedef std::pair<TStrPoolAllocatorPtrMapItr, bool > TStrPoolAllocatorPtrMapItrBoolPr ;
8383
8484public:
8585 using TRapidJsonWriterBase = JSON_WRITER<OUTPUT_STREAM, SOURCE_ENCODING, TARGET_ENCODING, STACK_ALLOCATOR, WRITE_FLAGS>;
8686
87+ // ! Instances of this class may very well be long lived, potentially for the lifetime of the application.
88+ // ! Over the course of that lifetime resources will accumulate in the underlying rapidjson memory
89+ // ! allocator. To prevent excessive memory expansion these resources will need to be cleaned regularly.
90+ // !
91+ // ! In preference to clients of this class explicitly clearing the allocator a helper/wrapper class -
92+ // ! \p CScopedRapidJsonPoolAllocator - is provided. This helper has an RAII style interface that clears the
93+ // ! allocator when it goes out of scope which requires that the writer provides the push/popAllocator
94+ // ! functions. The intent of this approach is to make it possible to use one or two separate allocators
95+ // ! for the writer at nested scope.
96+ // !
97+ // ! Note that allocators are not destroyed by the pop operation, they persist for the lifetime of the
98+ // ! writer in a cache for swift retrieval.
8799 CRapidJsonWriterBase (OUTPUT_STREAM& os) : TRapidJsonWriterBase(os) {
88100 // push a default rapidjson allocator onto our stack
89101 m_JsonPoolAllocators.push (boost::make_shared<CRapidJsonPoolAllocator>());
@@ -96,10 +108,9 @@ class CRapidJsonWriterBase : public JSON_WRITER<OUTPUT_STREAM, SOURCE_ENCODING,
96108
97109 CRapidJsonWriterBase (CRapidJsonWriterBase&& rhs) : TRapidJsonWriterBase(std::move(rhs)) {}
98110
99- virtual ~CRapidJsonWriterBase () {
100- // clean up resources
101- m_JsonPoolAllocators.pop ();
102- }
111+ // No need for an explicit destructor here as the allocators clear themselves
112+ // on destruction.
113+ virtual ~CRapidJsonWriterBase () = default ;
103114
104115 // ! Push a named allocator on to the stack
105116 // ! Look in the cache for the allocator - creating it if not present
0 commit comments