PDF SDK Documentation

Comprehensive Guide for Developers: Features, Integration, and API Reference

Loading...
Searching...
No Matches
callback.h
1// Copyright (c) 2009-2025 Avanquest Software. All rights reserved.
2
3#ifndef PDFSDK_CXX_CALLBACK_H_INCLUDED_
4#define PDFSDK_CXX_CALLBACK_H_INCLUDED_
5
6#include <cstring>
7#include <string>
8#include <utility>
9
10#include <pdfsdk/core.h>
11#include <pdfsdk/cxx/exception.h>
12
13#define PDFSDK_CALLBACK_BEGIN \
14 try { \
15 PDSetErrMessage("");
16
17#define PDFSDK_CALLBACK_END \
18 } \
19 catch (PDF::Exception & ex) { \
20 PDSetErrMessage(ex.GetErrorMessage()); \
21 return ex.GetErrorCode(); \
22 } \
23 catch (std::exception & ex) { \
24 PDSetErrMessage(ex.what()); \
25 return kPDErrInternalError; \
26 } \
27 catch (...) { \
28 PDSetErrMessage("Unknown error"); \
29 return kPDErrInternalError; \
30 }
31
32namespace PDF {
33
34template<class ElemT>
35inline PDErrCode CopyDataToBuffer(const ElemT* data,
36 size_t size,
37 void* buffer,
38 size_t bufsize,
39 size_t* pSize) {
40 if (pSize)
41 *pSize = size;
42
43 if (bufsize < size)
45
46 if (buffer && size > 0)
47 std::memcpy(buffer, data, size * sizeof(ElemT));
48 return kPDErrSuccess;
49}
50
51template<class ContT>
52inline PDErrCode CopyDataToBuffer(const ContT& cont, void* buffer, size_t bufsize, size_t* pSize) {
53 return CopyDataToBuffer(std::data(cont), std::size(cont), buffer, bufsize, pSize);
54}
55
56} // namespace PDF
57
58#endif // PDFSDK_CXX_CALLBACK_H_INCLUDED_
@ kPDErrSuccess
Operation was successful.
Definition errors.h:18
@ kPDErrBufferTooSmall
Memory buffer too small, increase buffer size.
Definition errors.h:25
int32_t PDErrCode
Definition errors.h:44