[Libreoffice-commits] core.git: l10ntools/inc l10ntools/source

Chirag Manwani cmkmanwani at gmail.com
Thu Mar 17 07:06:16 UTC 2016


 l10ntools/inc/xmlparse.hxx    |   24 +++++++++-------
 l10ntools/source/xmlparse.cxx |   60 +++++++++++++++++++++---------------------
 2 files changed, 43 insertions(+), 41 deletions(-)

New commits:
commit 5b3fee11f4019820cc1212a0441020609418dbf1
Author: Chirag Manwani <cmkmanwani at gmail.com>
Date:   Wed Mar 16 17:23:23 2016 +0530

    tdf#84938 Replaced #defined constants with enum class
    
    Change-Id: I2078f15f03fbadab8a0253763d779c3eb7cdf448
    Reviewed-on: https://gerrit.libreoffice.org/23302
    Reviewed-by: Noel Grandin <noelgrandin at gmail.com>
    Tested-by: Noel Grandin <noelgrandin at gmail.com>

diff --git a/l10ntools/inc/xmlparse.hxx b/l10ntools/inc/xmlparse.hxx
index 29397bf..54bba22 100644
--- a/l10ntools/inc/xmlparse.hxx
+++ b/l10ntools/inc/xmlparse.hxx
@@ -38,11 +38,13 @@
 class XMLParentNode;
 class XMLElement;
 
-#define XML_NODE_TYPE_FILE          0x001
-#define XML_NODE_TYPE_ELEMENT       0x002
-#define XML_NODE_TYPE_DATA          0x003
-#define XML_NODE_TYPE_COMMENT       0x004
-#define XML_NODE_TYPE_DEFAULT       0x005
+enum class XMLNodeType{
+    XFILE   = 0x001,
+    ELEMENT = 0x002,
+    DATA    = 0x003,
+    COMMENT = 0x004,
+    DEFAULT = 0x005
+};
 
 /** Holds data of Attributes
  */
@@ -77,7 +79,7 @@ protected:
     XMLNode(){}
 
 public:
-    virtual sal_uInt16 GetNodeType() const = 0;
+    virtual XMLNodeType GetNodeType() const = 0;
     virtual ~XMLNode(){}
 };
 
@@ -166,7 +168,7 @@ public:
 
     XMLFile& operator=(const XMLFile& rObj);
 
-    virtual sal_uInt16 GetNodeType() const override { return XML_NODE_TYPE_FILE; }
+    virtual XMLNodeType GetNodeType() const override { return XMLNodeType::XFILE; }
 
     /// returns file name
     OString GetName() const { return m_sFileName; }
@@ -224,7 +226,7 @@ public:
     XMLElement(const XMLElement&);
 
     XMLElement& operator=(const XMLElement& rObj);
-    virtual sal_uInt16 GetNodeType() const override { return XML_NODE_TYPE_ELEMENT; }
+    virtual XMLNodeType GetNodeType() const override { return XMLNodeType::ELEMENT; }
 
     /// returns element name
     OString GetName() const { return m_sElementName; }
@@ -265,7 +267,7 @@ public:
 
     // Default copy constructor and copy operator work well.
 
-    virtual sal_uInt16 GetNodeType() const override { return XML_NODE_TYPE_DATA; }
+    virtual XMLNodeType GetNodeType() const override { return XMLNodeType::DATA; }
 
     /// returns the data
     OString GetData() const { return m_sData; }
@@ -291,7 +293,7 @@ public:
 
     // Default copy constructor and copy operator work well.
 
-    virtual sal_uInt16 GetNodeType() const override { return XML_NODE_TYPE_COMMENT; }
+    virtual XMLNodeType GetNodeType() const override { return XMLNodeType::COMMENT; }
 
     /// returns the comment
     OString GetComment() const { return m_sComment; }
@@ -314,7 +316,7 @@ public:
 
     // Default copy constructor and copy operator work well.
 
-    virtual sal_uInt16 GetNodeType() const override { return XML_NODE_TYPE_DEFAULT; }
+    virtual XMLNodeType GetNodeType() const override { return XMLNodeType::DEFAULT; }
 
     /// returns the comment
     OString GetDefault() const { return m_sDefault; }
diff --git a/l10ntools/source/xmlparse.cxx b/l10ntools/source/xmlparse.cxx
index 714ef1d..97d6012 100644
--- a/l10ntools/source/xmlparse.cxx
+++ b/l10ntools/source/xmlparse.cxx
@@ -94,13 +94,13 @@ XMLParentNode::XMLParentNode( const XMLParentNode& rObj)
             {
                 switch(pNode->GetNodeType())
                 {
-                    case XML_NODE_TYPE_ELEMENT:
+                    case XMLNodeType::ELEMENT:
                         AddChild( new XMLElement( *static_cast<XMLElement* >(pNode) ) ); break;
-                    case XML_NODE_TYPE_DATA:
+                    case XMLNodeType::DATA:
                         AddChild( new XMLData   ( *static_cast<XMLData* >   (pNode) ) ); break;
-                    case XML_NODE_TYPE_COMMENT:
+                    case XMLNodeType::COMMENT:
                         AddChild( new XMLComment( *static_cast<XMLComment* >(pNode) ) ); break;
-                    case XML_NODE_TYPE_DEFAULT:
+                    case XMLNodeType::DEFAULT:
                         AddChild( new XMLDefault( *static_cast<XMLDefault* >(pNode) ) ); break;
                     default:    fprintf(stdout,"XMLParentNode::XMLParentNode( const XMLParentNode& rObj) strange obj");
                 }
@@ -173,14 +173,14 @@ bool XMLFile::Write( ofstream &rStream , XMLNode *pCur )
     else {
         switch( pCur->GetNodeType())
         {
-            case XML_NODE_TYPE_FILE:
+            case XMLNodeType::XFILE:
             {
                 if( GetChildList())
                     for ( size_t i = 0; i < GetChildList()->size(); i++ )
                         Write( rStream, (*GetChildList())[ i ] );
             }
             break;
-            case XML_NODE_TYPE_ELEMENT:
+            case XMLNodeType::ELEMENT:
             {
                 XMLElement *pElement = static_cast<XMLElement*>(pCur);
                 rStream  << "<";
@@ -209,13 +209,13 @@ bool XMLFile::Write( ofstream &rStream , XMLNode *pCur )
                 }
             }
             break;
-            case XML_NODE_TYPE_DATA:
+            case XMLNodeType::DATA:
             {
                 OString sData( static_cast<const XMLData*>(pCur)->GetData());
                 rStream << XMLUtil::QuotHTML( sData ).getStr();
             }
             break;
-            case XML_NODE_TYPE_COMMENT:
+            case XMLNodeType::COMMENT:
             {
                 const XMLComment *pComment = static_cast<const XMLComment*>(pCur);
                 rStream << "<!--";
@@ -223,7 +223,7 @@ bool XMLFile::Write( ofstream &rStream , XMLNode *pCur )
                 rStream << "-->";
             }
             break;
-            case XML_NODE_TYPE_DEFAULT:
+            case XMLNodeType::DEFAULT:
             {
                 const XMLDefault *pDefault = static_cast<const XMLDefault*>(pCur);
                 rStream <<  pDefault->GetDefault().getStr();
@@ -242,14 +242,14 @@ void XMLFile::Print( XMLNode *pCur, sal_uInt16 nLevel )
     {
         switch( pCur->GetNodeType())
         {
-            case XML_NODE_TYPE_FILE:
+            case XMLNodeType::XFILE:
             {
                 if( GetChildList())
                     for ( size_t i = 0; i < GetChildList()->size(); i++ )
                         Print( (*GetChildList())[ i ] );
             }
             break;
-            case XML_NODE_TYPE_ELEMENT:
+            case XMLNodeType::ELEMENT:
             {
                 XMLElement *pElement = static_cast<XMLElement*>(pCur);
 
@@ -278,19 +278,19 @@ void XMLFile::Print( XMLNode *pCur, sal_uInt16 nLevel )
                 }
             }
             break;
-            case XML_NODE_TYPE_DATA:
+            case XMLNodeType::DATA:
             {
                 const XMLData *pData = static_cast<const XMLData*>(pCur);
                 fprintf( stdout, "%s", pData->GetData().getStr());
             }
             break;
-            case XML_NODE_TYPE_COMMENT:
+            case XMLNodeType::COMMENT:
             {
                 const XMLComment *pComment = static_cast<const XMLComment*>(pCur);
                 fprintf( stdout, "<!--%s-->", pComment->GetComment().getStr());
             }
             break;
-            case XML_NODE_TYPE_DEFAULT:
+            case XMLNodeType::DEFAULT:
             {
                 const XMLDefault *pDefault = static_cast<const XMLDefault*>(pCur);
                 fprintf( stdout, "%s", pDefault->GetDefault().getStr());
@@ -429,20 +429,20 @@ void XMLFile::SearchL10NElements( XMLChildNode *pCur, int nPos )
     {
         switch( pCur->GetNodeType())
         {
-            case XML_NODE_TYPE_FILE:
+            case XMLNodeType::XFILE:
             {
                 if( GetChildList())
                 {
                     for ( size_t i = 0; i < GetChildList()->size(); i++ )
                     {
                         XMLChildNode* pElement = (*GetChildList())[ i ];
-                        if( pElement->GetNodeType() ==  XML_NODE_TYPE_ELEMENT )
+                        if( pElement->GetNodeType() ==  XMLNodeType::ELEMENT )
                             SearchL10NElements( pElement , i);
                     }
                 }
             }
             break;
-            case XML_NODE_TYPE_ELEMENT:
+            case XMLNodeType::ELEMENT:
             {
                 bool bInsert = true;
                 XMLElement *pElement = static_cast<XMLElement*>(pCur);
@@ -485,11 +485,7 @@ void XMLFile::SearchL10NElements( XMLChildNode *pCur, int nPos )
                 }
             }
             break;
-            case XML_NODE_TYPE_DATA:
-            break;
-            case XML_NODE_TYPE_COMMENT:
-            break;
-            case XML_NODE_TYPE_DEFAULT:
+            default:
             break;
         }
     }
@@ -504,19 +500,19 @@ bool XMLFile::CheckExportStatus( XMLParentNode *pCur )
     else {
         switch( pCur->GetNodeType())
         {
-            case XML_NODE_TYPE_FILE:
+            case XMLNodeType::XFILE:
             {
                 if( GetChildList())
                 {
                     for ( size_t i = 0; i < GetChildList()->size(); i++ )
                     {
                         XMLParentNode* pElement = static_cast<XMLParentNode*>((*GetChildList())[ i ]);
-                        if( pElement->GetNodeType() ==  XML_NODE_TYPE_ELEMENT ) CheckExportStatus( pElement );//, i);
+                        if( pElement->GetNodeType() ==  XMLNodeType::ELEMENT ) CheckExportStatus( pElement );//, i);
                     }
                 }
             }
             break;
-            case XML_NODE_TYPE_ELEMENT:
+            case XMLNodeType::ELEMENT:
             {
                 XMLElement *pElement = static_cast<XMLElement*>(pCur);
                 if (pElement->GetName().equalsIgnoreAsciiCase("TOPIC"))
@@ -546,6 +542,8 @@ bool XMLFile::CheckExportStatus( XMLParentNode *pCur )
                 }
             }
             break;
+            default:
+            break;
         }
     }
     return bStatusExport;
@@ -641,7 +639,7 @@ void XMLElement::ChangeLanguageTag( const OString &rValue )
         for ( size_t i = 0; i < pCList->size(); i++ )
         {
             XMLChildNode* pNode = (*pCList)[ i ];
-            if( pNode && pNode->GetNodeType() == XML_NODE_TYPE_ELEMENT )
+            if( pNode && pNode->GetNodeType() == XMLNodeType::ELEMENT )
             {
                 XMLElement* pElem = static_cast< XMLElement* >(pNode);
                 pElem->ChangeLanguageTag( rValue );
@@ -693,7 +691,7 @@ void XMLElement::Print(XMLNode *pCur, OStringBuffer& rBuffer, bool bRootelement
         {
             switch( pCur->GetNodeType())
             {
-                case XML_NODE_TYPE_ELEMENT:
+                case XMLNodeType::ELEMENT:
                 {
                     XMLElement *pElement = static_cast<XMLElement*>(pCur);
 
@@ -729,24 +727,26 @@ void XMLElement::Print(XMLNode *pCur, OStringBuffer& rBuffer, bool bRootelement
                     }
                 }
                 break;
-                case XML_NODE_TYPE_DATA:
+                case XMLNodeType::DATA:
                 {
                     const XMLData *pData = static_cast<const XMLData*>(pCur);
                     rBuffer.append( pData->GetData() );
                 }
                 break;
-                case XML_NODE_TYPE_COMMENT:
+                case XMLNodeType::COMMENT:
                 {
                     const XMLComment *pComment = static_cast<const XMLComment*>(pCur);
                     rBuffer.append( "<!--" + pComment->GetComment() + "-->" );
                 }
                 break;
-                case XML_NODE_TYPE_DEFAULT:
+                case XMLNodeType::DEFAULT:
                 {
                     const XMLDefault *pDefault = static_cast<const XMLDefault*>(pCur);
                     rBuffer.append( pDefault->GetDefault() );
                 }
                 break;
+                default:
+                break;
             }
         }
     }


More information about the Libreoffice-commits mailing list