Skip to content

Commit 8f7f84f

Browse files
spywogangatppaul-davies-autodesk
authored
Use specific class type instead of BaseClassName in ParameterCache template generation (#232)
* Use specific class type instead of BaseClassName in ParameterCache template generation The buildOutCacheTemplateParameters function was incorrectly using BaseClassName (e.g., "Base") for ALL class output parameters when building the ParameterCache template type. This meant that methods like GeolocationList::GetAt that return specific types like IGeolocation* were being cached as IBase* instead. When a method signature expects IGeolocation*& (reference to IGeolocation pointer) but the cache uses IBase* in its template, the compiler error occurs because: IBase*& and IGeolocation*& are incompatible types References to pointers cannot be implicitly converted, even with inheritance * Update Examples/RTTI/RTTI_component/Examples/Cpp/RTTI_example.cpp Co-authored-by: Paul Davies <[email protected]> --------- Co-authored-by: gangatp <[email protected]> Co-authored-by: Paul Davies <[email protected]>
1 parent 77282f4 commit 8f7f84f

File tree

3 files changed

+87
-1
lines changed

3 files changed

+87
-1
lines changed

Examples/RTTI/RTTI_component/Examples/Cpp/RTTI_example.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,48 @@ int main()
9999

100100
animal = iter->GetNextAnimal();
101101
assert(animal == nullptr);
102+
103+
// Test GetNextOptionalAnimal - class out parameter with bool return
104+
std::cout << std::endl;
105+
std::cout << "Testing GetNextOptionalAnimal:" << std::endl;
106+
auto iter2 = zoo->Iterator();
107+
PAnimal optionalAnimal;
108+
bool hasError;
109+
110+
hasError = iter2->GetNextOptinalAnimal(optionalAnimal);
111+
assert(hasError == true);
112+
assert(optionalAnimal != nullptr);
113+
std::cout << " Got animal: " << optionalAnimal->Name() << std::endl;
114+
assert(std::dynamic_pointer_cast<CGiraffe>(optionalAnimal) != nullptr);
115+
116+
hasError = iter2->GetNextOptinalAnimal(optionalAnimal);
117+
assert(hasError == true);
118+
assert(optionalAnimal != nullptr);
119+
std::cout << " Got animal: " << optionalAnimal->Name() << std::endl;
120+
assert(std::dynamic_pointer_cast<CTiger>(optionalAnimal) != nullptr);
121+
122+
std::cout << "✓ GetNextOptinalAnimal test passed" << std::endl;
123+
124+
// Test GetNextMandatoryAnimal - class out parameter with bool return
125+
std::cout << std::endl;
126+
std::cout << "Testing GetNextMandatoryAnimal:" << std::endl;
127+
auto iter3 = zoo->Iterator();
128+
PAnimal mandatoryAnimal;
129+
130+
hasError = iter3->GetNextMandatoryAnimal(mandatoryAnimal);
131+
assert(hasError == true);
132+
assert(mandatoryAnimal != nullptr);
133+
std::cout << " Got animal: " << mandatoryAnimal->Name() << std::endl;
134+
assert(std::dynamic_pointer_cast<CGiraffe>(mandatoryAnimal) != nullptr);
135+
136+
hasError = iter3->GetNextMandatoryAnimal(mandatoryAnimal);
137+
assert(hasError == true);
138+
assert(mandatoryAnimal != nullptr);
139+
std::cout << " Got animal: " << mandatoryAnimal->Name() << std::endl;
140+
assert(std::dynamic_pointer_cast<CTiger>(mandatoryAnimal) != nullptr);
141+
142+
std::cout << "✓ GetNextMandatoryAnimal test passed" << std::endl;
143+
std::cout << std::endl;
102144
}
103145
catch (std::exception &e)
104146
{

Examples/RTTI/RTTI_component/Examples/CppDynamic/RTTI_example.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,50 @@ int main()
112112
assert(animal == nullptr);
113113

114114
std::cout << "Trace 1" << std::endl;
115+
116+
// Test GetNextOptionalAnimal - class out parameter with bool return
117+
std::cout << std::endl;
118+
std::cout << "Testing GetNextOptinalAnimal:" << std::endl;
119+
auto iter2 = zoo->Iterator();
120+
PAnimal optionalAnimal;
121+
bool hasError;
122+
123+
hasError = iter2->GetNextOptinalAnimal(optionalAnimal);
124+
assert(hasError == true);
125+
assert(optionalAnimal != nullptr);
126+
std::cout << " Got animal: " << optionalAnimal->Name() << std::endl;
127+
assert(std::dynamic_pointer_cast<CGiraffe>(optionalAnimal) != nullptr);
128+
129+
hasError = iter2->GetNextOptinalAnimal(optionalAnimal);
130+
assert(hasError == true);
131+
assert(optionalAnimal != nullptr);
132+
std::cout << " Got animal: " << optionalAnimal->Name() << std::endl;
133+
assert(std::dynamic_pointer_cast<CTiger>(optionalAnimal) != nullptr);
134+
135+
std::cout << "✓ GetNextOptinalAnimal test passed" << std::endl;
136+
137+
// Test GetNextMandatoryAnimal - class out parameter with bool return
138+
std::cout << std::endl;
139+
std::cout << "Testing GetNextMandatoryAnimal:" << std::endl;
140+
auto iter3 = zoo->Iterator();
141+
PAnimal mandatoryAnimal;
142+
143+
hasError = iter3->GetNextMandatoryAnimal(mandatoryAnimal);
144+
assert(hasError == true);
145+
assert(mandatoryAnimal != nullptr);
146+
std::cout << " Got animal: " << mandatoryAnimal->Name() << std::endl;
147+
assert(std::dynamic_pointer_cast<CGiraffe>(mandatoryAnimal) != nullptr);
148+
149+
hasError = iter3->GetNextMandatoryAnimal(mandatoryAnimal);
150+
assert(hasError == true);
151+
assert(mandatoryAnimal != nullptr);
152+
std::cout << " Got animal: " << mandatoryAnimal->Name() << std::endl;
153+
assert(std::dynamic_pointer_cast<CTiger>(mandatoryAnimal) != nullptr);
154+
155+
std::cout << "✓ GetNextMandatoryAnimal test passed" << std::endl;
156+
157+
std::cout << std::endl;
158+
std::cout << "Trace 2" << std::endl;
115159
}
116160
catch (std::exception &e)
117161
{

Source/buildimplementationcpp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ func buildOutCacheTemplateParameters (method ComponentDefinitionMethod, NameSpac
973973

974974
cppParamType := getCppParamType(param, NameSpace, true);
975975
if param.ParamType == "class" || param.ParamType == "optionalclass" {
976-
cppParamType = fmt.Sprintf("I%s%s*", ClassIdentifier, BaseClassName)
976+
cppParamType = fmt.Sprintf("I%s%s*", ClassIdentifier, param.ParamClass)
977977
}
978978
result += cppParamType;
979979
}

0 commit comments

Comments
 (0)