diff --git a/kmime/Makefile.am b/kmime/Makefile.am index c5ee7b2df..57ff8718c 100644 --- a/kmime/Makefile.am +++ b/kmime/Makefile.am @@ -1,32 +1,35 @@ -INCLUDES= $(all_includes) +INCLUDES= -I$(top_srcdir)/libemailfunctions \ + $(all_includes) lib_LTLIBRARIES = libkmime.la libkmime_la_SOURCES = \ kmime_charfreq.cpp \ kmime_util.cpp \ kmime_mdn.cpp \ kmime_codecs.cpp \ kmime_codec_base64.cpp \ kmime_codec_uuencode.cpp \ kmime_codec_qp.cpp \ kmime_codec_identity.cpp \ kmime_parsers.cpp \ kmime_header_parsing.cpp \ kmime_content.cpp \ kmime_headers.cpp \ kmime_message.cpp \ kmime_newsarticle.cpp \ boolflags.cpp \ - kqcstringsplitter.cpp + kqcstringsplitter.cpp \ + kautodeletehash.cpp libkmime_la_LDFLAGS = $(all_libraries) -no-undefined -version-info 4:0:2 -libkmime_la_LIBADD = $(LIB_KDECORE) $(LIB_POLL) +libkmime_la_LIBADD = $(top_builddir)/libemailfunctions/libemailfunctions.la \ + $(LIB_KDECORE) $(LIB_POLL) METASOURCES = AUTO messages: $(XGETTEXT) *.cpp *.h -o $(podir)/libkmime.pot include $(top_srcdir)/admin/Doxyfile.am diff --git a/kmime/kautodeletehash.cpp b/kmime/kautodeletehash.cpp new file mode 100644 index 000000000..44ecd3014 --- /dev/null +++ b/kmime/kautodeletehash.cpp @@ -0,0 +1,22 @@ +/* + This file is part of libkdepim. + + Copyright (c) 2005 Ingo Kloecker + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "kautodeletehash.h" diff --git a/kmime/kautodeletehash.h b/kmime/kautodeletehash.h new file mode 100644 index 000000000..81a2d0493 --- /dev/null +++ b/kmime/kautodeletehash.h @@ -0,0 +1,76 @@ +/* + This file is part of libkdepim. + + Copyright (c) 2005 Ingo Kloecker + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __KPIM_KAUTODELETEHASH__ +#define __KPIM_KAUTODELETEHASH__ + +#include + +/** \brief KPIM holds all kinds of functions specific to KDE PIM. */ +namespace KPIM { + +/** + * The KAutoDeleteHash class is a convenience QHash subclass that provides + * automatic deletion of the values in the destructor. Apart from this + * KAutoDeleteHash behaves exactly like QHash. + * + * Since the automatic deletion is restricted to the destruction of the hash + * you have take care of the deletion of values you remove or replace yourself. + * To replace a value in the hash by another value use + * @code + * delete hash.take( key ); + * hash.insert( key, value ); + * @endcode + * and to remove a value from the hash use + * @code + * delete hash.take( key ); + * @endcode + * + * @author Ingo Klöcker + */ +template +class KAutoDeleteHash : public QHash +{ +public: + /** + * Constructs an empty hash. + */ + KAutoDeleteHash() {} + /** + * Constructs a copy of @p other (which can be a QHash or a KAutoDeleteHash). + */ + KAutoDeleteHash( const QHash &other ) : QHash( other ) {} + + /** + * Destroys the hash and deletes all values. References to the values in the + * hash and all iterators of this hash become invalid. + */ + ~KAutoDeleteHash() { while ( ! isEmpty() ) { + T *value = *begin(); + erase( begin() ); + delete value; + } + } +}; + +} // namespace KPIM + +#endif /* __KPIM_KAUTODELETEHASH__ */