sernatur/src/vapi/libconfig.vapi

225 lines
7.4 KiB
Vala

/*
* Copyright 2018 Chris Cromer
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
[CCode (cprefix = "", lower_case_cprefix = "", cheader_filename = "libconfig.h")]
namespace LibConfig {
using Posix; // Needed for Posix.FILE
[CCode (cname = "uint", cprefix = "LIBCONFIG_VER_", has_type_id = false)]
public enum Version {
MAJOR,
MINOR,
REVISION;
/**
* Convert the enum value into a string with a version number
* This method is here to override default enum to_string which will print the enum variable name by default
* @return string with version number
*/
public string to_string () {
int x_value = this;
return x_value.to_string();
}
}
[CCode (cname = "int", cprefix = "CONFIG_ERR_", has_type_id = false)]
public enum ConfigError {
NONE = 0,
FILE_IO = 1,
PARSE = 2
}
[CCode (cname = "int", cprefix = "CONFIG_OPTION_", has_type_id = false)]
[Flags]
public enum ConfigOption {
AUTOCONVERT = 0x01,
SEMICOLON_SEPARATORS = 0x02,
COLON_ASSIGNMENT_FOR_GROUPS = 0x04,
COLON_ASSIGNMENT_FOR_NON_GROUPS = 0x08,
OPEN_BRACE_ON_SEPARATE_LINE = 0x10,
[Version (since = "1.7")]
ALLOW_SCIENTIFIC_NOTATION = 0x20,
[Version (since = "1.7.1")]
FSYNC = 0x40
}
[CCode (cname = "int", cprefix = "CONFIG_TYPE_", has_type_id = false)]
public enum ConfigType {
NONE = 0,
GROUP = 1,
INT = 2,
INT64 = 3,
FLOAT = 4,
STRING = 5,
BOOL = 6,
ARRAY = 7,
LIST = 8
}
[CCode (cname = "int", cprefix = "CONFIG_FORMAT_", has_type_id = false)]
public enum ConfigFormat {
DEFAULT = 0,
HEX = 1
}
[CCode (cname = "config_t", cprefix = "config_", destroy_function = "config_destroy", has_type_id = false)]
public struct Config {
[CCode (cname = "config_init")]
public Config();
[Version (since = "1.7")]
public void clear ();
public bool read (FILE stream);
public bool read_file (string filename);
public bool read_string (string str);
public void write (FILE stream);
public bool write_file (string filename);
public void set_include_dir (string include_dir);
public string get_include_dir ();
//[Version (since = "1.7")]
//void config_set_include_func (config_include_fn_t func)
[Version (since = "1.6")]
public ushort get_float_precision ();
[Version (since = "1.6")]
public void set_float_precision (ushort digits);
public ConfigOption get_options ();
public void set_options (ConfigOption options);
[Version (since = "1.7")]
public ConfigOption get_option (int option);
[Version (since = "1.7")]
public void set_option (ConfigOption option, int flag);
[Version (deprecated = true, replacement = "get_option")]
public int get_auto_convert ();
[Version (deprecated = true, replacement = "set_option")]
public void set_auto_convert (int flag);
public ConfigFormat get_default_format ();
public void set_default_format (ConfigFormat format);
public ushort get_tab_width ();
public void set_tab_width (ushort width);
public bool lookup_int (string path, out int x_value);
public bool lookup_int64 (string path, out int64 x_value);
public bool lookup_float (string path, out float x_value);
public bool lookup_bool (string path, out bool x_value);
public bool lookup_string (string path, out string x_value);
public Setting? lookup (string path);
public Setting root_setting ();
[CCode (simple_generics = true)]
[Version (since = "1.7")]
public void set_hook<T> (T hook);
[CCode (simple_generics = true)]
[Version (since = "1.7")]
public T get_hook<T> ();
//[CCode (simple_generics = true)]
//public void set_destructor<T> (T void (* destructor));
public unowned string error_text ();
public unowned string? error_file ();
public int error_line ();
public ConfigError error_type ();
public string error_message () {
return this.error_file () + ":" + this.error_line ().to_string() + " - " + this.error_text ();
}
public string version() {
return Version.MAJOR.to_string () + "." + Version.MINOR.to_string () + "." + Version.REVISION.to_string ();
}
}
[CCode (cname = "config_setting_t", cprefix = "config_setting_", free_function = "", has_type_id = false, has_target = false)]
[Compact]
public class Setting {
public Setting? lookup (string path);
public int? get_int ();
public int64? get_int64 ();
public float? get_float ();
public bool? get_bool ();
public unowned string? get_string ();
public bool set_int (int x_value);
public bool set_int64 (int64 x_value);
public bool set_float (float x_value);
public bool set_bool (bool x_value);
public bool set_string (string x_value);
public bool lookup_int (string name, out int x_value);
public bool lookup_int64 (string name, out int64 x_value);
public bool lookup_float (string name, out float x_value);
public bool lookup_bool (string name, out bool x_value);
public bool lookup_string (string name, out string x_value);
public ConfigFormat get_format ();
public bool set_format (ConfigFormat format);
public Setting? get_member (string name);
public Setting? get_elem (uint index);
public int? get_int_elem (int index);
public int64? get_int64_elem (int index);
public float? get_float_elem (int index);
public bool? get_bool_elem (int index);
public unowned string? get_string_elem (int index);
public Setting? set_int_elem (int index, int x_value);
public Setting? set_int64_elem (int index, int64 x_value);
public Setting? set_float_elem (int index, float x_value);
public Setting? set_bool_elem (int index, bool x_value);
public Setting? set_string_elem (int index, string x_value);
public Setting? add (Setting parent, string? name, ConfigType type);
public bool remove (Setting parent, string name);
public int remove_elem (Setting parent, uint index);
public unowned string? name ();
public Setting? parent ();
public bool is_root ();
public int index ();
public int length ();
public ConfigType type ();
public bool is_group ();
public bool is_array ();
public bool is_list ();
public bool is_aggregate ();
public bool is_scalar ();
public bool is_number ();
public unowned string? source_file ();
public uint source_line ();
}
}