ReflectionByteCode

A ReflectionByteCode consists of three pointers into read-only memory, typically static initialised memory. No ownership semantic is implied, so the ReflectionByteCode destructor does nothing, and coping a ReflectionByteCode only involves copying the pointers so it is relatively cheap. To the extent that the underlying reflection information is recorded in static initialised memory, it is reasonable to regard a ReflectionByteCode as a value type.


$struct+ ReflectionByteCode
{
    ReflectionByteCode();

    ReflectionByteCode(const ReflectedInterface& r);
    ReflectionByteCode(const ReflectedClass& r);
    ReflectionByteCode(const ReflectedVariant& r);
    ReflectionByteCode(const ReflectedGlobalFunction& r);
    ReflectionByteCode(const ReflectedGlobalVariable& r);
    ReflectionByteCode(const ReflectedTypedef& r);
    ReflectionByteCode(const ReflectedEnum& r);
    ReflectionByteCode(const ReflectedFunctor& r);

    ReflectionByteCode(const octet_t* bc, ConstStringZ const* stringTable, const PtrMapOrSetFns* mapOrSetFns = nullptr);
    ReflectionByteCode(const ReflectedModelField& f, ConstStringZ const* stringTable);

    // Can be used for simple byte codes such a FT_VOID, FT_BOOL, FT_INT32 etc.
    static ReflectionByteCode MakeLeaf(octet_t bc);

    $ReflectionByteCode Clone();

    /////////////////////////////////////////// Methods ///////////////////////////////////////////

    template<typename T>
    void ReadValue(T& value);

    void ReadValue(xstring& value);

    $bool IsNull() const;

    $uint8 ReadType();
    $uint8 ReadByte();
    $bool ReadBool();
    $int16 ReadInt16();
    $int32 ReadInt32();
    $float64 ReadFloat64();
    $ConstStringZ ReadString();

    ReflectionByteCode& operator++();          // Prefix
    octet_t operator*() const;

    $ReflectionByteCode& increment();

    $void ScanPastBool();
    $void ScanPastInt16();
    $void ScanPastInt32();
    $void ScanPastString();
    $void ScanPastFloat64();

    // Returns nullptr if class not registered
    $const ReflectedInterface* GetReflectedInterface() const;
    $const ReflectedClass* GetReflectedClass() const;
    $const ReflectedVariant* GetReflectedVariant() const;
    $const ReflectedTypedef* GetReflectedTypedef() const;
    $const ReflectedEnum* GetReflectedEnum() const;
    $const ReflectedFunctor* GetReflectedFunctor() const;

    // Scan past one item of metadata
    $void ScanMetaDataItem();

    // Scan past the type
    $void ScanType();

    // Advance past all the metadata, const, volatile qualifiers and through the typedefs.
    $void AdvanceToUnderlyingType();

    // Advance past all the metadata, const, volatile qualifiers and through the typedefs.
    // Returns bit values as per EByteCodeQualifier.
    $uint32 AdvanceToUnderlyingType2();

    // Get the type after scanning past all the metadata, const, volatile qualifiers and through
    // the typedefs.
    $uint8 GetUnderlyingType() const;

    // Get the underlying type as well as the bit values as per EByteCodeQualifier
    QualifiedByteCode GetQualifiedUnderlyingType() const;

    // Does this type represent a POD (Plain Old Data)?
    $bool IsPOD() const;

    // Does this type have a const qualifier?
    $bool IsConst() const;

    // Retrieve the size of the type, if necessary scanning past initial meta data.
    $ssize_t GetTypeSize() const;

    // Retrieve the size of the type assuming AdvanceToUnderlyingType() has already been called
    $ssize_t GetTypeSizeOnUnderlyingType() const;

    void swap(ReflectionByteCode& rhs);
};