Browse Source

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
pull/567/head
Philippe Liard 13 years ago
committed by Mihaela Rosca
parent
commit
98e96f3a8b
9 changed files with 44 additions and 46 deletions
  1. +0
    -17
      cpp/src/phonenumbers/base/basictypes.h
  2. +18
    -13
      cpp/src/phonenumbers/base/memory/scoped_ptr.h
  3. +4
    -2
      cpp/src/phonenumbers/base/strings/string_piece.cc
  4. +4
    -2
      cpp/src/phonenumbers/base/strings/string_piece.h
  5. +12
    -6
      cpp/src/phonenumbers/base/synchronization/lock.h
  6. +4
    -2
      cpp/src/phonenumbers/base/template_util.h
  7. +0
    -2
      cpp/src/phonenumbers/regexp_cache.cc
  8. +1
    -1
      cpp/src/phonenumbers/regexp_cache.h
  9. +1
    -1
      cpp/src/phonenumbers/utf/stringpiece.h

+ 0
- 17
cpp/src/phonenumbers/base/basictypes.h View File

@ -282,21 +282,4 @@ template<typename T>
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_

+ 18
- 13
cpp/src/phonenumbers/base/memory/scoped_ptr.h View File

@ -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<U*, T*>::value),
COMPILE_ASSERT((is_convertible<U*, T*>::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<T> is like a T*, except that the destructor of scoped_ptr<T>
// 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 <class T, class D = base::DefaultDeleter<T> >
template <class T, class D = i18n::phonenumbers::DefaultDeleter<T> >
class scoped_ptr {
public:
// The element and deleter types.
@ -244,7 +245,8 @@ class scoped_ptr {
// implementation of scoped_ptr.
template <typename U, typename V>
scoped_ptr(scoped_ptr<U, V> other) : impl_(&other.impl_) {
COMPILE_ASSERT(!base::is_array<U>::value, U_cannot_be_an_array);
COMPILE_ASSERT(!i18n::phonenumbers::is_array<U>::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 <typename U, typename V>
scoped_ptr& operator=(scoped_ptr<U, V> rhs) {
COMPILE_ASSERT(!base::is_array<U>::value, U_cannot_be_an_array);
COMPILE_ASSERT(!i18n::phonenumbers::is_array<U>::value,
U_cannot_be_an_array);
impl_.TakeState(&rhs.impl_);
return *this;
}
@ -287,8 +290,8 @@ class scoped_ptr {
// Allow scoped_ptr<element_type> to be used in boolean expressions, but not
// implicitly convertible to a real bool (which is dangerous).
private:
typedef base::internal::scoped_ptr_impl<element_type, deleter_type>
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 <typename U, typename V> friend class scoped_ptr;
base::internal::scoped_ptr_impl<element_type, deleter_type> 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<T[], D> {
// Allow scoped_ptr<element_type> to be used in boolean expressions, but not
// implicitly convertible to a real bool (which is dangerous).
private:
typedef base::internal::scoped_ptr_impl<element_type, deleter_type>
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<T[], D> {
enum { type_must_be_complete = sizeof(element_type) };
// Actually hold the data.
base::internal::scoped_ptr_impl<element_type, deleter_type> 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


+ 4
- 2
cpp/src/phonenumbers/base/strings/string_piece.cc View File

@ -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

+ 4
- 2
cpp/src/phonenumbers/base/strings/string_piece.h View File

@ -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_

+ 12
- 6
cpp/src/phonenumbers/base/synchronization/lock.h View File

@ -20,15 +20,20 @@
#if defined(I18N_PHONENUMBERS_USE_BOOST)
#include <boost/thread/mutex.hpp>
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_

+ 4
- 2
cpp/src/phonenumbers/base/template_util.h View File

@ -7,7 +7,8 @@
#include <cstddef> // 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_

+ 0
- 2
cpp/src/phonenumbers/regexp_cache.cc View File

@ -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),


+ 1
- 1
cpp/src/phonenumbers/regexp_cache.h View File

@ -65,7 +65,7 @@ class RegExpCache {
private:
const AbstractRegExpFactory& regexp_factory_;
base::Lock lock_; // protects cache_impl_
Lock lock_; // protects cache_impl_
scoped_ptr<CacheImpl> cache_impl_; // protected by lock_
friend class RegExpCacheTest_CacheConstructor_Test;
DISALLOW_COPY_AND_ASSIGN(RegExpCache);


+ 1
- 1
cpp/src/phonenumbers/utf/stringpiece.h View File

@ -18,6 +18,6 @@
#include "phonenumbers/base/strings/string_piece.h"
using base::StringPiece;
using i18n::phonenumbers::StringPiece;
#endif // STRINGS_STRINGPIECE_H_

Loading…
Cancel
Save