From 94f3dc686d5f369ee596aa3e22344683f6773494 Mon Sep 17 00:00:00 2001 From: "philip.liard@gmail.com" Date: Tue, 30 Apr 2013 15:40:46 +0000 Subject: CPP: Move base code to i18n::phonenumbers namespace. This is needed to avoid name clashes when the library is embedded into Chromium. BUG=http://crbug.com/236272 R=jia.shao.peng@gmail.com Review URL: https://codereview.appspot.com/9029045 git-svn-id: http://libphonenumber.googlecode.com/svn/trunk/cpp/src/phonenumbers@569 ee073f10-1060-11df-b6a4-87a95322a99c --- base/basictypes.h | 17 ----------------- base/memory/scoped_ptr.h | 31 ++++++++++++++++++------------- base/strings/string_piece.cc | 6 ++++-- base/strings/string_piece.h | 6 ++++-- base/synchronization/lock.h | 18 ++++++++++++------ base/template_util.h | 6 ++++-- regexp_cache.cc | 2 -- regexp_cache.h | 2 +- utf/stringpiece.h | 2 +- 9 files changed, 44 insertions(+), 46 deletions(-) diff --git a/base/basictypes.h b/base/basictypes.h index 4a9d693..312252f 100644 --- a/base/basictypes.h +++ b/base/basictypes.h @@ -282,21 +282,4 @@ template inline void ignore_result(const T&) { } -// The following enum should be used only as a constructor argument to indicate -// that the variable has static storage class, and that the constructor should -// do nothing to its state. It indicates to the reader that it is legal to -// declare a static instance of the class, provided the constructor is given -// the base::LINKER_INITIALIZED argument. Normally, it is unsafe to declare a -// static variable that has a constructor or a destructor because invocation -// order is undefined. However, IF the type can be initialized by filling with -// zeroes (which the loader does for static variables), AND the destructor also -// does nothing to the storage, AND there are no virtual methods, then a -// constructor declared as -// explicit MyClass(base::LinkerInitialized x) {} -// and invoked as -// static MyClass my_variable_name(base::LINKER_INITIALIZED); -namespace base { -enum LinkerInitialized { LINKER_INITIALIZED }; -} // base - #endif // I18N_PHONENUMBERS_BASE_BASICTYPES_H_ diff --git a/base/memory/scoped_ptr.h b/base/memory/scoped_ptr.h index d6147a7..5619e11 100644 --- a/base/memory/scoped_ptr.h +++ b/base/memory/scoped_ptr.h @@ -24,7 +24,8 @@ using boost::scoped_ptr; #include "phonenumbers/base/basictypes.h" #include "phonenumbers/base/template_util.h" -namespace base { +namespace i18n { +namespace phonenumbers { // Function object which deletes its parameter, which must be a pointer. // If C is an array type, invokes 'delete[]' on the parameter; otherwise, @@ -47,7 +48,7 @@ struct DefaultDeleter { // cannot convert to T*. enum { T_must_be_complete = sizeof(T) }; enum { U_must_be_complete = sizeof(U) }; - COMPILE_ASSERT((base::is_convertible::value), + COMPILE_ASSERT((is_convertible::value), U_ptr_must_implicitly_convert_to_T_ptr); } inline void operator()(T* ptr) const { @@ -197,8 +198,8 @@ class scoped_ptr_impl { }; } // namespace internal - -} // namespace base +} // namespace phonenumbers +} // namespace i18n // A scoped_ptr is like a T*, except that the destructor of scoped_ptr // automatically deletes the pointer it holds (if any). @@ -216,7 +217,7 @@ class scoped_ptr_impl { // unique_ptr<> features. Known deficiencies include not supporting move-only // deleteres, function pointers as deleters, and deleters with reference // types. -template > +template > class scoped_ptr { public: // The element and deleter types. @@ -244,7 +245,8 @@ class scoped_ptr { // implementation of scoped_ptr. template scoped_ptr(scoped_ptr other) : impl_(&other.impl_) { - COMPILE_ASSERT(!base::is_array::value, U_cannot_be_an_array); + COMPILE_ASSERT(!i18n::phonenumbers::is_array::value, + U_cannot_be_an_array); } // operator=. Allows assignment from a scoped_ptr rvalue for a convertible @@ -259,7 +261,8 @@ class scoped_ptr { // scoped_ptr. template scoped_ptr& operator=(scoped_ptr rhs) { - COMPILE_ASSERT(!base::is_array::value, U_cannot_be_an_array); + COMPILE_ASSERT(!i18n::phonenumbers::is_array::value, + U_cannot_be_an_array); impl_.TakeState(&rhs.impl_); return *this; } @@ -287,8 +290,8 @@ class scoped_ptr { // Allow scoped_ptr to be used in boolean expressions, but not // implicitly convertible to a real bool (which is dangerous). private: - typedef base::internal::scoped_ptr_impl - scoped_ptr::*Testable; + typedef i18n::phonenumbers::internal::scoped_ptr_impl< + element_type, deleter_type> scoped_ptr::*Testable; public: operator Testable() const { return impl_.get() ? &scoped_ptr::impl_ : NULL; } @@ -316,7 +319,8 @@ class scoped_ptr { private: // Needed to reach into |impl_| in the constructor. template friend class scoped_ptr; - base::internal::scoped_ptr_impl impl_; + i18n::phonenumbers::internal::scoped_ptr_impl< + element_type, deleter_type> impl_; // Forbid comparison of scoped_ptr types. If U != T, it totally // doesn't make sense, and if U == T, it still doesn't make sense @@ -372,8 +376,8 @@ class scoped_ptr { // Allow scoped_ptr to be used in boolean expressions, but not // implicitly convertible to a real bool (which is dangerous). private: - typedef base::internal::scoped_ptr_impl - scoped_ptr::*Testable; + typedef i18n::phonenumbers::internal::scoped_ptr_impl< + element_type, deleter_type> scoped_ptr::*Testable; public: operator Testable() const { return impl_.get() ? &scoped_ptr::impl_ : NULL; } @@ -403,7 +407,8 @@ class scoped_ptr { enum { type_must_be_complete = sizeof(element_type) }; // Actually hold the data. - base::internal::scoped_ptr_impl impl_; + i18n::phonenumbers::internal::scoped_ptr_impl< + element_type, deleter_type> impl_; // Disable initialization from any type other than element_type*, by // providing a constructor that matches such an initialization, but is diff --git a/base/strings/string_piece.cc b/base/strings/string_piece.cc index 774c94e..64a4923 100644 --- a/base/strings/string_piece.cc +++ b/base/strings/string_piece.cc @@ -8,7 +8,8 @@ #include "phonenumbers/base/strings/string_piece.h" -namespace base { +namespace i18n { +namespace phonenumbers { typedef StringPiece::size_type size_type; @@ -216,4 +217,5 @@ StringPiece StringPiece::substr(size_type pos, size_type n) const { const StringPiece::size_type StringPiece::npos = size_type(-1); -} // namespace base +} // namespace phonenumbers +} // namespace i18n diff --git a/base/strings/string_piece.h b/base/strings/string_piece.h index 8ff8633..3d856f9 100644 --- a/base/strings/string_piece.h +++ b/base/strings/string_piece.h @@ -23,7 +23,8 @@ #include "phonenumbers/base/basictypes.h" -namespace base { +namespace i18n { +namespace phonenumbers { class StringPiece { public: @@ -187,6 +188,7 @@ inline bool operator>=(const StringPiece& x, const StringPiece& y) { return !(x < y); } -} // namespace base +} // namespace phonenumbers +} // namespace i18n #endif // I18N_PHONENUMBERS_BASE_STRINGS_STRING_PIECE_H_ diff --git a/base/synchronization/lock.h b/base/synchronization/lock.h index 502c75f..c68fefd 100644 --- a/base/synchronization/lock.h +++ b/base/synchronization/lock.h @@ -20,15 +20,20 @@ #if defined(I18N_PHONENUMBERS_USE_BOOST) #include -namespace base { - typedef boost::mutex Lock; - typedef boost::mutex::scoped_lock AutoLock; -} +namespace i18n { +namespace phonenumbers { + +typedef boost::mutex Lock; +typedef boost::mutex::scoped_lock AutoLock; + +} // namespace phonenumbers +} // namespace i18n #else // I18N_PHONENUMBERS_USE_BOOST #include "phonenumbers/base/thread_safety_check.h" -namespace base { +namespace i18n { +namespace phonenumbers { // Dummy lock implementation. If you care about thread-safety, please compile // with -DI18N_PHONENUMBERS_USE_BOOST. @@ -38,7 +43,8 @@ struct AutoLock { AutoLock(Lock) {} }; -} // namespace base +} // namespace phonenumbers +} // namespace i18n #endif // I18N_PHONENUMBERS_USE_BOOST #endif // I18N_PHONENUMBERS_BASE_SYNCHRONIZATION_LOCK_H_ diff --git a/base/template_util.h b/base/template_util.h index 8076e1e..e619dc6 100644 --- a/base/template_util.h +++ b/base/template_util.h @@ -7,7 +7,8 @@ #include // For size_t. -namespace base { +namespace i18n { +namespace phonenumbers { // template definitions from tr1 @@ -101,6 +102,7 @@ struct is_class sizeof(internal::YesType)> { }; -} // namespace base +} // namespace phonenumbers +} // namespace i18n #endif // I18N_PHONENUMBERS_BASE_TEMPLATE_UTIL_H_ diff --git a/regexp_cache.cc b/regexp_cache.cc index 24adc5b..dbd7676 100644 --- a/regexp_cache.cc +++ b/regexp_cache.cc @@ -28,8 +28,6 @@ using std::string; namespace i18n { namespace phonenumbers { -using base::AutoLock; - RegExpCache::RegExpCache(const AbstractRegExpFactory& regexp_factory, size_t min_items) : regexp_factory_(regexp_factory), diff --git a/regexp_cache.h b/regexp_cache.h index 46234c0..c2c471a 100644 --- a/regexp_cache.h +++ b/regexp_cache.h @@ -65,7 +65,7 @@ class RegExpCache { private: const AbstractRegExpFactory& regexp_factory_; - base::Lock lock_; // protects cache_impl_ + Lock lock_; // protects cache_impl_ scoped_ptr cache_impl_; // protected by lock_ friend class RegExpCacheTest_CacheConstructor_Test; DISALLOW_COPY_AND_ASSIGN(RegExpCache); diff --git a/utf/stringpiece.h b/utf/stringpiece.h index 962b117..70d3f76 100644 --- a/utf/stringpiece.h +++ b/utf/stringpiece.h @@ -18,6 +18,6 @@ #include "phonenumbers/base/strings/string_piece.h" -using base::StringPiece; +using i18n::phonenumbers::StringPiece; #endif // STRINGS_STRINGPIECE_H_ -- cgit v1.2.3