ROSE  0.11.145.0
Serializer.h
1 #ifndef Rosebud_Serializer_H
2 #define Rosebud_Serializer_H
3 #include <Rosebud/Ast.h>
4 
5 namespace Rosebud {
6 
11 class Serializer {
13  // Nested types
15 public:
17  using Ptr = SerializerPtr;
18 
20  // Data members
22 private:
23  static std::vector<Ptr> registry_;
24 
26  // Constructors, etc.
28 public:
29  virtual ~Serializer() {}
30 protected:
31  Serializer() {} // use derived class `instance` static member functions instea
32 
33 public:
35  static void registerSerializer(const Ptr&);
36 
38  static const std::vector<Ptr>& registeredSerializers();
39 
41  static Ptr lookup(const std::string&);
42 
44  // Properties
46 public:
48  virtual std::string name() const = 0;
49 
51  virtual std::string purpose() const = 0;
52 
54  // Code generation
56 public:
60  virtual bool isSerializable(const Ast::ClassPtr&) const = 0;
61 
66  virtual void generate(std::ostream &header, std::ostream &impl, const Ast::ClassPtr&, const Generator&) const = 0;
67 
69  // Support
71 private:
72  static void initRegistry();
73 };
74 
75 } // namespace
76 #endif
static Ptr lookup(const std::string &)
Return the registered serializer with the specified name.
Rosebud is a tool to generate code for ROSE.
Definition: Ast.h:14
std::shared_ptr< Serializer > SerializerPtr
Shared-ownership pointer to a Serializer.
Definition: ud/BasicTypes.h:32
virtual void generate(std::ostream &header, std::ostream &impl, const Ast::ClassPtr &, const Generator &) const =0
Generate code for the specified class.
virtual std::string purpose() const =0
Single-line description for the serializer.
static const std::vector< Ptr > & registeredSerializers()
Return all registered serializers.
static void registerSerializer(const Ptr &)
Register a serializer for use later.
std::shared_ptr< Class > ClassPtr
Shared-ownership pointer to a Class.
Definition: ud/BasicTypes.h:51
virtual std::string name() const =0
Every serializer has a unique name.
virtual bool isSerializable(const Ast::ClassPtr &) const =0
Determines if a class should be serialized.
SerializerPtr Ptr
Shared-ownership pointer.
Definition: Serializer.h:17
Base class for serialization generators.
Definition: Serializer.h:11