如何获取指针类型而不是未知的

时间:2019-01-15 21:36:41

标签: c++

我目前正在尝试为我的宠物项目游戏引擎编写一个序列化器/反序列化器。经过一番思考,我决定使用CPP-Reflection库进行类型自省https://github.com/AustinBrunkhorst/CPP-Reflection 调用SomeField.GetType(),其中SomeField的声明类似于 SomeType * SomeField返回一个UNKNOWN类型。如何获得指针类型?

class CameraComponent : public SceneComponent
{
DVWCLASS
public:
    CameraComponent();
    ~CameraComponent();

    virtual void OnCreate() override;
    virtual void OnUpdate() override;
    void SetActive();
    void SetCameraFOV(float HalfFOV);
    void SetAspectRatio(float AR);
    Camera* Cam;
private:
    CameraProxy* CamProxy;
} Meta(Enable);



class Camera
{
public:
    //Empty constructor
    Camera();
    //Empty destructor
    ~Camera();
    //Creates a camera with given position, forward and up vectors
    void Set(const glm::vec3& Position, const glm::vec3& Forward, const     glm::vec3& Up);
    //Sets cameras viewport
    void SetViewport(const Viewport& CameraViewport);
    glm::mat4x4 GetProjectionViewMatrix();
    //Updates ProjectionView matrix
    void Update();
    void SetPosition(const glm::vec3& NewPosition);
    void MoveForward(const float& Distance);
    void MoveUp(const float& Distance);
    void MoveRight(const float& Distance);
    void Rotate(const Rotator& Rotation);//не доделано?
    void RotateYaw(const float& Angle);  //Rotate around Up vector
    void RotatePitch(const float& Angle); //Rotate around Right vector
    void RotateRoll(const float& Angle); //Rotate around Forward vector
    void SetTransform(Transform& Transform);
    //Gets
    glm::vec3 get_forward();
    glm::vec3 get_up();
    glm::vec3 get_right();
    glm::mat4x4 get_ProjectionViewMatrix();
    Transform get_CameraTransform();
    Viewport get_CameraViewport();
    glm::vec3 get_position();

    void SetFOV(float HalfFOV);
    void SetAspectRatio(float Ratio);
    void SetClosePlane(float Distance);
    void SetFarPlane(float Distance, bool bInfinite);

//private:

    glm::vec3 Forward = ForwardVec;
    glm::vec3 Up = UpVec;
    glm::vec3 Right = RightVec;
    glm::mat4x4 ProjectionViewMatrix;
    Transform CameraTransform;
    Viewport CameraViewport;
private:
    constexpr static glm::vec3 ForwardVec = glm::vec3(0, 0, 1);
    constexpr static glm::vec3 UpVec = glm::vec3(0, 1, 0);
    constexpr static glm::vec3 RightVec = glm::vec3(1, 0, 0);

} Meta(Enable);



//CoreObject.cpp
    for (Field ClassField : Fields)
    {
        Type FieldType = ClassField.GetType();

        std::cout <<"Type of field " << ClassField.GetName() << " is "     << FieldType.GetName() << std::endl;
        //Check if it is a pointer
        if (FieldType.IsPointer())
        {
            Type DecayedType = FieldType.GetDecayedType();
            if (DecayedType.IsClass())
            {
                //If type is a pointer to DVWObject
                if (DecayedType.DerivesFrom(typeof(DVWObject)))
                {
                    //Store its name
                    Ar.Ar[ClassField.GetName()] = 
                            ClassField.GetValue(*this).GetValue<DVWObject*>()->Name.GetString();
                }

            }
    }

1 个答案:

答案 0 :(得分:0)

问题解决了。在查看了源代码之后,我发现位于MetaProperties.h中的EnablePtrType属性。将其添加到Meta(...)宏并从Object类继承可以生成指针类型