OpenClonk
C4PropertyPath.h
Go to the documentation of this file.
1
/*
2
* OpenClonk, http://www.openclonk.org
3
*
4
* Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
5
* Copyright (c) 2013, The OpenClonk Team and contributors
6
*
7
* Distributed under the terms of the ISC license; see accompanying file
8
* "COPYING" for details.
9
*
10
* "Clonk" is a registered trademark of Matthes Bender, used with permission.
11
* See accompanying file "TRADEMARK" for details.
12
*
13
* To redistribute this file separately, substitute the full license texts
14
* for the above references.
15
*/
16
17
/* Generation of scripts to access values in objects and effects */
18
19
#ifndef INC_C4PropertyPath
20
#define INC_C4PropertyPath
21
22
#include "
C4Include.h
"
// needed for automoc
23
#include "
script/C4Value.h
"
24
25
// Path to a property, like e.g. Object(123).foo.bar[456].baz
26
// Used to allow proper synchronization of property setting
27
class
C4PropertyPath
28
{
29
// TODO: For now just storing the path. May want to keep the path info later to allow validation/updating of values
30
StdCopyStrBuf
get_path, argument, set_path;
31
StdCopyStrBuf
root;
32
33
public
:
34
enum
PathType
35
{
36
PPT_Root
= 0,
37
PPT_Property
= 1,
38
PPT_Index
= 2,
39
PPT_SetFunction
= 3,
40
PPT_GlobalSetFunction
= 4,
41
PPT_RootSetFunction
= 5,
42
}
get_path_type
,
set_path_type
;
43
44
public
:
45
C4PropertyPath
() {}
46
C4PropertyPath
(
C4PropList
*target);
47
C4PropertyPath
(
C4Effect
*fx,
C4Object
*target_obj);
48
C4PropertyPath
(
const
char
*path) : get_path(path), root(path),
get_path_type
(
PPT_Root
),
set_path_type
(
PPT_Root
) {}
49
C4PropertyPath
(
const
C4PropertyPath
&parent, int32_t elem_index);
50
C4PropertyPath
(
const
C4PropertyPath
&parent,
const
char
*child_property);
51
void
SetSetPath
(
const
C4PropertyPath
&parent,
const
char
*child_property,
PathType
path_type);
52
void
Clear
() { get_path.
Clear
(); set_path.
Clear
(); }
53
const
char
*
GetGetPath
()
const
{
return
get_path.
getData
(); }
54
const
char
*
GetSetPath
()
const
{
return
set_path ? set_path.
getData
() : get_path.
getData
(); }
55
const
char
*
GetRoot
()
const
{
return
root.
getData
(); }
// Parent-most path (usually the object)
56
bool
IsEmpty
()
const
{
return
get_path.
getLength
() <= 0; }
57
58
C4Value
ResolveValue
()
const
;
59
C4Value
ResolveRoot
()
const
;
60
void
SetProperty
(
const
char
*set_string)
const
;
61
void
SetProperty
(
const
C4Value
&to_val,
const
C4PropListStatic
*ignore_reference_parent =
nullptr
)
const
;
62
void
DoCall
(
const
char
*call_string)
const
;
// Perform a script call where %s is replaced by the current path
63
64
bool
operator ==
(
const
C4PropertyPath
&v)
const
{
return
get_path == v.get_path; }
65
};
66
67
// Collection of paths and their last values
68
class
C4PropertyCollection
69
{
70
public
:
71
struct
Entry
72
{
73
C4PropertyPath
path
;
74
C4Value
value
;
75
StdCopyStrBuf
name
;
76
77
Entry
(
const
C4PropertyPath
&
path
,
const
C4Value
&
value
,
const
char
*
name
)
78
:
path
(
path
),
value
(
value
),
name
(
name
) {}
79
};
80
81
private
:
82
std::vector<Entry> entries;
83
std::unordered_set<void *> checked_values;
84
85
bool
CollectPropList(
C4PropList
*p,
const
C4PropertyPath
&path,
C4PropertyName
prop,
const
C4Value
&val,
const
char
*base_name);
86
void
CollectPropLists(
C4ValueArray
*target,
const
C4PropertyPath
&target_path,
C4PropertyName
prop,
const
C4Value
&val,
const
char
*base_name);
87
void
CollectPropLists(
C4PropList
*target,
const
C4PropertyPath
&target_path,
C4PropertyName
prop,
const
C4Value
&val,
const
char
*base_name);
88
89
public
:
90
// Reset
91
void
Clear
();
92
93
// Iterates over all game objects and effects to collect proplists that have the given property set to the given value
94
void
CollectPropLists(
C4PropertyName
prop,
const
C4Value
&val);
95
96
const
std::vector<Entry> &
GetEntries
()
const
{
return
entries; }
97
};
98
99
#endif
// INC_C4PropertyPath
C4Include.h
C4PropertyName
C4PropertyName
Definition:
C4StringTable.h:304
C4Value.h
C4Effect
Definition:
C4Effect.h:70
C4Object
Definition:
C4Object.h:97
C4PropList
Definition:
C4PropList.h:68
C4PropListStatic
Definition:
C4PropList.h:265
C4PropertyCollection
Definition:
C4PropertyPath.h:69
C4PropertyCollection::Clear
void Clear()
Definition:
C4PropertyPath.cpp:155
C4PropertyCollection::GetEntries
const std::vector< Entry > & GetEntries() const
Definition:
C4PropertyPath.h:96
C4PropertyPath
Definition:
C4PropertyPath.h:28
C4PropertyPath::SetProperty
void SetProperty(const char *set_string) const
Definition:
C4PropertyPath.cpp:111
C4PropertyPath::Clear
void Clear()
Definition:
C4PropertyPath.h:52
C4PropertyPath::ResolveValue
C4Value ResolveValue() const
Definition:
C4PropertyPath.cpp:131
C4PropertyPath::operator==
bool operator==(const C4PropertyPath &v) const
Definition:
C4PropertyPath.h:64
C4PropertyPath::ResolveRoot
C4Value ResolveRoot() const
Definition:
C4PropertyPath.cpp:137
C4PropertyPath::set_path_type
enum C4PropertyPath::PathType set_path_type
C4PropertyPath::C4PropertyPath
C4PropertyPath(const char *path)
Definition:
C4PropertyPath.h:48
C4PropertyPath::GetSetPath
const char * GetSetPath() const
Definition:
C4PropertyPath.h:54
C4PropertyPath::C4PropertyPath
C4PropertyPath()
Definition:
C4PropertyPath.h:45
C4PropertyPath::get_path_type
enum C4PropertyPath::PathType get_path_type
C4PropertyPath::GetRoot
const char * GetRoot() const
Definition:
C4PropertyPath.h:55
C4PropertyPath::IsEmpty
bool IsEmpty() const
Definition:
C4PropertyPath.h:56
C4PropertyPath::GetGetPath
const char * GetGetPath() const
Definition:
C4PropertyPath.h:53
C4PropertyPath::SetSetPath
void SetSetPath(const C4PropertyPath &parent, const char *child_property, PathType path_type)
Definition:
C4PropertyPath.cpp:89
C4PropertyPath::PathType
PathType
Definition:
C4PropertyPath.h:35
C4PropertyPath::PPT_RootSetFunction
@ PPT_RootSetFunction
Definition:
C4PropertyPath.h:41
C4PropertyPath::PPT_Root
@ PPT_Root
Definition:
C4PropertyPath.h:36
C4PropertyPath::PPT_Index
@ PPT_Index
Definition:
C4PropertyPath.h:38
C4PropertyPath::PPT_Property
@ PPT_Property
Definition:
C4PropertyPath.h:37
C4PropertyPath::PPT_GlobalSetFunction
@ PPT_GlobalSetFunction
Definition:
C4PropertyPath.h:40
C4PropertyPath::PPT_SetFunction
@ PPT_SetFunction
Definition:
C4PropertyPath.h:39
C4PropertyPath::DoCall
void DoCall(const char *call_string) const
Definition:
C4PropertyPath.cpp:143
C4ValueArray
Definition:
C4ValueArray.h:24
C4Value
Definition:
C4Value.h:73
StdCopyStrBuf
Definition:
StdBuf.h:685
StdStrBuf::getData
const char * getData() const
Definition:
StdBuf.h:442
StdStrBuf::Clear
void Clear()
Definition:
StdBuf.h:466
StdStrBuf::getLength
size_t getLength() const
Definition:
StdBuf.h:445
C4PropertyCollection::Entry
Definition:
C4PropertyPath.h:72
C4PropertyCollection::Entry::path
C4PropertyPath path
Definition:
C4PropertyPath.h:73
C4PropertyCollection::Entry::value
C4Value value
Definition:
C4PropertyPath.h:74
C4PropertyCollection::Entry::name
StdCopyStrBuf name
Definition:
C4PropertyPath.h:75
C4PropertyCollection::Entry::Entry
Entry(const C4PropertyPath &path, const C4Value &value, const char *name)
Definition:
C4PropertyPath.h:77
openclonk
src
editor
C4PropertyPath.h
Generated on Fri May 16 2025 04:33:16 for OpenClonk by
1.9.1