lily/src/type_manager.hpp

30 lines
850 B
C++

#pragma once
#include <memory>
#include <map>
#include <vector>
#include "type.hpp"
namespace lily {
class type_manager {
private:
int next_id;
std::vector<std::unique_ptr<type>> types;
std::map<std::string, type*> type_names;
public:
type_manager();
type_internal* create_int_type();
type_internal* create_str_type();
type_data* create_data_type(const std::string& name);
template <typename T, typename ... Args>
T* create_type(Args...as) {
auto new_type = std::make_unique<T>(as...);
T* raw_ptr = new_type.get();
types.push_back(std::move(new_type));
return raw_ptr;
}
type* require_type(const std::string& name) const;
};
}