NCBI C++ ToolKit
parameters.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef DBAPI_DRIVER_UTIL___PARAMETERS__HPP
2 #define DBAPI_DRIVER_UTIL___PARAMETERS__HPP
3 
4 /* $Id: parameters.hpp 70343 2015-12-17 20:11:40Z ucko $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Author: Vladimir Soussov
30  *
31  * File Description: Param container
32  *
33  */
34 
35 #include <dbapi/driver/types.hpp>
36 #include <deque>
37 
39 
40 namespace impl {
41 
43 string
44 g_SubstituteParam(const string& query, const string& name, const string& val);
45 
47 {
48 public:
49  CDB_Params(void);
50  ~CDB_Params();
51 
52  enum { kNoParamNumber = kMax_UInt };
53 
54  bool BindParam(unsigned int param_no, const string& param_name,
55  CDB_Object* param, bool is_out = false);
56  bool SetParam(unsigned int param_no, const string& param_name,
57  CDB_Object* param, bool is_out = false);
58 
59  unsigned int NofParams() const {
60  return static_cast<unsigned int>(m_Params.size());
61  }
62 
63  CDB_Object* GetParam(unsigned int param_no) const {
64  return (param_no >= NofParams()) ? 0 : m_Params[param_no].m_Param;
65  }
66 
67  const string& GetParamName(unsigned int param_no) const {
68  return (param_no >= NofParams()) ? kEmptyStr : m_Params[param_no].m_Name;
69  }
70 
71  /// This method will throw an exception if parameter's name doesn't exist.
72  unsigned int GetParamNum(const string& param_name) const;
73  /// This method will create a parameter if it doesn't exist.
74  unsigned int GetParamNum(unsigned int param_no, const string& param_name);
75 
76  enum EStatus {
77  fBound = 0x1, //< the parameter is bound to some pointer
78  fSet = 0x2, //< the parameter is set (value copied)
79  fOutput = 0x4 //< it is "output" parameter
80  };
81  typedef int TStatus;
82 
83  TStatus GetParamStatus(unsigned int param_no) const {
84  return (param_no >= NofParams()) ? 0 : m_Params[param_no].m_Status;
85  }
86 
87  void LockBinding(void)
88  {
89  m_Locked = true;
90  }
91  bool IsLocked(void) const
92  {
93  return m_Locked;
94  }
95 
96  /// Yield a lightweight copy of these parameters, sharing
97  /// representations for variable-length datatypes.
98  CDB_Params* SemiShallowClone(void) const;
99 private:
100  // No exceptions are thrown ...
101  bool GetParamNumInternal(const string& param_name, unsigned int& param_num) const;
102 
103  struct SParam {
104  SParam(void);
105  ~SParam(void);
106 
107  void Bind(const string& param_name, CDB_Object* param, bool is_out = false);
108  void Set(const string& param_name, CDB_Object* param, bool is_out = false);
109  void DeleteParam(void)
110  {
111  if ((m_Status & fSet) != 0) {
112  delete m_Param;
113  m_Status ^= fSet;
114  }
115  }
116 
117  string m_Name;
120  };
121 
122  deque<SParam> m_Params;
123  bool m_Locked;
124 };
125 
126 }
127 
129 
130 
131 #endif /* DBAPI_DRIVER_UTIL___PARAMETERS__HPP */
132 
133 
CDB_Object * GetParam(unsigned int param_no) const
Definition: parameters.hpp:63
deque< SParam > m_Params
Definition: parameters.hpp:122
void LockBinding(void)
Definition: parameters.hpp:87
bool IsLocked(void) const
Definition: parameters.hpp:91
const string & GetParamName(unsigned int param_no) const
Definition: parameters.hpp:67
TStatus GetParamStatus(unsigned int param_no) const
Definition: parameters.hpp:83
unsigned int NofParams() const
Definition: parameters.hpp:59
#define kMax_UInt
Definition: ncbi_limits.h:185
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define kEmptyStr
Definition: ncbistr.hpp:123
#define NCBI_DBAPIDRIVER_EXPORT
Definition: ncbi_export.h:392
string g_SubstituteParam(const string &query, const string &name, const string &val)
Definition: parameters.cpp:192
static string query
Modified on Mon Jul 22 05:05:03 2024 by modify_doxy.py rev. 669887