Exemple #1
0
int main()
{
  Hash::DirMap dir;
  dir["world.txt"] = world;
  dirHash2 = Dir::write(dir, "_writer_dir2.out");

  dir["hello.txt"] = hello;
  dirHash = Dir::write(dir, "_writer_dir.out");

  cache.addFile("_writer_dir.out");
  cache.addFile("_writer_dir2.out");
  rules.addURL(hello, "url-to-hello");
  rules.addURL(hello, "other-hello-url", 3, 2);
  rules.addURL(Hash("blah"), "you will never see this");
  rules.addArchive(arcHash2, dirHash2);
  rules.addArchive(arcHash, dirHash);
  rules.addURL(arcHash2, "url-to-arc2", 12, 3.4);
  rules.addURL(arcHash, "url-to-arc");

  lst.addDir("no-hint", dirHash);
  lst.setVersion("no-hint", "1.2.3");
  //lst.addHint("with-hint", arcHash2);
  lst.addDir("with-hint", dirHash);

  ListWriter wrt(cache);

  wrt.write(lst, "_writer/");

  printDir("_writer");

  return 0;
}
Exemple #2
0
void Spread::addRule(RuleSet &rules, const std::string &str)
{
  const char *ptr = str.c_str();

  // Decode rule string
  std::string verb = getNext(ptr);

  if(verb == "URL")
    {
      Hash hash = getHash(ptr);

      int prio;
      float w;
      std::string url;

      decodeURL(ptr, url, prio, w);

      if(hash.isNull() || url == "")
        fail("Invalid URL rule " + str);

       rules.addURL(hash, url, prio, w, str);
    }
  else if(verb == "ARC")
    {
      Hash arcHash = getHash(ptr);
      Hash dirHash = getHash(ptr);

      if(arcHash.isNull() || dirHash.isNull())
        fail("Invalid ARC rule " + str);

      rules.addArchive(arcHash, dirHash, str);
    }

  /* Ignore unknown rule verbs. More rules may be added later as
     optimizations or new sources for obtaining data. Clients who are
     not able to parse these rules should still be allowed to use the
     rules they DO understand.
   */
}