-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsvalue.h
More file actions
107 lines (84 loc) · 2.92 KB
/
Copy pathsvalue.h
File metadata and controls
107 lines (84 loc) · 2.92 KB
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
107
#pragma once
#include "types.h"
#ifdef __cplusplus
extern "C" {
#endif
void free_svalue (svalue_t * v, const char* caller);
void free_some_svalues(svalue_t *, int);
void assign_svalue(svalue_t *, svalue_t *);
void assign_svalue_no_free(svalue_t *, const svalue_t *);
void copy_some_svalues(svalue_t *, svalue_t *, int);
static inline int string_length_differs(const svalue_t *x, const svalue_t *y) {
return SVALUE_STRLEN(x) != SVALUE_STRLEN(y);
}
int svalue_string_lexcmp(const svalue_t *lhs, const svalue_t *rhs);
#define SV2STR_NOINDENT 0x0001 /* don't generate indention */
#define SV2STR_DONEINDENT 0x0002 /* indent of this line is already done */
#define SV2STR_NONEWLINE 0x0004 /* don't generate newline */
void svalue_to_string(svalue_t *, outbuffer_t *, int, char, int);
char *string_print_formatted(const char *, int, svalue_t *);
#ifdef __cplusplus
} // extern "C"
/*
* C++ RAII wrappers for svalue management.
* These provide safe ownership semantics without modifying the C API.
*/
namespace lpc {
class svalue_view;
class const_svalue_view;
class svalue_ref;
/**
* @brief Non-owning reference to a reference-counted svalue.
*
* For svalues with reference-counted types (T_STRING, T_OBJECT, T_ARRAY, etc.),
* this reference automatically increments the refcount on copy/move and decrements
* on destruction.
*
* Use this for passing reference-counted svalues safely without full ownership.
* Both copy and move semantics are supported.
*
* Example:
* svalue_t sv = ... // reference-counted svalue
* svalue_ref ref(&sv);
* // refcount is incremented
* // refcount is decremented when ref is destroyed
*/
class svalue_ref {
public:
/**
* Create a non-owning reference to an svalue.
* If the svalue is reference-counted, increments the refcount.
*/
explicit svalue_ref(svalue_t *sv) noexcept;
// Move semantics
svalue_ref(svalue_ref &&other) noexcept;
svalue_ref &operator=(svalue_ref &&other) noexcept;
// Copy semantics (both copies hold references)
svalue_ref(const svalue_ref &other) noexcept;
svalue_ref &operator=(const svalue_ref &other) noexcept;
// Destructor
~svalue_ref() noexcept;
// Accessors
[[nodiscard]] svalue_view view() noexcept;
[[nodiscard]] const_svalue_view view() const noexcept;
svalue_t *get() noexcept;
const svalue_t *get() const noexcept;
svalue_t *operator->() noexcept;
const svalue_t *operator->() const noexcept;
svalue_t &operator*() noexcept;
const svalue_t &operator*() const noexcept;
explicit operator bool() const noexcept;
/**
* Release ownership of the reference.
* The refcount is NOT decremented; caller becomes responsible.
*/
svalue_t *release() noexcept;
/**
* Decrement refcount (if applicable) and clear this reference.
*/
void reset(svalue_t *new_sv = nullptr) noexcept;
private:
svalue_t *sv_;
};
} // namespace lpc
#endif // __cplusplus