in tools/code-generation/generator/src/main/java/com/amazonaws/util/awsclientgenerator/domainmodels/codegeneration/cpp/CppViewHelper.java [325:389]
public static Set<String> computeHeaderIncludes(String projectName, Shape shape) {
Set<String> headers = new LinkedHashSet<>();
Set<String> visited = new LinkedHashSet<>();
Queue<Shape> toVisit = shape.getMembers().values().stream().map(ShapeMember::getShape).collect(Collectors.toCollection(() -> new LinkedList<>()));
boolean includeUtilityHeader = false;
boolean includeMemoryHeader = false;
while(!toVisit.isEmpty()) {
Shape next = toVisit.remove();
visited.add(next.getName());
if(next.isMap()) {
if(!visited.contains(next.getMapKey().getShape().getName())) {
toVisit.add(next.getMapKey().getShape());
}
if(!visited.contains(next.getMapValue().getShape().getName())) {
toVisit.add(next.getMapValue().getShape());
}
}
if(next.isList())
{
Shape shapeInList = next.getListMember().getShape();
if(!visited.contains(shapeInList.getName())) {
toVisit.add(shapeInList);
}
if (!shapeInList.isPrimitive() && shapeInList.isMutuallyReferencedWith(shape)) {
// C++ requires both forward declaration AND include in the case of mutual reference
// and if compile-time member object info required
headers.add(formatModelIncludeName(projectName, shapeInList));
}
}
if(!next.isPrimitive()) {
if (next.isException() && !next.isModeledException()) {
// C++ SDK code generator skips generating exceptions that can be expressed using
// a purely built-in C++ SDK Core exception class, so they must not be included.
continue;
}
// if `next` is a direct member of a `shape` and they are mutually referenced
if(next.isMutuallyReferencedWith(shape) &&
shape.getMembers().values().parallelStream().anyMatch(member -> member.getShape().getName().equals(next.getName()))) {
// Historically in this SDK, a single mutually referenced member is included as a shared_ptr,
// forward declaration and include shared_ptr header in the model header file is enough
includeMemoryHeader = true;
} else if (!shape.getName().equals(next.getName())) {
// non-ptr and non-ref objects require object info at compile time (so header is required)
// forward declaration may be required OR not depending on the mutual reference
headers.add(formatModelIncludeName(projectName, next));
}
includeUtilityHeader = true;
}
}
if(shape.isEvent() && shape.getName().endsWith("InitialResponse")) {
headers.add("<aws/core/http/HttpTypes.h>");
}
if(includeMemoryHeader) {
// Aws::MakeShared and std::shared_ptr
headers.add("<aws/core/utils/memory/stl/AWSAllocator.h>");
}
if(includeUtilityHeader) {
headers.add("<utility>");
}
headers.addAll(shape.getMembers().values().stream().filter(member -> member.isIdempotencyToken()).map(member -> "<aws/core/utils/UUID.h>").collect(Collectors.toList()));
return headers;
}