fb-cpp 0.0.1
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-api.h"
30#include "SmartPtrs.h"
31#include <cassert>
32#include <concepts>
33#include <memory>
34#include <string>
35#include <type_traits>
36
37#if FB_CPP_USE_BOOST_DLL != 0
38#include <boost/dll.hpp>
39#endif
40
41
45namespace fbcpp
46{
52 class Client final
53 {
54 public:
58 explicit Client(fb::IMaster* master)
59 : master{master}
60 {
61 assert(master);
62 }
63
64#if FB_CPP_USE_BOOST_DLL != 0
69 explicit Client(const boost::dll::fs::path& fbclientLibPath,
70 boost::dll::load_mode::type loadMode = boost::dll::load_mode::append_decorations |
71 boost::dll::load_mode::search_system_folders)
72 : Client{boost::dll::shared_library{fbclientLibPath, loadMode}}
73 {
74 }
75
80 explicit Client(boost::dll::shared_library fbclientLib)
81 : fbclientLib(fbclientLib)
82 {
83 const auto fbGetMasterInterface =
84 fbclientLib.get<decltype(fb::fb_get_master_interface)>("fb_get_master_interface");
85 master = fbGetMasterInterface();
86 assert(master);
87 }
88#endif
89
94 Client(Client&& o) noexcept
95 : master{o.master},
96 util{o.util},
97 int128Util{o.int128Util},
98 decFloat16Util{o.decFloat16Util},
99 decFloat34Util{o.decFloat34Util}
100#if FB_CPP_USE_BOOST_DLL != 0
101 ,
102 fbclientLib{std::move(o.fbclientLib)}
103#endif
104 {
105 o.master = nullptr;
106 o.util = nullptr;
107 o.int128Util = nullptr;
108 o.decFloat16Util = nullptr;
109 o.decFloat34Util = nullptr;
110 }
111
117 ~Client() noexcept = default;
118
119 Client& operator=(Client&&) = delete;
120
121 Client& operator=(const Client& o) = delete;
122 Client(const Client&) = delete;
123
124 public:
128 bool isValid() noexcept
129 {
130 return master != nullptr;
131 }
132
136 fb::IMaster* getMaster() noexcept
137 {
138 return master;
139 }
140
144 fb::IUtil* getUtil()
145 {
146 assert(master);
147
148 if (!util)
149 util = master->getUtilInterface();
150
151 return util;
152 }
153
157 template <std::derived_from<fb::IStatus> StatusType>
158 fb::IInt128* getInt128Util(StatusType* status)
159 {
160 assert(status);
161
162 if (!int128Util)
163 int128Util = getUtil()->getInt128(status);
164
165 return int128Util;
166 }
167
171 template <std::derived_from<fb::IStatus> StatusType>
172 fb::IDecFloat16* getDecFloat16Util(StatusType* status)
173 {
174 assert(status);
175
176 if (!decFloat16Util)
177 decFloat16Util = getUtil()->getDecFloat16(status);
178
179 return decFloat16Util;
180 }
181
185 template <std::derived_from<fb::IStatus> StatusType>
186 fb::IDecFloat34* getDecFloat34Util(StatusType* status)
187 {
188 assert(status);
189
190 if (!decFloat34Util)
191 decFloat34Util = getUtil()->getDecFloat34(status);
192
193 return decFloat34Util;
194 }
195
199 FbUniquePtr<fb::IStatus> newStatus()
200 {
201 assert(master);
202 return fbUnique(master->getStatus());
203 }
204
208 void shutdown();
209
210 private:
211 fb::IMaster* master;
212 fb::IUtil* util = nullptr;
213 fb::IInt128* int128Util = nullptr;
214 fb::IDecFloat16* decFloat16Util = nullptr;
215 fb::IDecFloat34* decFloat34Util = nullptr;
216#if FB_CPP_USE_BOOST_DLL != 0
217 boost::dll::shared_library fbclientLib;
218#endif
219 };
220} // namespace fbcpp
221
222
223#endif // FBCPP_CLIENT_H
Represents a Firebird client library instance.
Definition Client.h:53
fb::IUtil * getUtil()
Returns a Firebird IUtil interface.
Definition Client.h:144
Client(fb::IMaster *master)
Constructs a Client object that uses the specified IMaster interface.
Definition Client.h:58
FbUniquePtr< fb::IStatus > newStatus()
Creates and returns a Firebird IStatus instance.
Definition Client.h:199
fb::IDecFloat16 * getDecFloat16Util(StatusType *status)
Returns a Firebird IDecFloat16 interface.
Definition Client.h:172
fb::IMaster * getMaster() noexcept
Returns the Firebird IMaster interface.
Definition Client.h:136
void shutdown()
Shuts down the Firebird client library (or embedded engine) instance.
Definition Client.cpp:33
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:69
Client(boost::dll::shared_library fbclientLib)
Constructs a Client object that uses the specified Boost.DLL shared_library representing the Firebird...
Definition Client.h:80
~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:186
fb::IInt128 * getInt128Util(StatusType *status)
Returns a Firebird IInt128 interface.
Definition Client.h:158
bool isValid() noexcept
Returns whether the Client object is valid.
Definition Client.h:128
Client(Client &&o) noexcept
Move constructor.
Definition Client.h:94
fb-cpp namespace.
Definition Attachment.h:42