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