Cerata
A library to generate structural hardware designs
object.cc
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 #include "cerata/object.h"
16 
17 #include <memory>
18 #include <sstream>
19 
20 #include "cerata/utils.h"
21 #include "cerata/graph.h"
22 
23 namespace cerata {
24 
25 void Object::SetParent(Graph *parent) {
26  if (parent != nullptr) {
27  parent_ = parent;
28  } else {
29  throw std::runtime_error("Parent cannot be nullptr.");
30  }
31 }
32 
33 std::optional<Graph *> Object::parent() const { return parent_; }
34 
35 } // namespace cerata
cerata::Graph
A graph representing a hardware structure.
Definition: graph.h:37
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::parent_
std::optional< Graph * > parent_
An optional parent Graph to which this Object belongs. Initially no value.
Definition: object.h:73
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