Debian Codegraph @

modules/lsp-runtime-lib/include/lsp-plug.in/fmt/java/RawArray.h

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: 30 авг. 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 #ifndef LSP_PLUG_IN_FMT_JAVA_RAWARRAY_H_
23 #define LSP_PLUG_IN_FMT_JAVA_RAWARRAY_H_
24
25 #include <lsp-plug.in/runtime/version.h>
26 #include <lsp-plug.in/runtime/LSPString.h>
27 #include <lsp-plug.in/fmt/java/Object.h>
28 #include <lsp-plug.in/fmt/java/ObjectStreamField.h>
29
30 namespace lsp
31 {
32 namespace java
33 {
34 class RawArray: public Object
35 {
36 public:
37 static const char *CLASS_NAME;
38
39 private:
40 friend class ObjectStream;
41 RawArray & operator = (const RawArray &);
42
43 private:
44 size_t nLength;
45 ftype_t enItemType;
46 LSPString sItemType;
47 void *pData;
48
49 private:
50 status_t allocate(size_t items);
51 template <class type_t>
52 inline type_t *get() { return reinterpret_cast<type_t *>(pData); }
53
54 protected:
55 virtual status_t to_string_padded(LSPString *dst, size_t pad);
56
57 public:
58 explicit RawArray(const char *xc);
59 virtual ~RawArray();
60
61 public:
62 inline size_t length() const { return nLength; }
63 inline ftype_t item_type() const { return enItemType; }
64 inline size_t item_size_of() const { return size_of(enItemType); }
65 inline const LSPString *item_type_name() const { return &sItemType; }
66
67 virtual bool instanceof(const char *name) const;
68
69 public:
70 #define __GET_DEF(otype, name, jft_type) \
71 inline const otype *name() const { \
72 return (enItemType != jft_type) ? NULL : \
73 reinterpret_cast<const otype *>(pData); \
74 }
75
76 __GET_DEF(byte_t, get_bytes, JFT_BYTE)
77 __GET_DEF(short_t, get_shorts, JFT_SHORT)
78 __GET_DEF(int_t, get_ints, JFT_INTEGER)
79 __GET_DEF(long_t, get_longs, JFT_LONG)
80 __GET_DEF(float_t, get_floats, JFT_FLOAT)
81 __GET_DEF(double_t, get_doubles, JFT_DOUBLE)
82 __GET_DEF(bool_t, get_bools, JFT_BOOL)
83 __GET_DEF(char_t, get_chars, JFT_CHAR)
84 __GET_DEF(Object *, get_objects, JFT_OBJECT)
85
86 #undef __GET_DEF
87 };
88
89 } /* namespace java */
90 } /* namespace lsp */
91
92 #endif /* LSP_PLUG_IN_FMT_JAVA_RAWARRAY_H_ */