Using CCDataVisitor for serialization. Edit CCDataVisitor directly?

Using CCDataVisitor for serialization. Edit CCDataVisitor directly?
0.0 0


From what I understand of the visitor pattern, it seems to me that I have to add visit(MyClass *p) to CCDataVisitor for every new class I add that needs to use the visitor. Is this the intended use pattern? This makes little sense when cocos2d-x is used as an Xcode subproject and lies outside the repo.

New classes would also have to subclass CCObject and override acceptVisitor to call visit(MyClass *p) instead of visitObject(CCObject *p)


You can subclass CCDataVisitor and write own logic when accepting some object: CCPrettyPrinter is good example.

Ideally you shouldn’t keep own classes in CCDictionary/CCArray: such data cannot be serialized to standard JSON or Property List. However, you still can override visitObject() in your CCDataVisitor subclass and test own class using dynamic_cast<DateClass *>(obj) or comparison by typeid(*obj).hash().


Sorry for bumping this old thread :sweat: …but I’m trying to do serialization and haven’t found the way do it. Was it posible to use CCDataVisitor? if so, can it be used for an entire hierarchy of nodes?