00001 #include "bag1.hpp"
00002
00003 namespace eepgwde { namespace detail {
00004
00006 typedef std::list< std::list<boost::any> > columns_t;
00007
00008
00009 struct Bag::Impl {
00010 friend class Bag;
00011
00012 columns_t columns;
00013
00014
00015
00016 std::map< std::string, std::list<boost::any> * > attrs;
00017
00018 };
00019
00020 void writer0(std::ostream & os, const Bag::attr_pos_t::left_value_type & l) {
00021 os << l.first << " <--> " << l.second << "\n";
00022 }
00023
00024 std::ostream& operator<< (std::ostream& os,
00025 const Bag::attr_pos_t::left_map & l) {
00026 for(Bag::l_itr i = l.begin(); i != l.end(); ++i)
00027 writer0(os, *i);
00028 }
00029
00030 void Bag::add(int pos, const std::string & name0) {
00031 header.insert( Bag::attr_pos_t::value_type(pos, name0) );
00032
00033
00034 std::list<boost::any> v;
00035 impl->columns.push_back(v);
00036 columns_t::reference r = impl->columns.back();
00037 columns_t::pointer pr = &r;
00038
00039
00040 impl->attrs[name0] = pr;
00041 }
00042
00043
00044
00045
00046 std::list<boost::any> * Bag::get(const std::string & name0)
00047 throw (std::exception) {
00048
00049 columns_t::pointer pr = impl->attrs[name0];
00050
00051 return pr;
00052 }
00053
00054
00055
00056
00057
00058
00059 std::list<boost::any> * Bag::get(int pos)
00060 throw (std::exception) {
00061 Bag::l_itr li = header.left.find(pos);
00062 columns_t::pointer pr = impl->attrs[li->second];
00063 return pr;
00064 }
00065
00066 const std::list<boost::any> * Bag::get(const std::string & name0) const
00067 throw (std::exception) {
00068 return impl->attrs[name0];
00069 }
00070
00071 const std::list<boost::any> * Bag::get(int pos) const
00072 throw (std::exception) {
00073 Bag::l_itr li = header.left.find(pos);
00074 return impl->attrs[li->second];
00075 }
00076
00077
00078
00079
00080
00081
00082 std::list<boost::any> * Bag::append(int pos, const std::string & value0)
00083 throw (std::exception) {
00084 std::list<boost::any> * l0 = get(pos);
00085 if (!l0) return l0;
00086 boost::any a;
00087 if (value0.size())
00088 a = value0;
00089 l0->push_back(a);
00090 return l0;
00091 }
00092
00093 Bag::~Bag() throw() { }
00094
00095 Bag::Bag() throw(std::exception) : impl(new Impl) { }
00096
00097 }}
00098
00099 namespace eepgwde { namespace detail {
00100
00101
00102 struct DataFrame0::Impl {
00103 friend class DataFrame0;
00104 };
00105
00106 DataFrame0::~DataFrame0() throw() { }
00107
00108
00109 DataFrame0::DataFrame0(const Bag & bag0) : header_(bag0.header), impl(new Impl) {
00110 int cols0 = header_.right.size();
00111 int rows0 = (bag0.get((header_.right.begin())->first))->size();
00112
00113 boost::array<ma_any_t::index, 2> shape ={{ rows0, cols0 }};
00114
00115 frame.resize(shape);
00116
00117 ma_any_t & A = frame;
00118
00119 int col=0;
00120 for(Bag::r_itr hi = header_.right.begin(); hi != header_.right.end(); ++hi) {
00121
00122 const std::list<boost::any> * l0 = bag0.get(hi->first);
00123
00124 int row = 0;
00125 for (std::list<boost::any>::const_iterator j = l0->begin();
00126 j != l0->end(); ++j) {
00127 A[row++][col] = *j;
00128 }
00129 col++;
00130 }
00131 }
00132
00133 }}