-
Notifications
You must be signed in to change notification settings - Fork 0
/
MemberCall.h
87 lines (64 loc) · 1.72 KB
/
MemberCall.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#ifndef MEMBERCALL_H
#define MEMBERCALL_H
#include <memory>
#include <vector>
#include "Expression.h"
class MemberCall : public Expression
{
std::wstring record;
std::wstring member;
public:
MemberCall(std::wstring record, std::wstring member) : record(record), member(member)
{
}
virtual picojson::value asJson(std::shared_ptr<Substitution> subs, bool forConditionSection) const
{
/*
{
"Fn::GetAtt":[
"ElasticLoadBalancer",
"DNSName"
]
}*/
std::wstring keyname = record + L"." + member;
if (subs->HasSubstitute(keyname))
{
return subs->Substitute(keyname, forConditionSection);
}
std::wstring resolvedName = record;
if (subs->HasSubstitute(record))
{
picojson::value sub = subs->Substitute(record, forConditionSection);
if (sub.is<picojson::value::object>())
{
auto& obj = sub.get<picojson::value::object>();
if (obj.find(L"Ref") != obj.end() && obj.find(L"Ref")->second.is<std::wstring>())
{
resolvedName = obj[L"Ref"].get<std::wstring>();
}
}
}
std::map<std::wstring, picojson::value> obj;
std::vector<picojson::value> arr;
arr.push_back(picojson::value(resolvedName));
arr.push_back(picojson::value(member));
obj[L"Fn::GetAtt"] = picojson::value(arr);
return picojson::value(obj);
}
virtual ExpressionForm getForm() const
{
return MEMBER_CALL;
}
virtual std::wstring getType(std::shared_ptr<Substitution> subs) const
{
std::wstring keyname = record + L"." + member;
if (subs->HasTypeMapping(keyname))
{
return subs->GetType(keyname);
}
return L"string";
std::wcerr << "" << keyname << " is not defined" << std::endl;
exit(EXIT_FAILURE);
}
};
#endif // MEMBERCALL_H