Skip to content

Commit 74e3400

Browse files
committed
Rework in terms of an affirming -DHaveBlp and streamline code
1 parent a6e602a commit 74e3400

23 files changed

+235
-280
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 <edd@debian.org>
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 <edd@debian.org>
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: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ BEGIN_RCPP
9898
END_RCPP
9999
}
100100
// beqs_Impl
101-
DataFrame beqs_Impl(SEXP con, std::string screenName, std::string screenType, std::string group, std::string pitdate, std::string languageId, bool verbose);
101+
Rcpp::DataFrame beqs_Impl(SEXP con, std::string screenName, std::string screenType, std::string group, std::string pitdate, std::string languageId, bool verbose);
102102
RcppExport SEXP _Rblpapi_beqs_Impl(SEXP conSEXP, SEXP screenNameSEXP, SEXP screenTypeSEXP, SEXP groupSEXP, SEXP pitdateSEXP, SEXP languageIdSEXP, SEXP verboseSEXP) {
103103
BEGIN_RCPP
104104
Rcpp::RObject rcpp_result_gen;
@@ -148,8 +148,18 @@ BEGIN_RCPP
148148
return rcpp_result_gen;
149149
END_RCPP
150150
}
151+
// haveBlp
152+
bool haveBlp();
153+
RcppExport SEXP _Rblpapi_haveBlp() {
154+
BEGIN_RCPP
155+
Rcpp::RObject rcpp_result_gen;
156+
Rcpp::RNGScope rcpp_rngScope_gen;
157+
rcpp_result_gen = Rcpp::wrap(haveBlp());
158+
return rcpp_result_gen;
159+
END_RCPP
160+
}
151161
// bsrch_Impl
152-
DataFrame bsrch_Impl(SEXP con, std::string domain, std::string limit, bool verbose);
162+
Rcpp::DataFrame bsrch_Impl(SEXP con, std::string domain, std::string limit, bool verbose);
153163
RcppExport SEXP _Rblpapi_bsrch_Impl(SEXP conSEXP, SEXP domainSEXP, SEXP limitSEXP, SEXP verboseSEXP) {
154164
BEGIN_RCPP
155165
Rcpp::RObject rcpp_result_gen;
@@ -264,6 +274,7 @@ static const R_CallMethodDef CallEntries[] = {
264274
{"_Rblpapi_blpConnect_Impl", (DL_FUNC) &_Rblpapi_blpConnect_Impl, 4},
265275
{"_Rblpapi_getHeaderVersion", (DL_FUNC) &_Rblpapi_getHeaderVersion, 0},
266276
{"_Rblpapi_getRuntimeVersion", (DL_FUNC) &_Rblpapi_getRuntimeVersion, 0},
277+
{"_Rblpapi_haveBlp", (DL_FUNC) &_Rblpapi_haveBlp, 0},
267278
{"_Rblpapi_bsrch_Impl", (DL_FUNC) &_Rblpapi_bsrch_Impl, 4},
268279
{"_Rblpapi_fieldSearch_Impl", (DL_FUNC) &_Rblpapi_fieldSearch_Impl, 2},
269280
{"_Rblpapi_getBars_Impl", (DL_FUNC) &_Rblpapi_getBars_Impl, 8},

src/authenticate.cpp

Lines changed: 11 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,26 @@ Identity* authenticateWithApp(SEXP con_) {
180178
}
181179
return identity_p;
182180
}
181+
#else
182+
#include <Rcpp/Lightest>
183+
#endif
183184

184185
// Simpler interface
185186
//
186187
// [[Rcpp::export]]
187-
SEXP authenticate_Impl(SEXP con_, SEXP uuid_, SEXP ip_address_, SEXP is_auth_id_,
188-
SEXP app_name_) {
188+
SEXP authenticate_Impl(SEXP con_, SEXP uuid_, SEXP ip_address_, SEXP is_auth_id_, SEXP app_name_) {
189+
#if defined(HaveBlp)
189190
Identity* identity_p = NULL;
190191
if (uuid_ == R_NilValue) {
191192
identity_p = authenticateWithApp(con_);
192193
} else {
193194
identity_p = authenticateWithId(con_, uuid_, ip_address_, is_auth_id_, app_name_);
194195
}
195-
if(identity_p == NULL) { Rcpp::stop("Identity pointer is null\n"); }
196+
if (identity_p == NULL) {
197+
Rcpp::stop("Identity pointer is null\n");
198+
}
196199
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_) {
200+
#else // ie no Blp
203201
return R_NilValue;
204-
}
205-
206202
#endif
203+
}

src/bdh.cpp

Lines changed: 8 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,9 @@ Rcpp::List HistoricalDataResponseToDF(Event& event, const std::vector<std::strin
8987
}
9088
return res;
9189
}
90+
#else
91+
#include <Rcpp/Lightest>
92+
#endif
9293

9394
// Simpler interface with std::vector<std::string> thanks to Rcpp::Attributes
9495
// [[Rcpp::export]]
@@ -100,6 +101,8 @@ Rcpp::List bdh_Impl(SEXP con_,
100101
bool verbose, SEXP identity_,
101102
bool int_as_double) {
102103

104+
#if defined(HaveBlp)
105+
103106
Session* session =
104107
reinterpret_cast<Session*>(checkExternalPointer(con_,"blpapi::Session*"));
105108

@@ -189,19 +192,8 @@ Rcpp::List bdh_Impl(SEXP con_,
189192
}
190193
ans.attr("names") = ans_names;
191194
return ans;
192-
}
193195

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) {
196+
#else // ie no Blp
204197
return Rcpp::List();
205-
}
206-
207198
#endif
199+
}

0 commit comments

Comments
 (0)