aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Richard <[email protected]>2013-08-16 08:49:13 +0000
committerVincent Richard <[email protected]>2013-08-16 08:49:13 +0000
commit439642caea38ad45683e33573284154c5d9368e7 (patch)
tree9fc630acd2b0fb6c7b542175bde399b44cdddad0
parentAdded support for enhanced status codes (RFC-3463). (diff)
downloadvmime-439642caea38ad45683e33573284154c5d9368e7.tar.gz
vmime-439642caea38ad45683e33573284154c5d9368e7.zip
Made 'message::uid' a class to prevent implicit conversions between 'long' and 'string'.
-rw-r--r--src/net/message.cpp90
-rw-r--r--vmime/net/message.hpp28
2 files changed, 117 insertions, 1 deletions
diff --git a/src/net/message.cpp b/src/net/message.cpp
index 1024bcba..09fe6321 100644
--- a/src/net/message.cpp
+++ b/src/net/message.cpp
@@ -29,6 +29,8 @@
#include "vmime/net/message.hpp"
+#include <sstream>
+
namespace vmime {
namespace net {
@@ -52,6 +54,94 @@ size_t messagePart::getPartCount() const
}
+
+// message::uid
+
+
+message::uid::uid()
+{
+}
+
+
+message::uid::uid(const string& uid)
+ : m_str(uid)
+{
+}
+
+
+message::uid::uid(const unsigned long uid)
+{
+ std::ostringstream oss;
+ oss.imbue(std::locale::classic());
+ oss << uid;
+
+ m_str = oss.str();
+}
+
+
+message::uid::uid(const char* uid)
+ : m_str(uid)
+{
+}
+
+
+message::uid::uid(const uid& other)
+{
+ m_str = other.m_str;
+}
+
+
+message::uid& message::uid::operator=(const uid& other)
+{
+ m_str = other.m_str;
+ return *this;
+}
+
+
+message::uid& message::uid::operator=(const string& uid)
+{
+ m_str = uid;
+ return *this;
+}
+
+
+message::uid& message::uid::operator=(const unsigned long uid)
+{
+ std::ostringstream oss;
+ oss.imbue(std::locale::classic());
+ oss << uid;
+
+ m_str = oss.str();
+
+ return *this;
+}
+
+
+message::uid::operator string() const
+{
+ return m_str;
+}
+
+
+bool message::uid::empty() const
+{
+ return m_str.empty();
+}
+
+
+bool message::uid::operator==(const uid& other) const
+{
+ return m_str == other.m_str;
+}
+
+
+std::ostream& operator<<(std::ostream& os, const message::uid& uid)
+{
+ os << static_cast <string>(uid);
+ return os;
+}
+
+
} // net
} // vmime
diff --git a/vmime/net/message.hpp b/vmime/net/message.hpp
index 76bfb16b..de5e884a 100644
--- a/vmime/net/message.hpp
+++ b/vmime/net/message.hpp
@@ -177,7 +177,30 @@ public:
/** The type for an unique message identifier.
*/
- typedef string uid;
+ class uid
+ {
+ public:
+
+ uid();
+ uid(const string& uid);
+ uid(const unsigned long uid);
+ uid(const char* uid);
+ uid(const uid& other);
+
+ uid& operator=(const uid& other);
+ uid& operator=(const string& uid);
+ uid& operator=(const unsigned long uid);
+
+ operator string() const;
+
+ bool empty() const;
+
+ bool operator==(const uid& other) const;
+
+ private:
+
+ string m_str;
+ };
/** Return the MIME structure of the message (must fetch before).
*
@@ -315,6 +338,9 @@ public:
};
+VMIME_EXPORT std::ostream& operator<<(std::ostream& os, const message::uid& uid);
+
+
} // net
} // vmime