Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not support shared_ptr #352

Open
doudouodong opened this issue Mar 7, 2023 · 1 comment
Open

not support shared_ptr #352

doudouodong opened this issue Mar 7, 2023 · 1 comment

Comments

@doudouodong
Copy link

#ifndef PSDLAYER_H_
#define PSDLAYER_H_

#include "rttr/registration"

class PSDLayer
{
public:
PSDLayer();
virtual ~PSDLayer();

public:
int left;
int top;
int right;
int bottom;

RTTR_ENABLE()

};
#endif //PSDLAYER_H_

#include "core/psdlayer.h"

PSDLayer::PSDLayer():left(0),top(0),right(0),bottom(0){}

PSDLayer::~PSDLayer(){}

RTTR_REGISTRATION
{
rttr::registration::class_("PSDLayer")
.property("left", &PSDLayer::left)
.property("top", &PSDLayer::top)
.property("right", &PSDLayer::right)
.property("bottom", &PSDLayer::bottom)
;
}

#ifndef PSDTYPELAYER_H_
#define PSDTYPELAYER_H_

#include
#include "core/psdlayer.h"

class PSDTypeLayer : public PSDLayer
{
public:
PSDTypeLayer();
~PSDTypeLayer();

public:
RTTR_ENABLE(PSDLayer)
public:
std::string vips_text;
};
#endif // PSDTYPELAYER_H_

#include "core/psdtypelayer.h"

PSDTypeLayer::PSDTypeLayer()
{

}

PSDTypeLayer::~PSDTypeLayer()
{

}

RTTR_REGISTRATION
{
rttr::registration::class_("PSDTypeLayer")
.property("vips_text", &PSDTypeLayer::vips_text)
;
}

#ifndef PSDLAYERVECTOR_H_
#define PSDLAYERVECTOR_H_
#include

#include "core/psdlayer.h"

class PSDLayerVector
{
public:
PSDLayerVector();
~PSDLayerVector();

RTTR_ENABLE()

public:
std::vector<std::shared_ptr> layers;
};

#endif //PSDLAYERVECTOR_H_

#include "core/psdlayervector.h"

PSDLayerVector::PSDLayerVector()
{

}

PSDLayerVector::~PSDLayerVector()
{

}

RTTR_REGISTRATION
{
rttr::registration::class_("PSDLayerVector")
.property("layers", &PSDLayerVector::layers)
;
}

int main(int argc, char** argv)
{
PSDLayerVector layers;

auto p1 = std::make_shared<PSDLayer>();
p1->left = 100;
auto p2 = std::make_shared<PSDTypeLayer>();
p2->vips_text = "hello world";
layers.layers.push_back(p1);
layers.layers.push_back(p2);

std::string json_string;
json_string = io::to_json(layers);
std::cout << json_string << std::endl;


PSDLayerVector objlayers;
io::from_json(json_string, objlayers); 
return 0;

}

@btgoodwin
Copy link

I've run into something similar while trying to follow the example rapidjson to/from that you appear to be using here. My library uses JsonGLIB as its target type, and I'm currently testing how to handle registered object members that are shared pointers to other RTTR_ENABLE'd structures. I've found that in order for my variation of the fromjson_recursive function to work, I have to get the properties off the obj.get_type().get_raw_type().get_properties(); rather than obj.get_derived_type().get_properties() (which seems to work fine for value -type object members.

Despite being able to now pull the property list and apparently read and set the various members on this passed in rttr instance, the output structure does not have the created instance set on its member (I.e., target.shared_ptr_member.get() is nullptr.)

Did you ever make headway with this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants