Vuo  2.3.2
VuoSerializable.hh
Go to the documentation of this file.
1 
10 #pragma once
11 
12 #include <string>
13 #include <map>
14 #pragma clang diagnostic push
15 #pragma clang diagnostic ignored "-Wdocumentation"
16 #include "json-c/json.h"
17 #pragma clang diagnostic pop
18 
25 {
26 public:
27  typedef VuoSerializable * (*Constructor)(json_object *);
28  static bool registerSubclass(std::string type, Constructor makeFromJson);
29  static void destroy(void *t);
30  static std::string type;
32  virtual json_object *getJson();
33  std::string getType() const;
34  virtual char *getSummary() = 0;
35  virtual bool operator==(const VuoSerializable &that) = 0;
36  virtual bool operator<(const VuoSerializable &that) = 0;
38  virtual ~VuoSerializable();
39 private:
40  typedef std::map<std::string, Constructor> ConstructorMap;
41  static ConstructorMap *constructors;
42 };
43 
49 #define VuoSerializableRegister(class) \
50  std::string class::type = #class; \
51  static bool class ## Registered = VuoSerializable::registerSubclass(class::type, class::makeFromJson);
52 
60 #define VuoSerializableEquals(class) \
61  const class *thatSpecialized = dynamic_cast<const class *>(&that); \
62  if (!thatSpecialized) \
63  return false;
64 
72 #define VuoSerializableLessThan(class) \
73  const class *thatSpecialized = dynamic_cast<const class *>(&that); \
74  if (!thatSpecialized) \
75  return getType() < that.getType();