Roxen.git / server / etc / modules / Variable.pmod / module.pmod

version» Context lines:

Roxen.git/server/etc/modules/Variable.pmod/module.pmod:492:       mixed query()    //! Returns the current value for this variable.    {    mixed v;    if( !zero_type( v = changed_values[ _id ] ) )    return v;    return default_value();    }    +  mixed encode() +  //! Returns the current value for this variable encoded for storage. +  //! +  //! The default implementation just returns the value from @[query()]. +  //! +  //! @seealso +  //! @[query()], @[decode()] +  { +  return query(); +  } +  +  int decode(mixed encoded) +  //! Set the variable from the encoded representation +  //! returned by @[encode()]. +  //! +  //! The default implementation just calls @[set()] with the argument. +  //! +  //! @seealso +  //! @[set()], @[decode()] +  { +  return set(encoded); +  } +     int is_defaulted()    //! Return true if this variable is set to it's default value.    {    return zero_type( changed_values[ _id ] ) ||    equal(changed_values[ _id ], default_value());    }       array(string|mixed) verify_set_from_form( mixed new_value )    //! Like verify_set, but only called when the variables are set    //! from a form.
Roxen.git/server/etc/modules/Variable.pmod/module.pmod:899:    }   }      class TmpInt   //! @[Int] that doesn't get saved.   {    inherit Int;    void save() {}   }    + class Priority + //! @[Int] that gets adjusted to the configured range. + { +  inherit Int; +  constant type = "Priority"; +  protected int|NoLimit _max = 9, _min = 0;    -  +  void set_range(int|NoLimit minimum, int|NoLimit maximum ) +  //! Set the range of the variable. +  //! +  //! @note +  //! Also scales the value of the variable accordingly. +  { +  if (_max != maximum) { +  if (!maximum || !_max) { +  set_default_value(0); +  low_set(0); +  } else { +  // Scale the old value. +  int new_val = (query() * maximum)/_max; +  if (new_val < minimum) new_val = minimum; +  int new_default = (default_value() * maximum)/_max; +  set_default_value(new_default); +  low_set(new_val); +  } +  } +  _max = maximum; +  _min = minimum; +  } +  +  string|int encode() +  { +  if (!_max) return 0; +  int ones = _max/9; +  int val = query(); +  if (val % ones) { +  // New-style. +  int digits = sizeof(sprintf("%d", ones)); +  // NB: We pad with zeroes to the field size to encode the +  // field size that was used at encode time. +  return sprintf("%*0d", digits, val); +  } +  // Compat. +  return val / ones; +  } +  +  int decode(string|int encoded) +  { +  if (!_max) { +  return set(0); +  } +  int ones = _max/9; +  if (intp(encoded)) { +  return set(encoded * ones); +  } +  if (encoded == "") { +  // Paranoia check in case someone has modified the config file. +  return set(5 * ones); // Default value. +  } +  // Expand the encoded value to the current field size. +  int digits = sizeof(sprintf("%d", ones)); +  while (sizeof(encoded) < digits) { +  encoded += encoded; +  } +  if (sizeof(encoded) > digits) { +  encoded = encoded[..digits-1]; +  } +  return set(array_sscanf(encoded, "%d")[0]); +  } +  +  LocaleString|string doc() +  { +  return ::doc() + +  sprintf((string)LOCALE(0, "<p>%d is the highest priority and " +  "0 the lowest.</p>"), +  _max); +  } + } +    // =====================================================================   // String   // =====================================================================   class String   //! String variable   {    inherit Variable;    constant type = "String";    int width = 40;    //! The width of the input field. Used by overriding classes.