prg_env_attr_value_set()

摘要

为偏好设置赋值。

语法

prg_env_attr_value_set (attr_name, value)
参数 类型 说明
attr_name const char* 目标属性的名称。该值必须是已定义的偏好设置,否则会发生错误。
value_ptr void* 指定属性的新值。该参数可以接受 integer、double、字符串,或指向 PrgT_List 类型变量的指针。本函数内部的逻辑根据被赋值属性的类型判断所传参数的类型,并相应地调整其属性赋值方式。

返回类型

PrgT_Compcode

指示操作是否成功完成的完成代码。该代码可与两个符号常量 PrgC_Compcode_Success 和 PrgC_Compcode_Failure 进行比较。

头文件

prg_env.h

示例

mod_dirs_dir_add (const char * directory_str)
{
	FIN (mod_dirs_dir_add ())
	/* Note this is a list, not a list-pointer. */
	Prg_List * moddir_lptr;

	moddir_lptr = prg_list_create ();

	/* Populate the list with the model directories environment */
	/* attribute (mod_dirs). Each element of the list will be a string */
	/* representing a directory.*/
	prg_env_attr_value_get (PrgC_Env_Attr_List, "mod_dirs", moddir_lptr);

	/* Add a copy of the custom directory to the tail of the list. */
	prg_list_strings_append (moddir_lptr, directory_str, PRGC_NIL);

	/* Set the new list as the list of model directories.*/
	prg_env_attr_value_set ("mod_dirs", moddir_lptr);

	/* Free the list's elements. */
	prg_list_free (moddir_lptr);

	/* Free the list itself. */
	prg_mem_free (moddir_lptr);
	FOUT
}

详情

可以修改偏好设置在当前进程中的当前值。新值必须与被查询偏好的数据类型相同。属性值只在当前进程中改变,不影响存储在偏好设置文件或环境文件中的值。

如果属性为 PrgT_List 类型,value 参数所使用的列表必须在本函数调用之前通过 prg_list_create() 或 prg_list_init() 等函数完成分配和初始化。

用途

提供一种在当前进程内动态赋值偏好设置的机制。

错误

  • 程序中止:Segmentation violation.(由于无效的值指针、attr_name 的无效地址,或类型不正确的值)
  • 可恢复错误:Attribute name (<attr_name>) is unrecognized.
  • 可恢复错误:Object ID (<objid>) is out-of-range.
  • 可恢复错误:Value is invalid for attribute (<attr_name>).

参考

本站文档由 北京智网畅联科技有限公司 整理、翻译并提供 · Documentation compiled and provided by Beijing ZNetLink Technology Co., Ltd.

交流群 · QQ Group:OPNET/智网妙算网络仿真交流群(群号 486383494)

原文档 © 2017 Riverbed Technology · 本站为公益翻译,由 AI 辅助完成,请仔细甄别

Original documentation © 2017 Riverbed Technology. Community translation, AI-assisted. Contact: jiazequn@znetlink.com