Skip to content

Commit d95b113

Browse files
committed
Rework in terms of an affirming -DHaveBlp and streamline code
1 parent c93d93b commit d95b113

23 files changed

+194
-267
lines changed

ChangeLog

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
2025-03-14 Dirk Eddelbuettel <[email protected]>
2+
3+
* src/authenticate.cpp: Redefine in terms of -DHaveBlp flag and bring
4+
if/else inside the function itself
5+
* src/bdh.cpp: Idem
6+
* src/bdp.cpp: Idem
7+
* src/bds.cpp: Idem
8+
* src/beqs.cpp: Idem
9+
* src/blpConnect.cpp: Idem
10+
* src/blpVersion.cpp: Idem
11+
* src/blpapi_utils.cpp: Idem
12+
* src/bsrch.cpp: Idem
13+
* src/fieldsearch.cpp: Idem
14+
* src/getBars.cpp: Idem
15+
* src/getFieldInfo.cpp: Idem
16+
* src/getTicks.cpp: Idem
17+
* src/lookup.cpp: Idem
18+
* src/subscribe.cpp: Idem
19+
20+
* src/blpVersion.cpp: Define simple haveBlp() helper
21+
* man/haveBlp.Rd: Documentation for haveBlp()
22+
* R/init.R: Use more explicit haveBlp()
23+
124
2025-03-13 Dirk Eddelbuettel <[email protected]>
225

326
* DESCRIPTION (Version, Date): Roll micro version and date

R/RcppExports.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ getRuntimeVersion <- function() {
5959
.Call(`_Rblpapi_getRuntimeVersion`)
6060
}
6161

62+
#' This function returns a boolean indicating whether Blp support is available.
63+
#'
64+
#' @title Get Blp availability in current build
65+
#' @return A logical indicating whether Blp was available at build.
66+
#' @author Dirk Eddelbuettel
67+
haveBlp <- function() {
68+
.Call(`_Rblpapi_haveBlp`)
69+
}
70+
6271
bsrch_Impl <- function(con, domain, limit, verbose = FALSE) {
6372
.Call(`_Rblpapi_bsrch_Impl`, con, domain, limit, verbose)
6473
}

R/init.R

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,12 @@
2121
.pkgenv <- new.env(parent=emptyenv())
2222

2323
.onAttach <- function(libname, pkgname) {
24-
hrd <- getHeaderVersion()
25-
rtm <- getRuntimeVersion()
26-
if (nchar(hrd) + nchar(rtm) == 0) {
27-
packageStartupMessage("No Blp available so no Rblapi functionality.")
28-
} else {
24+
if (haveBlp()) {
2925
packageStartupMessage(paste0("Rblpapi version ", packageVersion("Rblpapi"),
30-
" using Blpapi headers ", hrd, " and run-time ", rtm, "."))
26+
" using Blpapi headers ", getHeaderVersion(),
27+
" and run-time ", getRuntimeVersion(), "."))
3128
packageStartupMessage(paste0("Please respect the Bloomberg licensing agreement ",
3229
"and terms of service."))
33-
3430
if (getOption("blpAutoConnect", FALSE)) {
3531
con <- blpConnect()
3632
if (getOption("blpVerbose", FALSE)) {
@@ -49,5 +45,7 @@
4945
}
5046
assign("con", con, envir=.pkgenv)
5147
assign("blpAuth", blpAuth, envir=.pkgenv)
48+
} else {
49+
packageStartupMessage("No Blp available so no Rblapi functionality.")
5250
}
5351
}

man/blpAuthenticate.Rd

Lines changed: 4 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/getTicks.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/haveBlp.Rd

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Makevars.win

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
##
33
## Makefile.win -- Windows build system
44
##
5-
## Copyright (C) 2015 - 2024 Whit Armstrong and Dirk Eddelbuettel
5+
## Copyright (C) 2015 - 2025 Whit Armstrong and Dirk Eddelbuettel
66
##
77
## This file is part of Rblpapi
88
##
@@ -28,8 +28,7 @@ else
2828
endif
2929

3030
## Standard compiler / linker flags including windows flavor
31-
# CXX_STD = CXX11
32-
PKG_CPPFLAGS = -I../inst/include -I.
31+
PKG_CPPFLAGS = -I../inst/include -I. -DHaveBlp
3332
PKG_LIBS = -lblpapi3_${WIN} -L${FLV}
3433

3534

src/RcppExports.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,16 @@ BEGIN_RCPP
147147
return rcpp_result_gen;
148148
END_RCPP
149149
}
150+
// haveBlp
151+
bool haveBlp();
152+
RcppExport SEXP _Rblpapi_haveBlp() {
153+
BEGIN_RCPP
154+
Rcpp::RObject rcpp_result_gen;
155+
Rcpp::RNGScope rcpp_rngScope_gen;
156+
rcpp_result_gen = Rcpp::wrap(haveBlp());
157+
return rcpp_result_gen;
158+
END_RCPP
159+
}
150160
// bsrch_Impl
151161
DataFrame bsrch_Impl(SEXP con, std::string domain, std::string limit, bool verbose);
152162
RcppExport SEXP _Rblpapi_bsrch_Impl(SEXP conSEXP, SEXP domainSEXP, SEXP limitSEXP, SEXP verboseSEXP) {
@@ -263,6 +273,7 @@ static const R_CallMethodDef CallEntries[] = {
263273
{"_Rblpapi_blpConnect_Impl", (DL_FUNC) &_Rblpapi_blpConnect_Impl, 3},
264274
{"_Rblpapi_getHeaderVersion", (DL_FUNC) &_Rblpapi_getHeaderVersion, 0},
265275
{"_Rblpapi_getRuntimeVersion", (DL_FUNC) &_Rblpapi_getRuntimeVersion, 0},
276+
{"_Rblpapi_haveBlp", (DL_FUNC) &_Rblpapi_haveBlp, 0},
266277
{"_Rblpapi_bsrch_Impl", (DL_FUNC) &_Rblpapi_bsrch_Impl, 4},
267278
{"_Rblpapi_fieldSearch_Impl", (DL_FUNC) &_Rblpapi_fieldSearch_Impl, 2},
268279
{"_Rblpapi_getBars_Impl", (DL_FUNC) &_Rblpapi_getBars_Impl, 8},

src/authenticate.cpp

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
// You should have received a copy of the GNU General Public License
2121
// along with Rblpapi. If not, see <http://www.gnu.org/licenses/>.
2222

23-
#if !defined(NoBlpHere)
24-
23+
#if defined(HaveBlp)
2524
#include <string>
2625
#include <blpapi_defs.h>
2726
#include <blpapi_element.h>
@@ -32,7 +31,6 @@
3231
#include <blpapi_session.h>
3332
#include <blpapi_event.h>
3433
#include <blpapi_message.h>
35-
#include <Rcpp.h>
3634
#include <finalizers.h>
3735
#include <blpapi_utils.h>
3836

@@ -180,27 +178,24 @@ Identity* authenticateWithApp(SEXP con_) {
180178
}
181179
return identity_p;
182180
}
181+
#endif
183182

184183
// Simpler interface
185184
//
186185
// [[Rcpp::export]]
187-
SEXP authenticate_Impl(SEXP con_, SEXP uuid_, SEXP ip_address_, SEXP is_auth_id_,
188-
SEXP app_name_) {
186+
SEXP authenticate_Impl(SEXP con_, SEXP uuid_, SEXP ip_address_, SEXP is_auth_id_, SEXP app_name_) {
187+
#if defined(HaveBlp)
189188
Identity* identity_p = NULL;
190189
if (uuid_ == R_NilValue) {
191190
identity_p = authenticateWithApp(con_);
192191
} else {
193192
identity_p = authenticateWithId(con_, uuid_, ip_address_, is_auth_id_, app_name_);
194193
}
195-
if(identity_p == NULL) { Rcpp::stop("Identity pointer is null\n"); }
194+
if (identity_p == NULL) {
195+
Rcpp::stop("Identity pointer is null\n");
196+
}
196197
return createExternalPointer<Identity>(identity_p, identityFinalizer, "blpapi::Identity*");
197-
}
198-
199-
#else // ie if defined(NoBlpHere)
200-
201-
#include <Rcpp/Lightest>
202-
SEXP authenticate_Impl(SEXP con_, SEXP uuid_, SEXP ip_address_, SEXP is_auth_id_, SEXP app_name_) {
198+
#else // ie no Blp
203199
return R_NilValue;
204-
}
205-
206200
#endif
201+
}

src/bdh.cpp

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
// You should have received a copy of the GNU General Public License
2020
// along with Rblpapi. If not, see <http://www.gnu.org/licenses/>.
2121

22-
#if !defined(NoBlpHere)
23-
22+
#if defined(HaveBlp)
2423
#include <vector>
2524
#include <string>
2625
#include <blpapi_session.h>
@@ -29,7 +28,6 @@
2928
#include <blpapi_event.h>
3029
#include <blpapi_message.h>
3130
#include <blpapi_element.h>
32-
#include <Rcpp.h>
3331
#include <blpapi_utils.h>
3432

3533
using BloombergLP::blpapi::Session;
@@ -89,6 +87,7 @@ Rcpp::List HistoricalDataResponseToDF(Event& event, const std::vector<std::strin
8987
}
9088
return res;
9189
}
90+
#endif
9291

9392
// Simpler interface with std::vector<std::string> thanks to Rcpp::Attributes
9493
// [[Rcpp::export]]
@@ -100,6 +99,8 @@ Rcpp::List bdh_Impl(SEXP con_,
10099
bool verbose, SEXP identity_,
101100
bool int_as_double) {
102101

102+
#if defined(HaveBlp)
103+
103104
Session* session =
104105
reinterpret_cast<Session*>(checkExternalPointer(con_,"blpapi::Session*"));
105106

@@ -189,19 +190,8 @@ Rcpp::List bdh_Impl(SEXP con_,
189190
}
190191
ans.attr("names") = ans_names;
191192
return ans;
192-
}
193193

194-
#else // ie if defined(NoBlpHere)
195-
196-
#include <Rcpp/Lightest>
197-
Rcpp::List bdh_Impl(SEXP con_,
198-
std::vector<std::string> securities,
199-
std::vector<std::string> fields,
200-
std::string start_date_, SEXP end_date_,
201-
SEXP options_, SEXP overrides_,
202-
bool verbose, SEXP identity_,
203-
bool int_as_double) {
194+
#else // ie no Blp
204195
return Rcpp::List();
205-
}
206-
207196
#endif
197+
}

0 commit comments

Comments
 (0)