diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-01-03 21:31:44 -0500 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-01-04 09:45:18 -0500 |
commit | 4cc17f3b959110f1eb0c616847c0a821ce384186 (patch) | |
tree | 70cf3f93bb4eff6fc436a6c4b6cfe014680fd449 /sc | |
parent | d5ea81b87b8a19b23007691c8b14e6787ecb0290 (diff) |
Remove hard-coded upper field limit from ScDPInitState.
This was going to cause trouble sooner or later....
Change-Id: I5eea2ba7b1cc4e358a0192b4863d79596549bad9
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/dptabres.hxx | 39 | ||||
-rw-r--r-- | sc/source/core/data/dptabres.cxx | 62 |
2 files changed, 41 insertions, 60 deletions
diff --git a/sc/inc/dptabres.hxx b/sc/inc/dptabres.hxx index 81c3c01ab262..97cb230cd515 100644 --- a/sc/inc/dptabres.hxx +++ b/sc/inc/dptabres.hxx @@ -51,35 +51,36 @@ class ScDPResultVisibilityData; struct ScDPValueData; class ScDPItemData; -// -// Member names that are being processed for InitFrom/LateInitFrom -// (needed for initialization of grouped items) -// +/** + * Member names that are being processed for InitFrom/LateInitFrom (needed + * for initialization of grouped items). + */ class ScDPInitState { - long* pIndex; // array - SCROW* pData; // array - long nCount; - public: - ScDPInitState(); - ~ScDPInitState(); + struct Member + { + long mnSrcIndex; + SCROW mnNameIndex; + + Member(long nSrcIndex, SCROW nNameIndex); + }; + + void AddMember(long nSourceIndex, SCROW nMember); + void RemoveMember(); - void AddMember( long nSourceIndex,SCROW nMember); - void RemoveMember(); + const std::vector<Member>& GetMembers() const { return maMembers; } - long GetCount() const { return nCount; } - const long* GetSource() const { return pIndex; } - const SCROW* GetNameIds() const { return pData; } +private: + std::vector<Member> maMembers; }; typedef ::std::vector<sal_Int32> ScMemberSortOrder; -// -// selected subtotal information, passed down the dimensions -// - +/** + * Select subtotal information, passed down the dimensions. + */ struct ScDPSubTotalState { ScSubTotalFunc eColForce; diff --git a/sc/source/core/data/dptabres.cxx b/sc/source/core/data/dptabres.cxx index 01c256d23c71..12a84dedd9cb 100644 --- a/sc/source/core/data/dptabres.cxx +++ b/sc/source/core/data/dptabres.cxx @@ -222,41 +222,21 @@ sal_Bool ScDPColMembersOrder::operator()( sal_Int32 nIndex1, sal_Int32 nIndex2 ) return lcl_IsLess( pDataMember1, pDataMember2, nMeasure, bAscending ); } -// ----------------------------------------------------------------------- - -ScDPInitState::ScDPInitState() : - nCount( 0 ) -{ - pIndex = new long[SC_DP_MAX_FIELDS]; - pData = new SCROW[SC_DP_MAX_FIELDS]; -} - -ScDPInitState::~ScDPInitState() -{ - delete[] pIndex; - delete[] pData; -} +ScDPInitState::Member::Member(long nSrcIndex, SCROW nNameIndex) : + mnSrcIndex(nSrcIndex), mnNameIndex(nNameIndex) {} void ScDPInitState::AddMember( long nSourceIndex, SCROW nMember ) { - OSL_ENSURE( nCount < SC_DP_MAX_FIELDS, "too many InitState members" ); - if ( nCount < SC_DP_MAX_FIELDS ) - { - pIndex[nCount] = nSourceIndex; - pData[nCount] = nMember; - ++nCount; - } + maMembers.push_back(Member(nSourceIndex, nMember)); } void ScDPInitState::RemoveMember() { - OSL_ENSURE( nCount > 0, "RemoveColIndex without index" ); - if ( nCount > 0 ) - --nCount; + OSL_ENSURE(!maMembers.empty(), "ScDPInitState::RemoveMember: Attempt to remmove member while empty."); + if (!maMembers.empty()) + maMembers.pop_back(); } -// ----------------------------------------------------------------------- - static void lcl_DumpRow( const String& rType, const String& rName, const ScDPAggData* pAggData, ScDocument* pDoc, ScAddress& rPos ) { @@ -2649,16 +2629,15 @@ sal_Bool ScDPGroupCompare::TestIncluded( const ScDPMember& rMember ) //! get array of groups (or indexes) before loop? ScDPItemData aMemberData; rMember.FillItemData( aMemberData ); - long nInitCount = rInitState.GetCount(); - const long* pInitSource = rInitState.GetSource(); - const SCROW* pInitNames = rInitState.GetNameIds(); - for (long nInitPos=0; nInitPos<nInitCount && bInclude; nInitPos++) + const std::vector<ScDPInitState::Member>& rMemStates = rInitState.GetMembers(); + std::vector<ScDPInitState::Member>::const_iterator it = rMemStates.begin(), itEnd = rMemStates.end(); + for (; it != itEnd && bInclude; ++it) { - if ( pResultData->GetGroupBase( pInitSource[nInitPos] ) == nDimSource ) + if (pResultData->GetGroupBase(it->mnSrcIndex) == nDimSource) { - bInclude = pResultData->IsInGroup( pInitNames[nInitPos], pInitSource[nInitPos], - aMemberData, nDimSource ); + bInclude = pResultData->IsInGroup( + it->mnNameIndex, it->mnSrcIndex, aMemberData, nDimSource); } } } @@ -2670,17 +2649,18 @@ sal_Bool ScDPGroupCompare::TestIncluded( const ScDPMember& rMember ) //! get array of groups (or indexes) before loop? ScDPItemData aMemberData; rMember.FillItemData( aMemberData ); - long nInitCount = rInitState.GetCount(); - const long* pInitSource = rInitState.GetSource(); - /*const ScDPItemData* pInitNames = rInitState.GetNames();*/ - const SCROW* pInitNames = rInitState.GetNameIds(); - for (long nInitPos=0; nInitPos<nInitCount && bInclude; nInitPos++) - if ( pResultData->GetGroupBase( pInitSource[nInitPos] ) == nGroupBase ) + const std::vector<ScDPInitState::Member>& rMemStates = rInitState.GetMembers(); + std::vector<ScDPInitState::Member>::const_iterator it = rMemStates.begin(), itEnd = rMemStates.end(); + for (; it != itEnd && bInclude; ++it) + { + if (pResultData->GetGroupBase(it->mnSrcIndex) == nGroupBase) { // same base (hierarchy between the two groups is irrelevant) - bInclude = pResultData->HasCommonElement( pInitNames[nInitPos], pInitSource[nInitPos], - aMemberData, nDimSource ); + bInclude = pResultData->HasCommonElement( + it->mnNameIndex, it->mnSrcIndex, aMemberData, nDimSource); } + + } } return bInclude; |