Completed codegen for serialize/deserialize functions
parent
5789c7de83
commit
07407ff763
103
wrap/Class.cpp
103
wrap/Class.cpp
|
@ -111,6 +111,8 @@ void Class::matlab_proxy(const string& toolboxPath, const string& wrapperName,
|
||||||
proxyFile.oss << "\n";
|
proxyFile.oss << "\n";
|
||||||
wrapperFile.oss << "\n";
|
wrapperFile.oss << "\n";
|
||||||
}
|
}
|
||||||
|
if (isSerializable)
|
||||||
|
serialization_fragments(proxyFile, wrapperFile, functionNames);
|
||||||
|
|
||||||
proxyFile.oss << " end\n";
|
proxyFile.oss << " end\n";
|
||||||
proxyFile.oss << "\n";
|
proxyFile.oss << "\n";
|
||||||
|
@ -123,10 +125,8 @@ void Class::matlab_proxy(const string& toolboxPath, const string& wrapperName,
|
||||||
proxyFile.oss << "\n";
|
proxyFile.oss << "\n";
|
||||||
wrapperFile.oss << "\n";
|
wrapperFile.oss << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add serialization if necessary
|
|
||||||
if (isSerializable)
|
if (isSerializable)
|
||||||
serialization_fragments(proxyFile, wrapperFile, functionNames);
|
deserialization_fragments(proxyFile, wrapperFile, functionNames);
|
||||||
|
|
||||||
proxyFile.oss << " end\n";
|
proxyFile.oss << " end\n";
|
||||||
proxyFile.oss << "end\n";
|
proxyFile.oss << "end\n";
|
||||||
|
@ -404,7 +404,7 @@ void Class::comment_fragment(FileWriter& proxyFile) const {
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
||||||
void Class::serialization_fragments(FileWriter& proxyFile,
|
void Class::serialization_fragments(FileWriter& proxyFile,
|
||||||
FileWriter& file, std::vector<std::string>& functionNames) const {
|
FileWriter& wrapperFile, std::vector<std::string>& functionNames) const {
|
||||||
|
|
||||||
//void Point3_string_serialize_17(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
//void Point3_string_serialize_17(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
||||||
//{
|
//{
|
||||||
|
@ -418,8 +418,8 @@ void Class::serialization_fragments(FileWriter& proxyFile,
|
||||||
//}
|
//}
|
||||||
|
|
||||||
int serialize_id = functionNames.size();
|
int serialize_id = functionNames.size();
|
||||||
const string matlabQualName =
|
const string
|
||||||
qualifiedName("."),
|
matlabQualName = qualifiedName("."),
|
||||||
matlabUniqueName = qualifiedName(),
|
matlabUniqueName = qualifiedName(),
|
||||||
cppClassName = qualifiedName("::");
|
cppClassName = qualifiedName("::");
|
||||||
const string wrapFunctionNameSerialize = matlabUniqueName + "_string_serialize_" + boost::lexical_cast<string>(serialize_id);
|
const string wrapFunctionNameSerialize = matlabUniqueName + "_string_serialize_" + boost::lexical_cast<string>(serialize_id);
|
||||||
|
@ -427,28 +427,50 @@ void Class::serialization_fragments(FileWriter& proxyFile,
|
||||||
|
|
||||||
// call
|
// call
|
||||||
//void Point3_string_serialize_17(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
//void Point3_string_serialize_17(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
||||||
file.oss << "void " << wrapFunctionNameSerialize << "(int nargout, mxArray *out[], int nargin, const mxArray *in[])\n";
|
wrapperFile.oss << "void " << wrapFunctionNameSerialize << "(int nargout, mxArray *out[], int nargin, const mxArray *in[])\n";
|
||||||
file.oss << "{\n";
|
wrapperFile.oss << "{\n";
|
||||||
file.oss << " typedef boost::shared_ptr<" << cppClassName << "> Shared;" << endl;
|
wrapperFile.oss << " typedef boost::shared_ptr<" << cppClassName << "> Shared;" << endl;
|
||||||
|
|
||||||
// check arguments - for serialize, no arguments
|
// check arguments - for serialize, no arguments
|
||||||
// example: checkArguments("string_serialize",nargout,nargin-1,0);
|
// example: checkArguments("string_serialize",nargout,nargin-1,0);
|
||||||
file.oss << " checkArguments(\"string_serialize\",nargout,nargin-1,0);\n";
|
wrapperFile.oss << " checkArguments(\"string_serialize\",nargout,nargin-1,0);\n";
|
||||||
|
|
||||||
// get class pointer
|
// get class pointer
|
||||||
// example: Shared obj = unwrap_shared_ptr<Point3>(in[0], "ptr_Point3");
|
// example: Shared obj = unwrap_shared_ptr<Point3>(in[0], "ptr_Point3");
|
||||||
file.oss << " Shared obj = unwrap_shared_ptr<" << cppClassName << ">(in[0], \"ptr_" << matlabUniqueName << "\");" << endl;
|
wrapperFile.oss << " Shared obj = unwrap_shared_ptr<" << cppClassName << ">(in[0], \"ptr_" << matlabUniqueName << "\");" << endl;
|
||||||
|
|
||||||
// Serialization boilerplate
|
// Serialization boilerplate
|
||||||
file.oss << " std::ostringstream out_archive_stream;\n";
|
wrapperFile.oss << " std::ostringstream out_archive_stream;\n";
|
||||||
file.oss << " boost::archive::text_oarchive out_archive(out_archive_stream);\n";
|
wrapperFile.oss << " boost::archive::text_oarchive out_archive(out_archive_stream);\n";
|
||||||
file.oss << " out_archive << *obj;\n";
|
wrapperFile.oss << " out_archive << *obj;\n";
|
||||||
file.oss << " out[0] = wrap< string >(out_archive_stream.str());\n";
|
wrapperFile.oss << " out[0] = wrap< string >(out_archive_stream.str());\n";
|
||||||
|
|
||||||
// finish
|
// finish
|
||||||
file.oss << "}\n";
|
wrapperFile.oss << "}\n";
|
||||||
|
|
||||||
|
// Generate code for matlab function
|
||||||
|
// function varargout string_serialize(this, varargin)
|
||||||
|
// % STRING_SERIALIZE usage: string_serialize() : returns string
|
||||||
|
// % Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html
|
||||||
|
// if length(varargin) == 0
|
||||||
|
// varargout{1} = geometry_wrapper(15, this, varargin{:});
|
||||||
|
// else
|
||||||
|
// error('Arguments do not match any overload of function Point3.string_serialize');
|
||||||
|
// end
|
||||||
|
// end
|
||||||
|
|
||||||
|
proxyFile.oss << " function varargout = string_serialize(this, varargin)\n";
|
||||||
|
proxyFile.oss << " % STRING_SERIALIZE usage: string_serialize() : returns string\n";
|
||||||
|
proxyFile.oss << " % Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html\n";
|
||||||
|
proxyFile.oss << " if length(varargin) == 0\n";
|
||||||
|
proxyFile.oss << " varargout{1} = geometry_wrapper(" << boost::lexical_cast<string>(serialize_id) << ", this, varargin{:});\n";
|
||||||
|
proxyFile.oss << " else\n";
|
||||||
|
proxyFile.oss << " error('Arguments do not match any overload of function " << matlabQualName << ".string_serialize');\n";
|
||||||
|
proxyFile.oss << " end\n";
|
||||||
|
proxyFile.oss << " end\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
void Class::deserialization_fragments(FileWriter& proxyFile, FileWriter& wrapperFile, std::vector<std::string>& functionNames) const {
|
||||||
//void Point3_string_deserialize_18(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
//void Point3_string_deserialize_18(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
||||||
//{
|
//{
|
||||||
// typedef boost::shared_ptr<Point3> Shared;
|
// typedef boost::shared_ptr<Point3> Shared;
|
||||||
|
@ -457,27 +479,52 @@ void Class::serialization_fragments(FileWriter& proxyFile,
|
||||||
// std::istringstream in_archive_stream(serialized);
|
// std::istringstream in_archive_stream(serialized);
|
||||||
// boost::archive::text_iarchive in_archive(in_archive_stream);
|
// boost::archive::text_iarchive in_archive(in_archive_stream);
|
||||||
// Shared output(new Point3());
|
// Shared output(new Point3());
|
||||||
// in_archive >> output;
|
// in_archive >> *output;
|
||||||
// out[0] = wrap_shared_ptr(output,"Point3", false);
|
// out[0] = wrap_shared_ptr(output,"Point3", false);
|
||||||
//}
|
//}
|
||||||
int deserialize_id = functionNames.size();
|
int deserialize_id = functionNames.size();
|
||||||
|
const string
|
||||||
|
matlabQualName = qualifiedName("."),
|
||||||
|
matlabUniqueName = qualifiedName(),
|
||||||
|
cppClassName = qualifiedName("::");
|
||||||
const string wrapFunctionNameDeserialize = matlabUniqueName + "_string_deserialize_" + boost::lexical_cast<string>(deserialize_id);
|
const string wrapFunctionNameDeserialize = matlabUniqueName + "_string_deserialize_" + boost::lexical_cast<string>(deserialize_id);
|
||||||
functionNames.push_back(wrapFunctionNameDeserialize);
|
functionNames.push_back(wrapFunctionNameDeserialize);
|
||||||
|
|
||||||
// call
|
// call
|
||||||
file.oss << "void " << wrapFunctionNameDeserialize << "(int nargout, mxArray *out[], int nargin, const mxArray *in[])\n";
|
wrapperFile.oss << "void " << wrapFunctionNameDeserialize << "(int nargout, mxArray *out[], int nargin, const mxArray *in[])\n";
|
||||||
file.oss << "{\n";
|
wrapperFile.oss << "{\n";
|
||||||
file.oss << " typedef boost::shared_ptr<" << cppClassName << "> Shared;" << endl;
|
wrapperFile.oss << " typedef boost::shared_ptr<" << cppClassName << "> Shared;" << endl;
|
||||||
|
|
||||||
// check arguments - for deserialize, 1 string argument
|
// check arguments - for deserialize, 1 string argument
|
||||||
file.oss << " checkArguments(\"" << matlabUniqueName << ".string_deserialize\",nargout,nargin,1);\n";
|
wrapperFile.oss << " checkArguments(\"" << matlabUniqueName << ".string_deserialize\",nargout,nargin,1);\n";
|
||||||
|
|
||||||
// string argument with deserialization boilerplate
|
// string argument with deserialization boilerplate
|
||||||
file.oss << " string serialized = unwrap< string >(in[0]);\n";
|
wrapperFile.oss << " string serialized = unwrap< string >(in[0]);\n";
|
||||||
file.oss << " std::istringstream in_archive_stream(serialized);\n";
|
wrapperFile.oss << " std::istringstream in_archive_stream(serialized);\n";
|
||||||
file.oss << " boost::archive::text_iarchive in_archive(in_archive_stream);\n";
|
wrapperFile.oss << " boost::archive::text_iarchive in_archive(in_archive_stream);\n";
|
||||||
file.oss << " Shared output(new " << cppClassName << "());\n";
|
wrapperFile.oss << " Shared output(new " << cppClassName << "());\n";
|
||||||
file.oss << " in_archive >> output;\n";
|
wrapperFile.oss << " in_archive >> *output;\n";
|
||||||
file.oss << " out[0] = wrap_shared_ptr(output,\"" << matlabQualName << "\", false);\n";
|
wrapperFile.oss << " out[0] = wrap_shared_ptr(output,\"" << matlabQualName << "\", false);\n";
|
||||||
file.oss << "}\n";
|
wrapperFile.oss << "}\n";
|
||||||
|
|
||||||
|
// Generate matlab function
|
||||||
|
// function varargout = string_deserialize(varargin)
|
||||||
|
// % STRING_DESERIALIZE usage: string_deserialize() : returns Point3
|
||||||
|
// % Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html
|
||||||
|
// if length(varargin) == 0
|
||||||
|
// varargout{1} = geometry_wrapper(18, varargin{:});
|
||||||
|
// else
|
||||||
|
// error('Arguments do not match any overload of function Point3.string_deserialize');
|
||||||
|
// end
|
||||||
|
// end
|
||||||
|
|
||||||
|
proxyFile.oss << " function varargout = string_deserialize(varargin)\n";
|
||||||
|
proxyFile.oss << " % STRING_DESERIALIZE usage: string_deserialize() : returns " << matlabQualName << "\n";
|
||||||
|
proxyFile.oss << " % Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html\n";
|
||||||
|
proxyFile.oss << " if length(varargin) == 0\n";
|
||||||
|
proxyFile.oss << " varargout{1} = geometry_wrapper(" << boost::lexical_cast<string>(deserialize_id) << ", varargin{:});\n";
|
||||||
|
proxyFile.oss << " else\n";
|
||||||
|
proxyFile.oss << " error('Arguments do not match any overload of function " << matlabQualName << ".string_deserialize');\n";
|
||||||
|
proxyFile.oss << " end\n";
|
||||||
|
proxyFile.oss << " end\n\n";
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,8 +66,12 @@ struct Class {
|
||||||
// The typedef line for this class, if this class is a typedef, otherwise returns an empty string.
|
// The typedef line for this class, if this class is a typedef, otherwise returns an empty string.
|
||||||
std::string getTypedef() const;
|
std::string getTypedef() const;
|
||||||
|
|
||||||
|
// Creates a member function that performs serialization
|
||||||
void serialization_fragments(FileWriter& proxyFile, FileWriter& wrapperFile, std::vector<std::string>& functionNames) const;
|
void serialization_fragments(FileWriter& proxyFile, FileWriter& wrapperFile, std::vector<std::string>& functionNames) const;
|
||||||
|
|
||||||
|
// Creates a static member function that performs deserialization
|
||||||
|
void deserialization_fragments(FileWriter& proxyFile, FileWriter& wrapperFile, std::vector<std::string>& functionNames) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void pointer_constructor_fragments(FileWriter& proxyFile, FileWriter& wrapperFile, const std::string& wrapperName, std::vector<std::string>& functionNames) const;
|
void pointer_constructor_fragments(FileWriter& proxyFile, FileWriter& wrapperFile, const std::string& wrapperName, std::vector<std::string>& functionNames) const;
|
||||||
void comment_fragment(FileWriter& proxyFile) const;
|
void comment_fragment(FileWriter& proxyFile) const;
|
||||||
|
|
|
@ -52,11 +52,11 @@ classdef Point3 < handle
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function varargout string_serialize(this, varargin)
|
function varargout = string_serialize(this, varargin)
|
||||||
% string_serialize usage: string_serialize() : returns string
|
% STRING_SERIALIZE usage: string_serialize() : returns string
|
||||||
% Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html
|
% Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html
|
||||||
if length(varargin) == 0
|
if length(varargin) == 0
|
||||||
varargout{1} = geometry_wrapper(14, this, varargin{:});
|
varargout{1} = geometry_wrapper(15, this, varargin{:});
|
||||||
else
|
else
|
||||||
error('Arguments do not match any overload of function Point3.string_serialize');
|
error('Arguments do not match any overload of function Point3.string_serialize');
|
||||||
end
|
end
|
||||||
|
@ -71,7 +71,7 @@ classdef Point3 < handle
|
||||||
% Usage
|
% Usage
|
||||||
% STATICFUNCTIONRET(double z)
|
% STATICFUNCTIONRET(double z)
|
||||||
if length(varargin) == 1 && isa(varargin{1},'double')
|
if length(varargin) == 1 && isa(varargin{1},'double')
|
||||||
varargout{1} = geometry_wrapper(15, varargin{:});
|
varargout{1} = geometry_wrapper(16, varargin{:});
|
||||||
else
|
else
|
||||||
error('Arguments do not match any overload of function Point3.StaticFunctionRet');
|
error('Arguments do not match any overload of function Point3.StaticFunctionRet');
|
||||||
end
|
end
|
||||||
|
@ -84,19 +84,19 @@ classdef Point3 < handle
|
||||||
% Usage
|
% Usage
|
||||||
% STATICFUNCTION()
|
% STATICFUNCTION()
|
||||||
if length(varargin) == 0
|
if length(varargin) == 0
|
||||||
varargout{1} = geometry_wrapper(16, varargin{:});
|
varargout{1} = geometry_wrapper(17, varargin{:});
|
||||||
else
|
else
|
||||||
error('Arguments do not match any overload of function Point3.StaticFunction');
|
error('Arguments do not match any overload of function Point3.StaticFunction');
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function varargout = string_deserialize(varargin)
|
function varargout = string_deserialize(varargin)
|
||||||
% STATICFUNCTION usage: string_deserialize() : returns Point3
|
% STRING_DESERIALIZE usage: string_deserialize() : returns Point3
|
||||||
% Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html
|
% Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html
|
||||||
if length(varargin) == 0
|
if length(varargin) == 0
|
||||||
varargout{1} = geometry_wrapper(16, varargin{:});
|
varargout{1} = geometry_wrapper(18, varargin{:});
|
||||||
else
|
else
|
||||||
error('Arguments do not match any overload of function Point3.StaticFunction');
|
error('Arguments do not match any overload of function Point3.string_deserialize');
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -223,23 +223,7 @@ void Point3_norm_14(int nargout, mxArray *out[], int nargin, const mxArray *in[]
|
||||||
out[0] = wrap< double >(obj->norm());
|
out[0] = wrap< double >(obj->norm());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Point3_StaticFunctionRet_15(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
void Point3_string_serialize_15(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
||||||
{
|
|
||||||
typedef boost::shared_ptr<Point3> SharedPoint3;
|
|
||||||
typedef boost::shared_ptr<Point3> Shared;
|
|
||||||
checkArguments("Point3.StaticFunctionRet",nargout,nargin,1);
|
|
||||||
double z = unwrap< double >(in[0]);
|
|
||||||
out[0] = wrap_shared_ptr(SharedPoint3(new Point3(Point3::StaticFunctionRet(z))),"Point3", false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Point3_staticFunction_16(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
|
||||||
{
|
|
||||||
typedef boost::shared_ptr<Point3> Shared;
|
|
||||||
checkArguments("Point3.staticFunction",nargout,nargin,0);
|
|
||||||
out[0] = wrap< double >(Point3::staticFunction());
|
|
||||||
}
|
|
||||||
|
|
||||||
void Point3_string_serialize_17(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
|
||||||
{
|
{
|
||||||
typedef boost::shared_ptr<Point3> Shared;
|
typedef boost::shared_ptr<Point3> Shared;
|
||||||
checkArguments("string_serialize",nargout,nargin-1,0);
|
checkArguments("string_serialize",nargout,nargin-1,0);
|
||||||
|
@ -250,6 +234,22 @@ void Point3_string_serialize_17(int nargout, mxArray *out[], int nargin, const m
|
||||||
out[0] = wrap< string >(out_archive_stream.str());
|
out[0] = wrap< string >(out_archive_stream.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Point3_StaticFunctionRet_16(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
||||||
|
{
|
||||||
|
typedef boost::shared_ptr<Point3> SharedPoint3;
|
||||||
|
typedef boost::shared_ptr<Point3> Shared;
|
||||||
|
checkArguments("Point3.StaticFunctionRet",nargout,nargin,1);
|
||||||
|
double z = unwrap< double >(in[0]);
|
||||||
|
out[0] = wrap_shared_ptr(SharedPoint3(new Point3(Point3::StaticFunctionRet(z))),"Point3", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Point3_staticFunction_17(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
||||||
|
{
|
||||||
|
typedef boost::shared_ptr<Point3> Shared;
|
||||||
|
checkArguments("Point3.staticFunction",nargout,nargin,0);
|
||||||
|
out[0] = wrap< double >(Point3::staticFunction());
|
||||||
|
}
|
||||||
|
|
||||||
void Point3_string_deserialize_18(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
void Point3_string_deserialize_18(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
||||||
{
|
{
|
||||||
typedef boost::shared_ptr<Point3> Shared;
|
typedef boost::shared_ptr<Point3> Shared;
|
||||||
|
@ -258,7 +258,7 @@ void Point3_string_deserialize_18(int nargout, mxArray *out[], int nargin, const
|
||||||
std::istringstream in_archive_stream(serialized);
|
std::istringstream in_archive_stream(serialized);
|
||||||
boost::archive::text_iarchive in_archive(in_archive_stream);
|
boost::archive::text_iarchive in_archive(in_archive_stream);
|
||||||
Shared output(new Point3());
|
Shared output(new Point3());
|
||||||
in_archive >> output;
|
in_archive >> *output;
|
||||||
out[0] = wrap_shared_ptr(output,"Point3", false);
|
out[0] = wrap_shared_ptr(output,"Point3", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue