コード例 #1
0
ファイル: rdf_storage.c プロジェクト: stefanhusmann/Amaya
/**
 * librdf_new_storage_with_options - Constructor - create a new librdf_storage object
 * @world: redland world object
 * @storage_name: the storage factory name
 * @name: an identifier for the storage
 * @options: &librdf_hash of options to use
 *
 * The options can be NULL if none are required.
 *
 * Return value: a new &librdf_storage object or NULL on failure
 */
librdf_storage*
librdf_new_storage_with_options (librdf_world *world, 
                                 char *storage_name, char *name, 
                                 librdf_hash *options) {
  librdf_storage_factory* factory;
  librdf_hash* options_hash;
  
  factory=librdf_get_storage_factory(storage_name);
  if(!factory)
    return NULL;

  options_hash=librdf_new_hash_from_hash(options);
  if(!options_hash)
    return NULL;

  if(librdf_hash_open(options_hash, NULL, 0, 1, 1, NULL)) {
    librdf_free_hash(options_hash);
    return NULL;
  }
  
  return librdf_new_storage_from_factory(world, factory, name, options_hash);
}
コード例 #2
0
ファイル: example9.c プロジェクト: tejaspathak/librdf
static int test_hash_funtionality(librdf_world *world, librdf_hash *h) {
        librdf_hash *ch;
  const char *test_put_array[]={
      "colour","yellow",
      "age", "new",
      "size", "large",
      "colour", "green",
      "fruit", "banana",
      "colour", "yellow",
  };

  const char *test_delete_array[]={
      "invalidkey", "invalidvalue",
      "colour", "yellow",
      "colour", "aaaaaaaaaaaaainvalidvalue",
      "colour", "zzzzzzzzzzzzzinvalidvalue",
      "colour", NULL,
      "fruit", NULL,
      "size", "large",
      "age", "new",
  };

  const char *test_get_values_for_key="colour";
  int len, i;

  for (i=1; i<=STRESS_TEST_PUT_ITERATION; i++) {
    fprintf(stdout, "put iteration.. %d\n", i);

    /* Test put */
    len = sizeof(test_put_array)/sizeof(const char*);
    test_put(world, h, test_put_array, len);
  }

  fprintf(stdout, "total values: %d.", librdf_hash_values_count(h));

  /* Test get all keys only */
  fprintf(stdout, "all hash keys:");
  librdf_hash_print_keys(h, stdout);
  fputc('\n', stdout);

  /* Test get all values of given key */
  fprintf(stdout, "all values of key '%s'=", test_get_values_for_key);
  librdf_hash_print_values(h, test_get_values_for_key, stdout);
  fputc('\n', stdout);

  /* Test cloning hash */
  fprintf(stdout, "cloning hash\n");
  ch = librdf_new_hash_from_hash(h);
  if(ch) {
    fprintf(stdout, "clone success. values count %d\n", librdf_hash_values_count(ch));
    fprintf(stdout, "resulting: ");
    librdf_hash_print(ch, stdout);
    fputc('\n', stdout);

    librdf_hash_close(ch);
    librdf_free_hash(ch);
  } else {
    fprintf(stderr, "Failed to clone hash\n");
  }

  /* Test delete */
  len = sizeof(test_delete_array)/sizeof(const char*);
  test_delete(world, h, test_delete_array, len);

  /* Test string related features */
  test_string_manipulation(world, h);

  return 0;
}