text: /*
   * Souffle - A Datalog Compiler
   * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved
   * Licensed under the Universal Permissive License v 1.0 as shown at:
   * - https://opensource.org/licenses/UPL
   * - <souffle root>/licenses/SOUFFLE-UPL.txt
   */
  
  /************************************************************************
   *
   * @file Negation.h
   *
   * Defines a class for evaluating conditions in the Relational Algebra
   * Machine.
   *
   ***********************************************************************/
  
  #pragma once
  
  #include "ram/Condition.h"
  #include "ram/Node.h"
  #include "ram/utility/NodeMapper.h"
  #include "souffle/utility/ContainerUtil.h"
  #include "souffle/utility/MiscUtil.h"
  #include <cassert>
  #include <memory>
  #include <sstream>
  #include <utility>
  #include <vector>
  
  namespace souffle::ram {
  
  /**
   * @class Negation
   * @brief Negates a given condition
   *
   * For example:
   * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
   * (NOT t0 IN A)
   * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
   */
  class Negation : public Condition {
  public:
      Negation(Own<Condition> op) : operand(std::move(op)) {
          assert(operand != nullptr && "operand of negation is a null-pointer");
      }
  
      /** @brief Get operand of negation */
      const Condition& getOperand() const {
          return *operand;
      }
  
      std::vector<const Node*> getChildNodes() const override {
          return {operand.get()};
      }
  
      Negation* clone() const override {
          return new Negation(souffle::clone(operand));
      }
  
      void apply(const NodeMapper& map) override {
          operand = map(std::move(operand));
      }
  
  protected:
      void print(std::ostream& os) const override {
          os << "(NOT " << *operand << ")";
      }
  
      bool equal(const Node& node) const override {
          const auto& other = static_cast<const Negation&>(node);
          return equal_ptr(operand, other.operand);
      }
  
      /** Operand */
      Own<Condition> operand;
  };
  
  }  // namespace souffle::ram
  