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 decFloat16Util{o.decFloat16Util},
98 decFloat34Util{o.decFloat34Util}
99#if FB_CPP_USE_BOOST_DLL != 0
100 ,
101 fbclientLib{std::move(o.fbclientLib)}
102#endif
103 {
104 o.master = nullptr;
105 o.util = nullptr;
106 o.decFloat16Util = nullptr;
107 o.decFloat34Util = nullptr;
108 }
109
115 ~Client() noexcept = default;
116
117 Client& operator=(Client&&) = delete;
118
119 Client& operator=(const Client& o) = delete;
120 Client(const Client&) = delete;
121
122 public:
126 bool isValid() noexcept
127 {
128 return master != nullptr;
129 }
130
134 fb::IMaster* getMaster() noexcept
135 {
136 return master;
137 }
138
142 fb::IUtil* getUtil()
143 {
144 assert(master);
145
146 if (!util)
147 util = master->getUtilInterface();
148
149 return util;
150 }
151
155 template <std::derived_from<fb::IStatus> StatusType>
156 fb::IDecFloat16* getDecFloat16Util(StatusType* status)
157 {
158 assert(status);
159
160 if (!decFloat16Util)
161 decFloat16Util = getUtil()->getDecFloat16(status);
162
163 return decFloat16Util;
164 }
165
169 template <std::derived_from<fb::IStatus> StatusType>
170 fb::IDecFloat34* getDecFloat34Util(StatusType* status)
171 {
172 assert(status);
173
174 if (!decFloat34Util)
175 decFloat34Util = getUtil()->getDecFloat34(status);
176
177 return decFloat34Util;
178 }
179
183 FbUniquePtr<fb::IStatus> newStatus()
184 {
185 assert(master);
186 return fbUnique(master->getStatus());
187 }
188
192 void shutdown();
193
194 private:
195 fb::IMaster* master;
196 fb::IUtil* util = nullptr;
197 fb::IDecFloat16* decFloat16Util = nullptr;
198 fb::IDecFloat34* decFloat34Util = nullptr;
199#if FB_CPP_USE_BOOST_DLL != 0
200 boost::dll::shared_library fbclientLib;
201#endif
202 };
203} // namespace fbcpp
204
205
206#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:142
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:183
fb::IDecFloat16 * getDecFloat16Util(StatusType *status)
Returns a Firebird IDecFloat16 interface.
Definition Client.h:156
fb::IMaster * getMaster() noexcept
Returns the Firebird IMaster interface.
Definition Client.h:134
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:170
bool isValid() noexcept
Returns whether the Client object is valid.
Definition Client.h:126
Client(Client &&o) noexcept
Move constructor.
Definition Client.h:94
fb-cpp namespace.
Definition Attachment.h:42