souffle  2.0.2-371-g6315b36
AbstractChoice.h
Go to the documentation of this file.
1 /*
2  * Souffle - A Datalog Compiler
3  * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved
4  * Licensed under the Universal Permissive License v 1.0 as shown at:
5  * - https://opensource.org/licenses/UPL
6  * - <souffle root>/licenses/SOUFFLE-UPL.txt
7  */
8 
9 /************************************************************************
10  *
11  * @file AbstractChoice.h
12  *
13  ***********************************************************************/
14 
15 #pragma once
16 
17 #include "ram/Condition.h"
18 #include "ram/Node.h"
19 #include "ram/utility/NodeMapper.h"
21 #include <cassert>
22 #include <memory>
23 #include <utility>
24 #include <vector>
25 
26 namespace souffle::ram {
27 
28 /**
29  * @class AbstractChoice
30  * @brief Abstract class for a choice operation
31  *
32  * Finding a single tuple, if it exists, such that a condition holds.
33  */
34 class AbstractChoice {
35 public:
36  AbstractChoice(Own<Condition> cond) : condition(std::move(cond)) {
37  assert(condition != nullptr && "Condition is a null-pointer");
38  }
39 
40  /** @brief Getter for the condition */
41  const Condition& getCondition() const {
42  assert(condition != nullptr && "condition of choice is a null-pointer");
43  return *condition;
44  }
45 
46  void apply(const NodeMapper& map) {
47  condition = map(std::move(condition));
48  }
49 
50  std::vector<const Node*> getChildNodes() const {
51  return {condition.get()};
52  }
53 
54 protected:
55  bool equal(const Node& node) const {
56  const auto& other = dynamic_cast<const AbstractChoice&>(node);
57  return equal_ptr(condition, other.condition);
58  }
59 
60  /** Condition for which a tuple in the relation may hold */
62 };
63 } // namespace souffle::ram
souffle::ram::AbstractChoice::AbstractChoice
AbstractChoice(Own< Condition > cond)
Definition: AbstractChoice.h:40
souffle::ram::AbstractChoice::apply
void apply(const NodeMapper &map)
Definition: AbstractChoice.h:50
souffle::ram::AbstractChoice
Abstract class for a choice operation.
Definition: AbstractChoice.h:38
souffle::Own
std::unique_ptr< A > Own
Definition: ContainerUtil.h:42
souffle::map
auto map(const std::vector< A > &xs, F &&f)
Applies a function to each element of a vector and returns the results.
Definition: ContainerUtil.h:158
souffle::ram::Condition
Abstract class for conditions and boolean values in RAM.
Definition: Condition.h:35
souffle::ram
Definition: AstToRamTranslator.h:54
souffle::ram::Node
Node is a superclass for all RAM IR classes.
Definition: Node.h:42
NodeMapper.h
souffle::ram::AbstractChoice::equal
bool equal(const Node &node) const
Definition: AbstractChoice.h:59
souffle::ram::NodeMapper
An abstract class for manipulating RAM Nodes by substitution.
Definition: NodeMapper.h:38
ContainerUtil.h
Condition.h
souffle::equal_ptr
bool equal_ptr(const T *a, const T *b)
Compares two values referenced by a pointer where the case where both pointers are null is also consi...
Definition: MiscUtil.h:130
souffle::ram::AbstractChoice::getChildNodes
std::vector< const Node * > getChildNodes() const
Definition: AbstractChoice.h:54
Node.h
std
Definition: Brie.h:3053
souffle::ram::AbstractChoice::condition
Own< Condition > condition
Condition for which a tuple in the relation may hold.
Definition: AbstractChoice.h:65
souffle::ram::AbstractChoice::getCondition
const Condition & getCondition() const
Getter for the condition.
Definition: AbstractChoice.h:45