Merge branch 'next'

This commit is contained in:
John Wiegley 2009-11-05 04:24:15 -05:00
commit 15555d497f
61 changed files with 940 additions and 1054 deletions

18
acprep
View file

@ -19,6 +19,7 @@ import string
import sys
import time
import tempfile
import datetime
try:
import hashlib
@ -181,8 +182,7 @@ class PrepareBuild(CommandLineApp):
self.current_flavor = 'debug'
self.products_dir = None
self.build_dir = self.source_dir
self.configure_args = ['--disable-shared',
'--with-included-gettext']
self.configure_args = ['--with-included-gettext']
self.sys_include_dirs = []
self.sys_library_dirs = []
@ -385,8 +385,14 @@ class PrepareBuild(CommandLineApp):
def current_version(self):
if not self.current_ver:
if exists('.git') and isdir('.git'):
tag = self.get_stdout('git', 'describe', '--all', '--long')
self.current_ver = re.sub('heads/', '', tag)
date = self.get_stdout('git', 'log', '--format=%ci', 'HEAD^..HEAD')
date = re.sub(" [-+][0-9][0-9][0-9][0-9]$", "", date)
when = datetime.datetime.strptime(date, "%Y-%m-%d %H:%M:%S")
self.current_ver = when.strftime("%Y%m%d_%H%M%S")
commit = self.get_stdout('git', 'log', '--format=%h', 'HEAD^..HEAD')
self.current_ver += "_" + commit
#tag = self.get_stdout('git', 'describe', '--all', '--long')
#self.current_ver = re.sub('heads/', '', tag)
else:
self.current_ver = "3.0a"
return self.current_ver
@ -472,7 +478,7 @@ class PrepareBuild(CommandLineApp):
def phase_version(self, *args):
self.log.info('Executing phase: version')
version_m4 = open('version.m4', 'w')
version_m4.write("m4_define([VERSION_NUMBER], [%s])" %
version_m4.write("m4_define([VERSION_NUMBER], [%s])\n" %
self.current_version())
version_m4.close()
@ -749,6 +755,8 @@ class PrepareBuild(CommandLineApp):
self.CXXFLAGS.append('-msse3')
self.CPPFLAGS.append('-D_GLIBCXX_FULLY_DYNAMIC_STRING=1')
self.configure_args.append('--disable-shared')
self.options.use_glibcxx_debug = True
self.locate_my_libraries()

@ -1 +1 @@
Subproject commit 629800e376c01b261a5116b2ba8702711ad8acee
Subproject commit 200cf64535a8a2545414e993349f6c87c8dd64ba

View file

@ -241,8 +241,12 @@ namespace {
}
}
expr_t::ptr_op_t account_t::lookup(const string& name)
expr_t::ptr_op_t account_t::lookup(const symbol_t::kind_t kind,
const string& name)
{
if (kind != symbol_t::FUNCTION)
return NULL;
switch (name[0]) {
case 'a':
if (name == "amount")
@ -378,6 +382,15 @@ account_t::xdata_t::details_t::operator+=(const details_t& other)
return *this;
}
void account_t::clear_xdata()
{
xdata_ = none;
foreach (accounts_map::value_type& pair, accounts)
if (! pair.second->has_flags(ACCOUNT_TEMP))
pair.second->clear_xdata();
}
value_t account_t::amount(const optional<expr_t&>& expr) const
{
if (xdata_ && xdata_->has_flags(ACCOUNT_EXT_VISITED)) {

View file

@ -114,12 +114,33 @@ public:
account_t * find_account(const string& name, bool auto_create = true);
account_t * find_account_re(const string& regexp);
typedef transform_iterator<function<account_t *(accounts_map::value_type&)>,
accounts_map::iterator>
accounts_map_seconds_iterator;
accounts_map_seconds_iterator accounts_begin() {
return make_transform_iterator
(accounts.begin(), bind(&accounts_map::value_type::second, _1));
}
accounts_map_seconds_iterator accounts_end() {
return make_transform_iterator
(accounts.end(), bind(&accounts_map::value_type::second, _1));
}
void add_post(post_t * post) {
posts.push_back(post);
}
bool remove_post(post_t * post);
virtual expr_t::ptr_op_t lookup(const string& name);
posts_list::iterator posts_begin() {
return posts.begin();
}
posts_list::iterator posts_end() {
return posts.end();
}
virtual expr_t::ptr_op_t lookup(const symbol_t::kind_t kind,
const string& name);
bool valid() const;
@ -209,9 +230,7 @@ public:
bool has_xdata() const {
return xdata_;
}
void clear_xdata() {
xdata_ = none;
}
void clear_xdata();
xdata_t& xdata() {
if (! xdata_)
xdata_ = xdata_t();

View file

@ -188,9 +188,10 @@ protected:
public:
explicit base_t(const string& _symbol)
: supports_flags<uint_least16_t>(commodity_t::european_by_default ?
COMMODITY_STYLE_EUROPEAN :
COMMODITY_STYLE_DEFAULTS),
: supports_flags<uint_least16_t>
(commodity_t::european_by_default ?
static_cast<uint_least16_t>(COMMODITY_STYLE_EUROPEAN) :
static_cast<uint_least16_t>(COMMODITY_STYLE_DEFAULTS)),
symbol(_symbol), precision(0), searched(false) {
TRACE_CTOR(base_t, "const string&");
}

View file

@ -70,19 +70,6 @@ public:
virtual void operator()(post_t&) {}
};
/**
* @brief Brief
*
* Long.
*/
class clear_post_xdata : public item_handler<post_t>
{
public:
virtual void operator()(post_t& post) {
post.clear_xdata();
}
};
class posts_iterator;
/**
@ -790,19 +777,6 @@ class forecast_posts : public generate_posts
// Account filters
//
/**
* @brief Brief
*
* Long.
*/
class clear_account_xdata : public item_handler<account_t>
{
public:
virtual void operator()(account_t& acct) {
acct.clear_xdata();
}
};
class accounts_iterator;
/**

View file

@ -67,6 +67,7 @@ global_scope_t::global_scope_t(char ** envp)
// open document, with a separate report_t object for each report it
// generated.
report_stack.push_front(new report_t(session()));
scope_t::default_scope = &report();
// Read the user's options, in the following order:
//
@ -111,7 +112,7 @@ void global_scope_t::read_init()
ifstream init(init_file);
if (session().read_journal(init_file, NULL, &report()) > 0 ||
if (session().journal->read(init_file, NULL, &report()) > 0 ||
session().journal->auto_xacts.size() > 0 ||
session().journal->period_xacts.size() > 0) {
throw_(parse_error, _("Transactions found in initialization file '%1'")
@ -314,28 +315,32 @@ option_t<global_scope_t> * global_scope_t::lookup_option(const char * p)
return NULL;
}
expr_t::ptr_op_t global_scope_t::lookup(const string& name)
expr_t::ptr_op_t global_scope_t::lookup(const symbol_t::kind_t kind,
const string& name)
{
const char * p = name.c_str();
switch (*p) {
case 'o':
if (WANT_OPT()) { p += OPT_PREFIX_LEN;
if (option_t<global_scope_t> * handler = lookup_option(p))
return MAKE_OPT_HANDLER(global_scope_t, handler);
}
switch (kind) {
case symbol_t::FUNCTION:
if (option_t<global_scope_t> * handler = lookup_option(name.c_str()))
return MAKE_OPT_FUNCTOR(global_scope_t, handler);
break;
case symbol_t::OPTION:
if (option_t<global_scope_t> * handler = lookup_option(name.c_str()))
return MAKE_OPT_HANDLER(global_scope_t, handler);
break;
case symbol_t::PRECOMMAND: {
const char * p = name.c_str();
switch (*p) {
case 'p':
if (WANT_PRECMD()) { const char * q = p + PRECMD_PREFIX_LEN;
switch (*q) {
case 'p':
if (is_eq(q, "push"))
if (is_eq(p, "push"))
return MAKE_FUNCTOR(global_scope_t::push_command);
else if (is_eq(q, "pop"))
else if (is_eq(p, "pop"))
return MAKE_FUNCTOR(global_scope_t::pop_command);
break;
}
}
default:
break;
}
@ -396,7 +401,7 @@ void global_scope_t::normalize_session_options()
function_t global_scope_t::look_for_precommand(scope_t& scope,
const string& verb)
{
if (expr_t::ptr_op_t def = scope.lookup(string(PRECMD_PREFIX) + verb))
if (expr_t::ptr_op_t def = scope.lookup(symbol_t::PRECOMMAND, verb))
return def->as_function();
else
return function_t();
@ -405,7 +410,7 @@ function_t global_scope_t::look_for_precommand(scope_t& scope,
function_t global_scope_t::look_for_command(scope_t& scope,
const string& verb)
{
if (expr_t::ptr_op_t def = scope.lookup(string(CMD_PREFIX) + verb))
if (expr_t::ptr_op_t def = scope.lookup(symbol_t::COMMAND, verb))
return def->as_function();
else
return function_t();

View file

@ -75,10 +75,14 @@ public:
void push_report() {
report_stack.push_front(new report_t(report_stack.front()));
scope_t::default_scope = &report();
}
void pop_report() {
if (! report_stack.empty())
assert(! report_stack.empty());
report_stack.pop_front();
// There should always be the "default report" waiting on the stack.
assert(! report_stack.empty());
scope_t::default_scope = &report();
}
void report_error(const std::exception& err);
@ -117,7 +121,8 @@ See LICENSE file included with the distribution for details and disclaimer.");
option_t<global_scope_t> * lookup_option(const char * p);
virtual expr_t::ptr_op_t lookup(const string& name);
virtual expr_t::ptr_op_t lookup(const symbol_t::kind_t kind,
const string& name);
OPTION(global_scope_t, args_only);
OPTION(global_scope_t, debug_);

View file

@ -304,8 +304,12 @@ value_t get_comment(item_t& item)
}
}
expr_t::ptr_op_t item_t::lookup(const string& name)
expr_t::ptr_op_t item_t::lookup(const symbol_t::kind_t kind,
const string& name)
{
if (kind != symbol_t::FUNCTION)
return NULL;
switch (name[0]) {
case 'a':
if (name == "actual")

View file

@ -189,7 +189,8 @@ public:
return _state;
}
virtual expr_t::ptr_op_t lookup(const string& name);
virtual expr_t::ptr_op_t lookup(const symbol_t::kind_t kind,
const string& name);
bool valid() const;

View file

@ -41,23 +41,23 @@
namespace ledger {
journal_t::journal_t()
: master(new account_t), was_loaded(false),
commodity_pool(new commodity_pool_t)
{
TRACE_CTOR(journal_t, "");
initialize();
}
// Add time commodity conversions, so that timelog's may be parsed
// in terms of seconds, but reported as minutes or hours.
if (commodity_t * commodity = commodity_pool->create("s"))
commodity->add_flags(COMMODITY_BUILTIN | COMMODITY_NOMARKET);
else
assert(false);
journal_t::journal_t(const path& pathname)
{
TRACE_CTOR(journal_t, "path");
initialize();
read(pathname);
}
// Add a "percentile" commodity
if (commodity_t * commodity = commodity_pool->create("%"))
commodity->add_flags(COMMODITY_BUILTIN | COMMODITY_NOMARKET);
else
assert(false);
journal_t::journal_t(const string& str)
{
TRACE_CTOR(journal_t, "string");
initialize();
read(str);
}
journal_t::~journal_t()
@ -80,6 +80,28 @@ journal_t::~journal_t()
commodity_pool.reset();
}
void journal_t::initialize()
{
master = new account_t;
basket = NULL;
was_loaded = false;
commodity_pool.reset(new commodity_pool_t);
// Add time commodity conversions, so that timelog's may be parsed
// in terms of seconds, but reported as minutes or hours.
if (commodity_t * commodity = commodity_pool->create("s"))
commodity->add_flags(COMMODITY_BUILTIN | COMMODITY_NOMARKET);
else
assert(false);
// Add a "percentile" commodity
if (commodity_t * commodity = commodity_pool->create("%"))
commodity->add_flags(COMMODITY_BUILTIN | COMMODITY_NOMARKET);
else
assert(false);
}
void journal_t::add_account(account_t * acct)
{
master->add_account(acct);
@ -134,6 +156,72 @@ bool journal_t::remove_xact(xact_t * xact)
return true;
}
std::size_t journal_t::read(std::istream& in,
const path& pathname,
account_t * master_alt,
scope_t * scope)
{
std::size_t count = 0;
try {
if (! scope)
scope = scope_t::default_scope;
if (! scope)
throw_(std::runtime_error,
_("No default scope in which to read journal file '%1'")
<< pathname);
value_t strict = expr_t("strict").calc(*scope);
count = parse(in, *scope, master_alt ? master_alt : master,
&pathname, strict.to_boolean());
}
catch (...) {
clear_xdata();
throw;
}
// xdata may have been set for some accounts and transaction due to the use
// of balance assertions or other calculations performed in valexpr-based
// posting amounts.
clear_xdata();
return count;
}
std::size_t journal_t::read(const path& pathname,
account_t * master,
scope_t * scope)
{
path filename = resolve_path(pathname);
if (! exists(filename))
throw_(std::runtime_error,
_("Cannot read journal file '%1'") << filename);
ifstream stream(filename);
std::size_t count = read(stream, filename, master, scope);
sources.push_back(fileinfo_t(filename));
return count;
}
void journal_t::clear_xdata()
{
foreach (xact_t * xact, xacts)
if (! xact->has_flags(ITEM_TEMP))
xact->clear_xdata();
foreach (auto_xact_t * xact, auto_xacts)
if (! xact->has_flags(ITEM_TEMP))
xact->clear_xdata();
foreach (period_xact_t * xact, period_xacts)
if (! xact->has_flags(ITEM_TEMP))
xact->clear_xdata();
master->clear_xdata();
}
bool journal_t::valid() const
{
if (! master->valid()) {

View file

@ -126,8 +126,19 @@ public:
hooks_t<xact_finalizer_t, xact_t> xact_finalize_hooks;
journal_t();
journal_t(const path& pathname);
journal_t(const string& str);
~journal_t();
void initialize();
std::list<fileinfo_t>::iterator sources_begin() {
return sources.begin();
}
std::list<fileinfo_t>::iterator sources_end() {
return sources.end();
}
// These four methods are delegated to the current session, since all
// accounts processed are gathered together at the session level.
void add_account(account_t * acct);
@ -138,6 +149,25 @@ public:
bool add_xact(xact_t * xact);
bool remove_xact(xact_t * xact);
xacts_list::iterator xacts_begin() {
return xacts.begin();
}
xacts_list::iterator xacts_end() {
return xacts.end();
}
auto_xacts_list::iterator auto_xacts_begin() {
return auto_xacts.begin();
}
auto_xacts_list::iterator auto_xacts_end() {
return auto_xacts.end();
}
period_xacts_list::iterator period_xacts_begin() {
return period_xacts.begin();
}
period_xacts_list::iterator period_xacts_end() {
return period_xacts.end();
}
void add_xact_finalizer(xact_finalizer_t * finalizer) {
xact_finalize_hooks.add_hook(finalizer);
}
@ -145,12 +175,22 @@ public:
xact_finalize_hooks.remove_hook(finalizer);
}
std::size_t read(std::istream& in,
const path& pathname,
account_t * master = NULL,
scope_t * scope = NULL);
std::size_t read(const path& pathname,
account_t * master = NULL,
scope_t * scope = NULL);
std::size_t parse(std::istream& in,
scope_t& session_scope,
account_t * master = NULL,
const path * original_file = NULL,
bool strict = false);
void clear_xdata();
bool valid() const;
#if defined(HAVE_BOOST_SERIALIZATION)

View file

@ -43,7 +43,7 @@ expr_t::ptr_op_t expr_t::op_t::compile(scope_t& scope, const int depth)
if (is_ident()) {
DEBUG("expr.compile", "lookup: " << as_ident());
if (ptr_op_t def = scope.lookup(as_ident())) {
if (ptr_op_t def = scope.lookup(symbol_t::FUNCTION, as_ident())) {
// Identifier references are first looked up at the point of
// definition, and then at the point of every use if they could
// not be found there.
@ -65,11 +65,11 @@ expr_t::ptr_op_t expr_t::op_t::compile(scope_t& scope, const int depth)
if (kind == O_DEFINE) {
switch (left()->kind) {
case IDENT:
scope.define(left()->as_ident(), right());
scope.define(symbol_t::FUNCTION, left()->as_ident(), right());
break;
case O_CALL:
if (left()->left()->is_ident())
scope.define(left()->left()->as_ident(), this);
scope.define(symbol_t::FUNCTION, left()->left()->as_ident(), this);
else
throw_(compile_error, _("Invalid function definition"));
break;
@ -152,9 +152,10 @@ value_t expr_t::op_t::calc(scope_t& scope, ptr_op_t * locus, const int depth)
if (! varname->is_ident())
throw_(calc_error, _("Invalid function definition"));
else if (args_index == args_count)
local_scope.define(varname->as_ident(), wrap_value(false));
local_scope.define(symbol_t::FUNCTION, varname->as_ident(),
wrap_value(false));
else
local_scope.define(varname->as_ident(),
local_scope.define(symbol_t::FUNCTION, varname->as_ident(),
wrap_value(call_args[args_index++]));
}
@ -178,7 +179,8 @@ value_t expr_t::op_t::calc(scope_t& scope, ptr_op_t * locus, const int depth)
_("Left operand of . operator is NULL"));
} else {
scope_t& objscope(*obj.as_scope());
if (ptr_op_t member = objscope.lookup(right()->as_ident())) {
if (ptr_op_t member =
objscope.lookup(symbol_t::FUNCTION, right()->as_ident())) {
result = member->calc(objscope, NULL, depth + 1);
break;
}

View file

@ -41,8 +41,7 @@ namespace {
op_bool_tuple find_option(scope_t& scope, const string& name)
{
char buf[128];
std::strcpy(buf, "opt_");
char * p = &buf[4];
char * p = buf;
foreach (char ch, name) {
if (ch == '-')
*p++ = '_';
@ -52,28 +51,27 @@ namespace {
*p++ = '_';
*p = '\0';
if (expr_t::ptr_op_t op = scope.lookup(buf))
if (expr_t::ptr_op_t op = scope.lookup(symbol_t::OPTION, buf))
return op_bool_tuple(op, true);
*--p = '\0';
return op_bool_tuple(scope.lookup(buf), false);
return op_bool_tuple(scope.lookup(symbol_t::OPTION, buf), false);
}
op_bool_tuple find_option(scope_t& scope, const char letter)
{
char buf[10];
std::strcpy(buf, "opt_");
buf[4] = letter;
buf[5] = '_';
buf[6] = '\0';
char buf[4];
buf[0] = letter;
buf[1] = '_';
buf[2] = '\0';
if (expr_t::ptr_op_t op = scope.lookup(buf))
if (expr_t::ptr_op_t op = scope.lookup(symbol_t::OPTION, buf))
return op_bool_tuple(op, true);
buf[5] = '\0';
buf[1] = '\0';
return op_bool_tuple(scope.lookup(buf), false);
return op_bool_tuple(scope.lookup(symbol_t::OPTION, buf), false);
}
void process_option(const string& whence, const function_t& opt,

View file

@ -190,6 +190,7 @@ public:
virtual value_t operator()(call_scope_t& args) {
if (! args.empty()) {
args.push_front(string_value("?expr"));
return handler_wrapper(args);
}
else if (wants_arg) {
@ -282,30 +283,6 @@ inline bool is_eq(const char * p, const char * n) {
} \
END(name)
#define OPT_PREFIX "opt_"
#define OPT_PREFIX_LEN 4
#define WANT_OPT() \
(std::strncmp(p, OPT_PREFIX, OPT_PREFIX_LEN) == 0)
#define PRECMD_PREFIX "precmd_"
#define PRECMD_PREFIX_LEN 7
#define WANT_PRECMD() \
(std::strncmp(p, PRECMD_PREFIX, PRECMD_PREFIX_LEN) == 0)
#define CMD_PREFIX "cmd_"
#define CMD_PREFIX_LEN 4
#define WANT_CMD() \
(std::strncmp(p, CMD_PREFIX, CMD_PREFIX_LEN) == 0)
#define DIR_PREFIX "dir_"
#define DIR_PREFIX_LEN 4
#define WANT_DIR() \
(std::strncmp(p, DIR_PREFIX, DIR_PREFIX_LEN) == 0)
bool process_option(const string& whence, const string& name, scope_t& scope,
const char * arg, const string& varname);

View file

@ -271,8 +271,12 @@ namespace {
}
}
expr_t::ptr_op_t post_t::lookup(const string& name)
expr_t::ptr_op_t post_t::lookup(const symbol_t::kind_t kind,
const string& name)
{
if (kind != symbol_t::FUNCTION)
return item_t::lookup(kind, name);
switch (name[0]) {
case 'a':
if (name[1] == '\0' || name == "amount")
@ -366,7 +370,7 @@ expr_t::ptr_op_t post_t::lookup(const string& name)
break;
}
return item_t::lookup(name);
return item_t::lookup(kind, name);
}
bool post_t::valid() const

View file

@ -119,7 +119,8 @@ public:
return ! has_flags(POST_VIRTUAL) || has_flags(POST_MUST_BALANCE);
}
virtual expr_t::ptr_op_t lookup(const string& name);
virtual expr_t::ptr_op_t lookup(const symbol_t::kind_t kind,
const string& name);
bool valid() const;

View file

@ -67,7 +67,7 @@ namespace {
{
std::istringstream in(str);
report.session.journal->parse(in, report.session);
report.session.clean_accounts();
report.session.journal->clear_xdata();
}
}
xact_t * first = report.session.journal->xacts.front();
@ -231,6 +231,9 @@ value_t args_command(call_scope_t& args)
out << std::endl << std::endl;
std::pair<expr_t, query_parser_t> info = args_to_predicate(begin, end);
if (! info.first)
throw_(std::runtime_error,
_("Invalid query predicate: %1") << join_args(args));
call_scope_t sub_args(static_cast<scope_t&>(args));
sub_args.push_back(string_value(info.first.text()));
@ -242,8 +245,12 @@ value_t args_command(call_scope_t& args)
<< std::endl << std::endl;
call_scope_t disp_sub_args(static_cast<scope_t&>(args));
disp_sub_args.push_back
(string_value(args_to_predicate(info.second).first.text()));
info = args_to_predicate(info.second);
if (! info.first)
throw_(std::runtime_error,
_("Invalid display predicate: %1") << join_args(args));
disp_sub_args.push_back(string_value(info.first.text()));
parse_command(disp_sub_args);
}

View file

@ -299,8 +299,7 @@ std::pair<expr_t, query_parser_t>
args_to_predicate(value_t::sequence_t::const_iterator begin,
value_t::sequence_t::const_iterator end);
std::pair<expr_t, query_parser_t>
args_to_predicate(query_parser_t parser);
std::pair<expr_t, query_parser_t> args_to_predicate(query_parser_t parser);
} // namespace ledger

View file

@ -142,9 +142,10 @@ void export_account()
class_< account_t::xdata_t > ("AccountXData")
#if 1
.def("flags", &supports_flags<uint_least16_t>::flags)
.add_property("flags",
&supports_flags<uint_least16_t>::flags,
&supports_flags<uint_least16_t>::set_flags)
.def("has_flags", &supports_flags<uint_least16_t>::has_flags)
.def("set_flags", &supports_flags<uint_least16_t>::set_flags)
.def("clear_flags", &supports_flags<uint_least16_t>::clear_flags)
.def("add_flags", &supports_flags<uint_least16_t>::add_flags)
.def("drop_flags", &supports_flags<uint_least16_t>::drop_flags)
@ -162,9 +163,10 @@ void export_account()
class_< account_t > ("Account")
#if 1
.def("flags", &supports_flags<>::flags)
.add_property("flags",
&supports_flags<>::flags,
&supports_flags<>::set_flags)
.def("has_flags", &supports_flags<>::has_flags)
.def("set_flags", &supports_flags<>::set_flags)
.def("clear_flags", &supports_flags<>::clear_flags)
.def("add_flags", &supports_flags<>::add_flags)
.def("drop_flags", &supports_flags<>::drop_flags)
@ -172,13 +174,11 @@ void export_account()
.add_property("parent",
make_getter(&account_t::parent,
return_value_policy<reference_existing_object>()))
return_internal_reference<>()))
.def_readwrite("name", &account_t::name)
.def_readwrite("note", &account_t::note)
.def_readonly("depth", &account_t::depth)
.def_readonly("accounts", &account_t::accounts)
.def_readonly("posts", &account_t::posts)
.def(self_ns::str(self))
@ -199,7 +199,14 @@ void export_account()
.def("valid", &account_t::valid)
.def("__len__", accounts_len)
.def("__getitem__", accounts_getitem, return_internal_reference<1>())
.def("__getitem__", accounts_getitem, return_internal_reference<>())
.def("__iter__", range<return_internal_reference<> >
(&account_t::accounts_begin, &account_t::accounts_end))
.def("accounts", range<return_internal_reference<> >
(&account_t::accounts_begin, &account_t::accounts_end))
.def("posts", range<return_internal_reference<> >
(&account_t::posts_begin, &account_t::posts_end))
.def("has_xdata", &account_t::has_xdata)
.def("clear_xdata", &account_t::clear_xdata)

View file

@ -214,6 +214,12 @@ void export_balance()
.def("valid", &balance_t::valid)
;
register_optional_to_python<balance_t>();
implicitly_convertible<long, balance_t>();
implicitly_convertible<string, balance_t>();
implicitly_convertible<amount_t, balance_t>();
#define EXC_TRANSLATE(type) \
register_exception_translator<type>(&exc_translate_ ## type);

View file

@ -1,62 +0,0 @@
/*
* Copyright (c) 2003-2009, John Wiegley. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of New Artisans LLC nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <system.hh>
#include "pyinterp.h"
namespace ledger {
using namespace boost::python;
#define EXC_TRANSLATOR(type) \
void exc_translate_ ## type(const type& err) { \
PyErr_SetString(PyExc_ArithmeticError, err.what()); \
}
//EXC_TRANSLATOR(chain_error)
void export_chain()
{
#if 0
struct_< item_handler_t > ("ItemHandler")
;
#endif
//register_optional_to_python<amount_t>();
#define EXC_TRANSLATE(type) \
register_exception_translator<type>(&exc_translate_ ## type);
//EXC_TRANSLATE(chain_error);
}
} // namespace ledger

View file

@ -130,12 +130,12 @@ void export_commodity()
class_< commodity_pool_t, boost::noncopyable > ("CommodityPool", no_init)
.add_property("null_commodity",
make_getter(&commodity_pool_t::null_commodity,
return_value_policy<reference_existing_object>()),
return_internal_reference<>()),
make_setter(&commodity_pool_t::null_commodity,
with_custodian_and_ward<1, 2>()))
.add_property("default_commodity",
make_getter(&commodity_pool_t::default_commodity,
return_value_policy<reference_existing_object>()),
return_internal_reference<>()),
make_setter(&commodity_pool_t::default_commodity,
with_custodian_and_ward<1, 2>()))
@ -189,9 +189,10 @@ void export_commodity()
class_< commodity_t, boost::noncopyable > ("Commodity", no_init)
#if 1
.def("flags", &delegates_flags<uint_least16_t>::flags)
.add_property("flags",
&supports_flags<uint_least16_t>::flags,
&supports_flags<uint_least16_t>::set_flags)
.def("has_flags", &delegates_flags<uint_least16_t>::has_flags)
.def("set_flags", &delegates_flags<uint_least16_t>::set_flags)
.def("clear_flags", &delegates_flags<uint_least16_t>::clear_flags)
.def("add_flags", &delegates_flags<uint_least16_t>::add_flags)
.def("drop_flags", &delegates_flags<uint_least16_t>::drop_flags)
@ -248,9 +249,9 @@ void export_commodity()
class_< annotation_t > ("Annotation", no_init)
#if 1
.def("flags", &supports_flags<>::flags)
.add_property("flags", &supports_flags<>::flags,
&supports_flags<>::set_flags)
.def("has_flags", &supports_flags<>::has_flags)
.def("set_flags", &supports_flags<>::set_flags)
.def("clear_flags", &supports_flags<>::clear_flags)
.def("add_flags", &supports_flags<>::add_flags)
.def("drop_flags", &supports_flags<>::drop_flags)

View file

@ -1,64 +0,0 @@
/*
* Copyright (c) 2003-2009, John Wiegley. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of New Artisans LLC nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <system.hh>
#include "pyinterp.h"
namespace ledger {
using namespace boost::python;
#define EXC_TRANSLATOR(type) \
void exc_translate_ ## type(const type& err) { \
PyErr_SetString(PyExc_ArithmeticError, err.what()); \
}
//EXC_TRANSLATOR(global_error)
void export_global()
{
#if 0
class_< global_scope_t > ("GlobalScope")
;
#endif
//register_optional_to_python<amount_t>();
//implicitly_convertible<string, amount_t>();
#define EXC_TRANSLATE(type) \
register_exception_translator<type>(&exc_translate_ ## type);
//EXC_TRANSLATE(global_error);
}
} // namespace ledger

View file

@ -109,9 +109,9 @@ void export_item()
class_< item_t > ("JournalItem", init<uint_least8_t>())
#endif
#if 1
.def("flags", &supports_flags<>::flags)
.add_property("flags", &supports_flags<>::flags,
&supports_flags<>::set_flags)
.def("has_flags", &supports_flags<>::has_flags)
.def("set_flags", &supports_flags<>::set_flags)
.def("clear_flags", &supports_flags<>::clear_flags)
.def("add_flags", &supports_flags<>::add_flags)
.def("drop_flags", &supports_flags<>::drop_flags)
@ -138,6 +138,9 @@ void export_item()
.def("get_tag", py_get_tag_1s)
.def("get_tag", py_get_tag_1m)
.def("get_tag", py_get_tag_2m)
.def("tag", py_get_tag_1s)
.def("tag", py_get_tag_1m)
.def("tag", py_get_tag_2m)
.def("set_tag", &item_t::set_tag)
@ -148,11 +151,11 @@ void export_item()
make_getter(&item_t::use_effective_date),
make_setter(&item_t::use_effective_date))
.def("date", &item_t::date)
.def("effective_date", &item_t::effective_date)
.add_property("date", &item_t::date, make_setter(&item_t::_date))
.add_property("effective_date", &item_t::effective_date,
make_setter(&item_t::_date_eff))
.def("set_state", &item_t::set_state)
.def("state", &item_t::state)
.add_property("state", &item_t::state, &item_t::set_state)
.def("lookup", &item_t::lookup)

View file

@ -171,6 +171,8 @@ namespace {
void export_journal()
{
class_< journal_t::fileinfo_t > ("FileInfo")
.def(init<path>())
.add_property("filename",
make_getter(&journal_t::fileinfo_t::filename),
make_setter(&journal_t::fileinfo_t::filename))
@ -186,17 +188,19 @@ void export_journal()
;
class_< journal_t, boost::noncopyable > ("Journal")
.def(init<path>())
.def(init<string>())
.add_property("master", make_getter(&journal_t::master,
return_internal_reference<1>()))
return_internal_reference<>()))
.add_property("basket",
make_getter(&journal_t::basket,
return_internal_reference<1>()),
return_internal_reference<>()),
make_setter(&journal_t::basket))
.add_property("sources", make_getter(&journal_t::sources))
.add_property("was_loaded", make_getter(&journal_t::was_loaded))
.add_property("commodity_pool",
make_getter(&journal_t::commodity_pool,
return_internal_reference<1>()))
return_internal_reference<>()))
#if 0
.add_property("xact_finalize_hooks",
make_getter(&journal_t::xact_finalize_hooks),
@ -206,10 +210,10 @@ void export_journal()
.def("add_account", &journal_t::add_account)
.def("remove_account", &journal_t::remove_account)
.def("find_account", py_find_account_1, return_internal_reference<1>())
.def("find_account", py_find_account_2, return_internal_reference<1>())
.def("find_account", py_find_account_1, return_internal_reference<>())
.def("find_account", py_find_account_2, return_internal_reference<>())
.def("find_account_re", &journal_t::find_account_re,
return_internal_reference<1>())
return_internal_reference<>())
.def("add_xact", &journal_t::add_xact)
.def("remove_xact", &journal_t::remove_xact)
@ -221,6 +225,19 @@ void export_journal()
.def("__len__", xacts_len)
.def("__getitem__", xacts_getitem, return_internal_reference<1>())
.def("__iter__", range<return_internal_reference<> >
(&journal_t::xacts_begin, &journal_t::xacts_end))
.def("xacts", range<return_internal_reference<> >
(&journal_t::xacts_begin, &journal_t::xacts_end))
.def("auto_xacts", range<return_internal_reference<> >
(&journal_t::auto_xacts_begin, &journal_t::auto_xacts_end))
.def("period_xacts", range<return_internal_reference<> >
(&journal_t::period_xacts_begin, &journal_t::period_xacts_end))
.def("sources", range<return_internal_reference<> >
(&journal_t::sources_begin, &journal_t::sources_end))
.def("clear_xdata", &journal_t::clear_xdata)
.def("valid", &journal_t::valid)
;
}

View file

@ -87,9 +87,10 @@ void export_post()
class_< post_t::xdata_t > ("PostingXData")
#if 1
.def("flags", &supports_flags<uint_least16_t>::flags)
.add_property("flags",
&supports_flags<uint_least16_t>::flags,
&supports_flags<uint_least16_t>::set_flags)
.def("has_flags", &supports_flags<uint_least16_t>::has_flags)
.def("set_flags", &supports_flags<uint_least16_t>::set_flags)
.def("clear_flags", &supports_flags<uint_least16_t>::clear_flags)
.def("add_flags", &supports_flags<uint_least16_t>::add_flags)
.def("drop_flags", &supports_flags<uint_least16_t>::drop_flags)
@ -131,12 +132,12 @@ void export_post()
.add_property("xact",
make_getter(&post_t::xact,
return_value_policy<reference_existing_object>()),
return_internal_reference<>()),
make_setter(&post_t::xact,
with_custodian_and_ward<1, 2>()))
.add_property("account",
make_getter(&post_t::account,
return_value_policy<reference_existing_object>()),
return_internal_reference<>()),
make_setter(&post_t::account,
with_custodian_and_ward<1, 2>()))
.add_property("amount",

View file

@ -1,64 +0,0 @@
/*
* Copyright (c) 2003-2009, John Wiegley. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of New Artisans LLC nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <system.hh>
#include "pyinterp.h"
namespace ledger {
using namespace boost::python;
#define EXC_TRANSLATOR(type) \
void exc_translate_ ## type(const type& err) { \
PyErr_SetString(PyExc_ArithmeticError, err.what()); \
}
//EXC_TRANSLATOR(report_error)
void export_report()
{
#if 0
class_< report_t > ("Report")
;
#endif
//register_optional_to_python<amount_t>();
//implicitly_convertible<string, amount_t>();
#define EXC_TRANSLATE(type) \
register_exception_translator<type>(&exc_translate_ ## type);
//EXC_TRANSLATE(report_error);
}
} // namespace ledger

View file

@ -38,59 +38,17 @@ namespace ledger {
using namespace boost::python;
namespace {
void py_scope_define(scope_t& scope, const string& name, expr_t& def)
{
return scope.define(name, def.get_op());
}
expr_t py_scope_lookup(scope_t& scope, const string& name)
{
return scope.lookup(name);
}
value_t py_scope_getattr(scope_t& scope, const string& name)
{
return expr_t(scope.lookup(name)).calc(scope);
}
struct scope_wrapper : public scope_t
{
PyObject * self;
scope_wrapper(PyObject * self_) : self(self_) {}
virtual expr_t::ptr_op_t lookup(const string&) {
return NULL;
}
};
}
void export_scope()
{
class_< scope_t, scope_wrapper, boost::noncopyable > ("Scope", no_init)
.def("define", py_scope_define)
.def("lookup", py_scope_lookup)
.def("__getattr__", py_scope_getattr)
;
class_< child_scope_t, bases<scope_t>,
boost::noncopyable > ("ChildScope")
.def(init<>())
.def(init<scope_t&>())
;
class_< symbol_scope_t, bases<child_scope_t>,
boost::noncopyable > ("SymbolScope")
.def(init<>())
.def(init<scope_t&>())
;
class_< call_scope_t, bases<child_scope_t>,
boost::noncopyable > ("CallScope", init<scope_t&>())
;
class_< bind_scope_t, bases<child_scope_t>,
boost::noncopyable > ("BindScope", init<scope_t&, scope_t&>())
class_< scope_t, boost::noncopyable > ("Scope", no_init)
#if 0
.def("is_posting", )
.def("is_transaction", )
.def("is_account", )
.def("is_journal", )
#endif
;
}

View file

@ -1,63 +0,0 @@
/*
* Copyright (c) 2003-2009, John Wiegley. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of New Artisans LLC nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <system.hh>
#include "pyinterp.h"
namespace ledger {
using namespace boost::python;
#define EXC_TRANSLATOR(type) \
void exc_translate_ ## type(const type& err) { \
PyErr_SetString(PyExc_ArithmeticError, err.what()); \
}
//EXC_TRANSLATOR(session_error)
void export_session()
{
class_< session_t, bases<symbol_scope_t>,
shared_ptr<session_t>, boost::noncopyable > ("SessionBase")
;
class_< python_interpreter_t, bases<session_t>,
shared_ptr<python_interpreter_t>, boost::noncopyable > ("Session")
;
#define EXC_TRANSLATE(type) \
register_exception_translator<type>(&exc_translate_ ## type);
//EXC_TRANSLATE(session_error);
}
} // namespace ledger

View file

@ -1,66 +0,0 @@
/*
* Copyright (c) 2003-2009, John Wiegley. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of New Artisans LLC nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <system.hh>
#include "pyinterp.h"
namespace ledger {
using namespace boost::python;
#define EXC_TRANSLATOR(type) \
void exc_translate_ ## type(const type& err) { \
PyErr_SetString(PyExc_ArithmeticError, err.what()); \
}
//EXC_TRANSLATOR(timelog_error)
void export_timelog()
{
#if 0
class_< time_xact_t > ("TimeXact")
;
class_< time_log_t > ("TimeLog")
;
#endif
//register_optional_to_python<amount_t>();
//implicitly_convertible<string, amount_t>();
#define EXC_TRANSLATE(type) \
register_exception_translator<type>(&exc_translate_ ## type);
//EXC_TRANSLATE(timelog_error);
}
} // namespace ledger

View file

@ -74,11 +74,13 @@ typedef register_python_conversion<bool, bool_to_python, bool_from_python>
bool_python_conversion;
#if defined(STRING_VERIFY_ON)
struct string_to_python
{
static PyObject* convert(const string& str)
static PyObject* convert(const ledger::string& str)
{
return incref(object(*boost::polymorphic_downcast<const std::string *>(&str)).ptr());
return incref(object(static_cast<const std::string&>(str)).ptr());
}
};
@ -95,15 +97,17 @@ struct string_from_python
const char* value = PyString_AsString(obj_ptr);
if (value == 0) throw_error_already_set();
void* storage =
reinterpret_cast<converter::rvalue_from_python_storage<string> *>(data)->storage.bytes;
new (storage) string(value);
reinterpret_cast<converter::rvalue_from_python_storage<ledger::string> *>(data)->storage.bytes;
new (storage) ledger::string(value);
data->convertible = storage;
}
};
typedef register_python_conversion<string, string_to_python, string_from_python>
typedef register_python_conversion<ledger::string, string_to_python, string_from_python>
string_python_conversion;
#endif // STRING_VERIFY_ON
struct istream_to_python
{
@ -168,9 +172,10 @@ void export_utils()
.def(init<supports_flags<uint_least8_t> >())
.def(init<uint_least8_t>())
.def("flags", &supports_flags<uint_least8_t>::flags)
.add_property("flags",
&supports_flags<uint_least8_t>::flags,
&supports_flags<uint_least8_t>::set_flags)
.def("has_flags", &supports_flags<uint_least8_t>::has_flags)
.def("set_flags", &supports_flags<uint_least8_t>::set_flags)
.def("clear_flags", &supports_flags<uint_least8_t>::clear_flags)
.def("add_flags", &supports_flags<uint_least8_t>::add_flags)
.def("drop_flags", &supports_flags<uint_least8_t>::drop_flags)
@ -180,9 +185,10 @@ void export_utils()
.def(init<supports_flags<uint_least16_t> >())
.def(init<uint_least16_t>())
.def("flags", &supports_flags<uint_least16_t>::flags)
.add_property("flags",
&supports_flags<uint_least16_t>::flags,
&supports_flags<uint_least16_t>::set_flags)
.def("has_flags", &supports_flags<uint_least16_t>::has_flags)
.def("set_flags", &supports_flags<uint_least16_t>::set_flags)
.def("clear_flags", &supports_flags<uint_least16_t>::clear_flags)
.def("add_flags", &supports_flags<uint_least16_t>::add_flags)
.def("drop_flags", &supports_flags<uint_least16_t>::drop_flags)
@ -200,16 +206,19 @@ void export_utils()
class_< delegates_flags<uint_least16_t>,
boost::noncopyable > ("DelegatesFlags16", no_init)
.def("flags", &delegates_flags<uint_least16_t>::flags)
.add_property("flags",
&delegates_flags<uint_least16_t>::flags,
&delegates_flags<uint_least16_t>::set_flags)
.def("has_flags", &delegates_flags<uint_least16_t>::has_flags)
.def("set_flags", &delegates_flags<uint_least16_t>::set_flags)
.def("clear_flags", &delegates_flags<uint_least16_t>::clear_flags)
.def("add_flags", &delegates_flags<uint_least16_t>::add_flags)
.def("drop_flags", &delegates_flags<uint_least16_t>::drop_flags)
;
bool_python_conversion();
#if defined(STRING_VERIFY_ON)
string_python_conversion();
#endif
istream_python_conversion();
ostream_python_conversion();
}

View file

@ -51,7 +51,7 @@ namespace {
{
if (value.is_scope()) {
if (scope_t * scope = value.as_scope())
return expr_t(scope->lookup(name), scope);
return expr_t(scope->lookup(symbol_t::FUNCTION, name), scope);
}
throw_(value_error, _("Cannot lookup attributes in %1") << value.label());
return expr_t();
@ -112,7 +112,7 @@ void export_value()
.def(init<balance_t>())
.def(init<mask_t>())
.def(init<std::string>())
// jww (2009-11-02): Need to support conversion of sequences
// jww (2009-11-02): Need to support conversion eof value_t::sequence_t
//.def(init<value_t::sequence_t>())
.def(init<value_t>())
@ -314,7 +314,9 @@ void export_value()
implicitly_convertible<long, value_t>();
implicitly_convertible<string, value_t>();
// jww (2009-11-02): ask mask objects here
implicitly_convertible<amount_t, value_t>();
implicitly_convertible<balance_t, value_t>();
implicitly_convertible<mask_t, value_t>();
implicitly_convertible<date_t, value_t>();
implicitly_convertible<datetime_t, value_t>();

View file

@ -85,12 +85,9 @@ void export_xact()
class_< xact_base_t, bases<item_t> > ("TransactionBase")
.add_property("journal",
make_getter(&xact_base_t::journal,
return_value_policy<reference_existing_object>()),
return_internal_reference<>()),
make_setter(&xact_base_t::journal,
with_custodian_and_ward<1, 2>()))
.add_property("posts",
make_getter(&xact_base_t::posts),
make_setter(&xact_base_t::posts))
.def("__len__", posts_len)
.def("__getitem__", posts_getitem,
@ -100,6 +97,12 @@ void export_xact()
.def("remove_post", &xact_base_t::add_post)
.def("finalize", &xact_base_t::finalize)
.def("__iter__", range<return_internal_reference<> >
(&xact_t::posts_begin, &xact_t::posts_end))
.def("posts", range<return_internal_reference<> >
(&xact_t::posts_begin, &xact_t::posts_end))
.def("valid", &xact_base_t::valid)
;
@ -119,6 +122,8 @@ void export_xact()
.def("lookup", &xact_t::lookup)
.def("clear_xdata", &xact_t::clear_xdata)
.def("valid", &xact_t::valid)
;
@ -141,7 +146,7 @@ void export_xact()
("AutomatedTransactionFinalizer")
.add_property("journal",
make_getter(&auto_xact_finalizer_t::journal,
return_value_policy<reference_existing_object>()),
return_internal_reference<>()),
make_setter(&auto_xact_finalizer_t::journal,
with_custodian_and_ward<1, 2>()))
.def("__call__", &auto_xact_finalizer_t::operator())

View file

@ -44,19 +44,14 @@ char * argv0;
void export_account();
void export_amount();
void export_balance();
void export_chain();
void export_commodity();
void export_expr();
void export_flags();
void export_format();
void export_global();
void export_item();
void export_journal();
void export_post();
void export_report();
void export_scope();
void export_session();
void export_timelog();
void export_times();
void export_utils();
void export_value();
@ -67,25 +62,24 @@ void initialize_for_python()
export_account();
export_amount();
export_balance();
export_chain();
export_commodity();
export_expr();
export_flags();
export_format();
export_global();
export_item();
export_journal();
export_post();
export_report();
export_scope();
export_session();
export_timelog();
export_times();
export_utils();
export_value();
export_xact();
#if 0
// jww (2009-11-04): This is not valid unless I export the session object.
// But I think Python scripters will interace with a journal instead.
scope().attr("current_session") = python_session;
#endif
}
struct python_run
@ -291,39 +285,41 @@ python_interpreter_t::lookup_option(const char * p)
return NULL;
}
expr_t::ptr_op_t python_interpreter_t::lookup(const string& name)
expr_t::ptr_op_t python_interpreter_t::lookup(const symbol_t::kind_t kind,
const string& name)
{
// Give our superclass first dibs on symbol definitions
if (expr_t::ptr_op_t op = session_t::lookup(name))
if (expr_t::ptr_op_t op = session_t::lookup(kind, name))
return op;
const char * p = name.c_str();
switch (*p) {
case 'o':
if (WANT_OPT()) { const char * q = p + OPT_PREFIX_LEN;
if (option_t<python_interpreter_t> * handler = lookup_option(q))
return MAKE_OPT_HANDLER(python_interpreter_t, handler);
}
break;
case 'p':
if (WANT_PRECMD()) { const char * q = p + PRECMD_PREFIX_LEN;
switch (*q) {
case 'p':
if (is_eq(q, "python"))
return MAKE_FUNCTOR(python_interpreter_t::python_command);
break;
}
}
break;
}
switch (kind) {
case symbol_t::FUNCTION:
if (is_initialized && main_nspace.has_key(name.c_str())) {
DEBUG("python.interp", "Python lookup: " << name);
if (python::object obj = main_nspace.get(name.c_str()))
return WRAP_FUNCTOR(functor_t(name, obj));
}
break;
case symbol_t::OPTION:
if (option_t<python_interpreter_t> * handler = lookup_option(name.c_str()))
return MAKE_OPT_HANDLER(python_interpreter_t, handler);
break;
case symbol_t::PRECOMMAND: {
const char * p = name.c_str();
switch (*p) {
case 'p':
if (is_eq(p, "python"))
return MAKE_FUNCTOR(python_interpreter_t::python_command);
break;
}
}
default:
break;
}
return NULL;
}
@ -338,7 +334,7 @@ value_t python_interpreter_t::functor_t::operator()(call_scope_t& args)
if (val.check())
return val();
#if 1
// jww (2009-02-24): Distinguish between "no return" and a value with an
// jww (2009-02-24): Distinguish between "no return" and values with
// unconvertable type
return NULL_VALUE;
#else

View file

@ -103,7 +103,8 @@ public:
option_t<python_interpreter_t> * lookup_option(const char * p);
virtual expr_t::ptr_op_t lookup(const string& name);
virtual expr_t::ptr_op_t lookup(const symbol_t::kind_t kind,
const string& name);
#if BOOST_VERSION >= 103700
OPTION_(python_interpreter_t, import_, DO_(scope) {

View file

@ -32,7 +32,6 @@
#ifndef _PY_UTILS_H
#define _PY_UTILS_H
template <typename T, typename TfromPy>
struct object_from_python
{

View file

@ -50,7 +50,7 @@ void report_t::posts_report(post_handler_ptr handler)
{
journal_posts_iterator walker(*session.journal.get());
pass_down_posts(chain_post_handlers(*this, handler), walker);
session.clean_posts();
session.journal->clear_xdata();
}
void report_t::generate_report(post_handler_ptr handler)
@ -70,7 +70,7 @@ void report_t::xact_report(post_handler_ptr handler, xact_t& xact)
{
xact_posts_iterator walker(xact);
pass_down_posts(chain_post_handlers(*this, handler), walker);
session.clean_posts(xact);
xact.clear_xdata();
}
void report_t::accounts_report(acct_handler_ptr handler)
@ -101,15 +101,14 @@ void report_t::accounts_report(acct_handler_ptr handler)
else
pass_down_accounts(handler, *iter.get());
session.clean_posts();
session.clean_accounts();
session.journal->clear_xdata();
}
void report_t::commodities_report(post_handler_ptr handler)
{
posts_commodities_iterator walker(*session.journal.get());
pass_down_posts(chain_post_handlers(*this, handler), walker);
session.clean_posts();
session.journal->clear_xdata();
}
value_t report_t::fn_amount_expr(call_scope_t& scope)
@ -413,6 +412,9 @@ namespace {
args.value().as_sequence().end();
std::pair<expr_t, query_parser_t> info = args_to_predicate(begin, end);
if (! info.first)
throw_(std::runtime_error,
_("Invalid query predicate: %1") << join_args(args));
string limit = info.first.text();
if (! limit.empty())
@ -422,7 +424,12 @@ namespace {
"Predicate = " << report.HANDLER(limit_).str());
if (info.second.tokens_remaining()) {
string display = args_to_predicate(info.second).first.text();
info = args_to_predicate(info.second);
if (! info.first)
throw_(std::runtime_error,
_("Invalid display predicate: %1") << join_args(args));
string display = info.first.text();
if (! display.empty())
report.HANDLER(display_).on(whence, display);
@ -456,8 +463,8 @@ value_t report_t::echo_command(call_scope_t& scope)
bool report_t::maybe_import(const string& module)
{
if (lookup(string(OPT_PREFIX) + "import_")) {
expr_t(string(OPT_PREFIX) + "import_(\"" + module + "\")").calc(*this);
if (lookup(symbol_t::OPTION, "import_")) {
expr_t(string("import_(\"") + module + "\")").calc(*this);
return true;
}
return false;
@ -699,17 +706,22 @@ option_t<report_t> * report_t::lookup_option(const char * p)
return NULL;
}
void report_t::define(const string& name, expr_t::ptr_op_t def)
void report_t::define(const symbol_t::kind_t kind, const string& name,
expr_t::ptr_op_t def)
{
session.define(name, def);
session.define(kind, name, def);
}
expr_t::ptr_op_t report_t::lookup(const string& name)
expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind,
const string& name)
{
if (expr_t::ptr_op_t def = session.lookup(name))
if (expr_t::ptr_op_t def = session.lookup(kind, name))
return def;
const char * p = name.c_str();
switch (kind) {
case symbol_t::FUNCTION:
switch (*p) {
case 'a':
if (is_eq(p, "amount_expr"))
@ -732,107 +744,7 @@ expr_t::ptr_op_t report_t::lookup(const string& name)
break;
case 'c':
if (WANT_CMD()) { const char * q = p + CMD_PREFIX_LEN;
switch (*q) {
case 'b':
if (*(q + 1) == '\0' || is_eq(q, "bal") || is_eq(q, "balance")) {
return expr_t::op_t::wrap_functor
(reporter<account_t, acct_handler_ptr, &report_t::accounts_report>
(new format_accounts(*this, report_format(HANDLER(balance_format_))),
*this, "#balance"));
}
else if (is_eq(q, "budget")) {
HANDLER(amount_).set_expr(string("#budget"), "(amount, 0)");
budget_flags |= BUDGET_WRAP_VALUES;
if (! (budget_flags & ~BUDGET_WRAP_VALUES))
budget_flags |= BUDGET_BUDGETED;
return expr_t::op_t::wrap_functor
(reporter<account_t, acct_handler_ptr, &report_t::accounts_report>
(new format_accounts(*this, report_format(HANDLER(budget_format_))),
*this, "#budget"));
}
break;
case 'c':
if (is_eq(q, "csv")) {
return WRAP_FUNCTOR
(reporter<>
(new format_posts(*this, report_format(HANDLER(csv_format_))),
*this, "#csv"));
}
else if (is_eq(q, "cleared")) {
HANDLER(amount_).set_expr(string("#cleared"),
"(amount, cleared ? amount : 0)");
return expr_t::op_t::wrap_functor
(reporter<account_t, acct_handler_ptr, &report_t::accounts_report>
(new format_accounts(*this, report_format(HANDLER(cleared_format_))),
*this, "#cleared"));
}
break;
case 'e':
if (is_eq(q, "equity"))
return WRAP_FUNCTOR
(reporter<>
(new format_posts(*this, report_format(HANDLER(print_format_))),
*this, "#equity"));
else if (is_eq(q, "entry"))
return WRAP_FUNCTOR(xact_command);
else if (is_eq(q, "emacs"))
return WRAP_FUNCTOR
(reporter<>(new format_emacs_posts(output_stream), *this, "#emacs"));
else if (is_eq(q, "echo"))
return MAKE_FUNCTOR(report_t::echo_command);
break;
case 'p':
if (*(q + 1) == '\0' || is_eq(q, "print"))
return WRAP_FUNCTOR
(reporter<>
(new format_posts(*this, report_format(HANDLER(print_format_)),
HANDLED(raw)), *this, "#print"));
else if (is_eq(q, "prices"))
return expr_t::op_t::wrap_functor
(reporter<post_t, post_handler_ptr, &report_t::commodities_report>
(new format_posts(*this, report_format(HANDLER(prices_format_))),
*this, "#prices"));
else if (is_eq(q, "pricesdb"))
return expr_t::op_t::wrap_functor
(reporter<post_t, post_handler_ptr, &report_t::commodities_report>
(new format_posts(*this, report_format(HANDLER(pricesdb_format_))),
*this, "#pricesdb"));
else if (is_eq(q, "python") && maybe_import("ledger.interp"))
return session.lookup(string(CMD_PREFIX) + "python");
break;
case 'r':
if (*(q + 1) == '\0' || is_eq(q, "reg") || is_eq(q, "register"))
return WRAP_FUNCTOR
(reporter<>
(new format_posts(*this, report_format(HANDLER(register_format_))),
*this, "#register"));
else if (is_eq(q, "reload"))
return MAKE_FUNCTOR(report_t::reload_command);
break;
case 's':
if (is_eq(q, "stats") || is_eq(q, "stat"))
return WRAP_FUNCTOR(report_statistics);
else
if (is_eq(q, "server") && maybe_import("ledger.server"))
return session.lookup(string(CMD_PREFIX) + "server");
break;
case 'x':
if (is_eq(q, "xact"))
return WRAP_FUNCTOR(xact_command);
break;
}
}
else if (is_eq(p, "cyan"))
if (is_eq(p, "cyan"))
return WRAP_FUNCTOR(fn_cyan);
break;
@ -884,53 +796,12 @@ expr_t::ptr_op_t report_t::lookup(const string& name)
break;
case 'o':
if (WANT_OPT()) { const char * q = p + OPT_PREFIX_LEN;
if (option_t<report_t> * handler = lookup_option(q))
return MAKE_OPT_HANDLER(report_t, handler);
}
else if (is_eq(p, "options")) {
if (is_eq(p, "options"))
return MAKE_FUNCTOR(report_t::fn_options);
}
break;
case 'p':
if (WANT_PRECMD()) { const char * q = p + PRECMD_PREFIX_LEN;
switch (*q) {
case 'a':
if (is_eq(q, "args"))
return WRAP_FUNCTOR(args_command);
break;
case 'e':
if (is_eq(q, "eval"))
return WRAP_FUNCTOR(eval_command);
break;
case 'f':
if (is_eq(q, "format"))
return WRAP_FUNCTOR(format_command);
break;
case 'g':
if (is_eq(q, "generate"))
return expr_t::op_t::wrap_functor
(reporter<post_t, post_handler_ptr, &report_t::generate_report>
(new format_posts(*this, report_format(HANDLER(print_format_)),
false), *this, "#generate"));
case 'h':
if (is_eq(q, "hello") && maybe_import("ledger.hello"))
return session.lookup(string(PRECMD_PREFIX) + "hello");
break;
case 'p':
if (is_eq(q, "parse"))
return WRAP_FUNCTOR(parse_command);
else if (is_eq(q, "period"))
return WRAP_FUNCTOR(period_command);
break;
case 't':
if (is_eq(q, "template"))
return WRAP_FUNCTOR(template_command);
break;
}
}
else if (is_eq(p, "post"))
if (is_eq(p, "post"))
return WRAP_FUNCTOR(fn_false);
else if (is_eq(p, "percent"))
return MAKE_FUNCTOR(report_t::fn_percent);
@ -996,6 +867,154 @@ expr_t::ptr_op_t report_t::lookup(const string& name)
// Check if they are trying to access an option's setting or value.
if (option_t<report_t> * handler = lookup_option(p))
return MAKE_OPT_FUNCTOR(report_t, handler);
break;
case symbol_t::OPTION:
if (option_t<report_t> * handler = lookup_option(p))
return MAKE_OPT_HANDLER(report_t, handler);
break;
case symbol_t::COMMAND:
switch (*p) {
case 'b':
if (*(p + 1) == '\0' || is_eq(p, "bal") || is_eq(p, "balance")) {
return expr_t::op_t::wrap_functor
(reporter<account_t, acct_handler_ptr, &report_t::accounts_report>
(new format_accounts(*this, report_format(HANDLER(balance_format_))),
*this, "#balance"));
}
else if (is_eq(p, "budget")) {
HANDLER(amount_).set_expr(string("#budget"), "(amount, 0)");
budget_flags |= BUDGET_WRAP_VALUES;
if (! (budget_flags & ~BUDGET_WRAP_VALUES))
budget_flags |= BUDGET_BUDGETED;
return expr_t::op_t::wrap_functor
(reporter<account_t, acct_handler_ptr, &report_t::accounts_report>
(new format_accounts(*this, report_format(HANDLER(budget_format_))),
*this, "#budget"));
}
break;
case 'c':
if (is_eq(p, "csv")) {
return WRAP_FUNCTOR
(reporter<>
(new format_posts(*this, report_format(HANDLER(csv_format_))),
*this, "#csv"));
}
else if (is_eq(p, "cleared")) {
HANDLER(amount_).set_expr(string("#cleared"),
"(amount, cleared ? amount : 0)");
return expr_t::op_t::wrap_functor
(reporter<account_t, acct_handler_ptr, &report_t::accounts_report>
(new format_accounts(*this, report_format(HANDLER(cleared_format_))),
*this, "#cleared"));
}
break;
case 'e':
if (is_eq(p, "equity"))
return WRAP_FUNCTOR
(reporter<>
(new format_posts(*this, report_format(HANDLER(print_format_))),
*this, "#equity"));
else if (is_eq(p, "entry"))
return WRAP_FUNCTOR(xact_command);
else if (is_eq(p, "emacs"))
return WRAP_FUNCTOR
(reporter<>(new format_emacs_posts(output_stream), *this, "#emacs"));
else if (is_eq(p, "echo"))
return MAKE_FUNCTOR(report_t::echo_command);
break;
case 'p':
if (*(p + 1) == '\0' || is_eq(p, "print"))
return WRAP_FUNCTOR
(reporter<>
(new format_posts(*this, report_format(HANDLER(print_format_)),
HANDLED(raw)), *this, "#print"));
else if (is_eq(p, "prices"))
return expr_t::op_t::wrap_functor
(reporter<post_t, post_handler_ptr, &report_t::commodities_report>
(new format_posts(*this, report_format(HANDLER(prices_format_))),
*this, "#prices"));
else if (is_eq(p, "pricesdb"))
return expr_t::op_t::wrap_functor
(reporter<post_t, post_handler_ptr, &report_t::commodities_report>
(new format_posts(*this, report_format(HANDLER(pricesdb_format_))),
*this, "#pricesdb"));
else if (is_eq(p, "python") && maybe_import("ledger.interp"))
return session.lookup(symbol_t::COMMAND, "python");
break;
case 'r':
if (*(p + 1) == '\0' || is_eq(p, "reg") || is_eq(p, "register"))
return WRAP_FUNCTOR
(reporter<>
(new format_posts(*this, report_format(HANDLER(register_format_))),
*this, "#register"));
else if (is_eq(p, "reload"))
return MAKE_FUNCTOR(report_t::reload_command);
break;
case 's':
if (is_eq(p, "stats") || is_eq(p, "stat"))
return WRAP_FUNCTOR(report_statistics);
else
if (is_eq(p, "server") && maybe_import("ledger.server"))
return session.lookup(symbol_t::COMMAND, "server");
break;
case 'x':
if (is_eq(p, "xact"))
return WRAP_FUNCTOR(xact_command);
break;
}
break;
case symbol_t::PRECOMMAND:
switch (*p) {
case 'a':
if (is_eq(p, "args"))
return WRAP_FUNCTOR(args_command);
break;
case 'e':
if (is_eq(p, "eval"))
return WRAP_FUNCTOR(eval_command);
break;
case 'f':
if (is_eq(p, "format"))
return WRAP_FUNCTOR(format_command);
break;
case 'g':
if (is_eq(p, "generate"))
return expr_t::op_t::wrap_functor
(reporter<post_t, post_handler_ptr, &report_t::generate_report>
(new format_posts(*this, report_format(HANDLER(print_format_)),
false), *this, "#generate"));
case 'h':
if (is_eq(p, "hello") && maybe_import("ledger.hello"))
return session.lookup(symbol_t::PRECOMMAND, "hello");
break;
case 'p':
if (is_eq(p, "parse"))
return WRAP_FUNCTOR(parse_command);
else if (is_eq(p, "period"))
return WRAP_FUNCTOR(period_command);
break;
case 't':
if (is_eq(p, "template"))
return WRAP_FUNCTOR(template_command);
break;
}
break;
default:
break;
}
return NULL;
}

View file

@ -311,9 +311,11 @@ public:
option_t<report_t> * lookup_option(const char * p);
virtual void define(const string& name, expr_t::ptr_op_t def);
virtual void define(const symbol_t::kind_t kind, const string& name,
expr_t::ptr_op_t def);
virtual expr_t::ptr_op_t lookup(const string& name);
virtual expr_t::ptr_op_t lookup(const symbol_t::kind_t kind,
const string& name);
/**
* Option handlers

View file

@ -35,31 +35,36 @@
namespace ledger {
void symbol_scope_t::define(const string& name, expr_t::ptr_op_t def)
scope_t * scope_t::default_scope = NULL;
void symbol_scope_t::define(const symbol_t::kind_t kind,
const string& name, expr_t::ptr_op_t def)
{
DEBUG("scope.symbols", "Defining '" << name << "' = " << def);
std::pair<symbol_map::iterator, bool> result
= symbols.insert(symbol_map::value_type(name, def));
= symbols.insert(symbol_map::value_type(symbol_t(kind, name, def), def));
if (! result.second) {
symbol_map::iterator i = symbols.find(name);
symbol_map::iterator i = symbols.find(symbol_t(kind, name));
assert(i != symbols.end());
symbols.erase(i);
std::pair<symbol_map::iterator, bool> result2
= symbols.insert(symbol_map::value_type(name, def));
if (! result2.second)
throw_(compile_error, _("Redefinition of '%1' in same scope") << name);
result = symbols.insert(symbol_map::value_type(symbol_t(kind, name, def),
def));
if (! result.second)
throw_(compile_error,
_("Redefinition of '%1' in the same scope") << name);
}
}
expr_t::ptr_op_t symbol_scope_t::lookup(const string& name)
expr_t::ptr_op_t symbol_scope_t::lookup(const symbol_t::kind_t kind,
const string& name)
{
symbol_map::const_iterator i = symbols.find(name);
symbol_map::const_iterator i = symbols.find(symbol_t(kind, name));
if (i != symbols.end())
return (*i).second;
return child_scope_t::lookup(name);
return child_scope_t::lookup(kind, name);
}
} // namespace ledger

View file

@ -50,6 +50,61 @@
namespace ledger {
/**
* @brief Brief
*
* Long.
*/
struct symbol_t
{
enum kind_t {
UNKNOWN,
FUNCTION,
OPTION,
PRECOMMAND,
COMMAND,
DIRECTIVE
};
kind_t kind;
string name;
expr_t::ptr_op_t definition;
symbol_t() : kind(UNKNOWN), name(""), definition(NULL) {
TRACE_CTOR(symbol_t, "");
}
symbol_t(kind_t _kind, string _name, expr_t::ptr_op_t _definition = NULL)
: kind(_kind), name(_name), definition(_definition) {
TRACE_CTOR(symbol_t, "symbol_t::kind_t, string");
}
symbol_t(const symbol_t& sym)
: kind(sym.kind), name(sym.name),
definition(sym.definition) {
TRACE_CTOR(symbol_t, "copy");
}
~symbol_t() throw() {
TRACE_DTOR(symbol_t);
}
bool operator<(const symbol_t& sym) const {
return kind < sym.kind || name < sym.name;
}
#if defined(HAVE_BOOST_SERIALIZATION)
private:
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */) {
ar & kind;
ar & name;
ar & definition;
}
#endif // HAVE_BOOST_SERIALIZATION
};
/**
* @brief Brief
*
@ -58,6 +113,8 @@ namespace ledger {
class scope_t
{
public:
static scope_t * default_scope;
explicit scope_t() {
TRACE_CTOR(scope_t, "");
}
@ -65,8 +122,10 @@ public:
TRACE_DTOR(scope_t);
}
virtual void define(const string&, expr_t::ptr_op_t) {}
virtual expr_t::ptr_op_t lookup(const string& name) = 0;
virtual void define(const symbol_t::kind_t, const string&,
expr_t::ptr_op_t) {}
virtual expr_t::ptr_op_t lookup(const symbol_t::kind_t kind,
const string& name) = 0;
#if defined(HAVE_BOOST_SERIALIZATION)
private:
@ -100,14 +159,16 @@ public:
TRACE_DTOR(child_scope_t);
}
virtual void define(const string& name, expr_t::ptr_op_t def) {
virtual void define(const symbol_t::kind_t kind,
const string& name, expr_t::ptr_op_t def) {
if (parent)
parent->define(name, def);
parent->define(kind, name, def);
}
virtual expr_t::ptr_op_t lookup(const string& name) {
virtual expr_t::ptr_op_t lookup(const symbol_t::kind_t kind,
const string& name) {
if (parent)
return parent->lookup(name);
return parent->lookup(kind, name);
return NULL;
}
@ -132,7 +193,7 @@ private:
*/
class symbol_scope_t : public child_scope_t
{
typedef std::map<const string, expr_t::ptr_op_t> symbol_map;
typedef std::map<symbol_t, expr_t::ptr_op_t> symbol_map;
symbol_map symbols;
@ -147,9 +208,11 @@ public:
TRACE_DTOR(symbol_scope_t);
}
virtual void define(const string& name, expr_t::ptr_op_t def);
virtual void define(const symbol_t::kind_t kind, const string& name,
expr_t::ptr_op_t def);
virtual expr_t::ptr_op_t lookup(const string& name);
virtual expr_t::ptr_op_t lookup(const symbol_t::kind_t kind,
const string& name);
#if defined(HAVE_BOOST_SERIALIZATION)
private:
@ -196,6 +259,9 @@ public:
return args[index];
}
void push_front(const value_t& val) {
args.push_front(val);
}
void push_back(const value_t& val) {
args.push_back(val);
}
@ -256,15 +322,17 @@ public:
TRACE_DTOR(bind_scope_t);
}
virtual void define(const string& name, expr_t::ptr_op_t def) {
parent->define(name, def);
grandchild.define(name, def);
virtual void define(const symbol_t::kind_t kind, const string& name,
expr_t::ptr_op_t def) {
parent->define(kind, name, def);
grandchild.define(kind, name, def);
}
virtual expr_t::ptr_op_t lookup(const string& name) {
if (expr_t::ptr_op_t def = grandchild.lookup(name))
virtual expr_t::ptr_op_t lookup(const symbol_t::kind_t kind,
const string& name) {
if (expr_t::ptr_op_t def = grandchild.lookup(kind, name))
return def;
return child_scope_t::lookup(name);
return child_scope_t::lookup(kind, name);
}
#if defined(HAVE_BOOST_SERIALIZATION)

View file

@ -72,35 +72,6 @@ session_t::session_t()
HANDLER(price_db_).on(none, path("./.pricedb").string());
}
std::size_t session_t::read_journal(std::istream& in,
const path& pathname,
account_t * master,
scope_t * scope)
{
if (! master)
master = journal->master;
std::size_t count = journal->parse(in, scope ? *scope : *this,
master, &pathname, HANDLED(strict));
// remove calculated totals and flags
clean_posts();
clean_accounts();
return count;
}
std::size_t session_t::read_journal(const path& pathname,
account_t * master,
scope_t * scope)
{
if (! exists(pathname))
throw_(std::logic_error, _("Cannot read file '%1'") << pathname);
ifstream stream(pathname);
return read_journal(stream, pathname, master, scope);
}
std::size_t session_t::read_data(const string& master_account)
{
bool populated_data_files = false;
@ -130,8 +101,6 @@ std::size_t session_t::read_data(const string& master_account)
price_db_path = resolve_path(HANDLER(price_db_).str());
optional<archive_t> cache;
#if 1
// jww (2009-11-01): The binary caching feature is disabled for now.
if (HANDLED(cache_) && master_account.empty()) {
cache = archive_t(HANDLED(cache_).str());
@ -140,23 +109,20 @@ std::size_t session_t::read_data(const string& master_account)
populated_price_db = true;
}
}
#endif
if (! (cache &&
cache->should_load(HANDLER(file_).data_files) &&
cache->load(journal))) {
if (price_db_path) {
if (exists(*price_db_path)) {
if (read_journal(*price_db_path) > 0)
if (journal->read(*price_db_path) > 0)
throw_(parse_error, _("Transactions not allowed in price history file"));
journal->sources.push_back(journal_t::fileinfo_t(*price_db_path));
}
HANDLER(file_).data_files.remove(*price_db_path);
}
foreach (const path& pathname, HANDLER(file_).data_files) {
path filename = resolve_path(pathname);
if (filename == "-") {
if (pathname == "-") {
// To avoid problems with stdin and pipes, etc., we read the entire
// file in beforehand into a memory buffer, and then parcel it out
// from there.
@ -172,15 +138,10 @@ std::size_t session_t::read_data(const string& master_account)
std::istringstream buf_in(buffer.str());
xact_count += read_journal(buf_in, "/dev/stdin", acct);
xact_count += journal->read(buf_in, "/dev/stdin", acct);
journal->sources.push_back(journal_t::fileinfo_t());
}
else if (exists(filename)) {
xact_count += read_journal(filename, acct);
journal->sources.push_back(journal_t::fileinfo_t(filename));
}
else {
throw_(parse_error, _("Could not read journal file '%1'") << filename);
} else {
xact_count += journal->read(pathname, acct);
}
}
@ -227,25 +188,6 @@ void session_t::close_journal_files()
amount_t::initialize(journal->commodity_pool);
}
void session_t::clean_posts()
{
journal_posts_iterator walker(*journal.get());
pass_down_posts(post_handler_ptr(new clear_post_xdata), walker);
}
void session_t::clean_posts(xact_t& xact)
{
xact_posts_iterator walker(xact);
pass_down_posts(post_handler_ptr(new clear_post_xdata), walker);
}
void session_t::clean_accounts()
{
basic_accounts_iterator acct_walker(*journal->master);
pass_down_accounts(acct_handler_ptr(new clear_account_xdata), acct_walker);
journal->master->clear_xdata();
}
option_t<session_t> * session_t::lookup_option(const char * p)
{
switch (*p) {
@ -287,23 +229,26 @@ option_t<session_t> * session_t::lookup_option(const char * p)
return NULL;
}
expr_t::ptr_op_t session_t::lookup(const string& name)
expr_t::ptr_op_t session_t::lookup(const symbol_t::kind_t kind,
const string& name)
{
const char * p = name.c_str();
switch (*p) {
case 'o':
if (WANT_OPT()) { p += OPT_PREFIX_LEN;
if (option_t<session_t> * handler = lookup_option(p))
switch (kind) {
case symbol_t::FUNCTION:
// Check if they are trying to access an option's setting or value.
if (option_t<session_t> * handler = lookup_option(name.c_str()))
return MAKE_OPT_FUNCTOR(session_t, handler);
break;
case symbol_t::OPTION:
if (option_t<session_t> * handler = lookup_option(name.c_str()))
return MAKE_OPT_HANDLER(session_t, handler);
}
break;
default:
break;
}
// Check if they are trying to access an option's setting or value.
if (option_t<session_t> * handler = lookup_option(p))
return MAKE_OPT_FUNCTOR(session_t, handler);
return symbol_scope_t::lookup(name);
return symbol_scope_t::lookup(kind, name);
}
} // namespace ledger

View file

@ -80,27 +80,11 @@ public:
flush_on_next_data_file = truth;
}
std::size_t read_journal(std::istream& in,
const path& pathname,
account_t * master = NULL,
scope_t * scope = NULL);
std::size_t read_journal(const path& pathname,
account_t * master = NULL,
scope_t * scope = NULL);
std::size_t read_data(const string& master_account = "");
void read_journal_files();
void close_journal_files();
void clean_posts();
void clean_posts(xact_t& xact);
void clean_accounts();
void clean_all() {
clean_posts();
clean_accounts();
}
void report_options(std::ostream& out)
{
HANDLER(account_).report(out);
@ -116,7 +100,8 @@ public:
option_t<session_t> * lookup_option(const char * p);
virtual expr_t::ptr_op_t lookup(const string& name);
virtual expr_t::ptr_op_t lookup(const symbol_t::kind_t kind,
const string& name);
/**
* Option handlers

View file

@ -155,6 +155,7 @@ typedef std::ostream::pos_type ostream_pos_type;
#include <boost/iostreams/stream.hpp>
#include <boost/iostreams/write.hpp>
#include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/iterator/transform_iterator.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/operators.hpp>
#include <boost/optional.hpp>
@ -242,12 +243,6 @@ void serialize(Archive& ar, istream_pos_type& pos, const unsigned int)
#include <boost/python/detail/wrap_python.hpp>
#include <datetime.h>
#include <boost/python/exception_translator.hpp>
#include <boost/python/implicit.hpp>
#include <boost/python/args.hpp>
#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
#include <boost/python/to_python_converter.hpp>
#include <boost/python/module_init.hpp>
#endif // HAVE_BOOST_PYTHON

View file

@ -140,7 +140,8 @@ namespace {
std::streamsize len,
account_t * account);
virtual expr_t::ptr_op_t lookup(const string& name);
virtual expr_t::ptr_op_t lookup(const symbol_t::kind_t kind,
const string& name);
};
void parse_amount_expr(scope_t& scope,
@ -749,11 +750,7 @@ void instance_t::general_directive(char * line)
break;
}
scoped_array<char> directive(new char[std::strlen(p) + DIR_PREFIX_LEN + 1]);
std::strcpy(directive.get(), DIR_PREFIX);
std::strcpy(directive.get() + DIR_PREFIX_LEN, p);
if (expr_t::ptr_op_t op = lookup(directive.get())) {
if (expr_t::ptr_op_t op = lookup(symbol_t::DIRECTIVE, p)) {
call_scope_t args(*this);
args.push_back(string_value(p));
op->as_function()(args);
@ -1233,9 +1230,10 @@ xact_t * instance_t::parse_xact(char * line,
}
}
expr_t::ptr_op_t instance_t::lookup(const string& name)
expr_t::ptr_op_t instance_t::lookup(const symbol_t::kind_t kind,
const string& name)
{
return scope.lookup(name);
return scope.lookup(kind, name);
}
std::size_t journal_t::parse(std::istream& in,

View file

@ -407,6 +407,8 @@ void report_memory(std::ostream& out, bool report_all)
}
#if defined(STRING_VERIFY_ON)
string::string() : std::string() {
TRACE_CTOR(string, "");
}
@ -443,6 +445,8 @@ string::~string() throw() {
TRACE_DTOR(string);
}
#endif // STRING_VERIFY_ON
} // namespace ledger
#endif // VERIFY_ON

View file

@ -62,6 +62,10 @@
#define TIMERS_ON 1
#endif
#if defined(VERIFY_ON)
//#define STRING_VERIFY_ON 1
#endif
/*@}*/
/**
@ -72,7 +76,7 @@
namespace ledger {
using namespace boost;
#if defined(VERIFY_ON)
#if defined(STRING_VERIFY_ON)
class string;
#else
typedef std::string string;
@ -158,6 +162,8 @@ void trace_dtor_func(void * ptr, const char * cls_name, std::size_t cls_size);
void report_memory(std::ostream& out, bool report_all = false);
#if defined(STRING_VERIFY_ON)
/**
* @brief Brief
*
@ -236,6 +242,8 @@ inline bool operator!=(const char* __lhs, const string& __rhs)
inline bool operator!=(const string& __lhs, const char* __rhs)
{ return __lhs.compare(__rhs) != 0; }
#endif // STRING_VERIFY_ON
} // namespace ledger
#else // ! VERIFY_ON

View file

@ -87,7 +87,7 @@ public:
* The sequence_t member type abstracts the type used to represent a
* resizable "array" of value_t objects.
*/
typedef std::vector<value_t> sequence_t;
typedef std::deque<value_t> sequence_t;
typedef sequence_t::iterator iterator;
typedef sequence_t::const_iterator const_iterator;
typedef sequence_t::difference_type difference_type;
@ -800,6 +800,14 @@ public:
return null;
}
void push_front(const value_t& val) {
if (is_null())
*this = sequence_t();
if (! is_sequence())
in_place_cast(SEQUENCE);
as_sequence_lval().push_front(val);
}
void push_back(const value_t& val) {
if (is_null())
*this = sequence_t();

View file

@ -76,6 +76,13 @@ bool xact_base_t::remove_post(post_t * post)
return true;
}
void xact_base_t::clear_xdata()
{
foreach (post_t * post, posts)
if (! post->has_flags(ITEM_TEMP))
post->clear_xdata();
}
bool xact_base_t::finalize()
{
// Scan through and compute the total balance for the xact. This is used
@ -422,8 +429,12 @@ namespace {
}
}
expr_t::ptr_op_t xact_t::lookup(const string& name)
expr_t::ptr_op_t xact_t::lookup(const symbol_t::kind_t kind,
const string& name)
{
if (kind != symbol_t::FUNCTION)
return item_t::lookup(kind, name);
switch (name[0]) {
case 'c':
if (name == "code")
@ -448,7 +459,7 @@ expr_t::ptr_op_t xact_t::lookup(const string& name)
break;
}
return item_t::lookup(name);
return item_t::lookup(kind, name);
}
bool xact_t::valid() const

View file

@ -77,7 +77,17 @@ public:
virtual void add_post(post_t * post);
virtual bool remove_post(post_t * post);
posts_list::iterator posts_begin() {
return posts.begin();
}
posts_list::iterator posts_end() {
return posts.end();
}
virtual bool finalize();
void clear_xdata();
virtual bool valid() const {
return true;
}
@ -123,7 +133,8 @@ public:
string idstring() const;
string id() const;
virtual expr_t::ptr_op_t lookup(const string& name);
virtual expr_t::ptr_op_t lookup(const symbol_t::kind_t kind,
const string& name);
virtual bool valid() const;

View file

@ -208,19 +208,14 @@ libledger_python_la_SOURCES = \
src/py_account.cc \
src/py_amount.cc \
src/py_balance.cc \
src/py_chain.cc \
src/py_commodity.cc \
src/py_expr.cc \
src/py_flags.cc \
src/py_format.cc \
src/py_global.cc \
src/py_item.cc \
src/py_journal.cc \
src/py_post.cc \
src/py_report.cc \
src/py_scope.cc \
src/py_session.cc \
src/py_timelog.cc \
src/py_times.cc \
src/py_utils.cc \
src/py_value.cc \