Errors converting existing C++ file to be blueprints callable

11 hours ago 2
ARTICLE AD BOX

I'd previously written a .cpp file called OSMParser.cpp intended to parse the contents of OSM XML files into a list of nodes and a list of ways - two OSMTypes defined as structs in a file called OSMTypes.h

These files, along with OSMParser.h were refactored by a team member of mine to be blueprints callable, but in this refactor many errors arose, which I was hoping to find assistance for.

#include "OSM/OSMParser.h" #include "C:\Program Files\Epic Games\UE_5.7\Engine\Source\ThirdParty\TinyXML2/tinyxml2.h" #include "OSM/OSMTypes.h" using namespace tinyxml2; UOSMParser:UOSMParser() {}; // Reads the doc static bool LoadDocument(const FString& FilePath, XMLDocument& Doc, FString& OutError) { const FTCHARToUTF8 Utf8Path(*FilePath); const XMLError Result = Doc.LoadFile(Utf8Path.Get()); if (Result != XML_SUCCESS) { OutError = FString::Printf(TEXT("Failed to load OSM file: %s"), *FilePath); return false; } XMLElement* OsmRoot = Doc.FirstChildElement("osm"); if (!OsmRoot) { OutError = TEXT("XML file does not contain an <osm> root element."); return false; } return true; } // Parse the nodes static void ReadNodes(XMLElement* OsmRoot, TMap<int64, FOSMNode>& OutNodes) { OutNodes.Empty(); for (XMLElement* NodeElem = OsmRoot->FirstChildElement("node"); NodeElem != nullptr; NodeElem = NodeElem->NextSiblingElement("node")) { const XMLAttribute* IdAttr = NodeElem->FindAttribute("id"); const XMLAttribute* LatAttr = NodeElem->FindAttribute("lat"); const XMLAttribute* LonAttr = NodeElem->FindAttribute("lon"); if (!IdAttr || !LatAttr || !LonAttr) { continue; } FOSMNode Node; Node.Id = IdAttr->Int64Value(); Node.Latitude = LatAttr->DoubleValue(); Node.Longitude = LonAttr->DoubleValue(); OutNodes.Add(Node.Id, Node); } } // Parse the ways static void ReadWays(XMLElement* OsmRoot, TArray<FOSMWay>& OutWays) { OutWays.Empty(); for (XMLElement* WayElem = OsmRoot->FirstChildElement("way"); WayElem != nullptr; WayElem = WayElem->NextSiblingElement("way")) { const XMLAttribute* IdAttr = WayElem->FindAttribute("id"); if (!IdAttr) { continue; } FOSMWay Way; Way.Id = IdAttr->Int64Value(); // Read node references in order for (XMLElement* NdElem = WayElem->FirstChildElement("nd"); NdElem != nullptr; NdElem = NdElem->NextSiblingElement("nd")) { const XMLAttribute* RefAttr = NdElem->FindAttribute("ref"); if (RefAttr) { Way.NodeIds.Add(RefAttr->Int64Value()); } } // Read tags for (XMLElement* TagElem = WayElem->FirstChildElement("tag"); TagElem != nullptr; TagElem = TagElem->NextSiblingElement("tag")) { const XMLAttribute* KAttr = TagElem->FindAttribute("k"); const XMLAttribute* VAttr = TagElem->FindAttribute("v"); if (KAttr && VAttr) { Way.Tags.Add( UTF8_TO_TCHAR(KAttr->Value()), UTF8_TO_TCHAR(VAttr->Value()) ); } } OutWays.Add(MoveTemp(Way)); } } // Essentially the launcher bool UOSMParser::ParseOSMFile( const FString& FilePath, TMap<int64, FOSMNode>& OutNodes, TArray<FOSMWay>& OutWays, FString& OutError) { OutNodes.Empty(); OutWays.Empty(); OutError.Empty(); XMLDocument Doc; if (!LoadDocument(FilePath, Doc, OutError)) { return false; } XMLElement* OsmRoot = Doc.FirstChildElement("osm"); if (!OsmRoot) { OutError = TEXT("Missing <osm> root element."); return false; } ReadNodes(OsmRoot, OutNodes); ReadWays(OsmRoot, OutWays); return true; }

With primary errors pertaining to UOSMParser - at the top UOSMParser:UOSMParser "this declaration has no storage class or type identifier" and then at bool OSMParser::UOSMParser "Incomplete type UOSMParser not allowed"

The other recurring error is every instance of int64 and Fstring "not a type name"

The corresponding .h file below has issues "expected ;" in the class declaration and "type is not supported by blueprints for the TArray and TMap in the UFunction

#pragma once #include "CoreMinimal.h" #include "Kismet/BlueprintFunctionLibrary.h" #include "OSMTypes.h" #include "OSMParser.generated.h" /** * Parses raw OpenStreetMap XML into raw OSM node/way structures. * Doesn't do projection or feature extraction. */ UCLASS() class GEOTWIN_API UOSMParser : public UBlueprintFunctionLibrary { GENERATED_BODY() public: /** * Parse an .osm XML file into raw OSM nodes and ways. * * @param FilePath Path to the .osm file * @param OutNodes Parsed OSM nodes indexed by node ID * @param OutWays Parsed OSM ways * @param OutError Error message if fail * @return True if succeeds */ UFUNCTION(BlueprintCallable, Category = "GeoTwin|OSM") static bool ParseOSMFile( const FString& FilePath, TMap<int64, FOSMNode>& OutNodes, TArray<FOSMWay>& OutWays, FString& OutError);

Any help would be greatly appreciated, if anyone believes OSMTypes.h may be relevant to any of these issues then I can edit to include it

Read Entire Article