本文整理汇总了C++中dictionary_new函数的典型用法代码示例。如果您正苦于以下问题:C++ dictionary_new函数的具体用法?C++ dictionary_new怎么用?C++ dictionary_new使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dictionary_new函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: Test_dictionary_unset
void Test_dictionary_unset(CuTest *tc)
{
int i, j;
char sec_name[32];
char key_name[64];
dictionary *dic1;
dictionary *dic2;
char *dic1_dump;
char *dic2_dump;
/* try dummy unsets */
dictionary_unset(NULL, NULL);
dictionary_unset(NULL, key_name);
/* Generate two similar dictionaries */
dic1 = dictionary_new(DICTMINSZ);
CuAssertPtrNotNull(tc, dic1);
for (i = 1 ; i < 10; ++i) {
sprintf(sec_name, "sec%d", i);
dictionary_set(dic1, sec_name, "");
for (j = 1 ; j < 10; ++j) {
sprintf(key_name, "%s:key%d", sec_name, j);
dictionary_set(dic1, key_name, "dummy_value");
}
}
dic2 = dictionary_new(DICTMINSZ);
CuAssertPtrNotNull(tc, dic2);
for (i = 1 ; i < 10; ++i) {
sprintf(sec_name, "sec%d", i);
dictionary_set(dic2, sec_name, "");
for (j = 1 ; j < 10; ++j) {
sprintf(key_name, "%s:key%d", sec_name, j);
dictionary_set(dic2, key_name, "dummy_value");
}
}
/* Make sure the dictionaries are the same */
dic1_dump = get_dump(dic1);
dic2_dump = get_dump(dic2);
CuAssertStrEquals(tc, dic1_dump, dic2_dump);
free(dic1_dump);
free(dic2_dump);
/* Those tests should not change the dictionary */
dictionary_unset(dic2, NULL);
dictionary_unset(dic2, "bad_key");
/* dic1 and dic2 must still be the same */
dic1_dump = get_dump(dic1);
dic2_dump = get_dump(dic2);
CuAssertStrEquals(tc, dic1_dump, dic2_dump);
free(dic1_dump);
free(dic2_dump);
}
开发者ID:DelusionalLogic,项目名称:iniparser,代码行数:54,代码来源:test_dictionary.c
示例2: Test_dictionary_wrapper
void Test_dictionary_wrapper(CuTest *tc)
{
dictionary *dic;
dic = dictionary_new(10);
CuAssertIntEquals(tc, -1, iniparser_set(dic, NULL, NULL));
CuAssertIntEquals(tc, -1, iniparser_set(NULL, "section", "value"));
CuAssertIntEquals(tc, 0, iniparser_set(dic, "section", NULL));
CuAssertIntEquals(tc, 0, iniparser_set(dic, "section:key", "value"));
CuAssertStrEquals(tc, "value", iniparser_getstring(dic, "section:key", NULL));
/* reset the key's value*/
CuAssertIntEquals(tc, 0, iniparser_set(dic, "section:key", NULL));
CuAssertStrEquals(tc, NULL, iniparser_getstring(dic, "section:key", "dummy"));
CuAssertIntEquals(tc, 0, iniparser_set(dic, "section:key", "value"));
CuAssertStrEquals(tc, "value", iniparser_getstring(dic, "section:key", NULL));
iniparser_unset(dic, "section:key");
CuAssertStrEquals(tc, "dummy", iniparser_getstring(dic, "section:key", "dummy"));
CuAssertStrEquals(tc, NULL, iniparser_getstring(dic, "section", "dummy"));
CuAssertIntEquals(tc, 0, iniparser_set(dic, "section:key", NULL));
CuAssertIntEquals(tc, 0, iniparser_set(dic, "section:key1", NULL));
CuAssertIntEquals(tc, 0, iniparser_set(dic, "section:key2", NULL));
iniparser_unset(dic, "section");
CuAssertStrEquals(tc, NULL, iniparser_getstring(dic, "section", NULL));
iniparser_freedict(dic);
}
开发者ID:2ion,项目名称:iniparser,代码行数:32,代码来源:test_iniparser.c
示例3: array_new
void array_new(ArrayValue* myself, char* xml) {
Tag* valueTag;
DictValue* curValue;
myself->values = NULL;
myself->size = 0;
while (*xml != '\0') {
valueTag = getNextTag(&xml);
if (valueTag == NULL) {
break;
}
myself->size++;
myself->values = realloc(myself->values, sizeof(DictValue*)
* myself->size);
curValue = (DictValue*) malloc(sizeof(DictValue));
curValue->key = (char*) malloc(sizeof("arraykey"));
strcpy(curValue->key, "arraykey");
curValue->next = NULL;
if (strcmp(valueTag->name, "dict") == 0) {
curValue->type = DictionaryType;
curValue = (DictValue*) realloc(curValue, sizeof(Dictionary));
dictionary_new((Dictionary*) curValue, valueTag->xml);
} else if (strcmp(valueTag->name, "string") == 0) {
curValue->type = StringType;
curValue = (DictValue*) realloc(curValue, sizeof(StringValue));
((StringValue*)curValue)->value = (char*) malloc(sizeof(char) * (strlen(valueTag->xml) + 1));
strcpy(((StringValue*)curValue)->value, valueTag->xml);
} else if(strcmp(valueTag->name, "data") == 0) {
size_t len;
curValue->type = StringType;
curValue = (DictValue*) realloc(curValue, sizeof(DataValue));
((DataValue*)curValue)->value = decodeBase64(valueTag->xml, &len);
((DataValue*)curValue)->len = len;
} else if(strcmp(valueTag->name, "integer") == 0) {
curValue->type = IntegerType;
curValue = (DictValue*) realloc(curValue, sizeof(IntegerValue));
sscanf(valueTag->xml, "%d", &(((IntegerValue*) curValue)->value));
} else if (strcmp(valueTag->name, "array") == 0) {
curValue->type = ArrayType;
curValue = (DictValue*) realloc(curValue, sizeof(ArrayValue));
array_new((ArrayValue*) curValue, valueTag->xml);
} else if (strcmp(valueTag->name, "true/") == 0) {
curValue->type = BoolType;
curValue = (DictValue*) realloc(curValue, sizeof(BoolValue));
((BoolValue*) curValue)->value = TRUE;
} else if (strcmp(valueTag->name, "false/") == 0) {
curValue->type = BoolType;
curValue = (DictValue*) realloc(curValue, sizeof(BoolValue));
((BoolValue*) curValue)->value = FALSE;
}
myself->values[myself->size - 1] = curValue;
releaseTag(valueTag);
}
}
开发者ID:DJHartley,项目名称:xpwn,代码行数:60,代码来源:plist.c
示例4: camera_control_backup_system_settings
void camera_control_backup_system_settings(CameraControl* cc, const char* file) {
int AutoAEC = 0;
int AutoAGC = 0;
int Gain = 0;
int Exposure = 0;
int Contrast = 0;
int Brightness = 0;
int fd = open_v4l2_device(cc->cameraID);
if (fd != -1) {
AutoAEC = v4l2_get_control(fd, V4L2_CID_EXPOSURE_AUTO);
AutoAGC = v4l2_get_control(fd, V4L2_CID_AUTOGAIN);
Gain = v4l2_get_control(fd, V4L2_CID_GAIN);
Exposure = v4l2_get_control(fd, V4L2_CID_EXPOSURE);
Contrast = v4l2_get_control(fd, V4L2_CID_CONTRAST);
Brightness = v4l2_get_control(fd, V4L2_CID_BRIGHTNESS);
v4l2_close(fd);
dictionary* ini = dictionary_new(0);
iniparser_set(ini, "PSEye", 0);
iniparser_set_int(ini, "PSEye:AutoAEC", AutoAEC);
iniparser_set_int(ini, "PSEye:AutoAGC", AutoAGC);
iniparser_set_int(ini, "PSEye:Gain", Gain);
iniparser_set_int(ini, "PSEye:Exposure", Exposure);
iniparser_set_int(ini, "PSEye:Contrast", Contrast);
iniparser_set_int(ini, "PSEye:Brightness", Brightness);
iniparser_save_ini(ini, file);
dictionary_del(ini);
}
}
开发者ID:kdienes,项目名称:psmoveapi,代码行数:31,代码来源:camera_control_linux.c
示例5: dictionary_hints
/**
Test funckji dictionary_hints().
Wstawienie do słownika 7 słów.
Sprawdzenie, czy funkcja zwraca prawidłowe podpowiedzi.
*/
static void dictionary_hints_test(void** state) {
struct dictionary *dict;
dict = dictionary_new();
struct word_list *l = malloc(sizeof(word_list));
word_list_init(l);
wchar_t *word1 = L"at";
wchar_t *word2 = L"car";
wchar_t *word3 = L"cat";
wchar_t *word4 = L"cats";
wchar_t *word5 = L"cut";
wchar_t *word6 = L"mat";
wchar_t *word7 = L"rat";
dictionary_insert(dict, word1);
dictionary_insert(dict, word2);
dictionary_insert(dict, word3);
dictionary_insert(dict, word4);
dictionary_insert(dict, word5);
dictionary_insert(dict, word6);
dictionary_insert(dict, word7);
dictionary_hints(dict, word3, l);
assert_string_equal(l->next->word, word1);
assert_string_equal(l->next->next->word, word2);
assert_string_equal(l->next->next->next->word, word3);
assert_string_equal(l->next->next->next->next->word, word4);
assert_string_equal(l->next->next->next->next->next->word, word5);
assert_string_equal(l->next->next->next->next->next->next->word, word6);
assert_string_equal(l->next->next->next->next->next->next->next->word, word7);
word_list_done(l);
dictionary_done(dict);
free(l);
}
开发者ID:agaX,项目名称:SpellChecker,代码行数:36,代码来源:dictionary_test.c
示例6: Test_iniparser_getsecname
void Test_iniparser_getsecname(CuTest *tc)
{
unsigned i;
char sec_name[32];
dictionary *dic;
/* NULL test */
CuAssertTrue(tc, iniparser_getsecname(NULL, 0) == NULL);
/* Empty dictionary */
dic = dictionary_new(10);
CuAssertPtrEquals(tc, NULL, iniparser_getsecname(dic, 0));
dictionary_del(dic);
/* Sections without entries dictionary */
dic = generate_dictionary(100, 0);
for (i = 0; i < 100; ++i) {
sprintf(sec_name, "sec%d", i);
CuAssertStrEquals(tc, sec_name, iniparser_getsecname(dic, i));
}
dictionary_del(dic);
/* Generic dictionary */
dic = generate_dictionary(10, 100);
for (i = 0; i < 10; ++i) {
sprintf(sec_name, "sec%d", i);
CuAssertStrEquals(tc, sec_name, iniparser_getsecname(dic, i));
}
dictionary_del(dic);
}
开发者ID:2ion,项目名称:iniparser,代码行数:29,代码来源:test_iniparser.c
示例7: dictionary_save_test
/**
Testuje zapisywanie słownika.
@param state Środowisko testowe.
*/
static void dictionary_save_test(void** state)
{
struct dictionary *dict = dictionary_new();
FILE *stream;
wchar_t *buf = NULL;
size_t len;
stream = open_wmemstream(&buf, &len);
if (stream == NULL)
{
fprintf(stderr, "Failed to open memory stream\n");
exit(EXIT_FAILURE);
}
dictionary_insert(dict, L"ciupaga");
assert_true(dictionary_save(dict, stream) == 0);
fflush(stream);
assert_true(wcscmp(L"ciupaga*^^^^^^^\n0\n", buf) == 0);
fseek(stream, 0, SEEK_SET);
fclose(stream);
# undef free
free(buf);
# define free(ptr) _test_free(ptr, __FILE__, __LINE__)
dictionary_done(dict);
}
开发者ID:mlazowik,项目名称:spellcheck,代码行数:31,代码来源:dictionary_test.c
示例8: dictionary_new
void INI::create()
{
if (this->ini)
this->free();
this->ini = dictionary_new(0);
}
开发者ID:barankaraoguz,项目名称:nSnake,代码行数:7,代码来源:INI.cpp
示例9: scripto_dblclick
void scripto_dblclick(t_scripto *x)
{
if (x->s_patcher)
object_method(x->s_patcher, gensym("vis"));
else {
t_dictionary *d = dictionary_new();
char parsebuf[256];
t_atom a;
long ac = 0;
t_atom *av = NULL;
// create a patcher without scroll bars and a toolbar
sprintf(parsebuf,"@defrect 0 0 300 400 @title scripto @enablehscroll 0 @enablevscroll 0 @presentation 0 @toolbarid \"\"");
atom_setparse(&ac,&av,parsebuf);
attr_args_dictionary(d,ac,av);
atom_setobj(&a,d);
sysmem_freeptr(av);
x->s_patcher = (t_object *)object_new_typed(CLASS_NOBOX,gensym("jpatcher"),1, &a);
freeobject((t_object *)d); // we created this dictionary and we don't need it anymore
object_method(x->s_patcher,gensym("vis"));
x->s_ui = newobject_sprintf(x->s_patcher, "@maxclass scripto_ui @patching_rect 0 0 300 400 @oncolor %.2f %.2f %.2f %.2f @offcolor %.2f %.2f %.2f %.2f",
x->s_oncolor.red, x->s_oncolor.green, x->s_oncolor.blue, x->s_oncolor.alpha, x->s_offcolor.red, x->s_offcolor.green, x->s_offcolor.blue, x->s_offcolor.alpha);
object_attach_byptr_register(x, x->s_ui, CLASS_BOX); // attach our UI object to us
object_attach_byptr_register(x, x->s_patcher, CLASS_NOBOX); // attach our UI object to us
}
}
开发者ID:AlvaroBuitrago,项目名称:max-test,代码行数:27,代码来源:scripto.c
示例10: addChild
static Link addChild(Link self,Link value,Link keys){
Link * args = array_getArray(keys);
size_t argn = array_getLength(keys);
if (argn != 1) return NULL;
string_t key = object_getString(args[0]);
if ( ! key ) return NULL;
Dict dict = self->value.vptr;
if ( ! dict){
dict = self->value.vptr = malloc( sizeof( *dict) );
dict->dictionary = dictionary_new();
dict->mutex = mutex_new();
}
mutex_lock(dict->mutex);
Link old = dictionary_insert(dict->dictionary, key, value );
mutex_unlock(dict->mutex);
if (old) link_free(old);
return value; // return original not duplicate child
}
开发者ID:elechak,项目名称:blue,代码行数:25,代码来源:dict.c
示例11: Test_dictionary_growing
void Test_dictionary_growing(CuTest *tc)
{
int i, j;
char sec_name[32];
char key_name[64];
dictionary *dic;
dic = dictionary_new(DICTMINSZ);
CuAssertPtrNotNull(tc, dic);
CuAssertIntEquals(tc, 0, dic->n);
/* Makes the dictionary grow */
for (i = 1 ; i < 101; ++i) {
sprintf(sec_name, "sec%d", i);
CuAssertIntEquals(tc, 0, dictionary_set(dic, sec_name, ""));
for (j = 1 ; j < 11; ++j) {
sprintf(key_name, "%s:key%d", sec_name, j);
CuAssertIntEquals(tc, 0, dictionary_set(dic, key_name, "dummy_value"));
CuAssertIntEquals(tc, i + (i - 1) * 10 + j, dic->n);
}
}
/* Shrink the dictionary */
for (i = 100 ; i > 0; --i) {
sprintf(sec_name, "sec%d", i);
for (j = 10 ; j > 0; --j) {
sprintf(key_name, "%s:key%d", sec_name, j);
dictionary_unset(dic, key_name);
}
dictionary_unset(dic, sec_name);
CuAssertIntEquals(tc, (i - 1) * (11), dic->n);
}
dictionary_del(dic);
}
开发者ID:DelusionalLogic,项目名称:iniparser,代码行数:35,代码来源:test_dictionary.c
示例12: generate_dictionary
/* Tool function to create and populate a generic non-empty dictionary */
static dictionary * generate_dictionary(unsigned sections, unsigned entries_per_section)
{
unsigned i, j ;
dictionary * dic;
char sec_name[32];
char key_name[64];
char key_value[32];
dic = dictionary_new(sections + sections * entries_per_section);
if (dic == NULL)
return NULL;
/* Insert the sections */
for (i = 0; i < sections; ++i) {
sprintf(sec_name, "sec%d", i);
dictionary_set(dic, sec_name, "");
for (j = 0; j < entries_per_section; ++j) {
/* Populate the section with the entries */
sprintf(key_name, "%s:key%d", sec_name, j);
sprintf(key_value, "value-%d/%d", i, j);
dictionary_set(dic, key_name, key_value);
}
}
return dic;
}
开发者ID:2ion,项目名称:iniparser,代码行数:27,代码来源:test_iniparser.c
示例13: Test_iniparser_getnsec
void Test_iniparser_getnsec(CuTest *tc)
{
int i;
char sec_name[32];
dictionary *dic;
/* NULL test */
CuAssertIntEquals(tc, -1, iniparser_getnsec(NULL));
/* Empty dictionary */
dic = dictionary_new(10);
CuAssertIntEquals(tc, 0, iniparser_getnsec(dic));
dictionary_del(dic);
/* Regular dictionary */
dic = generate_dictionary(512, 0);
CuAssertIntEquals(tc, 512, iniparser_getnsec(dic));
/* Check after removing sections */
for (i = 1; i < 512; ++i) {
sprintf(sec_name, "sec%d", i);
dictionary_unset(dic, sec_name);
CuAssertIntEquals(tc, 512 - i, iniparser_getnsec(dic));
}
dictionary_del(dic);
/* Mix sections and regular keys */
dic = generate_dictionary(10, 512);
CuAssertIntEquals(tc, 10, iniparser_getnsec(dic));
dictionary_del(dic);
}
开发者ID:2ion,项目名称:iniparser,代码行数:31,代码来源:test_iniparser.c
示例14: dictionary_setup
static int dictionary_setup(void **state) {
struct dictionary *d = dictionary_new();
dictionary_insert(d,first);
dictionary_insert(d,second);
dictionary_insert(d,third);
*state = d;
return 0;
}
开发者ID:cywinskikamil,项目名称:SpellCheck,代码行数:8,代码来源:dictionary_test.c
示例15: dictionary_setup
/**
Tworzy środowisko do testów
@param[in,out] state Środowisko
@return Kod błędu
*/
static int dictionary_setup(void **state)
{
dictionary *d = dictionary_new();
if (d == NULL)
return -1;
*state = d;
return 0;
}
开发者ID:starsep,项目名称:Spellcheck,代码行数:13,代码来源:dictionary_test.c
示例16: test_failure
void test_failure(){
if (g_test_trap_fork(0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR)){
dictionary *dd = dictionary_new();
dictionary_add(dd, NULL, "blank");
}
g_test_trap_assert_failed();
g_test_trap_assert_stderr("NULL is not a valid key.\n");
}
开发者ID:Kr1sso,项目名称:21st-century-c,代码行数:8,代码来源:dict_test.c
示例17: Test_iniparser_getseckeys
void Test_iniparser_getseckeys(CuTest *tc)
{
unsigned i;
char key_name[64];
dictionary *dic;
int nkeys;
const char * keys[10]; /* At most 10 elements per section */
/* NULL test */
CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(NULL, NULL, NULL));
CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(NULL, "dummy", NULL));
CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(NULL, "dummy", keys));
/* Empty dictionary */
dic = dictionary_new(10);
CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(dic, NULL, keys));
CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(dic, "dummy", keys));
dictionary_del(dic);
/* Generic dictionary */
dic = generate_dictionary(100, 10);
CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(dic, NULL, keys));
CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(dic, "dummy", keys));
CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(dic, "sec0", NULL));
nkeys = iniparser_getsecnkeys(dic, "sec42");
CuAssertIntEquals(tc, nkeys, 10);
CuAssertPtrEquals(tc, keys, iniparser_getseckeys(dic, "sec42", keys));
for (i = 0; i < 10; ++i) {
sprintf(key_name, "sec42:key%d", i);
CuAssertStrEquals(tc, key_name, keys[i]);
}
/* Remove some keys to make the dictionary more real */
dictionary_unset(dic, "sec42");
dictionary_unset(dic, "sec99:key9");
dictionary_unset(dic, "sec0:key0");
dictionary_unset(dic, "sec0:key1");
dictionary_unset(dic, "sec0:key2");
CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(dic, "sec42", keys));
nkeys = iniparser_getsecnkeys(dic, "sec99");
CuAssertIntEquals(tc, nkeys, 9);
CuAssertPtrEquals(tc, keys, iniparser_getseckeys(dic, "sec99", keys));
for (i = 0; i < 9; ++i) {
sprintf(key_name, "sec99:key%d", i);
CuAssertStrEquals(tc, key_name, keys[i]);
}
nkeys = iniparser_getsecnkeys(dic, "sec0");
CuAssertIntEquals(tc, nkeys, 7);
CuAssertPtrEquals(tc, keys, iniparser_getseckeys(dic, "sec0", keys));
for (i = 0; i < 7; ++i) {
sprintf(key_name, "sec0:key%d", i + 3);
CuAssertStrEquals(tc, key_name, keys[i]);
}
dictionary_del(dic);
}
开发者ID:2ion,项目名称:iniparser,代码行数:58,代码来源:test_iniparser.c
示例18: dictionary_new
/**
Test funkcji dictionary_new().
Stworzenie słownika.
*/
static void dictionary_new_test(void** state) {
struct dictionary *dict;
dict = dictionary_new();
assert_true(dict->root->letter == '-');
assert_true(dict->alphabet->letter == '#');
assert_int_equal(dict->root->isInWord, 0);
assert_null(dict->alphabet->next);
dictionary_done(dict);
}
开发者ID:agaX,项目名称:SpellChecker,代码行数:13,代码来源:dictionary_test.c
示例19: dict_setup_done_test
/// Funkcja sprawdzająca inicjalizację, dodanie słów ze stałych i destrukcję.
static void dict_setup_done_test(void **state) {
struct dictionary* d = dictionary_new();
assert_non_null(d);
assert_int_equal(dictionary_insert(d, first), 1);
assert_int_equal(dictionary_insert(d, second), 1);
assert_int_equal(dictionary_insert(d, third), 1);
assert_int_equal(dictionary_insert(d, forth), 1);
assert_int_equal(dictionary_insert(d, fifth), 1);
dictionary_done(d);
}
开发者ID:skazypl,项目名称:spellchecker,代码行数:11,代码来源:dictionary_test.c
示例20: config_init
int
config_init(void)
{
overrides = dictionary_new(0);
if(!overrides)
{
return -1;
}
return 0;
}
开发者ID:nevali,项目名称:spool,代码行数:10,代码来源:config.c
注:本文中的dictionary_new函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论