From 764600bc6175a32d119487afda2e8409f3395666 Mon Sep 17 00:00:00 2001 From: Kohei Yoshida Date: Tue, 18 Nov 2014 21:42:23 -0500 Subject: Apply pimpl to ResStringArray, to hide its internals. Change-Id: I23969735f35e221a1aad39081ee63d02066d856f --- tools/source/rc/resary.cxx | 57 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 9 deletions(-) (limited to 'tools') diff --git a/tools/source/rc/resary.cxx b/tools/source/rc/resary.cxx index dac1d94df054..03854d31eec0 100644 --- a/tools/source/rc/resary.cxx +++ b/tools/source/rc/resary.cxx @@ -17,11 +17,34 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#include #include +#include #include -ResStringArray::ResStringArray( const ResId& rResId ) +#include + +namespace { + +struct ImplResStringItem +{ + OUString m_aStr; + sal_IntPtr m_nValue; + + ImplResStringItem( const OUString& rStr, long nValue = 0 ) : + m_aStr(rStr), + m_nValue(nValue) + { } +}; + +} + +struct ResStringArray::Impl +{ + std::vector m_aStrings; +}; + +ResStringArray::ResStringArray( const ResId& rResId ) : + mpImpl(new Impl) { rResId.SetRT( RSC_STRINGARRAY ); ResMgr* pMgr = rResId.GetResMgr(); @@ -32,14 +55,14 @@ ResStringArray::ResStringArray( const ResId& rResId ) const sal_uInt32 nItems = pMgr->ReadLong(); if ( nItems ) { - m_aStrings.reserve( nItems ); + mpImpl->m_aStrings.reserve( nItems ); for ( sal_uInt32 i = 0; i < nItems; i++ ) { // load string - m_aStrings.push_back( ImplResStringItem( pMgr->ReadString() ) ); + mpImpl->m_aStrings.push_back(ImplResStringItem(pMgr->ReadString())); // load value - m_aStrings[i].m_nValue = pMgr->ReadLong(); + mpImpl->m_aStrings[i].m_nValue = pMgr->ReadLong(); } } } @@ -47,14 +70,30 @@ ResStringArray::ResStringArray( const ResId& rResId ) ResStringArray::~ResStringArray() { + delete mpImpl; +} + +OUString ResStringArray::GetString( sal_uInt32 nIndex ) const +{ + return (nIndex < mpImpl->m_aStrings.size()) ? mpImpl->m_aStrings[nIndex].m_aStr : OUString(); +} + +sal_IntPtr ResStringArray::GetValue( sal_uInt32 nIndex ) const +{ + return (nIndex < mpImpl->m_aStrings.size()) ? mpImpl->m_aStrings[nIndex].m_nValue : -1; +} + +sal_uInt32 ResStringArray::Count() const +{ + return sal_uInt32(mpImpl->m_aStrings.size()); } sal_uInt32 ResStringArray::FindIndex( sal_IntPtr nValue ) const { - const sal_uInt32 nItems = m_aStrings.size(); + const sal_uInt32 nItems = mpImpl->m_aStrings.size(); for ( sal_uInt32 i = 0; i < nItems; i++ ) { - if ( m_aStrings[i].m_nValue == nValue ) + if (mpImpl->m_aStrings[i].m_nValue == nValue) return i; } return RESARRAY_INDEX_NOTFOUND; @@ -62,8 +101,8 @@ sal_uInt32 ResStringArray::FindIndex( sal_IntPtr nValue ) const sal_uInt32 ResStringArray::AddItem( const OUString& rString, sal_IntPtr nValue ) { - m_aStrings.push_back( ImplResStringItem( rString, nValue)); - return m_aStrings.size(); + mpImpl->m_aStrings.push_back(ImplResStringItem(rString, nValue)); + return mpImpl->m_aStrings.size(); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit