1
/* $Id: ncbi_core_cxx.cpp,v 6.6 2001/03/02 20:08:17 lavr Exp $
2
* ===========================================================================
5
* National Center for Biotechnology Information
7
* This software/database is a "United States Government Work" under the
8
* terms of the United States Copyright Act. It was written as part of
9
* the author's official duties as a United States Government employee and
10
* thus cannot be copyrighted. This software/database is freely available
11
* to the public for use. The National Library of Medicine and the U.S.
12
* Government have not placed any restriction on its use or reproduction.
14
* Although all reasonable efforts have been taken to ensure the accuracy
15
* and reliability of the software and data, the NLM and the U.S.
16
* Government do not and cannot warrant the performance or results that
17
* may be obtained by using this software or data. The NLM and the U.S.
18
* Government disclaim all warranties, express or implied, including
19
* warranties of performance, merchantability or fitness for any particular
22
* Please cite the author in any work or product based on this material.
24
* ===========================================================================
26
* Author: Anton Lavrentiev
29
* C++->C conversion functions for basic corelib stuff:
34
* ---------------------------------------------------------------------------
35
* $Log: ncbi_core_cxx.cpp,v $
36
* Revision 6.6 2001/03/02 20:08:17 lavr
39
* Revision 6.5 2001/01/25 17:03:46 lavr
40
* s_LOG_Handler: user_data commented out as unused
42
* Revision 6.4 2001/01/23 23:08:06 lavr
43
* LOG_cxx2c introduced
45
* Revision 6.3 2001/01/12 05:48:50 vakatov
46
* Use reinterpret_cast<> rather than static_cast<> to cast functions.
47
* Added more paranoia to catch ALL possible exceptions in the s_*** functions.
49
* Revision 6.2 2001/01/11 23:51:47 lavr
50
* static_cast instead of linkage specification 'extern "C" {}'.
51
* Reason: MSVC++ doesn't allow C-linkage of the funs compiled in C++ file.
53
* Revision 6.1 2001/01/11 23:08:16 lavr
56
* ===========================================================================
59
#include <connect/ncbi_core_cxx.hpp>
60
#include <corelib/ncbistr.hpp>
67
static void s_REG_Get(void* user_data,
68
const char* section, const char* name,
69
char* value, size_t value_size)
72
string result = static_cast<CNcbiRegistry*> (user_data)->
75
if ( !result.empty() ) {
76
strncpy(value, result.c_str(), value_size - 1);
77
value[value_size - 1] = '\0';
80
STD_CATCH_ALL("s_REG_Get() failed");
84
static void s_REG_Set(void* user_data,
85
const char* section, const char* name,
86
const char* value, EREG_Storage storage)
89
static_cast<CNcbiRegistry*> (user_data)->
90
Set(section, name, value,
91
(storage == eREG_Persistent ? CNcbiRegistry::ePersistent : 0) |
92
CNcbiRegistry::eOverride | CNcbiRegistry::eTruncate);
94
STD_CATCH_ALL("s_REG_Set() failed");
98
static void s_REG_Cleanup(void* user_data)
101
delete static_cast<CNcbiRegistry*> (user_data);
103
STD_CATCH_ALL("s_REG_Cleanup() failed");
107
extern REG REG_cxx2c(CNcbiRegistry* reg, bool pass_ownership)
110
(static_cast<void*> (reg),
111
reinterpret_cast<FREG_Get> (s_REG_Get),
112
reinterpret_cast<FREG_Set> (s_REG_Set),
113
pass_ownership ? reinterpret_cast<FREG_Cleanup> (s_REG_Cleanup) : 0,
118
static void s_LOG_Handler(void* /*user_data*/, SLOG_Handler* call_data)
121
switch (call_data->level) {
129
level = eDiag_Warning;
135
level = eDiag_Critical;
143
CNcbiDiag diag(level, eDPF_Default);
145
diag.SetFile(call_data->file);
147
diag.SetLine(call_data->line);
148
diag << call_data->message;
149
if (call_data->raw_data && call_data->raw_size) {
151
"\n#################### [BEGIN] Raw Data (" <<
152
call_data->raw_size <<
153
" byte" << (call_data->raw_size != 1 ? "s" : "") << ")\n" <<
154
NStr::PrintableString
155
(string(static_cast<const char*>(call_data->raw_data),
156
call_data->raw_size)) <<
157
"\n#################### [END] Raw Data";
162
extern LOG LOG_cxx2c(void)
165
reinterpret_cast<FLOG_Handler> (s_LOG_Handler),