Browse Source

CPP: Fix compilation error when using GetInstance() caused by the Boost CL.

pull/567/head
Philip Liard 15 years ago
committed by Mihaela Rosca
parent
commit
81baa2c1dc
3 changed files with 9 additions and 3 deletions
  1. +2
    -2
      cpp/src/base/singleton.h
  2. +3
    -1
      cpp/src/phonenumberutil.h
  3. +4
    -0
      cpp/src/phonenumberutil_test.cc

+ 2
- 2
cpp/src/base/singleton.h View File

@ -31,7 +31,7 @@ class Singleton : private boost::noncopyable {
static T* GetInstance() { static T* GetInstance() {
boost::call_once(Init, flag); boost::call_once(Init, flag);
return instance;
return instance.get();
} }
private: private:
@ -43,7 +43,7 @@ class Singleton : private boost::noncopyable {
static boost::once_flag flag; static boost::once_flag flag;
}; };
template <class T> boost::scoped_ptr<T> Singleton<T>::instance = NULL;
template <class T> boost::scoped_ptr<T> Singleton<T>::instance;
template <class T> boost::once_flag Singleton<T>::flag = BOOST_ONCE_INIT; template <class T> boost::once_flag Singleton<T>::flag = BOOST_ONCE_INIT;
} // namespace phonenumbers } // namespace phonenumbers


+ 3
- 1
cpp/src/phonenumberutil.h View File

@ -62,9 +62,12 @@ class PhoneNumberUtil {
friend struct DefaultSingletonTraits<PhoneNumberUtil>; friend struct DefaultSingletonTraits<PhoneNumberUtil>;
#else #else
class PhoneNumberUtil : public Singleton<PhoneNumberUtil> { class PhoneNumberUtil : public Singleton<PhoneNumberUtil> {
friend class Singleton<PhoneNumberUtil>;
#endif #endif
friend class PhoneNumberUtilTest; friend class PhoneNumberUtilTest;
public: public:
~PhoneNumberUtil();
// INTERNATIONAL and NATIONAL formats are consistent with the definition // INTERNATIONAL and NATIONAL formats are consistent with the definition
// in ITU-T Recommendation E. 123. For example, the number of the Google // in ITU-T Recommendation E. 123. For example, the number of the Google
// Zürich office will be written as "+41 44 668 1800" in INTERNATIONAL // Zürich office will be written as "+41 44 668 1800" in INTERNATIONAL
@ -533,7 +536,6 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> {
scoped_ptr<map<string, PhoneMetadata> > region_to_metadata_map_; scoped_ptr<map<string, PhoneMetadata> > region_to_metadata_map_;
PhoneNumberUtil(); PhoneNumberUtil();
~PhoneNumberUtil();
// Gets all the supported regions. // Gets all the supported regions.
void GetSupportedRegions(set<string>* regions) const; void GetSupportedRegions(set<string>* regions) const;


+ 4
- 0
cpp/src/phonenumberutil_test.cc View File

@ -248,6 +248,10 @@ ostream& operator<<(ostream& os, const PhoneNumber& number) {
return os; return os;
} }
TEST_F(PhoneNumberUtilTest, GetInstance) {
EXPECT_FALSE(PhoneNumberUtil::GetInstance() == NULL);
}
TEST_F(PhoneNumberUtilTest, GetSupportedRegions) { TEST_F(PhoneNumberUtilTest, GetSupportedRegions) {
set<string> regions; set<string> regions;


Loading…
Cancel
Save