Skip to content
LeviMC
English
AutoLightDark
LeviLamina
Loading...
Searching...
No Matches
PathUtility.h
1#pragma once
2
3#include "mc/_HeaderOutputPredefine.h"
4#include "mc/deps/cereal/schema/dynamic/DynamicValue.h"
5#include "mc/scripting/data_sync/PathQueryError.h"
6
7// auto generated forward declare list
8// clang-format off
9namespace Bedrock::DDUI::PathUtility { struct PathQueryError; }
10namespace cereal { class DynamicValue; }
11// clang-format on
12
13namespace Bedrock::DDUI::PathUtility {
14// functions
15// NOLINTBEGIN
16template <class T>
17 requires std::is_same_v<T, cereal::DynamicValue>
18MCAPI nonstd::expected<gsl::not_null<T*>, ::Bedrock::DDUI::PathUtility::PathQueryError> queryDataStoreObjectT(
19 cereal::DynamicValue& originalObject,
20 std::string const& path,
21 std::string const& dataStoreName,
22 std::string const& propertyName
23);
24
25inline nonstd::expected<void, ::Bedrock::DDUI::PathUtility::PathQueryError> setPathOnDataStoreObject(
26 cereal::DynamicValue& originalObject,
27 std::string const& path,
28 cereal::DynamicValue const& newData,
29 std::string const& dataStoreName,
30 std::string const& propertyName
31) {
32 auto result = queryDataStoreObjectT<cereal::DynamicValue>(originalObject, path, dataStoreName, propertyName);
33
34 if (!result) {
35 return nonstd::make_unexpected(result.error());
36 }
37
38 result.value()->mValue = newData.mValue;
39
40 return {};
41}
42
43MCAPI ::std::optional<::std::variant<double, bool, ::std::string>>
44convertToPrimitive(::cereal::DynamicValue const& obj);
45
46MCNAPI ::nonstd::
47 expected<::std::vector<::std::variant<::std::string, uint>>, ::Bedrock::DDUI::PathUtility::PathQueryError>
48 parsePath(::std::string const& wholePath);
49
50MCNAPI ::std::string rebuildPath(
51 ::std::string const& datastore,
52 ::std::string const& property,
53 ::std::vector<::std::variant<::std::string, uint>> const& tokens,
54 ::std::optional<uint> maxTokenIndex
55);
56
57MCAPI ::std::optional<::cereal::DynamicValue> stringToDynamicValue(::std::string const& s);
58// NOLINTEND
59
60} // namespace Bedrock::DDUI::PathUtility
Definition DynamicValue.h:14
Definition PathQueryError.h:7