Tencent / rapidjson

A fast JSON parser/generator for C++ with both SAX/DOM style API
http://rapidjson.org/
Other
14k stars 3.5k forks source link

Polymorphism not used for PrettyWriter #2278

Open mondus opened 1 month ago

mondus commented 1 month ago

PrettyWritter extends the Writer class but the base class methods are not virtual and as such if a pointer to a PrettyWriter is cast to a Writer the default behaviour is that output is not written using pretty formatting.

See: https://github.com/FLAMEGPU/FLAMEGPU2/issues/1205

nglass commented 1 month ago

I disagree with this approach. Rapidjson is fast because it uses CRTP aka static-polymorphism. Introducing virtual on all the handler callbacks will cause a significant overhead for other users of the library. IMO you should introduce a writer template to your JSONStateWriter so you can have two implementations. one for writer and one for prettywriter.

It looks like you already do use templates for your JSONGraphWriter

template<typename T> void writeAnyVertex(T &writer