17b6bd0c4SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
37b6bd0c4SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
47b6bd0c4SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
57b6bd0c4SAndrew Rist  * distributed with this work for additional information
67b6bd0c4SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
77b6bd0c4SAndrew Rist  * to you under the Apache License, Version 2.0 (the
87b6bd0c4SAndrew Rist  * "License"); you may not use this file except in compliance
97b6bd0c4SAndrew Rist  * with the License.  You may obtain a copy of the License at
107b6bd0c4SAndrew Rist  *
117b6bd0c4SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
127b6bd0c4SAndrew Rist  *
137b6bd0c4SAndrew Rist  * Unless required by applicable law or agreed to in writing,
147b6bd0c4SAndrew Rist  * software distributed under the License is distributed on an
157b6bd0c4SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
167b6bd0c4SAndrew Rist  * KIND, either express or implied.  See the License for the
177b6bd0c4SAndrew Rist  * specific language governing permissions and limitations
187b6bd0c4SAndrew Rist  * under the License.
197b6bd0c4SAndrew Rist  *
207b6bd0c4SAndrew Rist  *************************************************************/
217b6bd0c4SAndrew Rist 
227b6bd0c4SAndrew Rist 
23*70e197d9SHerbert Dürr #ifndef HELPDATAFILEPROXY_DB_HXX_
24*70e197d9SHerbert Dürr #define HELPDATAFILEPROXY_DB_HXX_
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "com/sun/star/ucb/XSimpleFileAccess.hpp"
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <hash_map>
29cdf0e10cSrcweir #include <rtl/string.hxx>
30cdf0e10cSrcweir 
31*70e197d9SHerbert Dürr namespace helpdatafileproxy {
32cdf0e10cSrcweir 
33*70e197d9SHerbert Dürr     namespace hdf_internal
34cdf0e10cSrcweir     {
35cdf0e10cSrcweir         class Noncopyable
36cdf0e10cSrcweir         {
37cdf0e10cSrcweir             // not implemented
38cdf0e10cSrcweir             Noncopyable(const Noncopyable&);
39cdf0e10cSrcweir             void operator=(const Noncopyable&);
40cdf0e10cSrcweir         protected:
41cdf0e10cSrcweir             Noncopyable() {}
42cdf0e10cSrcweir             ~Noncopyable() {}
43cdf0e10cSrcweir         };
44cdf0e10cSrcweir     }
45cdf0e10cSrcweir 
46*70e197d9SHerbert Dürr 	class HDFData
47cdf0e10cSrcweir 	{
48*70e197d9SHerbert Dürr 		friend class		Hdf;
49cdf0e10cSrcweir 
50cdf0e10cSrcweir 		int					m_nSize;
51cdf0e10cSrcweir 		char*				m_pBuffer;
52cdf0e10cSrcweir 
53cdf0e10cSrcweir 		void copyToBuffer( const char* pSrcData, int nSize );
54cdf0e10cSrcweir 
55cdf0e10cSrcweir 	public:
56*70e197d9SHerbert Dürr 		HDFData( void )
57cdf0e10cSrcweir 			: m_nSize( 0 )
58cdf0e10cSrcweir 			, m_pBuffer( NULL )
59cdf0e10cSrcweir 		{}
60*70e197d9SHerbert Dürr 		~HDFData()
61cdf0e10cSrcweir 			{ delete [] m_pBuffer; }
62cdf0e10cSrcweir 
63cdf0e10cSrcweir   	    int getSize() const
64cdf0e10cSrcweir 			{ return m_nSize; }
65cdf0e10cSrcweir   	    const char* getData() const
66cdf0e10cSrcweir 			{ return m_pBuffer; }
67cdf0e10cSrcweir 	};
68cdf0e10cSrcweir 
69*70e197d9SHerbert Dürr 	struct eq
70*70e197d9SHerbert Dürr 	{
71*70e197d9SHerbert Dürr 		bool operator()( const rtl::OString& rKey1, const rtl::OString& rKey2 ) const
72*70e197d9SHerbert Dürr 			{ return rKey1.compareTo( rKey2 ) == 0; }
73*70e197d9SHerbert Dürr 	};
74*70e197d9SHerbert Dürr 
75*70e197d9SHerbert Dürr 	struct ha
76*70e197d9SHerbert Dürr 	{
77*70e197d9SHerbert Dürr 		size_t operator()( const rtl::OString& rName ) const
78*70e197d9SHerbert Dürr 			{ return rName.hashCode(); }
79*70e197d9SHerbert Dürr 	};
80*70e197d9SHerbert Dürr 
81cdf0e10cSrcweir 	typedef std::hash_map< rtl::OString,std::pair<int,int>,ha,eq >	StringToValPosMap;
82cdf0e10cSrcweir 	typedef std::hash_map< rtl::OString,rtl::OString,ha,eq >		StringToDataMap;
83cdf0e10cSrcweir 
84*70e197d9SHerbert Dürr 	class Hdf : hdf_internal::Noncopyable
85cdf0e10cSrcweir 	{
86cdf0e10cSrcweir 		rtl::OUString		m_aFileURL;
87cdf0e10cSrcweir 		StringToDataMap*	m_pStringToDataMap;
88cdf0e10cSrcweir 		StringToValPosMap*	m_pStringToValPosMap;
89cdf0e10cSrcweir 		com::sun::star::uno::Reference< com::sun::star::ucb::XSimpleFileAccess >
90cdf0e10cSrcweir 							m_xSFA;
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 		com::sun::star::uno::Sequence< sal_Int8 >
93cdf0e10cSrcweir 							m_aItData;
94cdf0e10cSrcweir 		const char*			m_pItData;
95cdf0e10cSrcweir 		int					m_nItRead;
96cdf0e10cSrcweir 		int					m_iItPos;
97cdf0e10cSrcweir 
98*70e197d9SHerbert Dürr 		bool implReadLenAndData( const char* pData, int& riPos, HDFData& rValue );
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 	public:
101*70e197d9SHerbert Dürr         //HDFHelp must get a fileURL which can then directly be used by simple file access.
102cdf0e10cSrcweir         //SimpleFileAccess requires file URLs as arguments. Passing file path may work but fails
103cdf0e10cSrcweir         //for example when using long file paths on Windows, which start with "\\?\"
104*70e197d9SHerbert Dürr 		Hdf( const rtl::OUString& rFileURL,
105cdf0e10cSrcweir 			com::sun::star::uno::Reference< com::sun::star::ucb::XSimpleFileAccess > xSFA )
106cdf0e10cSrcweir 				: m_aFileURL( rFileURL )
107cdf0e10cSrcweir 				, m_pStringToDataMap( NULL )
108cdf0e10cSrcweir 				, m_pStringToValPosMap( NULL )
109cdf0e10cSrcweir 				, m_xSFA( xSFA )
110cdf0e10cSrcweir 				, m_pItData( NULL )
111cdf0e10cSrcweir 				, m_nItRead( -1 )
112cdf0e10cSrcweir 				, m_iItPos( -1 )
113cdf0e10cSrcweir 		{
114cdf0e10cSrcweir             OSL_ASSERT(!rFileURL.compareTo(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("file:")), 5));
115cdf0e10cSrcweir         }
116*70e197d9SHerbert Dürr 		~Hdf()
117cdf0e10cSrcweir 			{ releaseHashMap(); }
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 		void createHashMap( bool bOptimizeForPerformance = false );
120cdf0e10cSrcweir 		void releaseHashMap( void );
121cdf0e10cSrcweir 
122*70e197d9SHerbert Dürr 		bool getValueForKey( const rtl::OString& rKey, HDFData& rValue );
123cdf0e10cSrcweir 
124cdf0e10cSrcweir 		bool startIteration( void );
125*70e197d9SHerbert Dürr 		bool getNextKeyAndValue( HDFData& rKey, HDFData& rValue );
126cdf0e10cSrcweir 		void stopIteration( void );
127cdf0e10cSrcweir 	};
128cdf0e10cSrcweir }
129cdf0e10cSrcweir 
130cdf0e10cSrcweir #endif
131cdf0e10cSrcweir 
132