Expand with intList
parent
6239881746
commit
11ab035380
|
|
@ -28,6 +28,7 @@
|
|||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iterator> // std::ostream_iterator
|
||||
//#include <cstdint> // on Linux GCC: fails with error regarding needing C++0x std flags
|
||||
//#include <cinttypes> // same failure as above
|
||||
|
|
@ -314,6 +315,25 @@ vector<Class> Class::expandTemplate(Str templateArg,
|
|||
return result;
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
vector<Class> Class::expandTemplate(Str templateArg,
|
||||
const vector<int>& integers) const {
|
||||
vector<Class> result;
|
||||
BOOST_FOREACH(int i, integers) {
|
||||
Qualified expandedClass = (Qualified) (*this);
|
||||
stringstream ss; ss << i;
|
||||
string instName = ss.str();
|
||||
expandedClass.expand(instName);
|
||||
const TemplateSubstitution ts(templateArg, instName, expandedClass);
|
||||
Class inst = expandTemplate(ts);
|
||||
inst.name_ = expandedClass.name();
|
||||
inst.templateArgs.clear();
|
||||
inst.typedefName = qualifiedName("::") + "<" + instName + ">";
|
||||
result.push_back(inst);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
void Class::addMethod(bool verbose, bool is_const, Str methodName,
|
||||
const ArgumentList& argumentList, const ReturnValue& returnValue,
|
||||
|
|
|
|||
|
|
@ -106,6 +106,10 @@ public:
|
|||
std::vector<Class> expandTemplate(Str templateArg,
|
||||
const std::vector<Qualified>& instantiations) const;
|
||||
|
||||
// Create new classes with integer template arguments
|
||||
std::vector<Class> expandTemplate(Str templateArg,
|
||||
const std::vector<int>& integers) const;
|
||||
|
||||
/// Add potentially overloaded, potentially templated method
|
||||
void addMethod(bool verbose, bool is_const, Str methodName,
|
||||
const ArgumentList& argumentList, const ReturnValue& returnValue,
|
||||
|
|
|
|||
|
|
@ -221,6 +221,29 @@ TEST( Class, TemplateSubstition ) {
|
|||
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
TEST( Class, TemplateSubstitionIntList ) {
|
||||
|
||||
using classic::space_p;
|
||||
|
||||
// Create type grammar that will place result in cls
|
||||
Class cls;
|
||||
Template t;
|
||||
ClassGrammar g(cls, t);
|
||||
|
||||
string markup(string("template<N = {3,4}>"
|
||||
"class Point2 {"
|
||||
" void myMethod(Matrix A) const;"
|
||||
"};"));
|
||||
|
||||
EXPECT(parse(markup.c_str(), g, space_p).full);
|
||||
|
||||
vector<Class> classes = cls.expandTemplate(t.argName(), t.intList());
|
||||
|
||||
// check the number of new classes is 2
|
||||
EXPECT_LONGS_EQUAL(2, classes.size());
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
TEST(Class, Template) {
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue