fb-cpp 0.0.2
A modern C++ wrapper for the Firebird database API
Loading...
Searching...
No Matches
Client.h
1/*
2 * MIT License
3 *
4 * Copyright (c) 2025 Adriano dos Santos Fernandes
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
25#ifndef FBCPP_CLIENT_H
26#define FBCPP_CLIENT_H
27
28#include "config.h"
29#include "fb-cpp-export.h"
30#include "fb-api.h"
31#include "SmartPtrs.h"
32#include <cassert>
33#include <concepts>
34#include <memory>
35#include <string>
36#include <type_traits>
37
38#if FB_CPP_USE_BOOST_DLL != 0
39#include <boost/dll.hpp>
40#endif
41
42
46namespace fbcpp
47{
53 class FB_CPP_EXPORT Client final
54 {
55 public:
59 explicit Client(fb::IMaster* master)
60 : master{master}
61 {
62 assert(master);
63 }
64
65#if FB_CPP_USE_BOOST_DLL != 0
70 explicit Client(const boost::dll::fs::path& fbclientLibPath,
71 boost::dll::load_mode::type loadMode = boost::dll::load_mode::append_decorations |
72 boost::dll::load_mode::search_system_folders)
73 : Client{boost::dll::shared_library{fbclientLibPath, loadMode}}
74 {
75 }
76
81 explicit Client(boost::dll::shared_library fbclientLib)
82 : fbclientLib(fbclientLib)
83 {
84 const auto fbGetMasterInterface =
85 fbclientLib.get<decltype(fb::fb_get_master_interface)>("fb_get_master_interface");
86 master = fbGetMasterInterface();
87 assert(master);
88 }
89#endif
90
95 Client(Client&& o) noexcept
96 : master{o.master},
97 util{o.util},
98 int128Util{o.int128Util},
99 decFloat16Util{o.decFloat16Util},
100 decFloat34Util{o.decFloat34Util}
101#if FB_CPP_USE_BOOST_DLL != 0
102 ,
103 fbclientLib{std::move(o.fbclientLib)}
104#endif
105 {
106 o.master = nullptr;
107 o.util = nullptr;
108 o.int128Util = nullptr;
109 o.decFloat16Util = nullptr;
110 o.decFloat34Util = nullptr;
111 }
112
118 ~Client() noexcept = default;
119
120 Client& operator=(Client&&) = delete;
121
122 Client& operator=(const Client& o) = delete;
123 Client(const Client&) = delete;
124
125 public:
129 bool isValid() noexcept
130 {
131 return master != nullptr;
132 }
133
137 fb::IMaster* getMaster() noexcept
138 {
139 return master;
140 }
141
145 fb::IUtil* getUtil()
146 {
147 assert(master);
148
149 if (!util)
150 util = master->getUtilInterface();
151
152 return util;
153 }
154
158 template <std::derived_from<fb::IStatus> StatusType>
159 fb::IInt128* getInt128Util(StatusType* status)
160 {
161 assert(status);
162
163 if (!int128Util)
164 int128Util = getUtil()->getInt128(status);
165
166 return int128Util;
167 }
168
172 template <std::derived_from<fb::IStatus> StatusType>
173 fb::IDecFloat16* getDecFloat16Util(StatusType* status)
174 {
175 assert(status);
176
177 if (!decFloat16Util)
178 decFloat16Util = getUtil()->getDecFloat16(status);
179
180 return decFloat16Util;
181 }
182
186 template <std::derived_from<fb::IStatus> StatusType>
187 fb::IDecFloat34* getDecFloat34Util(StatusType* status)
188 {
189 assert(status);
190
191 if (!decFloat34Util)
192 decFloat34Util = getUtil()->getDecFloat34(status);
193
194 return decFloat34Util;
195 }
196
201 {
202 assert(master);
203 return fbUnique(master->getStatus());
204 }
205
209 void shutdown();
210
211 private:
212 fb::IMaster* master;
213 fb::IUtil* util = nullptr;
214 fb::IInt128* int128Util = nullptr;
215 fb::IDecFloat16* decFloat16Util = nullptr;
216 fb::IDecFloat34* decFloat34Util = nullptr;
217#if FB_CPP_USE_BOOST_DLL != 0
218 boost::dll::shared_library fbclientLib;
219#endif
220 };
221} // namespace fbcpp
222
223
224#endif // FBCPP_CLIENT_H
Represents a Firebird client library instance.
Definition Client.h:54
fb::IUtil * getUtil()
Returns a Firebird IUtil interface.
Definition Client.h:145
Client(fb::IMaster *master)
Constructs a Client object that uses the specified IMaster interface.
Definition Client.h:59
FbUniquePtr< fb::IStatus > newStatus()
Creates and returns a Firebird IStatus instance.
Definition Client.h:200
fb::IDecFloat16 * getDecFloat16Util(StatusType *status)
Returns a Firebird IDecFloat16 interface.
Definition Client.h:173
fb::IMaster * getMaster() noexcept
Returns the Firebird IMaster interface.
Definition Client.h:137
Client(const boost::dll::fs::path &fbclientLibPath, boost::dll::load_mode::type loadMode=boost::dll::load_mode::append_decorations|boost::dll::load_mode::search_system_folders)
Constructs a Client object that loads the Firebird client library (or embedded engine) from the speci...
Definition Client.h:70
Client(boost::dll::shared_library fbclientLib)
Constructs a Client object that uses the specified Boost.DLL shared_library representing the Firebird...
Definition Client.h:81
~Client() noexcept=default
If the Client object was created using Boost.DLL, this destructor just releases the internal boost::d...
fb::IDecFloat34 * getDecFloat34Util(StatusType *status)
Returns a Firebird IDecFloat34 interface.
Definition Client.h:187
fb::IInt128 * getInt128Util(StatusType *status)
Returns a Firebird IInt128 interface.
Definition Client.h:159
Client(Client &&o) noexcept
Move constructor.
Definition Client.h:95
fb-cpp namespace.
Definition Attachment.h:46
FbUniquePtr< T > fbUnique(T *obj) noexcept
Creates a unique pointer for a Firebird disposable object.
Definition SmartPtrs.h:59
std::unique_ptr< T, impl::FbDisposeDeleter > FbUniquePtr
Unique pointer type for Firebird disposable objects.
Definition SmartPtrs.h:53