本文整理汇总了C++中Preferences::getData方法的典型用法代码示例。如果您正苦于以下问题:C++ Preferences::getData方法的具体用法?C++ Preferences::getData怎么用?C++ Preferences::getData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Preferences
的用法示例。
在下文中一共展示了Preferences::getData方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char ** argv) {
int argIndex;
char * identifier = "preferences_testharness";
Preferences * preferences;
char defaultData1[] = {0x00, 0x01, 0x02, 0x03, 0x04};
char defaultData2[] = {0xFE, 0xED, 0xFA, 0xCE};
void * data;
size_t length, byteIndex;
int action = ACTION_NONE;
for (argIndex = 0; argIndex < argc; argIndex++) {
if (!strcmp(argv[argIndex], "--help")) {
printUsage();
return EXIT_SUCCESS;
}
if (!strcmp(argv[argIndex], "-i")) {
if (argc < argIndex + 2) {
printUsage();
return EXIT_FAILURE;
}
identifier = argv[++argIndex];
} else if (!strcmp(argv[argIndex], "-a")) {
if (argc < argIndex + 2) {
printUsage();
return EXIT_FAILURE;
}
if (!strcmp(argv[argIndex + 1], "set")) {
action = ACTION_SET;
} else if (!strcmp(argv[argIndex + 1], "defaults")) {
action = ACTION_DEFAULTS;
} else {
printUsage();
return EXIT_FAILURE;
}
argIndex++;
}
}
preferences = Preferences_create(identifier);
preferences->addInteger(preferences, "integer1", 1);
preferences->addInteger(preferences, "integer2", -2);
preferences->addFloat(preferences, "float1", 4.0f);
preferences->addFloat(preferences, "float2", -0.125f);
preferences->addBoolean(preferences, "boolean1", true);
preferences->addBoolean(preferences, "boolean2", false);
preferences->addString(preferences, "string1", "Hello, world!");
preferences->addString(preferences, "string2", "foo");
preferences->addData(preferences, "data1", defaultData1, sizeof(defaultData1));
preferences->addData(preferences, "data2", defaultData2, sizeof(defaultData2));
preferences->load(preferences);
printf("integer1: %d\n", preferences->getInteger(preferences, "integer1"));
printf("integer2: %d\n", preferences->getInteger(preferences, "integer2"));
printf("float1: %f\n", preferences->getFloat(preferences, "float1"));
printf("float2: %f\n", preferences->getFloat(preferences, "float2"));
printf("boolean1: %s\n", preferences->getBoolean(preferences, "boolean1") ? "true" : "false");
printf("boolean2: %s\n", preferences->getBoolean(preferences, "boolean2") ? "true" : "false");
printf("string1: %s\n", preferences->getString(preferences, "string1"));
printf("string2: %s\n", preferences->getString(preferences, "string2"));
printf("data1:");
data = preferences->getData(preferences, "data1", &length);
for (byteIndex = 0; byteIndex < length; byteIndex++) {
printf(" %02X", ((unsigned char *) data)[byteIndex]);
}
putchar('\n');
printf("data2:");
data = preferences->getData(preferences, "data2", &length);
for (byteIndex = 0; byteIndex < length; byteIndex++) {
printf(" %02X", ((unsigned char *) data)[byteIndex]);
}
putchar('\n');
if (action == ACTION_SET) {
char data1[] = {0xFF, 0x7F, 0x00};
char data2[] = {0xAA, 0xBB};
preferences->setInteger(preferences, "integer1", -50);
preferences->setInteger(preferences, "integer2", 123);
preferences->setFloat(preferences, "float1", -1.0f);
preferences->setFloat(preferences, "float2", 2.25f);
preferences->setBoolean(preferences, "boolean1", false);
preferences->setBoolean(preferences, "boolean2", true);
preferences->setString(preferences, "string1", "bar");
preferences->setString(preferences, "string2", "baz");
preferences->setData(preferences, "data1", data1, sizeof(data1));
preferences->setData(preferences, "data2", data2, sizeof(data2));
preferences->save(preferences);
} else if (action == ACTION_DEFAULTS) {
preferences->loadDefaultValues(preferences);
preferences->save(preferences);
}
preferences->dispose(preferences);
//.........这里部分代码省略.........