本文整理汇总了C++中TSharedPtr::AsString方法的典型用法代码示例。如果您正苦于以下问题:C++ TSharedPtr::AsString方法的具体用法?C++ TSharedPtr::AsString怎么用?C++ TSharedPtr::AsString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TSharedPtr
的用法示例。
在下文中一共展示了TSharedPtr::AsString方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
MatchmakerModels::Region PlayFab::MatchmakerModels::readRegionFromValue(const TSharedPtr<FJsonValue>& value)
{
static TMap<FString, Region> _RegionMap;
if (_RegionMap.Num() == 0)
{
// Auto-generate the map on the first use
_RegionMap.Add(TEXT("USCentral"), RegionUSCentral);
_RegionMap.Add(TEXT("USEast"), RegionUSEast);
_RegionMap.Add(TEXT("EUWest"), RegionEUWest);
_RegionMap.Add(TEXT("Singapore"), RegionSingapore);
_RegionMap.Add(TEXT("Japan"), RegionJapan);
_RegionMap.Add(TEXT("Brazil"), RegionBrazil);
_RegionMap.Add(TEXT("Australia"), RegionAustralia);
}
if(value.IsValid())
{
auto output = _RegionMap.Find(value->AsString());
if (output != nullptr)
return *output;
}
return RegionUSCentral; // Basically critical fail
}
示例2: GetEngineIdentifierForProject
bool FDesktopPlatformBase::GetEngineIdentifierForProject(const FString& ProjectFileName, FString& OutIdentifier)
{
OutIdentifier.Empty();
// Load the project file
TSharedPtr<FJsonObject> ProjectFile = LoadProjectFile(ProjectFileName);
if(!ProjectFile.IsValid())
{
return false;
}
// Try to read the identifier from it
TSharedPtr<FJsonValue> Value = ProjectFile->TryGetField(TEXT("EngineAssociation"));
if(Value.IsValid() && Value->Type == EJson::String)
{
OutIdentifier = Value->AsString();
if(OutIdentifier.Len() > 0)
{
// If it's a path, convert it into an engine identifier
if(OutIdentifier.Contains(TEXT("/")) || OutIdentifier.Contains("\\"))
{
FString EngineRootDir = FPaths::ConvertRelativePathToFull(FPaths::GetPath(ProjectFileName), OutIdentifier);
if(!GetEngineIdentifierFromRootDir(EngineRootDir, OutIdentifier))
{
return false;
}
}
return true;
}
}
// Otherwise scan up through the directory hierarchy to find an installation
FString ParentDir = FPaths::GetPath(ProjectFileName);
FPaths::NormalizeDirectoryName(ParentDir);
// Keep going until we reach the root
int32 SeparatorIdx;
while(ParentDir.FindLastChar(TEXT('/'), SeparatorIdx))
{
ParentDir.RemoveAt(SeparatorIdx, ParentDir.Len() - SeparatorIdx);
if(IsValidRootDirectory(ParentDir) && GetEngineIdentifierFromRootDir(ParentDir, OutIdentifier))
{
return true;
}
}
// Otherwise check the engine version string for 4.0, in case this project existed before the engine association stuff went in
FString EngineVersionString = ProjectFile->GetStringField(TEXT("EngineVersion"));
if(EngineVersionString.Len() > 0)
{
FEngineVersion EngineVersion;
if(FEngineVersion::Parse(EngineVersionString, EngineVersion) && EngineVersion.HasChangelist() && EngineVersion.ToString(EVersionComponent::Minor) == TEXT("4.0"))
{
OutIdentifier = TEXT("4.0");
return true;
}
}
return false;
}
示例3: SetArrayField
void UVaRestJsonObject::SetArrayField(const FString& FieldName, const TArray<UVaRestJsonValue*>& InArray)
{
if (!JsonObj.IsValid())
{
return;
}
TArray< TSharedPtr<FJsonValue> > ValArray;
// Process input array and COPY original values
for (auto InVal : InArray)
{
TSharedPtr<FJsonValue> JsonVal = InVal->GetRootValue();
switch (InVal->GetType())
{
case EVaJson::None:
break;
case EVaJson::Null:
ValArray.Add(MakeShareable(new FJsonValueNull()));
break;
case EVaJson::String:
ValArray.Add(MakeShareable(new FJsonValueString(JsonVal->AsString())));
break;
case EVaJson::Number:
ValArray.Add(MakeShareable(new FJsonValueNumber(JsonVal->AsNumber())));
break;
case EVaJson::Boolean:
ValArray.Add(MakeShareable(new FJsonValueBoolean(JsonVal->AsBool())));
break;
case EVaJson::Array:
ValArray.Add(MakeShareable(new FJsonValueArray(JsonVal->AsArray())));
break;
case EVaJson::Object:
ValArray.Add(MakeShareable(new FJsonValueObject(JsonVal->AsObject())));
break;
default:
break;
}
}
JsonObj->SetArrayField(FieldName, ValArray);
}
示例4: CopyJsonValueToWriter
void CopyJsonValueToWriter( JsonWriter &Json, const FString& ValueName, const TSharedPtr<FJsonValue>& JsonValue )
{
if ( JsonValue->Type == EJson::String )
{
Json->WriteValue( ValueName, JsonValue->AsString() );
}
else if ( JsonValue->Type == EJson::Array )
{
if (ValueName.IsEmpty())
{
Json->WriteArrayStart();
}
else
{
Json->WriteArrayStart(ValueName);
}
const TArray<TSharedPtr<FJsonValue>>& Array = JsonValue->AsArray();
for ( const auto& ArrayValue : Array )
{
CopyJsonValueToWriter(Json, FString(), ArrayValue);
}
Json->WriteArrayEnd();
}
else if ( JsonValue->Type == EJson::Object )
{
if (ValueName.IsEmpty())
{
Json->WriteObjectStart();
}
else
{
Json->WriteObjectStart(ValueName);
}
const TSharedPtr<FJsonObject>& Object = JsonValue->AsObject();
for ( const auto& ObjectProperty : Object->Values)
{
CopyJsonValueToWriter(Json, ObjectProperty.Key, ObjectProperty.Value );
}
Json->WriteObjectEnd();
}
else
{
UE_LOG(LogChunkManifestGenerator, Warning, TEXT("Unrecognized json value type %d in object %s"), *UEnum::GetValueAsString(TEXT("Json.EJson"), JsonValue->Type), *ValueName)
}
}
示例5: DeserializeFromJSON
// @TODO LSwift: Perhaps replace FromBlob and ToBlob usage with hexadecimal notation instead
bool FBuildPatchAppManifest::DeserializeFromJSON( const FString& JSONInput )
{
bool bSuccess = true;
TSharedPtr<FJsonObject> JSONManifestObject;
TSharedRef<TJsonReader<TCHAR>> Reader = TJsonReaderFactory<TCHAR>::Create(JSONInput);
// Clear current data
DestroyData();
// Attempt to deserialize JSON
if (!FJsonSerializer::Deserialize(Reader, JSONManifestObject) || !JSONManifestObject.IsValid())
{
return false;
}
// Store a list of all data GUID for later use
TSet<FGuid> AllDataGuids;
// Get the values map
TMap<FString, TSharedPtr<FJsonValue>>& JsonValueMap = JSONManifestObject->Values;
// Manifest version did not always exist
int32 ManifestFileVersionInt = 0;
TSharedPtr<FJsonValue> JsonManifestFileVersion = JsonValueMap.FindRef(TEXT("ManifestFileVersion"));
if (JsonManifestFileVersion.IsValid() && FromStringBlob(JsonManifestFileVersion->AsString(), ManifestFileVersionInt))
{
Data->ManifestFileVersion = static_cast<EBuildPatchAppManifestVersion::Type>(ManifestFileVersionInt);
}
else
{
// Then we presume version just before we started outputting the version
Data->ManifestFileVersion = static_cast<EBuildPatchAppManifestVersion::Type>(EBuildPatchAppManifestVersion::StartStoringVersion - 1);
}
// Get the app and version strings
TSharedPtr< FJsonValue > JsonAppID = JsonValueMap.FindRef( TEXT("AppID") );
TSharedPtr< FJsonValue > JsonAppNameString = JsonValueMap.FindRef( TEXT("AppNameString") );
TSharedPtr< FJsonValue > JsonBuildVersionString = JsonValueMap.FindRef( TEXT("BuildVersionString") );
TSharedPtr< FJsonValue > JsonLaunchExe = JsonValueMap.FindRef( TEXT("LaunchExeString") );
TSharedPtr< FJsonValue > JsonLaunchCommand = JsonValueMap.FindRef( TEXT("LaunchCommand") );
TSharedPtr< FJsonValue > JsonPrereqName = JsonValueMap.FindRef( TEXT("PrereqName") );
TSharedPtr< FJsonValue > JsonPrereqPath = JsonValueMap.FindRef( TEXT("PrereqPath") );
TSharedPtr< FJsonValue > JsonPrereqArgs = JsonValueMap.FindRef( TEXT("PrereqArgs") );
bSuccess = bSuccess && JsonAppID.IsValid();
if( bSuccess )
{
bSuccess = bSuccess && FromStringBlob( JsonAppID->AsString(), Data->AppID );
}
bSuccess = bSuccess && JsonAppNameString.IsValid();
if( bSuccess )
{
Data->AppName = JsonAppNameString->AsString();
}
bSuccess = bSuccess && JsonBuildVersionString.IsValid();
if( bSuccess )
{
Data->BuildVersion = JsonBuildVersionString->AsString();
}
bSuccess = bSuccess && JsonLaunchExe.IsValid();
if( bSuccess )
{
Data->LaunchExe = JsonLaunchExe->AsString();
}
bSuccess = bSuccess && JsonLaunchCommand.IsValid();
if( bSuccess )
{
Data->LaunchCommand = JsonLaunchCommand->AsString();
}
// Get the prerequisites installer info. These are optional entries.
Data->PrereqName = JsonPrereqName.IsValid() ? JsonPrereqName->AsString() : FString();
Data->PrereqPath = JsonPrereqPath.IsValid() ? JsonPrereqPath->AsString() : FString();
Data->PrereqArgs = JsonPrereqArgs.IsValid() ? JsonPrereqArgs->AsString() : FString();
// Get the FileManifestList
TSharedPtr<FJsonValue> JsonFileManifestList = JsonValueMap.FindRef(TEXT("FileManifestList"));
bSuccess = bSuccess && JsonFileManifestList.IsValid();
if( bSuccess )
{
TArray<TSharedPtr<FJsonValue>> JsonFileManifestArray = JsonFileManifestList->AsArray();
for (auto JsonFileManifestIt = JsonFileManifestArray.CreateConstIterator(); JsonFileManifestIt && bSuccess; ++JsonFileManifestIt)
{
TSharedPtr<FJsonObject> JsonFileManifest = (*JsonFileManifestIt)->AsObject();
const int32 FileIndex = Data->FileManifestList.Add(FFileManifestData());
FFileManifestData& FileManifest = Data->FileManifestList[FileIndex];
FileManifest.Filename = JsonFileManifest->GetStringField(TEXT("Filename"));
bSuccess = bSuccess && FString::ToBlob(JsonFileManifest->GetStringField(TEXT("FileHash")), FileManifest.FileHash.Hash, FSHA1::DigestSize);
TArray<TSharedPtr<FJsonValue>> JsonChunkPartArray = JsonFileManifest->GetArrayField(TEXT("FileChunkParts"));
for (auto JsonChunkPartIt = JsonChunkPartArray.CreateConstIterator(); JsonChunkPartIt && bSuccess; ++JsonChunkPartIt)
{
const int32 ChunkIndex = FileManifest.FileChunkParts.Add(FChunkPartData());
FChunkPartData& FileChunkPart = FileManifest.FileChunkParts[ChunkIndex];
TSharedPtr<FJsonObject> JsonChunkPart = (*JsonChunkPartIt)->AsObject();
bSuccess = bSuccess && FGuid::Parse(JsonChunkPart->GetStringField(TEXT("Guid")), FileChunkPart.Guid);
bSuccess = bSuccess && FromStringBlob(JsonChunkPart->GetStringField(TEXT("Offset")), FileChunkPart.Offset);
bSuccess = bSuccess && FromStringBlob(JsonChunkPart->GetStringField(TEXT("Size")), FileChunkPart.Size);
AllDataGuids.Add(FileChunkPart.Guid);
}
//.........这里部分代码省略.........
示例6: Read
bool FModuleDescriptor::Read(const FJsonObject& Object, FText& OutFailReason)
{
// Read the module name
TSharedPtr<FJsonValue> NameValue = Object.TryGetField(TEXT("Name"));
if(!NameValue.IsValid() || NameValue->Type != EJson::String)
{
OutFailReason = LOCTEXT("ModuleWithoutAName", "Found a 'Module' entry with a missing 'Name' field");
return false;
}
Name = FName(*NameValue->AsString());
// Read the module type
TSharedPtr<FJsonValue> TypeValue = Object.TryGetField(TEXT("Type"));
if(!TypeValue.IsValid() || TypeValue->Type != EJson::String)
{
OutFailReason = FText::Format( LOCTEXT( "ModuleWithoutAType", "Found Module entry '{0}' with a missing 'Type' field" ), FText::FromName(Name) );
return false;
}
Type = EHostType::FromString(*TypeValue->AsString());
if(Type == EHostType::Max)
{
OutFailReason = FText::Format( LOCTEXT( "ModuleWithInvalidType", "Module entry '{0}' specified an unrecognized module Type '{1}'" ), FText::FromName(Name), FText::FromString(TypeValue->AsString()) );
return false;
}
// Read the loading phase
TSharedPtr<FJsonValue> LoadingPhaseValue = Object.TryGetField(TEXT("LoadingPhase"));
if(LoadingPhaseValue.IsValid() && LoadingPhaseValue->Type == EJson::String)
{
LoadingPhase = ELoadingPhase::FromString(*LoadingPhaseValue->AsString());
if(LoadingPhase == ELoadingPhase::Max)
{
OutFailReason = FText::Format( LOCTEXT( "ModuleWithInvalidLoadingPhase", "Module entry '{0}' specified an unrecognized module LoadingPhase '{1}'" ), FText::FromName(Name), FText::FromString(LoadingPhaseValue->AsString()) );
return false;
}
}
// Read the whitelisted platforms
TSharedPtr<FJsonValue> WhitelistPlatformsValue = Object.TryGetField(TEXT("WhitelistPlatforms"));
if(WhitelistPlatformsValue.IsValid() && WhitelistPlatformsValue->Type == EJson::Array)
{
const TArray< TSharedPtr< FJsonValue > >& PlatformsArray = WhitelistPlatformsValue->AsArray();
for(int Idx = 0; Idx < PlatformsArray.Num(); Idx++)
{
WhitelistPlatforms.Add(PlatformsArray[Idx]->AsString());
}
}
// Read the blacklisted platforms
TSharedPtr<FJsonValue> BlacklistPlatformsValue = Object.TryGetField(TEXT("BlacklistPlatforms"));
if(BlacklistPlatformsValue.IsValid() && BlacklistPlatformsValue->Type == EJson::Array)
{
const TArray< TSharedPtr< FJsonValue > >& PlatformsArray = BlacklistPlatformsValue->AsArray();
for(int Idx = 0; Idx < PlatformsArray.Num(); Idx++)
{
BlacklistPlatforms.Add(PlatformsArray[Idx]->AsString());
}
}
// Read the additional dependencies
TSharedPtr<FJsonValue> AdditionalDependenciesValue = Object.TryGetField(TEXT("AdditionalDependencies"));
if (AdditionalDependenciesValue.IsValid() && AdditionalDependenciesValue->Type == EJson::Array)
{
const TArray< TSharedPtr< FJsonValue > >& DepArray = AdditionalDependenciesValue->AsArray();
for (int Idx = 0; Idx < DepArray.Num(); Idx++)
{
AdditionalDependencies.Add(DepArray[Idx]->AsString());
}
}
return true;
}
示例7: DoExport
//.........这里部分代码省略.........
const FContext& Context = *ContextIter;
// Create the typical PO entry from the archive entry which matches the exact same namespace, source, and key metadata, if it exists.
{
const TSharedPtr<FArchiveEntry> ArchiveEntry = InternationalizationArchive->FindEntryBySource( Namespace, Source, Context.KeyMetadataObj );
if( ArchiveEntry.IsValid() )
{
const FString ConditionedArchiveSource = ConditionArchiveStrForPo(ArchiveEntry->Source.Text);
const FString ConditionedArchiveTranslation = ConditionArchiveStrForPo(ArchiveEntry->Translation.Text);
TSharedRef<FPortableObjectEntry> PoEntry = MakeShareable( new FPortableObjectEntry );
//@TODO: We support additional metadata entries that can be translated. How do those fit in the PO file format? Ex: isMature
PoEntry->MsgId = ConditionedArchiveSource;
PoEntry->MsgCtxt = ConditionIdentityForPOMsgCtxt(Namespace, Context.Key, Context.KeyMetadataObj);
PoEntry->MsgStr.Add( ConditionedArchiveTranslation );
const FString PORefString = ConvertSrcLocationToPORef( Context.SourceLocation );
PoEntry->AddReference(PORefString); // Source location.
PoEntry->AddExtractedComment( GetConditionedKeyForExtractedComment(Context.Key) ); // "Notes from Programmer" in the form of the Key.
if (ShouldAddSourceLocationsAsComments)
{
PoEntry->AddExtractedComment(GetConditionedReferenceForExtractedComment(PORefString)); // "Notes from Programmer" in the form of the Source Location, since this comes in handy too and OneSky doesn't properly show references, only comments.
}
TArray<FString> InfoMetaDataStrings;
if (Context.InfoMetadataObj.IsValid())
{
for (auto InfoMetaDataPair : Context.InfoMetadataObj->Values)
{
const FString KeyName = InfoMetaDataPair.Key;
const TSharedPtr<FLocMetadataValue> Value = InfoMetaDataPair.Value;
InfoMetaDataStrings.Add(GetConditionedInfoMetaDataForExtractedComment(KeyName, Value->AsString()));
}
}
if (InfoMetaDataStrings.Num())
{
PoEntry->AddExtractedComments(InfoMetaDataStrings);
}
NewPortableObject.AddEntry( PoEntry );
}
}
// If we're exporting for something other than the native culture, we'll need to create PO entries for archive entries based on the native archive's translation.
if (CultureName != NativeCultureName)
{
TSharedPtr<FArchiveEntry> NativeArchiveEntry;
// Find the native archive entry which matches the exact same namespace, source, and key metadata, if it exists.
for (const auto& NativeArchive : NativeArchives)
{
const TSharedPtr<FArchiveEntry> PotentialNativeArchiveEntry = NativeArchive->FindEntryBySource( Namespace, Source, Context.KeyMetadataObj );
if (PotentialNativeArchiveEntry.IsValid())
{
NativeArchiveEntry = PotentialNativeArchiveEntry;
break;
}
}
if (NativeArchiveEntry.IsValid())
{
// Only need to create this PO entry if the native archive entry's translation differs from its source, in which case we need to find the our translation of the native translation.
if (!NativeArchiveEntry->Source.IsExactMatch(NativeArchiveEntry->Translation))
{
const TSharedPtr<FArchiveEntry> ArchiveEntry = InternationalizationArchive->FindEntryBySource( Namespace, NativeArchiveEntry->Translation, NativeArchiveEntry->KeyMetadataObj );