ROSE 0.11.145.147
Serializer.h
1#ifndef Rosebud_Serializer_H
2#define Rosebud_Serializer_H
3#include <Rosebud/Ast.h>
4
5#include <Rosebud/Utility.h>
6
7namespace Rosebud {
8
15 // Nested types
17public:
20
22 // Data members
24private:
25 static std::vector<Ptr> registry_;
26
28 // Constructors, etc.
30public:
31 virtual ~Serializer() {}
32protected:
33 Serializer() {} // use derived class `instance` static member functions instea
34
35public:
37 static void registerSerializer(const Ptr&);
38
40 static const std::vector<Ptr>& registeredSerializers();
41
43 static Ptr lookup(const std::string&);
44
46 static std::vector<Ptr> lookup(const std::vector<std::string>&);
47
49 // Properties
51public:
53 virtual std::string name() const = 0;
54
56 virtual std::string purpose() const = 0;
57
59 // Code generation
61public:
65 virtual bool isSerializable(const Ast::ClassPtr&) const = 0;
66
71 virtual void genPrologue(std::ostream &header, std::ostream &impl, const Ast::ClassPtr&, const Hierarchy&,
72 const Generator&) const = 0;
73
81 virtual void genBody(std::ostream &header, std::ostream &impl, const Ast::ClassPtr&, const Hierarchy&,
82 const Generator&) const = 0;
83
88 virtual void genEpilogue(std::ostream &header, std::ostream &impl, const Ast::ClassPtr&, const Hierarchy&,
89 const Generator&) const = 0;
90
92 // Support
94private:
95 static void initRegistry();
96};
97
98} // namespace
99#endif
Base class for backend code generators.
Definition Generator.h:10
Base class for serialization generators.
Definition Serializer.h:13
virtual void genPrologue(std::ostream &header, std::ostream &impl, const Ast::ClassPtr &, const Hierarchy &, const Generator &) const =0
Generate prologue code.
virtual void genEpilogue(std::ostream &header, std::ostream &impl, const Ast::ClassPtr &, const Hierarchy &, const Generator &) const =0
Generate epilogue code.
SerializerPtr Ptr
Shared-ownership pointer.
Definition Serializer.h:19
static std::vector< Ptr > lookup(const std::vector< std::string > &)
Returns the serializers registered with the specified names.
virtual std::string purpose() const =0
Single-line description for the serializer.
static void registerSerializer(const Ptr &)
Register a serializer for use later.
static const std::vector< Ptr > & registeredSerializers()
Return all registered serializers.
virtual bool isSerializable(const Ast::ClassPtr &) const =0
Determines if a class should be serialized.
static Ptr lookup(const std::string &)
Return the registered serializer with the specified name.
virtual std::string name() const =0
Every serializer has a unique name.
virtual void genBody(std::ostream &header, std::ostream &impl, const Ast::ClassPtr &, const Hierarchy &, const Generator &) const =0
Generate main serialization code for the specified class.
Graph containing user-defined vertices and edges.
Definition Graph.h:634
std::shared_ptr< Class > ClassPtr
Shared-ownership pointer to a Class.
Rosebud is a tool to generate abstract syntax trees.
Definition Ast.h:14
std::shared_ptr< Serializer > SerializerPtr
Shared-ownership pointer to a Serializer.