-
Notifications
You must be signed in to change notification settings - Fork 0
/
smart_pointers.h
48 lines (33 loc) · 1.04 KB
/
smart_pointers.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Examples of the use of smart pointers to describe ownership
// Author: Jeff Trull <[email protected]>
#include <vector>
#include <memory>
class Design;
class Instance;
class Cell;
std::vector<std::unique_ptr<Cell>>
readCells(std::string const & fileName);
class Library {
std::shared_ptr<Cell> findCell(std::string const& cellName);
private:
std::vector<std::shared_ptr<Cell>> cells_;
};
class Instance {
public:
Instance(std::string const & name,
std::shared_ptr<const Cell> cell,
std::weak_ptr<Design> parent);
std::shared_ptr<Design> parent() const;
std::string const & name() const;
private:
std::string name_;
std::shared_ptr<const Cell> cell_;
std::weak_ptr<Design> parent_; // it might get deleted
};
class Design : public std::enable_shared_from_this<Design> {
public:
std::shared_ptr<Instance> addInstance(std::shared_ptr<const Cell> cell, std::string name);
void removeInstance(std::string const& name);
private:
std::vector<std::shared_ptr<Instance>> instances_;
};