Beispiel #1
0
int main()
{
  universe *u = new universe("patterns");
  list *colors = new list(u);
  list *names = new list(u);
  list *grids = new list(u);
  grid *g;
  color24 *c24;

  char *s2 = new char[100], *s, *s3, *s4 = new char[100];
  int rows, cols;
  strcpy(s2, "../A/patterns/");
  s = s2 + strlen(s2);
  ifstream in ("../A/data/patterns");
  in >> s;

  while (!in.eof()) {
    names->enqueue((item *) new ascii(u, s));
    s3 = s + strlen(s);
    strcpy(s3, ".A");
    ifstream in2 (s2);
    in2 >> rows >> cols >> s4;
cout << "Opening \"" << s2 << "\" (" << rows << ", " << cols << ", " << s4 << ")." << endl;
cout.flush();
    c24 = new color24(s4);
    g = new grid(u, find_or_create(u, colors, c24), rows, cols);
    grids->enqueue((item *) g);
    delete c24;
    for (int i=0; i<rows; i++) {
      for (int j=0; j<cols; j++) {
        in2 >> s4;
        c24 = new color24(s4);
        g->set(i, j, find_or_create(u, colors, c24));
        delete c24;
      }
    }
    in2.close();
    in >> s;
  }
  in.close();

  //*/

  ofstream out ("patterns");
  u->serialize(out);
  out.close();

  //*/

  delete u;
}
Beispiel #2
0
/* step 1: create the containers, connect them, and fill the id_table */
static GHashTable*
create_containers (MuMsgIter *iter)
{
	GHashTable *id_table;
	id_table = g_hash_table_new_full (g_str_hash, g_str_equal,
					  NULL,
					  (GDestroyNotify)mu_container_destroy);

	for (mu_msg_iter_reset (iter); !mu_msg_iter_is_done (iter);
	     mu_msg_iter_next (iter)) {

		MuContainer *c;
		MuMsg *msg;
		unsigned docid;

		/* 1.A */
		msg   = mu_msg_iter_get_msg_floating (iter); /* don't unref */
		docid = mu_msg_iter_get_docid (iter);

		c = find_or_create (id_table, msg, docid);

		/* 1.B and C */
		if (c)
			handle_references (id_table, c);
	}

	return id_table;
}
Beispiel #3
0
static void test5()
{
	auto m=LIBCXX_NAMESPACE::mcguffinmap
		<int, LIBCXX_NAMESPACE::ref<valueObj>>::create();

	auto v=LIBCXX_NAMESPACE::ref<valueObj>::create();

	std::vector<LIBCXX_NAMESPACE::ref<LIBCXX_NAMESPACE::obj>> mcguffin;

	mcguffin.push_back(m->insert(0, v));

	auto b=m->begin();

	std::cout << "test5: null: " << b->second.getptr().null() << std::endl;
	mcguffin.clear();
	std::cout << "test5: null: " << b->second.getptr().null() << std::endl;
	std::cout << "test5: size: " << m->size() << std::endl;

	auto ret=m->find_or_create(0, [&v]
				   {
					   return v;
				   });

	std::cout << "test5: nulls: " << ret.first.null()
		  << ", " << ret.second.null() << std::endl;
}
Beispiel #4
0
static void test4u()
{
	typedef LIBCXX_NAMESPACE::mcguffinmultimap
		<int, LIBCXX_NAMESPACE::ref<valueObj>> map_t;

	test34_common<map_t>("test4u: ");

	auto m=map_t::create();

	{
		std::vector<LIBCXX_NAMESPACE::ref<valueObj>> v;

		v.push_back(LIBCXX_NAMESPACE::ref<valueObj>::create());

		auto mcguffin=m->insert(std::make_pair(0, v.front()));

		std::cout << "test4u: this should be 0: "
			  << m->insert(std::make_pair(0, v.front())).null()
			  << std::endl;

		std::cout << "test4u: this should be 0: "
			  << m->insert(std::make_pair(1, v.front())).null()
			  << std::endl;
		v.clear();

		for (const auto &v:*m)
		{
			std::cout << "test4u: remaining key " << v.first
				  << std::flush
				  << " value: " << v.second.getptr()->v_proof
				  << std::endl;
		}
	}

	std::vector<LIBCXX_NAMESPACE::ptr<LIBCXX_NAMESPACE::obj>> save_mcguffin;

	{
		auto v=LIBCXX_NAMESPACE::ref<valueObj>::create();

		auto mcguffin1=m->find_or_create(0, [&v]
						 {
							 return v;
						 });

		auto mcguffin2=m->find_or_create(0, [&v]
						 {
							 return v;
						 });

		for (const auto &v:*m)
		{
			std::cout << "test4u: after find_or_create: " << v.first
				  << std::flush
				  << " value: " << v.second.getptr()->v_proof
				  << std::endl;

			auto p=v.second.mcguffin();

			std::cout << "test4u: mcguffin.null() should be 0: "
				  << p.null() << std::endl;
			save_mcguffin.push_back(p);
		}
	}

	for (const auto &v:*m)
	{
		std::cout << "test4u: mcguffin should exist: " << v.first
			  << std::flush
			  << " value: " << v.second.getptr()->v_proof
				  << std::endl;

		save_mcguffin.clear();

		std::cout << "test4u: mcguffin should work: " << v.first
			  << std::flush
			  << " null: " << v.second.getptr().null()
			  << std::endl;
	}
}