| /* |
| * Copyright (C) 2018 The Android Open Source Project |
| * |
| * 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. |
| */ |
| |
| #include "utils/variant.h" |
| |
| namespace libtextclassifier3 { |
| |
| std::string Variant::ToString() const { |
| switch (GetType()) { |
| case Variant::TYPE_BOOL_VALUE: |
| if (Value<bool>()) { |
| return "true"; |
| } else { |
| return "false"; |
| } |
| break; |
| case Variant::TYPE_INT_VALUE: |
| return std::to_string(Value<int>()); |
| break; |
| case Variant::TYPE_UINT_VALUE: |
| return std::to_string(Value<unsigned int>()); |
| break; |
| case Variant::TYPE_INT64_VALUE: |
| return std::to_string(Value<int64>()); |
| break; |
| case Variant::TYPE_FLOAT_VALUE: |
| return std::to_string(Value<float>()); |
| break; |
| case Variant::TYPE_DOUBLE_VALUE: |
| return std::to_string(Value<double>()); |
| break; |
| case Variant::TYPE_STRING_VALUE: |
| return ConstRefValue<std::string>(); |
| break; |
| default: |
| TC3_LOG(FATAL) << "Unsupported variant type: " << GetType(); |
| return ""; |
| break; |
| } |
| } |
| |
| logging::LoggingStringStream& operator<<(logging::LoggingStringStream& stream, |
| const Variant& value) { |
| return stream << "Variant(" << value.GetType() << ", " << value.ToString() |
| << ")"; |
| } |
| |
| } // namespace libtextclassifier3 |