xref: /aoo41x/main/rsc/source/tools/rschash.cxx (revision 477794c1)
1*477794c1SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*477794c1SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*477794c1SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*477794c1SAndrew Rist  * distributed with this work for additional information
6*477794c1SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*477794c1SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*477794c1SAndrew Rist  * "License"); you may not use this file except in compliance
9*477794c1SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*477794c1SAndrew Rist  *
11*477794c1SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*477794c1SAndrew Rist  *
13*477794c1SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*477794c1SAndrew Rist  * software distributed under the License is distributed on an
15*477794c1SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*477794c1SAndrew Rist  * KIND, either express or implied.  See the License for the
17*477794c1SAndrew Rist  * specific language governing permissions and limitations
18*477794c1SAndrew Rist  * under the License.
19*477794c1SAndrew Rist  *
20*477794c1SAndrew Rist  *************************************************************/
21*477794c1SAndrew Rist 
22*477794c1SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_rsc.hxx"
26cdf0e10cSrcweir #include <rschash.hxx>
27cdf0e10cSrcweir 
28cdf0e10cSrcweir using namespace rtl;
29cdf0e10cSrcweir 
AtomContainer()30cdf0e10cSrcweir AtomContainer::AtomContainer()
31cdf0e10cSrcweir {
32cdf0e10cSrcweir     m_aStringToID[ OString() ] = 0;
33cdf0e10cSrcweir     m_aIDToString[ 0 ] = OString();
34cdf0e10cSrcweir     m_nNextID = 1;
35cdf0e10cSrcweir }
36cdf0e10cSrcweir 
~AtomContainer()37cdf0e10cSrcweir AtomContainer::~AtomContainer()
38cdf0e10cSrcweir {
39cdf0e10cSrcweir }
40cdf0e10cSrcweir 
getID(const OString & rStr,bool bOnlyIfExists)41cdf0e10cSrcweir Atom AtomContainer::getID( const OString& rStr, bool bOnlyIfExists )
42cdf0e10cSrcweir {
43cdf0e10cSrcweir     OString aKey = rStr.toAsciiLowerCase();
44cdf0e10cSrcweir     std::hash_map< OString, Atom, OStringHash >::const_iterator it =
45cdf0e10cSrcweir         m_aStringToID.find( aKey );
46cdf0e10cSrcweir     if( it != m_aStringToID.end() )
47cdf0e10cSrcweir         return it->second;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir     if( bOnlyIfExists )
50cdf0e10cSrcweir         return InvalidAtom;
51cdf0e10cSrcweir 
52cdf0e10cSrcweir     Atom aRet = m_nNextID;
53cdf0e10cSrcweir     m_aStringToID[ aKey ] = m_nNextID;
54cdf0e10cSrcweir     m_aIDToString[ m_nNextID ] = rStr;
55cdf0e10cSrcweir     m_nNextID++;
56cdf0e10cSrcweir     return aRet;
57cdf0e10cSrcweir }
58cdf0e10cSrcweir 
getString(Atom nAtom)59cdf0e10cSrcweir const OString& AtomContainer::getString( Atom nAtom )
60cdf0e10cSrcweir {
61cdf0e10cSrcweir     std::hash_map< Atom, OString >::const_iterator it =
62cdf0e10cSrcweir         m_aIDToString.find( nAtom );
63cdf0e10cSrcweir     return (it != m_aIDToString.end()) ? it->second : m_aIDToString[0];
64cdf0e10cSrcweir }
65