本文整理汇总了C++中dictionary_set函数的典型用法代码示例。如果您正苦于以下问题:C++ dictionary_set函数的具体用法?C++ dictionary_set怎么用?C++ dictionary_set使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dictionary_set函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: ui_elem_new_type_id
ui_elem* ui_elem_new_type_id(char* name, int type_id) {
if ( dictionary_contains(ui_elems, name) ) {
error("UI Manager already contains element called %s!", name);
}
debug("Creating UI Element %s (%s)", name, type_id_name(type_id));
ui_elem* ui_e = NULL;
for(int i = 0; i < num_ui_elem_handlers; i++) {
ui_elem_handler ui_hand = ui_elem_handlers[i];
if (ui_hand.type_id == type_id) {
ui_e = ui_hand.new_func();
}
}
if (ui_e == NULL) {
error("Don't know how to create ui element %s. No handler for type %s!", name, type_id_name(type_id));
}
dictionary_set(ui_elems, name, ui_e);
int* type_ptr = malloc(sizeof(int));
*type_ptr = type_id;
dictionary_set(ui_elem_types, name, type_ptr);
char* name_copy = malloc(strlen(name) + 1);
strcpy(name_copy, name);
list_push_back(ui_elem_names, name_copy);
return ui_e;
}
开发者ID:RicoP,项目名称:Corange,代码行数:34,代码来源:ui_manager.c
示例2: 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
示例3: 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
示例4: 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
示例5: iniparser_setstr
int iniparser_setstr(dictionary * ini, char * entry, char * val)
{
// Check whether the dictionary is case-sensitive
if (ini->caseSensitive) {
dictionary_set(ini, entry, val);
} else {
dictionary_set(ini, inistrlwc(entry), val);
}
return 0 ;
}
开发者ID:Questionman,项目名称:SOAP3-dp-1,代码行数:11,代码来源:iniparser.c
示例6: Test_dictionary_dump
void Test_dictionary_dump(CuTest *tc)
{
int i, j;
char sec_name[32];
char key_name[64];
dictionary *dic;
char *dump_buff;
const char dump_real[] = "\
sec1\t[]\n\
sec1:key1\t[dummy_value]\n\
sec1:key2\t[dummy_value]\n\
sec1:key3\t[dummy_value]\n\
sec1:key4\t[dummy_value]\n\
sec2\t[]\n\
sec2:key1\t[dummy_value]\n\
sec2:key2\t[dummy_value]\n\
sec2:key3\t[dummy_value]\n\
sec2:key4\t[dummy_value]\n\
";
dic = dictionary_new(DICTMINSZ);
CuAssertPtrNotNull(tc, dic);
/* Try dummy values */
dictionary_dump(NULL, NULL);
dictionary_dump(dic, NULL);
/* Try with empty dictionary first */
dump_buff = get_dump(dic);
CuAssertStrEquals(tc, "empty dictionary\n", dump_buff);
free(dump_buff);
/* Populate the dictionary */
for (i = 1 ; i < 3; ++i) {
sprintf(sec_name, "sec%d", i);
dictionary_set(dic, sec_name, "");
for (j = 1 ; j < 5; ++j) {
sprintf(key_name, "%s:key%d", sec_name, j);
dictionary_set(dic, key_name, "dummy_value");
}
}
/* Check the dump file */
dump_buff = get_dump(dic);
CuAssertStrEquals(tc, dump_real, dump_buff);
free(dump_buff);
dictionary_del(dic);
}
开发者ID:DelusionalLogic,项目名称:iniparser,代码行数:49,代码来源:test_dictionary.c
示例7: applyTemplateFromDictionary
/* Apply template search from dictionary src to dictionary dst */
static int
applyTemplateFromDictionary(dictionary *dict, dictionary *src, char *search, int overwrite) {
char *key, *value, *pos;
int i = 0;
int found;
/* -1 on not found, 0+ on actual applies */
found = -1;
for(i=0; i<src->n; i++) {
key = src->key[i];
value = src->val[i];
pos = strstr(key, ":");
if(value != NULL && pos != NULL) {
*pos = '\0';
pos++;
if(!strcmp(search, key) && (strstr(pos,":") != NULL)) {
if(found < 0) found = 0;
if( overwrite || !CONFIG_ISSET(pos)) {
DBG("template %s setting %s to %s\n", search, pos, value);
dictionary_set(dict, pos, value);
found++;
}
}
/* reverse the damage - no need for strdup() */
pos--;
*pos = ':';
}
}
return found;
}
开发者ID:cperl82,项目名称:ptpd,代码行数:35,代码来源:configdefaults.c
示例8: debug
REGISTRY_PERSON *registry_person_allocate(const char *person_guid, time_t when) {
debug(D_REGISTRY, "Registry: registry_person_allocate('%s'): allocating new person, sizeof(PERSON)=%zu", (person_guid)?person_guid:"", sizeof(REGISTRY_PERSON));
REGISTRY_PERSON *p = mallocz(sizeof(REGISTRY_PERSON));
if(!person_guid) {
for(;;) {
uuid_t uuid;
uuid_generate(uuid);
uuid_unparse_lower(uuid, p->guid);
debug(D_REGISTRY, "Registry: Checking if the generated person guid '%s' is unique", p->guid);
if (!dictionary_get(registry.persons, p->guid)) {
debug(D_REGISTRY, "Registry: generated person guid '%s' is unique", p->guid);
break;
}
else
info("Registry: generated person guid '%s' found in the registry. Retrying...", p->guid);
}
}
else
strncpyz(p->guid, person_guid, GUID_LEN);
debug(D_REGISTRY, "Registry: registry_person_allocate('%s'): creating dictionary of urls", p->guid);
avl_init(&p->person_urls, person_url_compare);
p->first_t = p->last_t = (uint32_t)when;
p->usages = 0;
registry.persons_memory += sizeof(REGISTRY_PERSON);
registry.persons_count++;
dictionary_set(registry.persons, p->guid, p, sizeof(REGISTRY_PERSON));
return p;
}
开发者ID:darrentangdt,项目名称:netdata,代码行数:35,代码来源:registry_person.c
示例9: dictionary_set
// Check if the key is in the form section:key and if yes create the section in the dictionnary
// if it doesn't exist.
void InitParser::make_section_from_key(const string& key)
{
int pos = key.find(':');
if (!pos) return; // No ':' were found
string sec = key.substr(0,pos);
if (find_entry(sec)) return; // The section is already present into the dictionnary
dictionary_set(dico, sec.c_str(), NULL); // Add the section key
}
开发者ID:AssociationSirius,项目名称:requiem,代码行数:10,代码来源:init_parser.cpp
示例10: main3
int main3(int argc, char * argv[])
{
dictionary * ini ;
char* k1 = "hello:a";
char* v1 = "nihao";
char* k2 = "hello:b";
char* v2 = "heihei";
ini = dictionary_new(0);
dictionary_set(ini, k1, v1);
dictionary_set(ini, "hello", NULL);
dictionary_set(ini, k2, v2);
iniparser_dump_json(ini, stdout);
iniparser_freedict(ini);
return 0 ;
}
开发者ID:jannson,项目名称:iniparser,代码行数:17,代码来源:ex.c
示例11: ui_elem_add_type_id
void ui_elem_add_type_id(char* name, int type_id, ui_elem* ui_elem) {
if ( dictionary_contains(ui_elems, name) ) {
error("UI Manager already contains element called %s!", name);
}
dictionary_set(ui_elems, name, ui_elem);
int* type_ptr = malloc(sizeof(int));
*type_ptr = type_id;
dictionary_set(ui_elem_types, name, type_ptr);
char* name_copy = malloc(strlen(name) + 1);
strcpy(name_copy, name);
list_push_back(ui_elem_names, name_copy);
}
开发者ID:RicoP,项目名称:Corange,代码行数:17,代码来源:ui_manager.c
示例12: iniparser_setstr
int iniparser_setstr(
dictionary * ini,
char * entry,
char * val
)
{
dictionary_set(ini, entry, val);
return 0 ;
}
开发者ID:belen-albeza,项目名称:edivc,代码行数:9,代码来源:mainparse.c
示例13: iniparser_set
/*--------------------------------------------------------------------------*/
int iniparser_set(dictionary * ini, const char * entry, const char * val)
{
int result = 0;
char *lc_entry = xstrdup(entry);
strlwc(lc_entry);
result = dictionary_set(ini, lc_entry, val) ;
free(lc_entry);
return result;
}
开发者ID:chenan2005,项目名称:WebGameServer,代码行数:10,代码来源:iniparser.c
示例14: make_section_from_key
// Set the given entry with the provided value. If the entry cannot be found
// -1 is returned and the entry is created. Else 0 is returned.
int InitParser::set_str(const string& key, const string& val)
{
make_section_from_key(key);
int return_val;
if (find_entry(key)) return_val = 0;
else return_val = -1;
dictionary_set(dico, key.c_str(), val.c_str());
return return_val;
}
开发者ID:AssociationSirius,项目名称:requiem,代码行数:12,代码来源:init_parser.cpp
示例15: update_config
void update_config(char *token, char *username)
{
bstring file = locate_config_file();
bstring tmp = bstrcpy(file);
bcatcstr(tmp, ".tmp_XXXXXX");
int fd = mkstemp((char *) tmp->data);
if (fd < 0)
{
perror("mkstemp");
exit(1);
}
FILE *fp = fdopen(fd, "w");
if (fp == 0)
{
perror("fdopen");
exit(1);
}
dictionary *config;
struct stat statbuf;
int rc = stat((char *) file->data, &statbuf);
if (rc < 0 || statbuf.st_size == 0)
{
/* create a new empty dictionary */
config = dictionary_new(0);
dictionary_set(config, "authentication", 0);
}
else
{
config = iniparser_load(bdata(file));
}
iniparser_set(config, "authentication:token", token);
if (username)
iniparser_set(config, "authentication:user_id", username);
iniparser_dump_ini(config, fp);
iniparser_freedict(config);
fclose(fp);
if (rename(bdata(tmp), bdata(file)) < 0)
{
fprintf(stderr, "Error rename %s to %s: %s\n",
bdata(tmp), bdata(file), strerror(errno));
exit(1);
}
bdestroy(tmp);
bdestroy(file);
}
开发者ID:kbase,项目名称:auth_lite,代码行数:54,代码来源:kb-common.c
示例16: main
int main(int argc, char* argv[])
{
dictionary* d ;
char* val ;
int i ;
char cval[90] ;
/* Allocate dictionary */
printf("allocating...\n");
d = dictionary_new(0);
/* Set values in dictionary */
printf("setting %d values...\n", NVALS);
for (i=0 ; i<NVALS ; i++)
{
sprintf(cval, "%04d", i);
dictionary_set(d, cval, "salut");
}
printf("getting %d values...\n", NVALS);
for (i=0 ; i<NVALS ; i++)
{
sprintf(cval, "%04d", i);
val = dictionary_get(d, cval, DICT_INVALID_KEY);
if (val==DICT_INVALID_KEY)
{
printf("cannot get value for key [%s]\n", cval);
}
}
printf("unsetting %d values...\n", NVALS);
for (i=0 ; i<NVALS ; i++)
{
sprintf(cval, "%04d", i);
dictionary_unset(d, cval);
}
if (d->n != 0)
{
printf("error deleting values\n");
}
printf("deallocating...\n");
dictionary_del(d);
return 0 ;
}
开发者ID:freeeyes,项目名称:PSS,代码行数:50,代码来源:dictionary.c
示例17: strlen
frame_t *frame_factory_get(const char *key)
{
frame_t *frame;
char *addr_str;
// try to load frame using config from config cache
static char key_buf[MAX_TEXTURE_NAME+4+1];
static char addr_buff[16+1];
char *file;
int pf, loc;
int namelen = strlen(key);
if (frame_cache == NULL) {
printf("frame factory not inited!\n");
return NULL;
}
addr_str = dictionary_get(frame_cache, (char *)key, "0x0");
frame = (frame_t *)(strtol(addr_str, NULL, 0));
if (frame != 0) {
return frame;
}
if (strlen(key) > MAX_TEXTURE_NAME) {
oslFatalError("config key too long! %s", key);
}
strcpy(key_buf, key);
strcat(key_buf, ":f");
file = iniparser_getstring(texture_cfg, key_buf, NULL);
printf("search key %s, value %s\n", key_buf, file);
printf("texture cfg %p\n", texture_cfg);
key_buf[namelen] = '\0';
strcat(key_buf, ":pf");
pf = iniparser_getint(texture_cfg, key_buf, OSL_IN_VRAM);
key_buf[namelen] = '\0';
strcat(key_buf, ":loc");
loc = iniparser_getint(texture_cfg, key_buf, TAIKO_PF);
printf("ok so far!\n");;
frame = frame_create_simple(file, pf, loc);
if (frame != NULL) {
key_buf[namelen] = '\0';
sprintf(addr_buff, "%d", (int)frame);
dictionary_set(frame_cache, key_buf, addr_buff);
}
return frame;
}
开发者ID:mariodon,项目名称:psp-taikoclone,代码行数:50,代码来源:frame_factory.c
示例18: printf
int main
(int argc,
char *argv[])
{
LPDICTIONARY lpDict; // Ptr to workspace dictionary
LPWCHAR lpwVal;
int i;
WCHAR cval[90];
/* Allocate dictionary */
printf ("allocating...\n");
lpDict = dictionary_new (0);
/* Set values in dictionary */
printf ("setting %d values...\n", NVALS);
for (i = 0; i < NVALS; i++)
{
wsprintfW (cval, L"%04d", i);
dictionary_set (lpDict, cval, L"salut");
} // End FOR
printf ("getting %d values...\n", NVALS);
for (i = 0; i < NVALS; i++)
{
wsprintfW (cval, L"%04d", i);
lpwVal = dictionary_get (lpDict, cval, DICT_INVALID_KEY, NULL);
if (lpwVal EQ DICT_INVALID_KEY)
printf ("cannot get value for key [%s]\n", cval);
} // End FOR
printf ("unsetting %d values...\n", NVALS);
for (i = 0; i < NVALS; i++)
{
wsprintfW (cval, L"%04d", i);
dictionary_unset (lpDict, cval);
} // End FOR
if (lpDict->n NE 0)
printf ("error deleting values\n");
printf ("deallocating...\n");
dictionary_del (lpDict); lpDict = NULL;
return 0;
} // End main
开发者ID:PlanetAPL,项目名称:nars2000,代码行数:46,代码来源:dictionary.c
示例19: operator_def_evaluate
/*!
* \file
* \brief Operator \c def: add an entry into the \c dictionary.
*
* The entry is composed of a protected label on the top of the stack and the value under it.
* Both values are removed from the stack.
* Nothing else is modified.
*
* If the stack is not deep enough or the first one is not a \c value_protected_label, a \c basic_type_error is returned.
*
* assert is enforced.
*
* \author Jérôme DURAND-LOSE
* \version 1
* \date 2015
* \copyright GNU Public License.
*/
static basic_type operator_def_evaluate ( chunk const ch , va_list va ) {
interpretation_context ic = va_arg( va , interpretation_context);
chunk ch1 = linked_list_chunk_pop_front(ic->stack);
chunk ch2 = linked_list_chunk_pop_front(ic-> stack);
if(!(ch1) || !(ch2)){
return basic_type_error;
}
if(value_is_protected_label(ch1)){
dictionary_set(ic->dic , basic_type_get_pointer(chunk_answer_message(ch1 , "value_get_value")) , ch2);
chunk_destroy(ch1);
chunk_destroy(ch2);
return basic_type_void;
}
chunk_destroy(ch1);
chunk_destroy(ch2);
return basic_type_error;
}
开发者ID:ThibaultGeoffroy,项目名称:ProjetPASD,代码行数:34,代码来源:operator_def.c
示例20: iniparser_add_entry
/* Private: add an entry to the dictionary */
void
iniparser_add_entry (dictionary * d,
char * sec,
char * key,
char * val)
{
char longkey[2*ASCIILINESZ+1];
/* Make a key as section:keyword */
if (key)
sprintf (longkey, "%s:%s", sec, key);
else
strcpy (longkey, sec);
/* Add (key,val) to dictionary */
dictionary_set (d, longkey, val);
}
开发者ID:bhull2010,项目名称:libcompizfusionconfig-packages,代码行数:19,代码来源:iniparser.c
注:本文中的dictionary_set函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论