#include "coco/IR/Bag.h"
#include "coco/IR/DepSet.h"
+#include "coco/IR/ReadSet.h"
#include <set>
const DepSet *deps(void) const { return &_deps; }
public:
- Bag::ReaderSet *reads(void) { return &_reads; }
- const Bag::ReaderSet *reads(void) const { return &_reads; }
+ ReadSet *reads(void) { return &_reads; }
+ const ReadSet *reads(void) const { return &_reads; }
public:
Bag::UpdaterSet *updates(void) { return &_updates; }
/** @brief Links to dependent Object(s) */
DepSet _deps;
/** @brief Direct reads (not through Object) */
- Bag::ReaderSet _reads;
+ ReadSet _reads;
/** @brief Direct updates (not through Object) */
Bag::UpdaterSet _updates;
--- /dev/null
+#ifndef __COCO_IR_READ_H__
+#define __COCO_IR_READ_H__
+
+#include "coco/IR/ReadHook.h"
+
+#include <cassert>
+
+namespace coco
+{
+
+/**
+ * @brief A Read represents an edge between a Bag and its Reader
+ */
+class Read final
+{
+public:
+ Read(const PtrLink<Bag, BagInfo> *bag_link, Bag::Reader *read)
+ : _hook{bag_link, read}, _bag{nullptr}
+ {
+ // DO NOTHING
+ }
+
+public:
+ Bag *bag(void) const { return _bag; }
+
+public:
+ void bag(Bag *bag)
+ {
+ if (_bag)
+ {
+ _hook.onRelease(_bag);
+ _bag = nullptr;
+ }
+
+ assert(_bag == nullptr);
+
+ if (bag)
+ {
+ _bag = bag;
+ _hook.onTake(_bag);
+ }
+
+ assert(_bag == bag);
+ }
+
+private:
+ ReadHook _hook;
+ Bag *_bag;
+};
+
+} // namespace coco
+
+#endif // __COCO_IR_READ_H__
--- /dev/null
+#ifndef __COCO_IR_READ_SET_H__
+#define __COCO_IR_READ_SET_H__
+
+#include "coco/IR/Read.h"
+
+#include <set>
+
+namespace coco
+{
+
+using ReadSet = std::set<Read *>;
+
+} // namespace coco
+
+#endif // __COCO_IR_READ_SET_H__
for (auto read : *_info->reads())
{
- res.insert(read);
+ auto reader = read->reader();
+ assert(reader != nullptr);
+ res.insert(reader);
}
return res;
{
if (_bag)
{
- if (_link && _reader)
+ if (_link)
{
auto info = _link->find(_bag);
assert(info != nullptr);
- info->reads()->erase(_reader);
+ info->reads()->erase(this);
}
_bag = nullptr;
}
if (bag)
{
_bag = bag;
- if (_link && _reader)
+ if (_link)
{
auto info = _link->find(_bag);
assert(info != nullptr);
- info->reads()->insert(_reader);
+ info->reads()->insert(this);
}
}