1 // Copyright (C) 2014 Google Inc.
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
15 // A struct for storing address data: country code, administrative area,
16 // locality, etc. The field names correspond to the OASIS xAL standard:
17 // https://www.oasis-open.org/committees/ciq/download.shtml
19 #ifndef I18N_ADDRESSINPUT_ADDRESS_DATA_H_
20 #define I18N_ADDRESSINPUT_ADDRESS_DATA_H_
22 #include <libaddressinput/address_field.h>
29 namespace addressinput {
32 // CLDR (Common Locale Data Repository) region code.
33 std::string region_code;
35 // The address lines represent the most specific part of any address.
36 std::vector<std::string> address_line;
38 // Top-level administrative subdivision of this country.
39 std::string administrative_area;
41 // Generally refers to the city/town portion of an address.
44 // Dependent locality or sublocality. Used for UK dependent localities, or
45 // neighborhoods or boroughs in other locations.
46 std::string dependent_locality;
48 // Values are frequently alphanumeric.
49 std::string postal_code;
51 // This corresponds to the SortingCode sub-element of the xAL
52 // PostalServiceElements element. Use is very country-specific.
53 std::string sorting_code;
55 // Language code of the address. Should be in BCP-47 format.
56 std::string language_code;
58 // The organization, firm, company, or institution at this address. This
59 // corresponds to the FirmName sub-element of the xAL FirmType element.
60 std::string organization;
62 // Name of recipient or contact person. Not present in xAL.
63 std::string recipient;
65 // Returns whether the |field| is empty.
66 bool IsFieldEmpty(AddressField field) const;
68 // Returns the value of the |field|. The parameter must not be STREET_ADDRESS,
69 // which comprises multiple fields (will crash otherwise).
70 const std::string& GetFieldValue(AddressField field) const;
72 // Copies |value| into the |field|. The parameter must not be STREET_ADDRESS,
73 // which comprises multiple fields (will crash otherwise).
74 void SetFieldValue(AddressField field, const std::string& value);
76 // Returns the value of the |field|. The parameter must be STREET_ADDRESS,
77 // which comprises multiple fields (will crash otherwise).
78 const std::vector<std::string>& GetRepeatedFieldValue(
79 AddressField field) const;
81 bool operator==(const AddressData& other) const;
83 // Returns true if the parameter comprises multiple fields, false otherwise.
84 // Use it to determine whether to call |GetFieldValue| or
85 // |GetRepeatedFieldValue|.
86 static bool IsRepeatedFieldValue(AddressField field);
89 } // namespace addressinput
92 // Produces human-readable output in logging, for example in unit tests.
93 std::ostream& operator<<(std::ostream& o,
94 const i18n::addressinput::AddressData& address);
96 #endif // I18N_ADDRESSINPUT_ADDRESS_DATA_H_