Cerata
A library to generate structural hardware designs
object.h
1 // Copyright 2018-2019 Delft University of Technology
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #include <utility>
18 #include <string>
19 #include <memory>
20 #include <vector>
21 #include <unordered_map>
22 
23 #include "cerata/utils.h"
24 
25 namespace cerata {
26 
27 class Node;
28 class NodeArray;
29 class PortArray;
30 class Port;
31 class Graph;
32 
34 class Object : public Named {
35  public:
37  enum ID {
38  NODE,
39  ARRAY
40  };
41 
47  explicit Object(std::string name, ID id) : Named(std::move(name)), obj_id_(id) {}
48 
50  ID obj_id() const { return obj_id_; }
52  bool IsNode() const { return obj_id_ == NODE; }
54  bool IsArray() const { return obj_id_ == ARRAY; }
55 
57  virtual void SetParent(Graph *parent);
59  virtual std::optional<Graph *> parent() const;
61  virtual std::shared_ptr<Object> Copy() const = 0;
62 
64  virtual void AppendReferences(std::vector<Object *> *out) const = 0;
65 
67  std::unordered_map<std::string, std::string> meta;
68 
69  protected:
73  std::optional<Graph *> parent_ = {};
74 };
75 
76 } // namespace cerata
cerata::Object::meta
std::unordered_map< std::string, std::string > meta
KV storage for metadata of tools or specific backend implementations.
Definition: object.h:67
cerata::Object::IsNode
bool IsNode() const
Return true if this object is a node.
Definition: object.h:52
cerata::Object::ID
ID
Object type ID to conveniently cast the object during run-time.
Definition: object.h:37
cerata::Graph
A graph representing a hardware structure.
Definition: graph.h:37
cerata::Object::obj_id_
ID obj_id_
The object type ID.
Definition: object.h:71
cerata::Object::SetParent
virtual void SetParent(Graph *parent)
Set the parent graph of this object.
Definition: object.cc:25
cerata
Contains every Cerata class, function, etc...
Definition: api.h:41
cerata::Object::IsArray
bool IsArray() const
Return true if this object is an array.
Definition: object.h:54
cerata::Object::Copy
virtual std::shared_ptr< Object > Copy() const =0
Deep-copy the object.
cerata::Object::Object
Object(std::string name, ID id)
Cerata object constructor.
Definition: object.h:47
cerata::Named::name
std::string name() const
Return the name of the object.
Definition: utils.h:45
cerata::Object::ARRAY
@ ARRAY
Array object.
Definition: object.h:39
cerata::Object::NODE
@ NODE
Node object.
Definition: object.h:38
cerata::Object
A Cerata Object on a graph.
Definition: object.h:34
cerata::Named
Convenience structure for anything that is named. Names are case-sensitive.
Definition: utils.h:40
cerata::Object::AppendReferences
virtual void AppendReferences(std::vector< Object * > *out) const =0
Append all objects that this object owns to the output.
cerata::Object::parent_
std::optional< Graph * > parent_
An optional parent Graph to which this Object belongs. Initially no value.
Definition: object.h:73
cerata::Object::obj_id
ID obj_id() const
Return the object ID of this object.
Definition: object.h:50
cerata::Object::parent
virtual std::optional< Graph * > parent() const
Return the parent graph of this object, if any. Returns empty option otherwise.
Definition: object.cc:33