diff options
author | Nat Goodspeed <nat@lindenlab.com> | 2011-12-06 09:54:59 -0500 |
---|---|---|
committer | Nat Goodspeed <nat@lindenlab.com> | 2011-12-06 09:54:59 -0500 |
commit | 3e6c522084385e5c40796849b9cefa69e95c981f (patch) | |
tree | 3aeff09062d415b9f3361c17c3bc194ccdb0e031 /indra/llcommon | |
parent | 1a6846444f35a89001dffa33d1f76067193165f7 (diff) |
LLSD-14: Extract remaining conditional LLSD mbrs to namespace llsd.
Per Monty's code review, it's dubious practice to have a class in which
certain members are sometimes visible, other times not. If these were virtual
methods, or non-static data members, the error would be obvious -- but even
with static data members and non-virtual methods, it looks like an ODR
violation. Extract conditional methods as free functions, as in changeset
07cd70e75473.
Diffstat (limited to 'indra/llcommon')
-rw-r--r-- | indra/llcommon/llsd.cpp | 38 | ||||
-rw-r--r-- | indra/llcommon/llsd.h | 22 |
2 files changed, 23 insertions, 37 deletions
diff --git a/indra/llcommon/llsd.cpp b/indra/llcommon/llsd.cpp index 151eb4084a..e295e3c621 100644 --- a/indra/llcommon/llsd.cpp +++ b/indra/llcommon/llsd.cpp @@ -54,23 +54,17 @@ namespace using namespace LLSDUnnamedNamespace; #endif - -// Normally undefined -#ifdef LLSD_DEBUG_INFO +namespace llsd +{ // statics -S32 LLSD::sLLSDAllocationCount = 0; -S32 LLSD::sLLSDNetObjects = 0; - -#define ALLOC_LLSD_OBJECT { sLLSDNetObjects++; sLLSDAllocationCount++; } -#define FREE_LLSD_OBJECT { sLLSDNetObjects--; } +S32 sLLSDAllocationCount = 0; +S32 sLLSDNetObjects = 0; -#else +} // namespace llsd -#define ALLOC_LLSD_OBJECT -#define FREE_LLSD_OBJECT - -#endif +#define ALLOC_LLSD_OBJECT { llsd::sLLSDNetObjects++; llsd::sLLSDAllocationCount++; } +#define FREE_LLSD_OBJECT { llsd::sLLSDNetObjects--; } class LLSD::Impl /**< This class is the abstract base class of the implementation of LLSD @@ -158,6 +152,8 @@ public: safe(llsd.impl).calcStats(type_counts, share_counts); } + static const Impl& getImpl(const LLSD& llsd) { return safe(llsd.impl); } + static Impl& getImpl(LLSD& llsd) { return safe(llsd.impl); } static const LLSD& undef(); @@ -452,10 +448,8 @@ namespace { std::cout << "Map size: " << mData.size() << std::endl; - #ifdef LLSD_DEBUG_INFO - std::cout << "LLSD Net Objects: " << LLSD::sLLSDNetObjects << std::endl; - std::cout << "LLSD allocations: " << LLSD::sLLSDAllocationCount << std::endl; - #endif + std::cout << "LLSD Net Objects: " << llsd::sLLSDNetObjects << std::endl; + std::cout << "LLSD allocations: " << llsd::sLLSDAllocationCount << std::endl; std::cout << "LLSD::Impl Net Objects: " << sOutstandingCount << std::endl; std::cout << "LLSD::Impl allocations: " << sAllocationCount << std::endl; @@ -958,12 +952,10 @@ namespace llsd U32 allocationCount() { return LLSD::Impl::sAllocationCount; } U32 outstandingCount() { return LLSD::Impl::sOutstandingCount; } -} // namespace llsd - // Diagnostic dump of contents in an LLSD object -#ifdef LLSD_DEBUG_INFO -void LLSD::dumpStats() const { safe(impl).dumpStats(); } -#endif +void dumpStats(const LLSD& llsd) { LLSD::Impl::getImpl(llsd).dumpStats(); } + +} // namespace llsd // static std::string LLSD::typeString(Type type) @@ -982,7 +974,7 @@ std::string LLSD::typeString(Type type) "Array" }; - if (0 <= type && type < (sizeof(sTypeNameArray)/sizeof(sTypeNameArray[0]))) + if (0 <= type && type < LL_ARRAY_SIZE(sTypeNameArray)) { return sTypeNameArray[type]; } diff --git a/indra/llcommon/llsd.h b/indra/llcommon/llsd.h index ae083dd629..5eb69059ac 100644 --- a/indra/llcommon/llsd.h +++ b/indra/llcommon/llsd.h @@ -401,20 +401,8 @@ private: //@} public: -#ifdef LLSD_DEBUG_INFO - void dumpStats() const; // Output information on object and usage -#endif static std::string typeString(Type type); // Return human-readable type as a string - -#ifdef LLSD_DEBUG_INFO - /// @warn THESE COUNTS WILL NOT BE ACCURATE IN A MULTI-THREADED - /// ENVIRONMENT. - /// - /// These counts track LLSD (public) objects. - static S32 sLLSDAllocationCount; // Number of LLSD objects ever created - static S32 sLLSDNetObjects; // Number of LLSD objects that exist -#endif }; struct llsd_select_bool : public std::unary_function<LLSD, LLSD::Boolean> @@ -465,15 +453,21 @@ LL_COMMON_API std::ostream& operator<<(std::ostream& s, const LLSD& llsd); namespace llsd { +#ifdef LLSD_DEBUG_INFO /** @name Unit Testing Interface */ //@{ -#ifdef LLSD_DEBUG_INFO - /// @warn THESE COUNTS WILL NOT BE ACCURATE IN A MULTI-THREADED + LL_COMMON_API void dumpStats(const LLSD&); ///< Output information on object and usage + + /// @warn THE FOLLOWING COUNTS WILL NOT BE ACCURATE IN A MULTI-THREADED /// ENVIRONMENT. /// /// These counts track LLSD::Impl (hidden) objects. LL_COMMON_API U32 allocationCount(); ///< how many Impls have been made LL_COMMON_API U32 outstandingCount(); ///< how many Impls are still alive + + /// These counts track LLSD (public) objects. + LL_COMMON_API extern S32 sLLSDAllocationCount; ///< Number of LLSD objects ever created + LL_COMMON_API extern S32 sLLSDNetObjects; ///< Number of LLSD objects that exist #endif //@} |