So that I don’t know how to do, since this is a PHP extension, so I’m not using the C++ lib in the usual way.
Anyway I’m using something like this:
template <typename T>
class AsposeObjectWrapper
{
protected:
System::SharedPtr<T> _asposeObj;
public:
AsposeObjectWrapper(System::SharedPtr<T> asposeObj) : _asposeObj(asposeObj) {};
virtual ~AsposeObjectWrapper() {
_asposeObj.reset();
};
void __construct(Php::Parameters ¶ms) {};
template <typename AsposeType, typename AsposePhpType, auto Method, class ...Args>
AsposePhpType * wrapObject(Args &&... args)
{
System::SharedPtr<AsposeType> obj = (*_asposeObj.*Method)(args...);
AsposePhpType * phpValue = new AsposePhpType(obj);
return phpValue;
}
};
This class creates classes in our namespace. Each class holds an instance of an Apsose class, so we can use it internally and export some results to PHP. The template method above instantiates a custom class using an Aspose class instance as input.
So for example Aspose::Slides::Charts::Chart class is wrapped by AsposePhp::Chart class which is instantiated using the above template class.
And this is how I call the above method:
Php::Value DoubleChartValue::get_AsCell() {
return Php::Object("ChartDataCell", wrapObject<IChartDataCell, AsposePhp::ChartDataCell, &IDoubleChartValue::get_AsCell>());
}
What this returns is an instance of AsposePhp::ChartDataCell class whose _asposeObj member points to an instance of Aspose::Charts::IChartDataCell instance.
I use this approach everywhere and it works, from Presentation to Slides, all across the board. But for some reason, the XValue() and YValue() calls don’t work.
get_YValue()->get_AsCell() returns a ChartDataCell object, but calling the get_Value() on that doesn’t work because in that case this->_asposeObj is null (even though it should be System::Object).
Anyway I know this is not a reproducible example, but please let me know if you see anything wrong here. I’m new to C++, so probably I’m doing something wrong.