From: Robert Wilhelm (robert.wilhelm@gmx.net)
Date: Wed Oct 08 2003 - 18:17:42 EDT
I have made some test replacing eplacing UT_StringPtrMap with
UT_UTF8Hash in pp_TableAttrProp.cpp.
It is not finished, I just converted m_pAttributes but not
yet m_pProperties. Also it might leak memory. It needs
some cleanup. You name it.
But at least it compiles and I was able to load the RTF spec.
As I won´t be able to hack during the next days,
I have attached my current patch so it cannot get lost.
ML archives are a such a nice backup medium :-)
row
? pp_AttrProp.cpp.cvs
? ttt
Index: pp_AttrProp.cpp
===================================================================
RCS file: /cvsroot/abi/src/text/ptbl/xp/pp_AttrProp.cpp,v
retrieving revision 1.63
diff -u -r1.63 pp_AttrProp.cpp
--- pp_AttrProp.cpp 27 Sep 2003 06:36:34 -0000 1.63
+++ pp_AttrProp.cpp 8 Oct 2003 22:26:38 -0000
@@ -48,21 +48,9 @@
PP_AttrProp::~PP_AttrProp()
{
xxx_UT_DEBUGMSG(("deleting pp_AttrProp %x \n",this));
+
if (m_pAttributes)
{
- UT_StringPtrMap::UT_Cursor c1(m_pAttributes);
-
- const XML_Char * s = static_cast<const XML_Char *>(c1.first());
-
- while (true) {
- FREEP(s);
-
- if (!c1.is_valid())
- break;
-
- s = static_cast<const XML_Char *>(c1.next());
- }
-
delete m_pAttributes;
m_pAttributes = NULL;
}
@@ -112,7 +100,7 @@
if(!m_pAttributes)
return 0;
else
- return m_pAttributes->size();
+ return m_pAttributes->count();
}
@@ -275,7 +263,7 @@
{
if (!m_pAttributes)
{
- m_pAttributes = new UT_StringPtrMap(5);
+ m_pAttributes = new UT_UTF8Hash();
if (!m_pAttributes)
{
UT_DEBUGMSG(("setAttribute: could not allocate hash table.\n"));
@@ -296,7 +284,7 @@
UT_lowerString(copy);
char * szDupValue = UT_strdup(szValue);
- if(!m_pAttributes->insert(copy, static_cast<void *>(szDupValue)))
+ if(!m_pAttributes->ins(copy, szDupValue))
FREEP(szDupValue);
FREEP(copy);
@@ -365,25 +353,19 @@
{
if (!m_pAttributes)
return false;
- if (static_cast<UT_uint32>(ndx) >= m_pAttributes->size())
- return false;
- int i = 0;
- UT_StringPtrMap::UT_Cursor c(m_pAttributes);
- const void * val = NULL;
+ const UT_UTF8String* key;
+ const UT_UTF8String* value;
- for (val = c.first(); (c.is_valid() && (i < ndx)); val = c.next(), i++)
- {
- // noop
- }
+ bool ret;
+ unsigned int uindex = ndx;
- if ((i == ndx) && c.is_valid())
- {
- szName = static_cast<const XML_Char*>(c.key().c_str());
- szValue = static_cast<const XML_Char*>(val);
- return true;
- }
- return false;
+ if (!m_pAttributes->pair( uindex, key, value)) return false;
+
+ szName = key->utf8_str();
+ szValue = value->utf8_str();
+
+ return true;
}
bool PP_AttrProp::getNthProperty(int ndx, const XML_Char *& szName, const XML_Char *& szValue) const
@@ -447,16 +429,17 @@
return static_cast<PP_PropertyType *const>(pEntry->second());
}
+
bool PP_AttrProp::getAttribute(const XML_Char * szName, const XML_Char *& szValue) const
{
if (!m_pAttributes)
return false;
- const void * pEntry = m_pAttributes->pick(szName);
+ const UT_UTF8String* pEntry = (*m_pAttributes)[szName];
if (!pEntry)
return false;
- szValue = static_cast<const XML_Char *>(pEntry);
+ szValue = static_cast<const XML_Char *>(pEntry->utf8_str());
xxx_UT_DEBUGMSG(("SEVIOR: getAttribute Found value %s \n",szValue));
@@ -477,7 +460,7 @@
if (!m_pAttributes)
return false;
- return (m_pAttributes->size() > 0);
+ return (m_pAttributes->count() > 0);
}
bool PP_AttrProp::areAlreadyPresent(const XML_Char ** attributes, const XML_Char ** properties) const
@@ -588,8 +571,8 @@
s_PassedCheckSum++;
#endif
- UT_uint32 countMyAttrs = ((m_pAttributes) ? m_pAttributes->size() : 0);
- UT_uint32 countMatchAttrs = ((pMatch->m_pAttributes) ? pMatch->m_pAttributes->size() : 0);
+ UT_uint32 countMyAttrs = ((m_pAttributes) ? m_pAttributes->count() : 0);
+ UT_uint32 countMatchAttrs = ((pMatch->m_pAttributes) ? pMatch->m_pAttributes->count() : 0);
if (countMyAttrs != countMatchAttrs)
return false;
@@ -600,29 +583,38 @@
if (countMyAttrs != 0)
{
- UT_StringPtrMap::UT_Cursor ca1(m_pAttributes);
- UT_StringPtrMap::UT_Cursor ca2(pMatch->m_pAttributes);
+ unsigned int ui1,ui2;
+
- const void * v1 = ca1.first();
- const void * v2 = ca2.first();
+ ui1 = 0;
+ ui2 = 0;
do
{
- const XML_Char *l1 = static_cast<const XML_Char *>(ca1.key().c_str());
- const XML_Char *l2 = static_cast<const XML_Char *>(ca2.key().c_str());
+ const UT_UTF8String* key1;
+ const UT_UTF8String* value1;
- if (strcmp(l1, l2) != 0)
- return false;
+ const UT_UTF8String* key2;
+ const UT_UTF8String* value2;
- l1 = static_cast<const XML_Char *>(v1);
- l2 = static_cast<const XML_Char *>(v2);
+ m_pAttributes->pair( ui1, key1, value1);
+ pMatch->m_pAttributes->pair( ui2, key2, value2);
- if (strcmp(l1,l2) != 0)
+ const XML_Char *l1 = static_cast<const XML_Char *>(key1->utf8_str());
+ const XML_Char *l2 = static_cast<const XML_Char *>(key2->utf8_str());
+
+ if (strcmp(l1, l2) != 0)
+ return false;
+
+ l1 = static_cast<const XML_Char *>(value1->utf8_str());
+ l2 = static_cast<const XML_Char *>(value2->utf8_str());
+
+ if (strcmp(l1,l2) != 0)
return false;
- v1 = ca1.next();
- v2 = ca2.next();
- } while (ca1.is_valid());
+ ui1++;ui2++;
+
+ } while (ui1 < m_pAttributes->count());
}
if (countMyProps > 0)
@@ -771,16 +763,24 @@
if(!m_pAttributes)
return;
- UT_StringPtrMap::UT_Cursor _hc1(m_pAttributes);
+ unsigned int ui = 0;
+
const XML_Char * pEntry;
- for ( pEntry = static_cast<const XML_Char*>(_hc1.first()); _hc1.is_valid(); pEntry = static_cast<const XML_Char*>(_hc1.next()) )
+ for ( ui = 0; ui < m_pAttributes->count(); ui++)
{
+ const UT_UTF8String* key1;
+ const UT_UTF8String* value1;
+
+ m_pAttributes->pair( ui, key1, value1);
+
+ pEntry = value1->utf8_str();
+
if (pEntry && !*pEntry)
{
UT_ASSERT(!m_bIsReadOnly);
FREEP(pEntry);
- m_pAttributes->remove(_hc1.key(),pEntry);
+ m_pAttributes->del(*key1);
}
}
}
@@ -983,13 +983,19 @@
if (m_pAttributes)
{
- UT_StringPtrMap::UT_Cursor c1(m_pAttributes);
- const void *val = c1.first();
+ unsigned int ui = 0;
- while (val != NULL)
+ while ( ui < m_pAttributes->count())
{
- s1 = static_cast<const XML_Char *>(c1.key().c_str());
- s2 = static_cast<const XML_Char *>(val);
+
+ const UT_UTF8String* key;
+ const UT_UTF8String* value;
+
+ bool ret;
+
+ ret = m_pAttributes->pair( ui, key, value);
+ s1 = static_cast<const XML_Char *>(key->utf8_str());
+ s2 = static_cast<const XML_Char *>(value->utf8_str());
cch = UT_XML_strlen(s1);
@@ -1002,9 +1008,7 @@
m_checkSum = hashcodeBytesAP(m_checkSum, rgch, cch);
- if (!c1.is_valid())
- break;
- val = c1.next();
+ ui++;
}
}
@@ -1049,7 +1053,7 @@
void PP_AttrProp::operator = (const PP_AttrProp &Other)
{
- UT_uint32 countMyAttrs = ((Other.m_pAttributes) ? Other.m_pAttributes->size() : 0);
+ UT_uint32 countMyAttrs = ((Other.m_pAttributes) ? Other.m_pAttributes->count() : 0);
UT_uint32 Index;
for(Index = 0; Index < countMyAttrs; Index++)
Index: pp_AttrProp.h
===================================================================
RCS file: /cvsroot/abi/src/text/ptbl/xp/pp_AttrProp.h,v
retrieving revision 1.30
diff -u -r1.30 pp_AttrProp.h
--- pp_AttrProp.h 27 Sep 2003 06:36:34 -0000 1.30
+++ pp_AttrProp.h 8 Oct 2003 22:26:38 -0000
@@ -54,7 +54,7 @@
bool setProperties(const XML_Char ** properties);
bool setProperties(const UT_Vector * pVector);
- const XML_Char ** getAttributes () const { return m_pAttributes ? m_pAttributes->list () : 0; }
+ // const XML_Char ** getAttributes () const { return m_pAttributes ? m_pAttributes->list () : 0; }
const XML_Char ** getProperties () const { return m_pProperties ? m_pProperties->list () : 0; }
bool setAttribute(const XML_Char * szName, const XML_Char * szValue);
@@ -97,7 +97,7 @@
void _clearEmptyAttributes();
- UT_StringPtrMap * m_pAttributes;
+ UT_UTF8Hash* m_pAttributes;
UT_StringPtrMap * m_pProperties;
bool m_bIsReadOnly;
UT_uint32 m_checkSum;
This archive was generated by hypermail 2.1.4 : Wed Oct 08 2003 - 18:41:16 EDT