示例#1
0
static const char *current_(const char *profile, const char *key)
{
  static const char general[] = "general";

  /* - - - - - - - - - - - - - - - - - - - *
   * profile lookup order:
   * 1. config: "override"
   * 2. custom: caller provided
   * 3. config: caller provided
   * 4. custom: "general"
   * 5. config: "general"
   * 6. config: "fallback"
   * - - - - - - - - - - - - - - - - - - - */

  const char *res = 0;

  if( (res = override_(key)) )
  {
    // have override value
    goto cleanup;
  }

  if( !xstrnull(res = custom_(profile, key)) )
  {
    // have non-empty custom value for requested profile
    goto cleanup;
  }

  if( (res = config_(profile, key)) )
  {
    // have non-empty default value for requested profile
    goto cleanup;
  }

  if( !xstrsame(profile, general) )
  {
    if( !xstrnull(res = custom_(general, key)) )
    {
      // have non-empty custom value for general profile
      goto cleanup;
    }
    if( (res = config_(general, key)) )
    {
      // have non-empty default value for general profile
      goto cleanup;
    }
  }

  // use the fallback value
  res = fallback_(key);

cleanup:

  return res;
}
示例#2
0
// Executes the function matching the given string name. Throws if not defined.
void
Library::exec(std::string const& cmd, void* arg)
{
  if (cmd == "pipeline")
    pipeline_((Context*)arg);
  else if (cmd == "config")
    config_();
  else if (cmd == "ports")
    port_(arg);
  else
    throw std::string("Application library error: Unknown command '" +
      cmd + "'");
}