Branch: Tag:

2002-10-24

2002-10-24 17:53:32 by Martin Stjernholm <mast@lysator.liu.se>

Added RXML.Context.set_id_misc and RXML.Context.set_root_id_misc as
alternatives to set_misc which works better when the value should be
used after the RXML pass has finished.

Rev: server/etc/modules/RXML.pmod/module.pmod:1.300

2:   //   // Created 1999-07-30 by Martin Stjernholm.   // - // $Id: module.pmod,v 1.299 2002/10/22 08:50:57 jonasw Exp $ + // $Id: module.pmod,v 1.300 2002/10/24 17:53:32 mast Exp $      // Kludge: Must use "RXML.refs" somewhere for the whole module to be   // loaded correctly.
1918:    //! Neither @[index] nor @[value] is copied when stored in the    //! cache. That means that you probably don't want to change them    //! destructively, or else those changes can have propagated -  //! "backwards" when the cached p-code is used. +  //! "backwards" when the cached p-code is used. Sometimes that +  //! propagation can be a useful feature, though.    //!    //! @note -  +  //! Use @[set_id_misc] or @[set_root_id_misc] instead of this if you +  //! want to access the stored value after the RXML evaluation has +  //! finished. There is compatibility code that tries to keep +  //! @tt{id->misc->defines@} around for a while afterwards, but it's +  //! not recommended to depend on it since there are circumstances +  //! when the mapping will get overridden. +  //! +  //! @note    //! For compatibility reasons, changes of the _ok flag    //! (@tt{@[misc][" _ok"]@}) are detected and saved automatically.    //! Thus it is not necessary to call @[set_misc] to change it. This
1935:    }    }    +  void set_id_misc (mixed index, mixed value) +  //! Like @[set_misc], but sets a value in @[id->misc], which is +  //! useful if the value should be used by other code after the rxml +  //! evaluation. +  { +  if (value == nil) m_delete (id->misc, index); +  else id->misc[index] = value; +  if (mapping var_chg = misc->variable_changes) +  var_chg[encode_value_canonic (({1, index}))] = value; +  } +  +  void set_root_id_misc (mixed index, mixed value) +  //! Like @[set_id_misc], but sets a value in @[id->root_id->misc] +  //! instead. The difference is that the setting then is visible +  //! throughout the outermost request when the setting is made in an +  //! internal subrequest, e.g. through @[Configuration.try_get_file]. +  { +  if (value == nil) m_delete (id->root_id->misc, index); +  else id->root_id->misc[index] = value; +  if (mapping var_chg = misc->variable_changes) +  var_chg[encode_value_canonic (({2, index}))] = value; +  } +     static int last_internal_var_id = 0;       string alloc_internal_var()
6855:    }    }    -  else { -  // A runtime tag change. Can extend this by looking closer at var[0]. +  else switch (var[0]) { +  case 0: +  // A runtime tag change.   #ifdef DEBUG    if (TAG_DEBUG_TEST (ctx->frame))    TAG_DEBUG (ctx->frame,
6867:    ctx->direct_add_runtime_tag (var[1], tag);    else    ctx->direct_remove_runtime_tag (var[1]); +  break; +  +  case 1: +  // Set in id->misc. + #ifdef DEBUG +  if (TAG_DEBUG_TEST (ctx->frame)) +  TAG_DEBUG (ctx->frame, +  " Installing cached id->misc entry: %s: %s\n", +  format_short (var), format_short (settings[encoded_var])); + #endif +  ctx->set_id_misc (var[1], settings[encoded_var]); +  break; +  +  case 2: +  // Set in root_id->misc. + #ifdef DEBUG +  if (TAG_DEBUG_TEST (ctx->frame)) +  TAG_DEBUG (ctx->frame, +  " Installing cached id->root_id->misc entry: %s: %s\n", +  format_short (var), format_short (settings[encoded_var])); + #endif +  ctx->set_root_id_misc (var[1], settings[encoded_var]);    }       continue handle_var_loop;