WriteIterator xml_writer::create_iterator(const str& name, schema* type) { if (name.empty()) return WriteIterator( new xml_write_iterator(node_, type, types_) ); TiXmlElement* node = new TiXmlElement(name.c_str()); node_->LinkEndChild( node ); return WriteIterator( new xml_write_iterator(node, type, types_) ); }
ReadIterator xml_reader::create_iterator(const str& name, schema* type) { if (name.empty()) return ReadIterator( new xml_read_iterator(node_, type, types_, options_) ); TiXmlElement* node = node_->FirstChildElement(name.c_str()); if (!node) return ReadIterator(); return ReadIterator( new xml_read_iterator(node, type, types_, options_) ); }
void Parser::eq_(str& s, EvalAtomType atomType) { if (mInternalQ == NULL) return; if (s.empty()) return; EvalAtom* atom = new EvalAtom(s, atomType); mInternalQ->push_back(atom); }
//------------------------------------------------------------------------------ static int install_autorun(const char* clink_path, int wow64) { HKEY cmd_proc_key; const char* value; char* key_value; int i; // Remove any previous autorun entries so we never have more than one. We // could just check for an exisiting entry, but by always uninstalling and // reinstalling, we ensure clink's last in the chain, which allows it to // play nicely with other projects that hook cmd.exe and install autoruns. uninstall_autorun(clink_path, wow64); cmd_proc_key = open_cmd_proc_key(g_all_users, wow64, 1); if (cmd_proc_key == nullptr) { printf("ERROR: Failed to open registry key (%d)\n", GetLastError()); return 0; } key_value = nullptr; get_value(cmd_proc_key, "AutoRun", &key_value); i = key_value ? (int)strlen(key_value) : 0; i += 2048; str_base new_value((char*)malloc(i), i); new_value.clear(); // Build the new autorun entry by appending clink's entry to the current one. if (key_value != nullptr && *key_value != '\0') new_value << key_value << "&"; new_value << "\"" << clink_path << "\\clink.bat\" inject --autorun"; if (!g_clink_args.empty()) new_value << " " << g_clink_args; // Set it value = get_cmd_start(new_value.c_str()); i = 1; if (!set_value(cmd_proc_key, "AutoRun", value)) i = 0; // Tidy up. close_key(cmd_proc_key); free(new_value.data()); free(key_value); return i; }
void handle_expression(const str& text, param_list* args) { str expr_ = text; if (text.empty() && args) { variant vv = args->get("value"); if (vv.empty()) vv = args->get("v"); if (!vv.empty()) expr_ = variant_cast<str>(vv, ""); } expressions_.push_back(expr_); items_.push_back(ItemRenderer(new out_expr_renderer(expressions_.size() - 1))); }
str js_lang::render_assignment(const str& path, const str& prop, const str& value) { if (path.empty()) return prop + " = " + value; return path + "." + prop + " = " + value; }
bool SKAudio::initialize(SoundIoBackend backend, str& device_id) { if(!(sio = soundio_create())) { logit("E: SoundIo out of memory: "); return false; } if(auto err = (backend == SoundIoBackendNone) ? soundio_connect(sio) : soundio_connect_backend(sio, backend)) { logit("E: SoundIo can't connect to backend: " << soundio_strerror(err)); return false; } soundio_flush_events(sio); auto selected_device_index = -1; if(!device_id.empty()) { auto device_count = soundio_output_device_count(sio); for(decltype(device_count) i = 0; i < device_count; ++i) { SoundIoDevice* device = soundio_get_output_device(sio, i); if(!std::strcmp(device->id, device_id.c_str())) { selected_device_index = i; break; } } } if(selected_device_index == -1) selected_device_index = soundio_default_output_device_index(sio); if(selected_device_index == -1) { logit("E: SoundIo can't find device: "); return false; } if(!(dev = soundio_get_output_device(sio, selected_device_index))) { logit("E: SoundIo out of memory: "); return false; } device_id = dev->id; if(dev->probe_error) { logit("E: Cannot probe device: " << soundio_strerror(dev->probe_error)); return false; } if(!(out = soundio_outstream_create(dev))) { logit("E: SoundIo out of memory: "); return false; } return true; }
void base_write_archive::write( Writer w, const str& name, variant& v) { schema* type = true_type(v); void* this_ = v.get_pointer(); //3 use cases: //- we know the type as attibuted (ints, strings, things like that) // note the implementor is free to define its custom types // //- we are saving an iterable type // //- or we are saving an object, these seem to be reasonable assumptions. if (attributed_type(type)) { assert(!name.empty()); w->attribute(name, v); } else { size_t type_options = type->options(); if (type_options & TYPE_ITERATED) { iterable iter(v); iterator it = iter.begin(); iterator nd = iter.end(); WriteIterator wit = w->create_iterator(name, iter.iterated_type()); for(; it != nd; ++it) { variant iv = *it; Writer iw = wit->next(iv); if (iw) write(iw, "", iv); } } else { Writer writer_ = name.empty()? w : w->create_node(name); schema* otype = v.get_schema(); assert(otype); size_t oopt = otype->options(); if (oopt & TYPE_NON_INSTANTIABLE) { assert(type != otype); assert(types_); str class_id = types_->type_name(type); assert( !class_id.empty() ); w->attribute("class", class_id); } //collect what we're saving schema_collector sc; type->visit(&sc); schema_collector::container::iterator it = sc.begin(); schema_collector::container::iterator nd = sc.end(); for(; it != nd; it++) { schema_item& item = it->second; if (item.flags & CONST) continue; if (item.flags & TRANSIENT) continue; if (item.get) { variant value = item.get->get(this_); write(writer_, it->first, value); } } } } }