sw/source/ui/dbui/dbinsdlg.cxx |   71 +++++++++++++++++++----------------------
 1 file changed, 33 insertions(+), 38 deletions(-)

New commits:
commit f8eb7f9c7db6c3dd460868d00758733318cdc266
Author: Jochen Nitschke <j.nitschke+loger...@ok.de>
Date:   Thu Apr 28 01:35:05 2016 +0200

    use initialization list
    
    use anonymous union to make initialization and
    access easier
    prevent overwriting type and use scoped enum
    
    Change-Id: I76037ec666c5740096849b0c58fd9a187ada1d54
    Reviewed-on: https://gerrit.libreoffice.org/24455
    Tested-by: Jenkins <c...@libreoffice.org>
    Reviewed-by: jan iversen <j...@documentfoundation.org>
    Tested-by: jan iversen <j...@documentfoundation.org>
    Reviewed-by: Noel Grandin <noelgran...@gmail.com>

diff --git a/sw/source/ui/dbui/dbinsdlg.cxx b/sw/source/ui/dbui/dbinsdlg.cxx
index 3fe8b9a..af78932 100644
--- a/sw/source/ui/dbui/dbinsdlg.cxx
+++ b/sw/source/ui/dbui/dbinsdlg.cxx
@@ -110,49 +110,44 @@ const char cDBFieldEnd    = '>';
 // Helper structure for adding database rows as fields or text
 struct DB_Column
 {
-    enum ColType { DB_FILLTEXT, DB_COL_FIELD, DB_COL_TEXT, DB_SPLITPARA } 
eColType;
+    const enum class Type { FILLTEXT, COL_FIELD, COL_TEXT, SPLITPARA } 
eColType;
 
     union {
         OUString* pText;
         SwField* pField;
         sal_uLong nFormat;
-    } DB_ColumnData;
+    };
     const SwInsDBColumn* pColInfo;
 
-    DB_Column()
-    {
-        pColInfo = nullptr;
-        DB_ColumnData.pText = nullptr;
-        eColType = DB_SPLITPARA;
-    }
+    DB_Column() : eColType(Type::SPLITPARA),
+                  pText(nullptr),
+                  pColInfo(nullptr)
+    {}
 
     explicit DB_Column( const OUString& rText )
-    {
-        pColInfo = nullptr;
-        DB_ColumnData.pText = new OUString( rText );
-        eColType = DB_FILLTEXT;
-    }
+                        : eColType(Type::FILLTEXT),
+                          pText(new OUString(rText)),
+                          pColInfo(nullptr)
+    {}
 
-    DB_Column( const SwInsDBColumn& rInfo, sal_uLong nFormat )
-    {
-        pColInfo = &rInfo;
-        DB_ColumnData.nFormat = nFormat;
-        eColType = DB_COL_TEXT;
-    }
+    DB_Column( const SwInsDBColumn& rInfo, sal_uLong nFormat_ )
+                        : eColType(Type::COL_TEXT),
+                          nFormat(nFormat_),
+                          pColInfo(&rInfo)
+    {}
 
     DB_Column( const SwInsDBColumn& rInfo, SwDBField& rField )
-    {
-        pColInfo = &rInfo;
-        DB_ColumnData.pField = &rField;
-        eColType = DB_COL_FIELD;
-    }
+                        : eColType(Type::COL_FIELD),
+                          pField(&rField),
+                          pColInfo(&rInfo)
+    {}
 
     ~DB_Column()
     {
-        if( DB_COL_FIELD == eColType )
-            delete DB_ColumnData.pField;
-        else if( DB_FILLTEXT == eColType )
-            delete DB_ColumnData.pText;
+        if( Type::COL_FIELD == eColType )
+            delete pField;
+        else if( Type::FILLTEXT == eColType )
+            delete pText;
     }
 };
 
@@ -936,7 +931,7 @@ bool SwInsertDBColAutoPilot::SplitTextToColArr( const 
OUString& rText,
                             static_cast<SwDBFieldType*>(rSh.InsertFieldType( 
aFieldType )),
                                                             nFormat ) );
                     if( nSubType )
-                        pNew->DB_ColumnData.pField->SetSubType( nSubType );
+                        pNew->pField->SetSubType( nSubType );
                 }
                 else
                     pNew = new DB_Column( rFndCol, nFormat );
@@ -1281,11 +1276,11 @@ void SwInsertDBColAutoPilot::DataToDoc( const 
Sequence<Any>& rSelection,
                     OUString sIns;
                     switch( pDBCol->eColType )
                     {
-                    case DB_Column::DB_FILLTEXT:
-                        sIns =  *pDBCol->DB_ColumnData.pText;
+                    case DB_Column::Type::FILLTEXT:
+                        sIns =  *pDBCol->pText;
                         break;
 
-                    case DB_Column::DB_SPLITPARA:
+                    case DB_Column::Type::SPLITPARA:
                         rSh.SplitNode();
                         // when the template is not the same as the follow 
template,
                         // the selected has to be set newly
@@ -1293,10 +1288,10 @@ void SwInsertDBColAutoPilot::DataToDoc( const 
Sequence<Any>& rSelection,
                             rSh.SetTextFormatColl( pColl );
                         break;
 
-                    case DB_Column::DB_COL_FIELD:
+                    case DB_Column::Type::COL_FIELD:
                         {
                             std::unique_ptr<SwDBField> 
pField(static_cast<SwDBField *>(
-                                pDBCol->DB_ColumnData.pField->CopyField()));
+                                pDBCol->pField->CopyField()));
                             double nValue = DBL_MAX;
 
                             Reference< XPropertySet > xColumnProps;
@@ -1330,7 +1325,7 @@ void SwInsertDBColAutoPilot::DataToDoc( const 
Sequence<Any>& rSelection,
                         }
                         break;
 
-                    case DB_Column::DB_COL_TEXT:
+                    case DB_Column::Type::COL_TEXT:
                         {
                             double nValue = DBL_MAX;
                             Reference< XPropertySet > xColumnProps;
@@ -1339,18 +1334,18 @@ void SwInsertDBColAutoPilot::DataToDoc( const 
Sequence<Any>& rSelection,
                                                 xColumnProps,
                                                 aDBFormatData,
                                                 &nValue );
-                            if( pDBCol->DB_ColumnData.nFormat &&
+                            if( pDBCol->nFormat &&
                                 DBL_MAX != nValue )
                             {
                                 Color* pCol;
-                                
if(rNumFormatr.GetType(pDBCol->DB_ColumnData.nFormat) & 
css::util::NumberFormat::DATE)
+                                if(rNumFormatr.GetType(pDBCol->nFormat) & 
css::util::NumberFormat::DATE)
                                 {
                                     ::Date aStandard(1,1,1900);
                                     if (*rNumFormatr.GetNullDate() != 
aStandard)
                                         nValue += (aStandard - 
*rNumFormatr.GetNullDate());
                                 }
                                 rNumFormatr.GetOutputString( nValue,
-                                            pDBCol->DB_ColumnData.nFormat,
+                                            pDBCol->nFormat,
                                             sIns, &pCol );
                             }
                         }
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to