• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 Huawei Device Co., Ltd.
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 
16 #ifndef COUNTRY_CODE_H
17 #define COUNTRY_CODE_H
18 
19 #include <parcel.h>
20 #include <string>
21 
22 #include "constant_definition.h"
23 #include "country_code.h"
24 #include "string_ex.h"
25 
26 namespace OHOS {
27 namespace Location {
28 class CountryCode : public Parcelable {
29 public:
CountryCode()30     CountryCode()
31     {
32         countryCodeStr_ = "";
33         countryCodeType_ = COUNTRY_CODE_FROM_LOCALE;
34     }
35 
CountryCode(CountryCode & country)36     explicit CountryCode(CountryCode& country)
37     {
38         SetCountryCodeStr(country.GetCountryCodeStr());
39         SetCountryCodeType(country.GetCountryCodeType());
40     }
41 
42     ~CountryCode() override = default;
43 
IsSame(CountryCode & country)44     inline bool IsSame(CountryCode& country) const
45     {
46         return (countryCodeStr_ == country.GetCountryCodeStr()) &&
47             (countryCodeType_ == country.GetCountryCodeType());
48     }
49 
IsMoreReliable(int type)50     inline bool IsMoreReliable(int type) const
51     {
52         return (countryCodeType_ > type);
53     }
54 
GetCountryCodeStr()55     inline std::string GetCountryCodeStr() const
56     {
57         return countryCodeStr_;
58     }
59 
SetCountryCodeStr(std::string country)60     inline void SetCountryCodeStr(std::string country)
61     {
62         countryCodeStr_ = country;
63     }
64 
GetCountryCodeType()65     inline int GetCountryCodeType() const
66     {
67         return countryCodeType_;
68     }
69 
SetCountryCodeType(int type)70     inline void SetCountryCodeType(int type)
71     {
72         countryCodeType_ = type;
73     }
74 
ReadFromParcel(Parcel & parcel)75     void ReadFromParcel(Parcel& parcel)
76     {
77         countryCodeStr_ = Str16ToStr8(parcel.ReadString16());
78         countryCodeType_ = parcel.ReadInt64();
79     }
80 
Marshalling(Parcel & parcel)81     bool Marshalling(Parcel& parcel) const override
82     {
83         return parcel.WriteString16(Str8ToStr16(countryCodeStr_)) &&
84                parcel.WriteInt64(countryCodeType_);
85     }
86 
Unmarshalling(Parcel & parcel)87     static std::shared_ptr<CountryCode> Unmarshalling(Parcel& parcel)
88     {
89         auto country = std::make_shared<CountryCode>();
90         country->ReadFromParcel(parcel);
91         return country;
92     }
93 
ToString()94     std::string ToString()
95     {
96         std::string str = "countryCodeStr_ : " + countryCodeStr_ +
97             ", countryCodeType_ : " + std::to_string(countryCodeType_);
98         return str;
99     }
100 
101 private:
102     std::string countryCodeStr_;
103     int countryCodeType_;
104 };
105 } // namespace Location
106 } // namespace OHOS
107 #endif // COUNTRY_CODE_H