00001
00015 #include "eleve/config.hpp"
00016
00017 #include "eleve/src/utilities.hpp"
00018
00019 #include <iostream>
00020 #include <string>
00021 #include <list>
00022 #include <vector>
00023 #include <map>
00024
00025 #include <typeinfo>
00026
00027 #include <boost/bind.hpp>
00028 #include <boost/algorithm/string/trim.hpp>
00029 #include <boost/tokenizer.hpp>
00030 #include <boost/multi_array.hpp>
00031 #include <boost/date_time/gregorian/formatters.hpp>
00032
00033 #include "eleve/src/loader0.hpp"
00034 #include "eleve/src/scal0.hpp"
00035
00036 #include "bag1.hpp"
00037
00038 namespace eepgwde { namespace detail {
00039
00040
00041 static Bag bag0;
00042
00043 }; };
00044
00045 #include "eleve/src/typing0.hpp"
00046 #include "eleve/src/typing3.hpp"
00047 #include "eleve/src/typing1.hpp"
00048
00049
00050 std::string to0(const boost::gregorian::date &d) {
00051 return boost::gregorian::to_simple_string(d);
00052 }
00053
00054
00055 int main(int argc, char *argv[]) {
00056 using namespace std;
00057
00058 using namespace boost;
00059 using namespace eepgwde::detail;
00060
00061
00062 string s = "Field 1,\"putting quotes around fields, allows commas\",Field 3";
00063
00064 if (argc < 2) return(1);
00065 string n(argv[1]);
00066 loader l(n);
00067
00068 char * csv;
00069 string s1;
00070 int cols_header = 0;
00071
00072
00073
00074 while ( csv = l.get() ) {
00075 string s(csv);
00076 cerr << "line: " << s << endl;
00077
00078 tokenizer<escaped_list_separator<char> > tok(s);
00079 tokenizer<escaped_list_separator<char> >::iterator beg;
00080
00081 int pos;
00082
00083
00084 for(beg=tok.begin(), pos=1; beg!=tok.end(); ++beg, pos++)
00085 ;
00086 int cols_counted = pos;
00087
00088
00089 for(beg=tok.begin(), pos=1; beg!=tok.end(); ++beg, pos++) {
00090 if (l.line() == 1) {
00091 cols_header = cols_counted;
00092 s1 = *beg;
00093 trim(s1);
00094 cerr << "header: " << s1 << endl;
00095
00096 bag0.add(pos, s1);
00097 continue;
00098 }
00099 if (cols_counted == cols_header)
00100 bag0.append(pos, *beg);
00101 }
00102 }
00103
00104
00105
00106
00107 cerr << "Bag header mappings\n";
00108 cerr << bag0.header.left;
00109 cerr << "\n";
00110
00111
00112 for(Bag::r_itr hi = bag0.header.right.begin(); hi != bag0.header.right.end(); ++hi) {
00113
00114
00115 std::list<boost::any> * l0 = bag0.get(hi->first);
00116 cerr << hi->first << " "
00117 << "size: " << l0->size() << " "
00118 << "count non-empty <boost::any>: " << eepgwde::detail::count<boost::any>(l0) << " "
00119 << "count int: " << eepgwde::detail::count<int>(l0) << " "
00120 << "count double: " << eepgwde::detail::count<double>(l0) << " "
00121 << "count date: " << eepgwde::detail::count<posixdate>(l0) << " "
00122 << endl;
00123
00124
00125
00126 int fails = 0;
00127
00128 {
00129 vector<int> v;
00130 cerr << "int" << endl;
00131 try {
00132 eepgwde::daemon::watcher = 1;
00133 render(&v, l0, fails);
00134 cerr << "render: size: " << v.size() << endl;
00135 copy(v.begin(), v.end(), ostream_iterator<int>(cerr, "\t"));
00136 cerr << endl;
00137 } catch (const boost::bad_any_cast & e) {
00138 cerr << hi->first << " : fails1: " << fails << " : " << e.what() << endl;
00139 } catch (const boost::bad_lexical_cast & e1) {
00140 cerr << hi->first << " : fails2: " << fails << " : " << e1.what() << endl;
00141 }
00142 }
00143
00144
00145 {
00146 vector<double> v;
00147 cerr << "double" << endl;
00148 try {
00149 render(&v, l0, fails);
00150 cerr << "render: size: " << v.size() << endl;
00151 copy(v.begin(), v.end(), ostream_iterator<double>(cerr, "\t"));
00152 cerr << endl;
00153 } catch (const boost::bad_any_cast & e) {
00154 cerr << hi->first << " : fails: " << fails << " : " << e.what() << endl;
00155 } catch (const boost::bad_lexical_cast & e1) {
00156 cerr << hi->first << " : fails: " << fails << " : " << e1.what() << endl;
00157 }
00158 }
00159
00160
00161 {
00162 vector<posixdate> v;
00163 cerr << "date" << endl;
00164 try {
00165 render(&v, l0, fails);
00166 cerr << "render: size: " << v.size() << endl;
00167 vector<std::string> s(v.size());
00168 transform(v.begin(), v.end(),
00169 s.begin(),
00170 (boost::bind(&to0,_1)) );
00171 copy(s.begin(), s.end(), ostream_iterator<std::string>(cerr, "\t"));
00172 cerr << endl;
00173 } catch (const boost::bad_any_cast & e) {
00174 cerr << hi->first << " : fails: " << fails << " : " << e.what() << endl;
00175 } catch (const boost::bad_lexical_cast & e1) {
00176 cerr << hi->first << " : fails: " << fails << " : " << e1.what() << endl;
00177 }
00178 }
00179
00180
00181 using eepgwde::daemon::Q;
00182
00183 for (std::list<boost::any>::iterator j = l0->begin();
00184 j != l0->end(); ++j) {
00185 cerr << hi->first << " " << boost::any_cast<string>(*j)
00186 << " is_double: "
00187 << is<double>(*j)
00188 << "\n";
00189 }
00190 }
00191
00192
00193
00194 cerr << "over-render" << endl;
00195
00196
00197 for(Bag::r_itr hi = bag0.header.right.begin(); hi != bag0.header.right.end(); ++hi) {
00198
00199
00200 std::list<boost::any> * l0 = bag0.get(hi->first);
00201 cerr << hi->first << " "
00202 << "size: " << l0->size() << " "
00203 << "count non-empty: " << eepgwde::detail::count<boost::any>(l0) << " "
00204 << "count int: " << eepgwde::detail::count<int>(l0) << " "
00205 << "count double: " << eepgwde::detail::count<double>(l0) << " "
00206 << "count date: " << eepgwde::detail::count<posixdate>(l0) << " "
00207 << endl;
00208
00209
00210
00211 int fails = 0;
00212
00213 if (eepgwde::detail::count<double>(l0) > 0) {
00214 try {
00215 render<double>(l0, fails);
00216 cerr << "render: fails: " << fails << endl;
00217 } catch (const boost::bad_any_cast & e) {
00218 cerr << hi->first << " : fails: " << fails << " : " << e.what() << endl;
00219 } catch (const boost::bad_lexical_cast & e1) {
00220 cerr << hi->first << " : fails: " << fails << " : " << e1.what() << endl;
00221 }
00222 } else if (eepgwde::detail::count<posixdate>(l0) > 0) {
00223 try {
00224 render<posixdate>(l0, fails);
00225 cerr << "render: fails: " << fails << endl;
00226 } catch (const boost::bad_any_cast & e) {
00227 cerr << hi->first << " : fails: " << fails << " : " << e.what() << endl;
00228 } catch (const boost::bad_lexical_cast & e1) {
00229 cerr << hi->first << " : fails: " << fails << " : " << e1.what() << endl;
00230 }
00231 }
00232
00233
00234 using eepgwde::daemon::Q;
00235
00236 std::string s2;
00237 for (std::list<boost::any>::iterator j = l0->begin();
00238 j != l0->end(); ++j) {
00239 s2 = "un-castable";
00240 if (is<posixdate>(*j))
00241 s2 = boost::gregorian::to_simple_string(any_cast<posixdate>(*j));
00242 if (is<double>(*j))
00243 s2 = boost::lexical_cast<std::string>( any_cast<double>(*j) );
00244 if (is<std::string>(*j))
00245 s2 = boost::lexical_cast<std::string>( any_cast<std::string>(*j) );
00246 cerr << hi->first << " "
00247 << demangle( (j->type()).name() ) << " "
00248 << s2
00249 << "\n";
00250 }
00251 }
00252
00253 return 0;
00254 }