Kaydet (Commit) b7e3470a authored tarafından Herbert Dürr's avatar Herbert Dürr

#i122208# use rtl::CStringHash and rtl::CStringEqual instead of relying on…

#i122208# use rtl::CStringHash and rtl::CStringEqual instead of relying on pre-tr1-stl specializations

In stlport<=4 the functors hash and equal_to had specializions for conveniently handling c-strings.
For consistency reasons this specialization was not included in the TR1 report and the C++11 standard.
The two new helper functors are drop-in replacements for the old specializations.
üst f44ca372
...@@ -33,22 +33,6 @@ using namespace com::sun::star; ...@@ -33,22 +33,6 @@ using namespace com::sun::star;
using namespace com::sun::star::uno; using namespace com::sun::star::uno;
using namespace com::sun::star::lang; using namespace com::sun::star::lang;
struct equalStr
{
bool operator()(
const char * const &rA,
const char * const &rB) const
{ return !strcmp(rA, rB); }
};
struct hashStr
{
size_t operator()( const char * &rName ) const
{
return rtl::OString(rName).hashCode();
}
};
class ContainerListener; class ContainerListener;
struct ContainerStats { struct ContainerStats {
...@@ -253,7 +237,7 @@ namespace cppu_ifcontainer ...@@ -253,7 +237,7 @@ namespace cppu_ifcontainer
void testOMultiTypeInterfaceContainerHelperVar() void testOMultiTypeInterfaceContainerHelperVar()
{ {
typedef ::cppu::OMultiTypeInterfaceContainerHelperVar< typedef ::cppu::OMultiTypeInterfaceContainerHelperVar<
const char *,hashStr,equalStr> StrContainer; const char*, rtl::CStringHash, rtl::CStringEqual> StrContainer;
const char *pTypes[nTests] = const char *pTypes[nTests] =
{ {
......
...@@ -62,7 +62,7 @@ private: ...@@ -62,7 +62,7 @@ private:
struct ShapeHash struct ShapeHash
{ {
std::hash<const char*> maHashFunction; rtl::CStringHash maHashFunction;
size_t operator()( const ::com::sun::star::uno::Reference < ::com::sun::star::drawing::XShape > ) const; size_t operator()( const ::com::sun::star::uno::Reference < ::com::sun::star::drawing::XShape > ) const;
}; };
......
...@@ -307,15 +307,7 @@ static const CustomShapeTypeTranslationTable pCustomShapeTypeTranslationTable[] ...@@ -307,15 +307,7 @@ static const CustomShapeTypeTranslationTable pCustomShapeTypeTranslationTable[]
{ "mso-spt202", "rect" } { "mso-spt202", "rect" }
}; };
struct StringCheck typedef std::hash_map< const char*, const char*, CStringHash, CStringEqual> CustomShapeTypeTranslationHashMap;
{
bool operator()( const char* s1, const char* s2 ) const
{
return strcmp( s1, s2 ) == 0;
}
};
typedef std::hash_map< const char*, const char*, std::hash<const char*>, StringCheck> CustomShapeTypeTranslationHashMap;
static CustomShapeTypeTranslationHashMap* pCustomShapeTypeTranslationHashMap = NULL; static CustomShapeTypeTranslationHashMap* pCustomShapeTypeTranslationHashMap = NULL;
static const char* lcl_GetPresetGeometry( const char* sShapeType ) static const char* lcl_GetPresetGeometry( const char* sShapeType )
...@@ -869,7 +861,7 @@ ShapeExport& ShapeExport::WriteRectangleShape( Reference< XShape > xShape ) ...@@ -869,7 +861,7 @@ ShapeExport& ShapeExport::WriteRectangleShape( Reference< XShape > xShape )
} }
typedef ShapeExport& (ShapeExport::*ShapeConverter)( Reference< XShape > ); typedef ShapeExport& (ShapeExport::*ShapeConverter)( Reference< XShape > );
typedef std::hash_map< const char*, ShapeConverter, std::hash<const char*>, StringCheck> NameToConvertMapType; typedef std::hash_map< const char*, ShapeConverter, CStringHash, CStringEqual> NameToConvertMapType;
static const NameToConvertMapType& lcl_GetConverters() static const NameToConvertMapType& lcl_GetConverters()
{ {
......
...@@ -930,8 +930,31 @@ struct OStringHash ...@@ -930,8 +930,31 @@ struct OStringHash
/* ======================================================================= */ /* ======================================================================= */
/** Equality functor for classic c-strings (i.e. null-terminated char* strings) */
struct CStringEqual
{
bool operator()( const char* p1, const char* p2) const {
while( *p1)
if( *(p1++) != *(p2++))
return false;
return true;
}
};
/** Hashing functor for classic c-strings (i.e. null-terminated char* strings) */
struct CStringHash
{
size_t operator()( const char* p) const {
size_t n = 0;
while( *p)
n += 4*n + *(p++);
return n;
}
};
} /* Namespace */ } /* Namespace */
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif /* _RTL_STRING_HXX_ */ #endif /* _RTL_STRING_HXX_ */
...@@ -27,16 +27,9 @@ ...@@ -27,16 +27,9 @@
#include "pppoptimizertoken.hxx" #include "pppoptimizertoken.hxx"
#include <osl/mutex.hxx> #include <osl/mutex.hxx>
#include <hash_map> #include <hash_map>
#include <string.h> #include <rtl/string.hxx>
struct TCheck typedef std::hash_map< const char*, PPPOptimizerTokenEnum, rtl::CStringHash, rtl::CStringEqual> TypeNameHashMap;
{
bool operator()( const char* s1, const char* s2 ) const
{
return strcmp( s1, s2 ) == 0;
}
};
typedef std::hash_map< const char*, PPPOptimizerTokenEnum, std::hash<const char*>, TCheck> TypeNameHashMap;
static TypeNameHashMap* pHashMap = NULL; static TypeNameHashMap* pHashMap = NULL;
static ::osl::Mutex& getHashMapMutex() static ::osl::Mutex& getHashMapMutex()
{ {
......
...@@ -26,15 +26,9 @@ ...@@ -26,15 +26,9 @@
#include "svx/EnhancedCustomShapeTypeNames.hxx" #include "svx/EnhancedCustomShapeTypeNames.hxx"
#include <osl/mutex.hxx> #include <osl/mutex.hxx>
#include <hash_map> #include <hash_map>
#include "rtl/string.hxx"
struct TCheck typedef std::hash_map< const char*, MSO_SPT, rtl::CStringHash, rtl::CStringEqual> TypeNameHashMap;
{
bool operator()( const char* s1, const char* s2 ) const
{
return strcmp( s1, s2 ) == 0;
}
};
typedef std::hash_map< const char*, MSO_SPT, std::hash<const char*>, TCheck> TypeNameHashMap;
static TypeNameHashMap* pHashMap = NULL; static TypeNameHashMap* pHashMap = NULL;
static ::osl::Mutex& getHashMapMutex() static ::osl::Mutex& getHashMapMutex()
{ {
......
...@@ -131,8 +131,7 @@ FT_Error (*pFTEmbolden)(FT_GlyphSlot); ...@@ -131,8 +131,7 @@ FT_Error (*pFTEmbolden)(FT_GlyphSlot);
FT_Error (*pFTOblique)(FT_GlyphSlot); FT_Error (*pFTOblique)(FT_GlyphSlot);
static bool bEnableSizeFT = false; static bool bEnableSizeFT = false;
struct EqStr{ bool operator()(const char* a, const char* b) const { return !strcmp(a,b); } }; typedef ::std::hash_map< const char*, FtFontFile*, CStringHash, CStringEqual> FontFileList;
typedef ::std::hash_map<const char*,FtFontFile*,::std::hash<const char*>, EqStr> FontFileList;
namespace { struct vclFontFileList : public rtl::Static< FontFileList, vclFontFileList > {}; } namespace { struct vclFontFileList : public rtl::Static< FontFileList, vclFontFileList > {}; }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
......
...@@ -224,15 +224,7 @@ ostream & XMLTag::output(ostream & o, const string & sIndent) const ...@@ -224,15 +224,7 @@ ostream & XMLTag::output(ostream & o, const string & sIndent) const
return o; return o;
} }
struct eqstr typedef hash_map< const char*, TagLogger::Pointer_t, rtl::CStringHash, rtl::CStringEqual> TagLoggerHashMap_t;
{
bool operator()(const char* s1, const char* s2) const
{
return strcmp(s1, s2) == 0;
}
};
typedef hash_map<const char *, TagLogger::Pointer_t, hash<const char *>, eqstr> TagLoggerHashMap_t;
static TagLoggerHashMap_t * tagLoggers = NULL; static TagLoggerHashMap_t * tagLoggers = NULL;
TagLogger::TagLogger() TagLogger::TagLogger()
......
...@@ -26,18 +26,11 @@ ...@@ -26,18 +26,11 @@
#include "EnhancedCustomShapeToken.hxx" #include "EnhancedCustomShapeToken.hxx"
#include <osl/mutex.hxx> #include <osl/mutex.hxx>
#include <hash_map> #include <hash_map>
#include <string.h> #include <rtl/string.hxx>
namespace xmloff { namespace EnhancedCustomShapeToken { namespace xmloff { namespace EnhancedCustomShapeToken {
struct TCheck typedef std::hash_map< const char*, EnhancedCustomShapeTokenEnum, rtl::CStringHash, rtl::CStringEqual> TypeNameHashMap;
{
bool operator()( const char* s1, const char* s2 ) const
{
return strcmp( s1, s2 ) == 0;
}
};
typedef std::hash_map< const char*, EnhancedCustomShapeTokenEnum, std::hash<const char*>, TCheck> TypeNameHashMap;
static TypeNameHashMap* pHashMap = NULL; static TypeNameHashMap* pHashMap = NULL;
static ::osl::Mutex& getHashMapMutex() static ::osl::Mutex& getHashMapMutex()
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment