 |
Cerata
A library to generate structural hardware designs
|
23 #include "cerata/logging.h"
24 #include "cerata/node.h"
25 #include "cerata/literal.h"
42 void Add(
const std::shared_ptr<T> &
object) {
43 for (
const auto &existing_object :
objects_) {
44 if (existing_object->name() == object->name()) {
45 CERATA_LOG(FATAL,
"Object " + PoolTypeToString(*existing_object) +
" already exists in pool.");
52 std::optional<T *>
Get(
const std::string &name) {
54 for (
const auto &existing_object :
objects_) {
55 if (existing_object->name() == name) {
56 return existing_object.get();
77 std::string PoolTypeToString(
const T &
object) {
78 return object.ToString();
108 template<
typename LitType>
112 if (node->IsLiteral()) {
113 auto lit_node = std::dynamic_pointer_cast<Literal>(node);
114 if (lit_node->storage_type() == StorageTypeOf<LitType>()) {
115 auto raw_value = RawValueOf<LitType>(*lit_node);
116 if (raw_value == value) {
144 inline std::shared_ptr<Literal>
intl(int64_t i) {
151 inline std::shared_ptr<Literal>
strl(std::string str) {
156 inline std::shared_ptr<Literal>
booll(
bool value) {
std::shared_ptr< Literal > booll(bool value)
Return a literal node representing a Boolean.
TypePool * default_type_pool()
Return a global default TypePool.
static std::shared_ptr< Literal > Make(bool value)
Create a boolean literal.
Literal * rstrl(std::string str)
Obtain a raw pointer to a string literal from the default node pool.
std::optional< T * > Get(const std::string &name)
Retrieve a component from the pool by name, if it exists. Returns empty option otherwise.
Contains every Cerata class, function, etc...
std::shared_ptr< Literal > GetLiteral(LitType value)
Obtain a literal node of raw storage type LitType with some value.
std::shared_ptr< Literal > strl(std::string str)
Obtain a shared pointer to a string literal from the default node pool.
std::shared_ptr< Literal > intl(int64_t i)
Obtain a shared pointer to an integer literal from the default node pool.
ComponentPool * default_component_pool()
Return a global default component pool.
std::vector< std::shared_ptr< T > > objects_
A list of objects that this pool owns.
A pool to share ownership of objects.
Literal * rintl(int64_t i)
Obtain a raw pointer to an integer literal from the default node pool.
void Add(const std::shared_ptr< T > &object)
Add an object to the pool, taking shared ownership. Object may not already exist in the pool.
void Clear()
Release ownership of all components.
NodePool * default_node_pool()
Return a global default node pool that can store nodes without being owned by a graph.