convert INETMSG_MIME_VERSION constants to enum class

Desktop / LibreOffice - Noel Grandin [peralex.com] - 2 March 2015 00:59 UTC



###

diff --git a/include/tools/inetmsg.hxx b/include/tools/inetmsg.hxx
index 1134ef3..6bf03d2 100644
--- a/include/tools/inetmsg.hxx
+++ b/include/tools/inetmsg.hxx
@@ -106,13 +106,16 @@ enum class InetMessageField
NUMHDR = 16,
};

-#define INETMSG_MIME_VERSION 0
-#define INETMSG_MIME_CONTENT_DESCRIPTION 1
-#define INETMSG_MIME_CONTENT_DISPOSITION 2
-#define INETMSG_MIME_CONTENT_ID 3
-#define INETMSG_MIME_CONTENT_TYPE 4
-#define INETMSG_MIME_CONTENT_TRANSFER_ENCODING 5
-#define INETMSG_MIME_NUMHDR 6
+enum class InetMessageMime
+{
+ VERSION = 0,
+ CONTENT_DESCRIPTION = 1,
+ CONTENT_DISPOSITION = 2,
+ CONTENT_ID = 3,
+ CONTENT_TYPE = 4,
+ CONTENT_TRANSFER_ENCODING = 5,
+ NUMHDR = 6,
+};

enum INetMessageContainerType
{
@@ -141,7 +144,7 @@ class TOOLS_DLLPUBLIC INetMIMEMessage

::std::map m_nRFC822Index;

- sal_uIntPtr m_nMIMEIndex[INETMSG_MIME_NUMHDR];
+ ::std::map m_nMIMEIndex;
INetMIMEMessage* pParent;
INetMIMEMessgeList_impl aChildren;
OString m_aBoundary;
@@ -361,35 +364,35 @@ public:
void SetMIMEVersion (const OUString& rVersion);
OUString GetMIMEVersion() const
{
- return GetHeaderValue (m_nMIMEIndex[INETMSG_MIME_VERSION]);
+ return GetHeaderValue (m_nMIMEIndex.at(InetMessageMime::VERSION));
}

OUString GetContentDescription() const
{
- return GetHeaderValue (m_nMIMEIndex[INETMSG_MIME_CONTENT_DESCRIPTION]);
+ return GetHeaderValue (m_nMIMEIndex.at(InetMessageMime::CONTENT_DESCRIPTION));
}

void SetContentDisposition (const OUString& rDisposition);
OUString GetContentDisposition() const
{
- return GetHeaderValue (m_nMIMEIndex[INETMSG_MIME_CONTENT_DISPOSITION]);
+ return GetHeaderValue (m_nMIMEIndex.at(InetMessageMime::CONTENT_DISPOSITION));
}

OUString GetContentID() const
{
- return GetHeaderValue (m_nMIMEIndex[INETMSG_MIME_CONTENT_ID]);
+ return GetHeaderValue (m_nMIMEIndex.at(InetMessageMime::CONTENT_ID));
}

void SetContentType (const OUString& rType);
OUString GetContentType() const
{
- return GetHeaderValue (m_nMIMEIndex[INETMSG_MIME_CONTENT_TYPE]);
+ return GetHeaderValue (m_nMIMEIndex.at(InetMessageMime::CONTENT_TYPE));
}

void SetContentTransferEncoding (const OUString& rEncoding);
OUString GetContentTransferEncoding() const
{
- return GetHeaderValue (m_nMIMEIndex[INETMSG_MIME_CONTENT_TRANSFER_ENCODING]);
+ return GetHeaderValue (m_nMIMEIndex.at(InetMessageMime::CONTENT_TRANSFER_ENCODING));
}

OUString GetDefaultContentType ();
diff --git a/tools/source/inet/inetmsg.cxx b/tools/source/inet/inetmsg.cxx
index 3335e67..d975824 100644
--- a/tools/source/inet/inetmsg.cxx
+++ b/tools/source/inet/inetmsg.cxx
@@ -88,7 +88,7 @@ void INetMIMEMessage::SetHeaderField_Impl (
INetMessageHeader (rName, aSink.takeBuffer()), rnIndex);
}

-static std::map ImplINetRFC822MessageHeaderData =
+static const std::map ImplINetRFC822MessageHeaderData =
{
{ InetMessageField::BCC, "BCC" } ,
{ InetMessageField::CC, "CC" } ,
@@ -492,7 +492,7 @@ sal_uIntPtr INetMIMEMessage::SetRFC822HeaderField (
case INETMSG_RFC822_OK:
pData = pStop;
SetHeaderField_Impl (
- INetMessageHeader( ImplINetRFC822MessageHeaderData[nIdx], rHeader.GetValue() ),
+ INetMessageHeader( ImplINetRFC822MessageHeaderData.at(nIdx), rHeader.GetValue() ),
m_nRFC822Index[nIdx]);
nNewIndex = m_nRFC822Index[nIdx];
break;
@@ -506,14 +506,14 @@ sal_uIntPtr INetMIMEMessage::SetRFC822HeaderField (
return nNewIndex;
}

-static const char* ImplINetMIMEMessageHeaderData[] =
+static const std::map ImplINetMIMEMessageHeaderData =
{
- "MIME-Version",
- "Content-Description",
- "Content-Disposition",
- "Content-ID",
- "Content-Type",
- "Content-Transfer-Encoding"
+ { InetMessageMime::VERSION, "MIME-Version"},
+ { InetMessageMime::CONTENT_DESCRIPTION, "Content-Description"},
+ { InetMessageMime::CONTENT_DISPOSITION, "Content-Disposition"},
+ { InetMessageMime::CONTENT_ID, "Content-ID"},
+ { InetMessageMime::CONTENT_TYPE, "Content-Type"},
+ { InetMessageMime::CONTENT_TRANSFER_ENCODING, "Content-Transfer-Encoding"}
};

enum _ImplINetMIMEMessageHeaderState
@@ -535,8 +535,8 @@ INetMIMEMessage::INetMIMEMessage()
{
for (sal_uInt16 i = 0; i < static_cast(InetMessageField::NUMHDR); i++)
m_nRFC822Index[static_cast(i)] = CONTAINER_ENTRY_NOTFOUND;
- for (sal_uInt16 i = 0; i < INETMSG_MIME_NUMHDR; i++)
- m_nMIMEIndex[i] = CONTAINER_ENTRY_NOTFOUND;
+ for (sal_uInt16 i = 0; i < static_cast(InetMessageMime::NUMHDR); i++)
+ m_nMIMEIndex[static_cast(i)] = CONTAINER_ENTRY_NOTFOUND;
}

INetMIMEMessage::INetMIMEMessage (const INetMIMEMessage& rMsg)
@@ -585,9 +585,7 @@ void INetMIMEMessage::CopyImp (const INetMIMEMessage& rMsg)
bHeaderParsed = rMsg.bHeaderParsed;

size_t i;
- for (i = 0; i < INETMSG_MIME_NUMHDR; i++)
- m_nMIMEIndex[i] = rMsg.m_nMIMEIndex[i];
-
+ m_nMIMEIndex = rMsg.m_nMIMEIndex;
m_aBoundary = rMsg.m_aBoundary;

for (i = 0; i < rMsg.aChildren.size(); i++)
@@ -618,7 +616,7 @@ sal_uIntPtr INetMIMEMessage::SetHeaderField (
const sal_Char *pStop = pData + aName.getLength() + 1;
const sal_Char *check = "";

- sal_uIntPtr nIdx = CONTAINER_APPEND;
+ InetMessageMime nIdx = static_cast(CONTAINER_APPEND);
int eState = INETMSG_MIME_BEGIN;
int eOkState = INETMSG_MIME_OK;

@@ -639,7 +637,7 @@ sal_uIntPtr INetMIMEMessage::SetHeaderField (

case 'm':
check = "ime-version";
- nIdx = INETMSG_MIME_VERSION;
+ nIdx = InetMessageMime::VERSION;
break;

default:
@@ -661,7 +659,7 @@ sal_uIntPtr INetMIMEMessage::SetHeaderField (

case 'i':
check = "d";
- nIdx = INETMSG_MIME_CONTENT_ID;
+ nIdx = InetMessageMime::CONTENT_ID;
break;

case 't':
@@ -683,12 +681,12 @@ sal_uIntPtr INetMIMEMessage::SetHeaderField (
{
case 'e':
check = "scription";
- nIdx = INETMSG_MIME_CONTENT_DESCRIPTION;
+ nIdx = InetMessageMime::CONTENT_DESCRIPTION;
break;

case 'i':
check = "sposition";
- nIdx = INETMSG_MIME_CONTENT_DISPOSITION;
+ nIdx = InetMessageMime::CONTENT_DISPOSITION;
break;

default:
@@ -706,12 +704,12 @@ sal_uIntPtr INetMIMEMessage::SetHeaderField (
{
case 'r':
check = "ansfer-encoding";
- nIdx = INETMSG_MIME_CONTENT_TRANSFER_ENCODING;
+ nIdx = InetMessageMime::CONTENT_TRANSFER_ENCODING;
break;

case 'y':
check = "pe";
- nIdx = INETMSG_MIME_CONTENT_TYPE;
+ nIdx = InetMessageMime::CONTENT_TYPE;
break;

default:
@@ -741,7 +739,7 @@ sal_uIntPtr INetMIMEMessage::SetHeaderField (
case INETMSG_MIME_OK:
pData = pStop;
SetHeaderField_Impl (
- INetMessageHeader( ImplINetMIMEMessageHeaderData[nIdx], rHeader.GetValue()),
+ INetMessageHeader( ImplINetMIMEMessageHeaderData.at(nIdx), rHeader.GetValue()),
m_nMIMEIndex[nIdx]);
nNewIndex = m_nMIMEIndex[nIdx];
break;
@@ -759,24 +757,24 @@ void INetMIMEMessage::SetMIMEVersion (const OUString& rVersion)
{
SetHeaderField_Impl (
INetMIME::HEADER_FIELD_TEXT,
- ImplINetMIMEMessageHeaderData[INETMSG_MIME_VERSION], rVersion,
- m_nMIMEIndex[INETMSG_MIME_VERSION]);
+ ImplINetMIMEMessageHeaderData.at(InetMessageMime::VERSION), rVersion,
+ m_nMIMEIndex[InetMessageMime::VERSION]);
}

void INetMIMEMessage::SetContentDisposition (const OUString& rDisposition)
{
SetHeaderField_Impl (
INetMIME::HEADER_FIELD_TEXT,
- ImplINetMIMEMessageHeaderData[INETMSG_MIME_CONTENT_DISPOSITION], rDisposition,
- m_nMIMEIndex[INETMSG_MIME_CONTENT_DISPOSITION]);
+ ImplINetMIMEMessageHeaderData.at(InetMessageMime::CONTENT_DISPOSITION), rDisposition,
+ m_nMIMEIndex[InetMessageMime::CONTENT_DISPOSITION]);
}

void INetMIMEMessage::SetContentType (const OUString& rType)
{
SetHeaderField_Impl (
INetMIME::HEADER_FIELD_TEXT,
- ImplINetMIMEMessageHeaderData[INETMSG_MIME_CONTENT_TYPE], rType,
- m_nMIMEIndex[INETMSG_MIME_CONTENT_TYPE]);
+ ImplINetMIMEMessageHeaderData.at(InetMessageMime::CONTENT_TYPE), rType,
+ m_nMIMEIndex[InetMessageMime::CONTENT_TYPE]);
}

void INetMIMEMessage::SetContentTransferEncoding (
@@ -784,8 +782,8 @@ void INetMIMEMessage::SetContentTransferEncoding (
{
SetHeaderField_Impl (
INetMIME::HEADER_FIELD_TEXT,
- ImplINetMIMEMessageHeaderData[INETMSG_MIME_CONTENT_TRANSFER_ENCODING], rEncoding,
- m_nMIMEIndex[INETMSG_MIME_CONTENT_TRANSFER_ENCODING]);
+ ImplINetMIMEMessageHeaderData.at(InetMessageMime::CONTENT_TRANSFER_ENCODING), rEncoding,
+ m_nMIMEIndex[InetMessageMime::CONTENT_TRANSFER_ENCODING]);
}

OUString INetMIMEMessage::GetDefaultContentType()

63dc0b4 convert INETMSG_MIME_VERSION constants to enum class
include/tools/inetmsg.hxx | 31 ++++++++++++----------
tools/source/inet/inetmsg.cxx | 58 ++++++++++++++++++++---------------------
2 files changed, 45 insertions(+), 44 deletions(-)

Upstream: cgit.freedesktop.org


  • Share