Пример #1
0
/** Get the value of a numeric (floating point) setting
 *
 * @param cszName the name of the setting to retrieve
 * @param alternate the alternative value to use on error or missing.
 *
 * @return the current value of the setting or the alternate value if the
 *         setting is not defined or not of the expected type.
 */
double Settings::getNumber(const char *cszName, double alternate) {
  SettingDescription setting;
  if (findSetting(m_pActive, m_size, cszName, setting)<0)
    return alternate;
  if ((setting.typeAndModifier & SETTING_TYPE_MASK) != NumberSetting)
    return alternate;
  return setting.value.number;
  }
Пример #2
0
/** Get the value of a boolean setting
 *
 * @param cszName the name of the setting to retrieve
 * @param alternate the alternative value to use on error or missing.
 *
 * @return the current value of the setting or the alternate value if the
 *         setting is not defined or not of the expected type.
 */
bool Settings::getBoolean(const char *cszName, bool alternate) {
  SettingDescription setting;
  if (findSetting(m_pActive, m_size, cszName, setting)<0)
    return alternate;
  if ((setting.typeAndModifier & SETTING_TYPE_MASK) != BooleanSetting)
    return alternate;
  return setting.value.boolean;
  }
Пример #3
0
/** Get the value of an integer setting
 *
 * @param cszName the name of the setting to retrieve
 * @param alternate the alternative value to use on error or missing.
 *
 * @return the current value of the setting or the alternate value if the
 *         setting is not defined or not of the expected type.
 */
int Settings::getInteger(const char *cszName, int alternate) {
  SettingDescription setting;
  if (findSetting(m_pActive, m_size, cszName, setting)<0)
    return alternate;
  if ((setting.typeAndModifier & SETTING_TYPE_MASK) != IntegerSetting)
    return alternate;
  return setting.value.integer;
  }
Пример #4
0
/** Get the value of a string setting
 *
 * @param cszName the name of the setting to retrieve
 * @param cszAlternate the alternative value to use on error or missing.
 *
 * @return the current value of the setting or the alternate value if the
 *         setting is not defined or not of the expected type.
 */
const char *Settings::getString(const char *cszName, const char *cszAlternate) {
  SettingDescription setting;
  if (findSetting(m_pActive, m_size, cszName, setting)<0)
    return cszAlternate;
  if ((setting.typeAndModifier & SETTING_TYPE_MASK) != StringSetting)
    return cszAlternate;
  return setting.value.string;
  }
Пример #5
0
const char *getSetting(const char *key)
{
	struct Setting *setting = findSetting(key);

	if (setting == NULL)
		return NULL;

	return setting->value;
}
Пример #6
0
/** Set the value of a boolean setting
 *
 * @param cszName the name of the setting to modify
 * @param value the new value for the setting
 *
 * @return true on success, false if the setting is of the wrong type
 *         or the buffer is not large enough to contain the new value.
 */
bool Settings::setBoolean(const char *cszName, bool value) {
  SettingDescription setting;
  if (findSetting(m_pActive, m_size, cszName, setting)<0)
    return false;
  if ((setting.typeAndModifier & SETTING_TYPE_MASK) != BooleanSetting)
    return false;
  setting.value.boolean = value;
  // Now clone with the new value
  unsigned char *pBackup = getInactive(m_pBuffer1, m_pBuffer2, m_pActive);
  int result = cloneWithChange(m_pActive, pBackup, m_size, setting);
  if (result>0) {
    m_pActive = pBackup;
    m_used = result;
    return true;
    }
  return false;
  }
Пример #7
0
void registerSetting(const char *key, const char *defaultValue, SettingCB cb)
{
	struct Setting *setting;

	if ((setting = findSetting(key)) != NULL) {
		sgLogError("setting %s redefined", key);
		return;
	} else {
		sgLogDebug("register setting '%s', default '%s'", key, defaultValue);
		setting = newSetting(key, defaultValue);
		setting->defaultValue = defaultValue ? sgStrdup(defaultValue) : NULL;
		setting->cb = cb;

		if (setting->cb && defaultValue)
			setting->cb(defaultValue);
	}
}
Пример #8
0
void setSetting(const char *key, const char *value)
{
	struct Setting *setting;

	sgLogDebug("set setting '%s', value '%s'", key, value);

	if ((setting = findSetting(key)) == NULL) {
		sgLogWarn("setting '%s' is not registered (value='%s')", key, value);
		setting = newSetting(key, value);
	} else {
		sgFree(setting->value);
		setting->value = sgStrdup(value);
	}

	if (setting->cb)
		setting->cb(value);
}