Skip to content

Commit

Permalink
objectIsRawLiterial
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouhang95 committed Nov 5, 2024
1 parent f367bf6 commit 566b113
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
16 changes: 16 additions & 0 deletions zeno/include/zeno/funcs/LiterialConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ inline bool objectIsLiterial(std::shared_ptr<IObject> const &ptr) {
}
}

template <class T>
inline bool objectIsRawLiterial(std::shared_ptr<IObject> const &ptr) {
if constexpr (std::is_base_of_v<IObject, T>) {
return dynamic_cast<T *>(ptr.get());
} else if constexpr (std::is_same_v<std::string, T>) {
return dynamic_cast<StringObject *>(ptr.get());
} else if constexpr (std::is_same_v<NumericValue, T>) {
return dynamic_cast<NumericObject *>(ptr.get());
} else {
auto p = dynamic_cast<NumericObject *>(ptr.get());
return p && std::visit([&] (auto const &val) -> bool {
return std::is_same_v<T, std::decay_t<decltype(val)>>;
}, p->value);
}
}

template <class T>
inline auto objectToLiterial(std::shared_ptr<IObject> const &ptr, std::string const &msg = "objectToLiterial") {
if constexpr (std::is_base_of_v<IObject, T>) {
Expand Down
18 changes: 9 additions & 9 deletions zeno/src/nodes/JsonProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,37 +64,37 @@ ZENDEFNODE(WriteJson, {
});
static Json iobject_to_json(std::shared_ptr<IObject> iObject) {
Json json;
if (objectIsLiterial<int>(iObject)) {
if (objectIsRawLiterial<int>(iObject)) {
json = objectToLiterial<int>(iObject);
}
else if (objectIsLiterial<vec2i>(iObject)) {
else if (objectIsRawLiterial<vec2i>(iObject)) {
auto value = objectToLiterial<vec2i>(iObject);
json = { value[0], value[1]};
}
else if (objectIsLiterial<vec3i>(iObject)) {
else if (objectIsRawLiterial<vec3i>(iObject)) {
auto value = objectToLiterial<vec3i>(iObject);
json = { value[0], value[1], value[2]};
}
else if (objectIsLiterial<vec4i>(iObject)) {
else if (objectIsRawLiterial<vec4i>(iObject)) {
auto value = objectToLiterial<vec4i>(iObject);
json = { value[0], value[1], value[2], value[3]};
}
else if (objectIsLiterial<float>(iObject)) {
else if (objectIsRawLiterial<float>(iObject)) {
json = objectToLiterial<float>(iObject);
}
else if (objectIsLiterial<vec2f>(iObject)) {
else if (objectIsRawLiterial<vec2f>(iObject)) {
auto value = objectToLiterial<vec2f>(iObject);
json = { value[0], value[1]};
}
else if (objectIsLiterial<vec3f>(iObject)) {
else if (objectIsRawLiterial<vec3f>(iObject)) {
auto value = objectToLiterial<vec3f>(iObject);
json = { value[0], value[1], value[2]};
}
else if (objectIsLiterial<vec4f>(iObject)) {
else if (objectIsRawLiterial<vec4f>(iObject)) {
auto value = objectToLiterial<vec4f>(iObject);
json = { value[0], value[1], value[2], value[3]};
}
else if (objectIsLiterial<std::string>(iObject)) {
else if (objectIsRawLiterial<std::string>(iObject)) {
json = objectToLiterial<std::string>(iObject);
}
else if (auto list = std::dynamic_pointer_cast<ListObject>(iObject)) {
Expand Down

0 comments on commit 566b113

Please sign in to comment.