-
Notifications
You must be signed in to change notification settings - Fork 2
/
printer.h
51 lines (41 loc) · 1.78 KB
/
printer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#pragma once
#include "model.h"
#include "mustache/mustache.hpp"
#include <filesystem>
#include <fstream>
class Translator;
kainjow::mustache::partial makePartial(std::string s,
const std::string& delimiter);
class Printer {
public:
using context_type = kainjow::mustache::object;
using template_type = kainjow::mustache::mustache;
using templates_type = std::vector<std::pair<template_type, template_type>>;
using m_object_type = kainjow::mustache::object;
using string = std::string;
using fspath = std::filesystem::path;
Printer(context_type&& contextObj, fspath inputBasePath,
const fspath& outFilesListPath, string delimiter,
const Translator& translator);
Printer(Printer&& p) = default;
Printer::template_type makeMustache(const string& tmpl) const;
std::vector<std::string> print(const fspath& filePathBase,
const Model& model) const;
private:
const Translator& _translator;
kainjow::mustache::data _contextData;
string _delimiter;
template_type _typeRenderer;
fspath _inputBasePath;
mutable std::ofstream _outFilesList;
[[nodiscard]] m_object_type renderType(const TypeUsage& tu) const;
[[nodiscard]] m_object_type dumpField(const VarDecl& field) const;
void addList(m_object_type& target, const string& name,
const VarDecls& properties) const;
bool dumpAdditionalProperties(m_object_type& target, const FlatSchema& s) const;
[[nodiscard]] m_object_type dumpAllTypes(const Model::schemaptrs_type& types) const;
template <typename SchemaPtrT>
[[nodiscard]] m_object_type
dumpTypes(const std::vector<std::pair<SchemaPtrT, TypeUsage>>& types,
const Call* scope = {}) const;
};