idmap2: move Idmap.h to Result

Change the signatures of Idmap::FromApkAssets and
Idmap::FromBinaryStream from

  std::unique_ptr<const Idmap> func(..., std::ostream& out_error);

to

  Result<std::unique_ptr<const Idmap>> func(...);

The returned pointer is still a unique pointer to ensure the dynamically
allocated memory is automatically released when no longer used. This
means that using the returned value of either function requires one of
two patterns:

  const auto idmap = func(...);
  if (!idmap) {
    return Error(...);
  }
  (*idmap)->accept(...);

or

  auto result = func(...);
  if (!result) {
    return Error(...);
  }
  const auto idmap = std::move(*result);
  idmap->accept(...);

Note that in the second example, result must be non-const or
the call to std::move(*result) will not compile.

With this change, the entire idmap2 project has been converted to use
Result.

Test: make idmap2_tests
Change-Id: I533f4e03b99645523d94dd5f446ad76fb435f661
diff --git a/cmds/idmap2/idmap2d/Idmap2Service.cpp b/cmds/idmap2/idmap2d/Idmap2Service.cpp
index e03a9cc..4f65379 100644
--- a/cmds/idmap2/idmap2d/Idmap2Service.cpp
+++ b/cmds/idmap2/idmap2d/Idmap2Service.cpp
@@ -138,12 +138,10 @@
     return error("failed to load apk " + overlay_apk_path);
   }
 
-  std::stringstream err;
-  const std::unique_ptr<const Idmap> idmap =
-      Idmap::FromApkAssets(target_apk_path, *target_apk, overlay_apk_path, *overlay_apk,
-                           policy_bitmask, enforce_overlayable, err);
+  const auto idmap = Idmap::FromApkAssets(target_apk_path, *target_apk, overlay_apk_path,
+                                          *overlay_apk, policy_bitmask, enforce_overlayable);
   if (!idmap) {
-    return error(err.str());
+    return error(idmap.GetErrorMessage());
   }
 
   umask(kIdmapFilePermissionMask);
@@ -152,7 +150,7 @@
     return error("failed to open idmap path " + idmap_path);
   }
   BinaryStreamVisitor visitor(fout);
-  idmap->accept(&visitor);
+  (*idmap)->accept(&visitor);
   fout.close();
   if (fout.fail()) {
     return error("failed to write to idmap path " + idmap_path);