Debian Codegraph @

modules/lsp-runtime-lib/src/main/fmt/java/wrappers.cpp

raw
1 /*
2 * Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/>
3 * (C) 2020 Vladimir Sadovnikov <[email protected]>
4 *
5 * This file is part of lsp-runtime-lib
6 * Created on: 6 сент. 2019 г.
7 *
8 * lsp-runtime-lib is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version.
12 *
13 * lsp-runtime-lib is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with lsp-runtime-lib. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22 #include <lsp-plug.in/fmt/java/wrappers.h>
23
24 namespace lsp
25 {
26 namespace java
27 {
28 #define WRAPPER_DEF(name, type_t) \
29 const char *name::CLASS_NAME = "java.lang." #name; \
30 \
31 name::name(): Object(CLASS_NAME) {} \
32 \
33 name::~name() {} \
34 \
35 type_t name::value() const \
36 { \
37 if (nSlots <= 0) return 0; \
38 object_slot_t *s = &vSlots[nSlots-1]; \
39 if (s->size < sizeof(type_t)) return 0; \
40 type_t *ptr = reinterpret_cast<type_t *>(&vData[s->offset]); \
41 return *ptr; \
42 } \
43 \
44 status_t name::get_value(type_t *dst) const \
45 { \
46 if (nSlots <= 0) return STATUS_CORRUPTED; \
47 object_slot_t *s = &vSlots[nSlots-1]; \
48 if (s->size < sizeof(type_t)) return STATUS_CORRUPTED; \
49 type_t *ptr = reinterpret_cast<type_t *>(&vData[s->offset]); \
50 if (dst != NULL) *dst = *ptr; \
51 return STATUS_OK; \
52 } \
53
54 WRAPPER_DEF(Byte, byte_t);
55 WRAPPER_DEF(Short, short_t);
56 WRAPPER_DEF(Integer, int_t);
57 WRAPPER_DEF(Long, long_t);
58 WRAPPER_DEF(Double, double_t);
59 WRAPPER_DEF(Float, float_t);
60 WRAPPER_DEF(Boolean, bool_t);
61 WRAPPER_DEF(Character, char_t);
62
63 status_t Byte::to_string_padded(LSPString *dst, size_t pad)
64 {
65 return (dst->fmt_append_ascii("*%p = new Byte(%d)\n", this, int(value()))) ? STATUS_OK : STATUS_NO_MEM;
66 }
67
68 status_t Short::to_string_padded(LSPString *dst, size_t pad)
69 {
70 return (dst->fmt_append_ascii("*%p = new Short(%d)\n", this, int(value()))) ? STATUS_OK : STATUS_NO_MEM;
71 }
72
73 status_t Integer::to_string_padded(LSPString *dst, size_t pad)
74 {
75 return (dst->fmt_append_ascii("*%p = new Integer(%d)\n", this, int(value()))) ? STATUS_OK : STATUS_NO_MEM;
76 }
77
78 status_t Long::to_string_padded(LSPString *dst, size_t pad)
79 {
80 return (dst->fmt_append_ascii("*%p = new Long(%d)\n", this, int(value()))) ? STATUS_OK : STATUS_NO_MEM;
81 }
82
83 status_t Double::to_string_padded(LSPString *dst, size_t pad)
84 {
85 return (dst->fmt_append_ascii("*%p = new Double(%f)\n", this, value())) ? STATUS_OK : STATUS_NO_MEM;
86 }
87
88 status_t Float::to_string_padded(LSPString *dst, size_t pad)
89 {
90 return (dst->fmt_append_ascii("*%p = new Float(%f)\n", this, value())) ? STATUS_OK : STATUS_NO_MEM;
91 }
92
93 status_t Boolean::to_string_padded(LSPString *dst, size_t pad)
94 {
95 return (dst->fmt_append_ascii("*%p = new Boolean(%s)\n", this, (value()) ? "true" : "false")) ? STATUS_OK : STATUS_NO_MEM;
96 }
97
98 status_t Character::to_string_padded(LSPString *dst, size_t pad)
99 {
100 if (!dst->fmt_append_ascii("*%p = new Character('", this))
101 return STATUS_NO_MEM;
102 dst->append(lsp_wchar_t(value()));
103 return (dst->append_ascii("')\n")) ? STATUS_OK : STATUS_NO_MEM;
104 }
105
106 #undef WRAPPER_DEF
107 }
108 }
109