couch/core/Util.h

50 lines
1.1 KiB
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>
2021-03-04 14:29:48 -06:00
#include <sstream>
2021-01-19 16:36:10 -06:00
#include <string>
2021-03-04 14:29:48 -06:00
#include <vector>
2021-01-19 16:36:10 -06:00
#include <stdlib.h>
2021-01-18 18:25:47 -06:00
2021-01-21 15:26:39 -06:00
#include "types.h"
2021-01-24 16:37:35 -06:00
class Node;
2021-01-21 15:26:39 -06:00
#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);
}
2021-01-26 16:42:28 -06:00
for (Node *child : root->GetChildren()) {
2021-01-21 15:26:39 -06:00
T* res = FindNodeByType<T>(child, type);
if (res) {
return res;
}
}
return nullptr;
}
2021-03-04 14:29:48 -06:00
template<class T>
std::vector<T*> FindNodesByType(Node *&root, const Name &type) {
std::vector<T*> nodes;
if (root->GetType() == type) {
nodes.push_back(dynamic_cast<T*>(root));
}
for (Node *child : root->GetChildren()) {
std::vector<T*> childs = FindNodesByType<T>(child, type);
nodes.insert(nodes.begin(), childs.begin(), childs.end());
}
return nodes;
}
std::string ShaderArrayName(const char* arrName, int index, const char* memberName);
2021-01-18 18:25:47 -06:00
}
#endif /* UTIL_H */