SettingsPack

A collection of session-setting overrides. The pure-Kotlin port of libtorrent's settings_pack (settings_pack.hpp / settings_pack.cpp).

A SettingsPack stores only the settings that have been explicitly set on it (mirroring the C++ m_strings / m_ints / m_bools vectors). Reading a setting that has not been overridden falls back to the libtorrent default value for that key (see StringSettingDefaults, IntSettingDefaults, BoolSettingDefaults).

Keys are the 16-bit values from StringSetting, IntSetting and BoolSetting; the top two bits select the value type (see SettingType). Passing a key of the wrong type to a typed accessor is a no-op for setters and returns the type's zero value for getters, matching the defensive behaviour of the C++ accessors.

Unlike the C++ version, which keeps its vectors sorted for binary search, this port uses plain hash maps. The semantics (override-or-default, last-write-wins) are identical; only the storage layout differs.

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val size: Int

Total number of overrides currently held.

Functions

Link copied to clipboard
fun clear()

Remove all overrides (port of settings_pack::clear()).

fun clear(name: Int)

Remove the override for a single setting name (port of settings_pack::clear(int)).

Link copied to clipboard
fun forEach(action: (name: Int, value: Any) -> Unit)

Visit every override in this pack (port of settings_pack::for_each). The callback receives the 16-bit key and the value (String, Int or Boolean).

Link copied to clipboard
fun getBool(name: Int): Boolean

The current value of bool setting name: the override if set, otherwise the default.

Link copied to clipboard
fun getInt(name: Int): Int

The current value of int setting name: the override if set, otherwise the default.

Link copied to clipboard
fun getString(name: Int): String

The current value of string setting name: the override if set, otherwise the libtorrent default (which may be the empty string if the default is "no value").

Link copied to clipboard
fun hasVal(name: Int): Boolean

True if name has an explicit override in this pack (port of settings_pack::has_val).

Link copied to clipboard
fun setBool(name: Int, value: Boolean)

Override the bool setting name (a BoolSetting key). No-op if name isn't a bool key.

Link copied to clipboard
fun setInt(name: Int, value: Int)

Override the int setting name (an IntSetting key). No-op if name isn't an int key.

Link copied to clipboard
fun setString(name: Int, value: String)

Override the string setting name (a StringSetting key). No-op if name isn't a string key.