CLHEP/GenericFunctions/Argument.hh

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

Class Library for High Energy Physics (version 1.8)