1// Copyright (C) 2014 Google Inc. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15#include <libaddressinput/address_problem.h> 16 17#include <libaddressinput/util/basictypes.h> 18 19#include <cstddef> 20#include <ostream> 21 22using i18n::addressinput::AddressProblem; 23using i18n::addressinput::UNEXPECTED_FIELD; 24using i18n::addressinput::USES_P_O_BOX; 25 26std::ostream& operator<<(std::ostream& o, AddressProblem problem) { 27 static const char* const kProblemNames[] = { 28 "UNEXPECTED_FIELD", 29 "MISSING_REQUIRED_FIELD", 30 "UNKNOWN_VALUE", 31 "INVALID_FORMAT", 32 "MISMATCHING_VALUE", 33 "USES_P_O_BOX" 34 }; 35 COMPILE_ASSERT(UNEXPECTED_FIELD == 0, bad_base); 36 COMPILE_ASSERT(USES_P_O_BOX == arraysize(kProblemNames) - 1, bad_length); 37 38 if (problem < 0 || static_cast<size_t>(problem) >= arraysize(kProblemNames)) { 39 o << "[INVALID ENUM VALUE " << static_cast<int>(problem) << "]"; 40 } else { 41 o << kProblemNames[problem]; 42 } 43 return o; 44} 45