* mu-msg-cache: add support for GSList* values

This commit is contained in:
Dirk-Jan C. Binnema 2011-06-15 23:48:54 +03:00
parent 2ef079968a
commit 1e629e45c7
2 changed files with 72 additions and 3 deletions

View File

@ -17,15 +17,17 @@
**
*/
#include <mu-msg-flags.h>
#include <mu-msg-prio.h>
#include "mu-msg-flags.h"
#include "mu-msg-prio.h"
#include "mu-msg-cache.h"
#include "mu-str.h"
struct _MuMsgCache {
/* all string properties */
char *_str[MU_MSG_STRING_FIELD_ID_NUM];
GSList *_refs;
time_t _timestamp, _date;
size_t _size;
@ -123,6 +125,49 @@ mu_msg_cache_str (MuMsgCache *cache, MuMsgFieldId mfid)
const GSList*
mu_msg_cache_set_str_list (MuMsgCache *self, MuMsgFieldId mfid,
GSList *lst, gboolean do_free)
{
g_return_val_if_fail(self, NULL);
g_return_val_if_fail(mu_msg_field_is_string_list(mfid), NULL);
switch (mfid) {
case MU_MSG_FIELD_ID_REFS:
if (is_allocated(self, mfid))
mu_str_free_list (self->_refs);
self->_refs = lst;
break;
default:
g_return_val_if_reached(NULL);
return NULL;
}
set_cached (self, mfid);
if (do_free)
set_allocated (self, mfid);
else
reset_allocated (self, mfid);
return lst;
}
const GSList*
mu_msg_cache_str_list (MuMsgCache *self, MuMsgFieldId mfid)
{
g_return_val_if_fail (mu_msg_field_is_string_list(mfid), NULL);
switch (mfid) {
case MU_MSG_FIELD_ID_REFS:
return self->_refs;
default:
g_return_val_if_reached(NULL);
return NULL;
}
}
gint64
mu_msg_cache_set_num (MuMsgCache *self, MuMsgFieldId mfid, gint64 val)

View File

@ -84,6 +84,30 @@ const char* mu_msg_cache_str (MuMsgCache *cache, MuMsgFieldId mfid);
/**
* cache a string-list value
*
* @param self a mumsgcache
* @param mfid the MessageFieldId for a string-list value
* @param lst the list
* @param do_free whether the cache should free this value (i.e, take ownership)
*
* @return
*/
const GSList* mu_msg_cache_set_str_list (MuMsgCache *self, MuMsgFieldId mfid,
GSList *lst, gboolean do_free);
/**
* get a string-list value from the cache
*
* @param cache a MuMsgCache
* @param mfid the MessageFieldId for string-list value
*
* @return a list, which should not be modified
*/
const GSList* mu_msg_cache_str_list (MuMsgCache *cache, MuMsgFieldId mfid);
/**
* add a numeric value to the cache
*