~siretart/gnucash/ubuntu-fullsource

« back to all changes in this revision

Viewing changes to src/business/business-core/gncBusGuile.c

  • Committer: Reinhard Tartler
  • Date: 2008-08-03 07:25:46 UTC
  • Revision ID: siretart@tauware.de-20080803072546-y6p8xda8zpfi62ys
import gnucash_2.2.4.orig.tar.gz

The original tarball had the md5sum: 27e660297dc5b8ce574515779d05a5a5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * gncBusGuile.c -- Business Guile Helper Functions
 
3
 * Copyright (C) 2003 Derek Atkins
 
4
 * Author: Derek Atkins <warlord@MIT.EDU>
 
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       gnu@gnu.org
 
22
 */
 
23
 
 
24
#include "config.h"
 
25
 
 
26
#include "gncBusGuile.h"
 
27
#include "engine-helpers.h"
 
28
#include "swig-runtime.h"
 
29
#define FUNC_NAME __FUNCTION__
 
30
 
 
31
static swig_type_info *
 
32
get_acct_type ()
 
33
{
 
34
  static swig_type_info * account_type = NULL;
 
35
 
 
36
  if (!account_type)
 
37
      account_type = SWIG_TypeQuery("_p_Account");
 
38
 
 
39
  return account_type;
 
40
}
 
41
 
 
42
int gnc_account_value_pointer_p (SCM arg)
 
43
{
 
44
  swig_type_info * account_type = get_acct_type();
 
45
 
 
46
  return (SCM_CONSP (arg) &&
 
47
          SWIG_IsPointerOfType(SCM_CAR (arg), account_type) &&
 
48
          gnc_numeric_p (SCM_CDR (arg)));
 
49
}
 
50
 
 
51
GncAccountValue * gnc_scm_to_account_value_ptr (SCM valuearg)
 
52
{
 
53
  GncAccountValue *res;
 
54
  Account *acc = NULL;
 
55
  gnc_numeric value;
 
56
  swig_type_info * account_type = get_acct_type();
 
57
  SCM val;
 
58
 
 
59
  /* Get the account */
 
60
  val = SCM_CAR (valuearg);
 
61
  if (!SWIG_IsPointerOfType (val, account_type))
 
62
    return NULL;
 
63
 
 
64
  acc = SWIG_MustGetPtr(val, account_type, 1, 0);
 
65
 
 
66
  /* Get the value */
 
67
  val = SCM_CDR (valuearg);
 
68
  value = gnc_scm_to_numeric (val);
 
69
 
 
70
  /* Build and return the object */
 
71
  res = g_new0 (GncAccountValue, 1);
 
72
  res->account = acc;
 
73
  res->value = value;
 
74
  return res;
 
75
}
 
76
 
 
77
SCM gnc_account_value_ptr_to_scm (GncAccountValue *av)
 
78
{
 
79
  swig_type_info * account_type = get_acct_type();
 
80
  gnc_commodity * com;
 
81
  gnc_numeric val;
 
82
 
 
83
  if (!av) return SCM_BOOL_F;
 
84
 
 
85
  com = xaccAccountGetCommodity (av->account);
 
86
  val = gnc_numeric_convert (av->value, gnc_commodity_get_fraction (com),
 
87
                             GNC_RND_ROUND);
 
88
 
 
89
  return scm_cons (SWIG_NewPointerObj(av->account, account_type, 0),
 
90
                   gnc_numeric_to_scm (val));
 
91
}