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 #ifndef HELPDATAFILEPROXY_DB_HXX_ 24 #define HELPDATAFILEPROXY_DB_HXX_ 25 26 #include "com/sun/star/ucb/XSimpleFileAccess.hpp" 27 28 #include <hash_map> 29 #include <rtl/string.hxx> 30 31 namespace helpdatafileproxy { 32 33 namespace hdf_internal 34 { 35 class Noncopyable 36 { 37 // not implemented 38 Noncopyable(const Noncopyable&); 39 void operator=(const Noncopyable&); 40 protected: Noncopyable()41 Noncopyable() {} ~Noncopyable()42 ~Noncopyable() {} 43 }; 44 } 45 46 class HDFData 47 { 48 friend class Hdf; 49 50 int m_nSize; 51 char* m_pBuffer; 52 53 void copyToBuffer( const char* pSrcData, int nSize ); 54 55 public: HDFData(void)56 HDFData( void ) 57 : m_nSize( 0 ) 58 , m_pBuffer( NULL ) 59 {} ~HDFData()60 ~HDFData() 61 { delete [] m_pBuffer; } 62 getSize() const63 int getSize() const 64 { return m_nSize; } getData() const65 const char* getData() const 66 { return m_pBuffer; } 67 }; 68 69 struct eq 70 { operator ()helpdatafileproxy::eq71 bool operator()( const rtl::OString& rKey1, const rtl::OString& rKey2 ) const 72 { return rKey1.compareTo( rKey2 ) == 0; } 73 }; 74 75 struct ha 76 { operator ()helpdatafileproxy::ha77 size_t operator()( const rtl::OString& rName ) const 78 { return rName.hashCode(); } 79 }; 80 81 typedef std::hash_map< rtl::OString,std::pair<int,int>,ha,eq > StringToValPosMap; 82 typedef std::hash_map< rtl::OString,rtl::OString,ha,eq > StringToDataMap; 83 84 class Hdf : hdf_internal::Noncopyable 85 { 86 rtl::OUString m_aFileURL; 87 StringToDataMap* m_pStringToDataMap; 88 StringToValPosMap* m_pStringToValPosMap; 89 com::sun::star::uno::Reference< com::sun::star::ucb::XSimpleFileAccess > 90 m_xSFA; 91 92 com::sun::star::uno::Sequence< sal_Int8 > 93 m_aItData; 94 const char* m_pItData; 95 int m_nItRead; 96 int m_iItPos; 97 98 bool implReadLenAndData( const char* pData, int& riPos, HDFData& rValue ); 99 100 public: 101 //HDFHelp must get a fileURL which can then directly be used by simple file access. 102 //SimpleFileAccess requires file URLs as arguments. Passing file path may work but fails 103 //for example when using long file paths on Windows, which start with "\\?\" Hdf(const rtl::OUString & rFileURL,com::sun::star::uno::Reference<com::sun::star::ucb::XSimpleFileAccess> xSFA)104 Hdf( const rtl::OUString& rFileURL, 105 com::sun::star::uno::Reference< com::sun::star::ucb::XSimpleFileAccess > xSFA ) 106 : m_aFileURL( rFileURL ) 107 , m_pStringToDataMap( NULL ) 108 , m_pStringToValPosMap( NULL ) 109 , m_xSFA( xSFA ) 110 , m_pItData( NULL ) 111 , m_nItRead( -1 ) 112 , m_iItPos( -1 ) 113 { 114 OSL_ASSERT(!rFileURL.compareTo(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("file:")), 5)); 115 } ~Hdf()116 ~Hdf() 117 { releaseHashMap(); } 118 119 void createHashMap( bool bOptimizeForPerformance = false ); 120 void releaseHashMap( void ); 121 122 bool getValueForKey( const rtl::OString& rKey, HDFData& rValue ); 123 124 bool startIteration( void ); 125 bool getNextKeyAndValue( HDFData& rKey, HDFData& rValue ); 126 void stopIteration( void ); 127 }; 128 } 129 130 #endif 131 132