ReflectedDepField

Represents information about a $dep member variable of a class recorded in a ReflectedClass.


$struct+ ReflectedDepField
{
    $ConstStringZ GetName() const { return m_name; }
    $ssize_t GetOffset() const { return m_offset; }

    //////////////// State //////////////////
    ConstStringZ m_name;
    ssize_t m_offset;           // 0 for an agent
    const octet_t* m_bc;
    ssize_t m_depNodeOffset;
};


ConstStringZ m_name

The declared name of the $dep member variable represented as a pointer to a UTF-8 encoded null-terminated string (see ConstStringZ).


ssize_t m_offset

If the $dep is of type void then m_offset is 0.

Otherwise m_offset is the offset in bytes of the mutable cache member variable in the containing class. The mutable cache member variable has an underscore before and after the declared name of the $dep member variable.

For example for a $dep variable named x the mutable cache member is named _x_.


const octet_t* m_bc

Pointer to an array of octets which is the byte code defining the type of the $dep member variable.


ssize_t m_depNodeOffset

The offset in bytes of the DGDepNode member variable in the containing class. This member has the declared name of the $dep variable.

Example

Consider the following definition of reflected class X:


namespace ns
{
    $struct+ X
    {
        $dep int32 x = f();
    };
}

This is translated into the following code:


namespace ns
{
    struct X;
} //ns
namespace ceda
{
    template<> struct TypeTraits<ns::X>
    {
        static const bool is_exported = 1;
        static const bool is_reflected = 1;
        static const bool is_registered = 1;
        static const ceda::ETypeTraitKind kind = ceda::TTK_struct;
        static const bool has_metadata = 0;
    };
    template<> struct ClassTypeTraits<ns::X>
    {
        static const bool has_reflected_default_ctor = 1;
        static const bool has_reflected_dtor = 1;
        static const bool has_reflected_copy_ctor = 1;
        static const bool has_reflected_equality = 0;
        static const bool has_reflected_compare = 0;
        static const bool has_reflected_write_xostream = 0;
        static const bool has_reflected_serialise = 0;
        static const bool has_reflected_visit_IObjects = 0;
        static const bool has_reflected_visit_Prefs = 0;
        static const bool implements_IObject = 0;
        static const bool implements_IPersistable = 0;
        static const bool can_serialise_model = 0;
        static const bool has_model = 0;
        static const bool using_model_base_class = 0;
    };
} // namespace ceda
namespace ns
{
    struct X
    {
        void x_calc(ceda::int32& x) const
        {
            x = f();
        }
        mutable ceda::int32 _x_;
        struct Depnode_x : ceda::DGDepNode
        {
            typedef ceda::int32 value_type;
            Depnode_x() : ceda::DGDepNode(true) {}
            virtual ceda::xstring Name() const { return "X::x"; }
            virtual void VisitContainingObject(ceda::IObjectVisitor& _v) const
            {
                X const* _self = CONST_ATTRIB_CAST(X,x);
                _v << _self->_x_;
            }
            virtual bool RecalcCache() const
            {
                X const* _self = CONST_ATTRIB_CAST(X,x);
                value_type _prev = _self->_x_;
                _self->x_calc(_self->_x_);
                return _prev != _self->_x_;
            }
            virtual bool IsEvictable() const
            {
                X const* _self = CONST_ATTRIB_CAST(X,x);
                return ceda::CacheValueIsEvictable(_self->_x_);
            }
            virtual void OnEvict() const
            {
                X const* _self = CONST_ATTRIB_CAST(X,x);
                ceda::OnEvictCacheValue(_self->_x_);
            }
            value_type read() const { return CONST_ATTRIB_CAST(X,x)->Getx(); }
            operator value_type() const { return CONST_ATTRIB_CAST(X,x)->Getx(); }
        } x;
        ceda::int32 Getx() const { x.ReadBarrier(); return _x_; }
    public:
        void EvictDgsNodes() const
        {
            x.AlwaysEvict();
        }
        friend ceda::ReflectedClass const& _GetReflected(X const*);
    };
    ceda::ReflectedClass const& _GetReflected(X const*);
    ceda::TypeOps const& _GetTypeOps(X const*);
}

and the following code to register a ReflectedClass for X:


//### $struct+ ns::X
namespace ceda { XTarget* Ceda_Core_Object_exObject_GetXTarget(); }
namespace ns
{
    ceda::ReflectedClass const& _GetReflected(X const*)
    {
        static const ceda::octet_t X_x[] =
        {
            0x04
        };
        static const ceda::ReflectedDepField X_depfields[] =
        {
            { "x", offsetof(X,_x_), X_x, offsetof(X,x) },
        };
        static const ceda::ReflectedClass X_class =
        {
            0,
            "ns::X",
            sizeof(X),
            0,
            0,0,
            0,0,
            X_depfields,1,
            0,0,
            0,
            0,0,0,
            0,
            0,
            {
                sizeof(X),
                0,
                0,
                0,
                (ceda::ConstructArrayFn) (void (*)( X*, ceda::ssize_t, ceda::ssize_t)) ceda::ConstructArray<X>,
                (ceda::CopyConstructArrayFn) (void (*)(X*, ceda::ssize_t, X const*, ceda::ssize_t, ceda::ssize_t)) ceda::CopyConstructArray<X>,
                (ceda::AssignArrayFn) (void (*)(X*, ceda::ssize_t, X const*, ceda::ssize_t, ceda::ssize_t)) ceda::AssignArray<X>,
                (ceda::DestructArrayFn) (void (*)( X*, ceda::ssize_t, ceda::ssize_t)) ceda::DestructArray<X>,
                0,
                0,
                0,
                0,
                0,
                0
            }
        };
        return X_class;
    }
    ceda::TypeOps const& _GetTypeOps(X const*)
    {
        return ceda::GetReflectedClass<X>().m_ops;
    }

    // Registration of $struct+ ns::X
    void _Register_X()
    {
        cxVerify(ceda::RegisterReflectedClass(&_GetReflected( (X*) 0),ceda::Ceda_Core_Object_exObject_GetXTarget()) == ceda::NSE_OK);
    }
} // ns