Go to the documentation of this file.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
00071 static PyDataSource * getCurrentDataSource ();
00072
00074 const DataSource & dataSource() const { return *m_dataSource; }
00075
00076 unsigned int columns() const;
00077
00078 unsigned int rows() const;
00079
00081 const std::string & getTitle () const;
00082
00083 void setTitle(const std::string & title);
00084
00087 void setName(const std::string & name);
00088
00090 const std::vector<std::string> & getLabels() const;
00091
00093 const std::vector<double> & getColumn(const std::string & name) const;
00095 const std::vector<double> & getColumn(unsigned int index) const;
00096
00098 void replaceColumn(const std::string &,
00099 const std::vector<double> & col);
00100
00102 void replaceColumn(unsigned int index,
00103 const std::vector<double> & col);
00104
00107 void replaceColumn ( const std::string &,
00108 boost::python::numeric::array array );
00109
00112 void replaceColumn ( unsigned int index,
00113 boost::python::numeric::array array);
00114
00116 int addColumn( const std::string & label,
00117 const std::vector<double> & col );
00118
00125 int addColumn( const std::string & label,
00126 boost::python::numeric::array array );
00127
00129 void clear();
00130
00133 bool hasColumn(const std::string & name) const;
00134
00137 std::string registerNTuple();
00138
00141 void registerNTuple( const std::string & name );
00142
00146 boost::python::numeric::array
00147 columnAsNumArray( const std::string & label ) const;
00148
00152 boost::python::numeric::array
00153 columnAsNumArray( unsigned int index ) const;
00154
00157 void saveColumn ( const std::string & label,
00158 const std::vector < double > & v,
00159 const std::vector < intptr_t > & shape );
00160
00164 void saveColumnFromNumArray( const std::string & label,
00165 boost::python::numeric::array array );
00166
00170 void saveColumnFromNumArray( unsigned int index,
00171 boost::python::numeric::array array );
00172
00173
00176 void saveColumnFrom ( const std::string & label,
00177 const std::vector < double > & array );
00178
00181 void addRow ( const std::vector < double > & array );
00182
00185 void append ( const DataSource * source );
00186
00189 void append ( const PyDataSource * source );
00190
00191 class StopIteration : public std::exception {
00192 public:
00193 StopIteration(const std::string & what) : m_what(what) {}
00194 ~StopIteration() throw() {}
00195 const char * what() const throw() {
00196 return m_what.c_str();
00197 }
00198 private:
00199 const std::string m_what;
00200 };
00201
00202
00203 private:
00204
00206 std::string m_type;
00207
00209 DataSource * m_dataSource;
00210
00211 };
00212
00213 }
00214
00215 #endif // _PyDataSource_H