Skip to content

File listunaryoperator.h

File List > algebra > listoperators > listunaryoperator.h

Go to the documentation of this file

#ifndef TEMPLAT_LATTICE_ALGEBRA_OPERATORS_LISTOPERATORS_LISTUNARYOPERATOR_H
#define TEMPLAT_LATTICE_ALGEBRA_OPERATORS_LISTOPERATORS_LISTUNARYOPERATOR_H

/* This file is part of TempLat, available at https://cosmolattice.github.io/templat .
   Copyright 2021-2026 The TempLat authors, see AUTHORS.md.
   Released under the MIT license, see LICENSE.md. */

// File info: Main contributor(s): Adrien Florio, Year: 2019

#include "TempLat/util/containsspace.h"
#include "TempLat/lattice/algebra/spacestateinterface.h"
#include "TempLat/lattice/algebra/helpers/ghostshunter.h"
#include "TempLat/lattice/algebra/helpers/getstring.h"
#include "TempLat/lattice/algebra/helpers/getvectorsize.h"
#include "TempLat/lattice/algebra/helpers/confirmspace.h"
#include "TempLat/lattice/algebra/helpers/confirmghosts.h"
#include "TempLat/lattice/algebra/helpers/getcomponent.h"
#include "TempLat/lattice/algebra/helpers/getndim.h"

namespace TempLat
{

  template <typename R> class ListUnaryOperator
  {
  public:
    static consteval size_t getNDim() { return GetNDim::get<R>(); }

    ListUnaryOperator(const R &pR) : mR(pR) {}

    template <int N> device::Idx confirmGhostsUpToDate(Tag<N> i) const { return ConfirmGhosts::apply(mR, i); }

    template <int N, size_t NDim>
    void confirmSpace(Tag<N> i, const LayoutStruct<NDim> &newLayout, const SpaceStateType &spaceType) const
    {
      ConfirmSpace::apply(mR, i, newLayout, spaceType);
    }

    inline auto getToolBox() const { return GetToolBox::get(mR); }

    virtual std::string operatorString() const { return " "; }

    template <int N> std::string toString(Tag<N> i) const
    {
      std::string result = GetString::get(mR, i);

      if (ContainsSpace::test(result)) result = "(" + result + ")";

      return operatorString() + result;
    }

    using Getter = GetComponent;

  protected:
    R mR;
  };
} // namespace TempLat

#endif