16static bool xml_read_boolean(
const char *value)
21static const char *xml_write_boolean(
bool value)
23 return (value) ?
"true" :
"false";
26template<
int VECTOR_SIZE,
typename T>
32 if (tokens.size() % VECTOR_SIZE != 0) {
36 value.resize(tokens.size() / VECTOR_SIZE);
37 for (
size_t i = 0; i < value.size(); i++) {
38 float *value_float = (
float *)&value[i];
40 for (
size_t j = 0; j < VECTOR_SIZE; j++) {
41 value_float[j] = (
float)atof(tokens[i * VECTOR_SIZE + j].c_str());
46void xml_read_node(XMLReader &reader,
Node *
node,
const xml_node xml_node)
48 const xml_attribute name_attr = xml_node.attribute(
"name");
50 node->name = ustring(name_attr.value());
61 const xml_attribute attr = xml_node.attribute(socket.
name.c_str());
67 switch (socket.
type) {
69 node->set(socket, xml_read_boolean(attr.value()));
77 value.
resize(tokens.size());
78 for (
size_t i = 0; i < value.
size(); i++) {
79 value[i] = xml_read_boolean(tokens[i].c_str());
81 node->set(socket, value);
85 node->set(socket, (
float)atof(attr.value()));
91 node->set(socket, value);
95 node->set(socket, atoi(attr.value()));
99 node->set(socket, (uint)atoi(attr.value()));
103 node->set(socket, (
uint64_t)strtoull(attr.value(),
nullptr, 10));
111 value.
resize(tokens.size());
112 for (
size_t i = 0; i < value.
size(); i++) {
113 value[i] = atoi(attr.value());
115 node->set(socket, value);
124 if (value.
size() == 1) {
125 node->set(socket, value[0]);
135 node->set(socket, value);
141 if (value.
size() == 1) {
142 node->set(socket, value[0]);
149 node->set(socket, value);
153 node->set(socket, attr.value());
157 const ustring value(attr.value());
159 node->set(socket, value);
162 LOG_ERROR <<
"Unknown value \"" << value.c_str() <<
"\" for attribute \""
163 << socket.
name.c_str() <<
"\"";
172 value.
resize(tokens.size());
173 for (
size_t i = 0; i < value.
size(); i++) {
174 value[i] = ustring(tokens[i]);
176 node->set(socket, value);
182 if (value.
size() == 1) {
183 node->set(socket, value[0]);
190 node->set(socket, value);
194 const ustring value(attr.value());
195 const map<ustring, Node *>::iterator it = reader.node_map.find(value);
196 if (it != reader.node_map.end()) {
197 Node *value_node = it->second;
199 node->set(socket, it->second);
209 value.
resize(tokens.size());
210 for (
size_t i = 0; i < value.
size(); i++) {
211 const map<ustring, Node *>::iterator it = reader.node_map.find(ustring(tokens[i]));
212 if (it != reader.node_map.end()) {
213 Node *value_node = it->second;
214 value[i] = (value_node->
is_a(socket.
node_type)) ? value_node :
nullptr;
220 node->set(socket, value);
230 if (!
node->name.empty()) {
235xml_node xml_write_node(
Node *
node, xml_node xml_root)
237 xml_node xml_node = xml_root.append_child(
node->type->name.c_str());
239 xml_node.append_attribute(
"name") =
node->name.c_str();
248 if (
node->has_default_value(socket)) {
252 xml_attribute attr = xml_node.append_attribute(socket.
name.c_str());
254 switch (socket.
type) {
256 attr = xml_write_boolean(
node->get_bool(socket));
260 std::stringstream ss;
262 for (
size_t i = 0; i < value.
size(); i++) {
263 ss << xml_write_boolean(value[i]);
264 if (i != value.
size() - 1) {
268 attr = ss.str().c_str();
272 attr = (double)
node->get_float(socket);
276 std::stringstream ss;
278 for (
size_t i = 0; i < value.
size(); i++) {
280 if (i != value.size() - 1) {
284 attr = ss.str().c_str();
288 attr =
node->get_int(socket);
292 attr =
node->get_uint(socket);
296 attr =
node->get_uint64(socket);
300 std::stringstream ss;
302 for (
size_t i = 0; i < value.
size(); i++) {
304 if (i != value.size() - 1) {
308 attr = ss.str().c_str();
315 const float3 value =
node->get_float3(socket);
317 string_printf(
"%g %g %g", (
double)value.
x, (
double)value.
y, (
double)value.
z).c_str();
324 std::stringstream ss;
326 for (
size_t i = 0; i < value.
size(); i++) {
328 "%g %g %g", (
double)value[i].
x, (
double)value[i].
y, (
double)value[i].
z);
329 if (i != value.
size() - 1) {
333 attr = ss.str().c_str();
337 const float2 value =
node->get_float2(socket);
338 attr =
string_printf(
"%g %g", (
double)value.
x, (
double)value.
y).c_str();
342 std::stringstream ss;
344 for (
size_t i = 0; i < value.
size(); i++) {
346 if (i != value.
size() - 1) {
350 attr = ss.str().c_str();
355 attr =
node->get_string(socket).c_str();
359 std::stringstream ss;
361 for (
size_t i = 0; i < value.
size(); i++) {
363 if (i != value.size() - 1) {
367 attr = ss.str().c_str();
372 std::stringstream ss;
373 for (
int i = 0; i < 3; i++) {
381 attr = ss.str().c_str();
385 std::stringstream ss;
387 for (
size_t j = 0; j < value.
size(); j++) {
390 for (
int i = 0; i < 3; i++) {
398 if (j != value.
size() - 1) {
402 attr = ss.str().c_str();
406 Node *value =
node->get_node(socket);
408 attr = value->
name.c_str();
413 std::stringstream ss;
415 for (
size_t i = 0; i < value.
size(); i++) {
417 ss << value[i]->name.c_str();
419 if (i != value.
size() - 1) {
423 attr = ss.str().c_str();
unsigned long long int uint64_t
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
T * resize(const size_t newsize)
static bool xml_read_float_array(vector< float > &value, const xml_node node, const char *name)
#define CCL_NAMESPACE_END
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
bool string_iequals(const string &a, const string &b)
CCL_NAMESPACE_BEGIN string string_printf(const char *format,...)
void string_split(vector< string > &tokens, const string &str, const string &separators, bool skip_empty_tokens)
bool exists(ustring x) const
bool is_a(const NodeType *type)
const NodeType * node_type
const NodeEnum * enum_values