Esempio n. 1
0
	void Compare(const po::variables_map& variables, int& retcode)
	{
		retcode = 1;

		std::vector<std::wstring> inputs;
		if (variables.count("input"))
			inputs = variables["input"].as<std::vector<std::wstring>>();

		if (inputs.size() != 2)
		{
			std::wcerr << L"Error parsing options: must have 2 input files." << std::endl;
			return;
		}

		auto out = OpenOutput<wchar_t>(variables);
		if (!out) 
			return;

		bool fast = variables["fast"].as<bool>();
		bool noHeuristics = variables["no-heuristics"].as<bool>();
		bool verbose = variables["verbose"].as<bool>();
		bool tlbTimestamp = variables["tlb-timestamp"].as<bool>();

		BlockList ignoredRanges = boost::lexical_cast<BlockList>(variables["r"].as<std::wstring>());
		BlockList ignoredRanges1 = boost::lexical_cast<BlockList>(variables["r1"].as<std::wstring>());
		BlockList ignoredRanges2 = boost::lexical_cast<BlockList>(variables["r2"].as<std::wstring>());

		PEParser pe1(inputs[0]);
		PEParser pe2(inputs[1]);

		pe1.AddIgnoredRange(ignoredRanges1);
		pe1.AddIgnoredRange(ignoredRanges);
		pe2.AddIgnoredRange(ignoredRanges2);
		pe2.AddIgnoredRange(ignoredRanges);

		pe1.Open();
		pe2.Open();

		*out
			<< inputs[0] << L":\n\n" << pe1
			<< inputs[1] << L":\n\n" << pe2
			<< std::endl;

		auto result = PEParser::Compare(pe1, pe2, fast, noHeuristics, verbose, tlbTimestamp);

		*out << result << std::endl;

		bool success = false;

		bool identical = variables["identical"].as<bool>();
		if (identical)
			success = result.IsIdentical();
		else
			success = result.IsEquivalent();

		retcode = (success) ? 0 : 1;
	}
int main(int argc, const char** argv) {
  std::unique_ptr<Shape> pr1(new Rectangle);
  std::unique_ptr<Shape> pr2(new Rectangle);
  std::unique_ptr<Shape> pe1(new Ellipse);
  std::unique_ptr<Shape> pe2(new Ellipse);
  std::unique_ptr<Shape> pt(new Triangle);

  std::cout << "Dynamic type dispatch\n";

  LOG(pr1->Intersect(pe1.get()));
  LOG(pe1->Intersect(pr1.get()));
  LOG(pr1->Intersect(pr2.get()));

  // Here the dispatch is routed to Shape, since Ellipse doesn't define
  // intersections with ellipses.
  LOG(pe1->Intersect(pe2.get()));

  // Since Rectangle and Triangle don't define intersection ops with each other,
  // these calls are routed to Shape.
  LOG(pr1->Intersect(pt.get()));
  LOG(pt->Intersect(pr1.get()));

  return 0;
}