本文整理汇总了C++中POOL_MEM::bsprintf方法的典型用法代码示例。如果您正苦于以下问题:C++ POOL_MEM::bsprintf方法的具体用法?C++ POOL_MEM::bsprintf怎么用?C++ POOL_MEM::bsprintf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类POOL_MEM
的用法示例。
在下文中一共展示了POOL_MEM::bsprintf方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: object_key_value
void OUTPUT_FORMATTER::object_key_value(const char *key, const char *key_fmt,
const char *value, const char *value_fmt,
int wrap)
{
POOL_MEM string;
POOL_MEM wvalue(value);
rewrap(wvalue, wrap);
switch (api) {
#if HAVE_JANSSON
case API_MODE_JSON:
json_key_value_add(key, wvalue.c_str());
break;
#endif
default:
if (key_fmt) {
string.bsprintf(key_fmt, key);
result_message_plain->strcat(string);
}
if (value_fmt) {
string.bsprintf(value_fmt, wvalue.c_str());
result_message_plain->strcat(string);
}
Dmsg2(800, "obj: %s:%s\n", key, wvalue.c_str());
}
}
示例2: get_path_of_new_resource
bool CONFIG::get_path_of_new_resource(POOL_MEM &path, POOL_MEM &extramsg, const char *component,
const char *resourcetype, const char *name,
bool error_if_exists, bool create_directories)
{
POOL_MEM rel_path(PM_FNAME);
POOL_MEM directory(PM_FNAME);
POOL_MEM resourcetype_lowercase(resourcetype);
resourcetype_lowercase.toLower();
if (!get_path_of_resource(path, component, resourcetype, name, false)) {
return false;
}
path_get_directory(directory, path);
if (create_directories) {
path_create(directory);
}
if (!path_exists(directory)) {
extramsg.bsprintf("Resource config directory \"%s\" does not exist.\n", directory.c_str());
return false;
}
/*
* Store name for temporary file in extramsg.
* Can be used, if result is true.
* Otherwise it contains an error message.
*/
extramsg.bsprintf("%s.tmp", path.c_str());
if (!error_if_exists) {
return true;
}
/*
* File should not exists, as it is going to be created.
*/
if (path_exists(path)) {
extramsg.bsprintf("Resource config file \"%s\" already exists.\n", path.c_str());
return false;
}
if (path_exists(extramsg)) {
extramsg.bsprintf("Temporary resource config file \"%s.tmp\" already exists.\n", path.c_str());
return false;
}
return true;
}
示例3: json_finalize_result
void OUTPUT_FORMATTER::json_finalize_result(bool result)
{
POOL_MEM string;
json_t *msg_obj = json_object();
json_t *error_obj;
/*
* We mimic json-rpc result and error messages,
* To make it easier to implement real json-rpc later on.
*/
json_object_set(msg_obj, "jsonrpc", json_string("2.0"));
json_object_set(msg_obj, "id", json_null());
if (result) {
json_object_set(msg_obj, "result", result_array_json);
} else {
error_obj = json_object();
json_object_set_new(error_obj, "code", json_integer(1));
json_object_set_new(error_obj, "message", json_string("failed"));
json_object_set(error_obj, "data", result_array_json);
json_object_set_new(msg_obj, "error", error_obj);
}
string.bsprintf("%s\n", json_dumps(msg_obj, UA_JSON_FLAGS));
send_func(send_ctx, string.c_str());
json_array_clear(result_array_json);
json_object_clear(msg_obj);
}
示例4: list_result
/*
* If full_list is set, we list vertically, otherwise, we
* list on one line horizontally.
* Return number of rows
*/
int list_result(JCR *jcr, B_DB *mdb, OUTPUT_FORMATTER *send, e_list_type type)
{
SQL_FIELD *field;
SQL_ROW row;
int i, col_len, max_len = 0;
int num_fields;
char ewc[30];
POOL_MEM key;
POOL_MEM value;
Dmsg0(800, "list_result starts\n");
if (sql_num_rows(mdb) == 0) {
send->decoration(_("No results to list.\n"));
send->object_end("table");
return sql_num_rows(mdb);
}
num_fields = sql_num_fields(mdb);
switch (type) {
case NF_LIST:
case RAW_LIST:
/*
* No need to calculate things like column widths for
* unformated or raw output.
*/
break;
case HORZ_LIST:
case VERT_LIST:
Dmsg1(800, "list_result starts looking at %d fields\n", num_fields);
/*
* Determine column display widths
*/
sql_field_seek(mdb, 0);
for (i = 0; i < num_fields; i++) {
Dmsg1(800, "list_result processing field %d\n", i);
field = sql_fetch_field(mdb);
if (!field) {
break;
}
col_len = cstrlen(field->name);
if (type == VERT_LIST) {
if (col_len > max_len) {
max_len = col_len;
}
} else {
if (sql_field_is_numeric(mdb, field->type) && (int)field->max_length > 0) { /* fixup for commas */
field->max_length += (field->max_length - 1) / 3;
}
if (col_len < (int)field->max_length) {
col_len = field->max_length;
}
if (col_len < 4 && !sql_field_is_not_null(mdb, field->flags)) {
col_len = 4; /* 4 = length of the word "NULL" */
}
field->max_length = col_len; /* reset column info */
}
}
break;
}
Dmsg0(800, "list_result finished first loop\n");
switch (type) {
case NF_LIST:
case RAW_LIST:
Dmsg1(800, "list_result starts second loop looking at %d fields\n", num_fields);
while ((row = sql_fetch_row(mdb)) != NULL) {
send->object_start(row[0]);
sql_field_seek(mdb, 0);
for (i = 0; i < num_fields; i++) {
field = sql_fetch_field(mdb);
if (!field) {
break;
}
if (row[i] == NULL) {
value.bsprintf(" %s", "NULL");
} else {
value.bsprintf(" %s", row[i]);
}
send->object_key_value(field->name, value.c_str(), "%s");
}
if (type != RAW_LIST) {
send->decoration("\n");
}
send->object_end(row[0]);
}
break;
case HORZ_LIST:
Dmsg1(800, "list_result starts second loop looking at %d fields\n", num_fields);
list_dashes(mdb, send);
send->decoration("|");
sql_field_seek(mdb, 0);
for (i = 0; i < num_fields; i++) {
Dmsg1(800, "list_result looking at field %d\n", i);
field = sql_fetch_field(mdb);
//.........这里部分代码省略.........