stop duplicate definition of lcl_popOrZero()

This renames it to popOrZero() in node.hxx. Also one more call site
found in mathmlimport.hxx.

Change-Id: I3f0281315146347280d0836ceadcfdf9c80fa166
Reviewed-on: https://gerrit.libreoffice.org/12310
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Tested-by: Noel Grandin <noelgrandin@gmail.com>
This commit is contained in:
Takeshi Abe 2014-11-09 01:10:32 +09:00 committed by Noel Grandin
parent 775d99c87b
commit da2d24a285
4 changed files with 70 additions and 93 deletions

View File

@ -64,8 +64,15 @@ typedef std::stack< SmNode* > SmNodeStack;
typedef std::vector< SmNode * > SmNodeArray;
typedef std::vector< SmStructureNode * > SmStructureNodeArray;
template < typename T >
T* popOrZero( ::std::stack<T*> & rStack )
{
if (rStack.empty())
return 0;
T* pTmp = rStack.top();
rStack.pop();
return pTmp;
}
enum SmScaleMode { SCALE_NONE, SCALE_WIDTH, SCALE_HEIGHT };

View File

@ -81,19 +81,6 @@ using namespace ::xmloff::token;
#define IMPORT_SVC_NAME "com.sun.star.xml.XMLImportFilter"
namespace {
template < typename T >
T* lcl_popOrZero( ::std::stack<T*> & rStack )
{
if (rStack.empty())
return 0;
T* pTmp = rStack.top();
rStack.pop();
return pTmp;
}
}
sal_uLong SmXMLImportWrapper::Import(SfxMedium &rMedium)
{
sal_uLong nError = ERRCODE_SFX_DOLOADFAILED;
@ -704,7 +691,7 @@ void SmXMLContext_Helper::ApplyAttrs()
aToken.eType = TNBOLD;
SmStructureNode *pFontNode = static_cast<SmStructureNode *>
(new SmFontNode(aToken));
pFontNode->SetSubNodes(0,lcl_popOrZero(rNodeStack));
pFontNode->SetSubNodes(0,popOrZero(rNodeStack));
rNodeStack.push(pFontNode);
}
if (nIsItalic != -1)
@ -715,7 +702,7 @@ void SmXMLContext_Helper::ApplyAttrs()
aToken.eType = TNITALIC;
SmStructureNode *pFontNode = static_cast<SmStructureNode *>
(new SmFontNode(aToken));
pFontNode->SetSubNodes(0,lcl_popOrZero(rNodeStack));
pFontNode->SetSubNodes(0,popOrZero(rNodeStack));
rNodeStack.push(pFontNode);
}
if (nFontSize != 0.0)
@ -736,7 +723,7 @@ void SmXMLContext_Helper::ApplyAttrs()
else
pFontNode->SetSizeParameter(Fraction(nFontSize),FNTSIZ_ABSOLUT);
pFontNode->SetSubNodes(0,lcl_popOrZero(rNodeStack));
pFontNode->SetSubNodes(0,popOrZero(rNodeStack));
rNodeStack.push(pFontNode);
}
if (!sFontFamily.isEmpty())
@ -753,7 +740,7 @@ void SmXMLContext_Helper::ApplyAttrs()
aToken.aText = sFontFamily;
SmFontNode *pFontNode = new SmFontNode(aToken);
pFontNode->SetSubNodes(0,lcl_popOrZero(rNodeStack));
pFontNode->SetSubNodes(0,popOrZero(rNodeStack));
rNodeStack.push(pFontNode);
}
if (!sColor.isEmpty())
@ -767,7 +754,7 @@ void SmXMLContext_Helper::ApplyAttrs()
{
aToken.eType = static_cast<SmTokenType>(tok);
SmFontNode *pFontNode = new SmFontNode(aToken);
pFontNode->SetSubNodes(0,lcl_popOrZero(rNodeStack));
pFontNode->SetSubNodes(0,popOrZero(rNodeStack));
rNodeStack.push(pFontNode);
}
}
@ -966,7 +953,7 @@ void SmXMLPhantomContext_Impl::EndElement()
SmStructureNode *pPhantom = static_cast<SmStructureNode *>
(new SmFontNode(aToken));
SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
pPhantom->SetSubNodes(0,lcl_popOrZero(rNodeStack));
pPhantom->SetSubNodes(0,popOrZero(rNodeStack));
rNodeStack.push(pPhantom);
}
@ -1445,8 +1432,8 @@ void SmXMLSubContext_Impl::GenericEndElement(SmTokenType eType, SmSubSup eSubSup
for (sal_uLong i = 1; i < aSubNodes.size(); i++)
aSubNodes[i] = NULL;
aSubNodes[eSubSup+1] = lcl_popOrZero(rNodeStack);
aSubNodes[0] = lcl_popOrZero(rNodeStack);
aSubNodes[eSubSup+1] = popOrZero(rNodeStack);
aSubNodes[0] = popOrZero(rNodeStack);
pNode->SetSubNodes(aSubNodes);
rNodeStack.push(pNode);
}
@ -1505,9 +1492,9 @@ void SmXMLSubSupContext_Impl::GenericEndElement(SmTokenType eType,
for (sal_uLong i = 1; i < aSubNodes.size(); i++)
aSubNodes[i] = NULL;
aSubNodes[aSup+1] = lcl_popOrZero(rNodeStack);
aSubNodes[aSub+1] = lcl_popOrZero(rNodeStack);
aSubNodes[0] = lcl_popOrZero(rNodeStack);
aSubNodes[aSup+1] = popOrZero(rNodeStack);
aSubNodes[aSub+1] = popOrZero(rNodeStack);
aSubNodes[0] = popOrZero(rNodeStack);
pNode->SetSubNodes(aSubNodes);
rNodeStack.push(pNode);
}
@ -1546,7 +1533,7 @@ void SmXMLUnderContext_Impl::HandleAccent()
/*Just one special case for the underline thing*/
SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
SmNode *pTest = lcl_popOrZero(rNodeStack);
SmNode *pTest = popOrZero(rNodeStack);
SmToken aToken;
aToken.cMathChar = '\0';
aToken.eType = TUNDERLINE;
@ -1564,7 +1551,7 @@ void SmXMLUnderContext_Impl::HandleAccent()
else
aSubNodes[0] = pTest;
aSubNodes[1] = lcl_popOrZero(rNodeStack);
aSubNodes[1] = popOrZero(rNodeStack);
pNode->SetSubNodes(aSubNodes);
pNode->SetScaleMode(SCALE_WIDTH);
rNodeStack.push(pNode);
@ -1629,8 +1616,8 @@ void SmXMLOverContext_Impl::HandleAccent()
SmNodeArray aSubNodes;
aSubNodes.resize(2);
aSubNodes[0] = lcl_popOrZero(rNodeStack);
aSubNodes[1] = lcl_popOrZero(rNodeStack);
aSubNodes[0] = popOrZero(rNodeStack);
aSubNodes[1] = popOrZero(rNodeStack);
pNode->SetSubNodes(aSubNodes);
pNode->SetScaleMode(SCALE_WIDTH);
rNodeStack.push(pNode);
@ -2152,7 +2139,7 @@ void SmXMLDocContext_Impl::EndElement()
ContextArray.resize(1);
SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
ContextArray[0] = lcl_popOrZero(rNodeStack);
ContextArray[0] = popOrZero(rNodeStack);
SmToken aDummy;
SmStructureNode *pSNode = new SmLineNode(aDummy);
@ -2185,8 +2172,8 @@ void SmXMLFracContext_Impl::EndElement()
aToken.eType = TOVER;
SmStructureNode *pSNode = new SmBinVerNode(aToken);
SmNode *pOper = new SmRectangleNode(aToken);
SmNode *pSecond = lcl_popOrZero(rNodeStack);
SmNode *pFirst = lcl_popOrZero(rNodeStack);
SmNode *pSecond = popOrZero(rNodeStack);
SmNode *pFirst = popOrZero(rNodeStack);
pSNode->SetSubNodes(pFirst,pOper,pSecond);
rNodeStack.push(pSNode);
}
@ -2205,8 +2192,8 @@ void SmXMLRootContext_Impl::EndElement()
SmStructureNode *pSNode = new SmRootNode(aToken);
SmNode *pOper = new SmRootSymbolNode(aToken);
SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
SmNode *pIndex = lcl_popOrZero(rNodeStack);
SmNode *pBase = lcl_popOrZero(rNodeStack);
SmNode *pIndex = popOrZero(rNodeStack);
SmNode *pBase = popOrZero(rNodeStack);
pSNode->SetSubNodes(pIndex,pOper,pBase);
rNodeStack.push(pSNode);
}
@ -2227,7 +2214,7 @@ void SmXMLSqrtContext_Impl::EndElement()
SmStructureNode *pSNode = new SmRootNode(aToken);
SmNode *pOper = new SmRootSymbolNode(aToken);
SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
pSNode->SetSubNodes(0,pOper,lcl_popOrZero(rNodeStack));
pSNode->SetSubNodes(0,pOper,popOrZero(rNodeStack));
rNodeStack.push(pSNode);
}
@ -2465,14 +2452,14 @@ void SmXMLMultiScriptsContext_Impl::ProcessSubSupPairs(bool bIsPrescript)
/*On each loop the base and its sub sup pair becomes the
base for the next loop to which the next sub sup pair is
attached, i.e. wheels within wheels*/
aSubNodes[0] = lcl_popOrZero(aReverseStack);
aSubNodes[0] = popOrZero(aReverseStack);
SmNode *pScriptNode = lcl_popOrZero(aReverseStack);
SmNode *pScriptNode = popOrZero(aReverseStack);
if (pScriptNode && ((pScriptNode->GetToken().eType != TIDENT) ||
(!pScriptNode->GetToken().aText.isEmpty())))
aSubNodes[eSub+1] = pScriptNode;
pScriptNode = lcl_popOrZero(aReverseStack);
pScriptNode = popOrZero(aReverseStack);
if (pScriptNode && ((pScriptNode->GetToken().eType != TIDENT) ||
(!pScriptNode->GetToken().aText.isEmpty())))
aSubNodes[eSup+1] = pScriptNode;
@ -2480,7 +2467,7 @@ void SmXMLMultiScriptsContext_Impl::ProcessSubSupPairs(bool bIsPrescript)
pNode->SetSubNodes(aSubNodes);
aReverseStack.push(pNode);
}
rNodeStack.push(lcl_popOrZero(aReverseStack));
rNodeStack.push(popOrZero(aReverseStack));
}
else
{

View File

@ -245,11 +245,7 @@ public:
SmNodeStack & GetNodeStack() { return aNodeStack; }
SmNode *GetTree()
{
if (aNodeStack.empty())
return 0;
SmNode* result = aNodeStack.top();
aNodeStack.pop();
return result;
return popOrZero(aNodeStack);
}
bool GetSuccess() { return bSuccess; }

View File

@ -36,19 +36,6 @@ using namespace ::com::sun::star;
using namespace ::com::sun::star::i18n;
namespace {
template < typename T >
T* lcl_popOrZero( ::std::stack<T*> & rStack )
{
if (rStack.empty())
return 0;
T* pTmp = rStack.top();
rStack.pop();
return pTmp;
}
}
SmToken::SmToken() :
eType (TUNKNOWN),
cMathChar ('\0')
@ -1008,7 +995,7 @@ void SmParser::Align()
if (pSNode)
{
pSNode->SetSubNodes(lcl_popOrZero(m_aNodeStack), 0);
pSNode->SetSubNodes(popOrZero(m_aNodeStack), 0);
m_aNodeStack.push(pSNode);
}
}
@ -1027,14 +1014,14 @@ void SmParser::Line()
if (m_aCurToken.eType != TEND && m_aCurToken.eType != TNEWLINE)
{ Align();
ExpressionArray.resize(++n);
ExpressionArray[n - 1] = lcl_popOrZero(m_aNodeStack);
ExpressionArray[n - 1] = popOrZero(m_aNodeStack);
}
while (m_aCurToken.eType != TEND && m_aCurToken.eType != TNEWLINE)
{
Expression();
ExpressionArray.resize(++n);
ExpressionArray[n - 1] = lcl_popOrZero(m_aNodeStack);
ExpressionArray[n - 1] = popOrZero(m_aNodeStack);
}
//If there's no expression, add an empty one.
@ -1073,12 +1060,12 @@ void SmParser::Expression()
Relation();
RelationArray.resize(++n);
RelationArray[n - 1] = lcl_popOrZero(m_aNodeStack);
RelationArray[n - 1] = popOrZero(m_aNodeStack);
while (m_aCurToken.nLevel >= 4)
{ Relation();
RelationArray.resize(++n);
RelationArray[n - 1] = lcl_popOrZero(m_aNodeStack);
RelationArray[n - 1] = popOrZero(m_aNodeStack);
}
if (n > 1)
@ -1102,14 +1089,14 @@ void SmParser::Relation()
while (TokenInGroup(TGRELATION))
{
SmStructureNode *pSNode = new SmBinHorNode(m_aCurToken);
SmNode *pFirst = lcl_popOrZero(m_aNodeStack);
SmNode *pFirst = popOrZero(m_aNodeStack);
OpSubSup();
SmNode *pSecond = lcl_popOrZero(m_aNodeStack);
SmNode *pSecond = popOrZero(m_aNodeStack);
Sum();
pSNode->SetSubNodes(pFirst, pSecond, lcl_popOrZero(m_aNodeStack));
pSNode->SetSubNodes(pFirst, pSecond, popOrZero(m_aNodeStack));
m_aNodeStack.push(pSNode);
}
}
@ -1121,14 +1108,14 @@ void SmParser::Sum()
while (TokenInGroup(TGSUM))
{
SmStructureNode *pSNode = new SmBinHorNode(m_aCurToken);
SmNode *pFirst = lcl_popOrZero(m_aNodeStack);
SmNode *pFirst = popOrZero(m_aNodeStack);
OpSubSup();
SmNode *pSecond = lcl_popOrZero(m_aNodeStack);
SmNode *pSecond = popOrZero(m_aNodeStack);
Product();
pSNode->SetSubNodes(pFirst, pSecond, lcl_popOrZero(m_aNodeStack));
pSNode->SetSubNodes(pFirst, pSecond, popOrZero(m_aNodeStack));
m_aNodeStack.push(pSNode);
}
}
@ -1140,7 +1127,7 @@ void SmParser::Product()
while (TokenInGroup(TGPRODUCT))
{ SmStructureNode *pSNode;
SmNode *pFirst = lcl_popOrZero(m_aNodeStack),
SmNode *pFirst = popOrZero(m_aNodeStack),
*pOper;
bool bSwitchArgs = false;
@ -1163,7 +1150,7 @@ void SmParser::Product()
m_aCurToken.nGroup = TGPRODUCT;
GlyphSpecial();
pOper = lcl_popOrZero(m_aNodeStack);
pOper = popOrZero(m_aNodeStack);
break;
case TOVERBRACE :
@ -1192,7 +1179,7 @@ void SmParser::Product()
pSNode = new SmBinHorNode(m_aCurToken);
OpSubSup();
pOper = lcl_popOrZero(m_aNodeStack);
pOper = popOrZero(m_aNodeStack);
}
Power();
@ -1200,11 +1187,11 @@ void SmParser::Product()
if (bSwitchArgs)
{
//! vgl siehe SmBinDiagonalNode::Arrange
pSNode->SetSubNodes(pFirst, lcl_popOrZero(m_aNodeStack), pOper);
pSNode->SetSubNodes(pFirst, popOrZero(m_aNodeStack), pOper);
}
else
{
pSNode->SetSubNodes(pFirst, pOper, lcl_popOrZero(m_aNodeStack));
pSNode->SetSubNodes(pFirst, pOper, popOrZero(m_aNodeStack));
}
m_aNodeStack.push(pSNode);
}
@ -1231,7 +1218,7 @@ void SmParser::SubSup(sal_uLong nActiveGroup)
// initialize subnodes array
SmNodeArray aSubNodes;
aSubNodes.resize(1 + SUBSUP_NUM_ENTRIES);
aSubNodes[0] = lcl_popOrZero(m_aNodeStack);
aSubNodes[0] = popOrZero(m_aNodeStack);
for (sal_uInt16 i = 1; i < aSubNodes.size(); i++)
aSubNodes[i] = NULL;
@ -1271,7 +1258,7 @@ void SmParser::SubSup(sal_uLong nActiveGroup)
// set sub-/supscript if not already done
if (aSubNodes[nIndex] != NULL)
Error(PE_DOUBLE_SUBSUPSCRIPT);
aSubNodes[nIndex] = lcl_popOrZero(m_aNodeStack);
aSubNodes[nIndex] = popOrZero(m_aNodeStack);
}
pNode->SetSubNodes(aSubNodes);
@ -1444,7 +1431,7 @@ void SmParser::Term(bool bGroupNumberIdent)
nodeArray.resize(nTokens);
while (nTokens > 0)
{
nodeArray[nTokens-1] = lcl_popOrZero(m_aNodeStack);
nodeArray[nTokens-1] = popOrZero(m_aNodeStack);
nTokens--;
}
SmExpressionNode* pNode = new SmExpressionNode(SmToken());
@ -1542,7 +1529,7 @@ void SmParser::Term(bool bGroupNumberIdent)
else
FontAttribut();
SmNode* pTmp = lcl_popOrZero(m_aNodeStack);
SmNode* pTmp = popOrZero(m_aNodeStack);
// check if casting in following line is ok
OSL_ENSURE(pTmp && !pTmp->IsVisible(), "Sm : Ooops...");
@ -1553,7 +1540,7 @@ void SmParser::Term(bool bGroupNumberIdent)
Power();
SmNode *pFirstNode = lcl_popOrZero(m_aNodeStack);
SmNode *pFirstNode = popOrZero(m_aNodeStack);
while (n > 0)
{ aArray[n - 1]->SetSubNodes(0, pFirstNode);
pFirstNode = aArray[n - 1];
@ -1619,12 +1606,12 @@ void SmParser::Operator()
if (TokenInGroup(TGLIMIT) || TokenInGroup(TGPOWER))
SubSup(m_aCurToken.nGroup);
SmNode *pOperator = lcl_popOrZero(m_aNodeStack);
SmNode *pOperator = popOrZero(m_aNodeStack);
// get argument
Power();
pSNode->SetSubNodes(pOperator, lcl_popOrZero(m_aNodeStack));
pSNode->SetSubNodes(pOperator, popOrZero(m_aNodeStack));
m_aNodeStack.push(pSNode);
}
}
@ -1716,7 +1703,7 @@ void SmParser::UnOper()
case TNROOT :
NextToken();
Power();
pExtra = lcl_popOrZero(m_aNodeStack);
pExtra = popOrZero(m_aNodeStack);
break;
case TUOPER :
@ -1725,7 +1712,7 @@ void SmParser::UnOper()
m_aCurToken.eType = TUOPER;
m_aCurToken.nGroup = TGUNOPER;
GlyphSpecial();
pOper = lcl_popOrZero(m_aNodeStack);
pOper = popOrZero(m_aNodeStack);
break;
case TPLUS :
@ -1735,7 +1722,7 @@ void SmParser::UnOper()
case TNEG :
case TFACT :
OpSubSup();
pOper = lcl_popOrZero(m_aNodeStack);
pOper = popOrZero(m_aNodeStack);
break;
default :
@ -1744,7 +1731,7 @@ void SmParser::UnOper()
// get argument
Power();
pArg = lcl_popOrZero(m_aNodeStack);
pArg = popOrZero(m_aNodeStack);
if (eType == TABS)
{ pSNode = new SmBraceNode(aNodeToken);
@ -2013,7 +2000,7 @@ void SmParser::Brace()
NextToken();
Bracebody(true);
pBody = lcl_popOrZero(m_aNodeStack);
pBody = popOrZero(m_aNodeStack);
if (m_aCurToken.eType == TRIGHT)
{ NextToken();
@ -2041,7 +2028,7 @@ void SmParser::Brace()
NextToken();
Bracebody(false);
pBody = lcl_popOrZero(m_aNodeStack);
pBody = popOrZero(m_aNodeStack);
SmTokenType eExpectedType = TUNKNOWN;
switch (pLeft->GetToken().eType)
@ -2138,7 +2125,7 @@ void SmParser::Bracebody(bool bIsLeftRight)
aNodes.resize(nNum);
for (sal_uInt16 i = 0; i < nNum; i++)
{
aNodes[nNum - 1 - i] = lcl_popOrZero(m_aNodeStack);
aNodes[nNum - 1 - i] = popOrZero(m_aNodeStack);
}
pBody->SetSubNodes(aNodes);
@ -2198,7 +2185,7 @@ void SmParser::Binom()
for (int i = 0; i < 2; i++)
{
ExpressionArray[2 - (i + 1)] = lcl_popOrZero(m_aNodeStack);
ExpressionArray[2 - (i + 1)] = popOrZero(m_aNodeStack);
}
pSNode->SetSubNodes(ExpressionArray);
@ -2226,7 +2213,7 @@ void SmParser::Stack()
for (sal_uInt16 i = 0; i < n; i++)
{
ExpressionArray[n - (i + 1)] = lcl_popOrZero(m_aNodeStack);
ExpressionArray[n - (i + 1)] = popOrZero(m_aNodeStack);
}
if (m_aCurToken.eType != TRGROUP)
@ -2292,7 +2279,7 @@ void SmParser::Matrix()
for (size_t i = 0; i < (nRC); ++i)
{
ExpressionArray[(nRC) - (i + 1)] = lcl_popOrZero(m_aNodeStack);
ExpressionArray[(nRC) - (i + 1)] = popOrZero(m_aNodeStack);
}
if (m_aCurToken.eType != TRGROUP)
@ -2413,7 +2400,7 @@ SmNode *SmParser::Parse(const OUString &rBuffer)
NextToken();
Table();
SmNode* result = lcl_popOrZero(m_aNodeStack);
SmNode* result = popOrZero(m_aNodeStack);
return result;
}
@ -2435,7 +2422,7 @@ SmNode *SmParser::ParseExpression(const OUString &rBuffer)
NextToken();
Expression();
SmNode* result = lcl_popOrZero(m_aNodeStack);
SmNode* result = popOrZero(m_aNodeStack);
return result;
}