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,v 1.8 2008/04/23 13:20:00 vlad Exp $ */
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 #include <stdio.h>
40 
41 #ifndef __zd_f_vector_global_vars
42 
44 extern int g_iZdFVectorCounter;
45 
47 extern char* g_szZdFVectorOwnType;
48 
49 #endif /* __zd_f_vector_global_vars */
50 
51 
62 template <class T>
63 class ZdFVector : public ZdFunction
64 {
65 private:
66 
68  int m_nPoints;
69 
72  T *m_pFunc, *m_pArg;
73 
76  const T *m_pFuncC, *m_pArgC;
77 
79  std::vector<T> *m_vFunc, *m_vArg;
80 
82  double m_fArg0;
83 
85  double m_fArgStep;
86 
87 public:
88 
91  ZdFVector (int n, T* pFunc, double fArgStep = 1.0, double fArg0 = 0.0)
92  : ZqbAutoName(&g_iZdFVectorCounter, g_szZdFVectorOwnType),
93  m_nPoints(n),
94  m_pFunc(pFunc), m_pArg(NULL),
95  m_pFuncC(NULL), m_pArgC(NULL),
96  m_vFunc(NULL), m_vArg(NULL),
97  m_fArg0(fArg0), m_fArgStep(fArgStep)
98  {
99  if(NULL == m_pFunc || m_nPoints < 0)
100  m_nPoints = 0;
101  }
102 
105  ZdFVector (int n, T* pArg, T* pFunc)
106  : ZqbAutoName(&g_iZdFVectorCounter, g_szZdFVectorOwnType),
107  m_nPoints(n),
108  m_pFunc(pFunc), m_pArg(pArg),
109  m_pFuncC(NULL), m_pArgC(NULL),
110  m_vFunc(NULL), m_vArg(NULL),
111  m_fArg0(0.0), m_fArgStep(0.0)
112  {
113  if(NULL == m_pArg || NULL == m_pFunc || m_nPoints < 0)
114  m_nPoints = 0;
115  }
116 
119  ZdFVector (int n, const T* pArg, const T* pFunc)
120  : ZqbAutoName(&g_iZdFVectorCounter, g_szZdFVectorOwnType),
121  m_nPoints(n),
122  m_pFunc(NULL), m_pArg(NULL),
123  m_pFuncC(pFunc), m_pArgC(pArg),
124  m_vFunc(NULL), m_vArg(NULL),
125  m_fArg0(0.0), m_fArgStep(0.0)
126  {
127  if(NULL == m_pArg || NULL == m_pFunc || m_nPoints < 0)
128  m_nPoints = 0;
129  }
130 
133  ZdFVector (std::vector<T>* pvArg, std::vector<T>* pvFunc)
134  : ZqbAutoName(&g_iZdFVectorCounter, g_szZdFVectorOwnType),
135  m_nPoints(0),
136  m_pFunc(NULL), m_pArg(NULL),
137  m_pFuncC(NULL), m_pArgC(NULL),
138  m_vFunc(pvFunc), m_vArg(pvArg),
139  m_fArg0(0.0), m_fArgStep(0.0)
140  {
141  if(NULL == m_vArg || NULL == m_vFunc)
142  m_nPoints = 0;
143  else
144  m_nPoints = ZqbMIN(m_vArg->size(), m_vFunc->size());
145  }
146 
149  virtual ~ZdFVector () {
150  printf("~ZdFVector: deleted (%p)\n", this);
151  /* Nothing to do */
152  }
153 
155  virtual int count () {
156  return m_nPoints;
157  }
158 
161  virtual double argStep () {
162  if(NULL != m_pArg || NULL != m_pArgC || NULL != m_vArg)
163  return 0.0;
164  return m_fArgStep;
165  }
166 
168  virtual double arg (int i) {
169  if(NULL != m_pArg)
170  return m_pArg[i];
171  else if(NULL != m_pArgC)
172  return m_pArgC[i];
173  else if(NULL != m_vArg)
174  return (*m_vArg)[i];
175  return m_fArg0 + m_fArgStep * i;
176  }
177 
180  virtual double func (int i) {
181  if(i < 0 || i >= count())
182  return 0.0;
183  else if(NULL != m_pFunc)
184  return m_pFunc[i];
185  else if(NULL != m_pFuncC)
186  return m_pFuncC[i];
187  else if(NULL != m_vFunc)
188  return (*m_vFunc)[i];
189  return 0.0;
190  }
191 
193  virtual void setFunc (int i, double fNewValue) {
194  if(i < 0 || i >= count())
195  return;
196  if(NULL != m_pFunc)
197  m_pFunc[i] = fNewValue;
198  else if(NULL != m_vFunc)
199  (*m_vFunc)[i] = fNewValue;
200  }
201 
202 };
203 
204 
205 /*
206  * Common use derivations
207  */
208 
209 typedef class ZdFVector<int> ZdFVectorInt;
210 typedef class ZdFVector<float> ZdFVectorFloat;
211 typedef class ZdFVector<double> ZdFVectorDouble;
212 
213 
214 #endif /* zd_f_vector.hpp */
virtual void setFunc(int i, double fNewValue)
Definition: zd_f_vector.hpp:193
ZdFVector(int n, T *pArg, T *pFunc)
Definition: zd_f_vector.hpp:105
ZdFVector(int n, const T *pArg, const T *pFunc)
Definition: zd_f_vector.hpp:119
virtual ~ZdFVector()
Definition: zd_f_vector.hpp:149
Definition: zd_function.hpp:27
virtual double func(int i)
Definition: zd_f_vector.hpp:180
Definition: zd_f_vector.hpp:63
virtual double arg(int i)
Definition: zd_f_vector.hpp:168
Definition: zqb_autoname.hpp:18
ZdFVector(std::vector< T > *pvArg, std::vector< T > *pvFunc)
Definition: zd_f_vector.hpp:133
virtual int count()
Definition: zd_f_vector.hpp:155
ZdFVector(int n, T *pFunc, double fArgStep=1.0, double fArg0=0.0)
Definition: zd_f_vector.hpp:91
virtual double argStep()
Definition: zd_f_vector.hpp:161