Skip to content

Commit

Permalink
[cpp-ue4] Fix generated code not compiling when using unique array it…
Browse files Browse the repository at this point in the history
…ems (#17684)

* Add CollectionToUrlString for TSet

Added a template for converting collection to url string parameters for associative container

* Add generated samples

* Add TSet template

* Fix iterator
  • Loading branch information
roseatromero authored Jan 27, 2024
1 parent aa15ef9 commit d152f4d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,30 @@ inline FString CollectionToUrlString_multi(const TArray<T>& Collection, const TC
return Output;
}


template <typename T>
inline FString CollectionToUrlString_multi(const TSet<T>& Collection, const TCHAR* BaseName)
{
FString Output;
if (Collection.Num() == 0)
{
return Output;
}

int32 Index = 0;
for (typename TSet<T>::TConstIterator Iter = Collection.CreateConstIterator(); Iter; ++Iter)
{
if (Index == 0)
{
Output += FString::Format(TEXT("{0}={1}"), { FStringFormatArg(BaseName), ToUrlString(*Iter) });
Index++;
continue;
}
Output += FString::Format(TEXT("&{0}={1}"), { FStringFormatArg(BaseName), ToUrlString(*Iter) });
}
return Output;
}

//////////////////////////////////////////////////////////////////////////

inline void WriteJsonValue(JsonWriter& Writer, const TSharedPtr<FJsonValue>& Value)
Expand Down
24 changes: 24 additions & 0 deletions samples/client/petstore/cpp-ue4/Public/OpenAPIHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,30 @@ inline FString CollectionToUrlString_multi(const TArray<T>& Collection, const TC
return Output;
}


template <typename T>
inline FString CollectionToUrlString_multi(const TSet<T>& Collection, const TCHAR* BaseName)
{
FString Output;
if (Collection.Num() == 0)
{
return Output;
}

int32 Index = 0;
for (typename TSet<T>::TConstIterator Iter = Collection.CreateConstIterator(); Iter; ++Iter)
{
if (Index == 0)
{
Output += FString::Format(TEXT("{0}={1}"), { FStringFormatArg(BaseName), ToUrlString(*Iter) });
Index++;
continue;
}
Output += FString::Format(TEXT("&{0}={1}"), { FStringFormatArg(BaseName), ToUrlString(*Iter) });
}
return Output;
}

//////////////////////////////////////////////////////////////////////////

inline void WriteJsonValue(JsonWriter& Writer, const TSharedPtr<FJsonValue>& Value)
Expand Down

0 comments on commit d152f4d

Please sign in to comment.