fintp_udal
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DataParameter.h
Go to the documentation of this file.
1 /*
2 * FinTP - Financial Transactions Processing Application
3 * Copyright (C) 2013 Business Information Systems (Allevo) S.R.L.
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>
17 * or contact Allevo at : 031281 Bucuresti, 23C Calea Vitan, Romania,
18 * phone +40212554577, office@allevo.ro <mailto:office@allevo.ro>, www.allevo.ro.
19 */
20 
21 #ifndef DATAPARAMETER_H
22 #define DATAPARAMETER_H
23 
24 #include "DllMainUdal.h"
25 #include "Collections.h"
26 
27 #include <stdexcept>
28 #include <string>
29 using namespace std;
30 
31 namespace FinTP
32 {
38  {
39  public :
40 
44  typedef enum
45  {
46  // An enum constant representing the invalid type option
48  // An enum constant representing the char type option
50  // An enum constant representing the date type option
52  //An enum constant representing the timestamp type option
54  //An enum constant representing the shortint type option
56  //An enum constant representing the longint type option
58  //An enum constant representing the number type option
60  //An enum constant representing the large character type option
62  //An enum constant representing the binary option
64  //An enum constant representing the cursortype option
66  ARRAY
67 
68  } DATA_TYPE;
69 
75  static string ToString( DATA_TYPE type );
76  };
77 
82  {
83  public :
84 
85  void Clear() const;
86 
87  DbTimestamp& operator=( const DbTimestamp& source );
88  friend ostream& operator<< ( ostream& os, const DbTimestamp& value );
89  };
90 
91  class DataParameterBase;
92  template < class T > class DataParameter;
93 
98  {
99  public :
100  typedef enum
101  {
102  // An enum constant representing the PARAM_IN direction option
104  // An enum constant representing the PARAM_Out direction option
106  // An enum constant representing the PARAM_INOUT direction option
107  PARAM_INOUT
108  } PARAMETER_DIRECTION;
109 
110  protected :
111 
112  string m_Name;
115  unsigned int m_Dimension;
116  unsigned char *m_StoragePointer;
117 
118  public:
119 
124  explicit inline DataParameterBase( PARAMETER_DIRECTION paramDirection = DataParameterBase::PARAM_IN ) :
125  m_Name( "" ), m_Direction( paramDirection ), m_Type( DataType::INVALID_TYPE ), m_Dimension( 0 ), m_StoragePointer( NULL ) {}
126 
133  inline DataParameterBase( const string &paramName, DataType::DATA_TYPE paramType, PARAMETER_DIRECTION paramDirection = DataParameterBase::PARAM_IN, const unsigned int dimension = 0 ) :
134  m_Name( paramName ), m_Direction( paramDirection ), m_Type( paramType ), m_Dimension( dimension ), m_StoragePointer( NULL ) {}
135 
140  inline DataParameterBase( const DataParameterBase& source ) : m_Name( source.m_Name ), m_Direction( source.m_Direction ),
141  m_Type( source.m_Type ), m_Dimension( source.m_Dimension ), m_StoragePointer( source.m_StoragePointer ) {}
142 
143  inline DataParameterBase& operator=( const DataParameterBase& source )
144  {
145  if ( this == &source )
146  return *this;
147 
148  m_Name = source.m_Name;
149  m_Direction = source.m_Direction;
150  m_Type = source.m_Type;
151  m_Dimension = source.m_Dimension;
152  m_StoragePointer = source.m_StoragePointer;
153 
154  return *this;
155  }
156 
160  virtual ~DataParameterBase()
161  {
162  if ( m_StoragePointer != NULL )
163  m_StoragePointer = NULL;
164  };
165 
166  inline void setName( const string& name ) {
167  m_Name = name;
168  }
169 
170  inline string getName() const {
171  return m_Name;
172  }
173 
174  inline void setDirection( const PARAMETER_DIRECTION paramDirection ) {
175  m_Direction = paramDirection;
176  }
177 
179  return m_Direction;
180  }
181 
182  inline void setType( const DataType::DATA_TYPE dataType ) {
183  m_Type = dataType;
184  }
185 
186  inline DataType::DATA_TYPE getType() const {
187  return m_Type;
188  }
189 
190  inline void* getStoragePointer() {
191  return m_StoragePointer;
192  }
193 
194  inline const void* getReadStoragePointer() const {
195  return m_StoragePointer;
196  }
197 
198  inline virtual void** getBindHandle() {
199  return NULL;
200  }
201 
202  virtual void* getIndicatorValue() = 0;
203 
204  inline virtual void setDimension( const unsigned int dimension ) {
205  m_Dimension = dimension;
206  }
207 
208  inline virtual unsigned int getDimension() const {
209  return m_Dimension;
210  }
211 
212  virtual bool isNULLValue() const = 0;
213 
214  inline virtual void push_back( const string& value ) { throw logic_error("Not supported by this data type"); }
215  inline virtual const string& getElement( size_t position ) const { throw logic_error("Not supported by this data type"); }
216 
217  virtual void setString( string value );
218  void setInt( int value );
219  void setLong( long value );
220  void setShort( short value );
221  virtual void setDate( string value ) {
222  setString( value );
223  }
224  //void setBlob( blob value );
225 
226  int getInt();
227  long getLong();
228  short getShort();
229  string getString();
230  };
231 
232  template < class T >
236  class DataParameter : public DataParameterBase
237  {
238  public :
243  explicit inline DataParameter( PARAMETER_DIRECTION paramDirection = DataParameterBase::PARAM_IN ) :
244  DataParameterBase( paramDirection )
245  {
246  m_StoragePointer = ( unsigned char * )&m_Value;
248  }
249 
255  explicit inline DataParameter( const string& paramName, PARAMETER_DIRECTION paramDirection = DataParameterBase::PARAM_IN ) :
256  DataParameterBase( paramName, DataParameter< T >::getParamType(), paramDirection )
257  {
258  m_StoragePointer = ( unsigned char * )&m_Value;
260  }
261 
266  inline DataParameter( const DataParameter< T >& source ) : DataParameterBase( source )
267  {
268  m_Value = source.getValue();
269  m_StoragePointer = ( unsigned char * )&m_Value;
271  }
272 
278  inline DataParameter< T >& operator=( const DataParameter< T >& source )
279  {
280  if ( this == &source )
281  return *this;
282 
283  DataParameterBase::operator=( source );
284 
285  m_Value = source.m_Value;
286  m_StoragePointer = ( unsigned char * )&m_Value;
288 
289  return *this;
290  }
291 
292  virtual void setValue( T newValue ) = 0;
293  virtual T getValue() const = 0;
294 
295  inline virtual void setDimension( const unsigned int dimension )
296  {
297  m_Dimension = dimension;
298  }
299 
300  static DataType::DATA_TYPE getParamType();
301 
302  protected :
303 
305  };
306 
307  // custom overrides
308  /*template <>
309  void inline DataParameter< DbTimestamp >::setString( string value )
310  {
311 
312  }*/
313 
314  template <>
316  {
317  return DataType::CHAR_TYPE;
318  //VARCHAR_TYPE
319  }
320 
321  template <>
323  {
324  return DataType::TIMESTAMP_TYPE;
325  }
326 
327  template <>
329  {
330  return DataType::SHORTINT_TYPE;
331  }
332 
333  template <>
335  {
336  return DataType::LONGINT_TYPE;
337  }
338 
343  template <>
345  {
346  m_StoragePointer = NULL;
348  }
349 
355  template <>
356  inline DataParameter< string >::DataParameter( const string& paramName, PARAMETER_DIRECTION paramDirection ) :
357  DataParameterBase( paramName, DataParameter< string >::getParamType(), paramDirection )
358  {
359  m_StoragePointer = NULL;
361  }
362 
367  template <>
369  {
370  DataParameter< string >::setDimension( source.getDimension() );
371 
372  if( m_StoragePointer != NULL )
373  delete[] m_StoragePointer;
374 
375  m_StoragePointer = NULL;
376  m_Value = source.m_Value;
378  }
379 
383  template <>
385  {
386  if ( this == &source )
387  return *this;
388 
389  DataParameter::operator=( source );
390 
391  m_Value = source.m_Value;
392  m_StoragePointer = NULL;
394 
395  return *this;
396  }
397 
401  /*
402  //blob parameter implementation related
403  //blob specialization
404  template<>
405  class DataParameter< blob > : public DataParameterBase
406  {
407  protected :
408 
409  blob m_Value;
410 
411  public:
412 
413  inline DataParameter< blob >::DataParameter( PARAMETER_DIRECTION paramDirection ) : DataParameterBase( paramDirection )
414  {
415  m_StoragePointer = NULL;
416  m_Type = DataParameter< blob >::getParamType();
417  }
418 
419  inline DataParameter< blob >::DataParameter( const string& paramName, PARAMETER_DIRECTION paramDirection ) :
420  DataParameterBase( paramName, DataParameter< string >::getParamType(), paramDirection )
421  {
422  m_StoragePointer = NULL;
423  m_Type = DataParameter< blob >::getParamType();
424  }
425 
426  inline DataParameter< blob >::DataParameter( const DataParameter< blob >& source ) : DataParameterBase( source )
427  {
428  DataParameter< blob >::setDimension( source.getDimension() );
430  if( m_StoragePointer != NULL )
431  delete[] m_StoragePointer;
432 
433  m_StoragePointer = NULL;
434  m_Value = source.m_Value;
435  m_Type = DataParameter< string >::getParamType();
436  }
437 
438  inline DataParameter< blob >& DataParameter< blob >::operator=( const DataParameter< blob >& source )
439  {
440  if ( this == &source )
441  return *this;
442 
443  DataParameter::operator=( source );
444 
445  m_Value = source.m_Value;
446  m_StoragePointer = NULL;
447  m_Type = DataParameter< string >::getParamType();
448 
449  return *this;
450  }
451 
452  inline DataType::DATA_TYPE DataParameter< blob >::getParamType()
453  {
454  return DataType::BINARY;
455  }
456 
457  virtual void setValue( blob newValue ) = 0;
458  virtual blob getValue() const = 0;
459 
460  inline void DataParameter< blob >::setString( string source )
461  {
462  blob strBlob( source.begin(), source.end());
463  this->setValue( strBlob );
464  }
465 
466  };
467  */
468 
472  class ExportedUdalObject ParametersVector : public std::vector< DataParameterBase* >
473  {
474  public :
476  ~ParametersVector();
477 
481  void Dump() const;
482 
483  private :
484  ParametersVector( const ParametersVector& source );
485  ParametersVector& operator=( const ParametersVector& source );
486  bool m_Copy;
487  };
488 }
489 
490 #endif // DBPARAMETER_H