use rtl::Reference in Formula

instead of storing both a raw pointer and a uno::Reference

Change-Id: I7f8baae687e528e89c7cdea1a92099ff4a759878
Reviewed-on: https://gerrit.libreoffice.org/33169
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin 2017-01-16 14:24:22 +02:00
parent 4b668a5071
commit b936cf5838
2 changed files with 33 additions and 39 deletions

View File

@ -35,7 +35,7 @@
#define rchars(x) do { if (m_rxDocumentHandler.is()) m_rxDocumentHandler->characters(x); } while(false) #define rchars(x) do { if (m_rxDocumentHandler.is()) m_rxDocumentHandler->characters(x); } while(false)
#define runistr(x) do { if (m_rxDocumentHandler.is()) m_rxDocumentHandler->characters(x); } while(false) #define runistr(x) do { if (m_rxDocumentHandler.is()) m_rxDocumentHandler->characters(x); } while(false)
#define reucstr(x,y) do { if (m_rxDocumentHandler.is()) m_rxDocumentHandler->characters(OUString(x,y, RTL_TEXTENCODING_EUC_KR)); } while(false) #define reucstr(x,y) do { if (m_rxDocumentHandler.is()) m_rxDocumentHandler->characters(OUString(x,y, RTL_TEXTENCODING_EUC_KR)); } while(false)
#define padd(x,y,z) pList->addAttribute(x,y,z) #define padd(x,y,z) mxList->addAttribute(x,y,z)
#else #else
static int indent = 0; static int indent = 0;
#define inds indent++; for(int i = 0 ; i < indent ; i++) fprintf(stderr," ") #define inds indent++; for(int i = 0 ; i < indent ; i++) fprintf(stderr," ")
@ -52,9 +52,9 @@ void Formula::makeMathML(Node *res)
fprintf(stderr,"<math:math xmlns:math=\"http://www.w3.org/1998/Math/MathML\">\n"); fprintf(stderr,"<math:math xmlns:math=\"http://www.w3.org/1998/Math/MathML\">\n");
#else #else
padd("xmlns:math", "CDATA", "http://www.w3.org/1998/Math/MathML"); padd("xmlns:math", "CDATA", "http://www.w3.org/1998/Math/MathML");
rstartEl("math:math", rList); rstartEl("math:math", mxList.get());
pList->clear(); mxList->clear();
rstartEl("math:semantics", rList); rstartEl("math:semantics", mxList.get());
#endif #endif
if( tmp->child ) if( tmp->child )
makeLines( tmp->child ); makeLines( tmp->child );
@ -92,7 +92,7 @@ void Formula::makeLine(Node *res)
#ifdef DEBUG #ifdef DEBUG
inds; fprintf(stderr,"<math:mrow>\n"); inds; fprintf(stderr,"<math:mrow>\n");
#else #else
rstartEl("math:mrow", rList); rstartEl("math:mrow", mxList.get());
#endif #endif
if( res->child ) if( res->child )
makeExprList( res->child ); makeExprList( res->child );
@ -131,7 +131,7 @@ void Formula::makeExpr(Node *res)
inds; inds;
fprintf(stderr,"<math:mrow>\n"); fprintf(stderr,"<math:mrow>\n");
#else #else
rstartEl("math:mrow", rList); rstartEl("math:mrow", mxList.get());
#endif #endif
} }
@ -194,7 +194,7 @@ void Formula::makeIdentifier(Node *res)
fprintf(stderr,"<math:mi>%s</math:mi>\n",tmp->value); fprintf(stderr,"<math:mi>%s</math:mi>\n",tmp->value);
indo; indo;
#else #else
rstartEl("math:mi", rList); rstartEl("math:mi", mxList.get());
rchars(OUString::createFromAscii(tmp->value)); rchars(OUString::createFromAscii(tmp->value));
rendEl("math:mi"); rendEl("math:mi");
#endif #endif
@ -203,7 +203,7 @@ void Formula::makeIdentifier(Node *res)
{ {
#ifdef DEBUG #ifdef DEBUG
#else #else
rstartEl("math:mi", rList); rstartEl("math:mi", mxList.get());
reucstr(tmp->value, strlen(tmp->value)); reucstr(tmp->value, strlen(tmp->value));
rendEl("math:mi"); rendEl("math:mi");
#endif #endif
@ -216,7 +216,7 @@ void Formula::makeIdentifier(Node *res)
getMathMLEntity(tmp->value).c_str()); getMathMLEntity(tmp->value).c_str());
indo; indo;
#else #else
rstartEl("math:mi", rList); rstartEl("math:mi", mxList.get());
runistr(reinterpret_cast<sal_Unicode const *>(getMathMLEntity(tmp->value).c_str())); runistr(reinterpret_cast<sal_Unicode const *>(getMathMLEntity(tmp->value).c_str()));
rendEl("math:mi"); rendEl("math:mi");
#endif #endif
@ -227,7 +227,7 @@ void Formula::makeIdentifier(Node *res)
fprintf(stderr,"<math:mn>%s</math:mn>\n",tmp->value); fprintf(stderr,"<math:mn>%s</math:mn>\n",tmp->value);
indo; indo;
#else #else
rstartEl("math:mn", rList); rstartEl("math:mn", mxList.get());
rchars(OUString::createFromAscii(tmp->value)); rchars(OUString::createFromAscii(tmp->value));
rendEl("math:mn"); rendEl("math:mn");
#endif #endif
@ -238,7 +238,7 @@ void Formula::makeIdentifier(Node *res)
#ifdef DEBUG #ifdef DEBUG
inds; fprintf(stderr,"<math:mo>%s</math:mo>\n",tmp->value); indo; inds; fprintf(stderr,"<math:mo>%s</math:mo>\n",tmp->value); indo;
#else #else
rstartEl("math:mo", rList); rstartEl("math:mo", mxList.get());
runistr(reinterpret_cast<sal_Unicode const *>(getMathMLEntity(tmp->value).c_str())); runistr(reinterpret_cast<sal_Unicode const *>(getMathMLEntity(tmp->value).c_str()));
rendEl("math:mo"); rendEl("math:mo");
#endif #endif
@ -278,11 +278,11 @@ void Formula::makeSubSup(Node *res)
fprintf(stderr,"<math:msubsup>\n"); fprintf(stderr,"<math:msubsup>\n");
#else #else
if( res->id == ID_SUBEXPR ) if( res->id == ID_SUBEXPR )
rstartEl("math:msub", rList); rstartEl("math:msub", mxList.get());
else if( res->id == ID_SUPEXPR ) else if( res->id == ID_SUPEXPR )
rstartEl("math:msup", rList); rstartEl("math:msup", mxList.get());
else else
rstartEl("math:msubsup", rList); rstartEl("math:msubsup", mxList.get());
#endif #endif
tmp = tmp->child; tmp = tmp->child;
@ -323,7 +323,7 @@ void Formula::makeFraction(Node *res)
inds; inds;
fprintf(stderr,"<math:mfrac>\n"); fprintf(stderr,"<math:mfrac>\n");
#else #else
rstartEl("math:mfrac", rList); rstartEl("math:mfrac", mxList.get());
#endif #endif
tmp = tmp->child; tmp = tmp->child;
@ -331,7 +331,7 @@ void Formula::makeFraction(Node *res)
inds; inds;
fprintf(stderr,"<math:mrow>\n"); fprintf(stderr,"<math:mrow>\n");
#else #else
rstartEl("math:mrow", rList); rstartEl("math:mrow", mxList.get());
#endif #endif
if( res->id == ID_FRACTIONEXPR ) if( res->id == ID_FRACTIONEXPR )
@ -346,7 +346,7 @@ void Formula::makeFraction(Node *res)
fprintf(stderr,"<math:mrow>\n"); fprintf(stderr,"<math:mrow>\n");
#else #else
rendEl("math:mrow"); rendEl("math:mrow");
rstartEl("math:mrow", rList); rstartEl("math:mrow", mxList.get());
#endif #endif
if( res->id == ID_FRACTIONEXPR ) if( res->id == ID_FRACTIONEXPR )
@ -382,13 +382,13 @@ void Formula::makeDecoration(Node *res)
/* FIXME: no idea when 'accent' is true or false. */ /* FIXME: no idea when 'accent' is true or false. */
if( isover ){ if( isover ){
padd("accent","CDATA","true"); padd("accent","CDATA","true");
rstartEl("math:mover", rList); rstartEl("math:mover", mxList.get());
} }
else{ else{
padd("accentunder","CDATA","true"); padd("accentunder","CDATA","true");
rstartEl("math:munder", rList); rstartEl("math:munder", mxList.get());
} }
pList->clear(); mxList->clear();
#endif #endif
makeBlock(tmp->next); makeBlock(tmp->next);
@ -399,7 +399,7 @@ void Formula::makeDecoration(Node *res)
getMathMLEntity(tmp->value).c_str()); getMathMLEntity(tmp->value).c_str());
indo; indo;
#else #else
rstartEl("math:mo", rList); rstartEl("math:mo", mxList.get());
runistr(reinterpret_cast<sal_Unicode const *>(getMathMLEntity(tmp->value).c_str())); runistr(reinterpret_cast<sal_Unicode const *>(getMathMLEntity(tmp->value).c_str()));
rendEl("math:mo"); rendEl("math:mo");
#endif #endif
@ -430,9 +430,9 @@ void Formula::makeRoot(Node *res)
fprintf(stderr,"<math:mroot>\n"); fprintf(stderr,"<math:mroot>\n");
#else #else
if( tmp->id == ID_SQRTEXPR ) if( tmp->id == ID_SQRTEXPR )
rstartEl("math:msqrt", rList); rstartEl("math:msqrt", mxList.get());
else else
rstartEl("math:mroot", rList); rstartEl("math:mroot", mxList.get());
#endif #endif
if( tmp->id == ID_SQRTEXPR ){ if( tmp->id == ID_SQRTEXPR ){
@ -476,14 +476,14 @@ void Formula::makeParenth(Node *res)
indo; inds; indo; inds;
fprintf(stderr,"<math:mrow>\n"); fprintf(stderr,"<math:mrow>\n");
#else #else
rstartEl("math:mrow", rList); rstartEl("math:mrow", mxList.get());
rstartEl("math:mo", rList); rstartEl("math:mo", mxList.get());
if( tmp->id == ID_PARENTH ) if( tmp->id == ID_PARENTH )
rchars("("); rchars("(");
else else
rchars("|"); rchars("|");
rendEl("math:mo"); rendEl("math:mo");
rstartEl("math:mrow", rList); rstartEl("math:mrow", mxList.get());
#endif #endif
if( tmp->child ) if( tmp->child )
@ -502,7 +502,7 @@ void Formula::makeParenth(Node *res)
fprintf(stderr,"</math:mrow>\n"); fprintf(stderr,"</math:mrow>\n");
#else #else
rendEl("math:mrow"); rendEl("math:mrow");
rstartEl("math:mo", rList); rstartEl("math:mo", mxList.get());
if( tmp->id == ID_PARENTH ) if( tmp->id == ID_PARENTH )
rchars(")"); rchars(")");
else else
@ -525,8 +525,8 @@ void Formula::makeFence(Node *res)
OUString(reinterpret_cast<sal_Unicode const *>(getMathMLEntity(tmp->value).c_str()))); OUString(reinterpret_cast<sal_Unicode const *>(getMathMLEntity(tmp->value).c_str())));
padd("close", "CDATA", padd("close", "CDATA",
OUString(reinterpret_cast<sal_Unicode const *>(getMathMLEntity(tmp->next->next->value).c_str()))); OUString(reinterpret_cast<sal_Unicode const *>(getMathMLEntity(tmp->next->next->value).c_str())));
rstartEl("math:mfenced", rList); rstartEl("math:mfenced", mxList.get());
pList->clear(); mxList->clear();
#endif #endif
makeExprList(tmp->next); makeExprList(tmp->next);
@ -550,7 +550,7 @@ void Formula::makeBlock(Node *res)
inds; inds;
fprintf(stderr,"<math:mrow>\n"); fprintf(stderr,"<math:mrow>\n");
#else #else
rstartEl("math:mrow", rList); rstartEl("math:mrow", mxList.get());
#endif #endif
if( res->child ) if( res->child )

View File

@ -20,12 +20,9 @@
#ifndef INCLUDED_HWPFILTER_SOURCE_FORMULA_H #ifndef INCLUDED_HWPFILTER_SOURCE_FORMULA_H
#define INCLUDED_HWPFILTER_SOURCE_FORMULA_H #define INCLUDED_HWPFILTER_SOURCE_FORMULA_H
// DVO: remove DEBUG dependency
// #ifndef DEBUG
#include <com/sun/star/xml/sax/XDocumentHandler.hpp> #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
#include "attributes.hxx" #include "attributes.hxx"
// DVO: remove DEBUG dependency #include <rtl/ref.hxx>
// #endif
class Node; class Node;
@ -35,7 +32,6 @@ class Formula final
{ {
public: public:
explicit Formula(char *_eq) explicit Formula(char *_eq)
: pList(nullptr)
{ {
eq = _eq; eq = _eq;
trim(); trim();
@ -48,8 +44,7 @@ public:
} }
void setAttributeListImpl( AttributeListImpl *p ) void setAttributeListImpl( AttributeListImpl *p )
{ {
pList = p; mxList = p;
rList = static_cast<XAttributeList *>(pList);
} }
void parse(); void parse();
private: private:
@ -73,8 +68,7 @@ private:
private: private:
Reference< XDocumentHandler > m_rxDocumentHandler; Reference< XDocumentHandler > m_rxDocumentHandler;
Reference< XAttributeList > rList; rtl::Reference<AttributeListImpl> mxList;
AttributeListImpl *pList;
char *eq; char *eq;
}; };