akonadi
entity.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef AKONADI_ENTITY_H
00021 #define AKONADI_ENTITY_H
00022
00023 #include "akonadi_export.h"
00024
00025 namespace Akonadi {
00026 class Entity;
00027 }
00028
00029 AKONADI_EXPORT uint qHash( const Akonadi::Entity& );
00030
00031 #include <akonadi/attribute.h>
00032
00033 #include <QtCore/QHash>
00034 #include <QtCore/QSharedDataPointer>
00035
00036 #define AKONADI_DECLARE_PRIVATE( Class ) \
00037 Class##Private* d_func(); \
00038 const Class##Private* d_func() const; \
00039 friend class Class##Private;
00040
00041 namespace Akonadi {
00042
00043 class EntityPrivate;
00044
00055 class AKONADI_EXPORT Entity
00056 {
00057 public:
00061 typedef qint64 Id;
00062
00066 ~Entity();
00067
00071 void setId( Id identifier );
00072
00076 Id id() const;
00077
00081 void setRemoteId( const QString& id );
00082
00086 QString remoteId() const;
00087
00091 bool isValid() const;
00092
00097 bool operator==( const Entity &other ) const;
00098
00103 bool operator!=( const Entity &other ) const;
00104
00108 Entity& operator=( const Entity &other );
00109
00120 void addAttribute( Attribute *attribute );
00121
00125 void removeAttribute( const QByteArray &name );
00126
00131 bool hasAttribute( const QByteArray &name ) const;
00132
00136 Attribute::List attributes() const;
00137
00141 void clearAttributes();
00142
00146 Attribute* attribute( const QByteArray &name ) const;
00147
00151 enum CreateOption
00152 {
00153 AddIfMissing
00154 };
00155
00163 template <typename T> inline T* attribute( CreateOption option )
00164 {
00165 Q_UNUSED( option );
00166
00167 const T dummy;
00168 if ( hasAttribute( dummy.type() ) )
00169 return static_cast<T*>( attribute( dummy.type() ) );
00170
00171 T* attr = new T();
00172 addAttribute( attr );
00173 return attr;
00174 }
00175
00179 template <typename T> inline T* attribute() const
00180 {
00181 const T dummy;
00182 if ( hasAttribute( dummy.type() ) )
00183 return static_cast<T*>( attribute( dummy.type() ) );
00184 return 0;
00185 }
00186
00190 template <typename T> inline void removeAttribute()
00191 {
00192 const T dummy;
00193 removeAttribute( dummy.type() );
00194 }
00195
00199 template <typename T> inline bool hasAttribute() const
00200 {
00201 const T dummy;
00202 return hasAttribute( dummy.type() );
00203 }
00204
00205 protected:
00209 Entity( const Entity &other );
00210
00211
00212 Entity( EntityPrivate *dd );
00213 QSharedDataPointer<EntityPrivate> d_ptr;
00214
00215
00216 AKONADI_DECLARE_PRIVATE( Entity )
00217 };
00218
00219 }
00220
00221 #endif