00001
00006 #include "src/typing3.hpp"
00007 #include "src/typing1.hpp"
00008
00009 #include "csv4.hpp"
00010
00011 #include <iostream>
00012 #include <stdexcept>
00013
00014 namespace eepgwde { namespace detail {
00015
00016 const std::string Filter0::strike0_("strike");
00017 const std::string Filter0::maturity0_("maturity");
00018
00019 struct Filter0::Impl {
00020 friend class Filter0;
00021
00022 Filter0 const * owner;
00023
00024 std::string service0;
00025
00026
00027 DataFrame::ma_any_t frame_;
00028
00029 std::auto_ptr<DataFrame> df;
00030
00031 DataFrame::ma_any_t sorted0;
00032
00033 Impl(Filter0 const * owner,
00034 const std::string & service0,
00035 const DataFrame::ma_any_t & frame) :
00036 owner(owner), service0(service0), frame_(frame) {
00037 DataFrame * p = new DataFrame(frame_, service0);
00038 df = std::auto_ptr<DataFrame>(p);
00039 }
00040
00041 ~Impl() {
00042 }
00043
00044 };
00045
00046 Filter0::~Filter0() throw() {
00047 }
00048
00049 Filter0::Filter0(const std::string & service0,
00050 const DataFrame::ma_any_t & frame)
00051 throw(std::exception) :
00052 impl(new Impl(this, service0, frame)),
00053 strike(strike0_), maturity(maturity0_) {
00054 }
00055
00056 Filter0::operator DataFrame * () {
00057 return impl->df.get();
00058 }
00059
00060 void Filter0::add0(std::vector<DataFrame::Record *> & s) {
00061
00062 std::list<record_t *> attrs;
00063 back_insert_iterator< std::list<record_t *> > ii(attrs);
00064 transform(s.begin(), s.end(),
00065 ii,
00066 boost::bind(&DataFrame::Record::attrs,_1));
00067
00068
00069
00070 DataFrame::ma_any_t xframe1;
00071 impl->df->add(&xframe1, s);
00072 Impl * p = new Impl(this, impl->service0, xframe1);
00073 impl = std::auto_ptr<Impl>(p);
00074 }
00075
00076 DataFrame::ma_any_t
00077 Filter0::partition(DataFrame::Comparor & comparor) {
00078 DataFrame::payloader payload1(*impl->df);
00079
00080 std::vector<DataFrame::Record> sort0 = payload1;
00081
00082 std::vector<DataFrame::Record>::iterator mark =
00083 std::partition(sort0.begin(), sort0.end(),
00084 boost::bind(&DataFrame::Comparor::compare,
00085 boost::ref(comparor),_1) );
00086
00087 std::vector<DataFrame::Record>::iterator mark0 = sort0.begin();
00088 if (mark != sort0.end() && mark != sort0.begin() ) {
00089 mark0 = mark;
00090 }
00091
00092 BOOST_ASSERT(distance(sort0.begin(), mark0) > 1);
00093
00094
00095
00096
00097 sort(sort0.begin(), mark0,
00098 boost::bind(std::less<int>(),
00099 boost::bind(&DataFrame::Record::as<int>,_1, maturity),
00100 boost::bind(&DataFrame::Record::as<int>,_2, maturity) ));
00101
00102
00103 stable_sort(sort0.begin(), mark0,
00104 boost::bind(std::less<double>(),
00105 boost::bind(&DataFrame::Record::as<double>,_1, strike),
00106 boost::bind(&DataFrame::Record::as<double>,_2, strike) ));
00107
00108 int headings = 1;
00109 DataFrame::ma_any_t sorted00 = payload1.as(sort0.begin(), mark0, headings);
00110
00111
00112
00113 boost::array<DataFrame::ma_any_t::index, 2> shape =
00114 {{ sorted00.shape()[0], sorted00.shape()[1] }};
00115 return sorted00;
00116 }
00117
00118 }}
00119