103b7fc75SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
303b7fc75SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
403b7fc75SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
503b7fc75SAndrew Rist  * distributed with this work for additional information
603b7fc75SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
703b7fc75SAndrew Rist  * to you under the Apache License, Version 2.0 (the
803b7fc75SAndrew Rist  * "License"); you may not use this file except in compliance
903b7fc75SAndrew Rist  * with the License.  You may obtain a copy of the License at
1003b7fc75SAndrew Rist  *
1103b7fc75SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
1203b7fc75SAndrew Rist  *
1303b7fc75SAndrew Rist  * Unless required by applicable law or agreed to in writing,
1403b7fc75SAndrew Rist  * software distributed under the License is distributed on an
1503b7fc75SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1603b7fc75SAndrew Rist  * KIND, either express or implied.  See the License for the
1703b7fc75SAndrew Rist  * specific language governing permissions and limitations
1803b7fc75SAndrew Rist  * under the License.
1903b7fc75SAndrew Rist  *
2003b7fc75SAndrew Rist  *************************************************************/
2103b7fc75SAndrew Rist 
2203b7fc75SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #if ! defined INCLUDED_DP_PERSMAP_H
25cdf0e10cSrcweir #define INCLUDED_DP_PERSMAP_H
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "rtl/ustring.hxx"
28*3a63f8e7SHerbert Dürr #include "osl/file.hxx"
29cdf0e10cSrcweir #include <hash_map>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir namespace dp_misc
32cdf0e10cSrcweir {
33cdf0e10cSrcweir 
34cdf0e10cSrcweir typedef ::std::hash_map<
35cdf0e10cSrcweir     ::rtl::OString, ::rtl::OString, ::rtl::OStringHash > t_string2string_map;
36cdf0e10cSrcweir 
37cdf0e10cSrcweir //==============================================================================
38cdf0e10cSrcweir class PersistentMap
39cdf0e10cSrcweir {
40*3a63f8e7SHerbert Dürr 	::osl::File m_MapFile;
41*3a63f8e7SHerbert Dürr 	t_string2string_map m_entries;
42*3a63f8e7SHerbert Dürr 	bool m_bReadOnly;
43*3a63f8e7SHerbert Dürr 	bool m_bIsOpen;
44*3a63f8e7SHerbert Dürr 	bool m_bToBeCreated;
45*3a63f8e7SHerbert Dürr 	bool m_bIsDirty;
46*3a63f8e7SHerbert Dürr 
47cdf0e10cSrcweir public:
48cdf0e10cSrcweir     ~PersistentMap();
49cdf0e10cSrcweir     PersistentMap( ::rtl::OUString const & url, bool readOnly );
50cdf0e10cSrcweir     /** in mem db */
51cdf0e10cSrcweir     PersistentMap();
52cdf0e10cSrcweir 
53cdf0e10cSrcweir     bool has( ::rtl::OString const & key ) const;
54cdf0e10cSrcweir     bool get( ::rtl::OString * value, ::rtl::OString const & key ) const;
55cdf0e10cSrcweir     t_string2string_map getEntries() const;
56cdf0e10cSrcweir     void put( ::rtl::OString const & key, ::rtl::OString const & value );
57cdf0e10cSrcweir     bool erase( ::rtl::OString const & key, bool flush_immediately = true );
58*3a63f8e7SHerbert Dürr 
59*3a63f8e7SHerbert Dürr private:
60*3a63f8e7SHerbert Dürr 	bool open( void);
61*3a63f8e7SHerbert Dürr 	void flush( void);
62cdf0e10cSrcweir };
63cdf0e10cSrcweir 
64cdf0e10cSrcweir }
65cdf0e10cSrcweir 
66cdf0e10cSrcweir #endif
67*3a63f8e7SHerbert Dürr 
68