hc
2023-03-13 2ec15ae1cb4be1b4fcb56c6d621123d7ebdaad6c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
 * Copyright 2018 Rockchip Electronics Co. LTD
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * author: Rimon.Xu@rock-chips.com
 *   date: 20181205
 */
 
#ifndef INCLUDE_RT_BASE_RT_METADATA_H_
#define INCLUDE_RT_BASE_RT_METADATA_H_
 
#include <stdint.h>
#include <map>
#include "rt_type.h"   // NOLINT
#include "rt_error.h"  // NOLINT
 
class RtMetaData;
typedef RT_RET (*RTMetaValueFree)(void *);
 
struct RTMetaDataContext;
 
class RtMetaData {
 public:
    RtMetaData();
    RtMetaData(const RtMetaData &from);
    RtMetaData& operator = (const RtMetaData &);
 
    virtual ~RtMetaData();
 
    enum Type {
        TYPE_NONE     = MKTAG('n', 'o', 'n', 'e'),
        TYPE_C_STRING = MKTAG('c', 's', 't', 'r'),
        TYPE_INT32    = MKTAG('i', 'n', '3', '2'),
        TYPE_INT64    = MKTAG('i', 'n', '6', '4'),
        TYPE_FLOAT    = MKTAG('f', 'l', 'o', 'a'),
        TYPE_POINTER  = MKTAG('p', 'n', 't', 'r'),
        TYPE_INT8     = MKTAG('i', 'n', '0', '8'),
        TYPE_INT16    = MKTAG('i', 'n', '1', '6'),
        TYPE_STRUCT   = MKTAG('s', 'r', 'u', 't')
    };
 
    virtual void    clear();
    virtual RT_BOOL remove(UINT64 key);
 
    virtual RT_BOOL setCString(UINT64 key, const char *value);
    virtual RT_BOOL setInt32(UINT64 key, INT32 value);
    virtual RT_BOOL setInt64(UINT64 key, INT64 value);
    virtual RT_BOOL setFloat(UINT64 key, float value);
    virtual RT_BOOL setPointer(UINT64 key, RT_PTR value, RTMetaValueFree freeFunc = RT_NULL);
    virtual RT_BOOL setStructData(UINT64 key, const void *value, UINT32 size);
 
    virtual RT_BOOL findCString(UINT64 key, const char **value) const;
    virtual RT_BOOL findInt32(UINT64 key, INT32 *value) const;
    virtual RT_BOOL findInt64(UINT64 key, INT64 *value) const;
    virtual RT_BOOL findFloat(UINT64 key, float *value) const;
    virtual RT_BOOL findPointer(UINT64 key, RT_PTR *value) const;
    virtual RT_BOOL findStructData(UINT64 key, const void **value, UINT32 size) const;
 
    virtual RT_BOOL setCString(const char* key, const char *value);
    virtual RT_BOOL setInt32(const char* key, INT32 value);
    virtual RT_BOOL setInt64(const char* key, INT64 value);
    virtual RT_BOOL setFloat(const char* key, float value);
    virtual RT_BOOL setPointer(const char* key, RT_PTR value, RTMetaValueFree freeFunc = RT_NULL);
 
    virtual RT_BOOL findCString(const char* key, const char **value) const;
    virtual RT_BOOL findInt32(const char* key, INT32 *value) const;
    virtual RT_BOOL findInt64(const char* key, INT64 *value) const;
    virtual RT_BOOL findFloat(const char* key, float *value) const;
    virtual RT_BOOL findPointer(const char* key, RT_PTR *value) const;
 
    virtual RT_BOOL setData(
        UINT64 key, UINT32 type, const void *data, UINT32 size, RTMetaValueFree freeFunc = RT_NULL);
 
    virtual RT_BOOL findData(UINT64 key, UINT32 *type,
                  const void **data, UINT32 *size) const;
 
    virtual RT_BOOL hasData(UINT64 key) const;
    virtual RT_BOOL isEmpty();
 
    virtual void dumpToLog() const;
 
 private:
    struct              typed_data;
    std::map<UINT64, void *> mDataMaps;
    RTMetaDataContext  *mCtx;
};
 
extern "C" {
 
void *createRockitMetaData();
void  destroyRockitMetaData(void **meta);
 
}
 
#endif  // INCLUDE_RT_BASE_RT_METADATA_H_