CLHEP 2.0.4.7 Reference Documentation
CLHEP Home Page CLHEP Documentation CLHEP Bug Reports |
00001 // -*- C++ -*- 00002 // $Id: Argument.hh,v 1.2 2003/09/06 14:04:13 boudreau Exp $ 00003 #ifndef __ARGUMENT_H_ 00004 #define __ARGUMENT_H_ 00005 #include <iostream> 00006 #include <vector> 00007 #include <iterator> 00008 #include <algorithm> 00009 // Here is an argument 00010 00011 namespace Genfun { 00012 00017 class Argument { 00018 00019 public: 00020 00021 // Constructor 00022 Argument(int ndim=0); 00023 00024 // Copy Constructor 00025 Argument( const Argument &); 00026 00027 // Assignment operator 00028 const Argument & operator=(const Argument &); 00029 00030 // Destructor: 00031 ~Argument(); 00032 00033 // Set/Get Value 00034 double & operator[] (int I); 00035 const double & operator[] (int i) const; 00036 00037 // Get the dimensions 00038 unsigned int dimension() const; 00039 00040 private: 00041 00042 std::vector<double> *_data; 00043 00044 friend std::ostream & operator << (std::ostream & o, const Argument & a); 00045 00046 }; 00047 00048 inline Argument::Argument(const Argument & right): 00049 _data(new std::vector<double>(*(right._data))){ 00050 } 00051 00052 inline const Argument & Argument::operator=( const Argument & right) { 00053 if (this != &right) { 00054 delete _data; 00055 _data=NULL; 00056 _data = new std::vector<double>(*(right._data)); 00057 } 00058 return *this; 00059 } 00060 00061 inline unsigned int Argument::dimension() const { 00062 return _data->size(); 00063 } 00064 00065 inline double & Argument::operator[] (int i) { 00066 return (*_data)[i]; 00067 } 00068 00069 inline const double & Argument::operator[] (int i) const { 00070 return (*_data)[i]; 00071 } 00072 00073 inline Argument::Argument(int ndim): _data(new std::vector<double>(ndim)) { 00074 } 00075 00076 inline Argument::~Argument() { 00077 delete _data; 00078 } 00079 00080 00081 inline std::ostream & operator << (std::ostream & os, const Argument & a) { 00082 std::ostream_iterator<double> oi(os,","); 00083 std::copy (a._data->begin(),a._data->end(),oi); 00084 return os; 00085 } 00086 } // namespace Genfun 00087 #endif