1 //
2 // AbstractBinding.h
3 //
4 // Library: Data
5 // Package: DataCore
6 // Module:  AbstractBinding
7 //
8 // Definition of the AbstractBinding class.
9 //
10 // Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
11 // and Contributors.
12 //
13 // SPDX-License-Identifier:	BSL-1.0
14 //
15 
16 
17 #ifndef Data_AbstractBinding_INCLUDED
18 #define Data_AbstractBinding_INCLUDED
19 
20 
21 #include "Poco/Data/Data.h"
22 #include "Poco/Data/AbstractBinder.h"
23 #include "Poco/Any.h"
24 #include "Poco/RefCountedObject.h"
25 #include "Poco/AutoPtr.h"
26 #include <vector>
27 #include <list>
28 #include <deque>
29 #include <cstddef>
30 
31 
32 namespace Poco {
33 namespace Data {
34 
35 
36 class Data_API AbstractBinding
37 	/// AbstractBinding connects a value with a placeholder via an AbstractBinder interface.
38 {
39 public:
40 	using Ptr = SharedPtr<AbstractBinding>;
41 	using BinderPtr = AbstractBinder::Ptr;
42 
43 	enum Direction
44 	{
45 		PD_IN = AbstractBinder::PD_IN,
46 		PD_OUT = AbstractBinder::PD_OUT,
47 		PD_IN_OUT = AbstractBinder::PD_IN_OUT
48 	};
49 
50 	AbstractBinding(const std::string& name = "", Direction direction = PD_IN, Poco::UInt32 bulkSize = 0);
51 		/// Creates the AbstractBinding.
52 
53 	virtual ~AbstractBinding();
54 		/// Destroys the AbstractBinding.
55 
56 	void setBinder(BinderPtr pBinder);
57 		/// Sets the object used for binding; object does NOT take ownership of the pointer.
58 
59 	BinderPtr getBinder() const;
60 		/// Returns the AbstractBinder used for binding data.
61 
62 	virtual std::size_t numOfColumnsHandled() const = 0;
63 		/// Returns the number of columns that the binding handles.
64 		///
65 		/// The trivial case will be one single column but when
66 		/// complex types are used this value can be larger than one.
67 
68 	virtual std::size_t numOfRowsHandled() const = 0;
69 		/// Returns the number of rows that the binding handles.
70 		///
71 		/// The trivial case will be one single row but
72 		/// for collection data types it can be larger.
73 
74 	virtual bool canBind() const = 0;
75 		/// Returns true if we have enough data to bind
76 
77 	virtual void bind(std::size_t pos) = 0;
78 		/// Binds a value to the given column position
79 
80 	virtual void reset() = 0;
81 		/// Allows a binding to be reused.
82 
83 	AbstractBinder::Direction getDirection() const;
84 		/// Returns the binding direction.
85 
86 	const std::string& name() const;
87 		/// Returns the name for this binding.
88 
89 	bool isBulk() const;
90 		/// Returns true if extraction is bulk.
91 
92 	Poco::UInt32 bulkSize() const;
93 		/// Returns the size of the bulk binding.
94 
95 private:
96 	BinderPtr    _pBinder;
97 	std::string  _name;
98 	Direction    _direction;
99 	Poco::UInt32 _bulkSize;
100 };
101 
102 
103 using AbstractBindingVec = std::vector<AbstractBinding::Ptr>;
104 using AbstractBindingDeq = std::deque<AbstractBinding::Ptr>;
105 using AbstractBindingLst = std::list<AbstractBinding::Ptr>;
106 
107 
108 //
109 // inlines
110 //
getBinder()111 inline AbstractBinder::Ptr AbstractBinding::getBinder() const
112 {
113 	return _pBinder;
114 }
115 
116 
name()117 inline const std::string& AbstractBinding::name() const
118 {
119 	return _name;
120 }
121 
122 
getDirection()123 inline AbstractBinder::Direction AbstractBinding::getDirection() const
124 {
125 	return (AbstractBinder::Direction) _direction;
126 }
127 
128 
isBulk()129 inline bool AbstractBinding::isBulk() const
130 {
131 	return _bulkSize > 0;
132 }
133 
134 
bulkSize()135 inline Poco::UInt32 AbstractBinding::bulkSize() const
136 {
137 	return _bulkSize;
138 }
139 
140 
141 } } // namespace Poco::Data
142 
143 
144 #endif // Data_AbstractBinding_INCLUDED
145