NazaraEngine/include/Nazara/Shader/Ast/ExpressionValue.hpp

53 lines
1.3 KiB
C++

// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Shader module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_SHADER_AST_EXPRESSIONVALUE_HPP
#define NAZARA_SHADER_AST_EXPRESSIONVALUE_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Shader/Ast/Enums.hpp>
#include <variant>
namespace Nz::ShaderAst
{
struct Expression;
using ExpressionPtr = std::unique_ptr<Expression>;
template<typename T>
class ExpressionValue
{
public:
ExpressionValue() = default;
ExpressionValue(T value);
ExpressionValue(ExpressionPtr expr);
ExpressionValue(const ExpressionValue&) = default;
ExpressionValue(ExpressionValue&&) noexcept = default;
~ExpressionValue() = default;
ExpressionPtr&& GetExpression() &&;
const ExpressionPtr& GetExpression() const &;
const T& GetResultingValue() const;
bool IsExpression() const;
bool IsResultingValue() const;
bool HasValue() const;
void Reset();
ExpressionValue& operator=(const ExpressionValue&) = default;
ExpressionValue& operator=(ExpressionValue&&) noexcept = default;
private:
std::variant<std::monostate, T, ExpressionPtr> m_value;
};
}
#include <Nazara/Shader/Ast/ExpressionValue.inl>
#endif // NAZARA_SHADER_AST_EXPRESSIONVALUE_HPP