Skip to content

Commit

Permalink
Mandlil patch 2 (#3393)
Browse files Browse the repository at this point in the history
* Update lock_posix.h

Remove uses of the deprecated DISALLOW_COPY_AND_ASSIGN in favor of explicitly deleted constructors and assignment operators.

* Remove uses of the deprecated DISALLOW_COPY_AND_ASSIGN in favor of explicitly deleted constructors and assignment operators.
  • Loading branch information
mandlil committed Jan 17, 2024
1 parent ff46dbc commit b43d968
Show file tree
Hide file tree
Showing 16 changed files with 85 additions and 31 deletions.
7 changes: 6 additions & 1 deletion cpp/src/phonenumbers/asyoutypeformatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ class PhoneNumberUtil;

class AsYouTypeFormatter {
public:

// This type is neither copyable nor movable.
AsYouTypeFormatter(const AsYouTypeFormatter&) = delete;
AsYouTypeFormatter& operator=(const AsYouTypeFormatter&) = delete;

~AsYouTypeFormatter() {}

// Formats a phone number on-the-fly as each digit is entered.
Expand Down Expand Up @@ -233,7 +238,7 @@ class AsYouTypeFormatter {

// Disallow copy and assign since this class uses RegExpCache which can't be
// copied.
DISALLOW_COPY_AND_ASSIGN(AsYouTypeFormatter);

};

} // namespace phonenumbers
Expand Down
6 changes: 4 additions & 2 deletions cpp/src/phonenumbers/base/synchronization/lock_posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ class Lock {
DCHECK_EQ(0, ret);
}

// This type is neither copyable nor movable.
Lock(const Lock&) = delete;
Lock& operator=(const Lock&) = delete;

~Lock() {
const int ret = pthread_mutex_destroy(&mutex_);
(void) ret;
Expand All @@ -52,8 +56,6 @@ class Lock {
}

private:
DISALLOW_COPY_AND_ASSIGN(Lock);

mutable pthread_mutex_t mutex_;
};

Expand Down
10 changes: 7 additions & 3 deletions cpp/src/phonenumbers/geocoding/area_code_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#ifndef I18N_PHONENUMBERS_AREA_CODE_MAP_H_
#define I18N_PHONENUMBERS_AREA_CODE_MAP_H_

#include <cstdint>
#include <map>
#include <string>

Expand All @@ -39,6 +40,11 @@ struct PrefixDescriptions;
class AreaCodeMap {
public:
AreaCodeMap();

// This type is neither copyable nor movable.
AreaCodeMap(const AreaCodeMap&) = delete;
AreaCodeMap& operator=(const AreaCodeMap&) = delete;

~AreaCodeMap();

// Returns the description of the geographical area the number corresponds
Expand All @@ -61,12 +67,10 @@ class AreaCodeMap {
// (inclusive). Returns the position if {@code value} is found; otherwise,
// returns the position which has the largest value that is less than value.
// This means if value is the smallest, -1 will be returned.
int BinarySearch(int start, int end, int64 value) const;
int BinarySearch(int start, int end, int64_t value) const;

const PhoneNumberUtil& phone_util_;
scoped_ptr<const DefaultMapStorage> storage_;

DISALLOW_COPY_AND_ASSIGN(AreaCodeMap);
};

} // namespace phonenumbers
Expand Down
14 changes: 9 additions & 5 deletions cpp/src/phonenumbers/geocoding/default_map_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#ifndef I18N_PHONENUMBERS_DEFAULT_MAP_STORAGE_H_
#define I18N_PHONENUMBERS_DEFAULT_MAP_STORAGE_H_

#include <cstdint>
#include "phonenumbers/base/basictypes.h"

namespace i18n {
Expand All @@ -33,10 +34,15 @@ struct PrefixDescriptions;
class DefaultMapStorage {
public:
DefaultMapStorage();

// This type is neither copyable nor movable.
DefaultMapStorage(const DefaultMapStorage&) = delete;
DefaultMapStorage& operator=(const DefaultMapStorage&) = delete;

virtual ~DefaultMapStorage();

// Returns the phone number prefix located at the provided index.
int32 GetPrefix(int index) const;
int32_t GetPrefix(int index) const;

// Gets the description corresponding to the phone number prefix located
// at the provided index. If the description is not available in the current
Expand All @@ -59,15 +65,13 @@ class DefaultMapStorage {

private:
// Sorted sequence of phone number prefixes.
const int32* prefixes_;
const int32_t* prefixes_;
int prefixes_size_;
// Sequence of prefix descriptions, in the same order than prefixes_.
const char** descriptions_;
// Sequence of unique possible lengths in ascending order.
const int32* possible_lengths_;
const int32_t* possible_lengths_;
int possible_lengths_size_;

DISALLOW_COPY_AND_ASSIGN(DefaultMapStorage);
};

} // namespace phonenumbers
Expand Down
6 changes: 4 additions & 2 deletions cpp/src/phonenumbers/geocoding/mapping_file_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class MappingFileProvider {
int country_calling_code_size,
country_languages_getter get_country_languages);

// This type is neither copyable nor movable.
MappingFileProvider(const MappingFileProvider&) = delete;
MappingFileProvider& operator=(const MappingFileProvider&) = delete;

// Returns the name of the file that contains the mapping data for the
// country_calling_code in the language specified, or an empty string if no
// such file can be found.
Expand All @@ -68,8 +72,6 @@ class MappingFileProvider {
const int* const country_calling_codes_;
const int country_calling_codes_size_;
const country_languages_getter get_country_languages_;

DISALLOW_COPY_AND_ASSIGN(MappingFileProvider);
};

} // namespace phonenumbers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ class PhoneNumberOfflineGeocoder {
int prefix_language_code_pairs_size,
prefix_descriptions_getter get_prefix_descriptions);

// This type is neither copyable nor movable.
PhoneNumberOfflineGeocoder(const PhoneNumberOfflineGeocoder&) = delete;
PhoneNumberOfflineGeocoder& operator=(const PhoneNumberOfflineGeocoder&) =
delete;

virtual ~PhoneNumberOfflineGeocoder();

// Returns a text description for the given phone number, in the language
Expand Down Expand Up @@ -164,7 +169,6 @@ class PhoneNumberOfflineGeocoder {
// phone prefix map that has been loaded.
mutable absl::Mutex mu_;
mutable AreaCodeMaps available_maps_ ABSL_GUARDED_BY(mu_);
DISALLOW_COPY_AND_ASSIGN(PhoneNumberOfflineGeocoder);
};

} // namespace phonenumbers
Expand Down
5 changes: 4 additions & 1 deletion cpp/src/phonenumbers/phonenumbermatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ class PhoneNumberMatch {
// Default constructor.
PhoneNumberMatch();

// This type is neither copyable nor movable.
PhoneNumberMatch(const PhoneNumberMatch&) = delete;
PhoneNumberMatch& operator=(const PhoneNumberMatch&) = delete;

~PhoneNumberMatch() {}

// Returns the phone number matched by the receiver.
Expand Down Expand Up @@ -116,7 +120,6 @@ class PhoneNumberMatch {
// The matched phone number.
PhoneNumber number_;

DISALLOW_COPY_AND_ASSIGN(PhoneNumberMatch);
};

} // namespace phonenumbers
Expand Down
6 changes: 4 additions & 2 deletions cpp/src/phonenumbers/phonenumberutil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,10 @@ class PhoneNumberRegExpsAndMappings {
InitializeMapsAndSets();
}

private:
DISALLOW_COPY_AND_ASSIGN(PhoneNumberRegExpsAndMappings);
// This type is neither copyable nor movable.
PhoneNumberRegExpsAndMappings(const PhoneNumberRegExpsAndMappings&) = delete;
PhoneNumberRegExpsAndMappings& operator=(
const PhoneNumberRegExpsAndMappings&) = delete;
};

// Private constructor. Also takes care of initialisation.
Expand Down
5 changes: 4 additions & 1 deletion cpp/src/phonenumbers/phonenumberutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> {
friend class Singleton<PhoneNumberUtil>;

public:
// This type is neither copyable nor movable.
PhoneNumberUtil(const PhoneNumberUtil&) = delete;
PhoneNumberUtil& operator=(const PhoneNumberUtil&) = delete;

~PhoneNumberUtil();
static const char kRegionCodeForNonGeoEntity[];

Expand Down Expand Up @@ -970,7 +974,6 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> {
bool IsShorterThanPossibleNormalNumber(const PhoneMetadata* country_metadata,
const string& number) const;

DISALLOW_COPY_AND_ASSIGN(PhoneNumberUtil);
};

} // namespace phonenumbers
Expand Down
6 changes: 5 additions & 1 deletion cpp/src/phonenumbers/regex_based_matcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ class RegExpCache;
class RegexBasedMatcher : public MatcherApi {
public:
RegexBasedMatcher();

// This type is neither copyable nor movable.
RegexBasedMatcher(const RegexBasedMatcher&) = delete;
RegexBasedMatcher& operator=(const RegexBasedMatcher&) = delete;

~RegexBasedMatcher();

bool MatchNationalNumber(const string& number,
Expand All @@ -48,7 +53,6 @@ class RegexBasedMatcher : public MatcherApi {
const scoped_ptr<const AbstractRegExpFactory> regexp_factory_;
const scoped_ptr<RegExpCache> regexp_cache_;

DISALLOW_COPY_AND_ASSIGN(RegexBasedMatcher);
};

} // namespace phonenumbers
Expand Down
12 changes: 9 additions & 3 deletions cpp/src/phonenumbers/regexp_adapter_icu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ class IcuRegExpInput : public RegExpInput {
: utf8_input_(Utf8StringToUnicodeString(utf8_input)),
position_(0) {}


// This type is neither copyable nor movable.
IcuRegExpInput(const IcuRegExpInput&) = delete;
IcuRegExpInput& operator=(const IcuRegExpInput&) = delete;

virtual ~IcuRegExpInput() {}

virtual string ToString() const {
Expand All @@ -95,7 +100,6 @@ class IcuRegExpInput : public RegExpInput {
UnicodeString utf8_input_;
int position_;

DISALLOW_COPY_AND_ASSIGN(IcuRegExpInput);
};

// ICU implementation of the RegExp abstract class.
Expand All @@ -113,6 +117,10 @@ class IcuRegExp : public RegExp {
}
}

// This type is neither copyable nor movable.
IcuRegExp(const IcuRegExp&) = delete;
IcuRegExp& operator=(const IcuRegExp&) = delete;

virtual ~IcuRegExp() {}

virtual bool Consume(RegExpInput* input_string,
Expand Down Expand Up @@ -223,8 +231,6 @@ class IcuRegExp : public RegExp {

private:
scoped_ptr<RegexPattern> utf8_regexp_;

DISALLOW_COPY_AND_ASSIGN(IcuRegExp);
};

RegExpInput* ICURegExpFactory::CreateInput(const string& utf8_input) const {
Expand Down
5 changes: 4 additions & 1 deletion cpp/src/phonenumbers/regexp_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ class RegExpCache {
public:
explicit RegExpCache(const AbstractRegExpFactory& regexp_factory,
size_t min_items);
// This type is neither copyable nor movable.
RegExpCache(const RegExpCache&) = delete;
RegExpCache& operator=(const RegExpCache&) = delete;

~RegExpCache();

const RegExp& GetRegExp(const string& pattern);
Expand All @@ -68,7 +72,6 @@ class RegExpCache {
Lock lock_; // protects cache_impl_
scoped_ptr<CacheImpl> cache_impl_; // protected by lock_
friend class RegExpCacheTest_CacheConstructor_Test;
DISALLOW_COPY_AND_ASSIGN(RegExpCache);
};

} // namespace phonenumbers
Expand Down
7 changes: 5 additions & 2 deletions cpp/src/phonenumbers/shortnumberinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ class PhoneNumberUtil;
class ShortNumberInfo {
public:
ShortNumberInfo();

// This type is neither copyable nor movable.
ShortNumberInfo(const ShortNumberInfo&) = delete;
ShortNumberInfo& operator=(const ShortNumberInfo&) = delete;

~ShortNumberInfo();

// Cost categories of short numbers.
Expand Down Expand Up @@ -206,8 +211,6 @@ class ShortNumberInfo {
bool MatchesEmergencyNumberHelper(const string& number,
const string& region_code,
bool allow_prefix_match) const;

DISALLOW_COPY_AND_ASSIGN(ShortNumberInfo);
};

} // namespace phonenumbers
Expand Down
7 changes: 5 additions & 2 deletions cpp/test/phonenumbers/asyoutypeformatter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ namespace phonenumbers {
class PhoneMetadata;

class AsYouTypeFormatterTest : public testing::Test {
public:
// This type is neither copyable nor movable.
AsYouTypeFormatterTest(const AsYouTypeFormatterTest&) = delete;
AsYouTypeFormatterTest& operator=(const AsYouTypeFormatterTest&) = delete;

protected:
AsYouTypeFormatterTest() : phone_util_(*PhoneNumberUtil::GetInstance()) {
PhoneNumberUtil::GetInstance()->SetLogger(new StdoutLogger());
Expand All @@ -55,8 +60,6 @@ class AsYouTypeFormatterTest : public testing::Test {
scoped_ptr<AsYouTypeFormatter> formatter_;
string result_;

private:
DISALLOW_COPY_AND_ASSIGN(AsYouTypeFormatterTest);
};

TEST_F(AsYouTypeFormatterTest, ConvertUnicodeStringPosition) {
Expand Down
7 changes: 5 additions & 2 deletions cpp/test/phonenumbers/phonenumberutil_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ using google::protobuf::RepeatedPtrField;
static const int kInvalidCountryCode = 2;

class PhoneNumberUtilTest : public testing::Test {
public:
// This type is neither copyable nor movable.
PhoneNumberUtilTest(const PhoneNumberUtilTest&) = delete;
PhoneNumberUtilTest& operator=(const PhoneNumberUtilTest&) = delete;

protected:
PhoneNumberUtilTest() : phone_util_(*PhoneNumberUtil::GetInstance()) {
PhoneNumberUtil::GetInstance()->SetLogger(new StdoutLogger());
Expand Down Expand Up @@ -120,8 +125,6 @@ class PhoneNumberUtilTest : public testing::Test {

const PhoneNumberUtil& phone_util_;

private:
DISALLOW_COPY_AND_ASSIGN(PhoneNumberUtilTest);
};

TEST_F(PhoneNumberUtilTest, ContainsOnlyValidDigits) {
Expand Down
7 changes: 5 additions & 2 deletions cpp/test/phonenumbers/shortnumberinfo_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
namespace i18n {
namespace phonenumbers {
class ShortNumberInfoTest : public testing::Test {
public:
// This type is neither copyable nor movable.
ShortNumberInfoTest(const ShortNumberInfoTest&) = delete;
ShortNumberInfoTest& operator=(const ShortNumberInfoTest&) = delete;

protected:
PhoneNumber ParseNumberForTesting(const string& number,
const string& region_code) {
Expand All @@ -49,8 +54,6 @@ class ShortNumberInfoTest : public testing::Test {
const PhoneNumberUtil phone_util_;
const ShortNumberInfo short_info_;

private:
DISALLOW_COPY_AND_ASSIGN(ShortNumberInfoTest);
};

TEST_F(ShortNumberInfoTest, IsPossibleShortNumber) {
Expand Down

0 comments on commit b43d968

Please sign in to comment.