15static bool xml_read_boolean(
const char *value)
20static const char *xml_write_boolean(
bool value)
22 return (value) ?
"true" :
"false";
25template<
int VECTOR_SIZE,
typename T>
31 if (tokens.size() % VECTOR_SIZE != 0) {
35 value.resize(tokens.size() / VECTOR_SIZE);
36 for (
size_t i = 0;
i < value.size();
i++) {
37 float *value_float = (
float *)&value[
i];
39 for (
size_t j = 0; j < VECTOR_SIZE; j++) {
40 value_float[j] = (float)atof(tokens[
i * VECTOR_SIZE + j].c_str());
45void xml_read_node(XMLReader &reader,
Node *node,
const xml_node xml_node)
47 const xml_attribute name_attr = xml_node.attribute(
"name");
49 node->
name = ustring(name_attr.value());
60 const xml_attribute attr = xml_node.attribute(socket.
name.c_str());
66 switch (socket.
type) {
68 node->
set(socket, xml_read_boolean(attr.value()));
76 value.
resize(tokens.size());
77 for (
size_t i = 0;
i < value.
size();
i++) {
78 value[
i] = xml_read_boolean(tokens[
i].c_str());
80 node->
set(socket, value);
84 node->
set(socket, (
float)atof(attr.value()));
90 node->
set(socket, value);
94 node->
set(socket, atoi(attr.value()));
98 node->
set(socket, (
uint)atoi(attr.value()));
102 node->
set(socket, (
uint64_t)strtoull(attr.value(),
nullptr, 10));
110 value.
resize(tokens.size());
111 for (
size_t i = 0;
i < value.
size();
i++) {
112 value[
i] = atoi(attr.value());
114 node->
set(socket, value);
123 if (value.
size() == 1) {
124 node->
set(socket, value[0]);
134 node->
set(socket, value);
140 if (value.
size() == 1) {
141 node->
set(socket, value[0]);
148 node->
set(socket, value);
152 node->
set(socket, attr.value());
156 const ustring value(attr.value());
158 node->
set(socket, value);
162 "Unknown value \"%s\" for attribute \"%s\".\n",
164 socket.
name.c_str());
173 value.
resize(tokens.size());
174 for (
size_t i = 0;
i < value.
size();
i++) {
175 value[
i] = ustring(tokens[
i]);
177 node->
set(socket, value);
183 if (value.
size() == 1) {
184 node->
set(socket, value[0]);
191 node->
set(socket, value);
195 const ustring value(attr.value());
196 const map<ustring, Node *>::iterator it = reader.node_map.find(value);
197 if (it != reader.node_map.end()) {
198 Node *value_node = it->second;
200 node->
set(socket, it->second);
210 value.
resize(tokens.size());
211 for (
size_t i = 0;
i < value.
size();
i++) {
212 const map<ustring, Node *>::iterator it = reader.node_map.find(ustring(tokens[
i]));
213 if (it != reader.node_map.end()) {
214 Node *value_node = it->second;
215 value[
i] = (value_node->
is_a(socket.
node_type)) ? value_node :
nullptr;
221 node->
set(socket, value);
231 if (!node->
name.empty()) {
232 reader.node_map[node->
name] = node;
236xml_node xml_write_node(
Node *node, xml_node xml_root)
238 xml_node xml_node = xml_root.append_child(node->
type->
name.c_str());
240 xml_node.append_attribute(
"name") = node->
name.c_str();
253 xml_attribute attr = xml_node.append_attribute(socket.
name.c_str());
255 switch (socket.
type) {
257 attr = xml_write_boolean(node->
get_bool(socket));
261 std::stringstream ss;
263 for (
size_t i = 0;
i < value.
size();
i++) {
264 ss << xml_write_boolean(value[
i]);
265 if (
i != value.
size() - 1) {
269 attr = ss.str().c_str();
277 std::stringstream ss;
279 for (
size_t i = 0;
i < value.
size();
i++) {
281 if (
i != value.size() - 1) {
285 attr = ss.str().c_str();
301 std::stringstream ss;
303 for (
size_t i = 0;
i < value.
size();
i++) {
305 if (
i != value.size() - 1) {
309 attr = ss.str().c_str();
318 string_printf(
"%g %g %g", (
double)value.
x, (
double)value.
y, (
double)value.
z).c_str();
325 std::stringstream ss;
327 for (
size_t i = 0;
i < value.
size();
i++) {
329 "%g %g %g", (
double)value[
i].
x, (
double)value[
i].
y, (
double)value[
i].
z);
330 if (
i != value.
size() - 1) {
334 attr = ss.str().c_str();
339 attr =
string_printf(
"%g %g", (
double)value.
x, (
double)value.
y).c_str();
343 std::stringstream ss;
345 for (
size_t i = 0;
i < value.
size();
i++) {
347 if (
i != value.
size() - 1) {
351 attr = ss.str().c_str();
360 std::stringstream ss;
362 for (
size_t i = 0;
i < value.
size();
i++) {
364 if (
i != value.size() - 1) {
368 attr = ss.str().c_str();
373 std::stringstream ss;
374 for (
int i = 0;
i < 3;
i++) {
382 attr = ss.str().c_str();
386 std::stringstream ss;
388 for (
size_t j = 0; j < value.
size(); j++) {
391 for (
int i = 0;
i < 3;
i++) {
399 if (j != value.
size() - 1) {
403 attr = ss.str().c_str();
409 attr = value->
name.c_str();
414 std::stringstream ss;
416 for (
size_t i = 0;
i < value.
size();
i++) {
418 ss << value[
i]->name.c_str();
420 if (
i != value.
size() - 1) {
424 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
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
vector< SocketType, std::allocator< SocketType > > inputs
bool has_default_value(const SocketType &input) const
const array< float3 > & get_float3_array(const SocketType &input) const
const array< float > & get_float_array(const SocketType &input) const
const array< int > & get_int_array(const SocketType &input) const
float get_float(const SocketType &input) const
Transform get_transform(const SocketType &input) const
void set(const SocketType &input, bool value)
uint64_t get_uint64(const SocketType &input) const
float3 get_float3(const SocketType &input) const
const array< bool > & get_bool_array(const SocketType &input) const
const array< Node * > & get_node_array(const SocketType &input) const
bool get_bool(const SocketType &input) const
float2 get_float2(const SocketType &input) const
const array< ustring > & get_string_array(const SocketType &input) const
const array< float2 > & get_float2_array(const SocketType &input) const
ustring get_string(const SocketType &input) const
bool is_a(const NodeType *type)
Node * get_node(const SocketType &input) const
uint get_uint(const SocketType &input) const
int get_int(const SocketType &input) const
const array< Transform > & get_transform_array(const SocketType &input) const
const NodeType * node_type
const NodeEnum * enum_values