| 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: 29 авг. 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_OBJECT_H_ |
| 23 |
#define LSP_PLUG_IN_FMT_JAVA_OBJECT_H_ |
| 24 |
|
| 25 |
#include <lsp-plug.in/runtime/version.h> |
| 26 |
#include <lsp-plug.in/common/types.h> |
| 27 |
#include <lsp-plug.in/common/status.h> |
| 28 |
#include <lsp-plug.in/runtime/LSPString.h> |
| 29 |
#include <lsp-plug.in/fmt/java/const.h> |
| 30 |
|
| 31 |
namespace lsp |
| 32 |
{ |
| 33 |
namespace java |
| 34 |
{ |
| 35 |
typedef uint32_t handle_t; |
| 36 |
|
| 37 |
class ObjectStreamClass; |
| 38 |
class RawArray; |
| 39 |
class Enum; |
| 40 |
class String; |
| 41 |
|
| 42 |
typedef struct object_slot_t |
| 43 |
{ |
| 44 |
ObjectStreamClass *desc; // Slot descriptor |
| 45 |
size_t offset; // Offset from data beginning |
| 46 |
size_t size; // Size in bytes |
| 47 |
size_t __pad; |
| 48 |
} object_slot_t; |
| 49 |
|
| 50 |
/** |
| 51 |
* This is common Java object implementation, |
| 52 |
* should be always allocated with new() operator |
| 53 |
*/ |
| 54 |
class Object |
| 55 |
{ |
| 56 |
public: |
| 57 |
static const char *CLASS_NAME; |
| 58 |
|
| 59 |
private: |
| 60 |
friend class ObjectStream; |
| 61 |
friend class RawArray; |
| 62 |
|
| 63 |
protected: |
| 64 |
const char *pClass; |
| 65 |
object_slot_t *vSlots; |
| 66 |
size_t nSlots; |
| 67 |
uint8_t *vData; |
| 68 |
|
| 69 |
private: |
| 70 |
template <class type_t, class cast_t> |
| 71 |
inline status_t read_reference(const char *field, type_t *item, ftype_t type) const; |
| 72 |
|
| 73 |
template <class type_t, class wrapper_t> |
| 74 |
inline status_t read_prim_item(const char *field, type_t *item, ftype_t type) const; |
| 75 |
|
| 76 |
protected: |
| 77 |
virtual status_t to_string_padded(LSPString *dst, size_t pad); |
| 78 |
static bool pad_string(LSPString *dst, size_t pad); |
| 79 |
|
| 80 |
public: |
| 81 |
explicit Object(const char *class_name); |
| 82 |
Object(const Object &) = delete; |
| 83 |
Object(Object &&) = delete; |
| 84 |
virtual ~Object(); |
| 85 |
|
| 86 |
Object & operator = (const Object &) = delete; |
| 87 |
Object & operator = (Object &&) = delete; |
| 88 |
|
| 89 |
public: |
| 90 |
inline const char *class_name() const { return pClass; } |
| 91 |
|
| 92 |
virtual bool instanceof(const char *name) const; |
| 93 |
|
| 94 |
public: |
| 95 |
status_t get_byte(const char *field, byte_t *dst) const; |
| 96 |
status_t get_short(const char *field, short_t *dst) const; |
| 97 |
status_t get_int(const char *field, int_t *dst) const; |
| 98 |
status_t get_long(const char *field, long_t *dst) const; |
| 99 |
status_t get_float(const char *field, float_t *dst) const; |
| 100 |
status_t get_double(const char *field, double_t *dst) const; |
| 101 |
status_t get_char(const char *field, char_t *dst) const; |
| 102 |
status_t get_bool(const char *field, bool_t *dst) const; |
| 103 |
status_t get_array(const char *field, const RawArray **dst) const; |
| 104 |
status_t get_object(const char *field, const Object **dst) const; |
| 105 |
status_t get_string(const char *field, const String **dst) const; |
| 106 |
status_t get_string(const char *field, LSPString *dst) const; |
| 107 |
status_t get_string(const char *field, const char **dst) const; |
| 108 |
status_t get_enum(const char *field, const Enum **dst) const; |
| 109 |
status_t get_enum(const char *field, LSPString *dst) const; |
| 110 |
status_t get_enum(const char *field, const char **dst) const; |
| 111 |
|
| 112 |
public: |
| 113 |
template <class T> |
| 114 |
inline T *cast() { return (instanceof(T::CLASS_NAME)) ? static_cast<T *>(this) : NULL; } |
| 115 |
|
| 116 |
template <class T> |
| 117 |
inline const T *cast() const { return (instanceof(T::CLASS_NAME)) ? static_cast<const T *>(this) : NULL; } |
| 118 |
|
| 119 |
status_t to_string(LSPString *dst) const; |
| 120 |
}; |
| 121 |
|
| 122 |
} /* namespace java */ |
| 123 |
} /* namespace lsp */ |
| 124 |
|
| 125 |
#endif /* LSP_PLUG_IN_FMT_JAVA_OBJECT_H_ */ |