# macros.h

Go to the documentation of this file.

    00001 // -*- C++ -*-
    00002
    00003 /*
    00004  * Gnome Chemisty Utils
    00005  * macros.h
    00006  *
    00007  * Copyright (C) 2001-2008 Jean Bréfort <jean.brefort@normalesup.org>
    00008  *
    00009  * This program is free software; you can redistribute it and/or
    00010  * modify it under the terms of the GNU General Public License as
    00011  * published by the Free Software Foundation; either version 2 of the
    00012  * License, or (at your option) any later version.
    00013  *
    00014  * This program is distributed in the hope that it will be useful,
    00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00017  * GNU General Public License for more details.
    00018  *
    00019  * You should have received a copy of the GNU General Public License
    00020  * along with this program; if not, write to the Free Software
    00021  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
    00022  * USA
    00023  */
    00024
    00025 #ifndef GCU_MACROS_H
    00026 #define GCU_MACROS_H
    00027
    00028 #ifdef HAVE_GO_CONF_SYNC
    00029 #       include <goffice/app/go-conf.h>
    00030 #else
    00031 #       include <gconf/gconf-client.h>
    00032 #endif
    00033
    00054 #define GCU_PROP(type,member) \
    00055 public: \
    00056         void Set##member (type val) {m_##member = val;} \
    00057         type Get##member (void) const {return m_##member;}      \
    00058         type &GetRef##member (void) {return m_##member;}        \
    00059 private:        \
    00060         type m_##member;
    00061
    00076 #define GCU_POINTER_PROP(type,member) \
    00077 public: \
    00078         void Set##member (type *val) {m_##member = val;}        \
    00079         type *Get##member (void) {return m_##member;}   \
    00080         type const *Get##member (void) const {return m_##member;}       \
    00081 private:        \
    00082         type *m_##member;
    00083
    00097 #define GCU_RO_PROP(type,member) \
    00098 public: \
    00099         type Get##member (void) {return m_##member;}    \
    00100 private:        \
    00101         type m_##member;
    00102
    00116 #define GCU_RO_POINTER_PROP(type,member) \
    00117 public: \
    00118         type const *Get##member (void) const {return m_##member;}       \
    00119 private:        \
    00120         type *m_##member;
    00121
    00135 #define GCU_PROT_PROP(type,member) \
    00136 public: \
    00137         type Get##member (void) {return m_##member;}    \
    00138 protected:      \
    00139         type m_##member;
    00140
    00156 #define GCU_PROT_POINTER_PROP(type,member) \
    00157 public: \
    00158         type *Get##member (void) {return m_##member;}   \
    00159         type const *Get##member (void) const {return m_##member;}       \
    00160 protected:      \
    00161         type *m_##member;
    00162
    00173 #ifdef HAVE_GO_CONF_SYNC
    00174 #define go_conf_get_float go_conf_get_double
    00175 #define GCU_GCONF_GET(key,type,target,defaultval) \
    00176         target = go_conf_get_##type (m_ConfNode, key); \
    00177         if (target == (type) 0) \
    00178                 target = defaultval;
    00179 #else
    00180 #define GCU_GCONF_GET(key,type,target,defaultval) \
    00181         target = gconf_client_get_##type (m_ConfClient, ROOTDIR key, &error); \
    00182         if (error) {    \
    00183                 target = defaultval;    \
    00184                 g_message ("GConf failed: %s", error->message); \
    00185                 g_error_free (error);   \
    00186                 error = NULL;   \
    00187         }       \
    00188         if (target == (type) 0) \
    00189                 target = defaultval;
    00190 #endif
    00191
    00200 #ifdef HAVE_GO_CONF_SYNC
    00201 #define GCU_GCONF_GET_NO_CHECK(key,type,target,defaultval) \
    00202         target = go_conf_get_##type (m_ConfNode, key);
    00203 #else
    00204 #define GCU_GCONF_GET_NO_CHECK(key,type,target,defaultval) \
    00205         target = gconf_client_get_##type (m_ConfClient, ROOTDIR key, &error); \
    00206         if (error) {    \
    00207                 target = defaultval;    \
    00208                 g_message ("GConf failed: %s", error->message); \
    00209                 g_error_free (error);   \
    00210                 error = NULL;   \
    00211         }
    00212 #endif
    00213
    00225 #ifdef HAVE_GO_CONF_SYNC
    00226 #define GCU_GCONF_GET_N_TRANSFORM(key,type,target,defaultval,func) \
    00227         {       \
    00228                 type val = go_conf_get_##type (m_ConfNode, key); \
    00229                 if (val == (type) 0)    \
    00230                         val = defaultval; \
    00231                 target = func (val);    \
    00232         }
    00233 #else
    00234 #define GCU_GCONF_GET_N_TRANSFORM(key,type,target,defaultval,func) \
    00235         {       \
    00236                 type val = gconf_client_get_##type (m_ConfClient, ROOTDIR key, &error); \
    00237                 if (error) {    \
    00238                         val = defaultval;       \
    00239                         g_message ("GConf failed: %s", error->message); \
    00240                         g_error_free (error);   \
    00241                         error = NULL;   \
    00242                 }       \
    00243                 if (val == (type) 0)    \
    00244                         val = defaultval; \
    00245                 target = func (val);    \
    00246         }
    00247 #endif
    00248
    00258 #ifdef HAVE_GO_CONF_SYNC
    00259 #define GCU_GCONF_GET_STRING(key,target,defaultval) \
    00260         if (target) {   \
    00261                 g_free (target);        \
    00262                 target = NULL;  \
    00263         }       \
    00264         target = go_conf_get_string (m_ConfNode, key); \
    00265         if (target == NULL && defaultval)       \
    00266                 target = g_strdup (defaultval);
    00267 #else
    00268 #define GCU_GCONF_GET_STRING(key,target,defaultval) \
    00269         if (target) {   \
    00270                 g_free (target);        \
    00271                 target = NULL;  \
    00272         }       \
    00273         target = gconf_client_get_string (m_ConfClient, ROOTDIR key, &error); \
    00274         if (error) {    \
    00275                 if (defaultval) \
    00276                         target = g_strdup (defaultval); \
    00277                 g_message ("GConf failed: %s", error->message); \
    00278                 g_error_free (error);   \
    00279                 error = NULL;   \
    00280         } else if (target == NULL && defaultval)        \
    00281                         target = g_strdup (defaultval);
    00282 #endif
    00283
    00291 #ifdef HAVE_GO_CONF_SYNC
    00292 #define GCU_UPDATE_KEY(key,type,target,action) \
    00293         if (!strcmp (name, ROOTDIR key)) { \
    00294                 target = go_conf_get_##type (node, ((node)? key: ROOTDIR key)); \
    00295                 action \
    00296                 return; \
    00297         }
    00298 #else
    00299 #define GCU_UPDATE_KEY(key,type,target,action) \
    00300         if (!strcmp (gconf_entry_get_key (entry), ROOTDIR key)) { \
    00301                 target = gconf_value_get_##type (gconf_entry_get_value (entry)); \
    00302                 action \
    00303                 return; \
    00304         }
    00305 #endif
    00306
    00314 #ifdef HAVE_GO_CONF_SYNC
    00315 #define GCU_UPDATE_STRING_KEY(key,target,action) \
    00316         if (!strcmp (name, ROOTDIR key)) { \
    00317                 target = go_conf_get_string (node, ((node)? key: ROOTDIR key)); \
    00318                 action \
    00319                 return; \
    00320         }
    00321 #else
    00322 #define GCU_UPDATE_STRING_KEY(key,target,action) \
    00323         if (!strcmp (gconf_entry_get_key (entry), ROOTDIR key)) { \
    00324                 target = g_strdup (gconf_value_get_string (gconf_entry_get_value (entry))); \
    00325                 action \
    00326                 return; \
    00327         }
    00328 #endif
    00329
    00330 #endif  //      GCU_MACROS_H