souffle  2.0.2-371-g6315b36
LambdaNodeMapper.h
Go to the documentation of this file.
1 /*
2  * Souffle - A Datalog Compiler
3  * Copyright (c) 2013, 2015, 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 LambdaNodeMapper.h
12  *
13  * Declaration of RAM node and mappers for RAM nodes
14  *
15  ***********************************************************************/
16 
17 #pragma once
18 
19 #include "ram/utility/NodeMapper.h"
21 #include <cassert>
22 #include <functional>
23 #include <iostream>
24 #include <memory>
25 #include <typeinfo>
26 #include <utility>
27 #include <vector>
28 
29 namespace souffle::ram {
30 
31 class Node;
32 
33 /**
34  * @class LambdaNodeMapper
35  * @brief A special NodeMapper wrapping a lambda conducting node transformations.
36  */
37 template <typename Lambda>
38 class LambdaNodeMapper : public NodeMapper {
39  const Lambda& lambda;
40 
41 public:
42  /**
43  * @brief Constructor for LambdaNodeMapper
44  */
45  LambdaNodeMapper(const Lambda& lambda) : lambda(lambda) {}
46 
47  /**
48  * @brief Applies lambda
49  */
50  Own<Node> operator()(Own<Node> node) const override {
51  Own<Node> result = lambda(std::move(node));
52  assert(result != nullptr && "null-pointer in lambda ram-node mapper");
53  return result;
54  }
55 };
56 
57 /**
58  * @brief Creates a node mapper based on a corresponding lambda expression.
59  */
60 template <typename Lambda>
61 LambdaNodeMapper<Lambda> makeLambdaRamMapper(const Lambda& lambda) {
62  return LambdaNodeMapper<Lambda>(lambda);
63 }
64 
65 } // namespace souffle::ram
souffle::ram::LambdaNodeMapper::lambda
const Lambda & lambda
Definition: LambdaNodeMapper.h:45
souffle::Own
std::unique_ptr< A > Own
Definition: ContainerUtil.h:42
souffle::ram
Definition: AstToRamTranslator.h:54
souffle::ram::LambdaNodeMapper
A special NodeMapper wrapping a lambda conducting node transformations.
Definition: LambdaNodeMapper.h:44
NodeMapper.h
ContainerUtil.h
souffle::ram::LambdaNodeMapper::LambdaNodeMapper
LambdaNodeMapper(const Lambda &lambda)
Constructor for LambdaNodeMapper.
Definition: LambdaNodeMapper.h:51
souffle::ram::LambdaNodeMapper::operator()
Own< Node > operator()(Own< Node > node) const override
Applies lambda.
Definition: LambdaNodeMapper.h:56
souffle::ram::makeLambdaRamMapper
LambdaNodeMapper< Lambda > makeLambdaRamMapper(const Lambda &lambda)
Creates a node mapper based on a corresponding lambda expression.
Definition: LambdaNodeMapper.h:67