• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

spl/data/CommandParameter.h

00001 /*
00002  *   This file is part of the Standard Portable Library (SPL).
00003  *
00004  *   SPL is free software: you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation, either version 3 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   SPL is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with SPL.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 #ifndef _commandparameter_h
00018 #define _commandparameter_h
00019 
00020 #include <spl/Exception.h>
00021 #include <spl/collection/Hashtable.h>
00022 #include <spl/Memory.h>
00023 #include <spl/RefCountPtr.h>
00024 #include <spl/String.h>
00025 #include <spl/Variant.h>
00026 
00033 class ParameterDirection
00034 {
00035 public:
00036         enum
00037         {
00038                 PARAM_DIR_IN,
00039                 PARAM_DIR_OUT,
00040                 PARAM_DIR_INOUT,
00041                 PARAM_DIR_RET
00042         };
00043 };
00044 
00045 class CommandParameter;
00046 typedef RefCountPtr<CommandParameter> CommandParameterPtr;
00047 
00048 class CommandParameter : public IMemoryValidate
00049 {
00050 protected:
00051         String m_name;
00052         int m_type;
00053         int m_dir;
00054         Variant m_data;
00055         bool m_isnumeric;
00056         int m_len;
00057 
00058 public:
00059         CommandParameter(const String& name, int type, int dir, int len);
00060         CommandParameter(const String& name, int8 val);
00061         CommandParameter(const String& name, int16 val);
00062         CommandParameter(const String& name, int32 val);
00063         CommandParameter(const String& name, int64 val);
00064         CommandParameter(const String& name, float32 val);
00065         CommandParameter(const String& name, float64 val);
00066         CommandParameter(const String& name, bool val);
00067         CommandParameter(const String& name, DateTime val);
00068         CommandParameter(const String& name, char *val);
00069         CommandParameter(const CommandParameter& prm);
00070         virtual ~CommandParameter();
00071 
00072         CommandParameter& operator =(const CommandParameter& prm);
00073 
00074         byte GetByte();
00075         int16 GetInt16();
00076         int32 GetInt32();
00077         int64 GetInt64();
00078         Decimal GetDecimal();
00079         float32 GetFloat32();
00080         float64 GetFloat64();
00081         bool GetBit();
00082         DateTime GetTimeStamp();
00083         Date GetDate();
00084         DateTime GetDateTime();
00085         StringPtr GetChar();
00086         StringPtr GetVarchar();
00087         Variant &GetVariant();
00088 
00089         void Set(int8 val);
00090         void Set(int16 val);
00091         void Set(int32 val);
00092         void Set(int64 val);
00093         void Set(Decimal val);
00094         void Set(float32 val);
00095         void Set(float64 val);
00096         void Set(bool val);
00097         void Set(DateTime& val);
00098         void Set(Date& val);
00099         void Set(const String& val);
00100 
00101         inline int Type()
00102         {
00103                 return m_type;
00104         }
00105 
00106         inline int Direction()
00107         {
00108                 return m_dir;
00109         }
00110 
00111         inline int Length()
00112         {
00113                 return m_len;
00114         }
00115 
00116         inline bool IsNumeric()
00117         {
00118                 return m_isnumeric;
00119         }
00120 
00121         inline String& Name()
00122         {
00123                 return m_name;
00124         }
00125 
00126         inline StringPtr ToString()
00127         {
00128                 return m_data.ToString();
00129         }
00130 
00131 #if defined(DEBUG)
00132         virtual void CheckMem() const;
00133         virtual void ValidateMem() const;
00134 #endif
00135 };
00136 
00137 inline void ValidateType( CommandParameter *prm )
00138 {
00139         if ( NULL != prm )
00140         {
00141                 ASSERT_MEM( prm, sizeof(CommandParameter) );
00142                 prm->ValidateMem();
00143                 DEBUG_NOTE_MEM( prm );
00144                 prm->CheckMem();
00145         }
00146 }
00147 
00150 #endif