/** @file ISequence_Xfer.hpp
 *
 *  Generated automagically from ingredients:
 *  1. code generator:
 *       [xo-facet/codegen/genfacet]
 *     arguments:
 *       --input [idl/Sequence.json5]
 *  2. jinja2 template for abstract facet .hpp file:
 *       [iface_facet_any.hpp.j2]
 *  3. idl for facet methods
 *       [idl/Sequence.json5]
 *
 *  variables:
 *    {facet_hpp_fname} -> Sequence.hpp
 *    {impl_hpp_subdir} -> sequence
 *    {facet_ns1} -> xo
 *    {facet_detail_subdir} -> sequence
 *    {abstract_facet_fname} -> ASequence.hpp
 **/

#pragma once

#include "ASequence.hpp"
#include <xo/alloc2/GCObject.hpp>

namespace xo {
namespace scm {
    /** @class ISequence_Xfer
     **/
    template <typename DRepr, typename ISequence_DRepr>
    class ISequence_Xfer : public ASequence {
    public:
        /** @defgroup scm-sequence-xfer-type-traits **/
        ///@{
        /** actual implementation (not generated; often delegates to DRepr) **/
        using Impl = ISequence_DRepr;
        /** integer identifying a type **/
        using typeseq = ASequence::typeseq;
        using size_type = ASequence::size_type;
        using AGCObject = ASequence::AGCObject;
        ///@}

        /** @defgroup scm-sequence-xfer-methods **/
        ///@{

        static const DRepr & _dcast(Copaque d) { return *(const DRepr *)d; }
        static DRepr & _dcast(Opaque d) { return *(DRepr *)d; }

        // from ASequence

        // builtin methods
        typeseq _typeseq() const noexcept override { return s_typeseq; }
        void _drop(Opaque d) const noexcept override { _dcast(d).~DRepr(); }

        // const methods
        bool is_empty(Copaque data)  const  noexcept override {
            return I::is_empty(_dcast(data));
        }
        bool is_finite(Copaque data)  const  noexcept override {
            return I::is_finite(_dcast(data));
        }
        obj<AGCObject> at(Copaque data, size_type index)  const override {
            return I::at(_dcast(data), index);
        }

        // non-const methods

        ///@}

    private:
        using I = Impl;

    public:
        /** @defgroup scm-sequence-xfer-member-vars **/
        ///@{

        /** typeseq for template parameter DRepr **/
        static typeseq s_typeseq;
        /** true iff satisfies facet implementation **/
        static bool _valid;

        ///@}
    };

    template <typename DRepr, typename ISequence_DRepr>
    xo::facet::typeseq
    ISequence_Xfer<DRepr, ISequence_DRepr>::s_typeseq
      = xo::facet::typeseq::id<DRepr>();

    template <typename DRepr, typename ISequence_DRepr>
    bool
    ISequence_Xfer<DRepr, ISequence_DRepr>::_valid
      = xo::facet::valid_facet_implementation<ASequence,
                                              ISequence_Xfer>();

} /*namespace scm */
} /*namespace xo*/

/* end ISequence_Xfer.hpp */
