Rename tensorflow_statusor to statusor for ergonomic reasons.
Change-Id: Ie26adb36a456cb4afbf96ca06eef7031eea31fed
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0fc2807..ade217c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -735,6 +735,6 @@
# Third-party directories that we include using the simpler add_subdirectory method
add_subdirectory(third_party/abseil-cpp)
-add_subdirectory(third_party/tensorflow_statusor)
+add_subdirectory(third_party/statusor)
add_subdirectory(third_party/rapidjson)
add_subdirectory(third_party/tink)
diff --git a/config/validation/BUILD.gn b/config/validation/BUILD.gn
index 71ea6f6..2c415d7 100644
--- a/config/validation/BUILD.gn
+++ b/config/validation/BUILD.gn
@@ -11,7 +11,7 @@
public_deps = [
"//third_party/cobalt/config:cobalt_registry_proto",
- "//third_party/cobalt/third_party/tensorflow_statusor:statusor",
+ "//third_party/cobalt/third_party/statusor:statusor",
]
}
diff --git a/config/validation/CMakeLists.txt b/config/validation/CMakeLists.txt
index 882c1be..12a54b7 100644
--- a/config/validation/CMakeLists.txt
+++ b/config/validation/CMakeLists.txt
@@ -6,7 +6,7 @@
# across cobalt.
add_library(validator valid_cobalt_config.cc)
add_cobalt_dependencies(validator)
-target_link_libraries(validator tensorflow_statusor)
+target_link_libraries(validator statusor)
add_executable(validate validate_main.cc)
target_link_libraries(validate validator)
diff --git a/config/validation/valid_cobalt_config.cc b/config/validation/valid_cobalt_config.cc
index 9f3358c..06ebc90 100644
--- a/config/validation/valid_cobalt_config.cc
+++ b/config/validation/valid_cobalt_config.cc
@@ -7,7 +7,7 @@
#include <utility>
#include "config/validation/valid_cobalt_config.h"
-#include "third_party/tensorflow_statusor/statusor.h"
+#include "third_party/statusor/statusor.h"
namespace cobalt {
namespace config {
diff --git a/config/validation/valid_cobalt_config.h b/config/validation/valid_cobalt_config.h
index 48eb4c2..2830e22 100644
--- a/config/validation/valid_cobalt_config.h
+++ b/config/validation/valid_cobalt_config.h
@@ -8,13 +8,13 @@
#include <memory>
#include "config/cobalt_registry.pb.h"
-#include "third_party/tensorflow_statusor/statusor.h"
+#include "third_party/statusor/statusor.h"
namespace cobalt {
namespace config {
namespace validation {
-using tensorflow_statusor::StatusOr;
+using statusor::StatusOr;
// This represents a validated CobaltRegistry object. If the StatusOr returned
// from GetValidCobaltRegistry is a ValidCobaltRegistry then the provided
diff --git a/encoder/file_observation_store.cc b/encoder/file_observation_store.cc
index 2f8323c..ee21a52 100644
--- a/encoder/file_observation_store.cc
+++ b/encoder/file_observation_store.cc
@@ -14,7 +14,7 @@
namespace cobalt {
namespace encoder {
-using tensorflow_statusor::StatusOr;
+using statusor::StatusOr;
using util::FileSystem;
using util::Status;
using util::StatusCode;
diff --git a/encoder/file_observation_store.h b/encoder/file_observation_store.h
index fb2fe2b..a9b7959 100644
--- a/encoder/file_observation_store.h
+++ b/encoder/file_observation_store.h
@@ -17,7 +17,7 @@
#include "encoder/envelope_maker.h"
#include "encoder/observation_store.h"
#include "third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl.h"
-#include "third_party/tensorflow_statusor/statusor.h"
+#include "third_party/statusor/statusor.h"
#include "util/file_system.h"
#include "util/protected_fields.h"
@@ -136,7 +136,7 @@
// GetOldestFinalizedFile returns a file name for the oldest file in the
// store.
- tensorflow_statusor::StatusOr<std::string> GetOldestFinalizedFile(
+ statusor::StatusOr<std::string> GetOldestFinalizedFile(
util::ProtectedFields<Fields>::LockedFieldsPtr *fields);
// GenerateFinalizedName returns an absolute path that can be used for
diff --git a/encoder/shipping_manager_test.cc b/encoder/shipping_manager_test.cc
index b28d9b2..49c5176 100644
--- a/encoder/shipping_manager_test.cc
+++ b/encoder/shipping_manager_test.cc
@@ -33,7 +33,7 @@
using config::ClientConfig;
using send_retryer::CancelHandle;
using send_retryer::SendRetryer;
-using tensorflow_statusor::StatusOr;
+using statusor::StatusOr;
using util::EncryptedMessageMaker;
namespace {
diff --git a/logger/CMakeLists.txt b/logger/CMakeLists.txt
index 9034cdf..489a5d7 100644
--- a/logger/CMakeLists.txt
+++ b/logger/CMakeLists.txt
@@ -21,7 +21,7 @@
target_link_libraries(project_context
local_aggregation_proto_lib)
add_cobalt_dependencies(project_context)
-target_link_libraries(project_context project_configs tensorflow_statusor)
+target_link_libraries(project_context project_configs statusor)
add_library(observation_writer
observation_writer.cc)
diff --git a/logger/project_context.cc b/logger/project_context.cc
index f65a945..3dfaa4c 100644
--- a/logger/project_context.cc
+++ b/logger/project_context.cc
@@ -11,7 +11,7 @@
namespace cobalt {
namespace logger {
-using tensorflow_statusor::StatusOr;
+using statusor::StatusOr;
using util::StatusCode;
std::string MetricDebugString(const MetricDefinition& metric) {
diff --git a/logger/project_context.h b/logger/project_context.h
index 3c8e115..47c0c68 100644
--- a/logger/project_context.h
+++ b/logger/project_context.h
@@ -14,7 +14,7 @@
#include "config/project.pb.h"
#include "config/project_configs.h"
#include "logger/status.h"
-#include "third_party/tensorflow_statusor/statusor.h"
+#include "third_party/statusor/statusor.h"
namespace cobalt {
namespace logger {
@@ -64,7 +64,7 @@
//
// If either the customer or the project are not found in the supplied
// ProjectConfigs, then this will return an INVALID_ARGUMENT error.
- static tensorflow_statusor::StatusOr<std::unique_ptr<ProjectContext>>
+ static statusor::StatusOr<std::unique_ptr<ProjectContext>>
ConstructWithProjectConfigs(
const std::string& customer_name, const std::string& project_name,
std::shared_ptr<config::ProjectConfigs> project_configs,
diff --git a/third_party/clearcut/BUILD.gn b/third_party/clearcut/BUILD.gn
index b7bf2a3..6467e4b 100644
--- a/third_party/clearcut/BUILD.gn
+++ b/third_party/clearcut/BUILD.gn
@@ -23,6 +23,6 @@
public_deps = [
":clearcut_proto",
"//third_party/abseil-cpp",
- "//third_party/cobalt/third_party/tensorflow_statusor:statusor",
+ "//third_party/cobalt/third_party/statusor:statusor",
]
}
diff --git a/third_party/clearcut/CMakeLists.txt b/third_party/clearcut/CMakeLists.txt
index 56d4b6a..b7d7e9e 100644
--- a/third_party/clearcut/CMakeLists.txt
+++ b/third_party/clearcut/CMakeLists.txt
@@ -91,7 +91,7 @@
uploader.cc)
target_link_libraries(clearcut
absl::strings clearcut_proto_lib
- tensorflow_statusor status)
+ statusor status)
add_executable(clearcut_tests
diff --git a/third_party/clearcut/http_client.h b/third_party/clearcut/http_client.h
index bf3361b..327e7fb 100644
--- a/third_party/clearcut/http_client.h
+++ b/third_party/clearcut/http_client.h
@@ -8,13 +8,13 @@
#include <future>
#include <map>
-#include "third_party/tensorflow_statusor/statusor.h"
+#include "third_party/statusor/statusor.h"
#include "util/status.h"
namespace clearcut {
using cobalt::util::Status;
-using tensorflow_statusor::StatusOr;
+using statusor::StatusOr;
// HTTPResponse contains the response from the server.
//
diff --git a/third_party/clearcut/uploader.cc b/third_party/clearcut/uploader.cc
index c8602d4..0a24107 100644
--- a/third_party/clearcut/uploader.cc
+++ b/third_party/clearcut/uploader.cc
@@ -8,7 +8,7 @@
#include "glog/logging.h"
#include "third_party/clearcut/clearcut.pb.h"
#include "third_party/clearcut/uploader.h"
-#include "third_party/tensorflow_statusor/status_macros.h"
+#include "third_party/statusor/status_macros.h"
#include "unistd.h"
namespace clearcut {
diff --git a/third_party/clearcut/uploader.h b/third_party/clearcut/uploader.h
index 0de47df..8c40fa7 100644
--- a/third_party/clearcut/uploader.h
+++ b/third_party/clearcut/uploader.h
@@ -12,7 +12,7 @@
#include "third_party/abseil-cpp/absl/strings/escaping.h"
#include "third_party/clearcut/clearcut.pb.h"
#include "third_party/clearcut/http_client.h"
-#include "third_party/tensorflow_statusor/statusor.h"
+#include "third_party/statusor/statusor.h"
#include "util/status.h"
namespace clearcut {
diff --git a/third_party/statusor/BUILD.gn b/third_party/statusor/BUILD.gn
new file mode 100644
index 0000000..567323d
--- /dev/null
+++ b/third_party/statusor/BUILD.gn
@@ -0,0 +1,21 @@
+# Copyright 2018 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+static_library("statusor") {
+ sources = [
+ "status_macros.cc",
+ "status_macros.h",
+ "statusor.cc",
+ "statusor.h",
+ "statusor_internals.h",
+ ]
+
+ public_configs = [ "//third_party/cobalt:cobalt_config" ]
+
+ public_deps = [
+ "//third_party/cobalt/util:status",
+ "//third_party/glog:glog",
+ "//third_party/protobuf:protobuf_lite",
+ ]
+}
diff --git a/third_party/statusor/CMakeLists.txt b/third_party/statusor/CMakeLists.txt
new file mode 100644
index 0000000..d1fbc33
--- /dev/null
+++ b/third_party/statusor/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_library(statusor statusor.cc status_macros.cc)
+add_cobalt_dependencies(statusor status)
diff --git a/third_party/tensorflow_statusor/COBALT_README.md b/third_party/statusor/COBALT_README.md
similarity index 70%
rename from third_party/tensorflow_statusor/COBALT_README.md
rename to third_party/statusor/COBALT_README.md
index 48cecbc..c09bcbf 100644
--- a/third_party/tensorflow_statusor/COBALT_README.md
+++ b/third_party/statusor/COBALT_README.md
@@ -1,12 +1,12 @@
-# tensorflow_statusor::StatusOr
+# statusor::StatusOr
This is a copy of the StatusOr library from tensorflow.
You can find the original source of these files at:
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/compiler/xla
If you want to update the libraries, replace the xla namespace with
-tensorflow_statusor, and fix the includes to replace tensorflow/compiler/xla/
-with third_party/tensorflow_statusor. We also use grpc::Status instead of
+statusor, and fix the includes to replace tensorflow/compiler/xla/
+with third_party/statusor. We also use grpc::Status instead of
tensorflow's status class. The final change is to remove references to the TF_*
macros that cobalt does not use.
diff --git a/third_party/tensorflow_statusor/LICENSE b/third_party/statusor/LICENSE
similarity index 100%
rename from third_party/tensorflow_statusor/LICENSE
rename to third_party/statusor/LICENSE
diff --git a/third_party/tensorflow_statusor/README.md b/third_party/statusor/README.md
similarity index 100%
rename from third_party/tensorflow_statusor/README.md
rename to third_party/statusor/README.md
diff --git a/third_party/tensorflow_statusor/status_macros.cc b/third_party/statusor/status_macros.cc
similarity index 97%
rename from third_party/tensorflow_statusor/status_macros.cc
rename to third_party/statusor/status_macros.cc
index 0c2d6ed..ca554de 100644
--- a/third_party/tensorflow_statusor/status_macros.cc
+++ b/third_party/statusor/status_macros.cc
@@ -13,7 +13,7 @@
limitations under the License.
==============================================================================*/
-#include "third_party/tensorflow_statusor/status_macros.h"
+#include "third_party/statusor/status_macros.h"
#include "util/status.h"
#include <google/protobuf/stubs/strutil.h>
@@ -21,7 +21,7 @@
#include "glog/logging.h"
-namespace tensorflow_statusor {
+namespace statusor {
namespace status_macros {
using cobalt::util::Status;
@@ -164,4 +164,4 @@
}
} // namespace status_macros
-} // namespace tensorflow_statusor
+} // namespace statusor
diff --git a/third_party/tensorflow_statusor/status_macros.h b/third_party/statusor/status_macros.h
similarity index 96%
rename from third_party/tensorflow_statusor/status_macros.h
rename to third_party/statusor/status_macros.h
index 4938c15..7e80b08 100644
--- a/third_party/tensorflow_statusor/status_macros.h
+++ b/third_party/statusor/status_macros.h
@@ -13,8 +13,8 @@
limitations under the License.
==============================================================================*/
-#ifndef TENSORFLOW_COMPILER_XLA_STATUS_MACROS_H_
-#define TENSORFLOW_COMPILER_XLA_STATUS_MACROS_H_
+#ifndef THIRD_PARTY_STATUSOR_STATUS_MACROS_H_
+#define THIRD_PARTY_STATUSOR_STATUS_MACROS_H_
#include <memory>
#include <ostream> // NOLINT
@@ -23,9 +23,9 @@
#include <utility>
#include <vector>
-#include "third_party/tensorflow_statusor/statusor.h"
+#include "third_party/statusor/statusor.h"
-namespace tensorflow_statusor {
+namespace statusor {
namespace status_macros {
using cobalt::util::Status;
@@ -169,7 +169,7 @@
};
} // namespace status_macros
-} // namespace tensorflow_statusor
+} // namespace statusor
#define CB_RET_CHECK(condition) \
while (!(condition)) \
@@ -202,4 +202,4 @@
} \
lhs = std::move(statusor.ValueOrDie())
-#endif // TENSORFLOW_COMPILER_XLA_STATUS_MACROS_H_
+#endif // THIRD_PARTY_STATUSOR_STATUS_MACROS_H_
diff --git a/third_party/tensorflow_statusor/statusor.cc b/third_party/statusor/statusor.cc
similarity index 90%
rename from third_party/tensorflow_statusor/statusor.cc
rename to third_party/statusor/statusor.cc
index 257c3f7..6e75273 100644
--- a/third_party/tensorflow_statusor/statusor.cc
+++ b/third_party/statusor/statusor.cc
@@ -13,11 +13,11 @@
limitations under the License.
==============================================================================*/
-#include "third_party/tensorflow_statusor/statusor.h"
+#include "third_party/statusor/statusor.h"
#include "glog/logging.h"
#include "util/status.h"
-namespace tensorflow_statusor {
+namespace statusor {
namespace internal_statusor {
void Helper::HandleInvalidStatusCtorArg(Status* status) {
@@ -34,4 +34,4 @@
}
} // namespace internal_statusor
-} // namespace tensorflow_statusor
+} // namespace statusor
diff --git a/third_party/statusor/statusor.h b/third_party/statusor/statusor.h
new file mode 100644
index 0000000..9ac561f
--- /dev/null
+++ b/third_party/statusor/statusor.h
@@ -0,0 +1,318 @@
+/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+==============================================================================*/
+
+// StatusOr<T> is the union of a Status object and a T
+// object. StatusOr models the concept of an object that is either a
+// usable value, or an error Status explaining why such a value is
+// not present. To this end, StatusOr<T> does not allow its Status
+// value to be Status::OK. Furthermore, the value of a StatusOr<T*>
+// must not be null. This is enforced by a debug check in most cases,
+// but even when it is not, clients must not set the value to null.
+//
+// The primary use-case for StatusOr<T> is as the return value of a
+// function which may fail.
+//
+// Example client usage for a StatusOr<T>, where T is not a pointer:
+//
+// StatusOr<float> result = DoBigCalculationThatCouldFail();
+// if (result.ok()) {
+// float answer = result.ValueOrDie();
+// printf("Big calculation yielded: %f", answer);
+// } else {
+// LOG(ERROR) << result.status();
+// }
+//
+// Example client usage for a StatusOr<T*>:
+//
+// StatusOr<Foo*> result = FooFactory::MakeNewFoo(arg);
+// if (result.ok()) {
+// std::unique_ptr<Foo> foo(result.ValueOrDie());
+// foo->DoSomethingCool();
+// } else {
+// LOG(ERROR) << result.status();
+// }
+//
+// Example client usage for a StatusOr<std::unique_ptr<T>>:
+//
+// StatusOr<std::unique_ptr<Foo>> result = FooFactory::MakeNewFoo(arg);
+// if (result.ok()) {
+// std::unique_ptr<Foo> foo = std::move(result.ValueOrDie());
+// foo->DoSomethingCool();
+// } else {
+// LOG(ERROR) << result.status();
+// }
+//
+// Example factory implementation returning StatusOr<T*>:
+//
+// StatusOr<Foo*> FooFactory::MakeNewFoo(int arg) {
+// if (arg <= 0) {
+// return tensorflow::InvalidArgument("Arg must be positive");
+// } else {
+// return new Foo(arg);
+// }
+// }
+//
+// Note that the assignment operators require that destroying the currently
+// stored value cannot invalidate the argument; in other words, the argument
+// cannot be an alias for the current value, or anything owned by the current
+// value.
+#ifndef THIRD_PARTY_STATUSOR_STATUSOR_H_
+#define THIRD_PARTY_STATUSOR_STATUSOR_H_
+
+#include <utility>
+#include "third_party/statusor/statusor_internals.h"
+#include "util/status.h"
+
+namespace statusor {
+
+using cobalt::util::Status;
+
+template <typename T>
+class StatusOr : private internal_statusor::StatusOrData<T>,
+ private internal_statusor::TraitsBase<
+ std::is_copy_constructible<T>::value,
+ std::is_move_constructible<T>::value> {
+ template <typename U>
+ friend class StatusOr;
+
+ typedef internal_statusor::StatusOrData<T> Base;
+
+ public:
+ typedef T element_type;
+
+ // Constructs a new StatusOr with Status::UNKNOWN status. This is marked
+ // 'explicit' to try to catch cases like 'return {};', where people think
+ // StatusOr<std::vector<int>> will be initialized with an empty vector,
+ // instead of a Status::UNKNOWN status.
+ explicit StatusOr(); // NOLINT(runtime/explicit)
+
+ // StatusOr<T> will be copy constructible/assignable if T is copy
+ // constructible.
+ StatusOr(const StatusOr&) = default;
+ StatusOr& operator=(const StatusOr&) = default;
+
+ // StatusOr<T> will be move constructible/assignable if T is move
+ // constructible.
+ StatusOr(StatusOr&&) = default;
+ StatusOr& operator=(StatusOr&&) = default;
+
+ // Conversion copy/move constructor, T must be convertible from U.
+ // TODO(b/62186717): These should not participate in overload resolution if U
+ // is not convertible to T.
+ template <typename U>
+ StatusOr(const StatusOr<U>& other);
+ template <typename U>
+ StatusOr(StatusOr<U>&& other);
+
+ // Conversion copy/move assignment operator, T must be convertible from U.
+ template <typename U>
+ StatusOr& operator=(const StatusOr<U>& other);
+ template <typename U>
+ StatusOr& operator=(StatusOr<U>&& other);
+
+ // Constructs a new StatusOr with the given value. After calling this
+ // constructor, calls to ValueOrDie() will succeed, and calls to status() will
+ // return OK.
+ //
+ // NOTE: Not explicit - we want to use StatusOr<T> as a return type
+ // so it is convenient and sensible to be able to do 'return T()'
+ // when the return type is StatusOr<T>.
+ //
+ // REQUIRES: T is copy constructible.
+ StatusOr(const T& value); // NOLINT(runtime/explicit)
+
+ // Constructs a new StatusOr with the given non-ok status. After calling
+ // this constructor, calls to ValueOrDie() will CHECK-fail.
+ //
+ // NOTE: Not explicit - we want to use StatusOr<T> as a return
+ // value, so it is convenient and sensible to be able to do 'return
+ // Status()' when the return type is StatusOr<T>.
+ //
+ // REQUIRES: !status.ok(). This requirement is DCHECKed.
+ // In optimized builds, passing Status::OK here will have the effect
+ // of passing tensorflow::error::INTERNAL as a fallback.
+ StatusOr(const Status& status); // NOLINT(runtime/explicit)
+ StatusOr& operator=(const Status& status);
+
+ // TODO(b/62186997): Add operator=(T) overloads.
+
+ // Similar to the `const T&` overload.
+ //
+ // REQUIRES: T is move constructible.
+ StatusOr(T&& value); // NOLINT(runtime/explicit)
+
+ // RValue versions of the operations declared above.
+ StatusOr(Status&& status); // NOLINT(runtime/explicit)
+ StatusOr& operator=(Status&& status);
+
+ // Returns this->status().ok()
+ bool ok() const { return this->status_.ok(); }
+
+ const T& ValueOr(const T& other) const {
+ if (ok()) {
+ return ValueOrDie();
+ } else {
+ return other;
+ }
+ }
+
+ T ConsumeValueOr(T other) {
+ if (ok()) {
+ return ConsumeValueOrDie();
+ } else {
+ return other;
+ }
+ }
+
+ // Returns a reference to our status. If this contains a T, then
+ // returns Status::OK.
+ const Status& status() const&;
+ Status status() &&;
+
+ // Returns a reference to our current value, or CHECK-fails if !this->ok().
+ //
+ // Note: for value types that are cheap to copy, prefer simple code:
+ //
+ // T value = statusor.ValueOrDie();
+ //
+ // Otherwise, if the value type is expensive to copy, but can be left
+ // in the StatusOr, simply assign to a reference:
+ //
+ // T& value = statusor.ValueOrDie(); // or `const T&`
+ //
+ // Otherwise, if the value type supports an efficient move, it can be
+ // used as follows:
+ //
+ // T value = std::move(statusor).ValueOrDie();
+ //
+ // The std::move on statusor instead of on the whole expression enables
+ // warnings about possible uses of the statusor object after the move.
+ // C++ style guide waiver for ref-qualified overloads granted in cl/143176389
+ // See go/ref-qualifiers for more details on such overloads.
+ const T& ValueOrDie() const&;
+ T& ValueOrDie() &;
+ const T&& ValueOrDie() const&&;
+ T&& ValueOrDie() &&;
+
+ T ConsumeValueOrDie() { return std::move(ValueOrDie()); }
+
+ // Ignores any errors. This method does nothing except potentially suppress
+ // complaints from any tools that are checking that errors are not dropped on
+ // the floor.
+ void IgnoreError() const;
+};
+
+////////////////////////////////////////////////////////////////////////////////
+// Implementation details for StatusOr<T>
+
+template <typename T>
+StatusOr<T>::StatusOr() : Base(Status(cobalt::util::StatusCode::UNKNOWN, "")) {}
+
+template <typename T>
+StatusOr<T>::StatusOr(const T& value) : Base(value) {}
+
+template <typename T>
+StatusOr<T>::StatusOr(const Status& status) : Base(status) {}
+
+template <typename T>
+StatusOr<T>& StatusOr<T>::operator=(const Status& status) {
+ this->Assign(status);
+ return *this;
+}
+
+template <typename T>
+StatusOr<T>::StatusOr(T&& value) : Base(std::move(value)) {}
+
+template <typename T>
+StatusOr<T>::StatusOr(Status&& status) : Base(std::move(status)) {}
+
+template <typename T>
+StatusOr<T>& StatusOr<T>::operator=(Status&& status) {
+ this->Assign(std::move(status));
+ return *this;
+}
+
+template <typename T>
+template <typename U>
+inline StatusOr<T>::StatusOr(const StatusOr<U>& other)
+ : Base(static_cast<const typename StatusOr<U>::Base&>(other)) {}
+
+template <typename T>
+template <typename U>
+inline StatusOr<T>& StatusOr<T>::operator=(const StatusOr<U>& other) {
+ if (other.ok())
+ this->Assign(other.ValueOrDie());
+ else
+ this->Assign(other.status());
+ return *this;
+}
+
+template <typename T>
+template <typename U>
+inline StatusOr<T>::StatusOr(StatusOr<U>&& other)
+ : Base(static_cast<typename StatusOr<U>::Base&&>(other)) {}
+
+template <typename T>
+template <typename U>
+inline StatusOr<T>& StatusOr<T>::operator=(StatusOr<U>&& other) {
+ if (other.ok()) {
+ this->Assign(std::move(other).ValueOrDie());
+ } else {
+ this->Assign(std::move(other).status());
+ }
+ return *this;
+}
+
+template <typename T>
+const Status& StatusOr<T>::status() const& {
+ return this->status_;
+}
+template <typename T>
+Status StatusOr<T>::status() && {
+ return ok() ? Status::OK : std::move(this->status_);
+}
+
+template <typename T>
+const T& StatusOr<T>::ValueOrDie() const& {
+ this->EnsureOk();
+ return this->data_;
+}
+
+template <typename T>
+T& StatusOr<T>::ValueOrDie() & {
+ this->EnsureOk();
+ return this->data_;
+}
+
+template <typename T>
+const T&& StatusOr<T>::ValueOrDie() const&& {
+ this->EnsureOk();
+ return std::move(this->data_);
+}
+
+template <typename T>
+T&& StatusOr<T>::ValueOrDie() && {
+ this->EnsureOk();
+ return std::move(this->data_);
+}
+
+template <typename T>
+void StatusOr<T>::IgnoreError() const {
+ // no-op
+}
+
+} // namespace statusor
+
+#endif // THIRD_PARTY_STATUSOR_STATUSOR_H_
diff --git a/third_party/tensorflow_statusor/statusor_internals.h b/third_party/statusor/statusor_internals.h
similarity index 96%
rename from third_party/tensorflow_statusor/statusor_internals.h
rename to third_party/statusor/statusor_internals.h
index 338b7d3..57d4c83 100644
--- a/third_party/tensorflow_statusor/statusor_internals.h
+++ b/third_party/statusor/statusor_internals.h
@@ -13,14 +13,14 @@
limitations under the License.
==============================================================================*/
-#ifndef TENSORFLOW_COMPILER_XLA_STATUSOR_INTERNALS_H_
-#define TENSORFLOW_COMPILER_XLA_STATUSOR_INTERNALS_H_
+#ifndef THIRD_PARTY_STATUSOR_STATUSOR_INTERNALS_H_
+#define THIRD_PARTY_STATUSOR_STATUSOR_INTERNALS_H_
#include <utility>
#include "util/status.h"
-namespace tensorflow_statusor {
+namespace statusor {
namespace internal_statusor {
using cobalt::util::Status;
@@ -243,6 +243,6 @@
};
} // namespace internal_statusor
-} // namespace tensorflow_statusor
+} // namespace statusor
-#endif // TENSORFLOW_COMPILER_XLA_STATUSOR_INTERNALS_H_
+#endif // THIRD_PARTY_STATUSOR_STATUSOR_INTERNALS_H_
diff --git a/third_party/tensorflow_statusor/BUILD.gn b/third_party/tensorflow_statusor/BUILD.gn
index 567323d..7d40b8e 100644
--- a/third_party/tensorflow_statusor/BUILD.gn
+++ b/third_party/tensorflow_statusor/BUILD.gn
@@ -2,20 +2,15 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+# TODO(azani): Delete after tensorflow_statusor is deleted.
static_library("statusor") {
sources = [
- "status_macros.cc",
- "status_macros.h",
- "statusor.cc",
"statusor.h",
- "statusor_internals.h",
]
public_configs = [ "//third_party/cobalt:cobalt_config" ]
public_deps = [
- "//third_party/cobalt/util:status",
- "//third_party/glog:glog",
- "//third_party/protobuf:protobuf_lite",
+ "//third_party/cobalt/third_party/statusor:statusor",
]
}
diff --git a/third_party/tensorflow_statusor/CMakeLists.txt b/third_party/tensorflow_statusor/CMakeLists.txt
deleted file mode 100644
index 11e54ae..0000000
--- a/third_party/tensorflow_statusor/CMakeLists.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-add_library(tensorflow_statusor statusor.cc status_macros.cc)
-add_cobalt_dependencies(tensorflow_statusor status)
diff --git a/third_party/tensorflow_statusor/statusor.h b/third_party/tensorflow_statusor/statusor.h
index af410f0..7b23a7f 100644
--- a/third_party/tensorflow_statusor/statusor.h
+++ b/third_party/tensorflow_statusor/statusor.h
@@ -1,318 +1,19 @@
-/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
+// Copyright 2019 The Fuchsia Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
+// TODO(azani): Delete after tensorflow_statusor is deleted.
- http://www.apache.org/licenses/LICENSE-2.0
+#ifndef THIRD_PARTY_TENSORFLOW_STATUSOR_STATUSOR_H_
+#define THIRD_PARTY_TENSORFLOW_STATUSOR_STATUSOR_H_
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-==============================================================================*/
-
-// StatusOr<T> is the union of a Status object and a T
-// object. StatusOr models the concept of an object that is either a
-// usable value, or an error Status explaining why such a value is
-// not present. To this end, StatusOr<T> does not allow its Status
-// value to be Status::OK. Furthermore, the value of a StatusOr<T*>
-// must not be null. This is enforced by a debug check in most cases,
-// but even when it is not, clients must not set the value to null.
-//
-// The primary use-case for StatusOr<T> is as the return value of a
-// function which may fail.
-//
-// Example client usage for a StatusOr<T>, where T is not a pointer:
-//
-// StatusOr<float> result = DoBigCalculationThatCouldFail();
-// if (result.ok()) {
-// float answer = result.ValueOrDie();
-// printf("Big calculation yielded: %f", answer);
-// } else {
-// LOG(ERROR) << result.status();
-// }
-//
-// Example client usage for a StatusOr<T*>:
-//
-// StatusOr<Foo*> result = FooFactory::MakeNewFoo(arg);
-// if (result.ok()) {
-// std::unique_ptr<Foo> foo(result.ValueOrDie());
-// foo->DoSomethingCool();
-// } else {
-// LOG(ERROR) << result.status();
-// }
-//
-// Example client usage for a StatusOr<std::unique_ptr<T>>:
-//
-// StatusOr<std::unique_ptr<Foo>> result = FooFactory::MakeNewFoo(arg);
-// if (result.ok()) {
-// std::unique_ptr<Foo> foo = std::move(result.ValueOrDie());
-// foo->DoSomethingCool();
-// } else {
-// LOG(ERROR) << result.status();
-// }
-//
-// Example factory implementation returning StatusOr<T*>:
-//
-// StatusOr<Foo*> FooFactory::MakeNewFoo(int arg) {
-// if (arg <= 0) {
-// return tensorflow::InvalidArgument("Arg must be positive");
-// } else {
-// return new Foo(arg);
-// }
-// }
-//
-// Note that the assignment operators require that destroying the currently
-// stored value cannot invalidate the argument; in other words, the argument
-// cannot be an alias for the current value, or anything owned by the current
-// value.
-#ifndef TENSORFLOW_COMPILER_XLA_STATUSOR_H_
-#define TENSORFLOW_COMPILER_XLA_STATUSOR_H_
-
-#include <utility>
-#include "third_party/tensorflow_statusor/statusor_internals.h"
-#include "util/status.h"
+#include "third_party/statusor/statusor.h"
namespace tensorflow_statusor {
-using cobalt::util::Status;
-
-template <typename T>
-class StatusOr : private internal_statusor::StatusOrData<T>,
- private internal_statusor::TraitsBase<
- std::is_copy_constructible<T>::value,
- std::is_move_constructible<T>::value> {
- template <typename U>
- friend class StatusOr;
-
- typedef internal_statusor::StatusOrData<T> Base;
-
- public:
- typedef T element_type;
-
- // Constructs a new StatusOr with Status::UNKNOWN status. This is marked
- // 'explicit' to try to catch cases like 'return {};', where people think
- // StatusOr<std::vector<int>> will be initialized with an empty vector,
- // instead of a Status::UNKNOWN status.
- explicit StatusOr(); // NOLINT(runtime/explicit)
-
- // StatusOr<T> will be copy constructible/assignable if T is copy
- // constructible.
- StatusOr(const StatusOr&) = default;
- StatusOr& operator=(const StatusOr&) = default;
-
- // StatusOr<T> will be move constructible/assignable if T is move
- // constructible.
- StatusOr(StatusOr&&) = default;
- StatusOr& operator=(StatusOr&&) = default;
-
- // Conversion copy/move constructor, T must be convertible from U.
- // TODO(b/62186717): These should not participate in overload resolution if U
- // is not convertible to T.
- template <typename U>
- StatusOr(const StatusOr<U>& other);
- template <typename U>
- StatusOr(StatusOr<U>&& other);
-
- // Conversion copy/move assignment operator, T must be convertible from U.
- template <typename U>
- StatusOr& operator=(const StatusOr<U>& other);
- template <typename U>
- StatusOr& operator=(StatusOr<U>&& other);
-
- // Constructs a new StatusOr with the given value. After calling this
- // constructor, calls to ValueOrDie() will succeed, and calls to status() will
- // return OK.
- //
- // NOTE: Not explicit - we want to use StatusOr<T> as a return type
- // so it is convenient and sensible to be able to do 'return T()'
- // when the return type is StatusOr<T>.
- //
- // REQUIRES: T is copy constructible.
- StatusOr(const T& value); // NOLINT(runtime/explicit)
-
- // Constructs a new StatusOr with the given non-ok status. After calling
- // this constructor, calls to ValueOrDie() will CHECK-fail.
- //
- // NOTE: Not explicit - we want to use StatusOr<T> as a return
- // value, so it is convenient and sensible to be able to do 'return
- // Status()' when the return type is StatusOr<T>.
- //
- // REQUIRES: !status.ok(). This requirement is DCHECKed.
- // In optimized builds, passing Status::OK here will have the effect
- // of passing tensorflow::error::INTERNAL as a fallback.
- StatusOr(const Status& status); // NOLINT(runtime/explicit)
- StatusOr& operator=(const Status& status);
-
- // TODO(b/62186997): Add operator=(T) overloads.
-
- // Similar to the `const T&` overload.
- //
- // REQUIRES: T is move constructible.
- StatusOr(T&& value); // NOLINT(runtime/explicit)
-
- // RValue versions of the operations declared above.
- StatusOr(Status&& status); // NOLINT(runtime/explicit)
- StatusOr& operator=(Status&& status);
-
- // Returns this->status().ok()
- bool ok() const { return this->status_.ok(); }
-
- const T& ValueOr(const T& other) const {
- if (ok()) {
- return ValueOrDie();
- } else {
- return other;
- }
- }
-
- T ConsumeValueOr(T other) {
- if (ok()) {
- return ConsumeValueOrDie();
- } else {
- return other;
- }
- }
-
- // Returns a reference to our status. If this contains a T, then
- // returns Status::OK.
- const Status& status() const&;
- Status status() &&;
-
- // Returns a reference to our current value, or CHECK-fails if !this->ok().
- //
- // Note: for value types that are cheap to copy, prefer simple code:
- //
- // T value = statusor.ValueOrDie();
- //
- // Otherwise, if the value type is expensive to copy, but can be left
- // in the StatusOr, simply assign to a reference:
- //
- // T& value = statusor.ValueOrDie(); // or `const T&`
- //
- // Otherwise, if the value type supports an efficient move, it can be
- // used as follows:
- //
- // T value = std::move(statusor).ValueOrDie();
- //
- // The std::move on statusor instead of on the whole expression enables
- // warnings about possible uses of the statusor object after the move.
- // C++ style guide waiver for ref-qualified overloads granted in cl/143176389
- // See go/ref-qualifiers for more details on such overloads.
- const T& ValueOrDie() const&;
- T& ValueOrDie() &;
- const T&& ValueOrDie() const&&;
- T&& ValueOrDie() &&;
-
- T ConsumeValueOrDie() { return std::move(ValueOrDie()); }
-
- // Ignores any errors. This method does nothing except potentially suppress
- // complaints from any tools that are checking that errors are not dropped on
- // the floor.
- void IgnoreError() const;
-};
-
-////////////////////////////////////////////////////////////////////////////////
-// Implementation details for StatusOr<T>
-
-template <typename T>
-StatusOr<T>::StatusOr() : Base(Status(cobalt::util::StatusCode::UNKNOWN, "")) {}
-
-template <typename T>
-StatusOr<T>::StatusOr(const T& value) : Base(value) {}
-
-template <typename T>
-StatusOr<T>::StatusOr(const Status& status) : Base(status) {}
-
-template <typename T>
-StatusOr<T>& StatusOr<T>::operator=(const Status& status) {
- this->Assign(status);
- return *this;
-}
-
-template <typename T>
-StatusOr<T>::StatusOr(T&& value) : Base(std::move(value)) {}
-
-template <typename T>
-StatusOr<T>::StatusOr(Status&& status) : Base(std::move(status)) {}
-
-template <typename T>
-StatusOr<T>& StatusOr<T>::operator=(Status&& status) {
- this->Assign(std::move(status));
- return *this;
-}
-
-template <typename T>
-template <typename U>
-inline StatusOr<T>::StatusOr(const StatusOr<U>& other)
- : Base(static_cast<const typename StatusOr<U>::Base&>(other)) {}
-
-template <typename T>
-template <typename U>
-inline StatusOr<T>& StatusOr<T>::operator=(const StatusOr<U>& other) {
- if (other.ok())
- this->Assign(other.ValueOrDie());
- else
- this->Assign(other.status());
- return *this;
-}
-
-template <typename T>
-template <typename U>
-inline StatusOr<T>::StatusOr(StatusOr<U>&& other)
- : Base(static_cast<typename StatusOr<U>::Base&&>(other)) {}
-
-template <typename T>
-template <typename U>
-inline StatusOr<T>& StatusOr<T>::operator=(StatusOr<U>&& other) {
- if (other.ok()) {
- this->Assign(std::move(other).ValueOrDie());
- } else {
- this->Assign(std::move(other).status());
- }
- return *this;
-}
-
-template <typename T>
-const Status& StatusOr<T>::status() const& {
- return this->status_;
-}
-template <typename T>
-Status StatusOr<T>::status() && {
- return ok() ? Status::OK : std::move(this->status_);
-}
-
-template <typename T>
-const T& StatusOr<T>::ValueOrDie() const& {
- this->EnsureOk();
- return this->data_;
-}
-
-template <typename T>
-T& StatusOr<T>::ValueOrDie() & {
- this->EnsureOk();
- return this->data_;
-}
-
-template <typename T>
-const T&& StatusOr<T>::ValueOrDie() const&& {
- this->EnsureOk();
- return std::move(this->data_);
-}
-
-template <typename T>
-T&& StatusOr<T>::ValueOrDie() && {
- this->EnsureOk();
- return std::move(this->data_);
-}
-
-template <typename T>
-void StatusOr<T>::IgnoreError() const {
- // no-op
-}
+// Create an alias for statusor::StatusOr.
+using statusor::StatusOr;
} // namespace tensorflow_statusor
-#endif // TENSORFLOW_COMPILER_XLA_STATUSOR_H_
+#endif // THIRD_PARTY_TENSORFLOW_STATUSOR_STATUSOR_H_
diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt
index b38a807..7723832 100644
--- a/util/CMakeLists.txt
+++ b/util/CMakeLists.txt
@@ -14,7 +14,7 @@
target_link_libraries(encrypted_message_util
cobalt_crypto
status
- tensorflow_statusor)
+ statusor)
add_cobalt_dependencies(encrypted_message_util)
add_library(pem_util
@@ -57,7 +57,7 @@
posix_file_system.cc)
target_link_libraries(posix_file_system
status
- tensorflow_statusor)
+ statusor)
add_cobalt_dependencies(posix_file_system)
cobalt_make_protobuf_cpp_lib(consistent_proto_store_test_proto
diff --git a/util/clearcut/curl_handle.h b/util/clearcut/curl_handle.h
index 05fb94c..b63df50 100644
--- a/util/clearcut/curl_handle.h
+++ b/util/clearcut/curl_handle.h
@@ -12,7 +12,7 @@
#include <string>
#include "third_party/clearcut/http_client.h"
-#include "third_party/tensorflow_statusor/statusor.h"
+#include "third_party/statusor/statusor.h"
#include "util/status.h"
namespace cobalt {
@@ -20,7 +20,7 @@
namespace clearcut {
using ::clearcut::HTTPResponse;
-using tensorflow_statusor::StatusOr;
+using statusor::StatusOr;
using util::Status;
// CurlHandle wraps around a CURL * to make it easier to interact with curl.
diff --git a/util/clearcut/curl_http_client.h b/util/clearcut/curl_http_client.h
index ab5c6bb..11c35b8 100644
--- a/util/clearcut/curl_http_client.h
+++ b/util/clearcut/curl_http_client.h
@@ -6,7 +6,7 @@
#define COBALT_UTIL_CLEARCUT_CURL_HTTP_CLIENT_H_
#include "third_party/clearcut/http_client.h"
-#include "third_party/tensorflow_statusor/statusor.h"
+#include "third_party/statusor/statusor.h"
namespace cobalt {
namespace util {
@@ -15,7 +15,7 @@
using ::clearcut::HTTPClient;
using ::clearcut::HTTPRequest;
using ::clearcut::HTTPResponse;
-using tensorflow_statusor::StatusOr;
+using statusor::StatusOr;
// CurlHTTPClient implements clearcut::HTTPClient with a curl backend. This is
// a basic implementation that is designed to be used on linux clients (not
diff --git a/util/consistent_proto_store.cc b/util/consistent_proto_store.cc
index bce4b52..3694199 100644
--- a/util/consistent_proto_store.cc
+++ b/util/consistent_proto_store.cc
@@ -10,7 +10,7 @@
#include <iostream>
#include <utility>
-#include "third_party/tensorflow_statusor/status_macros.h"
+#include "third_party/statusor/status_macros.h"
namespace cobalt {
namespace util {
diff --git a/util/encrypted_message_util.cc b/util/encrypted_message_util.cc
index f02972d..41c32f4 100644
--- a/util/encrypted_message_util.cc
+++ b/util/encrypted_message_util.cc
@@ -43,7 +43,7 @@
}
}
-tensorflow_statusor::StatusOr<std::unique_ptr<EncryptedMessageMaker>>
+statusor::StatusOr<std::unique_ptr<EncryptedMessageMaker>>
EncryptedMessageMaker::Make(const std::string& public_key_pem,
EncryptedMessage::EncryptionScheme scheme) {
if (scheme == EncryptedMessage::NONE) {
@@ -54,7 +54,7 @@
return std::make_unique<EncryptedMessageMaker>(public_key_pem, scheme);
}
-tensorflow_statusor::StatusOr<std::unique_ptr<EncryptedMessageMaker>>
+statusor::StatusOr<std::unique_ptr<EncryptedMessageMaker>>
EncryptedMessageMaker::MakeAllowUnencrypted(
const std::string& public_key_pem,
EncryptedMessage::EncryptionScheme scheme) {
diff --git a/util/encrypted_message_util.h b/util/encrypted_message_util.h
index 41c03ef..6749aad 100644
--- a/util/encrypted_message_util.h
+++ b/util/encrypted_message_util.h
@@ -29,7 +29,7 @@
#include "./encrypted_message.pb.h"
#include "google/protobuf/message_lite.h"
-#include "third_party/tensorflow_statusor/statusor.h"
+#include "third_party/statusor/statusor.h"
#include "util/crypto_util/cipher.h"
namespace cobalt {
@@ -57,7 +57,7 @@
// |public_key_pem| must be appropriate to |scheme|. If |scheme| is
// EncryptedMessage::HYBRID_ECDH_V1 then |public_key_pem| must be a PEM
// encoding of a public key appropriate for that scheme.
- static tensorflow_statusor::StatusOr<std::unique_ptr<EncryptedMessageMaker>>
+ static statusor::StatusOr<std::unique_ptr<EncryptedMessageMaker>>
Make(const std::string& public_key_pem,
EncryptedMessage::EncryptionScheme scheme);
@@ -77,7 +77,7 @@
// EncryptedMessage::NONE then |public_key_pem| is ignored. If |scheme| is
// EncryptedMessage::HYBRID_ECDH_V1 then |public_key_pem| must be a PEM
// encoding of a public key appropriate for that scheme.
- static tensorflow_statusor::StatusOr<std::unique_ptr<EncryptedMessageMaker>>
+ static statusor::StatusOr<std::unique_ptr<EncryptedMessageMaker>>
MakeAllowUnencrypted(const std::string& public_key_pem,
EncryptedMessage::EncryptionScheme scheme);
diff --git a/util/file_system.h b/util/file_system.h
index 8221539..9ccbdfb 100644
--- a/util/file_system.h
+++ b/util/file_system.h
@@ -8,7 +8,7 @@
#include <string>
#include <vector>
-#include "third_party/tensorflow_statusor/statusor.h"
+#include "third_party/statusor/statusor.h"
namespace cobalt {
namespace util {
@@ -33,7 +33,7 @@
//
// Note: On unix like systems, the directories "." and ".." should not be
// returned.
- virtual tensorflow_statusor::StatusOr<std::vector<std::string>> ListFiles(
+ virtual statusor::StatusOr<std::vector<std::string>> ListFiles(
const std::string &directory) = 0;
// Delete deletes a file or an empty directory.
@@ -50,7 +50,7 @@
// Returns: A StatusOr containing the size of the file in bytes. An OK
// status indicates that the FileSize operation succeeded, even if the
// size_t is 0.
- virtual tensorflow_statusor::StatusOr<size_t> FileSize(
+ virtual statusor::StatusOr<size_t> FileSize(
const std::string &file) = 0;
// FileExists returns true if the |file| exists.
diff --git a/util/posix_file_system.cc b/util/posix_file_system.cc
index dacabc8..164e3a7 100644
--- a/util/posix_file_system.cc
+++ b/util/posix_file_system.cc
@@ -14,7 +14,7 @@
namespace cobalt {
namespace util {
-using tensorflow_statusor::StatusOr;
+using statusor::StatusOr;
using util::Status;
using util::StatusCode;
diff --git a/util/posix_file_system.h b/util/posix_file_system.h
index 3da7ca6..d5b8ae6 100644
--- a/util/posix_file_system.h
+++ b/util/posix_file_system.h
@@ -17,10 +17,10 @@
class PosixFileSystem : public FileSystem {
public:
bool MakeDirectory(const std::string &directory) override;
- tensorflow_statusor::StatusOr<std::vector<std::string>> ListFiles(
+ statusor::StatusOr<std::vector<std::string>> ListFiles(
const std::string &directory) override;
bool Delete(const std::string &file) override;
- tensorflow_statusor::StatusOr<size_t> FileSize(
+ statusor::StatusOr<size_t> FileSize(
const std::string &file) override;
bool FileExists(const std::string &file) override;
bool Rename(const std::string &from, const std::string &to) override;