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 22cdf0e10cSrcweir #if ! defined INCLUDED_DP_PERSMAP_H 23cdf0e10cSrcweir #define INCLUDED_DP_PERSMAP_H 24cdf0e10cSrcweir 25cdf0e10cSrcweir #include "rtl/ustring.hxx" 263a63f8e7SHerbert Dürr #include "osl/file.hxx" 27cdf0e10cSrcweir #include <hash_map> 28cdf0e10cSrcweir 29cdf0e10cSrcweir namespace dp_misc 30cdf0e10cSrcweir { 31cdf0e10cSrcweir 32cdf0e10cSrcweir typedef ::std::hash_map< 33cdf0e10cSrcweir ::rtl::OString, ::rtl::OString, ::rtl::OStringHash > t_string2string_map; 34cdf0e10cSrcweir 35cdf0e10cSrcweir //============================================================================== 36cdf0e10cSrcweir class PersistentMap 37cdf0e10cSrcweir { 383a63f8e7SHerbert Dürr ::osl::File m_MapFile; 393a63f8e7SHerbert Dürr t_string2string_map m_entries; 403a63f8e7SHerbert Dürr bool m_bReadOnly; 413a63f8e7SHerbert Dürr bool m_bIsOpen; 423a63f8e7SHerbert Dürr bool m_bToBeCreated; 433a63f8e7SHerbert Dürr bool m_bIsDirty; 443a63f8e7SHerbert Dürr 45cdf0e10cSrcweir public: 46cdf0e10cSrcweir ~PersistentMap(); 47cdf0e10cSrcweir PersistentMap( ::rtl::OUString const & url, bool readOnly ); 48cdf0e10cSrcweir /** in mem db */ 49cdf0e10cSrcweir PersistentMap(); 50cdf0e10cSrcweir 51cdf0e10cSrcweir bool has( ::rtl::OString const & key ) const; 52cdf0e10cSrcweir bool get( ::rtl::OString * value, ::rtl::OString const & key ) const; 53cdf0e10cSrcweir t_string2string_map getEntries() const; 54cdf0e10cSrcweir void put( ::rtl::OString const & key, ::rtl::OString const & value ); 55cdf0e10cSrcweir bool erase( ::rtl::OString const & key, bool flush_immediately = true ); 563a63f8e7SHerbert Dürr 57eaecd99eSHerbert Dürr protected: 583a63f8e7SHerbert Dürr bool open( void); 59eaecd99eSHerbert Dürr bool readAll( void); 60*516e460fSHerbert Dürr void add( ::rtl::OString const & key, ::rtl::OString const & value ); 613a63f8e7SHerbert Dürr void flush( void); 62cdf0e10cSrcweir }; 63cdf0e10cSrcweir 64cdf0e10cSrcweir } 65cdf0e10cSrcweir 66cdf0e10cSrcweir #endif 673a63f8e7SHerbert Dürr 68