From 8ab83a7cffd46849244dbe3c4f7cf39056268064 Mon Sep 17 00:00:00 2001 From: dellaert Date: Tue, 11 Nov 2014 22:55:36 +0100 Subject: [PATCH] Simplified expand --- wrap/Class.cpp | 61 +++++++++++++++++--------------------------------- wrap/Class.h | 8 +++++-- 2 files changed, 27 insertions(+), 42 deletions(-) diff --git a/wrap/Class.cpp b/wrap/Class.cpp index 075c98811..8c95331c5 100644 --- a/wrap/Class.cpp +++ b/wrap/Class.cpp @@ -250,7 +250,7 @@ void Class::pointer_constructor_fragments(FileWriter& proxyFile, vector expandArgumentListsTemplate( const vector& argLists, const string& templateArg, const vector& instName, - const std::vector& expandedClassNamespace, + const vector& expandedClassNamespace, const string& expandedClassName) { vector result; BOOST_FOREACH(const ArgumentList& argList, argLists) { @@ -276,7 +276,7 @@ vector expandArgumentListsTemplate( template map expandMethodTemplate(const map& methods, const string& templateArg, const vector& instName, - const std::vector& expandedClassNamespace, + const vector& expandedClassNamespace, const string& expandedClassName) { map result; typedef pair Name_Method; @@ -312,30 +312,20 @@ map expandMethodTemplate(const map& methods, } /* ************************************************************************* */ -Class expandClassTemplate(const Class& cls, const string& templateArg, +Class Class::expandTemplate(const string& templateArg, const vector& instName, - const std::vector& expandedClassNamespace, - const string& expandedClassName) { - Class inst; - inst.name = cls.name; - inst.templateArgs = cls.templateArgs; - inst.typedefName = cls.typedefName; - inst.isVirtual = cls.isVirtual; - inst.isSerializable = cls.isSerializable; - inst.qualifiedParent = cls.qualifiedParent; - inst.methods = expandMethodTemplate(cls.methods, templateArg, instName, + const vector& expandedClassNamespace, + const string& expandedClassName) const { + Class inst = *this; + inst.methods = expandMethodTemplate(methods, templateArg, instName, expandedClassNamespace, expandedClassName); - inst.static_methods = expandMethodTemplate(cls.static_methods, templateArg, + inst.static_methods = expandMethodTemplate(static_methods, templateArg, instName, expandedClassNamespace, expandedClassName); - inst.namespaces = cls.namespaces; - inst.constructor = cls.constructor; inst.constructor.args_list = expandArgumentListsTemplate( - cls.constructor.args_list, templateArg, instName, expandedClassNamespace, + constructor.args_list, templateArg, instName, expandedClassNamespace, expandedClassName); inst.constructor.name = inst.name; - inst.deconstructor = cls.deconstructor; inst.deconstructor.name = inst.name; - inst.verbose_ = cls.verbose_; return inst; } @@ -345,8 +335,8 @@ vector Class::expandTemplate(const string& templateArg, vector result; BOOST_FOREACH(const vector& instName, instantiations) { const string expandedName = name + instName.back(); - Class inst = expandClassTemplate(*this, templateArg, instName, - this->namespaces, expandedName); + Class inst = expandTemplate(templateArg, instName, namespaces, + expandedName); inst.name = expandedName; inst.templateArgs.clear(); inst.typedefName = qualifiedName("::") + "<" @@ -357,16 +347,7 @@ vector Class::expandTemplate(const string& templateArg, } /* ************************************************************************* */ -Class Class::expandTemplate(const string& templateArg, - const vector& instantiation, - const std::vector& expandedClassNamespace, - const string& expandedClassName) const { - return expandClassTemplate(*this, templateArg, instantiation, - expandedClassNamespace, expandedClassName); -} - -/* ************************************************************************* */ -std::string Class::getTypedef() const { +string Class::getTypedef() const { string result; BOOST_FOREACH(const string& namesp, namespaces) { result += ("namespace " + namesp + " { "); @@ -429,15 +410,15 @@ void Class::comment_fragment(FileWriter& proxyFile) const { /* ************************************************************************* */ void Class::serialization_fragments(FileWriter& proxyFile, - FileWriter& wrapperFile, const std::string& wrapperName, - std::vector& functionNames) const { + FileWriter& wrapperFile, const string& wrapperName, + vector& functionNames) const { //void Point3_string_serialize_17(int nargout, mxArray *out[], int nargin, const mxArray *in[]) //{ // typedef boost::shared_ptr Shared; // checkArguments("string_serialize",nargout,nargin-1,0); // Shared obj = unwrap_shared_ptr(in[0], "ptr_Point3"); -// std::ostringstream out_archive_stream; +// ostringstream out_archive_stream; // boost::archive::text_oarchive out_archive(out_archive_stream); // out_archive << *obj; // out[0] = wrap< string >(out_archive_stream.str()); @@ -469,7 +450,7 @@ void Class::serialization_fragments(FileWriter& proxyFile, << ">(in[0], \"ptr_" << matlabUniqueName << "\");" << endl; // Serialization boilerplate - wrapperFile.oss << " std::ostringstream out_archive_stream;\n"; + wrapperFile.oss << " ostringstream out_archive_stream;\n"; wrapperFile.oss << " boost::archive::text_oarchive out_archive(out_archive_stream);\n"; wrapperFile.oss << " out_archive << *obj;\n"; @@ -520,14 +501,14 @@ void Class::serialization_fragments(FileWriter& proxyFile, /* ************************************************************************* */ void Class::deserialization_fragments(FileWriter& proxyFile, - FileWriter& wrapperFile, const std::string& wrapperName, - std::vector& functionNames) const { + FileWriter& wrapperFile, const string& wrapperName, + vector& functionNames) const { //void Point3_string_deserialize_18(int nargout, mxArray *out[], int nargin, const mxArray *in[]) //{ // typedef boost::shared_ptr Shared; // checkArguments("Point3.string_deserialize",nargout,nargin,1); // string serialized = unwrap< string >(in[0]); - // std::istringstream in_archive_stream(serialized); + // istringstream in_archive_stream(serialized); // boost::archive::text_iarchive in_archive(in_archive_stream); // Shared output(new Point3()); // in_archive >> *output; @@ -553,7 +534,7 @@ void Class::deserialization_fragments(FileWriter& proxyFile, // string argument with deserialization boilerplate wrapperFile.oss << " string serialized = unwrap< string >(in[0]);\n"; - wrapperFile.oss << " std::istringstream in_archive_stream(serialized);\n"; + wrapperFile.oss << " istringstream in_archive_stream(serialized);\n"; wrapperFile.oss << " boost::archive::text_iarchive in_archive(in_archive_stream);\n"; wrapperFile.oss << " Shared output(new " << cppClassName << "());\n"; @@ -604,7 +585,7 @@ void Class::deserialization_fragments(FileWriter& proxyFile, } /* ************************************************************************* */ -std::string Class::getSerializationExport() const { +string Class::getSerializationExport() const { //BOOST_CLASS_EXPORT_GUID(gtsam::SharedDiagonal, "gtsamSharedDiagonal"); return "BOOST_CLASS_EXPORT_GUID(" + qualifiedName("::") + ", \"" + qualifiedName() + "\");"; diff --git a/wrap/Class.h b/wrap/Class.h index 2ca976f66..c3ef09814 100644 --- a/wrap/Class.h +++ b/wrap/Class.h @@ -59,9 +59,13 @@ struct Class { std::string qualifiedName(const std::string& delim = "") const; ///< creates a namespace-qualified name, optional delimiter - std::vector expandTemplate(const std::string& templateArg, const std::vector >& instantiations) const; + Class expandTemplate(const std::string& templateArg, + const std::vector& instantiation, + const std::vector& expandedClassNamespace, + const std::string& expandedClassName) const; - Class expandTemplate(const std::string& templateArg, const std::vector& instantiation, const std::vector& expandedClassNamespace, const std::string& expandedClassName) const; + std::vector expandTemplate(const std::string& templateArg, + const std::vector >& instantiations) const; // The typedef line for this class, if this class is a typedef, otherwise returns an empty string. std::string getTypedef() const;