2015-07-17 20:22:30 +00:00
|
|
|
#include <exception>
|
|
|
|
|
|
|
|
#include "phonenumbers/phonenumberutil.h"
|
|
|
|
|
2015-07-22 19:23:40 +00:00
|
|
|
#include "mask.h"
|
|
|
|
|
2015-07-21 21:41:44 +00:00
|
|
|
class PhoneNumberTooLongException : public std::runtime_error {
|
2015-07-17 20:22:30 +00:00
|
|
|
public:
|
|
|
|
PhoneNumberTooLongException(const i18n::phonenumbers::PhoneNumber& number, const char* msg);
|
|
|
|
|
|
|
|
private:
|
|
|
|
i18n::phonenumbers::PhoneNumber _number;
|
|
|
|
|
|
|
|
static const i18n::phonenumbers::PhoneNumberUtil* const phoneUtil;
|
|
|
|
};
|
|
|
|
|
2015-07-21 17:32:30 +00:00
|
|
|
class ShortPhoneNumber {
|
2015-07-17 20:22:30 +00:00
|
|
|
public:
|
|
|
|
enum : size_t {
|
|
|
|
MAX_COUNTRY_CODE = 999,
|
|
|
|
//15 digits
|
|
|
|
MAX_NATIONAL_NUMBER = 999999999999999,
|
|
|
|
MAX_LEADING_ZEROS = 15,
|
|
|
|
};
|
2015-07-22 19:23:40 +00:00
|
|
|
|
|
|
|
enum : size_t {
|
|
|
|
COUNTRY_CODE_BITS = 10,
|
|
|
|
NATIONAL_NUMBER_BITS = 50,
|
|
|
|
LEADING_ZEROS_BITS = 4,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum : size_t {
|
|
|
|
COUNTRY_CODE_OFFSET = 0,
|
|
|
|
NATIONAL_NUMBER_OFFSET = COUNTRY_CODE_OFFSET + COUNTRY_CODE_BITS,
|
|
|
|
LEADING_ZEROS_OFFSET = NATIONAL_NUMBER_OFFSET + NATIONAL_NUMBER_BITS,
|
|
|
|
};
|
2015-07-17 20:22:30 +00:00
|
|
|
|
|
|
|
ShortPhoneNumber(i18n::phonenumbers::PhoneNumber number);
|
|
|
|
|
2015-07-21 17:32:30 +00:00
|
|
|
operator i18n::phonenumbers::PhoneNumber() const;
|
|
|
|
|
2015-07-22 19:23:40 +00:00
|
|
|
google::protobuf::uint32 country_code() const {
|
|
|
|
return getMasked(_data, COUNTRY_CODE_BITS, COUNTRY_CODE_OFFSET);
|
|
|
|
}
|
|
|
|
|
|
|
|
void country_code(google::protobuf::uint32 value) {
|
|
|
|
_data = setMasked(_data, (google::protobuf::uint64)value, COUNTRY_CODE_BITS, COUNTRY_CODE_OFFSET);
|
|
|
|
}
|
|
|
|
|
|
|
|
google::protobuf::uint64 national_number() const {
|
|
|
|
return getMasked(_data, NATIONAL_NUMBER_BITS, NATIONAL_NUMBER_OFFSET);
|
|
|
|
}
|
|
|
|
|
|
|
|
void national_number(google::protobuf::uint64 value) {
|
|
|
|
_data = setMasked(_data, value, NATIONAL_NUMBER_BITS, NATIONAL_NUMBER_OFFSET);
|
|
|
|
}
|
|
|
|
|
|
|
|
google::protobuf::uint64 leading_zeros() const {
|
|
|
|
return getMasked(_data, LEADING_ZEROS_BITS, LEADING_ZEROS_OFFSET);
|
|
|
|
}
|
|
|
|
|
|
|
|
void leading_zeros(google::protobuf::uint64 value) {
|
|
|
|
_data = setMasked(_data, value, LEADING_ZEROS_BITS, LEADING_ZEROS_OFFSET);
|
|
|
|
}
|
|
|
|
|
2015-07-17 20:22:30 +00:00
|
|
|
private:
|
2015-07-22 19:23:40 +00:00
|
|
|
google::protobuf::uint64 _data;
|
2015-07-17 20:22:30 +00:00
|
|
|
};
|
|
|
|
|