Skip to content
Snippets Groups Projects
Commit 3e6c5220 authored by Nat Goodspeed's avatar Nat Goodspeed
Browse files

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.
parent 1a684644
No related branches found
No related tags found
No related merge requests found
...@@ -54,23 +54,17 @@ namespace ...@@ -54,23 +54,17 @@ namespace
using namespace LLSDUnnamedNamespace; using namespace LLSDUnnamedNamespace;
#endif #endif
namespace llsd
// Normally undefined {
#ifdef LLSD_DEBUG_INFO
// statics // statics
S32 LLSD::sLLSDAllocationCount = 0; S32 sLLSDAllocationCount = 0;
S32 LLSD::sLLSDNetObjects = 0; S32 sLLSDNetObjects = 0;
#define ALLOC_LLSD_OBJECT { sLLSDNetObjects++; sLLSDAllocationCount++; }
#define FREE_LLSD_OBJECT { sLLSDNetObjects--; }
#else } // namespace llsd
#define ALLOC_LLSD_OBJECT #define ALLOC_LLSD_OBJECT { llsd::sLLSDNetObjects++; llsd::sLLSDAllocationCount++; }
#define FREE_LLSD_OBJECT #define FREE_LLSD_OBJECT { llsd::sLLSDNetObjects--; }
#endif
class LLSD::Impl class LLSD::Impl
/**< This class is the abstract base class of the implementation of LLSD /**< This class is the abstract base class of the implementation of LLSD
...@@ -158,6 +152,8 @@ class LLSD::Impl ...@@ -158,6 +152,8 @@ class LLSD::Impl
safe(llsd.impl).calcStats(type_counts, share_counts); 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(); static const LLSD& undef();
...@@ -452,10 +448,8 @@ namespace ...@@ -452,10 +448,8 @@ namespace
{ {
std::cout << "Map size: " << mData.size() << std::endl; std::cout << "Map size: " << mData.size() << std::endl;
#ifdef LLSD_DEBUG_INFO std::cout << "LLSD Net Objects: " << llsd::sLLSDNetObjects << std::endl;
std::cout << "LLSD Net Objects: " << LLSD::sLLSDNetObjects << std::endl; std::cout << "LLSD allocations: " << llsd::sLLSDAllocationCount << std::endl;
std::cout << "LLSD allocations: " << LLSD::sLLSDAllocationCount << std::endl;
#endif
std::cout << "LLSD::Impl Net Objects: " << sOutstandingCount << std::endl; std::cout << "LLSD::Impl Net Objects: " << sOutstandingCount << std::endl;
std::cout << "LLSD::Impl allocations: " << sAllocationCount << std::endl; std::cout << "LLSD::Impl allocations: " << sAllocationCount << std::endl;
...@@ -958,12 +952,10 @@ namespace llsd ...@@ -958,12 +952,10 @@ namespace llsd
U32 allocationCount() { return LLSD::Impl::sAllocationCount; } U32 allocationCount() { return LLSD::Impl::sAllocationCount; }
U32 outstandingCount() { return LLSD::Impl::sOutstandingCount; } U32 outstandingCount() { return LLSD::Impl::sOutstandingCount; }
} // namespace llsd
// Diagnostic dump of contents in an LLSD object // Diagnostic dump of contents in an LLSD object
#ifdef LLSD_DEBUG_INFO void dumpStats(const LLSD& llsd) { LLSD::Impl::getImpl(llsd).dumpStats(); }
void LLSD::dumpStats() const { safe(impl).dumpStats(); }
#endif } // namespace llsd
// static // static
std::string LLSD::typeString(Type type) std::string LLSD::typeString(Type type)
...@@ -982,7 +974,7 @@ std::string LLSD::typeString(Type type) ...@@ -982,7 +974,7 @@ std::string LLSD::typeString(Type type)
"Array" "Array"
}; };
if (0 <= type && type < (sizeof(sTypeNameArray)/sizeof(sTypeNameArray[0]))) if (0 <= type && type < LL_ARRAY_SIZE(sTypeNameArray))
{ {
return sTypeNameArray[type]; return sTypeNameArray[type];
} }
......
...@@ -401,20 +401,8 @@ class LL_COMMON_API LLSD ...@@ -401,20 +401,8 @@ class LL_COMMON_API LLSD
//@} //@}
public: 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 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> 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); ...@@ -465,15 +453,21 @@ LL_COMMON_API std::ostream& operator<<(std::ostream& s, const LLSD& llsd);
namespace llsd namespace llsd
{ {
#ifdef LLSD_DEBUG_INFO
/** @name Unit Testing Interface */ /** @name Unit Testing Interface */
//@{ //@{
#ifdef LLSD_DEBUG_INFO LL_COMMON_API void dumpStats(const LLSD&); ///< Output information on object and usage
/// @warn THESE COUNTS WILL NOT BE ACCURATE IN A MULTI-THREADED
/// @warn THE FOLLOWING COUNTS WILL NOT BE ACCURATE IN A MULTI-THREADED
/// ENVIRONMENT. /// ENVIRONMENT.
/// ///
/// These counts track LLSD::Impl (hidden) objects. /// These counts track LLSD::Impl (hidden) objects.
LL_COMMON_API U32 allocationCount(); ///< how many Impls have been made LL_COMMON_API U32 allocationCount(); ///< how many Impls have been made
LL_COMMON_API U32 outstandingCount(); ///< how many Impls are still alive 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 #endif
//@} //@}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment