aboutsummaryrefslogtreecommitdiffstats
path: root/vmime
diff options
context:
space:
mode:
Diffstat (limited to 'vmime')
-rw-r--r--vmime/address.hpp4
-rw-r--r--vmime/addressList.hpp26
-rw-r--r--vmime/attachment.hpp4
-rw-r--r--vmime/base.hpp96
-rw-r--r--vmime/body.hpp47
-rw-r--r--vmime/bodyPart.hpp20
-rw-r--r--vmime/charset.hpp4
-rw-r--r--vmime/component.hpp8
-rw-r--r--vmime/contentDisposition.hpp4
-rw-r--r--vmime/contentDispositionField.hpp2
-rw-r--r--vmime/contentHandler.hpp4
-rw-r--r--vmime/contentTypeField.hpp2
-rw-r--r--vmime/dateTime.hpp4
-rw-r--r--vmime/defaultAttachment.hpp14
-rw-r--r--vmime/defaultParameter.hpp7
-rw-r--r--vmime/disposition.hpp4
-rw-r--r--vmime/emptyContentHandler.hpp2
-rw-r--r--vmime/encoder.hpp2
-rw-r--r--vmime/encoderFactory.hpp24
-rw-r--r--vmime/encoding.hpp8
-rw-r--r--vmime/genericField.hpp31
-rw-r--r--vmime/genericParameter.hpp25
-rw-r--r--vmime/header.hpp38
-rw-r--r--vmime/headerField.hpp13
-rw-r--r--vmime/headerFieldFactory.hpp8
-rw-r--r--vmime/htmlTextPart.hpp37
-rw-r--r--vmime/mailbox.hpp4
-rw-r--r--vmime/mailboxField.hpp2
-rw-r--r--vmime/mailboxGroup.hpp26
-rw-r--r--vmime/mailboxList.hpp24
-rw-r--r--vmime/mdn/MDNHelper.hpp40
-rw-r--r--vmime/mdn/MDNInfos.hpp5
-rw-r--r--vmime/mdn/receivedMDNInfos.hpp6
-rw-r--r--vmime/mdn/sendableMDNInfos.hpp6
-rw-r--r--vmime/mediaType.hpp4
-rw-r--r--vmime/messageBuilder.hpp22
-rw-r--r--vmime/messageId.hpp6
-rw-r--r--vmime/messageIdSequence.hpp28
-rw-r--r--vmime/messageParser.hpp16
-rw-r--r--vmime/messaging/authenticationInfos.hpp2
-rw-r--r--vmime/messaging/authenticator.hpp3
-rw-r--r--vmime/messaging/defaultAuthenticator.hpp7
-rw-r--r--vmime/messaging/events.hpp18
-rw-r--r--vmime/messaging/folder.hpp26
-rw-r--r--vmime/messaging/imap/IMAPConnection.hpp26
-rw-r--r--vmime/messaging/imap/IMAPFolder.hpp25
-rw-r--r--vmime/messaging/imap/IMAPMessage.hpp5
-rw-r--r--vmime/messaging/imap/IMAPParser.hpp12
-rw-r--r--vmime/messaging/imap/IMAPStore.hpp16
-rw-r--r--vmime/messaging/imap/IMAPTag.hpp2
-rw-r--r--vmime/messaging/maildir/maildirFolder.hpp31
-rw-r--r--vmime/messaging/maildir/maildirMessage.hpp11
-rw-r--r--vmime/messaging/maildir/maildirStore.hpp8
-rw-r--r--vmime/messaging/maildir/maildirUtils.hpp3
-rw-r--r--vmime/messaging/message.hpp12
-rw-r--r--vmime/messaging/pop3/POP3Folder.hpp23
-rw-r--r--vmime/messaging/pop3/POP3Message.hpp1
-rw-r--r--vmime/messaging/pop3/POP3Store.hpp14
-rw-r--r--vmime/messaging/sendmail/sendmailTransport.hpp2
-rw-r--r--vmime/messaging/service.hpp18
-rw-r--r--vmime/messaging/serviceFactory.hpp23
-rw-r--r--vmime/messaging/serviceInfos.hpp4
-rw-r--r--vmime/messaging/session.hpp15
-rw-r--r--vmime/messaging/smtp/SMTPTransport.hpp6
-rw-r--r--vmime/messaging/socket.hpp12
-rw-r--r--vmime/messaging/store.hpp8
-rw-r--r--vmime/messaging/timeoutHandler.hpp7
-rw-r--r--vmime/messaging/transport.hpp4
-rw-r--r--vmime/misc/importanceHelper.hpp6
-rw-r--r--vmime/object.hpp108
-rw-r--r--vmime/parameter.hpp9
-rw-r--r--vmime/parameterFactory.hpp10
-rw-r--r--vmime/parameterizedHeaderField.hpp28
-rw-r--r--vmime/path.hpp4
-rw-r--r--vmime/plainTextPart.hpp6
-rw-r--r--vmime/platforms/posix/posixChildProcess.hpp10
-rw-r--r--vmime/platforms/posix/posixFile.hpp16
-rw-r--r--vmime/platforms/posix/posixSocket.hpp2
-rw-r--r--vmime/platforms/windows/windowsFile.hpp38
-rw-r--r--vmime/platforms/windows/windowsSocket.hpp5
-rw-r--r--vmime/propertySet.hpp22
-rw-r--r--vmime/relay.hpp4
-rw-r--r--vmime/standardFields.hpp6
-rw-r--r--vmime/standardParams.hpp2
-rw-r--r--vmime/streamContentHandler.hpp9
-rw-r--r--vmime/stringContentHandler.hpp2
-rw-r--r--vmime/text.hpp61
-rw-r--r--vmime/textPart.hpp6
-rw-r--r--vmime/textPartFactory.hpp14
-rw-r--r--vmime/typeAdapter.hpp12
-rw-r--r--vmime/types.hpp14
-rw-r--r--vmime/utility/childProcess.hpp8
-rw-r--r--vmime/utility/file.hpp32
-rw-r--r--vmime/utility/path.hpp2
-rw-r--r--vmime/utility/smartPtr.hpp508
-rw-r--r--vmime/utility/stream.hpp12
-rw-r--r--vmime/word.hpp13
97 files changed, 1314 insertions, 626 deletions
diff --git a/vmime/address.hpp b/vmime/address.hpp
index 405908ae..2fce4f63 100644
--- a/vmime/address.hpp
+++ b/vmime/address.hpp
@@ -59,7 +59,7 @@ public:
*/
virtual const bool isGroup() const = 0;
- virtual address* clone() const = 0;
+ virtual ref <component> clone() const = 0;
protected:
@@ -71,7 +71,7 @@ protected:
* @param newPosition will receive the new position in the input buffer
* @return a new address object, or null if no more address is available in the input buffer
*/
- static address* parseNext(const string& buffer, const string::size_type position, const string::size_type end, string::size_type* newPosition);
+ static ref <address> parseNext(const string& buffer, const string::size_type position, const string::size_type end, string::size_type* newPosition);
};
diff --git a/vmime/addressList.hpp b/vmime/addressList.hpp
index f5629ebe..d5c63c3d 100644
--- a/vmime/addressList.hpp
+++ b/vmime/addressList.hpp
@@ -47,19 +47,19 @@ public:
~addressList();
- addressList* clone() const;
+ ref <component> clone() const;
void copyFrom(const component& other);
addressList& operator=(const addressList& other);
addressList& operator=(const mailboxList& other);
- const std::vector <const component*> getChildComponents() const;
+ const std::vector <ref <const component> > getChildComponents() const;
/** Add a address at the end of the list.
*
* @param addr address to append
*/
- void appendAddress(address* addr);
+ void appendAddress(ref <address> addr);
/** Insert a new address before the specified address.
*
@@ -67,7 +67,7 @@ public:
* @param addr address to insert
* @throw exceptions::no_such_address if the address is not in the list
*/
- void insertAddressBefore(address* beforeAddress, address* addr);
+ void insertAddressBefore(ref <address> beforeAddress, ref <address> addr);
/** Insert a new address before the specified position.
*
@@ -75,7 +75,7 @@ public:
* the beginning of the list)
* @param addr address to insert
*/
- void insertAddressBefore(const int pos, address* addr);
+ void insertAddressBefore(const int pos, ref <address> addr);
/** Insert a new address after the specified address.
*
@@ -83,21 +83,21 @@ public:
* @param addr address to insert
* @throw exceptions::no_such_address if the address is not in the list
*/
- void insertAddressAfter(address* afterAddress, address* addr);
+ void insertAddressAfter(ref <address> afterAddress, ref <address> addr);
/** Insert a new address after the specified position.
*
* @param pos position of the address before the new address
* @param addr address to insert
*/
- void insertAddressAfter(const int pos, address* addr);
+ void insertAddressAfter(const int pos, ref <address> addr);
/** Remove the specified address from the list.
*
* @param addr address to remove
* @throw exceptions::no_such_address if the address is not in the list
*/
- void removeAddress(address* addr);
+ void removeAddress(ref <address> addr);
/** Remove the address at the specified position.
*
@@ -126,30 +126,30 @@ public:
* @param pos position
* @return address at position 'pos'
*/
- address* getAddressAt(const int pos);
+ ref <address> getAddressAt(const int pos);
/** Return the address at the specified position.
*
* @param pos position
* @return address at position 'pos'
*/
- const address* getAddressAt(const int pos) const;
+ const ref <const address> getAddressAt(const int pos) const;
/** Return the address list.
*
* @return list of addresses
*/
- const std::vector <const address*> getAddressList() const;
+ const std::vector <ref <const address> > getAddressList() const;
/** Return the address list.
*
* @return list of addresses
*/
- const std::vector <address*> getAddressList();
+ const std::vector <ref <address> > getAddressList();
private:
- std::vector <address*> m_list;
+ std::vector <ref <address> > m_list;
public:
diff --git a/vmime/attachment.hpp b/vmime/attachment.hpp
index 60c7b29d..72fb13d0 100644
--- a/vmime/attachment.hpp
+++ b/vmime/attachment.hpp
@@ -37,7 +37,7 @@ namespace vmime
/** Base class for all types of attachment.
*/
-class attachment
+class attachment : public object
{
friend class messageBuilder;
friend class messageParser;
@@ -63,7 +63,7 @@ public:
/** Return the data contained in this attachment.
* @return attachment data
*/
- virtual const contentHandler& getData() const = 0;
+ virtual const ref <const contentHandler> getData() const = 0;
/** Return the encoding used for this attachment.
* @return attachment data encoding
diff --git a/vmime/base.hpp b/vmime/base.hpp
index 7f3fa670..175bfdd9 100644
--- a/vmime/base.hpp
+++ b/vmime/base.hpp
@@ -31,6 +31,7 @@
#include "vmime/types.hpp"
#include "vmime/constants.hpp"
#include "vmime/utility/stream.hpp"
+#include "vmime/utility/smartPtr.hpp"
namespace vmime
@@ -80,17 +81,6 @@ namespace vmime
}
- // Free the pointer elements in a STL container and empty the container
-
- template <class CONTAINER>
- void free_container(CONTAINER& c)
- {
- for (typename CONTAINER::iterator it = c.begin() ; it != c.end() ; ++it)
- delete (*it);
-
- c.clear();
- }
-
// Copy one vector to another, with type conversion
template <class T1, class T2>
@@ -164,6 +154,90 @@ namespace vmime
/** Utility classes. */
namespace utility { }
+
+#ifndef VMIME_BUILDING_DOC
+ /** Work-around for friend template functions.
+ *
+ * Make this class a friend if you want to be able to use
+ * vmime::create() with private/protected constructors.
+ */
+ struct creator
+ {
+ template <class T>
+ static ref <T> create() { return ref <T>::fromPtr(new T); }
+
+ template <class T, class P0>
+ static ref <T> create(const P0& p0) { return ref <T>::fromPtr(new T(p0)); }
+
+ template <class T, class P0, class P1>
+ static ref <T> create(const P0& p0, const P1& p1) { return ref <T>::fromPtr(new T(p0, p1)); }
+
+ template <class T, class P0, class P1, class P2>
+ static ref <T> create(const P0& p0, const P1& p1, const P2& p2) { return ref <T>::fromPtr(new T(p0, p1, p2)); }
+
+ template <class T, class P0, class P1, class P2, class P3>
+ static ref <T> create(const P0& p0, const P1& p1, const P2& p2, const P3& p3) { return ref <T>::fromPtr(new T(p0, p1, p2, p3)); }
+
+ template <class T, class P0, class P1, class P2, class P3, class P4>
+ static ref <T> create(const P0& p0, const P1& p1, const P2& p2, const P3& p3, const P4& p4) { return ref <T>::fromPtr(new T(p0, p1, p2, p3, p4)); }
+ };
+#endif // VMIME_BUILDING_DOC
+
+ /** Create a new object and return a reference to it.
+ * @return reference to the new object
+ */
+ template <class T>
+ static ref <T> create() { return creator::create <T>(); }
+
+ /** Create a new object and return a reference to it.
+ * @return reference to the new object
+ */
+ template <class T, class P0>
+ static ref <T> create(const P0& p0) { return creator::create <T, P0>(p0); }
+
+ /** Create a new object and return a reference to it.
+ * @return reference to the new object
+ */
+ template <class T, class P0, class P1>
+ static ref <T> create(const P0& p0, const P1& p1) { return creator::create <T, P0, P1>(p0, p1); }
+
+ /** Create a new object and return a reference to it.
+ * @return reference to the new object
+ */
+ template <class T, class P0, class P1, class P2>
+ static ref <T> create(const P0& p0, const P1& p1, const P2& p2) { return creator::create <T, P0, P1, P2>(p0, p1, p2); }
+
+ /** Create a new object and return a reference to it.
+ * @return reference to the new object
+ */
+ template <class T, class P0, class P1, class P2, class P3>
+ static ref <T> create(const P0& p0, const P1& p1, const P2& p2, const P3& p3) { return creator::create <T, P0, P1, P2, P3>(p0, p1, p2, p3); }
+
+ /** Create a new object and return a reference to it.
+ * @return reference to the new object
+ */
+ template <class T, class P0, class P1, class P2, class P3, class P4>
+ static ref <T> create(const P0& p0, const P1& p1, const P2& p2, const P3& p3, const P4& p4) { return creator::create <T, P0, P1, P2, P3, P4>(p0, p1, p2, p3, p4); }
+
+
+ /** Clone helper.
+ * Use "vmime::clone(obj)" instead of "obj->clone().cast <objtype>()".
+ */
+ template <class T>
+ ref <T> clone(ref <T> x)
+ {
+ return x->clone().template dynamicCast <T>();
+ }
+
+ /** Clone helper.
+ * Use "vmime::clone(obj)" instead of "obj.clone().cast <objtype>()".
+ */
+ template <class T>
+ ref <T> clone(T& x)
+ {
+ return x.clone().template dynamicCast <T>();
+ }
+
} // vmime
diff --git a/vmime/body.hpp b/vmime/body.hpp
index 56cc54b1..46d53f50 100644
--- a/vmime/body.hpp
+++ b/vmime/body.hpp
@@ -47,10 +47,6 @@ class body : public component
{
friend class bodyPart;
-private:
-
- body(bodyPart* parentPart);
-
public:
body();
@@ -60,7 +56,7 @@ public:
*
* @param part part to append
*/
- void appendPart(bodyPart* part);
+ void appendPart(ref <bodyPart> part);
/** Insert a new part before the specified part.
*
@@ -68,7 +64,7 @@ public:
* @param part part to insert
* @throw exceptions::no_such_part if the part is not in the list
*/
- void insertPartBefore(bodyPart* beforePart, bodyPart* part);
+ void insertPartBefore(ref <bodyPart> beforePart, ref <bodyPart> part);
/** Insert a new part before the specified position.
*
@@ -76,7 +72,7 @@ public:
* the beginning of the list)
* @param part part to insert
*/
- void insertPartBefore(const int pos, bodyPart* part);
+ void insertPartBefore(const int pos, ref <bodyPart> part);
/** Insert a new part after the specified part.
*
@@ -84,21 +80,21 @@ public:
* @param part part to insert
* @throw exceptions::no_such_part if the part is not in the list
*/
- void insertPartAfter(bodyPart* afterPart, bodyPart* part);
+ void insertPartAfter(ref <bodyPart> afterPart, ref <bodyPart> part);
/** Insert a new part after the specified position.
*
* @param pos position of the part before the new part
* @param part part to insert
*/
- void insertPartAfter(const int pos, bodyPart* part);
+ void insertPartAfter(const int pos, ref <bodyPart> part);
/** Remove the specified part from the list.
*
* @param part part to remove
* @throw exceptions::no_such_part if the part is not in the list
*/
- void removePart(bodyPart* part);
+ void removePart(ref <bodyPart> part);
/** Remove the part at the specified position.
*
@@ -127,26 +123,26 @@ public:
* @param pos position
* @return part at position 'pos'
*/
- bodyPart* getPartAt(const int pos);
+ ref <bodyPart> getPartAt(const int pos);
/** Return the part at the specified position.
*
* @param pos position
* @return part at position 'pos'
*/
- const bodyPart* getPartAt(const int pos) const;
+ const ref <const bodyPart> getPartAt(const int pos) const;
/** Return the part list.
*
* @return list of parts
*/
- const std::vector <const bodyPart*> getPartList() const;
+ const std::vector <ref <const bodyPart> > getPartList() const;
/** Return the part list.
*
* @return list of parts
*/
- const std::vector <bodyPart*> getPartList();
+ const std::vector <ref <bodyPart> > getPartList();
/** Return the prolog text.
*
@@ -176,13 +172,13 @@ public:
*
* @return read-only body contents
*/
- const contentHandler& getContents() const;
+ const ref <const contentHandler> getContents() const;
/** Set the body contents.
*
* @param contents new body contents
*/
- void setContents(const contentHandler& contents);
+ void setContents(ref <contentHandler> contents);
/** Return the media type of the data contained in the body contents.
* This is a shortcut for getHeader()->ContentType()->getValue()
@@ -221,29 +217,30 @@ public:
*/
static const bool isValidBoundary(const string& boundary);
- body* clone() const;
+ ref <component> clone() const;
void copyFrom(const component& other);
body& operator=(const body& other);
- const std::vector <const component*> getChildComponents() const;
+ const std::vector <ref <const component> > getChildComponents() const;
private:
+ void setParentPart(weak_ref <bodyPart> parent);
+
+
string m_prologText;
string m_epilogText;
- contentHandler* m_contents;
+ ref <contentHandler> m_contents;
- bodyPart* m_part;
- header* m_header;
+ weak_ref <bodyPart> m_part;
+ weak_ref <header> m_header;
- std::vector <bodyPart*> m_parts;
+ std::vector <ref <bodyPart> > m_parts;
const bool isRootPart() const;
- void initNewPart(bodyPart* part);
-
- void setContentsImpl(const contentHandler& cts);
+ void initNewPart(ref <bodyPart> part);
public:
diff --git a/vmime/bodyPart.hpp b/vmime/bodyPart.hpp
index 60c64528..a7a63274 100644
--- a/vmime/bodyPart.hpp
+++ b/vmime/bodyPart.hpp
@@ -47,44 +47,44 @@ public:
*
* @return header section
*/
- const header* getHeader() const;
+ const ref <const header> getHeader() const;
/** Return the header section of this part.
*
* @return header section
*/
- header* getHeader();
+ ref <header> getHeader();
/** Return the body section of this part.
*
* @return body section
*/
- const body* getBody() const;
+ const ref <const body> getBody() const;
/** Return the body section of this part.
*
* @return body section
*/
- body* getBody();
+ ref <body> getBody();
/** Return the parent part of this part.
*
* @return parent part or NULL if not known
*/
- bodyPart* getParentPart() const;
+ weak_ref <bodyPart> getParentPart() const;
- bodyPart* clone() const;
+ ref <component> clone() const;
void copyFrom(const component& other);
bodyPart& operator=(const bodyPart& other);
- const std::vector <const component*> getChildComponents() const;
+ const std::vector <ref <const component> > getChildComponents() const;
private:
- header m_header;
- body m_body;
+ ref <header> m_header;
+ ref <body> m_body;
- bodyPart* m_parent;
+ weak_ref <bodyPart> m_parent;
public:
diff --git a/vmime/charset.hpp b/vmime/charset.hpp
index 3c24a0ca..db614001 100644
--- a/vmime/charset.hpp
+++ b/vmime/charset.hpp
@@ -53,7 +53,7 @@ public:
const bool operator==(const charset& value) const;
const bool operator!=(const charset& value) const;
- const std::vector <const component*> getChildComponents() const;
+ const std::vector <ref <const component> > getChildComponents() const;
/** Returns the default charset used on the system.
*
@@ -107,7 +107,7 @@ public:
*/
static void convert(utility::inputStream& in, utility::outputStream& out, const charset& source, const charset& dest);
- charset* clone() const;
+ ref <component> clone() const;
void copyFrom(const component& other);
private:
diff --git a/vmime/component.hpp b/vmime/component.hpp
index 5a22bfd5..a7a4da1e 100644
--- a/vmime/component.hpp
+++ b/vmime/component.hpp
@@ -32,7 +32,7 @@ namespace vmime
* It defines the methods for parsing and generating all the components.
*/
-class component
+class component : public object
{
public:
@@ -77,7 +77,7 @@ public:
*
* @return a copy of this component
*/
- virtual component* clone() const = 0;
+ virtual ref <component> clone() const = 0;
/** Replace data in this component by data in other component.
* Both components must be of the same type.
@@ -108,13 +108,13 @@ public:
*
* @return list of child components
*/
- const std::vector <component*> getChildComponents();
+ const std::vector <ref <component> > getChildComponents();
/** Return the list of children of this component (const version).
*
* @return list of child components
*/
- virtual const std::vector <const component*> getChildComponents() const = 0;
+ virtual const std::vector <ref <const component> > getChildComponents() const = 0;
protected:
diff --git a/vmime/contentDisposition.hpp b/vmime/contentDisposition.hpp
index eb56130e..1efc56bb 100644
--- a/vmime/contentDisposition.hpp
+++ b/vmime/contentDisposition.hpp
@@ -55,11 +55,11 @@ public:
*/
void setName(const string& name);
- contentDisposition* clone() const;
+ ref <component> clone() const;
void copyFrom(const component& other);
contentDisposition& operator=(const contentDisposition& other);
- const std::vector <const component*> getChildComponents() const;
+ const std::vector <ref <const component> > getChildComponents() const;
contentDisposition& operator=(const string& name);
diff --git a/vmime/contentDispositionField.hpp b/vmime/contentDispositionField.hpp
index 74382c49..e813674c 100644
--- a/vmime/contentDispositionField.hpp
+++ b/vmime/contentDispositionField.hpp
@@ -35,7 +35,7 @@ namespace vmime
class contentDispositionField : public parameterizedHeaderField, public genericField <contentDisposition>
{
- friend class headerFieldFactory::registerer <contentDispositionField>;
+ friend class vmime::creator; // create ref
protected:
diff --git a/vmime/contentHandler.hpp b/vmime/contentHandler.hpp
index 45cbb48e..bdc2fde0 100644
--- a/vmime/contentHandler.hpp
+++ b/vmime/contentHandler.hpp
@@ -33,7 +33,7 @@ namespace vmime
{
-class contentHandler
+class contentHandler : public object
{
public:
@@ -47,7 +47,7 @@ public:
*
* @return copy of this object
*/
- virtual contentHandler* clone() const = 0;
+ virtual ref <contentHandler> clone() const = 0;
/** Output the contents into the specified stream. Data will be
* encoded before being written into the stream. This is used internally
diff --git a/vmime/contentTypeField.hpp b/vmime/contentTypeField.hpp
index 442d6ba4..d273c662 100644
--- a/vmime/contentTypeField.hpp
+++ b/vmime/contentTypeField.hpp
@@ -34,7 +34,7 @@ namespace vmime
class contentTypeField : public parameterizedHeaderField, public genericField <mediaType>
{
- friend class headerFieldFactory::registerer <contentTypeField>;
+ friend class vmime::creator; // create ref
protected:
diff --git a/vmime/dateTime.hpp b/vmime/dateTime.hpp
index 1b205c22..08ba99a0 100644
--- a/vmime/dateTime.hpp
+++ b/vmime/dateTime.hpp
@@ -216,7 +216,7 @@ public:
void copyFrom(const component& other);
- datetime* clone() const;
+ ref <component> clone() const;
// Comparison
const bool operator==(const datetime& other) const;
@@ -229,7 +229,7 @@ public:
// Current date and time
static const datetime now();
- const std::vector <const component*> getChildComponents() const;
+ const std::vector <ref <const component> > getChildComponents() const;
public:
diff --git a/vmime/defaultAttachment.hpp b/vmime/defaultAttachment.hpp
index 65589b48..c451d9f8 100644
--- a/vmime/defaultAttachment.hpp
+++ b/vmime/defaultAttachment.hpp
@@ -41,8 +41,8 @@ protected:
public:
- defaultAttachment(const contentHandler& data, const encoding& enc, const mediaType& type, const text& desc = NULL_TEXT);
- defaultAttachment(const contentHandler& data, const mediaType& type, const text& desc = NULL_TEXT);
+ defaultAttachment(ref <contentHandler> data, const encoding& enc, const mediaType& type, const text& desc = NULL_TEXT);
+ defaultAttachment(ref <contentHandler> data, const mediaType& type, const text& desc = NULL_TEXT);
defaultAttachment(const defaultAttachment& attach);
~defaultAttachment();
@@ -51,15 +51,15 @@ public:
const mediaType& getType() const;
const text& getDescription() const;
- const contentHandler& getData() const;
+ const ref <const contentHandler> getData() const;
const encoding& getEncoding() const;
protected:
- mediaType m_type; // Media type (eg. "application/octet-stream")
- text m_desc; // Description (eg. "The image you requested")
- contentHandler* m_data; // Attachment data (eg. the file contents)
- encoding m_encoding; // Encoding
+ mediaType m_type; // Media type (eg. "application/octet-stream")
+ text m_desc; // Description (eg. "The image you requested")
+ ref <contentHandler> m_data; // Attachment data (eg. the file contents)
+ encoding m_encoding; // Encoding
private:
diff --git a/vmime/defaultParameter.hpp b/vmime/defaultParameter.hpp
index 7c6f7af7..6160c446 100644
--- a/vmime/defaultParameter.hpp
+++ b/vmime/defaultParameter.hpp
@@ -36,7 +36,7 @@ namespace vmime
class defaultParameter : public parameter
{
- friend class parameterFactory::registerer <defaultParameter>;
+ friend class vmime::creator; // create ref
protected:
@@ -59,8 +59,11 @@ private:
void parse(const std::vector <valueChunk>& chunks);
+ const ref <const component> getValueImp() const;
+ const ref <component> getValueImp();
- word m_value;
+
+ ref <word> m_value;
};
diff --git a/vmime/disposition.hpp b/vmime/disposition.hpp
index 8421962e..452ba794 100644
--- a/vmime/disposition.hpp
+++ b/vmime/disposition.hpp
@@ -42,11 +42,11 @@ public:
disposition(const string& actionMode, const string& sendingMode, const string& type, const string& modifier);
- disposition* clone() const;
+ ref <component> clone() const;
void copyFrom(const component& other);
disposition& operator=(const disposition& other);
- const std::vector <const component*> getChildComponents() const;
+ const std::vector <ref <const component> > getChildComponents() const;
/** Set the disposition action mode.
diff --git a/vmime/emptyContentHandler.hpp b/vmime/emptyContentHandler.hpp
index cee2fcbb..636bb691 100644
--- a/vmime/emptyContentHandler.hpp
+++ b/vmime/emptyContentHandler.hpp
@@ -34,7 +34,7 @@ public:
emptyContentHandler();
- contentHandler* clone() const;
+ ref <contentHandler> clone() const;
void generate(utility::outputStream& os, const vmime::encoding& enc, const string::size_type maxLineLength = lineLengthLimits::infinite) const;
diff --git a/vmime/encoder.hpp b/vmime/encoder.hpp
index 3fe81bed..a093b48d 100644
--- a/vmime/encoder.hpp
+++ b/vmime/encoder.hpp
@@ -33,7 +33,7 @@ namespace vmime
/** Encode/decode data in different encodings.
*/
-class encoder
+class encoder : public object
{
public:
diff --git a/vmime/encoderFactory.hpp b/vmime/encoderFactory.hpp
index d466b17c..3fe5d624 100644
--- a/vmime/encoderFactory.hpp
+++ b/vmime/encoderFactory.hpp
@@ -44,17 +44,15 @@ public:
static encoderFactory* getInstance();
/** Information about a registered encoder. */
- class registeredEncoder
+ class registeredEncoder : public object
{
- friend class encoderFactory;
-
protected:
virtual ~registeredEncoder() { }
public:
- virtual encoder* create() const = 0;
+ virtual ref <encoder> create() const = 0;
virtual const string& getName() const = 0;
};
@@ -64,7 +62,7 @@ private:
template <class E>
class registeredEncoderImpl : public registeredEncoder
{
- friend class encoderFactory;
+ friend class vmime::creator;
protected:
@@ -72,9 +70,9 @@ private:
public:
- encoder* create() const
+ ref <encoder> create() const
{
- return new E;
+ return vmime::create <E>();
}
const string& getName() const
@@ -88,7 +86,7 @@ private:
};
- std::vector <registeredEncoder*> m_encoders;
+ std::vector <ref <registeredEncoder> > m_encoders;
public:
@@ -99,7 +97,7 @@ public:
template <class E>
void registerName(const string& name)
{
- m_encoders.push_back(new registeredEncoderImpl <E>(utility::stringUtils::toLower(name)));
+ m_encoders.push_back(vmime::create <registeredEncoderImpl <E> >(utility::stringUtils::toLower(name)));
}
/** Create a new encoder instance from an encoding name.
@@ -109,7 +107,7 @@ public:
* @throw exceptions::no_encoder_available if no encoder is registered
* for this encoding
*/
- encoder* create(const string& name);
+ ref <encoder> create(const string& name);
/** Return information about a registered encoder.
*
@@ -118,7 +116,7 @@ public:
* @throw exceptions::no_encoder_available if no encoder is registered
* for this encoding
*/
- const registeredEncoder* getEncoderByName(const string& name) const;
+ const ref <const registeredEncoder> getEncoderByName(const string& name) const;
/** Return the number of registered encoders.
*
@@ -131,13 +129,13 @@ public:
* @param pos position of the registered encoder to return
* @return registered encoder at the specified position
*/
- const registeredEncoder* getEncoderAt(const int pos) const;
+ const ref <const registeredEncoder> getEncoderAt(const int pos) const;
/** Return a list of all registered encoders.
*
* @return list of registered encoders
*/
- const std::vector <const registeredEncoder*> getEncoderList() const;
+ const std::vector <ref <const registeredEncoder> > getEncoderList() const;
};
diff --git a/vmime/encoding.hpp b/vmime/encoding.hpp
index 5a741144..fc2efe02 100644
--- a/vmime/encoding.hpp
+++ b/vmime/encoding.hpp
@@ -66,7 +66,7 @@ public:
const bool operator==(const encoding& value) const;
const bool operator!=(const encoding& value) const;
- const std::vector <const component*> getChildComponents() const;
+ const std::vector <ref <const component> > getChildComponents() const;
/** Decide which encoding to use based on the specified data.
*
@@ -83,9 +83,9 @@ public:
* @param data data used to determine encoding
* @return suitable encoding for specified data
*/
- static const encoding decide(const contentHandler& data);
+ static const encoding decide(ref <const contentHandler> data);
- encoding* clone() const;
+ ref <component> clone() const;
void copyFrom(const component& other);
/** Use encoderFactory to obtain an encoder/decoder object
@@ -95,7 +95,7 @@ public:
* is registered for the encoding
* @return a new encoder object for the encoding type
*/
- encoder* getEncoder() const;
+ ref <encoder> getEncoder() const;
private:
diff --git a/vmime/genericField.hpp b/vmime/genericField.hpp
index 34c6e9e4..9b306c6f 100644
--- a/vmime/genericField.hpp
+++ b/vmime/genericField.hpp
@@ -37,11 +37,22 @@ namespace vmime
template <class VALUE_TYPE>
class genericField : virtual public headerField
{
- friend class headerFieldFactory::registerer <genericField <VALUE_TYPE> >;
+ friend class vmime::creator; // create ref
protected:
- genericField() { }
+ genericField() : m_value(vmime::create <VALUE_TYPE>()) { }
+
+
+ const ref <const component> getValueImp() const
+ {
+ return (m_value);
+ }
+
+ ref <component> getValueImp()
+ {
+ return (m_value);
+ }
public:
@@ -51,31 +62,31 @@ public:
return (*this);
}
- const VALUE_TYPE& getValue() const
+ template <class TYPE>
+ void setValue(const TYPE& value)
{
- return (m_value);
+ *m_value = value;
}
VALUE_TYPE& getValue()
{
- return (m_value);
+ return *m_value;
}
- template <class TYPE>
- void setValue(const TYPE& value)
+ const VALUE_TYPE& getValue() const
{
- m_value = value;
+ return *m_value;
}
void setValue(const component& value)
{
const VALUE_TYPE& v = dynamic_cast <const VALUE_TYPE&>(value);
- m_value = v;
+ *m_value = v;
}
private:
- VALUE_TYPE m_value;
+ ref <VALUE_TYPE> m_value;
};
diff --git a/vmime/genericParameter.hpp b/vmime/genericParameter.hpp
index 79d55ba4..f0be82ae 100644
--- a/vmime/genericParameter.hpp
+++ b/vmime/genericParameter.hpp
@@ -37,11 +37,22 @@ namespace vmime
template <class VALUE_TYPE>
class genericParameter : public parameter
{
- friend class parameterFactory::registerer <genericParameter <VALUE_TYPE> >;
+ friend class vmime::creator; // create ref
protected:
- genericParameter() { }
+ genericParameter() : m_value(vmime::create <VALUE_TYPE>()) { }
+
+
+ const ref <const component> getValueImp() const
+ {
+ return m_value;
+ }
+
+ const ref <component> getValueImp()
+ {
+ return m_value;
+ }
public:
@@ -53,29 +64,29 @@ public:
const VALUE_TYPE& getValue() const
{
- return (m_value);
+ return (*m_value);
}
VALUE_TYPE& getValue()
{
- return (m_value);
+ return (*m_value);
}
template <class TYPE>
void setValue(const TYPE& value)
{
- m_value = value;
+ *m_value = value;
}
void setValue(const component& value)
{
const VALUE_TYPE& v = dynamic_cast <const VALUE_TYPE&>(value);
- m_value = v;
+ *m_value = v;
}
private:
- VALUE_TYPE m_value;
+ ref <VALUE_TYPE> m_value;
};
diff --git a/vmime/header.hpp b/vmime/header.hpp
index e663e297..eecd66d8 100644
--- a/vmime/header.hpp
+++ b/vmime/header.hpp
@@ -58,10 +58,8 @@ public:
~header();
#define FIELD_ACCESS(methodName, fieldName, type) \
- type& methodName() { return dynamic_cast <type&> \
- (*getField(fields::fieldName)); } \
- const type& methodName() const { return dynamic_cast <const type&> \
- (*findField(fields::fieldName)); }
+ ref <type> methodName() { return getField(fields::fieldName).dynamicCast <type>(); } \
+ ref <const type> methodName() const { return findField(fields::fieldName).dynamicCast <const type>(); }
FIELD_ACCESS(From, FROM, mailboxField)
FIELD_ACCESS(Sender, SENDER, mailboxField)
@@ -107,14 +105,14 @@ public:
* @throw exceptions::no_such_field if no field with this name exists
* @return first field with the specified name
*/
- headerField* findField(const string& fieldName) const;
+ ref <headerField> findField(const string& fieldName) const;
/** Find all fields that match the specified name.
* If no field is found, an empty vector is returned.
*
* @return list of fields with the specified name
*/
- std::vector <headerField*> findAllFields(const string& fieldName);
+ std::vector <ref <headerField> > findAllFields(const string& fieldName);
/** Find the first field that matches the specified name.
* If no field is found, one will be created and inserted into
@@ -123,13 +121,13 @@ public:
* @return first field with the specified name or a new field
* if no field is found
*/
- headerField* getField(const string& fieldName);
+ ref <headerField> getField(const string& fieldName);
/** Add a field at the end of the list.
*
* @param field field to append
*/
- void appendField(headerField* field);
+ void appendField(ref <headerField> field);
/** Insert a new field before the specified field.
*
@@ -137,7 +135,7 @@ public:
* @param field field to insert
* @throw exceptions::no_such_field if the field is not in the list
*/
- void insertFieldBefore(headerField* beforeField, headerField* field);
+ void insertFieldBefore(ref <headerField> beforeField, ref <headerField> field);
/** Insert a new field before the specified position.
*
@@ -145,7 +143,7 @@ public:
* the beginning of the list)
* @param field field to insert
*/
- void insertFieldBefore(const int pos, headerField* field);
+ void insertFieldBefore(const int pos, ref <headerField> field);
/** Insert a new field after the specified field.
*
@@ -153,21 +151,21 @@ public:
* @param field field to insert
* @throw exceptions::no_such_field if the field is not in the list
*/
- void insertFieldAfter(headerField* afterField, headerField* field);
+ void insertFieldAfter(ref <headerField> afterField, ref <headerField> field);
/** Insert a new field after the specified position.
*
* @param pos position of the field before the new field
* @param field field to insert
*/
- void insertFieldAfter(const int pos, headerField* field);
+ void insertFieldAfter(const int pos, ref <headerField> field);
/** Remove the specified field from the list.
*
* @param field field to remove
* @throw exceptions::no_such_field if the field is not in the list
*/
- void removeField(headerField* field);
+ void removeField(ref <headerField> field);
/** Remove the field at the specified position.
*
@@ -196,36 +194,36 @@ public:
* @param pos position
* @return field at position 'pos'
*/
- headerField* getFieldAt(const int pos);
+ ref <headerField> getFieldAt(const int pos);
/** Return the field at the specified position.
*
* @param pos position
* @return field at position 'pos'
*/
- const headerField* getFieldAt(const int pos) const;
+ const ref <const headerField> getFieldAt(const int pos) const;
/** Return the field list.
*
* @return list of fields
*/
- const std::vector <const headerField*> getFieldList() const;
+ const std::vector <ref <const headerField> > getFieldList() const;
/** Return the field list.
*
* @return list of fields
*/
- const std::vector <headerField*> getFieldList();
+ const std::vector <ref <headerField> > getFieldList();
- header* clone() const;
+ ref <component> clone() const;
void copyFrom(const component& other);
header& operator=(const header& other);
- const std::vector <const component*> getChildComponents() const;
+ const std::vector <ref <const component> > getChildComponents() const;
private:
- std::vector <headerField*> m_fields;
+ std::vector <ref <headerField> > m_fields;
public:
diff --git a/vmime/headerField.hpp b/vmime/headerField.hpp
index ba4f5601..6020dd28 100644
--- a/vmime/headerField.hpp
+++ b/vmime/headerField.hpp
@@ -35,6 +35,7 @@ namespace vmime
class headerField : public component
{
friend class headerFieldFactory;
+ friend class header;
protected:
@@ -45,11 +46,11 @@ public:
~headerField();
- headerField* clone() const;
+ ref <component> clone() const;
void copyFrom(const component& other);
headerField& operator=(const headerField& other);
- const std::vector <const component*> getChildComponents() const;
+ const std::vector <ref <const component> > getChildComponents() const;
/** Return the name of this field.
*
@@ -97,10 +98,16 @@ public:
void parse(const string& buffer, const string::size_type position, const string::size_type end, string::size_type* newPosition = NULL);
void generate(utility::outputStream& os, const string::size_type maxLineLength = lineLengthLimits::infinite, const string::size_type curLinePos = 0, string::size_type* newLinePos = NULL) const;
- static headerField* parseNext(const string& buffer, const string::size_type position, const string::size_type end, string::size_type* newPosition = NULL);
+protected:
+
+ virtual const ref <const component> getValueImp() const = 0;
+ virtual ref <component> getValueImp() = 0;
private:
+ static ref <headerField> parseNext(const string& buffer, const string::size_type position, const string::size_type end, string::size_type* newPosition = NULL);
+
+
string m_name;
};
diff --git a/vmime/headerFieldFactory.hpp b/vmime/headerFieldFactory.hpp
index bad8bfe7..4f02cb98 100644
--- a/vmime/headerFieldFactory.hpp
+++ b/vmime/headerFieldFactory.hpp
@@ -36,7 +36,7 @@ protected:
headerFieldFactory();
~headerFieldFactory();
- typedef headerField* (*AllocFunc)(void);
+ typedef ref <headerField> (*AllocFunc)(void);
typedef std::map <string, AllocFunc> NameMap;
NameMap m_nameMap;
@@ -51,10 +51,10 @@ public:
{
public:
- static headerField* creator()
+ static ref <headerField> creator()
{
// Allocate a new object
- return new TYPE();
+ return vmime::create <TYPE>();
}
};
#endif // VMIME_BUILDING_DOC
@@ -67,7 +67,7 @@ public:
(utility::stringUtils::toLower(name), &registerer<T>::creator));
}
- headerField* create(const string& name, const string& body = NULL_STRING);
+ ref <headerField> create(const string& name, const string& body = NULL_STRING);
};
diff --git a/vmime/htmlTextPart.hpp b/vmime/htmlTextPart.hpp
index 3dd31ae4..40fa6f6f 100644
--- a/vmime/htmlTextPart.hpp
+++ b/vmime/htmlTextPart.hpp
@@ -37,39 +37,36 @@ namespace vmime
class htmlTextPart : public textPart
{
-protected:
-
- ~htmlTextPart();
-
public:
htmlTextPart();
+ ~htmlTextPart();
const mediaType getType() const;
const charset& getCharset() const;
void setCharset(const charset& ch);
- const contentHandler& getPlainText() const;
- void setPlainText(const contentHandler& plainText);
+ const ref <const contentHandler> getPlainText() const;
+ void setPlainText(ref <contentHandler> plainText);
- const contentHandler& getText() const;
- void setText(const contentHandler& text);
+ const ref <const contentHandler> getText() const;
+ void setText(ref <contentHandler> text);
/** Embedded object (eg: image for &lt;IMG> tag).
*/
- class embeddedObject
+ class embeddedObject : public object
{
public:
- embeddedObject(const contentHandler& data, const encoding& enc,
+ embeddedObject(ref <contentHandler> data, const encoding& enc,
const string& id, const mediaType& type);
/** Return data stored in this embedded object.
*
* @return stored data
*/
- const contentHandler& getData() const;
+ const ref <const contentHandler> getData() const;
/** Return the encoding used for data in this
* embedded object.
@@ -93,7 +90,7 @@ public:
private:
- contentHandler* m_data;
+ ref <contentHandler> m_data;
encoding m_encoding;
string m_id;
mediaType m_type;
@@ -114,7 +111,7 @@ public:
* @param id object identifier
* @return embedded object with the specified identifier
*/
- const embeddedObject* findObject(const string& id) const;
+ const ref <const embeddedObject> findObject(const string& id) const;
/** Return the number of embedded objects.
*
@@ -127,7 +124,7 @@ public:
* @param pos position of the embedded object
* @return embedded object at position 'pos'
*/
- const embeddedObject* getObjectAt(const int pos) const;
+ const ref <const embeddedObject> getObjectAt(const int pos) const;
/** Embed an object and returns a string which identifies it.
*
@@ -148,7 +145,7 @@ public:
* @return an unique object identifier used to identify the new
* object among all other embedded objects
*/
- const string addObject(const contentHandler& data, const mediaType& type);
+ const string addObject(ref <contentHandler> data, const mediaType& type);
/** Embed an object and returns a string which identifies it.
*
@@ -158,17 +155,17 @@ public:
* @return an unique object identifier used to identify the new
* object among all other embedded objects
*/
- const string addObject(const contentHandler& data, const encoding& enc, const mediaType& type);
+ const string addObject(ref <contentHandler> data, const encoding& enc, const mediaType& type);
private:
- contentHandler* m_plainText;
- contentHandler* m_text;
+ ref <contentHandler> m_plainText;
+ ref <contentHandler> m_text;
charset m_charset;
- std::vector <embeddedObject*> m_objects;
+ std::vector <ref <embeddedObject> > m_objects;
- void findEmbeddedParts(const bodyPart& part, std::vector <const bodyPart*>& cidParts, std::vector <const bodyPart*>& locParts);
+ void findEmbeddedParts(const bodyPart& part, std::vector <ref <const bodyPart> >& cidParts, std::vector <ref <const bodyPart> >& locParts);
void addEmbeddedObject(const bodyPart& part, const string& id);
bool findPlainTextPart(const bodyPart& part, const bodyPart& parent, const bodyPart& textPart);
diff --git a/vmime/mailbox.hpp b/vmime/mailbox.hpp
index 1c30e102..d4f8a276 100644
--- a/vmime/mailbox.hpp
+++ b/vmime/mailbox.hpp
@@ -74,14 +74,14 @@ public:
// Assignment
void copyFrom(const component& other);
- mailbox* clone() const;
+ ref <component> clone() const;
mailbox& operator=(const mailbox& other);
const bool isEmpty() const;
void clear();
- const std::vector <const component*> getChildComponents() const;
+ const std::vector <ref <const component> > getChildComponents() const;
const bool isGroup() const;
diff --git a/vmime/mailboxField.hpp b/vmime/mailboxField.hpp
index 9a97d7a0..47bd0b59 100644
--- a/vmime/mailboxField.hpp
+++ b/vmime/mailboxField.hpp
@@ -31,7 +31,7 @@ namespace vmime
class mailboxField : public genericField <mailbox>
{
- friend class headerFieldFactory::registerer <mailboxField>;
+ friend class vmime::creator; // create ref
protected:
diff --git a/vmime/mailboxGroup.hpp b/vmime/mailboxGroup.hpp
index 413d353d..d503a4df 100644
--- a/vmime/mailboxGroup.hpp
+++ b/vmime/mailboxGroup.hpp
@@ -45,10 +45,10 @@ public:
void copyFrom(const component& other);
- mailboxGroup* clone() const;
+ ref <component> clone() const;
mailboxGroup& operator=(const component& other);
- const std::vector <const component*> getChildComponents() const;
+ const std::vector <ref <const component> > getChildComponents() const;
/** Return the name of the group.
*
@@ -66,7 +66,7 @@ public:
*
* @param mbox mailbox to append
*/
- void appendMailbox(mailbox* mbox);
+ void appendMailbox(ref <mailbox> mbox);
/** Insert a new mailbox before the specified mailbox.
*
@@ -74,7 +74,7 @@ public:
* @param mbox mailbox to insert
* @throw exceptions::no_such_mailbox if the mailbox is not in the list
*/
- void insertMailboxBefore(mailbox* beforeMailbox, mailbox* mbox);
+ void insertMailboxBefore(ref <mailbox> beforeMailbox, ref <mailbox> mbox);
/** Insert a new mailbox before the specified position.
*
@@ -82,7 +82,7 @@ public:
* the beginning of the list)
* @param mbox mailbox to insert
*/
- void insertMailboxBefore(const int pos, mailbox* mbox);
+ void insertMailboxBefore(const int pos, ref <mailbox> mbox);
/** Insert a new mailbox after the specified mailbox.
*
@@ -90,21 +90,21 @@ public:
* @param mbox mailbox to insert
* @throw exceptions::no_such_mailbox if the mailbox is not in the list
*/
- void insertMailboxAfter(mailbox* afterMailbox, mailbox* mbox);
+ void insertMailboxAfter(ref <mailbox> afterMailbox, ref <mailbox> mbox);
/** Insert a new mailbox after the specified position.
*
* @param pos position of the mailbox before the new mailbox
* @param mbox mailbox to insert
*/
- void insertMailboxAfter(const int pos, mailbox* mbox);
+ void insertMailboxAfter(const int pos, ref <mailbox> mbox);
/** Remove the specified mailbox from the list.
*
* @param mbox mailbox to remove
* @throw exceptions::no_such_mailbox if the mailbox is not in the list
*/
- void removeMailbox(mailbox* mbox);
+ void removeMailbox(ref <mailbox> mbox);
/** Remove the mailbox at the specified position.
*
@@ -133,33 +133,33 @@ public:
* @param pos position
* @return mailbox at position 'pos'
*/
- mailbox* getMailboxAt(const int pos);
+ ref <mailbox> getMailboxAt(const int pos);
/** Return the mailbox at the specified position.
*
* @param pos position
* @return mailbox at position 'pos'
*/
- const mailbox* getMailboxAt(const int pos) const;
+ const ref <const mailbox> getMailboxAt(const int pos) const;
/** Return the mailbox list.
*
* @return list of mailboxes
*/
- const std::vector <const mailbox*> getMailboxList() const;
+ const std::vector <ref <const mailbox> > getMailboxList() const;
/** Return the mailbox list.
*
* @return list of mailboxes
*/
- const std::vector <mailbox*> getMailboxList();
+ const std::vector <ref <mailbox> > getMailboxList();
const bool isGroup() const;
private:
text m_name;
- std::vector <mailbox*> m_list;
+ std::vector <ref <mailbox> > m_list;
public:
diff --git a/vmime/mailboxList.hpp b/vmime/mailboxList.hpp
index 5b77e5b2..8c73e623 100644
--- a/vmime/mailboxList.hpp
+++ b/vmime/mailboxList.hpp
@@ -43,17 +43,17 @@ public:
mailboxList(const mailboxList& mboxList);
- mailboxList* clone() const;
+ ref <component> clone() const;
void copyFrom(const component& other);
mailboxList& operator=(const mailboxList& other);
- const std::vector <const component*> getChildComponents() const;
+ const std::vector <ref <const component> > getChildComponents() const;
/** Add a mailbox at the end of the list.
*
* @param mbox mailbox to append
*/
- void appendMailbox(mailbox* mbox);
+ void appendMailbox(ref <mailbox> mbox);
/** Insert a new mailbox before the specified mailbox.
*
@@ -61,7 +61,7 @@ public:
* @param mbox mailbox to insert
* @throw exceptions::no_such_mailbox if the mailbox is not in the list
*/
- void insertMailboxBefore(mailbox* beforeMailbox, mailbox* mbox);
+ void insertMailboxBefore(ref <mailbox> beforeMailbox, ref <mailbox> mbox);
/** Insert a new mailbox before the specified position.
*
@@ -69,7 +69,7 @@ public:
* the beginning of the list)
* @param mbox mailbox to insert
*/
- void insertMailboxBefore(const int pos, mailbox* mbox);
+ void insertMailboxBefore(const int pos, ref <mailbox> mbox);
/** Insert a new mailbox after the specified mailbox.
*
@@ -77,21 +77,21 @@ public:
* @param mbox mailbox to insert
* @throw exceptions::no_such_mailbox if the mailbox is not in the list
*/
- void insertMailboxAfter(mailbox* afterMailbox, mailbox* mbox);
+ void insertMailboxAfter(ref <mailbox> afterMailbox, ref <mailbox> mbox);
/** Insert a new mailbox after the specified position.
*
* @param pos position of the mailbox before the new mailbox
* @param mbox mailbox to insert
*/
- void insertMailboxAfter(const int pos, mailbox* mbox);
+ void insertMailboxAfter(const int pos, ref <mailbox> mbox);
/** Remove the specified mailbox from the list.
*
* @param mbox mailbox to remove
* @throw exceptions::no_such_mailbox if the mailbox is not in the list
*/
- void removeMailbox(mailbox* mbox);
+ void removeMailbox(ref <mailbox> mbox);
/** Remove the mailbox at the specified position.
*
@@ -120,26 +120,26 @@ public:
* @param pos position
* @return mailbox at position 'pos'
*/
- mailbox* getMailboxAt(const int pos);
+ ref <mailbox> getMailboxAt(const int pos);
/** Return the mailbox at the specified position.
*
* @param pos position
* @return mailbox at position 'pos'
*/
- const mailbox* getMailboxAt(const int pos) const;
+ const ref <const mailbox> getMailboxAt(const int pos) const;
/** Return the mailbox list.
*
* @return list of mailboxes
*/
- const std::vector <const mailbox*> getMailboxList() const;
+ const std::vector <ref <const mailbox> > getMailboxList() const;
/** Return the mailbox list.
*
* @return list of mailboxes
*/
- const std::vector <mailbox*> getMailboxList();
+ const std::vector <ref <mailbox> > getMailboxList();
private:
diff --git a/vmime/mdn/MDNHelper.hpp b/vmime/mdn/MDNHelper.hpp
index af923cd4..a9d8166a 100644
--- a/vmime/mdn/MDNHelper.hpp
+++ b/vmime/mdn/MDNHelper.hpp
@@ -42,14 +42,14 @@ public:
* @param msg message in which to add a MDN request
* @param mailboxes list of mailboxes to which the MDN will be sent
*/
- static void attachMDNRequest(message* msg, const mailboxList& mailboxes);
+ static void attachMDNRequest(ref <message> msg, const mailboxList& mailboxes);
/** Attach a MDN request to the specified message.
*
* @param msg message in which to add a MDN request
* @param mbox mailbox to which the MDN will be sent
*/
- static void attachMDNRequest(message* msg, const mailbox& mbox);
+ static void attachMDNRequest(ref <message> msg, const mailbox& mbox);
/** Return a list of possible MDNs that can be generated
* for the specified message.
@@ -57,14 +57,14 @@ public:
* @param msg message for which to send a MDN
* @return list of possible MDNs
*/
- static const std::vector <sendableMDNInfos> getPossibleMDNs(const message* msg);
+ static const std::vector <sendableMDNInfos> getPossibleMDNs(const ref <const message> msg);
/** Test whether the specified message is a MDN.
*
* @param msg message
* @return true if the message is a MDN, false otherwise
*/
- static const bool isMDN(const message* msg);
+ static const bool isMDN(const ref <const message> msg);
/** If the specified message is a MDN, return information
* about it.
@@ -73,7 +73,7 @@ public:
* @throw exceptions::invalid_argument if the message is not a MDN
* @return information about the MDN
*/
- static receivedMDNInfos getReceivedMDN(const message* msg);
+ static receivedMDNInfos getReceivedMDN(const ref <const message> msg);
/** Check whether we need user confirmation for sending a MDN even
* if he/she explicitely allowed automatic send of MDNs. This can
@@ -82,7 +82,7 @@ public:
* @param msg message for which to send a MDN
* @return true if user confirmation should be asked, false otherwise
*/
- static bool needConfirmation(const message* msg);
+ static const bool needConfirmation(const ref <const message> msg);
/** Build a new MDN for the message. The resulting MDN can then be
* sent over SMTP transport service.
@@ -98,26 +98,26 @@ public:
* @param reportingUAProducts list of products in the reporting user-agent (optional)
* @return a new message object containing the MDN
*/
- static message* buildMDN(const sendableMDNInfos& mdnInfos,
- const string& text,
- const charset& ch,
- const mailbox& expeditor,
- const disposition& dispo,
- const string& reportingUA = NULL_STRING,
- const std::vector <string>& reportingUAProducts
+ static ref <message> buildMDN(const sendableMDNInfos& mdnInfos,
+ const string& text,
+ const charset& ch,
+ const mailbox& expeditor,
+ const disposition& dispo,
+ const string& reportingUA = NULL_STRING,
+ const std::vector <string>& reportingUAProducts
= std::vector <string>());
private:
- static bodyPart* createFirstMDNPart(const sendableMDNInfos& mdnInfos,
- const string& text, const charset& ch);
+ static ref <bodyPart> createFirstMDNPart(const sendableMDNInfos& mdnInfos,
+ const string& text, const charset& ch);
- static bodyPart* createSecondMDNPart(const sendableMDNInfos& mdnInfos,
- const disposition& dispo,
- const string& reportingUA,
- const std::vector <string>& reportingUAProducts);
+ static ref <bodyPart> createSecondMDNPart(const sendableMDNInfos& mdnInfos,
+ const disposition& dispo,
+ const string& reportingUA,
+ const std::vector <string>& reportingUAProducts);
- static bodyPart* createThirdMDNPart(const sendableMDNInfos& mdnInfos);
+ static ref <bodyPart> createThirdMDNPart(const sendableMDNInfos& mdnInfos);
};
diff --git a/vmime/mdn/MDNInfos.hpp b/vmime/mdn/MDNInfos.hpp
index 13347eed..85f1f34a 100644
--- a/vmime/mdn/MDNInfos.hpp
+++ b/vmime/mdn/MDNInfos.hpp
@@ -21,6 +21,7 @@
#define VMIME_MDN_MDNINFOS_HPP_INCLUDED
+#include "vmime/types.hpp"
#include "vmime/message.hpp"
@@ -31,7 +32,7 @@ namespace mdn {
/** Holds information about Message Disposition Notifications (MDN).
*/
-class MDNInfos
+class MDNInfos : public object
{
public:
@@ -42,7 +43,7 @@ public:
*
* @return related message
*/
- virtual const message* getMessage() const = 0;
+ virtual const ref <const message> getMessage() const = 0;
};
diff --git a/vmime/mdn/receivedMDNInfos.hpp b/vmime/mdn/receivedMDNInfos.hpp
index 1f3d179c..2f2aa7c4 100644
--- a/vmime/mdn/receivedMDNInfos.hpp
+++ b/vmime/mdn/receivedMDNInfos.hpp
@@ -37,13 +37,13 @@ class receivedMDNInfos : public MDNInfos
{
public:
- receivedMDNInfos(const message* msg);
+ receivedMDNInfos(const ref <const message> msg);
receivedMDNInfos(const receivedMDNInfos& other);
receivedMDNInfos& operator=(const receivedMDNInfos& other);
- const message* getMessage() const;
+ const ref <const message> getMessage() const;
/** Return the identifier of the message for which this MDN
* has been generated.
@@ -65,7 +65,7 @@ private:
void extract();
- const message* m_msg;
+ ref <const message> m_msg;
disposition m_disp;
messageId m_omid;
diff --git a/vmime/mdn/sendableMDNInfos.hpp b/vmime/mdn/sendableMDNInfos.hpp
index 6e5a6f0a..0e268062 100644
--- a/vmime/mdn/sendableMDNInfos.hpp
+++ b/vmime/mdn/sendableMDNInfos.hpp
@@ -36,12 +36,12 @@ class sendableMDNInfos : public MDNInfos
{
public:
- sendableMDNInfos(const message* msg, const mailbox& mbox);
+ sendableMDNInfos(const ref <const message> msg, const mailbox& mbox);
sendableMDNInfos(const sendableMDNInfos& other);
sendableMDNInfos& operator=(const sendableMDNInfos& other);
- const message* getMessage() const;
+ const ref <const message> getMessage() const;
/** Return the recipient of the MDN (the mailbox that will receive
* the notification message).
@@ -55,7 +55,7 @@ private:
void copyFrom(const sendableMDNInfos& other);
- const message* m_msg;
+ ref <const message> m_msg;
mailbox m_mailbox;
};
diff --git a/vmime/mediaType.hpp b/vmime/mediaType.hpp
index 9a6b2f69..97b521d8 100644
--- a/vmime/mediaType.hpp
+++ b/vmime/mediaType.hpp
@@ -47,11 +47,11 @@ public:
mediaType& operator=(const string& type);
- mediaType* clone() const;
+ ref <component> clone() const;
void copyFrom(const component& other);
mediaType& operator=(const mediaType& other);
- const std::vector <const component*> getChildComponents() const;
+ const std::vector <ref <const component> > getChildComponents() const;
/** Return the media type.
* See the constants in vmime::mediaTypes.
diff --git a/vmime/messageBuilder.hpp b/vmime/messageBuilder.hpp
index 3c371d02..e30db6d8 100644
--- a/vmime/messageBuilder.hpp
+++ b/vmime/messageBuilder.hpp
@@ -128,17 +128,17 @@ public:
void setSubject(const text& subject);
/** Attach a new object to the message.
- * This is a synonym for messageBuilder::appendAttachment().
+ * \deprecated Use messageBuilder::appendAttachment() instead.
*
* @param attach new attachment
*/
- void attach(attachment* attach);
+ void attach(ref <attachment> attach);
/** Attach a new object to the message.
*
* @param attach new attachment
*/
- void appendAttachment(attachment* attach);
+ void appendAttachment(ref <attachment> attach);
/** Remove the attachment at the specified position.
*
@@ -151,14 +151,14 @@ public:
* @param pos position of the attachment
* @return attachment at the specified position
*/
- const attachment* getAttachmentAt(const int pos) const;
+ const ref <const attachment> getAttachmentAt(const int pos) const;
/** Return the attachment at the specified position.
*
* @param pos position of the attachment
* @return attachment at the specified position
*/
- attachment* getAttachmentAt(const int pos);
+ ref <attachment> getAttachmentAt(const int pos);
/** Return the number of attachments in the message.
*
@@ -170,13 +170,13 @@ public:
*
* @return list of attachments
*/
- const std::vector <const attachment*> getAttachmentList() const;
+ const std::vector <ref <const attachment> > getAttachmentList() const;
/** Return the list of attachments.
*
* @return list of attachments
*/
- const std::vector <attachment*> getAttachmentList();
+ const std::vector <ref <attachment> > getAttachmentList();
/** Change the type of the text part and construct a new part.
*
@@ -188,14 +188,14 @@ public:
*
* @return text part of the message
*/
- textPart* getTextPart();
+ ref <textPart> getTextPart();
/** Construct a new message based on the information specified
* in this object.
*
* @return a new message
*/
- message* construct() const;
+ ref <message> construct() const;
private:
@@ -207,9 +207,9 @@ private:
text m_subject;
- textPart* m_textPart;
+ ref <textPart> m_textPart;
- std::vector <attachment*> m_attach;
+ std::vector <ref <attachment> > m_attach;
};
diff --git a/vmime/messageId.hpp b/vmime/messageId.hpp
index 0b471ab2..9d75631d 100644
--- a/vmime/messageId.hpp
+++ b/vmime/messageId.hpp
@@ -89,11 +89,11 @@ public:
*/
const string getId() const;
- messageId* clone() const;
+ ref <component> clone() const;
void copyFrom(const component& other);
messageId& operator=(const messageId& other);
- const std::vector <const component*> getChildComponents() const;
+ const std::vector <ref <const component> > getChildComponents() const;
private:
@@ -119,7 +119,7 @@ protected:
* @param newPosition will receive the new position in the input buffer
* @return a new message-id object, or null if no more message-id can be parsed from the input buffer
*/
- static messageId* parseNext(const string& buffer, const string::size_type position, const string::size_type end, string::size_type* newPosition);
+ static ref <messageId> parseNext(const string& buffer, const string::size_type position, const string::size_type end, string::size_type* newPosition);
};
diff --git a/vmime/messageIdSequence.hpp b/vmime/messageIdSequence.hpp
index 405ab322..8bd66de6 100644
--- a/vmime/messageIdSequence.hpp
+++ b/vmime/messageIdSequence.hpp
@@ -41,18 +41,18 @@ public:
~messageIdSequence();
- messageIdSequence* clone() const;
+ ref <component> clone() const;
void copyFrom(const component& other);
messageIdSequence& operator=(const messageIdSequence& other);
- const std::vector <const component*> getChildComponents() const;
+ const std::vector <ref <const component> > getChildComponents() const;
/** Add a message-id at the end of the list.
*
* @param mid message-id to append
*/
- void appendMessageId(messageId* mid);
+ void appendMessageId(ref <messageId> mid);
/** Insert a new message-id before the specified message-id.
*
@@ -60,7 +60,7 @@ public:
* @param mid message-id to insert
* @throw exceptions::no_such_messageid if the message-id is not in the list
*/
- void insertMessageIdBefore(messageId* beforeMid, messageId* mid);
+ void insertMessageIdBefore(ref <messageId> beforeMid, ref <messageId> mid);
/** Insert a new message-id before the specified position.
*
@@ -68,7 +68,7 @@ public:
* the beginning of the list)
* @param mid message-id to insert
*/
- void insertMessageIdBefore(const int pos, messageId* mid);
+ void insertMessageIdBefore(const int pos, ref <messageId> mid);
/** Insert a new message-id after the specified message-id.
*
@@ -76,21 +76,21 @@ public:
* @param mid message-id to insert
* @throw exceptions::no_such_message_id if the message-id is not in the list
*/
- void insertMessageIdAfter(messageId* afterMid, messageId* mid);
+ void insertMessageIdAfter(ref <messageId> afterMid, ref <messageId> mid);
/** Insert a new message-id after the specified position.
*
* @param pos position of the message-id before the new message-id
* @param mid message-id to insert
*/
- void insertMessageIdAfter(const int pos, messageId* mid);
+ void insertMessageIdAfter(const int pos, ref <messageId> mid);
/** Remove the specified message-id from the list.
*
* @param mid message-id to remove
* @throw exceptions::no_such_message_id if the message-id is not in the list
*/
- void removeMessageId(messageId* mid);
+ void removeMessageId(ref <messageId> mid);
/** Remove the message-id at the specified position.
*
@@ -119,30 +119,30 @@ public:
* @param pos position
* @return message-id at position 'pos'
*/
- messageId* getMessageIdAt(const int pos);
+ const ref <messageId> getMessageIdAt(const int pos);
/** Return the message-id at the specified position.
*
* @param pos position
* @return message-id at position 'pos'
*/
- const messageId* getMessageIdAt(const int pos) const;
+ const ref <const messageId> getMessageIdAt(const int pos) const;
/** Return the message-id list.
*
* @return list of message-ids
*/
- const std::vector <const messageId*> getMessageIdList() const;
+ const std::vector <ref <const messageId> > getMessageIdList() const;
/** Return the message-id list.
*
* @return list of message-ids
*/
- const std::vector <messageId*> getMessageIdList();
+ const std::vector <ref <messageId> > getMessageIdList();
private:
- std::vector <messageId*> m_list;
+ std::vector <ref <messageId> > m_list;
public:
@@ -155,8 +155,6 @@ public:
};
-
-
} // vmime
diff --git a/vmime/messageParser.hpp b/vmime/messageParser.hpp
index 71d52547..82deb767 100644
--- a/vmime/messageParser.hpp
+++ b/vmime/messageParser.hpp
@@ -93,26 +93,26 @@ public:
* @param pos position of the attachment
* @return attachment at position 'pos'
*/
- const attachment* getAttachmentAt(const int pos) const;
+ const ref <const attachment> getAttachmentAt(const int pos) const;
/** Return the attachments of the message.
*
* @return list of attachments in the message
*/
- const std::vector <const attachment*> getAttachmentList() const;
+ const std::vector <ref <const attachment> > getAttachmentList() const;
/** Return information about the specified attachment.
*
* @param a attachment to retrieve information about
* @return information about the specified attachment
*/
- const contentDispositionField* getAttachmentInfo(const attachment* a) const;
+ const ref <const contentDispositionField> getAttachmentInfo(const ref <const attachment> a) const;
/** Return the text parts of the message.
*
* @return list of text parts in the message
*/
- const std::vector <const textPart*> getTextPartList() const;
+ const std::vector <ref <const textPart> > getTextPartList() const;
/** Return the number of text parts in the message.
*
@@ -125,7 +125,7 @@ public:
* @param pos position of the text part
* @return text part at position 'pos'
*/
- const textPart* getTextPartAt(const int pos) const;
+ const ref <const textPart> getTextPartAt(const int pos) const;
private:
@@ -139,10 +139,10 @@ private:
datetime m_date;
- std::vector <attachment*> m_attach;
- std::map <attachment*, contentDispositionField*> m_attachInfo;
+ std::vector <ref <attachment> > m_attach;
+ std::map <attachment*, ref <contentDispositionField> > m_attachInfo;
- std::vector <textPart*> m_textParts;
+ std::vector <ref <textPart> > m_textParts;
void parse(const message& msg);
diff --git a/vmime/messaging/authenticationInfos.hpp b/vmime/messaging/authenticationInfos.hpp
index 2ae35ad4..3682056b 100644
--- a/vmime/messaging/authenticationInfos.hpp
+++ b/vmime/messaging/authenticationInfos.hpp
@@ -31,7 +31,7 @@ namespace messaging {
/** This class encapsulates user credentials.
*/
-class authenticationInfos
+class authenticationInfos : public object
{
public:
diff --git a/vmime/messaging/authenticator.hpp b/vmime/messaging/authenticator.hpp
index 374a48e7..3aa4b9ad 100644
--- a/vmime/messaging/authenticator.hpp
+++ b/vmime/messaging/authenticator.hpp
@@ -21,6 +21,7 @@
#define VMIME_MESSAGING_AUTHENTICATOR_HPP_INCLUDED
+#include "vmime/types.hpp"
#include "vmime/messaging/authenticationInfos.hpp"
@@ -31,7 +32,7 @@ namespace messaging {
/** This class is used to obtain user credentials.
*/
-class authenticator
+class authenticator : public object
{
public:
diff --git a/vmime/messaging/defaultAuthenticator.hpp b/vmime/messaging/defaultAuthenticator.hpp
index b3f5b811..55d1af42 100644
--- a/vmime/messaging/defaultAuthenticator.hpp
+++ b/vmime/messaging/defaultAuthenticator.hpp
@@ -29,6 +29,9 @@ namespace vmime {
namespace messaging {
+class session;
+
+
/** Default implementation for authenticator. It simply returns
* the credentials set in the session properties (named 'username'
* and 'password'). This is the default implementation used if
@@ -39,11 +42,11 @@ class defaultAuthenticator : public authenticator
{
public:
- defaultAuthenticator(const propertySet& props, const string& prefix);
+ defaultAuthenticator(weak_ref <session> session, const string& prefix);
private:
- const propertySet& m_props;
+ weak_ref <session> m_session;
const string m_prefix;
const authenticationInfos requestAuthInfos() const;
diff --git a/vmime/messaging/events.hpp b/vmime/messaging/events.hpp
index 93dc9b36..a74d6459 100644
--- a/vmime/messaging/events.hpp
+++ b/vmime/messaging/events.hpp
@@ -48,13 +48,13 @@ public:
};
- messageCountEvent(folder* folder, const Types type, const std::vector <int>& nums);
+ messageCountEvent(ref <folder> folder, const Types type, const std::vector <int>& nums);
/** Return the folder in which messages have been added/removed.
*
* @return folder in which message count changed
*/
- const folder* getFolder() const;
+ ref <const folder> getFolder() const;
/** Return the event type.
*
@@ -76,7 +76,7 @@ public:
private:
- folder* m_folder;
+ ref <folder> m_folder;
const Types m_type;
std::vector <int> m_nums;
};
@@ -111,13 +111,13 @@ public:
};
- messageChangedEvent(folder* folder, const Types type, const std::vector <int>& nums);
+ messageChangedEvent(ref <folder> folder, const Types type, const std::vector <int>& nums);
/** Return the folder in which messages have changed.
*
* @return folder in which message count changed
*/
- const folder* getFolder() const;
+ ref <const folder> getFolder() const;
/** Return the event type.
*
@@ -139,7 +139,7 @@ public:
private:
- folder* m_folder;
+ ref <folder> m_folder;
const Types m_type;
std::vector <int> m_nums;
};
@@ -175,13 +175,13 @@ public:
};
- folderEvent(folder* folder, const Types type, const utility::path& oldPath, const utility::path& newPath);
+ folderEvent(ref <folder> folder, const Types type, const utility::path& oldPath, const utility::path& newPath);
/** Return the folder on which the event occured.
*
* @return folder on which the event occured
*/
- const folder* getFolder() const;
+ ref <const folder> getFolder() const;
/** Return the event type.
*
@@ -197,7 +197,7 @@ public:
private:
- folder* m_folder;
+ ref <folder> m_folder;
const Types m_type;
const utility::path m_oldPath;
const utility::path m_newPath;
diff --git a/vmime/messaging/folder.hpp b/vmime/messaging/folder.hpp
index 945c862b..246a0e06 100644
--- a/vmime/messaging/folder.hpp
+++ b/vmime/messaging/folder.hpp
@@ -45,11 +45,11 @@ class store;
/** Abstract representation of a folder in a message store.
*/
-class folder
+class folder : public object
{
protected:
- folder(const folder&) { }
+ folder(const folder&) : object() { }
folder() { }
public:
@@ -160,7 +160,7 @@ public:
* @param num message sequence number
* @return a new object referencing the specified message
*/
- virtual message* getMessage(const int num) = 0;
+ virtual ref <message> getMessage(const int num) = 0;
/** Get new references to messages in this folder.
*
@@ -168,14 +168,14 @@ public:
* @param to sequence number of the last message to get
* @return new objects referencing the specified messages
*/
- virtual std::vector <message*> getMessages(const int from = 1, const int to = -1) = 0;
+ virtual std::vector <ref <message> > getMessages(const int from = 1, const int to = -1) = 0;
/** Get new references to messages in this folder.
*
* @param nums sequence numbers of the messages to delete
* @return new objects referencing the specified messages
*/
- virtual std::vector <message*> getMessages(const std::vector <int>& nums) = 0;
+ virtual std::vector <ref <message> > getMessages(const std::vector <int>& nums) = 0;
/** Return the number of messages in this folder.
*
@@ -188,7 +188,7 @@ public:
* @param name sub-folder name
* @return a new object referencing the specified folder
*/
- virtual folder* getFolder(const folder::path::component& name) = 0;
+ virtual ref <folder> getFolder(const folder::path::component& name) = 0;
/** Get the list of all sub-folders in this folder.
*
@@ -196,7 +196,7 @@ public:
* If set to false, only the direct children are returned.
* @return list of sub-folders
*/
- virtual std::vector <folder*> getFolders(const bool recursive = false) = 0;
+ virtual std::vector <ref <folder> > getFolders(const bool recursive = false) = 0;
/** Rename (move) this folder to another location.
*
@@ -247,7 +247,7 @@ public:
* @param date date/time for the new message (if NULL, the current time is used)
* @param progress progression listener, or NULL if not used
*/
- virtual void addMessage(vmime::message* msg, const int flags = message::FLAG_UNDEFINED, vmime::datetime* date = NULL, utility::progressionListener* progress = NULL) = 0;
+ virtual void addMessage(ref <vmime::message> msg, const int flags = message::FLAG_UNDEFINED, vmime::datetime* date = NULL, utility::progressionListener* progress = NULL) = 0;
/** Add a message to this folder.
*
@@ -296,19 +296,19 @@ public:
*
* @return parent folder object
*/
- virtual folder* getParent() = 0;
+ virtual ref <folder> getParent() = 0;
/** Return a reference to the store to which this folder belongs.
*
* @return the store object to which this folder is attached
*/
- virtual const store* getStore() const = 0;
+ virtual weak_ref <const store> getStore() const = 0;
/** Return a reference to the store to which this folder belongs.
*
* @return the store object to which this folder is attached
*/
- virtual store* getStore() = 0;
+ virtual weak_ref <store> getStore() = 0;
/** Fetchable objects.
*/
@@ -331,14 +331,14 @@ public:
* @param options objects to fetch (combination of folder::FetchOptions flags)
* @param progress progression listener, or NULL if not used
*/
- virtual void fetchMessages(std::vector <message*>& msg, const int options, utility::progressionListener* progress = NULL) = 0;
+ virtual void fetchMessages(std::vector <ref <message> >& msg, const int options, utility::progressionListener* progress = NULL) = 0;
/** Fetch objects for the specified message.
*
* @param msg the message
* @param options objects to fetch (combination of folder::FetchOptions flags)
*/
- virtual void fetchMessage(message* msg, const int options) = 0;
+ virtual void fetchMessage(ref <message> msg, const int options) = 0;
/** Return the list of fetchable objects supported by
* the underlying protocol (see folder::FetchOptions).
diff --git a/vmime/messaging/imap/IMAPConnection.hpp b/vmime/messaging/imap/IMAPConnection.hpp
index 8cf37933..5ceca567 100644
--- a/vmime/messaging/imap/IMAPConnection.hpp
+++ b/vmime/messaging/imap/IMAPConnection.hpp
@@ -40,11 +40,11 @@ class IMAPTag;
class IMAPStore;
-class IMAPConnection
+class IMAPConnection : public object
{
public:
- IMAPConnection(IMAPStore* store, authenticator* auth);
+ IMAPConnection(weak_ref <IMAPStore> store, ref <authenticator> auth);
~IMAPConnection();
@@ -75,31 +75,31 @@ public:
IMAPParser::response* readResponse(IMAPParser::literalHandler* lh = NULL);
- const IMAPTag* getTag() const;
- const IMAPParser* getParser() const;
+ ref <const IMAPTag> getTag() const;
+ ref <const IMAPParser> getParser() const;
- const IMAPStore* getStore() const;
- IMAPStore* getStore();
+ weak_ref <const IMAPStore> getStore() const;
+ weak_ref <IMAPStore> getStore();
- session* getSession();
+ ref <session> getSession();
private:
- IMAPStore* m_store;
+ weak_ref <IMAPStore> m_store;
- authenticator* m_auth;
+ ref <authenticator> m_auth;
- socket* m_socket;
+ ref <socket> m_socket;
- IMAPParser* m_parser;
+ ref <IMAPParser> m_parser;
- IMAPTag* m_tag;
+ ref <IMAPTag> m_tag;
char m_hierarchySeparator;
ProtocolStates m_state;
- timeoutHandler* m_timeoutHandler;
+ ref <timeoutHandler> m_timeoutHandler;
void internalDisconnect();
diff --git a/vmime/messaging/imap/IMAPFolder.hpp b/vmime/messaging/imap/IMAPFolder.hpp
index 128fea3c..0d803a7f 100644
--- a/vmime/messaging/imap/IMAPFolder.hpp
+++ b/vmime/messaging/imap/IMAPFolder.hpp
@@ -48,6 +48,7 @@ private:
friend class IMAPStore;
friend class IMAPMessage;
+ friend class vmime::creator; // vmime::create <IMAPFolder>
IMAPFolder(const folder::path& path, IMAPStore* store, const int type = TYPE_UNDEFINED, const int flags = FLAG_UNDEFINED);
@@ -74,13 +75,13 @@ public:
const bool isOpen() const;
- message* getMessage(const int num);
- std::vector <message*> getMessages(const int from = 1, const int to = -1);
- std::vector <message*> getMessages(const std::vector <int>& nums);
+ ref <message> getMessage(const int num);
+ std::vector <ref <message> > getMessages(const int from = 1, const int to = -1);
+ std::vector <ref <message> > getMessages(const std::vector <int>& nums);
const int getMessageCount();
- folder* getFolder(const folder::path::component& name);
- std::vector <folder*> getFolders(const bool recursive = false);
+ ref <folder> getFolder(const folder::path::component& name);
+ std::vector <ref <folder> > getFolders(const bool recursive = false);
void rename(const folder::path& newPath);
@@ -91,7 +92,7 @@ public:
void setMessageFlags(const int from, const int to, const int flags, const int mode = message::FLAG_MODE_SET);
void setMessageFlags(const std::vector <int>& nums, const int flags, const int mode = message::FLAG_MODE_SET);
- void addMessage(vmime::message* msg, const int flags = message::FLAG_UNDEFINED, vmime::datetime* date = NULL, utility::progressionListener* progress = NULL);
+ void addMessage(ref <vmime::message> msg, const int flags = message::FLAG_UNDEFINED, vmime::datetime* date = NULL, utility::progressionListener* progress = NULL);
void addMessage(utility::inputStream& is, const int size, const int flags = message::FLAG_UNDEFINED, vmime::datetime* date = NULL, utility::progressionListener* progress = NULL);
void copyMessage(const folder::path& dest, const int num);
@@ -102,14 +103,14 @@ public:
void expunge();
- folder* getParent();
+ ref <folder> getParent();
- const store* getStore() const;
- store* getStore();
+ weak_ref <const store> getStore() const;
+ weak_ref <store> getStore();
- void fetchMessages(std::vector <message*>& msg, const int options, utility::progressionListener* progress = NULL);
- void fetchMessage(message* msg, const int options);
+ void fetchMessages(std::vector <ref <message> >& msg, const int options, utility::progressionListener* progress = NULL);
+ void fetchMessage(ref <message> msg, const int options);
const int getFetchCapabilities() const;
@@ -130,7 +131,7 @@ private:
IMAPStore* m_store;
- IMAPConnection* m_connection;
+ ref <IMAPConnection> m_connection;
folder::path m_path;
folder::path::component m_name;
diff --git a/vmime/messaging/imap/IMAPMessage.hpp b/vmime/messaging/imap/IMAPMessage.hpp
index 43199110..33e43fec 100644
--- a/vmime/messaging/imap/IMAPMessage.hpp
+++ b/vmime/messaging/imap/IMAPMessage.hpp
@@ -43,6 +43,7 @@ class IMAPMessage : public message
private:
friend class IMAPFolder;
+ friend class vmime::creator; // vmime::create <IMAPMessage>
IMAPMessage(IMAPFolder* folder, const int num);
IMAPMessage(const IMAPMessage&) : message() { }
@@ -97,8 +98,8 @@ private:
bool m_expunged;
uid m_uid;
- header* m_header;
- structure* m_structure;
+ ref <header> m_header;
+ ref <structure> m_structure;
};
diff --git a/vmime/messaging/imap/IMAPParser.hpp b/vmime/messaging/imap/IMAPParser.hpp
index 98deac3a..205644de 100644
--- a/vmime/messaging/imap/IMAPParser.hpp
+++ b/vmime/messaging/imap/IMAPParser.hpp
@@ -74,18 +74,18 @@ namespace imap {
#endif
-class IMAPParser
+class IMAPParser : public object
{
public:
- IMAPParser(IMAPTag* tag, socket* sok, timeoutHandler* _timeoutHandler)
+ IMAPParser(weak_ref <IMAPTag> tag, weak_ref <socket> sok, weak_ref <timeoutHandler> _timeoutHandler)
: m_tag(tag), m_socket(sok), m_progress(NULL),
m_literalHandler(NULL), m_timeoutHandler(_timeoutHandler)
{
}
- const IMAPTag* tag() const
+ weak_ref <const IMAPTag> tag() const
{
return (m_tag);
}
@@ -4914,14 +4914,14 @@ public:
private:
- IMAPTag* m_tag;
- socket* m_socket;
+ weak_ref <IMAPTag> m_tag;
+ weak_ref <socket> m_socket;
utility::progressionListener* m_progress;
literalHandler* m_literalHandler;
- timeoutHandler* m_timeoutHandler;
+ weak_ref <timeoutHandler> m_timeoutHandler;
string m_buffer;
diff --git a/vmime/messaging/imap/IMAPStore.hpp b/vmime/messaging/imap/IMAPStore.hpp
index 59689b87..227a0f27 100644
--- a/vmime/messaging/imap/IMAPStore.hpp
+++ b/vmime/messaging/imap/IMAPStore.hpp
@@ -52,14 +52,14 @@ class IMAPStore : public store
public:
- IMAPStore(session* sess, authenticator* auth);
+ IMAPStore(ref <session> sess, ref <authenticator> auth);
~IMAPStore();
const string getProtocolName() const;
- folder* getDefaultFolder();
- folder* getRootFolder();
- folder* getFolder(const folder::path& path);
+ ref <folder> getDefaultFolder();
+ ref <folder> getRootFolder();
+ ref <folder> getFolder(const folder::path& path);
const bool isValidFolderName(const folder::path::component& name) const;
@@ -77,18 +77,18 @@ public:
private:
// Connection
- IMAPConnection* m_connection;
+ ref <IMAPConnection> m_connection;
// Used to request the authentication informations only the
// first time, and reuse these informations the next time.
- class authenticator* m_oneTimeAuth;
+ ref <class authenticator> m_oneTimeAuth;
- class authenticator* oneTimeAuthenticator();
+ ref <class authenticator> oneTimeAuthenticator();
- IMAPConnection* connection();
+ ref <IMAPConnection> connection();
void registerFolder(IMAPFolder* folder);
diff --git a/vmime/messaging/imap/IMAPTag.hpp b/vmime/messaging/imap/IMAPTag.hpp
index da9569ac..526efb74 100644
--- a/vmime/messaging/imap/IMAPTag.hpp
+++ b/vmime/messaging/imap/IMAPTag.hpp
@@ -29,7 +29,7 @@ namespace messaging {
namespace imap {
-class IMAPTag
+class IMAPTag : public object
{
private:
diff --git a/vmime/messaging/maildir/maildirFolder.hpp b/vmime/messaging/maildir/maildirFolder.hpp
index 106337c1..e7702673 100644
--- a/vmime/messaging/maildir/maildirFolder.hpp
+++ b/vmime/messaging/maildir/maildirFolder.hpp
@@ -49,9 +49,10 @@ private:
friend class maildirStore;
friend class maildirMessage;
+ friend class vmime::creator; // vmime::create <maildirFolder>
- maildirFolder(const folder::path& path, maildirStore* store);
+ maildirFolder(const folder::path& path, weak_ref <maildirStore> store);
maildirFolder(const maildirFolder&) : folder() { }
~maildirFolder();
@@ -75,13 +76,13 @@ public:
const bool isOpen() const;
- message* getMessage(const int num);
- std::vector <message*> getMessages(const int from = 1, const int to = -1);
- std::vector <message*> getMessages(const std::vector <int>& nums);
+ ref <message> getMessage(const int num);
+ std::vector <ref <message> > getMessages(const int from = 1, const int to = -1);
+ std::vector <ref <message> > getMessages(const std::vector <int>& nums);
const int getMessageCount();
- folder* getFolder(const folder::path::component& name);
- std::vector <folder*> getFolders(const bool recursive = false);
+ ref <folder> getFolder(const folder::path::component& name);
+ std::vector <ref <folder> > getFolders(const bool recursive = false);
void rename(const folder::path& newPath);
@@ -92,7 +93,7 @@ public:
void setMessageFlags(const int from, const int to, const int flags, const int mode = message::FLAG_MODE_SET);
void setMessageFlags(const std::vector <int>& nums, const int flags, const int mode = message::FLAG_MODE_SET);
- void addMessage(vmime::message* msg, const int flags = message::FLAG_UNDEFINED, vmime::datetime* date = NULL, utility::progressionListener* progress = NULL);
+ void addMessage(ref <vmime::message> msg, const int flags = message::FLAG_UNDEFINED, vmime::datetime* date = NULL, utility::progressionListener* progress = NULL);
void addMessage(utility::inputStream& is, const int size, const int flags = message::FLAG_UNDEFINED, vmime::datetime* date = NULL, utility::progressionListener* progress = NULL);
void copyMessage(const folder::path& dest, const int num);
@@ -103,14 +104,14 @@ public:
void expunge();
- folder* getParent();
+ ref <folder> getParent();
- const store* getStore() const;
- store* getStore();
+ weak_ref <const store> getStore() const;
+ weak_ref <store> getStore();
- void fetchMessages(std::vector <message*>& msg, const int options, utility::progressionListener* progress = NULL);
- void fetchMessage(message* msg, const int options);
+ void fetchMessages(std::vector <ref <message> >& msg, const int options, utility::progressionListener* progress = NULL);
+ void fetchMessage(ref <message> msg, const int options);
const int getFetchCapabilities() const;
@@ -118,12 +119,12 @@ private:
void scanFolder();
- void listFolders(std::vector <folder*>& list, const bool recursive);
+ void listFolders(std::vector <ref <folder> >& list, const bool recursive);
void registerMessage(maildirMessage* msg);
void unregisterMessage(maildirMessage* msg);
- const utility::file::path getMessageFSPath(const int number);
+ const utility::file::path getMessageFSPath(const int number) const;
void onStoreDisconnected();
@@ -138,7 +139,7 @@ private:
void notifyMessagesCopied(const folder::path& dest);
- maildirStore* m_store;
+ weak_ref <maildirStore> m_store;
folder::path m_path;
folder::path::component m_name;
diff --git a/vmime/messaging/maildir/maildirMessage.hpp b/vmime/messaging/maildir/maildirMessage.hpp
index 6eb8a7d2..c3e2e377 100644
--- a/vmime/messaging/maildir/maildirMessage.hpp
+++ b/vmime/messaging/maildir/maildirMessage.hpp
@@ -39,10 +39,11 @@ class maildirFolder;
class maildirMessage : public message
{
friend class maildirFolder;
+ friend class vmime::creator; // vmime::create <maildirMessage>
private:
- maildirMessage(maildirFolder* folder, const int num);
+ maildirMessage(weak_ref <maildirFolder> folder, const int num);
maildirMessage(const maildirMessage&) : message() { }
~maildirMessage();
@@ -72,7 +73,7 @@ public:
private:
- void fetch(maildirFolder* folder, const int options);
+ void fetch(weak_ref <maildirFolder> folder, const int options);
void onFolderClosed();
@@ -81,7 +82,7 @@ private:
void extractImpl(utility::outputStream& os, utility::progressionListener* progress, const int start, const int length, const int partialStart, const int partialLength, const bool peek) const;
- maildirFolder* m_folder;
+ weak_ref <maildirFolder> m_folder;
int m_num;
int m_size;
@@ -89,8 +90,8 @@ private:
bool m_expunged;
uid m_uid;
- header* m_header;
- structure* m_structure;
+ ref <header> m_header;
+ ref <structure> m_structure;
};
diff --git a/vmime/messaging/maildir/maildirStore.hpp b/vmime/messaging/maildir/maildirStore.hpp
index 25007e09..23c667a4 100644
--- a/vmime/messaging/maildir/maildirStore.hpp
+++ b/vmime/messaging/maildir/maildirStore.hpp
@@ -49,14 +49,14 @@ class maildirStore : public store
public:
- maildirStore(session* sess, authenticator* auth);
+ maildirStore(ref <session> sess, ref <authenticator> auth);
~maildirStore();
const string getProtocolName() const;
- folder* getDefaultFolder();
- folder* getRootFolder();
- folder* getFolder(const folder::path& path);
+ ref <folder> getDefaultFolder();
+ ref <folder> getRootFolder();
+ ref <folder> getFolder(const folder::path& path);
const bool isValidFolderName(const folder::path::component& name) const;
diff --git a/vmime/messaging/maildir/maildirUtils.hpp b/vmime/messaging/maildir/maildirUtils.hpp
index 583cdc6b..8f322d92 100644
--- a/vmime/messaging/maildir/maildirUtils.hpp
+++ b/vmime/messaging/maildir/maildirUtils.hpp
@@ -73,7 +73,8 @@ public:
* @param mode type of path to return (see FolderFSPathMode)
* @return filesystem path for the specified folder
*/
- static const utility::file::path getFolderFSPath(maildirStore* store, const utility::path& folderPath, const FolderFSPathMode mode);
+ static const utility::file::path getFolderFSPath(weak_ref <maildirStore> store,
+ const utility::path& folderPath, const FolderFSPathMode mode);
/** Test whether the specified file-system directory corresponds to
* a maildir sub-folder. The name of the directory should not start
diff --git a/vmime/messaging/message.hpp b/vmime/messaging/message.hpp
index b423e039..3f87f8f5 100644
--- a/vmime/messaging/message.hpp
+++ b/vmime/messaging/message.hpp
@@ -37,12 +37,12 @@ class structure;
/** A MIME part in a message.
*/
-class part
+class part : public object
{
protected:
part() { }
- part(const part&) { }
+ part(const part&) : object() { }
virtual ~part() { }
@@ -114,12 +114,12 @@ public:
/** Structure of a MIME part/message.
*/
-class structure
+class structure : public object
{
protected:
structure() { }
- structure(const structure&) { }
+ structure(const structure&) : object() { }
public:
@@ -152,12 +152,12 @@ public:
/** Abstract representation of a message in a store/transport service.
*/
-class message
+class message : public object
{
protected:
message() { }
- message(const message&) { }
+ message(const message&) : object() { }
public:
diff --git a/vmime/messaging/pop3/POP3Folder.hpp b/vmime/messaging/pop3/POP3Folder.hpp
index 8cfe12db..bb29f858 100644
--- a/vmime/messaging/pop3/POP3Folder.hpp
+++ b/vmime/messaging/pop3/POP3Folder.hpp
@@ -48,6 +48,7 @@ private:
friend class POP3Store;
friend class POP3Message;
+ friend class vmime::creator; // vmime::create <POP3Folder>
POP3Folder(const folder::path& path, POP3Store* store);
POP3Folder(const POP3Folder&) : folder() { }
@@ -73,13 +74,13 @@ public:
const bool isOpen() const;
- message* getMessage(const int num);
- std::vector <message*> getMessages(const int from = 1, const int to = -1);
- std::vector <message*> getMessages(const std::vector <int>& nums);
+ ref <message> getMessage(const int num);
+ std::vector <ref <message> > getMessages(const int from = 1, const int to = -1);
+ std::vector <ref <message> > getMessages(const std::vector <int>& nums);
const int getMessageCount();
- folder* getFolder(const folder::path::component& name);
- std::vector <folder*> getFolders(const bool recursive = false);
+ ref <folder> getFolder(const folder::path::component& name);
+ std::vector <ref <folder> > getFolders(const bool recursive = false);
void rename(const folder::path& newPath);
@@ -90,7 +91,7 @@ public:
void setMessageFlags(const int from, const int to, const int flags, const int mode = message::FLAG_MODE_SET);
void setMessageFlags(const std::vector <int>& nums, const int flags, const int mode = message::FLAG_MODE_SET);
- void addMessage(vmime::message* msg, const int flags = message::FLAG_UNDEFINED, vmime::datetime* date = NULL, utility::progressionListener* progress = NULL);
+ void addMessage(ref <vmime::message> msg, const int flags = message::FLAG_UNDEFINED, vmime::datetime* date = NULL, utility::progressionListener* progress = NULL);
void addMessage(utility::inputStream& is, const int size, const int flags = message::FLAG_UNDEFINED, vmime::datetime* date = NULL, utility::progressionListener* progress = NULL);
void copyMessage(const folder::path& dest, const int num);
@@ -101,14 +102,14 @@ public:
void expunge();
- folder* getParent();
+ ref <folder> getParent();
- const store* getStore() const;
- store* getStore();
+ weak_ref <const store> getStore() const;
+ weak_ref <store> getStore();
- void fetchMessages(std::vector <message*>& msg, const int options, utility::progressionListener* progress = NULL);
- void fetchMessage(message* msg, const int options);
+ void fetchMessages(std::vector <ref <message> >& msg, const int options, utility::progressionListener* progress = NULL);
+ void fetchMessage(ref <message> msg, const int options);
const int getFetchCapabilities() const;
diff --git a/vmime/messaging/pop3/POP3Message.hpp b/vmime/messaging/pop3/POP3Message.hpp
index 55475cc1..499f3427 100644
--- a/vmime/messaging/pop3/POP3Message.hpp
+++ b/vmime/messaging/pop3/POP3Message.hpp
@@ -43,6 +43,7 @@ class POP3Message : public message
private:
friend class POP3Folder;
+ friend class vmime::creator; // vmime::create <POP3Message>
POP3Message(POP3Folder* folder, const int num);
POP3Message(const POP3Message&) : message() { }
diff --git a/vmime/messaging/pop3/POP3Store.hpp b/vmime/messaging/pop3/POP3Store.hpp
index 2de892cc..3ff291ea 100644
--- a/vmime/messaging/pop3/POP3Store.hpp
+++ b/vmime/messaging/pop3/POP3Store.hpp
@@ -46,18 +46,16 @@ class POP3Store : public store
friend class POP3Folder;
friend class POP3Message;
-private:
-
public:
- POP3Store(session* sess, authenticator* auth);
+ POP3Store(ref <session> sess, ref <authenticator> auth);
~POP3Store();
const string getProtocolName() const;
- folder* getDefaultFolder();
- folder* getRootFolder();
- folder* getFolder(const folder::path& path);
+ ref <folder> getDefaultFolder();
+ ref <folder> getRootFolder();
+ ref <folder> getFolder(const folder::path& path);
const bool isValidFolderName(const folder::path::component& name) const;
@@ -94,10 +92,10 @@ private:
std::list <POP3Folder*> m_folders;
- socket* m_socket;
+ ref <socket> m_socket;
bool m_authentified;
- timeoutHandler* m_timeoutHandler;
+ ref <timeoutHandler> m_timeoutHandler;
// Service infos
diff --git a/vmime/messaging/sendmail/sendmailTransport.hpp b/vmime/messaging/sendmail/sendmailTransport.hpp
index accf45b9..c63a6fac 100644
--- a/vmime/messaging/sendmail/sendmailTransport.hpp
+++ b/vmime/messaging/sendmail/sendmailTransport.hpp
@@ -43,7 +43,7 @@ class sendmailTransport : public transport
{
public:
- sendmailTransport(session* sess, authenticator* auth);
+ sendmailTransport(ref <session> sess, ref <authenticator> auth);
~sendmailTransport();
const string getProtocolName() const;
diff --git a/vmime/messaging/service.hpp b/vmime/messaging/service.hpp
index d0b710d7..9d2e76d9 100644
--- a/vmime/messaging/service.hpp
+++ b/vmime/messaging/service.hpp
@@ -39,11 +39,11 @@ namespace messaging {
/** Base class for messaging services.
*/
-class service
+class service : public object
{
protected:
- service(session* sess, const serviceInfos& infos, authenticator* auth);
+ service(ref <session> sess, const serviceInfos& infos, ref <authenticator> auth);
public:
@@ -72,13 +72,13 @@ public:
*
* @return session object
*/
- const session* getSession() const;
+ ref <const session> getSession() const;
/** Return the session object associated with this service instance.
*
* @return session object
*/
- session* getSession();
+ ref <session> getSession();
/** Return information about this service.
*
@@ -110,13 +110,13 @@ public:
*
* @return authenticator object
*/
- const authenticator* getAuthenticator() const;
+ ref <const authenticator> getAuthenticator() const;
/** Return the authenticator object used with this service instance.
*
* @return authenticator object
*/
- authenticator* getAuthenticator();
+ ref <authenticator> getAuthenticator();
/** Set a property for this service (service prefix is added automatically).
*
@@ -149,10 +149,8 @@ public:
private:
- bool m_deleteAuth;
-
- session* m_session;
- authenticator* m_auth;
+ ref <session> m_session;
+ ref <authenticator> m_auth;
};
diff --git a/vmime/messaging/serviceFactory.hpp b/vmime/messaging/serviceFactory.hpp
index 782e4c75..c7eff565 100644
--- a/vmime/messaging/serviceFactory.hpp
+++ b/vmime/messaging/serviceFactory.hpp
@@ -59,7 +59,7 @@ public:
static serviceFactory* getInstance();
/** Information about a registered service. */
- class registeredService
+ class registeredService : public object
{
friend class serviceFactory;
@@ -69,7 +69,7 @@ public:
public:
- virtual service* create(session* sess, authenticator* auth) const = 0;
+ virtual ref <service> create(ref <session> sess, ref <authenticator> auth) const = 0;
virtual const string& getName() const = 0;
virtual const serviceInfos& getInfos() const = 0;
@@ -81,6 +81,7 @@ private:
class registeredServiceImpl : public registeredService
{
friend class serviceFactory;
+ friend class vmime::creator;
protected:
@@ -91,9 +92,9 @@ private:
public:
- service* create(session* sess, authenticator* auth) const
+ ref <service> create(ref <session> sess, ref <authenticator> auth) const
{
- return new S(sess, auth);
+ return vmime::create <S>(sess, auth);
}
const serviceInfos& getInfos() const
@@ -112,7 +113,7 @@ private:
const serviceInfos& m_servInfos;
};
- std::vector <registeredService*> m_services;
+ std::vector <ref <registeredService> > m_services;
public:
@@ -124,7 +125,7 @@ public:
void registerServiceByProtocol(const string& protocol)
{
const string name = utility::stringUtils::toLower(protocol);
- m_services.push_back(new registeredServiceImpl <S>(name));
+ m_services.push_back(vmime::create <registeredServiceImpl <S> >(name));
}
/** Create a new service instance from a protocol name.
@@ -136,7 +137,7 @@ public:
* @throw exceptions::no_service_available if no service is registered
* for this protocol
*/
- service* create(session* sess, const string& protocol, authenticator* auth = NULL);
+ ref <service> create(ref <session> sess, const string& protocol, ref <authenticator> auth = NULL);
/** Create a new service instance from a URL.
*
@@ -148,7 +149,7 @@ public:
* @throw exceptions::no_service_available if no service is registered
* for this protocol
*/
- service* create(session* sess, const utility::url& u, authenticator* auth = NULL);
+ ref <service> create(ref <session> sess, const utility::url& u, ref <authenticator> auth = NULL);
/** Return information about a registered protocol.
*
@@ -157,7 +158,7 @@ public:
* @throw exceptions::no_service_available if no service is registered
* for this protocol
*/
- const registeredService* getServiceByProtocol(const string& protocol) const;
+ ref <const registeredService> getServiceByProtocol(const string& protocol) const;
/** Return the number of registered services.
*
@@ -170,13 +171,13 @@ public:
* @param pos position of the registered service to return
* @return registered service at the specified position
*/
- const registeredService* getServiceAt(const int pos) const;
+ ref <const registeredService> getServiceAt(const int pos) const;
/** Return a list of all registered services.
*
* @return list of registered services
*/
- const std::vector <const registeredService*> getServiceList() const;
+ const std::vector <ref <const registeredService> > getServiceList() const;
};
diff --git a/vmime/messaging/serviceInfos.hpp b/vmime/messaging/serviceInfos.hpp
index d812512e..bdfcd887 100644
--- a/vmime/messaging/serviceInfos.hpp
+++ b/vmime/messaging/serviceInfos.hpp
@@ -201,7 +201,7 @@ public:
* @return value of the property
*/
template <typename TYPE>
- const TYPE getPropertyValue(session* s, const property& p) const
+ const TYPE getPropertyValue(ref <session> s, const property& p) const
{
if (p.getFlags() & property::FLAG_REQUIRED)
return s->getProperties()[getPropertyPrefix() + p.getName()].template getValue <TYPE>();
@@ -217,7 +217,7 @@ public:
* @param p property to test
* @return true if the property is set, false otherwise
*/
- const bool hasProperty(session* s, const property& p) const;
+ const bool hasProperty(ref <session> s, const property& p) const;
};
diff --git a/vmime/messaging/session.hpp b/vmime/messaging/session.hpp
index bce4a2c0..e2b92634 100644
--- a/vmime/messaging/session.hpp
+++ b/vmime/messaging/session.hpp
@@ -40,11 +40,12 @@ class transport;
* for connection to a service.
*/
-class session
+class session : public object
{
public:
session();
+ session(const session& sess);
session(const propertySet& props);
virtual ~session();
@@ -59,7 +60,7 @@ public:
* credentials by reading the session properties "auth.username" and "auth.password".
* @return a new transport service
*/
- transport* getTransport(authenticator* auth = NULL);
+ ref <transport> getTransport(ref <authenticator> auth = NULL);
/** Return a transport service instance for the specified protocol.
*
@@ -69,7 +70,7 @@ public:
* credentials by reading the session properties "auth.username" and "auth.password".
* @return a new transport service
*/
- transport* getTransport(const string& protocol, authenticator* auth = NULL);
+ ref <transport> getTransport(const string& protocol, ref <authenticator> auth = NULL);
/** Return a transport service instance for the specified URL.
*
@@ -79,7 +80,7 @@ public:
* credentials by reading the session properties "auth.username" and "auth.password".
* @return a new transport service
*/
- transport* getTransport(const utility::url& url, authenticator* auth = NULL);
+ ref <transport> getTransport(const utility::url& url, ref <authenticator> auth = NULL);
/** Return a transport service instance for the protocol specified
* in the session properties.
@@ -91,7 +92,7 @@ public:
* credentials by reading the session properties "auth.username" and "auth.password".
* @return a new store service
*/
- store* getStore(authenticator* auth = NULL);
+ ref <store> getStore(ref <authenticator> auth = NULL);
/** Return a store service instance for the specified protocol.
*
@@ -101,7 +102,7 @@ public:
* credentials by reading the session properties "auth.username" and "auth.password".
* @return a new store service
*/
- store* getStore(const string& protocol, authenticator* auth = NULL);
+ ref <store> getStore(const string& protocol, ref <authenticator> auth = NULL);
/** Return a store service instance for the specified URL.
*
@@ -111,7 +112,7 @@ public:
* credentials by reading the session properties "auth.username" and "auth.password".
* @return a new store service
*/
- store* getStore(const utility::url& url, authenticator* auth = NULL);
+ ref <store> getStore(const utility::url& url, ref <authenticator> auth = NULL);
/** Properties for the session and for the services.
*/
diff --git a/vmime/messaging/smtp/SMTPTransport.hpp b/vmime/messaging/smtp/SMTPTransport.hpp
index 61a5a7fe..191d134c 100644
--- a/vmime/messaging/smtp/SMTPTransport.hpp
+++ b/vmime/messaging/smtp/SMTPTransport.hpp
@@ -40,7 +40,7 @@ class SMTPTransport : public transport
{
public:
- SMTPTransport(session* sess, authenticator* auth);
+ SMTPTransport(ref <session> sess, ref <authenticator> auth);
~SMTPTransport();
const string getProtocolName() const;
@@ -67,11 +67,11 @@ private:
void internalDisconnect();
- socket* m_socket;
+ ref <socket> m_socket;
bool m_authentified;
bool m_extendedSMTP;
- timeoutHandler* m_timeoutHandler;
+ ref <timeoutHandler> m_timeoutHandler;
// Service infos
diff --git a/vmime/messaging/socket.hpp b/vmime/messaging/socket.hpp
index dbbed819..dc5cdad9 100644
--- a/vmime/messaging/socket.hpp
+++ b/vmime/messaging/socket.hpp
@@ -31,7 +31,7 @@ namespace messaging {
/** Interface for connecting to servers.
*/
-class socket
+class socket : public object
{
public:
@@ -81,6 +81,14 @@ public:
* @param count number of bytes to send (size of buffer)
*/
virtual void sendRaw(const char* buffer, const int count) = 0;
+
+protected:
+
+ socket() { }
+
+private:
+
+ socket(const socket&) : object() { }
};
@@ -93,7 +101,7 @@ public:
virtual ~socketFactory() { }
- virtual socket* create() = 0;
+ virtual ref <socket> create() = 0;
};
diff --git a/vmime/messaging/store.hpp b/vmime/messaging/store.hpp
index 6b5d8be7..68dfaf98 100644
--- a/vmime/messaging/store.hpp
+++ b/vmime/messaging/store.hpp
@@ -37,7 +37,7 @@ class store : public service
{
protected:
- store(session* sess, const serviceInfos& infos, authenticator* auth)
+ store(ref <session> sess, const serviceInfos& infos, ref <authenticator> auth)
: service(sess, infos, auth) { }
public:
@@ -47,21 +47,21 @@ public:
*
* @return default folder
*/
- virtual folder* getDefaultFolder() = 0;
+ virtual ref <folder> getDefaultFolder() = 0;
/** Return the root folder. This is protocol dependant
* and usually is the user's mail drop root folder.
*
* @return root folder
*/
- virtual folder* getRootFolder() = 0;
+ virtual ref <folder> getRootFolder() = 0;
/** Return the folder specified by the path.
*
* @param path absolute folder path
* @return folder at the specified path
*/
- virtual folder* getFolder(const folder::path& path) = 0;
+ virtual ref <folder> getFolder(const folder::path& path) = 0;
/** Test whether the specified folder name is a syntactically
* a valid name.
diff --git a/vmime/messaging/timeoutHandler.hpp b/vmime/messaging/timeoutHandler.hpp
index 79af504e..75d333e0 100644
--- a/vmime/messaging/timeoutHandler.hpp
+++ b/vmime/messaging/timeoutHandler.hpp
@@ -21,6 +21,9 @@
#define VMIME_MESSAGING_TIMEOUTHANDLER_HPP_INCLUDED
+#include "vmime/types.hpp"
+
+
namespace vmime {
namespace messaging {
@@ -28,7 +31,7 @@ namespace messaging {
/** A class to manage time-out in messaging services.
*/
-class timeoutHandler
+class timeoutHandler : public object
{
public:
@@ -63,7 +66,7 @@ public:
virtual ~timeoutHandlerFactory() { }
- virtual timeoutHandler* create() = 0;
+ virtual ref <timeoutHandler> create() = 0;
};
diff --git a/vmime/messaging/transport.hpp b/vmime/messaging/transport.hpp
index 272fdb32..8f499154 100644
--- a/vmime/messaging/transport.hpp
+++ b/vmime/messaging/transport.hpp
@@ -42,7 +42,7 @@ class transport : public service
{
protected:
- transport(session* sess, const serviceInfos& infos, authenticator* auth);
+ transport(ref <session> sess, const serviceInfos& infos, ref <authenticator> auth);
public:
@@ -51,7 +51,7 @@ public:
* @param msg message to send
* @param progress progression listener, or NULL if not used
*/
- virtual void send(vmime::message* msg, utility::progressionListener* progress = NULL);
+ virtual void send(ref <vmime::message> msg, utility::progressionListener* progress = NULL);
/** Send a message over this transport service.
*
diff --git a/vmime/misc/importanceHelper.hpp b/vmime/misc/importanceHelper.hpp
index d450defb..b9118659 100644
--- a/vmime/misc/importanceHelper.hpp
+++ b/vmime/misc/importanceHelper.hpp
@@ -54,7 +54,7 @@ public:
*
* @param msg message on which to reset importance
*/
- static void resetImportance(message* msg);
+ static void resetImportance(ref <message> msg);
/** Return the importance of the specified message.
*
@@ -62,14 +62,14 @@ public:
* @return importance of the message, or default importance is no
* information about importance is given in the message
*/
- static const Importance getImportance(const message* msg);
+ static const Importance getImportance(const ref <const message> msg);
/** Set the importance of the specified message.
*
* @param msg message on which to set importance
* @param i new message importance
*/
- static void setImportance(message* msg, const Importance i);
+ static void setImportance(ref <message> msg, const Importance i);
};
diff --git a/vmime/object.hpp b/vmime/object.hpp
new file mode 100644
index 00000000..b8024e56
--- /dev/null
+++ b/vmime/object.hpp
@@ -0,0 +1,108 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2005 Vincent Richard <[email protected]>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of
+// the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+//
+
+#ifndef VMIME_OBJECT_HPP_INCLUDED
+#define VMIME_OBJECT_HPP_INCLUDED
+
+
+#include <vector>
+
+
+namespace vmime
+{
+
+
+/** Base object for all objects in the library. This implements
+ * reference counting and auto-deletion.
+ */
+
+class object
+{
+ template <class T> friend class utility::ref;
+ template <class T> friend class utility::weak_ref;
+
+protected:
+
+ object();
+ object(const object&);
+
+ virtual ~object();
+
+#ifndef VMIME_BUILDING_DOC
+
+ /** Add a strong reference to this object. A strong
+ * reference ensure the object remains alive.
+ */
+ void addStrong() const;
+
+ /** Add a weak reference to this object. A weak
+ * reference helps to resolve circular references.
+ */
+ void addWeak(utility::weak_ref_base* w) const;
+
+ /** Release a strong reference to this object.
+ *
+ * @return true if the object is not referenced anymore.
+ */
+ void releaseStrong() const;
+
+ /** Release a weak reference to this object.
+ *
+ * @return true if the object is not referenced anymore.
+ */
+ void releaseWeak(utility::weak_ref_base* w) const;
+
+ /** Return a reference to this object.
+ *
+ * @return reference to self
+ */
+ ref <object> thisRef();
+
+ /** Return a reference to this object (const version).
+ *
+ * @return reference to self
+ */
+ ref <const object> thisRef() const;
+
+ /** Return a weak reference to this object.
+ *
+ * @return weak reference to self
+ */
+ weak_ref <object> thisWeakRef();
+
+ /** Return a weak reference to this object (const version).
+ *
+ * @return weak reference to self
+ */
+ weak_ref <const object> thisWeakRef() const;
+
+#endif // VMIME_BUILDING_DOC
+
+private:
+
+ mutable int m_strongCount;
+ mutable std::vector <utility::weak_ref_base*> m_weakRefs;
+};
+
+
+} // vmime
+
+
+#endif // VMIME_OBJECT_HPP_INCLUDED
+
diff --git a/vmime/parameter.hpp b/vmime/parameter.hpp
index b62c87ab..9c5df03b 100644
--- a/vmime/parameter.hpp
+++ b/vmime/parameter.hpp
@@ -50,11 +50,11 @@ public:
#endif // VMIME_BUILDING_DOC
- parameter* clone() const;
+ ref <component> clone() const;
void copyFrom(const component& other);
parameter& operator=(const parameter& other);
- const std::vector <const component*> getChildComponents() const;
+ const std::vector <ref <const component> > getChildComponents() const;
/** Return the name of the parameter.
*
@@ -88,6 +88,11 @@ public:
void parse(const string& buffer, const string::size_type position, const string::size_type end, string::size_type* newPosition = NULL);
void generate(utility::outputStream& os, const string::size_type maxLineLength = lineLengthLimits::infinite, const string::size_type curLinePos = 0, string::size_type* newLinePos = NULL) const;
+protected:
+
+ virtual const ref <const component> getValueImp() const = 0;
+ virtual const ref <component> getValueImp() = 0;
+
private:
string m_name;
diff --git a/vmime/parameterFactory.hpp b/vmime/parameterFactory.hpp
index 28d8cbdb..e2daf731 100644
--- a/vmime/parameterFactory.hpp
+++ b/vmime/parameterFactory.hpp
@@ -36,7 +36,7 @@ protected:
parameterFactory();
~parameterFactory();
- typedef parameter* (*AllocFunc)(void);
+ typedef ref <parameter> (*AllocFunc)(void);
typedef std::map <string, AllocFunc> NameMap;
NameMap m_nameMap;
@@ -51,10 +51,10 @@ public:
{
public:
- static parameter* creator()
+ static ref <parameter> creator()
{
// Allocate a new object
- return new TYPE();
+ return vmime::create <TYPE>();
}
};
#endif // VMIME_BUILDING_DOC
@@ -74,7 +74,7 @@ public:
* @param value value to be parsed
* @return created parameter
*/
- parameter* create(const string& name, const string& value = NULL_STRING);
+ ref <parameter> create(const string& name, const string& value = NULL_STRING);
/** Create a new parameter and set its value. The returned parameter
* can then be added in a vmime::parameterizedHeaderField object.
@@ -83,7 +83,7 @@ public:
* @param value value to be set
* @return created parameter
*/
- parameter* create(const string& name, const component& value);
+ ref <parameter> create(const string& name, const component& value);
};
diff --git a/vmime/parameterizedHeaderField.hpp b/vmime/parameterizedHeaderField.hpp
index 02645eb8..aadacd08 100644
--- a/vmime/parameterizedHeaderField.hpp
+++ b/vmime/parameterizedHeaderField.hpp
@@ -64,7 +64,7 @@ public:
* @throw exceptions::no_such_parameter if no parameter with this name exists
* @return first parameter with the specified name
*/
- parameter* findParameter(const string& paramName) const;
+ ref <parameter> findParameter(const string& paramName) const;
/** Find the first parameter that matches the specified name.
* If no parameter is found, one will be created and inserted into
@@ -73,13 +73,13 @@ public:
* @return first parameter with the specified name or a new field
* if no parameter is found
*/
- parameter* getParameter(const string& paramName);
+ ref <parameter> getParameter(const string& paramName);
/** Add a parameter at the end of the list.
*
* @param param parameter to append
*/
- void appendParameter(parameter* param);
+ void appendParameter(ref <parameter> param);
/** Insert a new parameter before the specified parameter.
*
@@ -87,7 +87,7 @@ public:
* @param param parameter to insert
* @throw exceptions::no_such_parameter if the parameter is not in the list
*/
- void insertParameterBefore(parameter* beforeParam, parameter* param);
+ void insertParameterBefore(ref <parameter> beforeParam, ref <parameter> param);
/** Insert a new parameter before the specified position.
*
@@ -95,7 +95,7 @@ public:
* the beginning of the list)
* @param param parameter to insert
*/
- void insertParameterBefore(const int pos, parameter* param);
+ void insertParameterBefore(const int pos, ref <parameter> param);
/** Insert a new parameter after the specified parameter.
*
@@ -103,21 +103,21 @@ public:
* @param param parameter to insert
* @throw exceptions::no_such_parameter if the parameter is not in the list
*/
- void insertParameterAfter(parameter* afterParam, parameter* param);
+ void insertParameterAfter(ref <parameter> afterParam, ref <parameter> param);
/** Insert a new parameter after the specified position.
*
* @param pos position of the parameter before the new parameter
* @param param parameter to insert
*/
- void insertParameterAfter(const int pos, parameter* param);
+ void insertParameterAfter(const int pos, ref <parameter> param);
/** Remove the specified parameter from the list.
*
* @param param parameter to remove
* @throw exceptions::no_such_parameter if the parameter is not in the list
*/
- void removeParameter(parameter* param);
+ void removeParameter(ref <parameter> param);
/** Remove the parameter at the specified position.
*
@@ -146,30 +146,30 @@ public:
* @param pos position
* @return parameter at position 'pos'
*/
- parameter* getParameterAt(const int pos);
+ const ref <parameter> getParameterAt(const int pos);
/** Return the parameter at the specified position.
*
* @param pos position
* @return parameter at position 'pos'
*/
- const parameter* getParameterAt(const int pos) const;
+ const ref <parameter> getParameterAt(const int pos) const;
/** Return the parameter list.
*
* @return list of parameters
*/
- const std::vector <const parameter*> getParameterList() const;
+ const std::vector <ref <const parameter> > getParameterList() const;
/** Return the parameter list.
*
* @return list of parameters
*/
- const std::vector <parameter*> getParameterList();
+ const std::vector <ref <parameter> > getParameterList();
private:
- std::vector <parameter*> m_params;
+ std::vector <ref <parameter> > m_params;
public:
@@ -179,7 +179,7 @@ public:
void parse(const string& buffer, const string::size_type position, const string::size_type end, string::size_type* newPosition = NULL);
void generate(utility::outputStream& os, const string::size_type maxLineLength = lineLengthLimits::infinite, const string::size_type curLinePos = 0, string::size_type* newLinePos = NULL) const;
- const std::vector <const component*> getChildComponents() const;
+ const std::vector <ref <const component> > getChildComponents() const;
};
diff --git a/vmime/path.hpp b/vmime/path.hpp
index 5e50feb9..4559a554 100644
--- a/vmime/path.hpp
+++ b/vmime/path.hpp
@@ -69,10 +69,10 @@ public:
// Assignment
void copyFrom(const component& other);
- path* clone() const;
+ ref <component> clone() const;
path& operator=(const path& other);
- const std::vector <const component*> getChildComponents() const;
+ const std::vector <ref <const component> > getChildComponents() const;
protected:
diff --git a/vmime/plainTextPart.hpp b/vmime/plainTextPart.hpp
index fd5b3e02..a8be4d84 100644
--- a/vmime/plainTextPart.hpp
+++ b/vmime/plainTextPart.hpp
@@ -43,12 +43,12 @@ public:
const charset& getCharset() const;
void setCharset(const charset& ch);
- const contentHandler& getText() const;
- void setText(const contentHandler& text);
+ const ref <const contentHandler> getText() const;
+ void setText(ref <contentHandler> text);
private:
- contentHandler* m_text;
+ ref <contentHandler> m_text;
charset m_charset;
const int getPartCount() const;
diff --git a/vmime/platforms/posix/posixChildProcess.hpp b/vmime/platforms/posix/posixChildProcess.hpp
index 21c79133..517bf9b3 100644
--- a/vmime/platforms/posix/posixChildProcess.hpp
+++ b/vmime/platforms/posix/posixChildProcess.hpp
@@ -41,8 +41,8 @@ public:
void start(const std::vector <string> args, const int flags = 0);
- utility::outputStream* getStdIn();
- utility::inputStream* getStdOut();
+ ref <utility::outputStream> getStdIn();
+ ref <utility::inputStream> getStdOut();
void waitForFinish();
@@ -51,8 +51,8 @@ private:
utility::file::path m_processPath;
bool m_started;
- utility::outputStream* m_stdIn;
- utility::inputStream* m_stdOut;
+ ref <utility::outputStream> m_stdIn;
+ ref <utility::inputStream> m_stdOut;
sigset_t m_oldProcMask;
pid_t m_pid;
@@ -67,7 +67,7 @@ class posixChildProcessFactory : public utility::childProcessFactory
{
public:
- utility::childProcess* create(const utility::file::path& path) const;
+ ref <utility::childProcess> create(const utility::file::path& path) const;
};
diff --git a/vmime/platforms/posix/posixFile.hpp b/vmime/platforms/posix/posixFile.hpp
index e64f8d70..b8adb026 100644
--- a/vmime/platforms/posix/posixFile.hpp
+++ b/vmime/platforms/posix/posixFile.hpp
@@ -83,7 +83,7 @@ public:
posixFileWriter(const vmime::utility::file::path& path, const vmime::string& nativePath);
- vmime::utility::outputStream* getOutputStream();
+ ref <vmime::utility::outputStream> getOutputStream();
private:
@@ -99,7 +99,7 @@ public:
posixFileReader(const vmime::utility::file::path& path, const vmime::string& nativePath);
- vmime::utility::inputStream* getInputStream();
+ ref <vmime::utility::inputStream> getInputStream();
private:
@@ -117,7 +117,7 @@ public:
~posixFileIterator();
const bool hasMoreElements() const;
- vmime::utility::file* nextElement();
+ ref <vmime::utility::file> nextElement();
private:
@@ -153,16 +153,16 @@ public:
const bool exists() const;
- const vmime::utility::file* getParent() const;
+ ref <vmime::utility::file> getParent() const;
void rename(const path& newName);
void remove();
- vmime::utility::fileWriter* getFileWriter();
- vmime::utility::fileReader* getFileReader();
+ ref <vmime::utility::fileWriter> getFileWriter();
+ ref <vmime::utility::fileReader> getFileReader();
- vmime::utility::fileIterator* getFiles() const;
+ ref <vmime::utility::fileIterator> getFiles() const;
private:
@@ -180,7 +180,7 @@ class posixFileSystemFactory : public vmime::utility::fileSystemFactory
{
public:
- vmime::utility::file* create(const vmime::utility::file::path& path) const;
+ ref <vmime::utility::file> create(const vmime::utility::file::path& path) const;
const vmime::utility::file::path stringToPath(const vmime::string& str) const;
const vmime::string pathToString(const vmime::utility::file::path& path) const;
diff --git a/vmime/platforms/posix/posixSocket.hpp b/vmime/platforms/posix/posixSocket.hpp
index 99e12940..909ada6a 100644
--- a/vmime/platforms/posix/posixSocket.hpp
+++ b/vmime/platforms/posix/posixSocket.hpp
@@ -61,7 +61,7 @@ class posixSocketFactory : public vmime::messaging::socketFactory
{
public:
- vmime::messaging::socket* create();
+ ref <vmime::messaging::socket> create();
};
diff --git a/vmime/platforms/windows/windowsFile.hpp b/vmime/platforms/windows/windowsFile.hpp
index 15465198..86d8dcc1 100644
--- a/vmime/platforms/windows/windowsFile.hpp
+++ b/vmime/platforms/windows/windowsFile.hpp
@@ -37,7 +37,7 @@ class windowsFileSystemFactory : public vmime::utility::fileSystemFactory
{
public:
- vmime::utility::file* create(const vmime::utility::file::path& path) const;
+ ref <vmime::utility::file> create(const vmime::utility::file::path& path) const;
const vmime::utility::file::path stringToPath(const vmime::string& str) const;
const vmime::string pathToString(const vmime::utility::file::path& path) const;
@@ -57,9 +57,9 @@ public:
class windowsFile : public vmime::utility::file
{
public:
+
windowsFile(const vmime::utility::file::path& path);
-public:
void createFile();
void createDirectory(const bool createAll = false);
@@ -70,34 +70,37 @@ public:
const bool canWrite() const;
const length_type getLength();
-
+
const path& getFullPath() const;
const bool exists() const;
- const file* getParent() const;
+ ref <file> getParent() const;
void rename(const path& newName);
void remove();
- vmime::utility::fileWriter* getFileWriter();
+ ref <vmime::utility::fileWriter> getFileWriter();
- vmime::utility::fileReader* getFileReader();
+ ref <vmime::utility::fileReader> getFileReader();
- vmime::utility::fileIterator* getFiles() const;
+ ref <vmime::utility::fileIterator> getFiles() const;
private:
+
static void createDirectoryImpl(const vmime::utility::file::path& fullPath, const vmime::utility::file::path& path, const bool recursive = false);
private:
+
vmime::utility::file::path m_path;
vmime::string m_nativePath;
};
-
+
class windowsFileIterator : public vmime::utility::fileIterator
{
public:
+
windowsFileIterator(const vmime::utility::file::path& path, const vmime::string& nativePath);
~windowsFileIterator();
@@ -105,11 +108,13 @@ public:
vmime::utility::file* nextElement();
private:
+
void findFirst();
void findNext();
bool isCurrentOrParentDir() const;
private:
+
vmime::utility::file::path m_path;
vmime::string m_nativePath;
WIN32_FIND_DATA m_findData;
@@ -121,12 +126,15 @@ private:
class windowsFileReader : public vmime::utility::fileReader
{
public:
+
windowsFileReader(const vmime::utility::file::path& path, const vmime::string& nativePath);
public:
- vmime::utility::inputStream* getInputStream();
+
+ ref <vmime::utility::inputStream> getInputStream();
private:
+
vmime::utility::file::path m_path;
vmime::string m_nativePath;
};
@@ -135,16 +143,19 @@ private:
class windowsFileReaderInputStream : public vmime::utility::inputStream
{
public:
+
windowsFileReaderInputStream(const vmime::utility::file::path& path, HANDLE hFile);
~windowsFileReaderInputStream();
public:
+
const bool eof() const;
void reset();
const size_type read(value_type* const data, const size_type count);
const size_type skip(const size_type count);
private:
+
const vmime::utility::file::path m_path;
HANDLE m_hFile;
};
@@ -153,12 +164,15 @@ private:
class windowsFileWriter : public vmime::utility::fileWriter
{
public:
+
windowsFileWriter(const vmime::utility::file::path& path, const vmime::string& nativePath);
public:
- vmime::utility::outputStream* getOutputStream();
+
+ ref <vmime::utility::outputStream> getOutputStream();
private:
+
vmime::utility::file::path m_path;
vmime::string m_nativePath;
};
@@ -167,17 +181,21 @@ private:
class windowsFileWriterOutputStream : public vmime::utility::outputStream
{
public:
+
windowsFileWriterOutputStream(const vmime::utility::file::path& path, HANDLE hFile);
~windowsFileWriterOutputStream();
public:
+
void write(const value_type* const data, const size_type count);
private:
+
const vmime::utility::file::path m_path;
HANDLE m_hFile;
};
+
} // windows
} // platforms
} // vmime
diff --git a/vmime/platforms/windows/windowsSocket.hpp b/vmime/platforms/windows/windowsSocket.hpp
index 8a06d4d3..bbf76643 100644
--- a/vmime/platforms/windows/windowsSocket.hpp
+++ b/vmime/platforms/windows/windowsSocket.hpp
@@ -40,6 +40,7 @@ public:
~windowsSocket();
public:
+
void connect(const vmime::string& address, const vmime::port_t port);
const bool isConnected() const;
void disconnect();
@@ -51,6 +52,7 @@ public:
void sendRaw(const char* buffer, const int count);
private:
+
char m_buffer[65536];
SOCKET m_desc;
};
@@ -60,7 +62,8 @@ private:
class windowsSocketFactory : public vmime::messaging::socketFactory
{
public:
- vmime::messaging::socket* create();
+
+ ref <vmime::messaging::socket> create();
};
diff --git a/vmime/propertySet.hpp b/vmime/propertySet.hpp
index b1fc0be1..5bd03dd2 100644
--- a/vmime/propertySet.hpp
+++ b/vmime/propertySet.hpp
@@ -39,13 +39,13 @@ namespace vmime
/** Manage a list of (name,value) pairs.
*/
-class propertySet
+class propertySet : public object
{
public:
/** A property holds a (name,value) pair.
*/
- class property
+ class property : public object
{
public:
@@ -259,7 +259,7 @@ public:
template <class TYPE>
const TYPE getProperty(const string& name) const
{
- const property* const prop = find(name);
+ const ref <property> prop = find(name);
if (!prop) throw exceptions::no_such_property(name);
//return (prop->getValue <TYPE>()); // BUG: with g++ < 3.4
@@ -278,7 +278,7 @@ public:
template <class TYPE>
const TYPE getProperty(const string& name, const TYPE defaultValue) const
{
- const property* const prop = find(name);
+ const ref <property> prop = find(name);
//return (prop ? prop->getValue <TYPE>() : defaultValue); // BUG: with g++ < 3.4
return (prop ? prop->template getValue <TYPE>() : defaultValue);
}
@@ -318,13 +318,13 @@ private:
void parse(const string& props);
- class propFinder : public std::unary_function <property*, bool>
+ class propFinder : public std::unary_function <ref <property>, bool>
{
public:
propFinder(const string& name) : m_name(utility::stringUtils::toLower(name)) { }
- const bool operator()(property* const p) const
+ const bool operator()(ref <property> p) const
{
return (utility::stringUtils::toLower(p->getName()) == m_name);
}
@@ -334,10 +334,10 @@ private:
const std::string m_name;
};
- property* find(const string& name) const;
- property* findOrCreate(const string& name);
+ ref <property> find(const string& name) const;
+ ref <property> findOrCreate(const string& name);
- typedef std::list <property*> list_type;
+ typedef std::list <ref <property> > list_type;
list_type m_props;
public:
@@ -404,13 +404,13 @@ public:
*
* @return list of properties
*/
- const std::vector <const property*> getPropertyList() const;
+ const std::vector <ref <const property> > getPropertyList() const;
/** Return the property list.
*
* @return list of properties
*/
- const std::vector <property*> getPropertyList();
+ const std::vector <ref <property> > getPropertyList();
};
diff --git a/vmime/relay.hpp b/vmime/relay.hpp
index c97db613..168084fb 100644
--- a/vmime/relay.hpp
+++ b/vmime/relay.hpp
@@ -43,11 +43,11 @@ public:
public:
- relay* clone() const;
+ ref <component> clone() const;
void copyFrom(const component& other);
relay& operator=(const relay& other);
- const std::vector <const component*> getChildComponents() const;
+ const std::vector <ref <const component> > getChildComponents() const;
const string& getFrom() const;
void setFrom(const string& from);
diff --git a/vmime/standardFields.hpp b/vmime/standardFields.hpp
index 8fdb2a99..89d30da8 100644
--- a/vmime/standardFields.hpp
+++ b/vmime/standardFields.hpp
@@ -44,7 +44,7 @@ namespace vmime
#define DECLARE_STANDARD_FIELD(fieldClassName, valueTypeClassName) \
class fieldClassName : public genericField <valueTypeClassName> { \
- friend class headerFieldFactory::registerer <fieldClassName>; \
+ friend class vmime::creator; \
protected: \
fieldClassName() { } \
fieldClassName(const fieldClassName&) \
@@ -61,7 +61,7 @@ namespace vmime
#define DECLARE_STANDARD_FIELD_PARAM(fieldClassName, valueTypeClassName) \
class fieldClassName : public genericParameterizedHeaderField <valueTypeClassName> { \
- friend class headerFieldFactory::registerer <fieldClassName>; \
+ friend class vmime::creator; \
protected: \
fieldClassName() { } \
fieldClassName(const fieldClassName&) \
@@ -74,7 +74,7 @@ namespace vmime
#define DECLARE_STANDARD_FIELD_PARAM(fieldClassName, valueTypeClassName) \
class fieldClassName : public genericField <valueTypeClassName>, \
public parameterizedHeaderField { \
- friend class headerFieldFactory::registerer <fieldClassName>; \
+ friend class vmime::creator; \
protected: \
fieldClassName() { } \
fieldClassName(const fieldClassName&) \
diff --git a/vmime/standardParams.hpp b/vmime/standardParams.hpp
index 6c48835f..06e29c3e 100644
--- a/vmime/standardParams.hpp
+++ b/vmime/standardParams.hpp
@@ -35,7 +35,7 @@ namespace vmime
#define DECLARE_STANDARD_PARAM(paramClassName, valueTypeClassName) \
class paramClassName : public genericParameter <valueTypeClassName> { \
- friend class parameterFactory::registerer <paramClassName>; \
+ friend class vmime::creator; \
protected: \
paramClassName() { } \
paramClassName(const paramClassName&) \
diff --git a/vmime/streamContentHandler.hpp b/vmime/streamContentHandler.hpp
index 1dfa4071..3e668703 100644
--- a/vmime/streamContentHandler.hpp
+++ b/vmime/streamContentHandler.hpp
@@ -33,16 +33,16 @@ class streamContentHandler : public contentHandler
public:
streamContentHandler();
- streamContentHandler(utility::inputStream* is, const utility::stream::size_type length, const bool own, const vmime::encoding& enc = NO_ENCODING);
+ streamContentHandler(ref <utility::inputStream> is, const utility::stream::size_type length, const vmime::encoding& enc = NO_ENCODING);
~streamContentHandler();
streamContentHandler(const streamContentHandler& cts);
streamContentHandler& operator=(const streamContentHandler& cts);
- contentHandler* clone() const;
+ ref <contentHandler> clone() const;
- void setData(utility::inputStream* is, const utility::stream::size_type length, const bool own, const vmime::encoding& enc = NO_ENCODING);
+ void setData(ref <utility::inputStream> is, const utility::stream::size_type length, const vmime::encoding& enc = NO_ENCODING);
void generate(utility::outputStream& os, const vmime::encoding& enc, const string::size_type maxLineLength = lineLengthLimits::infinite) const;
@@ -65,8 +65,7 @@ private:
vmime::encoding m_encoding;
// Actual data
- utility::smart_ptr <utility::inputStream> m_ownedStream; // 'contentHandler' objects are copiable...
- utility::inputStream* m_stream;
+ mutable ref <utility::inputStream> m_stream;
string::size_type m_length;
};
diff --git a/vmime/stringContentHandler.hpp b/vmime/stringContentHandler.hpp
index f3e905fa..f66a4b41 100644
--- a/vmime/stringContentHandler.hpp
+++ b/vmime/stringContentHandler.hpp
@@ -42,7 +42,7 @@ public:
stringContentHandler(const stringContentHandler& cts);
stringContentHandler& operator=(const stringContentHandler& cts);
- contentHandler* clone() const;
+ ref <contentHandler> clone() const;
// Set the data contained in the body.
//
diff --git a/vmime/text.hpp b/vmime/text.hpp
index 0f42b982..ed75824c 100644
--- a/vmime/text.hpp
+++ b/vmime/text.hpp
@@ -48,18 +48,18 @@ public:
const bool operator==(const text& t) const;
const bool operator!=(const text& t) const;
- text* clone() const;
+ ref <component> clone() const;
void copyFrom(const component& other);
text& operator=(const component& other);
text& operator=(const text& other);
- const std::vector <const component*> getChildComponents() const;
+ const std::vector <ref <const component> > getChildComponents() const;
/** Add a word at the end of the list.
*
* @param w word to append
*/
- void appendWord(word* w);
+ void appendWord(ref <word> w);
/** Insert a new word before the specified position.
*
@@ -67,14 +67,14 @@ public:
* the beginning of the list)
* @param w word to insert
*/
- void insertWordBefore(const int pos, word* w);
+ void insertWordBefore(const int pos, ref <word> w);
/** Insert a new word after the specified position.
*
* @param pos position of the word before the new word
* @param w word to insert
*/
- void insertWordAfter(const int pos, word* w);
+ void insertWordAfter(const int pos, ref <word> w);
/** Remove the word at the specified position.
*
@@ -103,26 +103,26 @@ public:
* @param pos position
* @return word at position 'pos'
*/
- word* getWordAt(const int pos);
+ const ref <word> getWordAt(const int pos);
/** Return the word at the specified position.
*
* @param pos position
* @return word at position 'pos'
*/
- const word* getWordAt(const int pos) const;
+ const ref <const word> getWordAt(const int pos) const;
/** Return the word list.
*
* @return list of words
*/
- const std::vector <const word*> getWordList() const;
+ const std::vector <ref <const word> > getWordList() const;
/** Return the word list.
*
* @return list of words
*/
- const std::vector <word*> getWordList();
+ const std::vector <ref <word> > getWordList();
// Decoding
#if VMIME_WIDE_CHAR_SUPPORT
@@ -153,13 +153,27 @@ public:
*
* @param in input string
* @param ch input charset
- * @param generateInExisting if not NULL, the resulting text will be generated
- * in the specified object instead of a new created object (in this case, the
- * function returns the same pointer). Can be used to avoid copying the
- * resulting object into an existing object.
- * @return new text object or existing object if generateInExisting != NULL
- */
- static text* newFromString(const string& in, const charset& ch, text* generateInExisting = NULL);
+ * @return new text object
+ */
+ static ref <text> newFromString(const string& in, const charset& ch);
+
+ /** This function can be used to make several encoded words from a text.
+ * All the characters in the text must be in the same specified charset.
+ *
+ * <p>Eg: giving:</p>
+ * <pre> &lt;iso-8859-1> "Linux dans un t'el'ephone mobile"
+ * ("=?iso-8859-1?Q?Linux_dans_un_t=E9l=E9phone_mobile?=")
+ * </pre><p>it will return:</p>
+ * <pre> &lt;us-ascii> "Linux dans un "
+ * &lt;iso-8859-1> "t'el'ephone "
+ * &lt;us-ascii> "mobile"
+ * ("Linux dans un =?iso-8859-1?Q?t=E9l=E9phone_?= mobile")
+ * </pre>
+ *
+ * @param in input string
+ * @param ch input charset
+ */
+ void createFromString(const string& in, const charset& ch);
/** Flags used by "encodeAndFold" function.
*/
@@ -193,7 +207,18 @@ public:
* resulting object into an existing object.
* @return new text object or existing object if generateInExisting != NULL
*/
- static text* decodeAndUnfold(const string& in, text* generateInExisting = NULL);
+ static ref <text> decodeAndUnfold(const string& in);
+
+ /** Decode and unfold text (RFC-2047).
+ *
+ * @param in input string
+ * @param generateInExisting if not NULL, the resulting text will be generated
+ * in the specified object instead of a new created object (in this case, the
+ * function returns the same pointer). Can be used to avoid copying the
+ * resulting object into an existing object.
+ * @return new text object or existing object if generateInExisting != NULL
+ */
+ static text* decodeAndUnfold(const string& in, text* generateInExisting);
using component::parse;
@@ -205,7 +230,7 @@ public:
private:
- std::vector <word*> m_words;
+ std::vector <ref <word> > m_words;
};
diff --git a/vmime/textPart.hpp b/vmime/textPart.hpp
index 5186592a..42aeecae 100644
--- a/vmime/textPart.hpp
+++ b/vmime/textPart.hpp
@@ -35,7 +35,7 @@ namespace vmime
/** Generic text part.
*/
-class textPart
+class textPart : public object
{
friend class textPartFactory;
friend class messageBuilder; // for generateIn, getPartCount
@@ -69,13 +69,13 @@ public:
*
* @return text of the part
*/
- virtual const contentHandler& getText() const = 0;
+ virtual const ref <const contentHandler> getText() const = 0;
/** Set the text contained in the part.
*
* @param text text of the part
*/
- virtual void setText(const contentHandler& text) = 0;
+ virtual void setText(ref <contentHandler> text) = 0;
protected:
diff --git a/vmime/textPartFactory.hpp b/vmime/textPartFactory.hpp
index d117edb8..5a7486ba 100644
--- a/vmime/textPartFactory.hpp
+++ b/vmime/textPartFactory.hpp
@@ -36,10 +36,10 @@ protected:
textPartFactory();
~textPartFactory();
- typedef textPart* (*AllocFunc)(void);
- typedef std::map <string, AllocFunc> NameMap;
+ typedef ref <textPart> (*AllocFunc)(void);
+ typedef std::vector <std::pair <mediaType, AllocFunc> > MapType;
- NameMap m_nameMap;
+ MapType m_map;
#ifndef VMIME_BUILDING_DOC
template <class TYPE>
@@ -47,10 +47,10 @@ protected:
{
public:
- static textPart* creator()
+ static ref <textPart> creator()
{
// Allocate a new object
- return new TYPE();
+ return vmime::create <TYPE>();
}
};
#endif // VMIME_BUILDING_DOC
@@ -62,10 +62,10 @@ public:
template <class T>
void registerType(const mediaType& type)
{
- m_nameMap.insert(NameMap::value_type(type.generate(), &registerer<T>::creator));
+ m_map.push_back(MapType::value_type(type, &registerer<T>::creator));
}
- textPart* create(const mediaType& type);
+ ref <textPart> create(const mediaType& type);
};
diff --git a/vmime/typeAdapter.hpp b/vmime/typeAdapter.hpp
index 9565b567..0dc59808 100644
--- a/vmime/typeAdapter.hpp
+++ b/vmime/typeAdapter.hpp
@@ -30,7 +30,7 @@ namespace vmime
{
-/** An adapter to allow any type being treated as a 'component'.
+/** An adapter to allow any type to act as a 'component'.
*/
template <class TYPE>
@@ -43,7 +43,7 @@ public:
}
typeAdapter(typeAdapter& a)
- : m_value(a.m_value)
+ : component(), m_value(a.m_value)
{
}
@@ -53,9 +53,9 @@ public:
}
- typeAdapter* clone() const
+ ref <component> clone() const
{
- return new typeAdapter(*this);
+ return create <typeAdapter>(*this);
}
@@ -112,9 +112,9 @@ public:
*newLinePos = curLinePos + oss.str().length();
}
- const std::vector <const component*> getChildComponents() const
+ const std::vector <ref <const component> > getChildComponents() const
{
- return std::vector <const component*>();
+ return std::vector <ref <const component> >();
}
private:
diff --git a/vmime/types.hpp b/vmime/types.hpp
index 9a2d7f19..1028fed3 100644
--- a/vmime/types.hpp
+++ b/vmime/types.hpp
@@ -25,6 +25,7 @@
#include <string>
#include "vmime/config.hpp"
+#include "vmime/utility/smartPtr.hpp"
namespace vmime
@@ -37,7 +38,20 @@ namespace vmime
typedef unsigned short port_t;
typedef int char_t;
+
+ // Some aliases
+ namespace utils = utility;
+
+ using vmime::utility::ref;
+ using vmime::utility::weak_ref;
+ using vmime::utility::null_ref;
+
+ extern const null_ref null;
}
+// This is here because 'vmime::ref' need to be declared...
+#include "vmime/object.hpp"
+
+
#endif // VMIME_TYPES_HPP_INCLUDED
diff --git a/vmime/utility/childProcess.hpp b/vmime/utility/childProcess.hpp
index b6d876bf..e7499350 100644
--- a/vmime/utility/childProcess.hpp
+++ b/vmime/utility/childProcess.hpp
@@ -35,7 +35,7 @@ namespace utility {
* and/or standard output.
*/
-class childProcess
+class childProcess : public object
{
public:
@@ -61,13 +61,13 @@ public:
*
* @return output stream wrapper for child's stdin
*/
- virtual utility::outputStream* getStdIn() = 0;
+ virtual ref <utility::outputStream> getStdIn() = 0;
/** Return a wrapper to the child process standard output.
*
* @return input stream wrapper for child's stdout
*/
- virtual utility::inputStream* getStdOut() = 0;
+ virtual ref <utility::inputStream> getStdOut() = 0;
/** Wait for the process to finish.
*
@@ -91,7 +91,7 @@ public:
*
* @param path full path of the process executable file
*/
- virtual childProcess* create(const utility::file::path& path) const = 0;
+ virtual ref <childProcess> create(const utility::file::path& path) const = 0;
};
diff --git a/vmime/utility/file.hpp b/vmime/utility/file.hpp
index 89fbeebe..ca93bb00 100644
--- a/vmime/utility/file.hpp
+++ b/vmime/utility/file.hpp
@@ -40,7 +40,7 @@ class file;
/** File list iterator (see file::getFiles).
*/
-class fileIterator
+class fileIterator : public object
{
public:
@@ -57,40 +57,40 @@ public:
*
* @return next file or NULL
*/
- virtual file* nextElement() = 0;
+ virtual ref <file> nextElement() = 0;
};
/** Write to a file.
*/
-class fileWriter
+class fileWriter : public object
{
public:
virtual ~fileWriter() { }
- virtual utility::outputStream* getOutputStream() = 0;
+ virtual ref <utility::outputStream> getOutputStream() = 0;
};
/** Read from a file.
*/
-class fileReader
+class fileReader : public object
{
public:
virtual ~fileReader() { }
- virtual utility::inputStream* getInputStream() = 0;
+ virtual ref <utility::inputStream> getInputStream() = 0;
};
/** Abstract representation of a file or directory.
*/
-class file
+class file : public object
{
public:
@@ -161,7 +161,7 @@ public:
*
* @return parent directory (or NULL if root)
*/
- virtual const file* getParent() const = 0;
+ virtual ref <file> getParent() const = 0;
/** Rename the file/directory.
*
@@ -181,13 +181,13 @@ public:
*
* @return file writer object
*/
- virtual fileWriter* getFileWriter() = 0;
+ virtual ref <fileWriter> getFileWriter() = 0;
/** Return an object capable of reading from this file.
*
* @return file reader object
*/
- virtual fileReader* getFileReader() = 0;
+ virtual ref <fileReader> getFileReader() = 0;
/** Enumerate files contained in this directory.
*
@@ -195,7 +195,15 @@ public:
* @throw exceptions::not_a_directory if this is not a directory,
* exceptions::filesystem_exception if another error occurs
*/
- virtual fileIterator* getFiles() const = 0;
+ virtual ref <fileIterator> getFiles() const = 0;
+
+protected:
+
+ file() { }
+
+private:
+
+ file(const file&) : object() { }
};
@@ -213,7 +221,7 @@ public:
* @param path full path (absolute) of the file
* @return new file object for the path
*/
- virtual file* create(const file::path& path) const = 0;
+ virtual ref <file> create(const file::path& path) const = 0;
/** Parse a path contained in a string.
*
diff --git a/vmime/utility/path.hpp b/vmime/utility/path.hpp
index 06d1403f..fde3b7f7 100644
--- a/vmime/utility/path.hpp
+++ b/vmime/utility/path.hpp
@@ -34,7 +34,7 @@ namespace utility {
/** Abstract representation of a path (filesystem, mailbox, etc).
*/
-class path
+class path : public object
{
public:
diff --git a/vmime/utility/smartPtr.hpp b/vmime/utility/smartPtr.hpp
index 7b895629..65ea2ff6 100644
--- a/vmime/utility/smartPtr.hpp
+++ b/vmime/utility/smartPtr.hpp
@@ -21,6 +21,13 @@
#define VMIME_UTILITY_SMARTPTR_HPP_INCLUDED
+#include <map>
+
+
+// Forward reference to 'object'
+namespace vmime { class object; }
+
+
namespace vmime {
namespace utility {
@@ -47,116 +54,489 @@ public:
};
-/** Smart auto-delete, referencable and copiable pointer.
+/** Null reference.
*/
-template <class T>
-class smart_ptr
+class null_ref
{
private:
- struct data
+ int foo;
+};
+
+
+/** Strong reference (smart pointer).
+ */
+
+template <class T>
+class ref
+{
+public:
+
+ template <class U> friend class ref;
+ template <class U> friend class weak_ref;
+
+
+ ref() : m_ptr(0) { }
+ ref(const ref& r) : m_ptr(0) { attach(r); }
+ ref(const null_ref&) : m_ptr(0) { }
+
+ virtual ~ref() { detach(); }
+
+ // Allow creating NULL ref (NULL casts to anything*)
+ ref(class null_pointer*) : m_ptr(0) { }
+
+
+ // Access to wrapped object
+ operator const T*() const { return m_ptr; }
+
+ T& operator *() { return *m_ptr; }
+ const T& operator *() const { return *m_ptr; }
+
+ T* operator ->() { return m_ptr; }
+ const T* operator ->() const { return m_ptr; }
+
+ const T* const get() const { return m_ptr; }
+ T* const get() { return m_ptr; }
+
+
+ // dynamic_cast
+ template <class U>
+ ref <U> dynamicCast() const
{
- int refCount;
- T* ptr;
- };
+ U* p = dynamic_cast <U*>(const_cast <T*>(m_ptr));
+ if (!p) return ref <U>();
- data* m_data;
+ p->addStrong();
+ ref <U> r;
+ r.m_ptr = p;
- typedef std::map <T*, data*> MapType;
- static MapType sm_map;
+ return r;
+ }
-public:
+ // static_cast
+ template <class U>
+ ref <U> staticCast() const
+ {
+ U* p = static_cast <U*>(const_cast <T*>(m_ptr));
+ if (!p) return ref <U>();
- smart_ptr() : m_data(NULL) { }
- smart_ptr(T* const p) : m_data(NULL) { if (p) { attach(p); } }
- smart_ptr(const smart_ptr& p) : m_data(NULL) { if (p.m_data) { attach(p); } }
+ p->addStrong();
- ~smart_ptr() { detach(); }
+ ref <U> r;
+ r.m_ptr = p;
- smart_ptr& operator=(smart_ptr& p)
+ return r;
+ }
+
+ // const_cast
+ template <class U>
+ ref <U> constCast() const
{
- attach(p);
- return (*this);
+ U* p = const_cast <U*>(m_ptr);
+ if (!p) return ref <U>();
+
+ m_ptr->addStrong();
+
+ ref <U> r;
+ r.m_ptr = p;
+
+ return r;
}
- smart_ptr& operator=(T* const p)
+ // Implicit downcast
+ template <class U>
+ operator ref <const U>() const
{
- if (!p)
- detach();
- else
- attach(p);
+ if (m_ptr)
+ m_ptr->addStrong();
+
+ ref <const U> r;
+ r.m_ptr = m_ptr; // will type check at compile-time (prevent from implicit upcast)
- return (*this);
+ return r;
}
- operator T*() { return (m_data ? m_data->ptr : NULL); }
- operator const T*() { return (m_data ? m_data->ptr : NULL); }
+ template <class U>
+ operator ref <U>()
+ {
+ if (m_ptr)
+ m_ptr->addStrong();
- T& operator *() { return (*(m_data->ptr)); }
- T* operator ->() { return (m_data->ptr); }
+ ref <U> r;
+ r.m_ptr = m_ptr; // will type check at compile-time (prevent from implicit upcast)
- const T* const ptr() const { return (m_data ? m_data->ptr : NULL); }
- T* const ptr() { return (m_data ? m_data->ptr : NULL); }
+ return r;
+ }
-private:
+ template <class U>
+ ref <T>& operator=(const ref <U>& other)
+ {
+ U* ptr = other.m_ptr; // will type check at compile-time (prevent from implicit upcast)
+
+ if (ptr)
+ ptr->addStrong();
+
+ detach();
+
+ m_ptr = ptr;
+
+ return *this;
+ }
+
+ // Implicit non-const => const conversion
+ operator ref <const T>() const
+ {
+ if (m_ptr)
+ m_ptr->addStrong();
+
+ ref <const T> r;
+ r.m_ptr = m_ptr;
+
+ return r;
+ }
+
+ // Copy
+ ref& operator=(const ref& p)
+ {
+ attach(p);
+ return *this;
+ }
+
+ // NULL-pointer comparison
+ bool operator==(const class null_pointer*) const { return m_ptr == 0; }
+ bool operator!=(const class null_pointer*) const { return m_ptr != 0; }
+
+ /** Create a ref<> from a raw pointer.
+ *
+ * WARNING: you should use this function only if you know what
+ * you are doing. In general, you should create ref objects using
+ * vmime::create().
+ *
+ * When this function returns, the pointer is owned by the ref,
+ * you should not attempt to delete it manually.
+ *
+ * @param ptr raw pointer to encapsulate
+ * @return a ref which encapsulates the specified raw pointer
+ */
+ static ref <T> fromPtr(T* const ptr)
+ {
+ if (ptr)
+ ptr->addStrong();
+
+ ref <T> r;
+ r.m_ptr = ptr;
+
+ return r;
+ }
+
+protected:
void detach()
{
- if (m_data)
+ if (m_ptr)
{
- if (m_data->refCount == 1)
- {
- typename MapType::iterator it = sm_map.find(m_data->ptr);
- if (it != sm_map.end()) sm_map.erase(it);
-
- delete (m_data->ptr);
- delete (m_data);
- }
- else
- {
- m_data->refCount--;
- }
-
- m_data = NULL;
+ m_ptr->releaseStrong();
+ m_ptr = 0;
}
}
- void attach(T* const p)
+ template <class U>
+ void attach(U* const ptr)
+ {
+ if (ptr)
+ ptr->addStrong();
+
+ detach();
+
+ m_ptr = ptr;
+ }
+
+ template <class U>
+ void attach(const ref <U>& r)
+ {
+ if (r.m_ptr)
+ r.m_ptr->addStrong();
+
+ detach();
+
+ m_ptr = r.m_ptr;
+ }
+
+private:
+
+ T* m_ptr;
+};
+
+
+
+template <class T, class U>
+bool operator==(const ref <T>& a, const ref <U>& b)
+{
+ return (a.get() == b.get());
+}
+
+template <class T, class U>
+bool operator!=(const ref <T>& a, const ref <U>& b)
+{
+ return (a.get() != b.get());
+}
+
+template <class T>
+bool operator==(const ref <T>& a, T* const p)
+{
+ return (a.get() == p);
+}
+
+template <class T>
+bool operator!=(const ref <T>& a, T* const p)
+{
+ return (a.get() != p);
+}
+
+template <class T>
+bool operator==(T* const p, const ref <T>& a)
+{
+ return (a.get() == p);
+}
+
+template <class T>
+bool operator!=(T* const p, const ref <T>& a)
+{
+ return (a.get() != p);
+}
+
+
+
+/** Base class for weak references.
+ */
+
+class weak_ref_base
+{
+ friend class vmime::object; // calls 'notifyObjectDestroyed'
+
+protected:
+
+ weak_ref_base() { }
+ weak_ref_base(const weak_ref_base&) { }
+ virtual ~weak_ref_base() { }
+
+
+ virtual void notifyObjectDestroyed() = 0;
+};
+
+
+/** Weak reference.
+ * Avoid circular references.
+ */
+
+template <class T>
+class weak_ref : public weak_ref_base
+{
+public:
+
+ template <class U> friend class weak_ref;
+
+
+ weak_ref() : m_ptr(0) { }
+ weak_ref(const ref <T>& r) : m_ptr(0) { attach(r); }
+ weak_ref(const weak_ref& r) : weak_ref_base(), m_ptr(0) { attach(r); }
+ weak_ref(const null_ref&) : m_ptr(0) { }
+ weak_ref(T* const p) : m_ptr(0) { attach(p); }
+
+ ~weak_ref() { detach(); }
+
+
+ // Access to wrapped object
+ operator const T*() const { return m_ptr; }
+
+ T& operator *() { return *m_ptr; }
+ const T& operator *() const { return *m_ptr; }
+
+ T* operator ->() { return m_ptr; }
+ const T* operator ->() const { return m_ptr; }
+
+ const T* const get() const { return m_ptr; }
+ T* const get() { return m_ptr; }
+
+ // dynamic_cast
+ template <class U>
+ weak_ref <U> dynamicCast() const
+ {
+ U* p = dynamic_cast <U*>(const_cast <T*>(m_ptr));
+ if (!p) return weak_ref <U>();
+
+ weak_ref <U> r;
+
+ p->addWeak(&r);
+
+ r.m_ptr = p;
+
+ return r;
+ }
+
+ // static_cast
+ template <class U>
+ weak_ref <U> staticCast() const
+ {
+ U* p = static_cast <U*>(const_cast <T*>(m_ptr));
+ if (!p) return weak_ref <U>();
+
+ weak_ref <U> r;
+
+ p->addWeak(&r);
+
+ r.m_ptr = p;
+
+ return r;
+ }
+
+ // const_cast
+ template <class U>
+ weak_ref <U> constCast() const
+ {
+ U* p = const_cast <U*>(m_ptr);
+ if (!p) return weak_ref <U>();
+
+ weak_ref <U> r;
+
+ p->addWeak(&r);
+
+ r.m_ptr = p;
+
+ return r;
+ }
+
+ // Implicit downcast
+ template <class U>
+ operator weak_ref <const U>()
+ {
+ weak_ref <const U> r;
+
+ if (m_ptr)
+ m_ptr->addWeak(&r);
+
+ r.m_ptr = m_ptr; // will type check at compile-time (prevent from implicit upcast)
+
+ return r;
+ }
+
+ // Implicit downcast
+ template <class U>
+ operator weak_ref <U>()
+ {
+ weak_ref <U> r;
+
+ if (m_ptr)
+ m_ptr->addWeak(&r);
+
+ r.m_ptr = m_ptr; // will type check at compile-time (prevent from implicit upcast)
+
+ return r;
+ }
+
+ template <class U>
+ weak_ref <T>& operator=(const weak_ref <U>& other)
{
+ U* ptr = other.m_ptr; // will type check at compile-time (prevent from implicit upcast)
+
+ if (ptr)
+ ptr->addWeak(this);
+
detach();
- typename MapType::iterator it = sm_map.find(p);
+ m_ptr = ptr;
+
+ return *this;
+ }
+
+ // Implicit non-const => const conversion
+ operator weak_ref <const T>() const
+ {
+ weak_ref <const T> r;
+
+ if (m_ptr)
+ m_ptr->addWeak(&r);
+
+ r.m_ptr = m_ptr;
+
+ return r;
+ }
+
+ template <class U>
+ operator weak_ref <const U>() const
+ {
+ weak_ref <const U> r;
+
+ if (m_ptr)
+ m_ptr->addWeak(&r);
+
+ r.m_ptr = m_ptr;
+
+ return r;
+ }
+
+ // Copy
+ weak_ref& operator=(const weak_ref& p)
+ {
+ attach(p);
+ return *this;
+ }
+
+ // NULL-pointer comparison
+ bool operator==(const class null_pointer*) const { return m_ptr == 0; }
+ bool operator!=(const class null_pointer*) const { return m_ptr != 0; }
+
+private:
- if (it != sm_map.end())
+ void notifyObjectDestroyed()
+ {
+ m_ptr = 0;
+ }
+
+ void detach()
+ {
+ if (m_ptr)
{
- (*it).second->refCount++;
+ m_ptr->releaseWeak(this);
+ m_ptr = 0;
}
- else
- {
- m_data = new data;
- m_data->refCount = 1;
- m_data->ptr = p;
+ }
- sm_map.insert(typename MapType::value_type(p, m_data));
- }
+ void attach(const ref <T>& r)
+ {
+ if (r.m_ptr)
+ r.m_ptr->addWeak(this);
+
+ detach();
+
+ m_ptr = r.m_ptr;
}
- void attach(const smart_ptr <T>& p)
+ void attach(const weak_ref& r)
{
- data* newData = p.m_data;
- if (newData) newData->refCount++;
+ if (r.m_ptr)
+ r.m_ptr->addWeak(this);
detach();
- m_data = newData;
+ m_ptr = r.m_ptr;
}
-};
+ void attach(T* const p)
+ {
+ if (p)
+ p->addWeak(this);
-template <class T>
-typename smart_ptr <T>::MapType smart_ptr <T>::sm_map;
+ detach();
+
+ m_ptr = p;
+ }
+
+
+ T* m_ptr;
+};
} // utility
diff --git a/vmime/utility/stream.hpp b/vmime/utility/stream.hpp
index bfcd6192..5dd9d4dc 100644
--- a/vmime/utility/stream.hpp
+++ b/vmime/utility/stream.hpp
@@ -54,7 +54,7 @@ class stringProxy;
/** Base class for input/output stream.
*/
-class stream
+class stream : public object
{
public:
@@ -264,6 +264,8 @@ public:
private:
+ inputStreamStringAdapter(const inputStreamStringAdapter&);
+
const string m_buffer; // do _NOT_ keep a reference...
const string::size_type m_begin;
const string::size_type m_end;
@@ -289,6 +291,8 @@ public:
private:
+ inputStreamStringProxyAdapter(const inputStreamStringProxyAdapter&);
+
const stringProxy& m_buffer;
string::size_type m_pos;
};
@@ -315,6 +319,8 @@ public:
private:
+ inputStreamPointerAdapter(const inputStreamPointerAdapter&);
+
std::istream* m_stream;
const bool m_own;
};
@@ -336,6 +342,8 @@ public:
private:
+ outputStreamSocketAdapter(const outputStreamSocketAdapter&);
+
messaging::socket& m_socket;
};
@@ -356,6 +364,8 @@ public:
private:
+ inputStreamSocketAdapter(const inputStreamSocketAdapter&);
+
messaging::socket& m_socket;
};
diff --git a/vmime/word.hpp b/vmime/word.hpp
index 6b180173..adb944b7 100644
--- a/vmime/word.hpp
+++ b/vmime/word.hpp
@@ -35,6 +35,8 @@ namespace vmime
class word : public component
{
+ friend class text;
+
public:
word();
@@ -100,7 +102,7 @@ public:
*
* @return a copy of this word
*/
- word* clone() const;
+ ref <component> clone() const;
using component::parse;
@@ -111,13 +113,14 @@ public:
void generate(utility::outputStream& os, const string::size_type maxLineLength, const string::size_type curLinePos, string::size_type* newLinePos, const int flags, const bool isFirstWord) const;
- const std::vector <const component*> getChildComponents() const;
+ const std::vector <ref <const component> > getChildComponents() const;
+
+private:
- static word* parseNext(const string& buffer, const string::size_type position, const string::size_type end, string::size_type* newPosition, bool prevIsEncoded, bool* isEncoded, bool isFirst);
+ static ref <word> parseNext(const string& buffer, const string::size_type position, const string::size_type end, string::size_type* newPosition, bool prevIsEncoded, bool* isEncoded, bool isFirst);
- static const std::vector <word*> parseMultiple(const string& buffer, const string::size_type position, const string::size_type end, string::size_type* newPosition);
+ static const std::vector <ref <word> > parseMultiple(const string& buffer, const string::size_type position, const string::size_type end, string::size_type* newPosition);
-private:
// The "m_buffer" of this word holds the data, and this data is encoded
// in the specified "m_charset".