Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:34

0001 // -*- C++ -*-
0002 //
0003 #ifndef __ARGUMENT_H_
0004 #define __ARGUMENT_H_
0005 #include <iostream>
0006 #include <vector>
0007 #include <iterator>
0008 #include <algorithm>
0009 // Here is an argument
0010 
0011 namespace Genfun {
0012 
0013   /**
0014    * @author
0015    * @ingroup genfun
0016    */
0017   class Argument {
0018 
0019   public:
0020 
0021     // Constructor
0022     Argument(int ndim=0);
0023 
0024     // Copy Constructor
0025     Argument( const Argument &);
0026 
0027     // Assignment operator
0028     const Argument & operator=(const Argument &);
0029 
0030     // Destructor:
0031     ~Argument();
0032 
0033     // Set/Get Value
0034     double & operator[] (int I);
0035     const double & operator[] (int i) const; 
0036 
0037     // Get the dimensions
0038     unsigned int dimension() const;
0039 
0040   private:
0041 
0042     std::vector<double> *_data;
0043 
0044     friend std::ostream & operator << (std::ostream & o, const Argument & a);
0045 
0046   };
0047 
0048   inline Argument::Argument(const Argument & right):
0049     _data(new std::vector<double>(*(right._data))){
0050   }
0051 
0052   inline const Argument & Argument::operator=( const Argument & right) {
0053     if (this != &right) {
0054       delete _data;
0055       _data=NULL;
0056       _data = new std::vector<double>(*(right._data));
0057     }
0058     return *this;
0059   }
0060 
0061   inline unsigned int Argument::dimension() const {
0062     return (unsigned int)_data->size();
0063   }
0064 
0065   inline double & Argument::operator[] (int i) {
0066     return (*_data)[i];
0067   } 
0068 
0069   inline const double & Argument::operator[] (int i) const {
0070     return (*_data)[i];
0071   } 
0072 
0073   inline Argument::Argument(int ndim): _data(new std::vector<double>(ndim)) {
0074   }
0075 
0076   inline Argument::~Argument() {
0077     delete _data;
0078   }
0079 
0080 
0081   inline std::ostream & operator << (std::ostream & os, const Argument & a) {
0082     std::ostream_iterator<double> oi(os,",");
0083     std::copy (a._data->begin(),a._data->end(),oi);
0084     return os;
0085   }
0086 } // namespace Genfun
0087 #endif