GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
gncBusGuile.c
1 /*
2  * gncBusGuile.c -- Business Guile Helper Functions
3  * Copyright (C) 2003 Derek Atkins
4  * Author: Derek Atkins <[email protected]>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, contact:
18  *
19  * Free Software Foundation Voice: +1-617-542-5942
20  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
21  * Boston, MA 02110-1301, USA [email protected]
22  */
23 
24 #include "config.h"
25 
26 #include "gncBusGuile.h"
27 #include "engine-helpers.h"
28 #include "engine-helpers-guile.h"
29 #include "swig-runtime.h"
30 #include "guile-mappings.h"
31 #define FUNC_NAME G_STRFUNC
32 
33 static swig_type_info *
34 get_acct_type ()
35 {
36  static swig_type_info * account_type = NULL;
37 
38  if (!account_type)
39  account_type = SWIG_TypeQuery("_p_Account");
40 
41  return account_type;
42 }
43 
44 GncAccountValue * gnc_scm_to_account_value_ptr (SCM valuearg)
45 {
46  GncAccountValue *res;
47  Account *acc = NULL;
48  gnc_numeric value;
49  swig_type_info * account_type = get_acct_type();
50  SCM val;
51 
52  /* Get the account */
53  val = SCM_CAR (valuearg);
54  if (!SWIG_IsPointerOfType (val, account_type))
55  return NULL;
56 
57  acc = SWIG_MustGetPtr(val, account_type, 1, 0);
58 
59  /* Get the value */
60  val = SCM_CDR (valuearg);
61  value = gnc_scm_to_numeric (val);
62 
63  /* Build and return the object */
64  res = g_new0 (GncAccountValue, 1);
65  res->account = acc;
66  res->value = value;
67  return res;
68 }
69 
70 SCM gnc_account_value_ptr_to_scm (GncAccountValue *av)
71 {
72  swig_type_info * account_type = get_acct_type();
73  gnc_commodity * com;
74  gnc_numeric val;
75 
76  if (!av) return SCM_BOOL_F;
77 
78  com = xaccAccountGetCommodity (av->account);
79  val = gnc_numeric_convert (av->value, gnc_commodity_get_fraction (com),
81 
82  return scm_cons (SWIG_NewPointerObj(av->account, account_type, 0),
83  gnc_numeric_to_scm (val));
84 }
int gnc_commodity_get_fraction(const gnc_commodity *cm)
gnc_numeric gnc_numeric_convert(gnc_numeric n, gint64 denom, gint how)
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
Definition: Account.c:3148