本文整理汇总了C++中String::AppendWithFormat方法的典型用法代码示例。如果您正苦于以下问题:C++ String::AppendWithFormat方法的具体用法?C++ String::AppendWithFormat怎么用?C++ String::AppendWithFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类String
的用法示例。
在下文中一共展示了String::AppendWithFormat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GenerateStringXML
bool AndroidProjectGenerator::GenerateStringXML()
{
FileSystem* fs = GetSubsystem<FileSystem>();
ToolSystem* toolSystem = GetSubsystem<ToolSystem>();
Project* project = toolSystem->GetProject();
AndroidBuildSettings* settings = project->GetBuildSettings()->GetAndroidBuildSettings();
String appName = settings->GetAppName();
if (!appName.Length())
{
errorText_ = "Invalid App Name";
return false;
}
String strings = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
strings += "<resources>\n";
strings.AppendWithFormat("<string name=\"app_name\">%s</string>\n", appName.CString());
strings += "</resources>\n";
// Create res/values if it doesn't exist
if (!fs->DirExists(buildPath_ + "/res/values"))
{
fs->CreateDirsRecursive(buildPath_ + "/res/values");
}
// Check that we successfully created it
if (!fs->DirExists(buildPath_ + "/res/values"))
{
errorText_ = "Unable to create directory: " + buildPath_ + "/res/values";
return false;
}
File file(context_, buildPath_ + "/res/values/strings.xml", FILE_WRITE);
if (!file.IsOpen())
{
errorText_ = "Unable to write: " + buildPath_ + "/res/values/strings.xml";
return false;
}
file.Write(strings.CString(), strings.Length());
return true;
}
示例2: GenerateActivitySource
bool AndroidProjectGenerator::GenerateActivitySource()
{
ToolSystem* toolSystem = GetSubsystem<ToolSystem>();
Project* project = toolSystem->GetProject();
AndroidBuildSettings* settings = project->GetBuildSettings()->GetAndroidBuildSettings();
String packageName = settings->GetPackageName();
if (!packageName.Length())
{
errorText_ = "Invalid Package Name";
return false;
}
Vector<String> elements = settings->GetPackageName().Split('.');
String path;
path.Join(elements, "/");
path = buildPath_ + "/src/" + path;
Poco::File dirs(path.CString());
dirs.createDirectories();
if (!dirs.exists())
{
errorText_ = "Unable to create ";
return false;
}
String source;
source.AppendWithFormat("package %s;\n", packageName.CString());
source += "import org.libsdl.app.SDLActivity;\n";
source += "public class AtomicGameEngine extends SDLActivity {\n";
source += "}\n";
File file(context_, path + "/AtomicGameEngine.java", FILE_WRITE);
if (!file.IsOpen())
return false;
file.Write(source.CString(), source.Length());
return true;
}
示例3: RequestServerActivation
void LicenseSystem::RequestServerActivation(const String& key)
{
if (serverActivation_.NotNull())
{
ATOMIC_LOGERROR("UIActivation::RequestServerActivation - request already exists");
return;
}
key_ = key;
CurlManager* cm = GetSubsystem<CurlManager>();
String post;
String id = GenerateMachineID();
post.AppendWithFormat("key=%s&id=%s", key.CString(), id.CString());
// todo, this should be a verify url (shouldn't auto add id)
serverActivation_ = cm->MakeRequest("https://store.atomicgameengine.com/licenses/license_activate.php", post);
SubscribeToEvent(serverActivation_, E_CURLCOMPLETE, ATOMIC_HANDLER(LicenseSystem, HandleActivationResult));
}
示例4: WriteClassDefine
void JSBModule::WriteClassDefine(String& source)
{
source += "static void jsb_init_classes(JSVM* vm)\n{\n";
for (unsigned i = 0; i < classes_.Size(); i++)
{
JSBClass* klass = classes_.At(i);
if (klass->isNumberArray())
continue;
source.AppendWithFormat(" jsb_class_define_%s(vm);\n", klass->GetName().CString());
}
source += "\n}\n\n";
}
示例5: RequestServerVerification
void LicenseSystem::RequestServerVerification(const String& key)
{
if (serverVerification_.NotNull())
{
LOGERROR("LicenseSystem::RequestServerLicense - request already exists");
return;
}
key_ = key;
CurlManager* cm = GetSubsystem<CurlManager>();
String post;
String id = GenerateMachineID();
post.AppendWithFormat("key=%s&id=%s", key.CString(), id.CString());
serverVerification_ = cm->MakeRequest("https://store.atomicgameengine.com/licenses/license_verify.php", post);
SubscribeToEvent(serverVerification_, E_CURLCOMPLETE, HANDLER(LicenseSystem, HandleVerification));
}
示例6: WriteClassDefine
void JSBModuleWriter::WriteClassDefine(String& source)
{
Vector<SharedPtr<JSBClass>> classes = module_->classes_.Values();
source += "static void jsb_init_classes(JSVM* vm)\n{\n";
for (unsigned i = 0; i < classes.Size(); i++)
{
JSBClass* klass = classes.At(i);
if (klass->IsNumberArray())
continue;
source.AppendWithFormat(" jsb_class_define_%s(vm);\n", klass->GetName().CString());
}
source += "\n}\n\n";
}
示例7: MessageCallback
void Script::MessageCallback(const asSMessageInfo* msg)
{
String message;
message.AppendWithFormat("%s:%d,%d %s", msg->section, msg->row, msg->col, msg->message);
switch (msg->type)
{
case asMSGTYPE_ERROR:
LOGERROR(message);
break;
case asMSGTYPE_WARNING:
LOGWARNING(message);
break;
default:
LOGINFO(message);
break;
}
}
示例8: UpdateIssues
void IssuesWidget::UpdateIssues()
{
AEJavascript* aejs = GetSubsystem<AEJavascript>();
const Vector<JSError>& errors = aejs->GetJSErrors();
issueList_->DeleteAllItems();
for (unsigned i = 0; i < errors.Size(); i++)
{
const JSError& error = errors[i];
String errorString;
String filename = GetFileNameAndExtension(error.fullpath);
errorString.AppendWithFormat("%s - %s - Line: %i Column: %i",
filename.CString(), error.message.CString(), error.line, error.column);
issueList_->AddItem(errorString.CString(), NULL, TBID(i));
}
}
示例9:
void ResourceOps::HandleCreate2DLevel(const String& resourcePath, const String& resourceName,
bool navigateToResource, bool reportError)
{
Editor* editor = GetSubsystem<Editor>();
if (!CheckCreate2DLevel(resourcePath, resourceName, reportError))
return;
ResourceCache* cache = GetSubsystem<ResourceCache>();
SharedPtr<File> srcFile = cache->GetFile("ClockworkEditor/templates/template_empty.tmx");
if (srcFile.Null() || !srcFile->IsOpen())
{
editor->PostModalError("Create Script Error", "Could not open module template");
return;
}
String fullpath = resourcePath + resourceName;
if (!resourceName.EndsWith(".tmx"))
fullpath += ".tmx";
if (!CopyFile(srcFile, fullpath))
{
String errorMsg;
errorMsg.AppendWithFormat("Error copying template:\n\n%s\n\nto:\n\n%s",
"ClockworkEditor/template_empty.tmx", fullpath.CString());
editor->PostModalError("Create 2D Level Error", errorMsg);
return;
}
if (navigateToResource)
{
//ResourceFrame* rframe = GetSubsystem<MainFrame>()->GetResourceFrame();
//rframe->EditResource(fullpath);
}
GetSubsystem<MainFrame>()->GetProjectFrame()->Refresh();
}
示例10: GenerateSource
void JSClassWriter::GenerateSource(String& sourceOut)
{
String source = "";
if (klass_->IsNumberArray())
return;
WriteFunctions(source);
String packageName = klass_->GetModule()->GetPackage()->GetName();
source.AppendWithFormat("static void jsb_class_define_%s(JSVM* vm)\n{\n", klass_->GetName().CString());
source.Append("duk_context* ctx = vm->GetJSContext();\n");
GenerateStaticFunctionsSource(source, packageName);
GenerateNonStaticFunctionsSource(source, packageName);
source.Append("}\n");
sourceOut += source;
}
示例11: WriteModulePreInit
void JSModuleWriter::WriteModulePreInit(String& source)
{
source.AppendWithFormat("\nvoid jsb_package_%s_preinit_%s (JSVM* vm)\n{\n\njsb_declare_classes(vm);\n",
module_->package_->GetName().ToLower().CString(), module_->GetName().ToLower().CString());
// register enums and constants
source += "// enums and constants\n";
source += "duk_context* ctx = vm->GetJSContext();\n";
source.AppendWithFormat("duk_get_global_string(ctx, \"%s\");\n", module_->package_->GetName().CString());
source += "// enums\n";
Vector<SharedPtr<JSBEnum>> enums = module_->enums_.Values();
for (unsigned i = 0; i < enums.Size(); i++)
{
JSBEnum* jenum = enums[i];
HashMap<String, String>& values = jenum->GetValues();
HashMap<String, String>::ConstIterator itr = values.Begin();
while (itr != values.End())
{
String name = (*itr).first_;
source.AppendWithFormat("duk_push_number(ctx, (double) %s);\n", name.CString());
source.AppendWithFormat("duk_put_prop_string(ctx, -2, \"%s\");\n",name.CString());
itr++;
}
}
source += "// constants\n";
Vector<String> constants = module_->constants_.Keys();
for (unsigned i = 0; i < constants.Size(); i++)
{
source.AppendWithFormat("duk_push_number(ctx, (double) %s);\n", constants.At(i).CString());
source.AppendWithFormat("duk_put_prop_string(ctx, -2, \"%s\");\n", constants.At(i).CString());
}
source += "duk_pop(ctx);\n";
source += "// end enums and constants\n";
source += "\n}\n";
}
示例12: RequestServerVerification
void LicenseSystem::RequestServerVerification(const String& key)
{
if (serverVerification_.NotNull())
{
ATOMIC_LOGERROR("LicenseSystem::RequestServerLicense - request already exists");
return;
}
FileSystem* fileSystem = GetSubsystem<FileSystem>();
if (fileSystem->FileExists(licenseCachePath_))
{
Time* time = GetSubsystem<Time>();
unsigned currentTime = time->GetTimeSinceEpoch();
unsigned fileTime = fileSystem->GetLastModifiedTime(licenseCachePath_);
unsigned deltaMinutes = (currentTime - fileTime)/60;
if (deltaMinutes < 1)
{
ATOMIC_LOGINFOF("%u minutes, using cached license", deltaMinutes);
SendEvent(E_LICENSE_SUCCESS);
return;
}
}
ATOMIC_LOGINFO("LicenseSystem::RequestServerLicense - requesting verification");
key_ = key;
CurlManager* cm = GetSubsystem<CurlManager>();
String post;
String id = GenerateMachineID();
post.AppendWithFormat("key=%s&id=%s", key.CString(), id.CString());
serverVerification_ = cm->MakeRequest("https://store.atomicgameengine.com/licenses/license_verify.php", post);
SubscribeToEvent(serverVerification_, E_CURLCOMPLETE, ATOMIC_HANDLER(LicenseSystem, HandleVerification));
}
示例13: UpdatePanel
void SceneHudPanel::UpdatePanel(float frametime, const SharedPtr<Urho3D::UIElement> &widget)
{
if (!limiter_.ShouldUpdate(frametime))
return;
Text *sceneText = dynamic_cast<Text*>(widget.Get());
if (!sceneText || !framework_->Renderer())
return;
Scene *scene = framework_->Renderer()->MainCameraScene();
if (!scene)
return;
String str;
SceneInfo info;
auto entities = scene->Entities();
info.ents = entities.Size();
for(auto entIter = entities.Begin(); entIter != entities.End(); ++entIter)
{
const EntityPtr ent = entIter->second_;
if (ent->Parent())
info.entsParented++;
else
info.entsRoot++;
if (ent->IsLocal())
info.entsLocal++;
if (ent->IsReplicated())
info.entsReplicated++;
if (ent->IsTemporary())
info.entsTemporary++;
String group = ent->Group().Trimmed();
if (!group.Empty())
{
info.entGroups[group]++;
InsertAlpha(info.groups, group);
if ((int)group.Length() > info.pad)
info.pad = group.Length() + 2;
}
auto components = ent->Components();
info.comps += components.Size();
for(auto compIter = components.Begin(); compIter != components.End(); ++compIter)
{
auto comp = compIter->second_;
String type = comp->TypeName();
info.compTypes[type]++;
InsertAlpha(info.types, type);
if (comp->IsLocal())
info.compsLocal++;
if (comp->IsReplicated())
info.compsReplicated++;
if (comp->IsTemporary())
info.compsTemporary++;
if ((int)type.Length() > info.pad)
info.pad = type.Length() + 2;
}
if (components.Empty())
info.entsEmpty++;
}
str.AppendWithFormat("%s %u\n", PadString("Entities", info.pad).CString(), info.ents);
str.AppendWithFormat(" %s %u\n", PadString("Root", info.pad).CString(), info.entsRoot);
str.AppendWithFormat(" %s %u\n", PadString("Parented", info.pad).CString(), info.entsParented);
str.AppendWithFormat(" %s %u\n", PadString("Empty", info.pad).CString(), info.entsEmpty);
str.AppendWithFormat(" %s %u\n", PadString("Replicated", info.pad).CString(), info.entsReplicated);
str.AppendWithFormat(" %s %u\n", PadString("Local", info.pad).CString(), info.entsLocal);
str.AppendWithFormat(" %s %u\n\n", PadString("Temporary", info.pad).CString(), info.entsTemporary);
if (!info.groups.Empty())
{
str.AppendWithFormat("%s %u\n", PadString("Entity Groups", info.pad).CString(), info.groups.Size());
foreach(auto &group, info.groups)
{
uint num = info.entGroups[group];
str.AppendWithFormat(" %s %u\n", PadString(group, info.pad).CString(), num);
}
str.Append("\n");
}
示例14: GenerateSource
void JSPackageWriter::GenerateSource()
{
String source = "// This file was autogenerated by JSBind, changes will be lost\n\n";
String defineGuard = package_->GetPlatformDefineGuard();
if (defineGuard.Length())
{
source += ToString("%s\n\n", defineGuard.CString());
}
source += "#include <Duktape/duktape.h>\n";
source += "#include <AtomicJS/Javascript/JSVM.h>\n";
source += "#include <AtomicJS/Javascript/JSAPI.h>\n";
source += "\n\nnamespace Atomic\n{\n";
String packageLower = package_->GetName().ToLower();
for (unsigned i = 0; i < package_->modules_.Size(); i++)
{
JSBModule* module = package_->modules_.At(i);
if (module->GetDotNetModule())
continue;
String moduleGuard = module->GetModuleDefineGuard();
if (moduleGuard.Length())
{
source += ToString("\n%s\n", moduleGuard.CString());
}
String moduleLower = module->GetName().ToLower();
source.AppendWithFormat("\nextern void jsb_package_%s_preinit_%s (JSVM* vm);", packageLower.CString(), moduleLower.CString());
source.AppendWithFormat("\nextern void jsb_package_%s_init_%s (JSVM* vm);", packageLower.CString(), moduleLower.CString());
if (moduleGuard.Length())
{
source += ToString("\n#endif\n", moduleGuard.CString());
}
}
source += "\n\nstatic void jsb_modules_setup_prototypes(JSVM* vm)\n{\n";
source += " // It is important that these are in order so the prototypes are created properly\n";
source += " // This isn't trivial as modules can have dependencies, so do it here\n\n";
WriteProtoTypeSetup(source);
source += "\n}\n";
source.AppendWithFormat("\n\nstatic void jsb_package_%s_preinit(JSVM* vm)\n{", packageLower.CString());
source.Append("\n // Create the global package object\n");
source.Append(" duk_context* ctx = vm->GetJSContext();\n");
source.Append(" duk_push_object(ctx);\n");
source.AppendWithFormat(" duk_put_global_string(ctx, \"%s\");\n", package_->GetName().CString());
for (unsigned i = 0; i < package_->modules_.Size(); i++)
{
JSBModule* module = package_->modules_.At(i);
if (module->GetDotNetModule())
continue;
String moduleGuard = module->GetModuleDefineGuard();
if (moduleGuard.Length())
{
source += ToString("\n%s\n", moduleGuard.CString());
}
if (module->Requires("3D"))
source += "\n#ifdef ATOMIC_3D";
String moduleLower = module->GetName().ToLower();
source.AppendWithFormat("\n jsb_package_%s_preinit_%s(vm);", packageLower.CString(), moduleLower.CString());
if (module->Requires("3D"))
source += "\n#endif //ATOMIC_3D\n";
if (moduleGuard.Length())
{
source += ToString("\n#endif\n", moduleGuard.CString());
}
}
source += "\n}\n\n";
source.AppendWithFormat("\n\nvoid jsb_package_%s_init(JSVM* vm)\n{", packageLower.CString());
source.AppendWithFormat("\n\n jsb_package_%s_preinit(vm);\n", packageLower.CString());
source += "\n\n jsb_modules_setup_prototypes(vm);\n";
//.........这里部分代码省略.........
示例15: WriteConstructor
void JSFunctionWriter::WriteConstructor(String& source)
{
// TODO: refactor this
if (function_->name_ == "RefCounted")
{
source.Append("// finalizer may be called more than once\n" \
"static int jsb_finalizer_RefCounted(duk_context *ctx)\n" \
"{\n" \
"JSVM* vm = JSVM::GetJSVM(ctx);\n" \
\
"duk_get_prop_index(ctx, 0, JS_INSTANCE_INDEX_FINALIZED);\n" \
\
"if (!duk_is_boolean(ctx, -1))\n" \
"{\n" \
"RefCounted* ref = vm->GetObjectPtr(duk_get_heapptr(ctx, 0));\n" \
"vm->RemoveObject(ref);\n" \
"ref->ReleaseRef();\n" \
"duk_push_boolean(ctx, 1);\n" \
"duk_put_prop_index(ctx, 0, JS_INSTANCE_INDEX_FINALIZED);\n" \
"}\n" \
\
"return 0;\n" \
"}\n");
}
JSBClass* klass = function_->class_;
JSBClass* base = klass->GetBaseClass();
// Constructor
source.AppendWithFormat("duk_ret_t jsb_constructor_%s(duk_context* ctx)\n{\n", klass->GetName().CString());
source.Append( "\nJSVM* vm = JSVM::GetJSVM(ctx);\n" \
"duk_push_this(ctx);\n" \
"void *ptr = duk_get_heapptr(ctx, -1);\n" \
"duk_pop(ctx);\n\n");
source.Append(" if (!vm->GetObjectPtr(ptr, true))\n {\n");
if (!klass->IsAbstract() && !klass->IsNumberArray())
{
String marshal;
WriteParameterMarshal(marshal);
String sparams;
int cparam = 0;
const Vector<JSBFunctionType*>& parameters = function_->GetParameters();
for (unsigned i = 0; i < parameters.Size(); i++, cparam++)
{
JSBFunctionType * ptype = parameters.At(i);
String sarg;
if (ptype->type_->asClassType())
{
JSBClassType* classType = ptype->type_->asClassType();
JSBClass* klass = classType->class_;
if (klass->GetName() == "Context")
{
sarg = "vm->GetContext()";
cparam--;
}
}
if (!sarg.Length())
{
sarg.AppendWithFormat("__arg%i", cparam);
}
sparams += sarg;
if (i + 1 < parameters.Size())
sparams += ", ";
}
source.AppendWithFormat("if (!duk_get_top(ctx) || !duk_is_pointer(ctx, 0))\n"\
"{\n"\
"%s\n"\
"%s* native = new %s(%s);\n" \
"vm->AddObject(ptr, native, INSTANTIATION_JAVASCRIPT);\n"\
"}\n" \
"else if (duk_is_pointer(ctx, 0))\n" \
"{\n" \
"RefCounted* rc = (RefCounted*) duk_get_pointer(ctx, 0);\n" \
"vm->AddObject(ptr, rc, rc->GetInstantiationType());\n" \
"}\n", marshal.CString(), klass->GetNativeName().CString(), klass->GetNativeName().CString(), sparams.CString());
}
else
{
if (klass->IsAbstract())
source.Append("assert(0); // abstract class new'd\n");
if (klass->IsNumberArray())
//.........这里部分代码省略.........