@@ -71,28 +71,40 @@ template<typename OUTPUT_STREAM,
7171 template <typename , typename , typename , typename , unsigned > class JSON_WRITER = rapidjson::Writer>
7272class CRapidJsonWriterBase : public JSON_WRITER <OUTPUT_STREAM, SOURCE_ENCODING, TARGET_ENCODING, STACK_ALLOCATOR, WRITE_FLAGS> {
7373public:
74- using TTimeVec = std::vector<core_t ::TTime>;
75- using TStrVec = std::vector<std::string>;
76- using TDoubleVec = std::vector<double >;
77- using TDoubleDoublePr = std::pair<double , double >;
78- using TDoubleDoublePrVec = std::vector<TDoubleDoublePr>;
79- using TDoubleDoubleDoublePrPr = std::pair<double , TDoubleDoublePr>;
80- using TDoubleDoubleDoublePrPrVec = std::vector<TDoubleDoubleDoublePrPr>;
81- using TStrUSet = boost::unordered_set<std::string>;
82- using TDocument = rapidjson::Document;
83- using TValue = rapidjson::Value;
84- using TDocumentWeakPtr = boost::weak_ptr<TDocument>;
85- using TValuePtr = boost::shared_ptr<TValue>;
86-
87- using TPoolAllocatorPtr = boost::shared_ptr<CRapidJsonPoolAllocator>;
88- using TPoolAllocatorPtrStack = std::stack<TPoolAllocatorPtr>;
89- using TStrPoolAllocatorPtrMap = boost::unordered_map<std::string, TPoolAllocatorPtr>;
90- using TStrPoolAllocatorPtrMapItr = TStrPoolAllocatorPtrMap::iterator;
91- using TStrPoolAllocatorPtrMapItrBoolPr = std::pair<TStrPoolAllocatorPtrMapItr, bool >;
74+ typedef std::vector<core_t ::TTime> TTimeVec ;
75+ typedef std::vector<std::string> TStrVec ;
76+ typedef std::vector<double > TDoubleVec ;
77+ typedef std::pair<double , double > TDoubleDoublePr ;
78+ typedef std::vector<TDoubleDoublePr> TDoubleDoublePrVec ;
79+ typedef std::pair<double , TDoubleDoublePr> TDoubleDoubleDoublePrPr ;
80+ typedef std::vector<TDoubleDoubleDoublePrPr> TDoubleDoubleDoublePrPrVec ;
81+ typedef boost::unordered_set<std::string> TStrUSet ;
82+ typedef rapidjson::Document TDocument ;
83+ typedef rapidjson::Value TValue ;
84+ typedef boost::weak_ptr<TDocument> TDocumentWeakPtr ;
85+ typedef boost::shared_ptr<TValue> TValuePtr ;
86+
87+ typedef boost::shared_ptr<CRapidJsonPoolAllocator> TPoolAllocatorPtr ;
88+ typedef std::stack<TPoolAllocatorPtr> TPoolAllocatorPtrStack ;
89+ typedef boost::unordered_map<std::string, TPoolAllocatorPtr> TStrPoolAllocatorPtrMap ;
90+ typedef TStrPoolAllocatorPtrMap::iterator TStrPoolAllocatorPtrMapItr ;
91+ typedef std::pair<TStrPoolAllocatorPtrMapItr, bool > TStrPoolAllocatorPtrMapItrBoolPr ;
9292
9393public:
9494 using TRapidJsonWriterBase = JSON_WRITER<OUTPUT_STREAM, SOURCE_ENCODING, TARGET_ENCODING, STACK_ALLOCATOR, WRITE_FLAGS>;
9595
96+ // ! Instances of this class may very well be long lived, potentially for the lifetime of the application.
97+ // ! Over the course of that lifetime resources will accumulate in the underlying rapidjson memory
98+ // ! allocator. To prevent excessive memory expansion these resources will need to be cleaned regularly.
99+ // !
100+ // ! In preference to clients of this class explicitly clearing the allocator a helper/wrapper class -
101+ // ! \p CScopedRapidJsonPoolAllocator - is provided. This helper has an RAII style interface that clears the
102+ // ! allocator when it goes out of scope which requires that the writer provides the push/popAllocator
103+ // ! functions. The intent of this approach is to make it possible to use one or two separate allocators
104+ // ! for the writer at nested scope.
105+ // !
106+ // ! Note that allocators are not destroyed by the pop operation, they persist for the lifetime of the
107+ // ! writer in a cache for swift retrieval.
96108 CRapidJsonWriterBase (OUTPUT_STREAM& os) : TRapidJsonWriterBase(os) {
97109 // push a default rapidjson allocator onto our stack
98110 m_JsonPoolAllocators.push (boost::make_shared<CRapidJsonPoolAllocator>());
@@ -105,10 +117,9 @@ class CRapidJsonWriterBase : public JSON_WRITER<OUTPUT_STREAM, SOURCE_ENCODING,
105117
106118 CRapidJsonWriterBase (CRapidJsonWriterBase&& rhs) : TRapidJsonWriterBase(std::move(rhs)) {}
107119
108- virtual ~CRapidJsonWriterBase () {
109- // clean up resources
110- m_JsonPoolAllocators.pop ();
111- }
120+ // No need for an explicit destructor here as the allocators clear themselves
121+ // on destruction.
122+ virtual ~CRapidJsonWriterBase () = default ;
112123
113124 // ! Push a named allocator on to the stack
114125 // ! Look in the cache for the allocator - creating it if not present
0 commit comments