prg_env_attr_value_get()

摘要

获取偏好设置的值。

语法

prg_env_attr_value_get (attr_type, attr_name, value_ptr)
参数 类型 说明
attr_type PrgT_Env_Attr_Type 偏好设置的数据类型。该值必须是已定义的偏好类型,否则会发生错误。可用类型列于 表 1 Environment Attribute Package Symbolic Constants 中。
attr_name const char* 目标属性的名称。该值必须是已定义的偏好设置,否则会发生错误。
value_ptr void* 指向某个变量的指针,该变量将被填入指定属性的值。更多信息参见详情一节。

返回类型

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
}

详情

value_ptr 参数可以接受一个字符串,或指向 integer、double 或 PrgT_List 类型变量的指针。参数指针的数据类型必须与指定属性的数据类型一致,否则会发生错误。

  • 对于字符串,字符数组必须足够大,以容纳该属性的值。
  • 如果属性为 Boolean 类型,返回值将是 OPC_BOOLINT_ENABLED 或 OPC_BOOLINT_DISABLED。
  • 如果属性为 PrgT_List 类型,value_ptr 所使用的列表必须在本函数调用之前通过 prg_list_create() 或 prg_list_init() 等函数完成分配和初始化。

用途

提供一种从当前进程获取偏好设置的机制。可以获取偏好设置在当前进程中的当前值。

该函数与 prg_preference_value_get() 的区别在于:prg_preference_value_get() 确保它所请求的任何属性之后都会出现在用户选择 Edit Preferences 时,而本函数不保证这种行为。你可能更愿意使用本函数来获取用户无需查看或编辑的偏好设置值;这可以避免 Preferences Editor 被无关属性塞得过满。

错误

  • 程序中止:Segmentation violation(由于无效的值指针、指向内存不足的指针,或 attr_name 的无效地址)
  • 可恢复错误:Attribute name (<attr_name>) is unrecognized

参考

本站文档由 北京智网畅联科技有限公司 整理、翻译并提供 · 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