GeoModel - GeoModelCore
Argument.h
1 //==========================================================================//
2 // Imported from the QAT library (qat.pitt.edu) by the copyright holder //
3 // Joe Boudreau. Software licensed under the terms and conditions of the //
4 // GNU Lesser Public License v3. //
5 //==========================================================================//
6 
7 // --------------------------------------------------------------------//
8 // //
9 // A function of more than one variable uses this argument class to //
10 // agglomerate the variables. It is similar to a vector. //
11 // //
12 //---------------------------------------------------------------------//
13 #ifndef __ARGUMENT_H_
14 #define __ARGUMENT_H_
15 #include <iostream>
16 #include <vector>
17 #include <iterator>
18 #include <algorithm>
19 #include <initializer_list>
20 
21 namespace GeoGenfun {
22 
23  class Argument {
24 
25  public:
26 
27  // Constructor
28  Argument(int ndim=0);
29 
30  // Copy Constructor
31  Argument( const Argument &);
32 
33  // Construct from initializer list:
34  Argument(std::initializer_list<double> );
35 
36  // Assignment operator
37  const Argument & operator=(const Argument &);
38 
39  // Destructor:
40  ~Argument();
41 
42  // Set/Get Value
43  double & operator[] (int I);
44  const double & operator[] (int i) const;
45 
46  // Get the dimensions
47  unsigned int dimension() const;
48 
49  private:
50 
51  std::vector<double> *_data;
52 
53  friend std::ostream & operator << (std::ostream & o, const Argument & a);
54 
55  };
56 
57  inline Argument::Argument(const Argument & right):
58  _data(new std::vector<double>(*(right._data))){
59  }
60 
61  inline const Argument & Argument::operator=( const Argument & right) {
62  if (this != &right) {
63  delete _data;
64  _data=NULL;
65  _data = new std::vector<double>(*(right._data));
66  }
67  return *this;
68  }
69 
70  inline unsigned int Argument::dimension() const {
71  return _data->size();
72  }
73 
74  inline double & Argument::operator[] (int i) {
75  return (*_data)[i];
76  }
77 
78  inline const double & Argument::operator[] (int i) const {
79  return (*_data)[i];
80  }
81 
82  inline Argument::Argument(int ndim): _data(new std::vector<double>(ndim)) {
83  }
84 
85  inline Argument::~Argument() {
86  delete _data;
87  }
88 
89  // Construct from initializer list:
90  inline Argument::Argument(std::initializer_list<double> lst):_data(new std::vector<double>(lst)) {
91  }
92 
93 
94  inline std::ostream & operator << (std::ostream & os, const Argument & a) {
95  std::ostream_iterator<double> oi(os,",");
96  std::copy (a._data->begin(),a._data->end(),oi);
97  return os;
98  }
99 
100 
101 } // namespace GeoGenfun
102 #endif
Definition: Abs.h:15