// SPDX-License-Identifier: MIT
#pragma once
#include <optional>
#include <string>
#include "Comment.hh"
namespace fedem
{
namespace fson
{
// ─────────────────────────────────────────────────────────────────────
// Include (docs/notation/00011-include.rrd)
//
// A "%include" directive appearing among the entries of an object (or,
// for a root-level directive, among the entries of the root object).
// It is a structural node — it carries no value of its own — but it is
// preserved verbatim on write-back (project hard requirement: round-trip
// must not lose structure).
//
// %include "base.fson" → merge: the target's root object
// members are shallow-merged into the
// including object as defaults; any
// key already present in the host wins
// %include "base.fson" as vault → alias: the target's root value is
// exposed under the bare/quoted key
// "vault" (open-root: the target need
// not be an object)
//
// The path is stored exactly as written in the source (the string value,
// already unescaped by the parser). The alias, when present, is the
// resolved key text. Resolution against the file system is performed by
// the loader, not by this node.
//
// A disabled directive ("--%include …") is invisible to resolution — its
// defaults are not applied and its alias is not bound — but it is kept in
// the structure and written back with its "--" prefix, mirroring the
// disabled-member semantics ("yok hükmünde").
//
// Move-only; duplicate with clone().
// ─────────────────────────────────────────────────────────────────────
class Include final
{
public:
explicit Include( std::string path,
std::optional< std::string > alias = std::nullopt,
bool disabled = false );
Include( Include&& other ) noexcept = default;
Include& operator=( Include&& other ) noexcept = default;
Include clone( ) const;
std::string const& getPath( ) const noexcept;
void setPath( std::string path );
bool hasAlias( ) const noexcept;
std::optional< std::string > const& getAlias( ) const noexcept;
void setAlias( std::optional< std::string > alias );
bool isDisabled( ) const noexcept;
void setDisabled( bool disabled ) noexcept;
CommentList& getLeadingComments( ) noexcept;
CommentList const& getLeadingComments( ) const noexcept;
std::optional< Comment >& getTrailingComment( ) noexcept;
std::optional< Comment > const& getTrailingComment( ) const noexcept;
private:
std::string path;
std::optional< std::string > alias;
bool disabled;
CommentList leading;
std::optional< Comment > trailing;
Include( Include const& ) = delete;
Include& operator=( Include const& ) = delete;
};
inline Include::Include( std::string path,
std::optional< std::string > alias,
bool disabled )
: path( std::move( path ) )
, alias( std::move( alias ) )
, disabled( disabled )
{
}
inline Include Include::clone( ) const
{
Include copy( path, alias, disabled );
copy.leading = leading;
copy.trailing = trailing;
return copy;
}
inline std::string const& Include::getPath( ) const noexcept
{
return path;
}
inline void Include::setPath( std::string path )
{
this->path = std::move( path );
}
inline bool Include::hasAlias( ) const noexcept
{
return alias.has_value( );
}
inline std::optional< std::string > const& Include::getAlias( ) const noexcept
{
return alias;
}
inline void Include::setAlias( std::optional< std::string > alias )
{
this->alias = std::move( alias );
}
inline bool Include::isDisabled( ) const noexcept
{
return disabled;
}
inline void Include::setDisabled( bool disabled ) noexcept
{
this->disabled = disabled;
}
inline CommentList& Include::getLeadingComments( ) noexcept
{
return leading;
}
inline CommentList const& Include::getLeadingComments( ) const noexcept
{
return leading;
}
inline std::optional< Comment >& Include::getTrailingComment( ) noexcept
{
return trailing;
}
inline std::optional< Comment > const& Include::getTrailingComment( ) const noexcept
{
return trailing;
}
} // end namespace fson
} // end namespace fedem