00001
00002
00014 #ifndef _PyDataSource_H
00015 #define _PyDataSource_H
00016
00017 #include <exception>
00018 #include <string>
00019 #include <vector>
00020
00021 #ifndef _MSC_VER
00022 #include <inttypes.h>
00023 #endif
00024
00025 namespace boost {
00026 namespace python {
00027 namespace numeric {
00028 class array;
00029 }
00030 }
00031 }
00032
00033 namespace hippodraw {
00034
00035 class DataSource;
00036
00043 class PyDataSource
00044 {
00045
00046 private:
00047
00051 void checkRank ( boost::python::numeric::array array );
00052
00053 public:
00054
00056 PyDataSource();
00057
00059 PyDataSource(const std::string & dataSource);
00060
00064 PyDataSource ( const std::string & name, DataSource * source );
00065
00066 virtual ~PyDataSource();
00067
00073 void static extractVector ( boost::python::numeric::array array,
00074 std::vector<double> & col );
00075
00079 template < typename T >
00080 void static copy_direct ( boost::python::numeric::array array,
00081 std::vector<double > & col );
00082
00086 static PyDataSource * getCurrentDataSource ();
00087
00089 const DataSource & dataSource() const { return *m_dataSource; }
00090
00091 unsigned int columns() const;
00092
00093 unsigned int rows() const;
00094
00096 const std::string & getTitle () const;
00097
00098 void setTitle(const std::string & title);
00099
00102 void setName(const std::string & name);
00103
00105 const std::vector<std::string> & getLabels() const;
00106
00108 const std::vector<double> & getColumn(const std::string & name) const;
00110 const std::vector<double> & getColumn(unsigned int index) const;
00111
00113 void replaceColumn(const std::string &,
00114 const std::vector<double> & col);
00115
00117 void replaceColumn(unsigned int index,
00118 const std::vector<double> & col);
00119
00122 void replaceColumn ( const std::string &,
00123 boost::python::numeric::array array );
00124
00127 void replaceColumn ( unsigned int index,
00128 boost::python::numeric::array array);
00129
00131 int addColumn( const std::string & label,
00132 const std::vector<double> & col );
00133
00140 int addColumn( const std::string & label,
00141 boost::python::numeric::array array );
00142
00144 void clear();
00145
00148 bool hasColumn(const std::string & name) const;
00149
00152 std::string registerNTuple();
00153
00156 void registerNTuple( const std::string & name );
00157
00161 boost::python::numeric::array
00162 columnAsNumArray( const std::string & label ) const;
00163
00167 boost::python::numeric::array
00168 columnAsNumArray( unsigned int index ) const;
00169
00172 void saveColumn ( const std::string & label,
00173 const std::vector < double > & v,
00174 const std::vector < intptr_t > & shape );
00175
00179 void saveColumnFromNumArray( const std::string & label,
00180 boost::python::numeric::array array );
00181
00185 void saveColumnFromNumArray( unsigned int index,
00186 boost::python::numeric::array array );
00187
00188
00191 void saveColumnFrom ( const std::string & label,
00192 const std::vector < double > & array );
00193
00196 void addRow ( const std::vector < double > & array );
00197
00200 void append ( const DataSource * source );
00201
00204 void append ( const PyDataSource * source );
00205
00206 class StopIteration : public std::exception {
00207 public:
00208 StopIteration(const std::string & what) : m_what(what) {}
00209 ~StopIteration() throw() {}
00210 const char * what() const throw() {
00211 return m_what.c_str();
00212 }
00213 private:
00214 const std::string m_what;
00215 };
00216
00217
00218 private:
00219
00221 std::string m_type;
00222
00224 DataSource * m_dataSource;
00225
00226 };
00227
00228 }
00229
00230 #endif // _PyDataSource_H