17 #include "msdevstudio/MSconfig.h"
25 #define _GLIBCPP_USE_C99 1
46 #ifdef ITERATOR_MEMBER_DEFECT
50 using std::runtime_error;
55 using namespace hippodraw;
58 DataSource (
const std::string & name )
76 m_ds_name ( ds.m_ds_name ),
77 m_title( ds.m_title ),
78 m_labels ( ds.m_labels ),
80 m_shape ( ds.m_shape )
85 DataSource (
const std::vector < std::string > & labels )
86 : m_labels ( labels ),
101 : m_ds_name (
"null" ),
102 m_title (
"Not valid DataSource" ),
163 if ( i >=
m_labels.size() )
return false;
170 const vector <string> &
184 string what (
"DataSource: argument out of range" );
185 throw runtime_error ( what );
196 vector< string >::const_iterator first
200 #ifdef DISTANCE_DEFECT
203 index = distance (
m_labels.begin(), first );
215 if ( index >= size ) {
216 string what (
"DataSource: Index `" );
218 what +=
"' out of range 0 to ";
220 throw runtime_error ( what );
226 const vector < double > &
234 for (
unsigned int i = 0;
i <
size;
i++ ) {
241 const vector < double > &
247 const string what (
"DataSource: Attempt to get column whose label"
249 throw runtime_error ( what );
259 vector< string >::const_iterator first
271 if ( yes ==
false ) {
272 string what (
"DataSource: `" );
274 what +=
"' not found in this data source";
275 throw runtime_error ( what );
284 unsigned int cols = row.size ();
285 if ( size != cols ) {
286 string what (
"DataSource: Attempt to add row of size `" );
288 what +=
"' to DataSource with `";
291 throw runtime_error ( what );
311 const vector < unsigned int > &
323 shape.push_back (
rows () );
329 const std::string & label )
const
333 string what (
"DataSource: No column with label `" );
336 throw runtime_error ( what );
351 const std::vector < double > & array )
353 string what (
"DataSource: The type of data source does not support "
354 "replacing a column." );
355 throw runtime_error ( what );
361 const std::vector < double > & array )
366 string what (
"DataSource: Attempt to replace column `" );
368 what +=
"' which does not exist.";
369 throw runtime_error ( what );
379 const std::vector < double > &,
380 const std::vector < intptr_t > & )
382 string what (
"DataSource: This type of data source does not support"
383 " the notion of shape." );
384 throw runtime_error ( what );
391 const std::vector < double > & )
393 string what (
"DataSource: This type of data source does not support "
394 "adding a column." );
395 throw runtime_error ( what );
401 const std::vector < double > &,
402 const std::vector < intptr_t > & )
404 string what (
"DataSource: This type of data source does not support"
405 " the notion of shape." );
406 throw runtime_error ( what );
417 assert ( column <
columns () );
423 double min = DBL_MAX;
424 double max = DBL_MIN;
425 double pos = DBL_MAX;
426 for (
unsigned int i = 0;
i <
size;
i++ ) {
429 if ( x != HUGE_VAL &&
431 isnan ( x ) ==
false ) {
432 min = std::min ( min, x );
433 max = std::max ( max, x );
434 if ( x > 0.0 ) pos = std::min ( pos, x );
441 if ( valid ==
true ) {
466 const std::vector< unsigned int > & )
478 assert ( column <
columns () );
481 unsigned int index = 0;
482 double m =
valueAt ( 0, column );
484 for (
unsigned int i = 1;
i <
size;
i++ ) {
499 assert ( column <
columns () );
502 unsigned int index = 0;
503 double m =
valueAt ( 0, column );
505 for (
unsigned int i = 1;
i <
size;
i++ ) {
520 assert ( column <
columns () );
525 for (
unsigned int i = 0;
i <
size;
i++ ) {
532 const vector < string > &
543 return valueAt ( row, column );
548 addRow (
const std::vector < double > & row )
550 string what (
"This data source is not capable of adding rows" );
551 throw runtime_error ( what );
558 string what (
"This data source is not capable of erasing rows" );
559 throw runtime_error ( what );
567 unsigned int ncolumns = source ->
columns ();
568 if ( ncolumns !=
columns () ) {
569 string what (
"DataSource: Number of columns of source (" );
571 what +=
") not equal to current (";
574 throw runtime_error ( what );
584 unsigned int size = source ->
rows ();
585 for (
unsigned int i = 0;
i <
size;
i++ ) {
586 const vector < double > & src_row = source ->
getRow (
i );
595 string what (
"DataSource: This data source is not capable of containing\n"
596 "an array in a column." );
597 throw runtime_error ( what );
virtual void setTitle(const std::string &title)
Sets the title of the data source to title.
Part of an implementation of the Observable-Observer pattern based on the example in the GOF Patterns...
virtual void notifyObservers() const
Notifies Observer objects of a change.
virtual void replaceColumn(const std::string &label, const std::vector< double > &array)
Replaces data in column label with contents of array.
virtual void addRow(const std::vector< double > &row)
Adds a row to the data source.
virtual double * doubleArrayAt(unsigned int row, unsigned int column) const
Returns an array at row and column.
std::vector< std::string > m_labels
The labels of the vectors of the data.
virtual void fillShape(std::vector< int > &v, unsigned int column) const
Fills the vector with the shape of a column.
const std::vector< std::string > & getDuplicatedLabels() const
Returns the column labels that were duplicated, or an empty vector.
virtual bool setReleventIndex(const std::string &column, const std::vector< unsigned int > &index)
In case we are dealing with multidimensional data in rows of this column we would like to deal with o...
void throwIfInvalidRowSize(const std::vector< double > &row)
Throws a DataSourceException if the size of the row is not equal to the number of columns...
std::vector< std::string > m_dups
A list of labels that duplicated others in a DataSource file.
virtual void expandIfNeeded(const std::vector< std::string > &labels) const
Expand the multidimension column if needed.
virtual ~DataSource()
The destructor.
std::string m_ds_name
The name of the data source .
virtual void addLabel(const std::string &label)
Adds a new label for a column.
std::string m_title
The title.
virtual void eraseRow(unsigned int index)
Erase a row from the data source.
column
The column indices for 2 dimension data point tuple.
bool isNull() const
Returns true if the receiving objects is a null object.
virtual void willDelete(const Observable *)
Notifies this Observer object that one of its Observable objects is about to be deleted.
const std::string & title() const
Returns a const reference to the title of the data source.
std::vector< intptr_t > shape(numeric::array arr)
bool isValidLabel(const std::string &label) const
Returns true if label is a valid label for a column in the DataSource.
DataSource()
The default constructor creating an data source with 0 columns.
The namespace for conversion to string.
virtual void setShape(std::vector< unsigned int > &shape)
Sets the shape of the data elements.
std::vector< unsigned int > m_shape
The shape of the data.
virtual const std::vector< double > & getColumn(const std::string &name) const
Returns the data in the column with label name.
hippodraw::DataSource class interface.
unsigned int getRank() const
Returns the rank of the data source.
virtual double valueAt(unsigned int row, unsigned int column) const =0
Returns the value in the table in position given by the row and column indexes.
virtual const std::vector< unsigned int > & getShape() const
Returns the shape of the data elements.
virtual const std::vector< std::string > & getLabels() const
Returns the list of available labels.
virtual void copyPrivate(const DataSource &other)
Copies the contents of the other DataSource.
virtual double sum(unsigned int column) const
Returns the sum of all the elements in the sequence of column column.
virtual void append(const DataSource *source)
Appends the contents of the DataSource source.
bool isValidColumn(unsigned int index) const
Returns true if index is valid, otherwise throws a DataSourceException.
intp size(numeric::array arr)
virtual bool setLabelAt(const std::string &s, unsigned int index)
Changes the label of a data column to s.
bool m_is_null
A flag to indicate the object is null.
string convert(int i)
Converts an integer to a string.
virtual double valueAtNoCache(unsigned int row, unsigned int column) const
Returns the value in the table in position given by the row and column indexes without storing it int...
void setRange(double low, double high, double pos)
Changes the current Range.
virtual void throwIfInvalidLabel(const std::string &label) const
Throws a DataSourceException object if label is not a valid label for this DataSource.
virtual bool fillRange(unsigned int column, Range &) const
Fills the Range object from data indexed by column.
virtual unsigned int rows() const =0
Returns the number of rows.
virtual void checkWidth(const DataSource *source)
Checks the number of columns.
hippodraw::Range class interface
virtual int indexOf(const std::string &label) const
Returns true if the specified column labeled label has been filled.
unsigned int columns() const
Returns the number of columns or data arrays available from this DataSource.
virtual int addColumn(const std::string &label, const std::vector< double > &data, const std::vector< intptr_t > &shape)
Adds column vector.
virtual bool isUseable(const std::string &column) const
Returns true if the column is usable.
Expresses a range of values.
virtual unsigned int indexOfMinElement(unsigned int index) const
Returns row index of the minimum element in a column for the given column.
virtual void setLabels(const std::vector< std::string > &v)
Assigns the label to each column from the vector of strings @ v.
virtual const std::vector< double > & getRow(unsigned int) const =0
Returns a const reference to slice along the axis known as a row.
virtual unsigned int indexOfMaxElement(unsigned int index) const
Returns row index of the maximum element in a column for the given column.
virtual const std::string & getLabelAt(unsigned int index) const
Returns the label for the column at index index.
void setName(const std::string &name)
Sets the name of the data source.
const std::string & getName() const
Returns the name of the data source.
virtual bool isMultiDimensional(const std::string &column) const
Returns true if the column contains multidimensional data.
Observer class interface.
std::vector< double > m_array
A temporary array that can be returned by const reference.
Base class for DataSource.