1 // -*- C++ -*- 2 // $Id: Argument.hh,v 1.2 2003/09/06 14:04:13 boudreau Exp $ 3 #ifndef __ARGUMENT_H_ 4 #define __ARGUMENT_H_ 5 #include <iostream> 6 #include <vector> 7 #include <iterator> 8 #include <algorithm> 9 // Here is an argument 10 11 namespace Genfun { 12 13 /** 14 * @author 15 * @ingroup genfun 16 */ 17 class Argument { 18 19 public: 20 21 // Constructor 22 Argument(int ndim=0); 23 24 // Copy Constructor 25 Argument( const Argument &); 26 27 // Assignment operator 28 const Argument & operator=(const Argument &); 29 30 // Destructor: 31 ~Argument(); 32 33 // Set/Get Value 34 double & operator[] (int I); 35 const double & operator[] (int i) const; 36 37 // Get the dimensions 38 unsigned int dimension() const; 39 40 private: 41 42 std::vector<double> *_data; 43 44 friend std::ostream & operator << (std::ostream & o, const Argument & a); 45 46 }; 47 Argument(const Argument & right)48 inline Argument::Argument(const Argument & right): 49 _data(new std::vector<double>(*(right._data))){ 50 } 51 operator =(const Argument & right)52 inline const Argument & Argument::operator=( const Argument & right) { 53 if (this != &right) { 54 delete _data; 55 _data=NULL; 56 _data = new std::vector<double>(*(right._data)); 57 } 58 return *this; 59 } 60 dimension() const61 inline unsigned int Argument::dimension() const { 62 return _data->size(); 63 } 64 operator [](int i)65 inline double & Argument::operator[] (int i) { 66 return (*_data)[i]; 67 } 68 operator [](int i) const69 inline const double & Argument::operator[] (int i) const { 70 return (*_data)[i]; 71 } 72 Argument(int ndim)73 inline Argument::Argument(int ndim): _data(new std::vector<double>(ndim)) { 74 } 75 ~Argument()76 inline Argument::~Argument() { 77 delete _data; 78 } 79 80 operator <<(std::ostream & os,const Argument & a)81 inline std::ostream & operator << (std::ostream & os, const Argument & a) { 82 std::ostream_iterator<double> oi(os,","); 83 std::copy (a._data->begin(),a._data->end(),oi); 84 return os; 85 } 86 } // namespace Genfun 87 #endif 88