couch/core/Util.h

33 lines
586 B
C
Raw Normal View History

2021-01-18 18:25:47 -06:00
#ifndef UTIL_H
#define UTIL_H
2021-01-19 16:36:10 -06:00
#include <iostream>
#include <string>
#include <stdlib.h>
2021-01-18 18:25:47 -06:00
2021-01-21 15:26:39 -06:00
#include "types.h"
#include "Node.h"
2021-01-18 18:25:47 -06:00
namespace Util {
2021-01-19 16:36:10 -06:00
void Die(const char *msg);
void Die(const char * msg, const char * more);
void Die(std::string msg);
2021-01-21 15:26:39 -06:00
template<class T>
T* FindNodeByType(Node *&root, const Name &type) {
if (root->GetType() == type) {
return dynamic_cast<T*>(root);
}
for (Node *child : root->children) {
T* res = FindNodeByType<T>(child, type);
if (res) {
return res;
}
}
return nullptr;
}
2021-01-18 18:25:47 -06:00
}
#endif /* UTIL_H */