summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2012-05-20 15:03:22 -0500
committerJohn Wiegley <johnw@newartisans.com>2012-05-20 15:03:22 -0500
commita9bdcc33013b5e1e76571ee1104bd8c7f278e775 (patch)
tree5c71b678e8180cc49dd6a8ad7bc27ce1abaf24ad
parent1b83c684fbb88b40a4b3b7114a9116b0e582bc67 (diff)
downloadfork-ledger-a9bdcc33013b5e1e76571ee1104bd8c7f278e775.tar.gz
fork-ledger-a9bdcc33013b5e1e76571ee1104bd8c7f278e775.tar.bz2
fork-ledger-a9bdcc33013b5e1e76571ee1104bd8c7f278e775.zip
Work around collision between Format's put & Graph
-rw-r--r--src/filters.cc1
-rw-r--r--src/history.cc200
-rw-r--r--src/history.h48
-rw-r--r--src/pyutils.h4
-rw-r--r--src/system.hh.in13
-rw-r--r--src/utils.cc40
-rw-r--r--src/utils.h94
7 files changed, 178 insertions, 222 deletions
diff --git a/src/filters.cc b/src/filters.cc
index 7f426bf3..f5694133 100644
--- a/src/filters.cc
+++ b/src/filters.cc
@@ -37,7 +37,6 @@
#include "report.h"
#include "compare.h"
#include "pool.h"
-#include "history.h"
namespace ledger {
diff --git a/src/history.cc b/src/history.cc
index 556abd26..cf92d096 100644
--- a/src/history.cc
+++ b/src/history.cc
@@ -31,6 +31,13 @@
#include <system.hh>
+#include <boost/graph/adjacency_list.hpp>
+#include <boost/graph/filtered_graph.hpp>
+#include <boost/graph/dijkstra_shortest_paths.hpp>
+#if 0
+#include <boost/graph/graphviz.hpp>
+#endif
+
#include "history.h"
template <typename T>
@@ -40,8 +47,142 @@ struct f_max : public std::binary_function<T, T, bool> {
}
};
+namespace boost {
+ enum edge_price_point_t { edge_price_point };
+ enum edge_price_ratio_t { edge_price_ratio };
+ BOOST_INSTALL_PROPERTY(edge, price_point);
+ BOOST_INSTALL_PROPERTY(edge, price_ratio);
+}
+
namespace ledger {
+class commodity_history_impl_t : public noncopyable
+{
+public:
+ typedef adjacency_list
+ <vecS, // Store all edges in a vector
+ vecS, // Store all vertices in a vector
+ undirectedS, // Relations are both ways
+
+ // All vertices are commodities
+ property<vertex_name_t, const commodity_t *,
+ property<vertex_index_t, std::size_t> >,
+
+ // All edges are weights computed as the absolute difference between
+ // the reference time of a search and a known price point. A
+ // filtered_graph is used to select the recent price point to the
+ // reference time before performing the search.
+ property<edge_weight_t, long,
+ property<edge_price_ratio_t, price_map_t,
+ property<edge_price_point_t, price_point_t> > >,
+
+ // Graph itself has a std::string name
+ property<graph_name_t, std::string>
+ > Graph;
+
+ Graph price_graph;
+
+ typedef graph_traits<Graph>::vertex_descriptor vertex_descriptor;
+ typedef graph_traits<Graph>::edge_descriptor edge_descriptor;
+
+ typedef property_map<Graph, vertex_name_t>::type NameMap;
+ typedef property_map<Graph, edge_weight_t>::type EdgeWeightMap;
+ typedef property_map<Graph, edge_price_point_t>::type PricePointMap;
+ typedef property_map<Graph, edge_price_ratio_t>::type PriceRatioMap;
+
+ PricePointMap pricemap;
+ PriceRatioMap ratiomap;
+
+ commodity_history_impl_t()
+ : pricemap(get(edge_price_point, price_graph)),
+ ratiomap(get(edge_price_ratio, price_graph)) {}
+
+ void add_commodity(commodity_t& comm);
+
+ void add_price(const commodity_t& source,
+ const datetime_t& when,
+ const amount_t& price);
+ void remove_price(const commodity_t& source,
+ const commodity_t& target,
+ const datetime_t& date);
+
+ void map_prices(function<void(datetime_t, const amount_t&)> fn,
+ const commodity_t& source,
+ const datetime_t& moment,
+ const datetime_t& _oldest = datetime_t(),
+ bool bidirectionally = false);
+
+ optional<price_point_t>
+ find_price(const commodity_t& source,
+ const datetime_t& moment,
+ const datetime_t& oldest = datetime_t());
+
+ optional<price_point_t>
+ find_price(const commodity_t& source,
+ const commodity_t& target,
+ const datetime_t& moment,
+ const datetime_t& oldest = datetime_t());
+
+ void print_map(std::ostream& out, const datetime_t& moment = datetime_t());
+};
+
+commodity_history_t::commodity_history_t()
+{
+ p_impl.reset(new commodity_history_impl_t);
+}
+
+void commodity_history_t::add_commodity(commodity_t& comm)
+{
+ p_impl->add_commodity(comm);
+}
+
+void commodity_history_t::add_price(const commodity_t& source,
+ const datetime_t& when,
+ const amount_t& price)
+{
+ p_impl->add_price(source, when, price);
+}
+
+void commodity_history_t::remove_price(const commodity_t& source,
+ const commodity_t& target,
+ const datetime_t& date)
+{
+ p_impl->remove_price(source, target, date);
+}
+
+void commodity_history_t::map_prices(
+ function<void(datetime_t, const amount_t&)> fn,
+ const commodity_t& source,
+ const datetime_t& moment,
+ const datetime_t& _oldest,
+ bool bidirectionally)
+{
+ p_impl->map_prices(fn, source, moment, _oldest, bidirectionally);
+}
+
+optional<price_point_t>
+commodity_history_t::find_price(const commodity_t& source,
+ const datetime_t& moment,
+ const datetime_t& oldest)
+{
+ return p_impl->find_price(source, moment, oldest);
+}
+
+optional<price_point_t>
+commodity_history_t::find_price(const commodity_t& source,
+ const commodity_t& target,
+ const datetime_t& moment,
+ const datetime_t& oldest)
+{
+ return p_impl->find_price(source, target, moment, oldest);
+}
+
+void commodity_history_t::print_map(std::ostream& out,
+ const datetime_t& moment)
+{
+ p_impl->print_map(out, moment);
+}
+
template <typename EdgeWeightMap,
typename PricePointMap,
typename PriceRatioMap>
@@ -107,20 +248,20 @@ public:
};
typedef filtered_graph
- <commodity_history_t::Graph,
- recent_edge_weight<commodity_history_t::EdgeWeightMap,
- commodity_history_t::PricePointMap,
- commodity_history_t::PriceRatioMap> > FGraph;
+ <commodity_history_impl_t::Graph,
+ recent_edge_weight<commodity_history_impl_t::EdgeWeightMap,
+ commodity_history_impl_t::PricePointMap,
+ commodity_history_impl_t::PriceRatioMap> > FGraph;
typedef property_map<FGraph, vertex_name_t>::type FNameMap;
typedef property_map<FGraph, vertex_index_t>::type FIndexMap;
typedef iterator_property_map
- <commodity_history_t::vertex_descriptor*, FIndexMap,
- commodity_history_t::vertex_descriptor,
- commodity_history_t::vertex_descriptor&> FPredecessorMap;
+ <commodity_history_impl_t::vertex_descriptor*, FIndexMap,
+ commodity_history_impl_t::vertex_descriptor,
+ commodity_history_impl_t::vertex_descriptor&> FPredecessorMap;
typedef iterator_property_map<long*, FIndexMap, long, long&> FDistanceMap;
-void commodity_history_t::add_commodity(commodity_t& comm)
+void commodity_history_impl_t::add_commodity(commodity_t& comm)
{
if (! comm.graph_index()) {
comm.set_graph_index(num_vertices(price_graph));
@@ -128,9 +269,9 @@ void commodity_history_t::add_commodity(commodity_t& comm)
}
}
-void commodity_history_t::add_price(const commodity_t& source,
- const datetime_t& when,
- const amount_t& price)
+void commodity_history_impl_t::add_price(const commodity_t& source,
+ const datetime_t& when,
+ const amount_t& price)
{
assert(source != price.commodity());
@@ -151,9 +292,9 @@ void commodity_history_t::add_price(const commodity_t& source,
}
}
-void commodity_history_t::remove_price(const commodity_t& source,
- const commodity_t& target,
- const datetime_t& date)
+void commodity_history_impl_t::remove_price(const commodity_t& source,
+ const commodity_t& target,
+ const datetime_t& date)
{
assert(source != target);
@@ -172,12 +313,12 @@ void commodity_history_t::remove_price(const commodity_t& source,
}
}
-void commodity_history_t::map_prices(function<void(datetime_t,
- const amount_t&)> fn,
- const commodity_t& source,
- const datetime_t& moment,
- const datetime_t& oldest,
- bool bidirectionally)
+void commodity_history_impl_t::map_prices(
+ function<void(datetime_t, const amount_t&)> fn,
+ const commodity_t& source,
+ const datetime_t& moment,
+ const datetime_t& oldest,
+ bool bidirectionally)
{
DEBUG("history.map", "Mapping prices for source commodity: " << source);
@@ -225,9 +366,9 @@ void commodity_history_t::map_prices(function<void(datetime_t,
}
optional<price_point_t>
-commodity_history_t::find_price(const commodity_t& source,
- const datetime_t& moment,
- const datetime_t& oldest)
+commodity_history_impl_t::find_price(const commodity_t& source,
+ const datetime_t& moment,
+ const datetime_t& oldest)
{
vertex_descriptor sv = vertex(*source.graph_index(), price_graph);
@@ -286,10 +427,10 @@ commodity_history_t::find_price(const commodity_t& source,
}
optional<price_point_t>
-commodity_history_t::find_price(const commodity_t& source,
- const commodity_t& target,
- const datetime_t& moment,
- const datetime_t& oldest)
+commodity_history_impl_t::find_price(const commodity_t& source,
+ const commodity_t& target,
+ const datetime_t& moment,
+ const datetime_t& oldest)
{
assert(source != target);
@@ -439,8 +580,10 @@ private:
Name name;
};
-void commodity_history_t::print_map(std::ostream& out, const datetime_t& moment)
+void commodity_history_impl_t::print_map(std::ostream& out,
+ const datetime_t& moment)
{
+#if 0
if (moment.is_not_a_date_time()) {
write_graphviz(out, price_graph,
label_writer<NameMap>(get(vertex_name, price_graph)));
@@ -450,6 +593,7 @@ void commodity_history_t::print_map(std::ostream& out, const datetime_t& moment)
(get(edge_weight, price_graph), pricemap, ratiomap, moment));
write_graphviz(out, fg, label_writer<FNameMap>(get(vertex_name, fg)));
}
+#endif
}
} // namespace ledger
diff --git a/src/history.h b/src/history.h
index af0d90f9..4362c9f9 100644
--- a/src/history.h
+++ b/src/history.h
@@ -49,57 +49,17 @@
#include "amount.h"
#include "commodity.h"
-namespace boost {
- enum edge_price_point_t { edge_price_point };
- enum edge_price_ratio_t { edge_price_ratio };
- BOOST_INSTALL_PROPERTY(edge, price_point);
- BOOST_INSTALL_PROPERTY(edge, price_ratio);
-}
-
namespace ledger {
typedef std::map<datetime_t, amount_t> price_map_t;
+class commodity_history_impl_t;
class commodity_history_t : public noncopyable
{
-public:
- typedef adjacency_list
- <vecS, // Store all edges in a vector
- vecS, // Store all vertices in a vector
- undirectedS, // Relations are both ways
-
- // All vertices are commodities
- property<vertex_name_t, const commodity_t *,
- property<vertex_index_t, std::size_t> >,
-
- // All edges are weights computed as the absolute difference between
- // the reference time of a search and a known price point. A
- // filtered_graph is used to select the recent price point to the
- // reference time before performing the search.
- property<edge_weight_t, long,
- property<edge_price_ratio_t, price_map_t,
- property<edge_price_point_t, price_point_t> > >,
-
- // Graph itself has a std::string name
- property<graph_name_t, std::string>
- > Graph;
+ unique_ptr<commodity_history_impl_t> p_impl;
- Graph price_graph;
-
- typedef graph_traits<Graph>::vertex_descriptor vertex_descriptor;
- typedef graph_traits<Graph>::edge_descriptor edge_descriptor;
-
- typedef property_map<Graph, vertex_name_t>::type NameMap;
- typedef property_map<Graph, edge_weight_t>::type EdgeWeightMap;
- typedef property_map<Graph, edge_price_point_t>::type PricePointMap;
- typedef property_map<Graph, edge_price_ratio_t>::type PriceRatioMap;
-
- PricePointMap pricemap;
- PriceRatioMap ratiomap;
-
- commodity_history_t()
- : pricemap(get(edge_price_point, price_graph)),
- ratiomap(get(edge_price_ratio, price_graph)) {}
+public:
+ commodity_history_t();
void add_commodity(commodity_t& comm);
diff --git a/src/pyutils.h b/src/pyutils.h
index a34eee00..406ca1ee 100644
--- a/src/pyutils.h
+++ b/src/pyutils.h
@@ -180,10 +180,6 @@ namespace boost { namespace python {
BOOST_PYTHON_RETURN_TO_PYTHON_BY_VALUE(T,expr, pytype) \
BOOST_PYTHON_ARG_TO_PYTHON_BY_VALUE(T,expr)
-#if !HAVE_CXX11 && (VERIFY_ON || HAVE_BOOST_PYTHON)
-BOOST_PYTHON_TO_PYTHON_BY_VALUE(ledger::string, ::PyUnicode_FromEncodedObject(::PyString_FromString(x.c_str()), "UTF-8", NULL), &PyUnicode_Type)
-#endif
-
} } // namespace boost::python
//boost::python::register_ptr_to_python< boost::shared_ptr<Base> >();
diff --git a/src/system.hh.in b/src/system.hh.in
index e81dfc00..35396c90 100644
--- a/src/system.hh.in
+++ b/src/system.hh.in
@@ -184,18 +184,10 @@ typedef std::ostream::pos_type ostream_pos_type;
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>
-#if !(defined(__GXX_EXPERIMENTAL_CXX0X__) && __GXX_EXPERIMENTAL_CXX0X__)
#include <boost/foreach.hpp>
-#endif
-
+#include <boost/format.hpp>
#include <boost/function.hpp>
-#include <boost/graph/adjacency_list.hpp>
-#include <boost/graph/filtered_graph.hpp>
-#include <boost/graph/dijkstra_shortest_paths.hpp>
-#include <boost/graph/graphviz.hpp>
-
-#include <boost/format.hpp>
#include <boost/intrusive_ptr.hpp>
#include <boost/iostreams/stream.hpp>
@@ -237,11 +229,10 @@ typedef std::ostream::pos_type ostream_pos_type;
#if HAVE_GETTEXT
#include <libintl.h>
#define _(str) gettext(str)
-#define _f(str) boost::format(gettext(str))
#else
#define _(str) str
-#define _f(str) boost::format(str)
#endif
+#define _f(str) boost::format(_(str))
#if HAVE_BOOST_SERIALIZATION
diff --git a/src/utils.cc b/src/utils.cc
index d32eef5a..c8f44124 100644
--- a/src/utils.cc
+++ b/src/utils.cc
@@ -489,46 +489,6 @@ void report_memory(std::ostream& out, bool report_all)
namespace ledger {
-#if !HAVE_CXX11 && (VERIFY_ON || HAVE_BOOST_PYTHON)
-
-string::string() : std::string() {
- TRACE_CTOR(string, "");
-}
-string::string(const string& str) : std::string(str) {
- TRACE_CTOR(string, "copy");
-}
-string::string(const std::string& str) : std::string(str) {
- TRACE_CTOR(string, "const std::string&");
-}
-string::string(size_type len, char x) : std::string(len, x) {
- TRACE_CTOR(string, "size_type, char");
-}
-string::string(const char * str) : std::string(str) {
- TRACE_CTOR(string, "const char *");
-}
-string::string(const char * str, const char * end) : std::string(str, end) {
- TRACE_CTOR(string, "const char *, const char *");
-}
-string::string(const string& str, size_type x) : std::string(str, x) {
- TRACE_CTOR(string, "const string&, size_type");
-}
-string::string(const string& str, size_type x, size_type y)
- : std::string(str, x, y) {
- TRACE_CTOR(string, "const string&, size_type, size_type");
-}
-string::string(const char * str, size_type x) : std::string(str, x) {
- TRACE_CTOR(string, "const char *, size_type");
-}
-string::string(const char * str, size_type x, size_type y)
- : std::string(str, x, y) {
- TRACE_CTOR(string, "const char *, size_type, size_type");
-}
-string::~string() throw() {
- TRACE_DTOR(string);
-}
-
-#endif // !HAVE_CXX11 && (VERIFY_ON || HAVE_BOOST_PYTHON)
-
string empty_string("");
strings_list split_arguments(const char * line)
diff --git a/src/utils.h b/src/utils.h
index cbcfb131..893b3d70 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -80,12 +80,7 @@
namespace ledger {
using namespace boost;
-#if !HAVE_CXX11 && (VERIFY_ON || HAVE_BOOST_PYTHON)
- class string;
-#else
typedef std::string string;
-#endif
-
typedef std::list<string> strings_list;
typedef posix_time::ptime ptime;
@@ -100,14 +95,6 @@ namespace ledger {
typedef boost::filesystem::filesystem_error filesystem_error;
}
-#if BOOST_FILESYSTEM_VERSION == 3
-#if !HAVE_CXX11 && (VERIFY_ON || HAVE_BOOST_PYTHON)
-namespace boost { namespace filesystem3 { namespace path_traits {
-template<> struct is_pathable<ledger::string> { static const bool value = true; };
-}}}
-#endif // VERIFY_ON || HAVE_BOOST_PYTHON
-#endif // BOOST_FILESYSTEM_VERSION == 3
-
/*@}*/
/**
@@ -201,87 +188,6 @@ void report_memory(std::ostream& out, bool report_all = false);
namespace ledger {
-#if !HAVE_CXX11 && (VERIFY_ON || HAVE_BOOST_PYTHON)
-
-class string : public std::string
-{
-public:
- string();
- string(const string& str);
- string(const std::string& str);
- string(size_type len, char x);
- template<class _InputIterator>
- string(_InputIterator __beg, _InputIterator __end)
- : std::string(__beg, __end) {
- TRACE_CTOR(string, "InputIterator, InputIterator");
- }
- string(const char * str);
- string(const char * str, const char * end);
- string(const string& str, size_type x);
- string(const string& str, size_type x, size_type y);
- string(const char * str, size_type x);
- string(const char * str, size_type x, size_type y);
- ~string() throw();
-
-#if HAVE_BOOST_SERIALIZATION
-private:
- /** Serialization. */
-
- friend class boost::serialization::access;
-
- template<class Archive>
- void serialize(Archive& ar, const unsigned int /* version */) {
- ar & boost::serialization::base_object<std::string>(*this);
- }
-#endif // HAVE_BOOST_SERIALIZATION
-};
-
-inline string operator+(const string& __lhs, const string& __rhs)
-{
- string __str(__lhs);
- __str.append(__rhs);
- return __str;
-}
-
-string operator+(const char* __lhs, const string& __rhs);
-string operator+(char __lhs, const string& __rhs);
-
-inline string operator+(const string& __lhs, const char* __rhs)
-{
- string __str(__lhs);
- __str.append(__rhs);
- return __str;
-}
-
-inline string operator+(const string& __lhs, char __rhs)
-{
- typedef string __string_type;
- typedef string::size_type __size_type;
- __string_type __str(__lhs);
- __str.append(__size_type(1), __rhs);
- return __str;
-}
-
-inline bool operator==(const string& __lhs, const string& __rhs)
-{ return __lhs.compare(__rhs) == 0; }
-
-inline bool operator==(const char* __lhs, const string& __rhs)
-{ return __rhs.compare(__lhs) == 0; }
-
-inline bool operator==(const string& __lhs, const char* __rhs)
-{ return __lhs.compare(__rhs) == 0; }
-
-inline bool operator!=(const string& __lhs, const string& __rhs)
-{ return __rhs.compare(__lhs) != 0; }
-
-inline bool operator!=(const char* __lhs, const string& __rhs)
-{ return __rhs.compare(__lhs) != 0; }
-
-inline bool operator!=(const string& __lhs, const char* __rhs)
-{ return __lhs.compare(__rhs) != 0; }
-
-#endif // !HAVE_CXX11 && (VERIFY_ON || HAVE_BOOST_PYTHON)
-
extern string empty_string;
strings_list split_arguments(const char * line);