OpenClonk
C4PropertyPath Class Reference

#include <C4PropertyPath.h>

Public Types

enum  PathType {
  PPT_Root = 0 , PPT_Property = 1 , PPT_Index = 2 , PPT_SetFunction = 3 ,
  PPT_GlobalSetFunction = 4 , PPT_RootSetFunction = 5
}
 

Public Member Functions

 C4PropertyPath ()
 
 C4PropertyPath (C4PropList *target)
 
 C4PropertyPath (C4Effect *fx, C4Object *target_obj)
 
 C4PropertyPath (const char *path)
 
 C4PropertyPath (const C4PropertyPath &parent, int32_t elem_index)
 
 C4PropertyPath (const C4PropertyPath &parent, const char *child_property)
 
void SetSetPath (const C4PropertyPath &parent, const char *child_property, PathType path_type)
 
void Clear ()
 
const char * GetGetPath () const
 
const char * GetSetPath () const
 
const char * GetRoot () const
 
bool IsEmpty () const
 
C4Value ResolveValue () const
 
C4Value ResolveRoot () const
 
void SetProperty (const char *set_string) const
 
void SetProperty (const C4Value &to_val, const C4PropListStatic *ignore_reference_parent=nullptr) const
 
void DoCall (const char *call_string) const
 
bool operator== (const C4PropertyPath &v) const
 

Public Attributes

enum C4PropertyPath::PathType get_path_type
 
enum C4PropertyPath::PathType set_path_type
 

Detailed Description

Definition at line 27 of file C4PropertyPath.h.

Member Enumeration Documentation

◆ PathType

Enumerator
PPT_Root 
PPT_Property 
PPT_Index 
PPT_SetFunction 
PPT_GlobalSetFunction 
PPT_RootSetFunction 

Definition at line 34 of file C4PropertyPath.h.

35  {
36  PPT_Root = 0,
37  PPT_Property = 1,
38  PPT_Index = 2,
39  PPT_SetFunction = 3,
enum C4PropertyPath::PathType set_path_type
enum C4PropertyPath::PathType get_path_type

Constructor & Destructor Documentation

◆ C4PropertyPath() [1/6]

C4PropertyPath::C4PropertyPath ( )
inline

Definition at line 45 of file C4PropertyPath.h.

45 {}

◆ C4PropertyPath() [2/6]

C4PropertyPath::C4PropertyPath ( C4PropList target)

Definition at line 31 of file C4PropertyPath.cpp.

32 {
33  // Build string to set target
34  if (target)
35  {
36  // Object target
37  C4Object *obj = target->GetObject();
38  C4PropListStatic *target_static;
39  if (obj)
40  {
41  get_path.Format("Object(%d)", (int)obj->Number);
42  root = get_path;
43  }
44  else if ((target_static = target->IsStatic()))
45  {
46  // Global static prop lists: Resolve name
47  get_path = target_static->GetDataString();
48  root = get_path;
49  }
50  else
51  {
52  // Otherwise leave empty. We do not want assignments into temporary values, etc.
53  }
54  }
55 }
virtual C4Object * GetObject()
Definition: C4PropList.cpp:636
virtual class C4PropListStatic * IsStatic()
Definition: C4PropList.h:89
StdStrBuf GetDataString() const
Definition: C4PropList.cpp:229
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:174

References StdStrBuf::Format(), C4PropListStatic::GetDataString(), C4PropList::GetObject(), C4PropList::IsStatic(), and C4PropListNumbered::Number.

Here is the call graph for this function:

◆ C4PropertyPath() [3/6]

C4PropertyPath::C4PropertyPath ( C4Effect fx,
C4Object target_obj 
)

Definition at line 57 of file C4PropertyPath.cpp.

58 {
59  // Effect property path: Represent as GetEffect("name", Object(%d), index) for object effects and GetEffect("name", nil, index) for global effects
60  if (!fx) return;
61  const char *name = fx->GetName();
62  int32_t index = 0;
63  for (C4Effect *ofx = target_obj ? target_obj->pEffects : ::ScriptEngine.pGlobalEffects; ofx; ofx = ofx->pNext)
64  if (ofx == fx) break; else if (!strcmp(ofx->GetName(), name)) ++index;
65  if (target_obj)
66  {
67  get_path.Format(R"(GetEffect("%s", Object(%d), %d))", name, (int)target_obj->Number, (int)index);
68  root.Format("Object(%d)", (int)target_obj->Number);
69  }
70  else
71  {
72  get_path.Format(R"(GetEffect("%s", nil, %d))", name, (int)index);
73  root = ::Strings.P[P_Global].GetData();
74  }
75 }
C4AulScriptEngine ScriptEngine
Definition: C4Globals.cpp:43
C4StringTable Strings
Definition: C4Globals.cpp:42
@ P_Global
C4Effect * pGlobalEffects
Definition: C4Aul.h:144
C4Effect * pNext
Definition: C4Effect.h:75
C4Effect * pEffects
Definition: C4Object.h:155
virtual const char * GetName() const
Definition: C4PropList.cpp:618
StdStrBuf GetData() const
Definition: C4StringTable.h:50
C4String P[P_LAST]

References StdStrBuf::Format(), C4String::GetData(), C4PropList::GetName(), C4PropListNumbered::Number, C4StringTable::P, P_Global, C4Object::pEffects, C4AulScriptEngine::pGlobalEffects, C4Effect::pNext, ScriptEngine, and Strings.

Here is the call graph for this function:

◆ C4PropertyPath() [4/6]

C4PropertyPath::C4PropertyPath ( const char *  path)
inline

Definition at line 48 of file C4PropertyPath.h.

48 : get_path(path), root(path), get_path_type(PPT_Root), set_path_type(PPT_Root) {}

◆ C4PropertyPath() [5/6]

C4PropertyPath::C4PropertyPath ( const C4PropertyPath parent,
int32_t  elem_index 
)

Definition at line 77 of file C4PropertyPath.cpp.

77  : root(parent.root)
78 {
79  get_path.Format("%s[%d]", parent.GetGetPath(), (int)elem_index);
81 }
const char * GetGetPath() const

References StdStrBuf::Format(), get_path_type, GetGetPath(), PPT_Index, and set_path_type.

Here is the call graph for this function:

◆ C4PropertyPath() [6/6]

C4PropertyPath::C4PropertyPath ( const C4PropertyPath parent,
const char *  child_property 
)

Definition at line 83 of file C4PropertyPath.cpp.

85 {
86  get_path.Format("%s.%s", parent.GetGetPath(), child_property);
87 }

References StdStrBuf::Format(), and GetGetPath().

Here is the call graph for this function:

Member Function Documentation

◆ Clear()

void C4PropertyPath::Clear ( )
inline

Definition at line 52 of file C4PropertyPath.h.

52 { get_path.Clear(); set_path.Clear(); }
void Clear()
Definition: StdBuf.h:466

References StdStrBuf::Clear().

Here is the call graph for this function:

◆ DoCall()

void C4PropertyPath::DoCall ( const char *  call_string) const

Definition at line 143 of file C4PropertyPath.cpp.

144 {
145  // Compose script call
146  StdStrBuf script;
147  script.Format(call_string, get_path.getData());
148  // Execute synced scripted
150 }
C4Console Console
Definition: C4Globals.cpp:45
@ CID_Script
Definition: C4PacketBase.h:154
C4EditCursor EditCursor
Definition: C4Console.h:90
void EMControl(enum C4PacketType eCtrlType, class C4ControlPacket *pCtrl)
const char * getData() const
Definition: StdBuf.h:442

References CID_Script, Console, C4Console::EditCursor, C4EditCursor::EMControl(), StdStrBuf::Format(), and StdStrBuf::getData().

Here is the call graph for this function:

◆ GetGetPath()

const char* C4PropertyPath::GetGetPath ( ) const
inline

Definition at line 53 of file C4PropertyPath.h.

53 { return get_path.getData(); }

References StdStrBuf::getData().

Referenced by C4PropertyPath(), and SetSetPath().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetRoot()

const char* C4PropertyPath::GetRoot ( ) const
inline

Definition at line 55 of file C4PropertyPath.h.

55 { return root.getData(); } // Parent-most path (usually the object)

References StdStrBuf::getData().

Referenced by SetSetPath().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetSetPath()

const char* C4PropertyPath::GetSetPath ( ) const
inline

Definition at line 54 of file C4PropertyPath.h.

54 { return set_path ? set_path.getData() : get_path.getData(); }

References StdStrBuf::getData().

Referenced by SetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsEmpty()

bool C4PropertyPath::IsEmpty ( ) const
inline

Definition at line 56 of file C4PropertyPath.h.

56 { return get_path.getLength() <= 0; }
size_t getLength() const
Definition: StdBuf.h:445

References StdStrBuf::getLength().

Here is the call graph for this function:

◆ operator==()

bool C4PropertyPath::operator== ( const C4PropertyPath v) const
inline

Definition at line 64 of file C4PropertyPath.h.

64 { return get_path == v.get_path; }

◆ ResolveRoot()

C4Value C4PropertyPath::ResolveRoot ( ) const

Definition at line 137 of file C4PropertyPath.cpp.

138 {
139  if (!root.getLength()) return C4VNull;
140  return AulExec.DirectExec(::ScriptEngine.GetPropList(), root.getData(), "resolve property root", false, nullptr);
141 }
C4AulExec AulExec
Definition: C4AulExec.cpp:29
const C4Value C4VNull
Definition: C4Value.cpp:30
C4Value DirectExec(C4PropList *p, const char *szScript, const char *szContext, bool fPassErrors=false, C4AulScriptContext *context=nullptr, bool parse_function=false)
Definition: C4AulExec.cpp:1012
C4PropListStatic * GetPropList()
Definition: C4Aul.h:151

References AulExec, C4VNull, C4AulExec::DirectExec(), StdStrBuf::getData(), StdStrBuf::getLength(), C4AulScriptEngine::GetPropList(), and ScriptEngine.

Here is the call graph for this function:

◆ ResolveValue()

C4Value C4PropertyPath::ResolveValue ( ) const

Definition at line 131 of file C4PropertyPath.cpp.

132 {
133  if (!get_path.getLength()) return C4VNull;
134  return AulExec.DirectExec(::ScriptEngine.GetPropList(), get_path.getData(), "resolve property", false, nullptr);
135 }

References AulExec, C4VNull, C4AulExec::DirectExec(), StdStrBuf::getData(), StdStrBuf::getLength(), C4AulScriptEngine::GetPropList(), and ScriptEngine.

Here is the call graph for this function:

◆ SetProperty() [1/2]

void C4PropertyPath::SetProperty ( const C4Value to_val,
const C4PropListStatic ignore_reference_parent = nullptr 
) const

Definition at line 126 of file C4PropertyPath.cpp.

127 {
128  SetProperty(to_val.GetDataString(9999999, ignore_reference_parent).getData());
129 }
void SetProperty(const char *set_string) const
StdStrBuf GetDataString(int depth=10, const class C4PropListStatic *ignore_reference_parent=nullptr) const
Definition: C4Value.cpp:131

References StdStrBuf::getData(), C4Value::GetDataString(), and SetProperty().

Here is the call graph for this function:

◆ SetProperty() [2/2]

void C4PropertyPath::SetProperty ( const char *  set_string) const

Definition at line 111 of file C4PropertyPath.cpp.

112 {
113  // Compose script to update property
114  const char *set_path_c = GetSetPath();
115  StdStrBuf script;
117  script.Format("%s(%s)", set_path_c, set_string);
119  script.Format("%s(%s,%s)", argument.getData(), set_path_c, set_string);
120  else
121  script.Format("%s=%s", set_path_c, set_string);
122  // Execute synced scripted
124 }
const char * GetSetPath() const

References CID_Script, Console, C4Console::EditCursor, C4EditCursor::EMControl(), StdStrBuf::Format(), StdStrBuf::getData(), GetSetPath(), PPT_GlobalSetFunction, PPT_RootSetFunction, PPT_SetFunction, and set_path_type.

Referenced by SetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetSetPath()

void C4PropertyPath::SetSetPath ( const C4PropertyPath parent,
const char *  child_property,
C4PropertyPath::PathType  path_type 
)

Definition at line 89 of file C4PropertyPath.cpp.

90 {
91  set_path_type = path_type;
92  if (path_type == PPT_Property)
93  set_path.Format("%s.%s", parent.GetGetPath(), child_property);
94  else if (path_type == PPT_SetFunction)
95  set_path.Format("%s->%s", parent.GetGetPath(), child_property);
96  else if (path_type == PPT_GlobalSetFunction)
97  {
98  set_path.Copy(parent.GetGetPath());
99  argument.Copy(child_property);
100  }
101  else if (path_type == PPT_RootSetFunction)
102  {
103  set_path.Format("%s->%s", parent.GetRoot(), child_property);
104  }
105  else
106  {
107  assert(false);
108  }
109 }
const char * GetRoot() const
void Copy()
Definition: StdBuf.h:467

References StdStrBuf::Copy(), StdStrBuf::Format(), GetGetPath(), GetRoot(), PPT_GlobalSetFunction, PPT_Property, PPT_RootSetFunction, PPT_SetFunction, and set_path_type.

Here is the call graph for this function:

Member Data Documentation

◆ get_path_type

enum C4PropertyPath::PathType C4PropertyPath::get_path_type

Referenced by C4PropertyPath().

◆ set_path_type

enum C4PropertyPath::PathType C4PropertyPath::set_path_type

The documentation for this class was generated from the following files: