33 #include <boost/format.hpp>
43 #include <unordered_map>
44 #include <unordered_set>
57 forAll([
this](std::shared_ptr<Generatable> c) {
63 virtual void reads(
const std::string& var) {
66 std::string(
"Couldn't find parent for ") +
name();
67 throw std::runtime_error(err.c_str());
73 std::unordered_set<std::string> readList;
75 for (
auto&& r : readList) {
80 virtual void writes(
const std::string& var) {
83 std::string(
"Couldn't find parent for ") +
name();
84 throw std::runtime_error(err.c_str());
92 std::string(
"Couldn't find parent for ") +
name();
93 throw std::runtime_error(err.c_str());
101 std::string(
"Couldn't find parent for ") +
name();
102 throw std::runtime_error(err.c_str());
108 if (
parent() ==
nullptr) {
110 std::string(
"Couldn't find parent for ") +
name_;
111 throw std::runtime_error(err.c_str());
117 if (
parent() ==
nullptr) {
119 std::string(
"Couldn't find parent for ") +
name_;
120 throw std::runtime_error(err.c_str());
126 if (
parent() ==
nullptr) {
128 std::string(
"Couldn't find parent for ") +
name_;
129 throw std::runtime_error(err.c_str());
135 if (
parent() ==
nullptr) {
137 std::string(
"Couldn't find parent for ") +
name_;
138 throw std::runtime_error(err.c_str());
145 if (intWidth == -1) {
146 std::string err =
name_
147 + std::string(
" does not have an integer width value.");
148 throw std::runtime_error(err.c_str());
154 if (
parent() ==
nullptr) {
156 std::string(
"Couldn't find parent for ") +
name_;
157 throw std::runtime_error(err.c_str());
163 throw std::runtime_error(
"Shouldn't be here!");
167 throw std::runtime_error(
"Shouldn't be here!");
170 virtual void hdl(std::ostream& stream,
Language lang,
int indent) {
174 std::string err = std::string(
"Attempted to generate ") +
name_;
175 throw std::runtime_error(err);
185 std::shared_ptr<Generatable> c) { c->hdl(stream, lang); });
190 forAll([&](std::shared_ptr<Generatable> c) {
191 c->hdl(stream, lang, indent);
195 template <
typename Func>
void forAll(Func func) {
201 template <
typename Type,
typename Func>
void forAll(Func func) {
203 Type* ptr =
dynamic_cast<Type*
>(c.get());
210 if (
parent() ==
nullptr) {
212 }
else if (
dynamic_cast<Type*
>(
parent()) !=
nullptr) {
220 if (
parent() ==
nullptr) {
221 throw std::runtime_error(
"Couldn't find parent'");
222 }
else if (
dynamic_cast<Type*
>(
parent()) !=
nullptr) {
223 return dynamic_cast<Type*
>(
parent());
234 template <
class Component>
236 components_.push_back(std::make_shared<Component>(c));
239 const std::string&
name() const noexcept {
return name_; }