bump product version to 5.0.4.1
[LibreOffice.git] / tools / source / rc / resary.cxx
blob03854d31eec04675248f6646a3d6eb34979d4c13
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <tools/resary.hxx>
21 #include <tools/resmgr.hxx>
22 #include <tools/rcid.h>
24 #include <vector>
26 namespace {
28 struct ImplResStringItem
30 OUString m_aStr;
31 sal_IntPtr m_nValue;
33 ImplResStringItem( const OUString& rStr, long nValue = 0 ) :
34 m_aStr(rStr),
35 m_nValue(nValue)
36 { }
41 struct ResStringArray::Impl
43 std::vector<ImplResStringItem> m_aStrings;
46 ResStringArray::ResStringArray( const ResId& rResId ) :
47 mpImpl(new Impl)
49 rResId.SetRT( RSC_STRINGARRAY );
50 ResMgr* pMgr = rResId.GetResMgr();
51 if( pMgr && pMgr->GetResource( rResId ) )
53 pMgr->GetClass();
54 pMgr->Increment( sizeof( RSHEADER_TYPE ) );
55 const sal_uInt32 nItems = pMgr->ReadLong();
56 if ( nItems )
58 mpImpl->m_aStrings.reserve( nItems );
59 for ( sal_uInt32 i = 0; i < nItems; i++ )
61 // load string
62 mpImpl->m_aStrings.push_back(ImplResStringItem(pMgr->ReadString()));
64 // load value
65 mpImpl->m_aStrings[i].m_nValue = pMgr->ReadLong();
71 ResStringArray::~ResStringArray()
73 delete mpImpl;
76 OUString ResStringArray::GetString( sal_uInt32 nIndex ) const
78 return (nIndex < mpImpl->m_aStrings.size()) ? mpImpl->m_aStrings[nIndex].m_aStr : OUString();
81 sal_IntPtr ResStringArray::GetValue( sal_uInt32 nIndex ) const
83 return (nIndex < mpImpl->m_aStrings.size()) ? mpImpl->m_aStrings[nIndex].m_nValue : -1;
86 sal_uInt32 ResStringArray::Count() const
88 return sal_uInt32(mpImpl->m_aStrings.size());
91 sal_uInt32 ResStringArray::FindIndex( sal_IntPtr nValue ) const
93 const sal_uInt32 nItems = mpImpl->m_aStrings.size();
94 for ( sal_uInt32 i = 0; i < nItems; i++ )
96 if (mpImpl->m_aStrings[i].m_nValue == nValue)
97 return i;
99 return RESARRAY_INDEX_NOTFOUND;
102 sal_uInt32 ResStringArray::AddItem( const OUString& rString, sal_IntPtr nValue )
104 mpImpl->m_aStrings.push_back(ImplResStringItem(rString, nValue));
105 return mpImpl->m_aStrings.size();
108 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */