UNIVERS  15.3
UNIVERS base processing software API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
zd_f_vector.hpp
1 /* zd_f_vector.hpp */
2 /* $Id: zd_f_vector.hpp 20080 2009-12-15 15:57:52Z vlad $ */
3 
4 /*
5  * $Log: zd_f_vector.hpp,v $
6  * Revision 1.8 2008/04/23 13:20:00 vlad
7  * Fixed order of initializations.
8  *
9  * Revision 1.7 2007/04/13 19:42:18 vlad
10  * + argStep() and setFunc() impementation.
11  * + check for index in range in func()
12  *
13  * Revision 1.6 2006/06/07 14:27:08 guser4
14  * Right order of member initialization.
15  *
16  * Revision 1.5 2006/06/01 10:26:03 guser4
17  * Fixed bug in arg() for constant argument step data.
18  *
19  * Revision 1.4 2006/04/24 08:31:02 guser1
20  * Use m_nPoints instead of m_nSamples/
21  *
22  * Revision 1.3 2006/04/13 14:55:16 vlad
23  * Fixed cut&paste typo.
24  *
25  * Revision 1.2 2006/03/12 01:39:51 rus1
26  * Fixed stupid bugs.
27  *
28  * Revision 1.1 2006/03/07 10:53:00 rus1
29  * + ZdFVector template.
30  *
31  */
32 
33 #ifndef __zd_f_vector_hpp
34 #define __zd_f_vector_hpp
35 
36 #include "zqb_macros.h"
37 #include "zd_function.hpp"
38 
39 
40 #ifndef __zd_f_vector_global_vars
41 
43 extern int g_iZdFVectorCounter;
44 
46 extern char* g_szZdFVectorOwnType;
47 
48 #endif /* __zd_f_vector_global_vars */
49 
50 
61 template <class T>
62 class ZdFVector : public ZdFunction
63 {
64 private:
65 
67  int m_nPoints;
68 
71  T *m_pFunc, *m_pArg;
72 
75  const T *m_pFuncC, *m_pArgC;
76 
78  std::vector<T> *m_vFunc, *m_vArg;
79 
81  double m_fArg0;
82 
84  double m_fArgStep;
85 
86 public:
87 
90  ZdFVector (int n, T* pFunc, double fArgStep = 1.0, double fArg0 = 0.0)
91  : ZqbAutoName(&g_iZdFVectorCounter, g_szZdFVectorOwnType),
92  m_nPoints(n),
93  m_pFunc(pFunc), m_pArg(NULL),
94  m_pFuncC(NULL), m_pArgC(NULL),
95  m_vFunc(NULL), m_vArg(NULL),
96  m_fArg0(fArg0), m_fArgStep(fArgStep)
97  {
98  if(NULL == m_pFunc || m_nPoints < 0)
99  m_nPoints = 0;
100  }
101 
104  ZdFVector (int n, T* pArg, T* pFunc)
105  : ZqbAutoName(&g_iZdFVectorCounter, g_szZdFVectorOwnType),
106  m_nPoints(n),
107  m_pFunc(pFunc), m_pArg(pArg),
108  m_pFuncC(NULL), m_pArgC(NULL),
109  m_vFunc(NULL), m_vArg(NULL),
110  m_fArg0(0.0), m_fArgStep(0.0)
111  {
112  if(NULL == m_pArg || NULL == m_pFunc || m_nPoints < 0)
113  m_nPoints = 0;
114  }
115 
118  ZdFVector (int n, const T* pArg, const T* pFunc)
119  : ZqbAutoName(&g_iZdFVectorCounter, g_szZdFVectorOwnType),
120  m_nPoints(n),
121  m_pFunc(NULL), m_pArg(NULL),
122  m_pFuncC(pFunc), m_pArgC(pArg),
123  m_vFunc(NULL), m_vArg(NULL),
124  m_fArg0(0.0), m_fArgStep(0.0)
125  {
126  if(NULL == m_pArg || NULL == m_pFunc || m_nPoints < 0)
127  m_nPoints = 0;
128  }
129 
132  ZdFVector (std::vector<T>* pvArg, std::vector<T>* pvFunc)
133  : ZqbAutoName(&g_iZdFVectorCounter, g_szZdFVectorOwnType),
134  m_nPoints(0),
135  m_pFunc(NULL), m_pArg(NULL),
136  m_pFuncC(NULL), m_pArgC(NULL),
137  m_vFunc(pvFunc), m_vArg(pvArg),
138  m_fArg0(0.0), m_fArgStep(0.0)
139  {
140  if(NULL == m_vArg || NULL == m_vFunc)
141  m_nPoints = 0;
142  else
143  m_nPoints = ZqbMIN(m_vArg->size(), m_vFunc->size());
144  }
145 
148  virtual ~ZdFVector () {
149  /* Nothing to do */
150  }
151 
153  virtual int count () {
154  return m_nPoints;
155  }
156 
159  virtual double argStep () {
160  if(NULL != m_pArg || NULL != m_pArgC || NULL != m_vArg)
161  return 0.0;
162  return m_fArgStep;
163  }
164 
166  virtual double arg (int i) {
167  if(NULL != m_pArg)
168  return m_pArg[i];
169  else if(NULL != m_pArgC)
170  return m_pArgC[i];
171  else if(NULL != m_vArg)
172  return (*m_vArg)[i];
173  return m_fArg0 + m_fArgStep * i;
174  }
175 
178  virtual double func (int i) {
179  if(i < 0 || i >= count())
180  return 0.0;
181  else if(NULL != m_pFunc)
182  return m_pFunc[i];
183  else if(NULL != m_pFuncC)
184  return m_pFuncC[i];
185  else if(NULL != m_vFunc)
186  return (*m_vFunc)[i];
187  return 0.0;
188  }
189 
191  virtual void setFunc (int i, double fNewValue) {
192  if(i < 0 || i >= count())
193  return;
194  if(NULL != m_pFunc)
195  m_pFunc[i] = fNewValue;
196  else if(NULL != m_vFunc)
197  (*m_vFunc)[i] = fNewValue;
198  }
199 
200 };
201 
202 
203 /*
204  * Common use derivations
205  */
206 
207 typedef class ZdFVector<int> ZdFVectorInt;
208 typedef class ZdFVector<float> ZdFVectorFloat;
209 typedef class ZdFVector<double> ZdFVectorDouble;
210 
211 
212 #endif /* zd_f_vector.hpp */
virtual void setFunc(int i, double fNewValue)
Definition: zd_f_vector.hpp:191
ZdFVector(int n, T *pArg, T *pFunc)
Definition: zd_f_vector.hpp:104
ZdFVector(int n, const T *pArg, const T *pFunc)
Definition: zd_f_vector.hpp:118
virtual ~ZdFVector()
Definition: zd_f_vector.hpp:148
Definition: zd_function.hpp:27
virtual double func(int i)
Definition: zd_f_vector.hpp:178
Definition: zd_f_vector.hpp:63
virtual double arg(int i)
Definition: zd_f_vector.hpp:166
Definition: zqb_autoname.hpp:18
ZdFVector(std::vector< T > *pvArg, std::vector< T > *pvFunc)
Definition: zd_f_vector.hpp:132
virtual int count()
Definition: zd_f_vector.hpp:153
ZdFVector(int n, T *pFunc, double fArgStep=1.0, double fArg0=0.0)
Definition: zd_f_vector.hpp:90
virtual double argStep()
Definition: zd_f_vector.hpp:159