From 1799ed3a2adf1af7ed08b3b3ded3594a4c0e184e Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Tue, 24 Feb 2009 16:08:49 -0400 Subject: Moved python/*.cc files into src/ This is because soon, I intend to have real Python source files in python/. --- python/py_balance.cc | 270 --------------------------------------------------- 1 file changed, 270 deletions(-) delete mode 100644 python/py_balance.cc (limited to 'python/py_balance.cc') diff --git a/python/py_balance.cc b/python/py_balance.cc deleted file mode 100644 index 4215519c..00000000 --- a/python/py_balance.cc +++ /dev/null @@ -1,270 +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 "pyinterp.h" -#include "pyutils.h" -#include "balance.h" - -#include -#include -#include - -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(balance_error) - -void export_balance() -{ -#if 0 - class_< balance_t > ("Balance") - ; -#endif - - //register_optional_to_python(); - - //implicitly_convertible(); - -#define EXC_TRANSLATE(type) \ - register_exception_translator(&exc_translate_ ## type); - - //EXC_TRANSLATE(balance_error); -} - -} // namespace ledger - -#if 0 -unsigned int balance_len(balance_t& bal) -{ - return bal.amounts.size(); -} - -amount_t balance_getitem(balance_t& bal, int i) -{ - std::size_t len = bal.amounts.size(); - - if (abs(i) >= len) { - PyErr_SetString(PyExc_IndexError, "Index out of range"); - throw_error_already_set(); - } - - int x = i < 0 ? len + i : i; - balance_t::amounts_map::iterator elem = bal.amounts.begin(); - while (--x >= 0) - elem++; - - return (*elem).second; -} - -unsigned int balance_pair_len(balance_pair_t& bal_pair) -{ - return balance_len(bal_pair.quantity); -} - -amount_t balance_pair_getitem(balance_pair_t& bal_pair, int i) -{ - return balance_getitem(bal_pair.quantity, i); -} - -void export_balance() -{ - class_< balance_t > ("Balance") - .def(init()) - .def(init()) - .def(init()) - .def(init()) - .def(init()) - - .def(self += self) - .def(self += other()) - .def(self += long()) - .def(self + self) - .def(self + other()) - .def(self + long()) - .def(self -= self) - .def(self -= other()) - .def(self -= long()) - .def(self - self) - .def(self - other()) - .def(self - long()) - .def(self *= self) - .def(self *= other()) - .def(self *= long()) - .def(self * self) - .def(self * other()) - .def(self * long()) - .def(self /= self) - .def(self /= other()) - .def(self /= long()) - .def(self / self) - .def(self / other()) - .def(self / long()) - .def(- self) - - .def(self < self) - .def(self < other()) - .def(self < long()) - .def(self <= self) - .def(self <= other()) - .def(self <= long()) - .def(self > self) - .def(self > other()) - .def(self > long()) - .def(self >= self) - .def(self >= other()) - .def(self >= long()) - .def(self == self) - .def(self == other()) - .def(self == long()) - .def(self != self) - .def(self != other()) - .def(self != long()) - .def(! self) - - .def(self_ns::str(self)) - - .def("__abs__", &balance_t::abs) - .def("__len__", balance_len) - .def("__getitem__", balance_getitem) - - .def("valid", &balance_t::valid) - - .def("realzero", &balance_t::realzero) - .def("amount", &balance_t::amount) - .def("value", &balance_t::value) - .def("price", &balance_t::price) - .def("date", &balance_t::date) - .def("strip_annotations", &balance_t::strip_annotations) - .def("write", &balance_t::write) - .def("round", &balance_t::round) - .def("negate", &balance_t::negate) - .def("negated", &balance_t::negated) - ; - - class_< balance_pair_t > ("BalancePair") - .def(init()) - .def(init()) - .def(init()) - .def(init()) - .def(init()) - .def(init()) - - .def(self += self) - .def(self += other()) - .def(self += other()) - .def(self += long()) - .def(self + self) - .def(self + other()) - .def(self + other()) - .def(self + long()) - .def(self -= self) - .def(self -= other()) - .def(self -= other()) - .def(self -= long()) - .def(self - self) - .def(self - other()) - .def(self - other()) - .def(self - long()) - .def(self *= self) - .def(self *= other()) - .def(self *= other()) - .def(self *= long()) - .def(self * self) - .def(self * other()) - .def(self * other()) - .def(self * long()) - .def(self /= self) - .def(self /= other()) - .def(self /= other()) - .def(self /= long()) - .def(self / self) - .def(self / other()) - .def(self / other()) - .def(self / long()) - .def(- self) - - .def(self < self) - .def(self < other()) - .def(self < other()) - .def(self < long()) - .def(self <= self) - .def(self <= other()) - .def(self <= other()) - .def(self <= long()) - .def(self > self) - .def(self > other()) - .def(self > other()) - .def(self > long()) - .def(self >= self) - .def(self >= other()) - .def(self >= other()) - .def(self >= long()) - .def(self == self) - .def(self == other()) - .def(self == other()) - .def(self == long()) - .def(self != self) - .def(self != other()) - .def(self != other()) - .def(self != long()) - .def(! self) - - .def(self_ns::str(self)) - - .def("__abs__", &balance_pair_t::abs) - .def("__len__", balance_pair_len) - .def("__getitem__", balance_pair_getitem) - - .def("valid", &balance_pair_t::valid) - - .def("realzero", &balance_pair_t::realzero) - .def("amount", &balance_pair_t::amount) - .def("value", &balance_pair_t::value) - .def("price", &balance_pair_t::price) - .def("date", &balance_pair_t::date) - .def("strip_annotations", &balance_pair_t::strip_annotations) - .def("write", &balance_pair_t::write) - .def("round", &balance_pair_t::round) - .def("negate", &balance_pair_t::negate) - .def("negated", &balance_pair_t::negated) - - .add_property("cost", - make_getter(&balance_pair_t::cost, - return_value_policy())) - ; -} -#endif -- cgit v1.2.3