#ifndef MRT_MARRAY_H
#define MRT_MARRAY_H
#include "Common/BaseObject.h"
namespace MapleRuntime {
#ifdef POINTER_IS_64BIT
class ATTR_PACKED(8) MArray : public BaseObject {
#else
class ATTR_PACKED(4) MArray : public BaseObject {
#endif
public:
static constexpr MOffset GetContentOffset();
inline static MArray* NewArray(MIndex nElems, TypeInfo& arrayClass,
AllocType allocType = AllocType::MOVEABLE_OBJECT);
inline static MArray* NewRefArray(MIndex nElems, TypeInfo& arrayClass,
AllocType allocType = AllocType::MOVEABLE_OBJECT);
inline static MArray* NewKnownWidthArray(MIndex nElems, TypeInfo& arrayClass, const U32 elemBytes,
AllocType allocType = AllocType::MOVEABLE_OBJECT);
inline MIndex GetLength() const;
inline void SetLength(MIndex number);
inline MIndex GetMArraySize() const;
inline MSize GetElementSize() const;
inline MIndex GetContentSize() const;
inline bool IsPrimitiveArray() const;
template<typename T>
inline T GetPrimitiveElement(MIndex index) const;
template<typename T>
inline void SetPrimitiveElement(MIndex index, T value);
inline ObjectPtr GetRefElement(MIndex index);
inline void SetRefElement(MIndex index, const ObjectPtr mObj);
inline U8* ConvertToCArray() const;
void ForEachRefFieldInRange(const RefFieldVisitor& visitor, MAddress fieldStart, MIndex fieldEnd) const;
private:
MIndex length;
};
}
#endif