Code View

mstring / mstring-1.3.1.2 / src / MParameter.hh
// SPDX-License-Identifier: MIT
#pragma once

#include <iosfwd>
#include <string>

#include "MWriter.hh"
#include "Message.hh"

/// \file MParameter.hh
/// \brief Writers for the `@ name type` parameters of a message.
///
/// A generated class stores a parameter by value — `std::decay_t< type >` —
/// so an exception or streamable object built from `std::string const &`
/// never refers to a temporary that is gone by the time it is printed.

/// \brief `type name` in a parameter list.
class ParameterWriter
  : public Writer
{
  public:
    ParameterWriter( std::ostream &stream, std::string &indent,
                     bool separator = false, bool maybeUnused = false );

    void operator( )( const Parameter &parameter );

  protected:
    bool _Separator;
    bool _MaybeUnused;
};

/// \brief The data member of a generated class.
class ParameterToVariableWriter
  : public Writer
{
  public:
    ParameterToVariableWriter( std::ostream &stream, std::string &indent );

    void operator( )( const Parameter &parameter );
};

/// \brief The inline getter of a generated class.
class ParameterToGetterWriter
  : public Writer
{
  public:
    ParameterToGetterWriter( std::ostream &stream, std::string &indent );

    void operator( )( const Parameter &parameter );
};

/// \brief `member_name( name )` in a constructor's initializer list.
class ParameterVariableConstructorWriter
  : public Writer
{
  public:
    ParameterVariableConstructorWriter( std::ostream &stream, std::string &indent, bool separator = false );

    void operator( )( const Parameter &parameter );

  protected:
    bool _Separator;
};

/// \brief The arguments of a call: the parameter names, optionally prefixed
///        (`member_` to pass a class' stored values).
class ParameterCallWriter
  : public Writer
{
  public:
    ParameterCallWriter( std::ostream &stream, std::string &indent,
                         std::string memberPrefix, bool separator = false );

    void operator( )( const Parameter &parameter );

  protected:
    std::string _MemberPrefix;
    bool _Separator;
};

/// \brief The storage type of a parameter in a generated class.
std::string StorageType( const Parameter &parameter );