/***********************************************************************//** * @brief Read model from XML element * * @param[in] xml XML element containing power law model information. * * @exception GException::model_invalid_parnum * Invalid number of model parameters found in XML element. * @exception GException::model_invalid_parnames * Invalid model parameter name found in XML element. * * Read the function information from an XML element and load the nodes * from the associated file. The XML element is required to have an * attribute "file" that specifies the function nodes and a parameter * named "Normalization". ***************************************************************************/ void GModelSpectralFunc::read(const GXmlElement& xml) { // Verify that XML element has exactly 1 parameter if (xml.elements() != 1 || xml.elements("parameter") != 1) { throw GException::model_invalid_parnum(G_READ, xml, "Spectral function requires exactly 1 parameter."); } // Get parameter element GXmlElement* par = static_cast<GXmlElement*>(xml.element("parameter", 0)); // Get value if (par->attribute("name") == "Normalization") { m_norm.read(*par); } else { throw GException::model_invalid_parnames(G_READ, xml, "Require \"Normalization\" parameter."); } // Load nodes from file load_nodes(xml.attribute("file")); // Return return; }
bool Object::load_nodes(TiXmlNode *node) { int result = true; if (node->Type() == TiXmlNode::TINYXML_ELEMENT) { if (strcmp(node->Value(), "object") == 0) { result = load_object_attributes(node->ToElement()); } else if (strcmp(node->Value(), "string") == 0) { load_strings(node->ToElement()); } else { load_attributes(node->ToElement()); } } for (TiXmlNode *child = node->FirstChild(); child != 0; child = child->NextSibling()) { if (!load_nodes(child)) { result = false; } } return result; }
void load_config(config_type& config, boost::filesystem::path& config_path) { // Load values from config file. echo() << "Using config file: " << config_path; libconfig::Config configuration; set_config_path(configuration, config_path); // Read off values. // libconfig is ANSI/MBCS on Windows - no Unicode support. // This reads ANSI/MBCS values from XML. If they are UTF-8 (and above the // ASCII band) the values will be misinterpreted upon use. const libconfig::Setting& root = configuration.getRoot(); root.lookupValue("output-file", config.output_file); root.lookupValue("error-file", config.error_file); root.lookupValue("blockchain-path", config.blockchain_path); root.lookupValue("hosts-file", config.hosts_file); root.lookupValue("service", config.service); root.lookupValue("heartbeat", config.heartbeat); root.lookupValue("publisher_enabled", config.publisher_enabled); root.lookupValue("block-publish", config.block_publish); root.lookupValue("tx-publish", config.tx_publish); root.lookupValue("certificate", config.certificate); root.lookupValue("client-allowed-certs", config.client_allowed_certs); load_whitelist(root, config); root.lookupValue("name", config.name); root.lookupValue("outgoing-connections", config.outgoing_connections); root.lookupValue("listener_enabled", config.listener_enabled); load_nodes(root, config); root.lookupValue("log_requests", config.log_requests); root.lookupValue("history_db_active_height", config.history_db_active_height); }
template <typename INT> const INT *Node_Set<INT>::Nodes() const { // See if already loaded... if (!nodes) { load_nodes(); } return nodes; }
template <typename INT> void Node_Set<INT>::apply_map(const INT *node_map) { SMART_ASSERT(node_map != nullptr); if (nodes != nullptr) { delete[] nodes; nodes = nullptr; delete[] nodeIndex; nodeIndex = nullptr; } load_nodes(node_map); }
/***********************************************************************//** * @brief File constructor * * @param[in] filename File name of nodes. * * Creates instance of a spectral function model from a list of nodes that is * found in the specified file. See GModelSpectralFunc::load_nodes() for more * information about the expected structure of the file. ***************************************************************************/ GModelSpectralFunc::GModelSpectralFunc(const std::string& filename) : GModelSpectral() { // Initialise members init_members(); // Load nodes load_nodes(filename); // Return return; }
WorldDB::WorldDB(const char *name) : m_object_prefix(""), m_save_prefix(""), m_chest(0) { WorldNode::m_keygen = 1; TiXmlDocument doc(name); if (doc.LoadFile()) { load_nodes(&doc); m_status = new Status; } }
template <typename INT> size_t Node_Set<INT>::Node_Id(size_t position) const { if (numEntity <= 0) { return 0; } else { // See if already loaded... if (!nodes) { load_nodes(); } SMART_ASSERT(position < numEntity); return nodes[nodeIndex[position]]; } }
/***********************************************************************//** * @brief Read model from XML element * * @param[in] xml XML element. * * Reads the temporal information from an XML element. The XML element should * have the format * * <temporalModel type="LightCurve" file=".."> * <parameter name="Normalization" scale="1" value="1" min="0.1" max="10" free="1"/> * </temporalModel> ***************************************************************************/ void GModelTemporalLightCurve::read(const GXmlElement& xml) { // Get parameter pointers const GXmlElement* norm = gammalib::xml_get_par(G_READ, xml, m_norm.name()); // Read parameters m_norm.read(*norm); // Load nodes from file load_nodes(gammalib::xml_file_expand(xml, xml.attribute("file"))); // Return return; }
bool Object::load(const char *fn, MediaDB *media) { m_media = media; TiXmlDocument doc(fn); if (doc.LoadFile()) { load_nodes(&doc); m_fn = std::string(fn); int lastindex = m_fn.find_last_of("."); m_name = m_fn.substr(0, lastindex); } return m_loaded; }
/***********************************************************************//** * @brief File constructor * * @param[in] filename File name of nodes. * @param[in] norm Normalization factor. * * Constructs spectral file function model from a list of nodes that is found * in the specified ASCII file. See the load_nodes() method for more * information about the expected structure of the file. ***************************************************************************/ GModelSpectralFunc::GModelSpectralFunc(const GFilename& filename, const double& norm) : GModelSpectral() { // Initialise members init_members(); // Load nodes load_nodes(filename); // Set normalization m_norm.value(norm); // Return return; }
/***********************************************************************//** * @brief File constructor * * @param[in] filename File name of nodes. * @param[in] norm Normalization factor. * * Constructs light curve model from a list of nodes that is found in the * specified FITS file. See the load_nodes() method for more information * about the expected structure of the file. ***************************************************************************/ GModelTemporalLightCurve::GModelTemporalLightCurve(const GFilename& filename, const double& norm) : GModelTemporal() { // Initialise members init_members(); // Load nodes load_nodes(filename); // Set normalization m_norm.value(norm); // Return return; }
bool Object::load_nodes(TiXmlNode *node) { int result = true; if (node->Type() == TiXmlNode::TINYXML_ELEMENT) { if (strcmp(node->Value(), "object") == 0) { result = load_object_attributes(node->ToElement()); } else if (strcmp(node->Value(), "string") == 0) { load_strings(node->ToElement()); } else if (strcmp(node->Value(), "weak_parts") == 0) { m_weak_parts.push_back(new CollisionParts(node->ToElement())); } else if (strcmp(node->Value(), "weak_part") == 0) { if (m_weak_parts.size()) { CollisionParts *parts = m_weak_parts.back(); parts->add_parts(node->ToElement()); } } else if (strcmp(node->Value(), "shielded_parts") == 0) { m_shielded_parts.push_back(new CollisionParts(node->ToElement())); } else if (strcmp(node->Value(), "shielded_part") == 0) { if (m_shielded_parts.size()) { CollisionParts *parts = m_shielded_parts.back(); parts->add_parts(node->ToElement()); } } else { load_attributes(node->ToElement()); } } for (TiXmlNode *child = node->FirstChild(); child != 0; child = child->NextSibling()) { if (!load_nodes(child)) { result = false; } } return result; }
bool WorldDB::load_nodes(TiXmlNode *node) { int result = true; if (node->Type() == TiXmlNode::TINYXML_ELEMENT) { if (strcmp(node->Value(), "world") == 0) { result = load_world_attributes(node->ToElement()); } else if (strcmp(node->Value(), "object") == 0) { WorldObject *object = new WorldObject; result = load_object_attributes(object, node->ToElement()); if (result) { // Check if location exists, otherwise allocate new and insert WorldLocation *location = get_location(object->m_location.c_str()); if (location) { location->m_nodes.push_back(object); } } } else if (strcmp(node->Value(), "lock") == 0) { WorldLock *lock = new WorldLock; result = load_lock_attributes(lock, node->ToElement()); if (result) { // Check if location exists, otherwise allocate new and insert WorldLocation *location = get_location(lock->m_location.c_str()); if (location) { location->m_nodes.push_back(lock); } } } else if (strcmp(node->Value(), "chest") == 0) { WorldChest *chest = new WorldChest; result = load_chest_attributes(chest, node->ToElement()); if (result) { // Check if location exists, otherwise allocate new and insert WorldLocation *location = get_location(chest->m_location.c_str()); if (location) { m_chest = chest; location->m_nodes.push_back(chest); } } } else if (m_chest) { if (strcmp(node->Value(), "treasure") == 0) { WorldObject *object = new WorldObject; result = load_object_attributes(object, node->ToElement()); if (result) { m_chest->m_objects.push_back(object); } else { goto error; } } } } for (TiXmlNode *child = node->FirstChild(); child != 0; child = child->NextSibling()) { if (!load_nodes(child)) { result = false; } } error: return result; }
/***********************************************************************//** * @brief Loads nodes from node file and set filename * * @param[in] filename Node file name. * * Loads the nodes from a file function node file and sets the filename. ***************************************************************************/ inline void GModelSpectralFunc::filename(const GFilename& filename) { load_nodes(filename); return; }
/** Parse a keyfile * * @param _load_mesh : whether the mesh shall loaded * @return success : whether loading the data was successful * * The parameter can be used to prevent the loading of the mesh, * even though we use parse_mesh. We need this for includes. */ bool KeyFile::load(bool _load_mesh) { // read file auto my_filepath = resolve_include_filepath(get_filepath()); std::vector<char> char_buffer = read_binary_file(my_filepath); has_linebreak_at_eof = char_buffer.back() == '\n'; #ifdef QD_DEBUG std::cout << "done." << std::endl; #endif // init parallel worker if master file // if (parent_kf == this) // _wq.init_workers(1); // convert buffer into blocks size_t iLine = 0; std::string last_keyword; std::vector<std::string> line_buffer; std::vector<std::string> line_buffer_tmp; bool found_pgp_section = false; std::string line; auto string_buffer = std::string(char_buffer.begin(), char_buffer.end()); std::stringstream st(string_buffer); // for (; std::getline(st, line); ++iLine) { for (; std::getline(st, line); ++iLine) { if (line.find("-----BEGIN PGP") != std::string::npos) { found_pgp_section = true; #ifdef QD_DEBUG std::cout << "Found PGP Section\n"; #endif } // remove windows file ending ... I hate it ... if (line.size() != 0 && line.back() == '\r') line.pop_back(); // new keyword if (line[0] == '*' || found_pgp_section) { if (!line_buffer.empty() && !last_keyword.empty()) { // transfer possible header for following keyword (see function) transfer_comment_header(line_buffer, line_buffer_tmp); // get type auto kw_type = Keyword::determine_keyword_type(last_keyword); #ifdef QD_DEBUG std::cout << last_keyword << " -> "; switch (kw_type) { case (Keyword::KeywordType::NODE): std::cout << "NODE\n"; break; case (Keyword::KeywordType::ELEMENT): std::cout << "ELEMENT\n"; break; case (Keyword::KeywordType::PART): std::cout << "PART\n"; break; case (Keyword::KeywordType::GENERIC): std::cout << "GENERIC\n"; break; case (Keyword::KeywordType::INCLUDE): std::cout << "INCLUDE\n"; break; case (Keyword::KeywordType::INCLUDE_PATH): std::cout << "INCLUDE_PATH\n"; break; } #endif auto kw = create_keyword(line_buffer, kw_type, iLine - line_buffer.size() - line_buffer_tmp.size() + 1); if (kw) keywords[kw->get_keyword_name()].push_back(kw); // transfer cropped data line_buffer = line_buffer_tmp; } // we always trim keywords trim_right(line); last_keyword = line; } // IF:line[0] == '*' // Encrypted Sections // // Extracts encrypted section here and places it in a line in the // line buffer. An encrypted section is treated like a keyword. if (found_pgp_section) { found_pgp_section = false; // get stream position const auto stream_position = st.tellg(); const auto end_position = string_buffer.find("-----END PGP", stream_position); if (end_position == std::string::npos) throw( std::runtime_error("Could not find \"-----END PGP MESSAGE-----\" for " "corresponding \"-----BEGIN PGP MESSAGE-----\" ")); // set stream position behind encrypted section st.seekg(end_position); // extract encrypted stuff line += '\n'; line += std::string(char_buffer.begin() + stream_position, char_buffer.begin() + end_position); // print_string_as_hex(line); if (line.back() == '\n') line.pop_back(); if (line.back() == '\r') line.pop_back(); } // we stupidly add every line to the buffer line_buffer.push_back(line); } // for:line // allocate last block if (!line_buffer.empty() && !last_keyword.empty()) { auto kw = create_keyword(line_buffer, Keyword::determine_keyword_type(last_keyword), iLine - line_buffer.size() + 1); if (kw) keywords[kw->get_keyword_name()].push_back(kw); } // only load files above *END! const auto end_kw_position = get_end_keyword_position(); // includes if (load_includes) { // update include dirs get_include_dirs(true); // do the thing for (auto& include_kw : include_keywords) { if (include_kw->get_position() < end_kw_position) // Note: prevent loading the mesh here include_kw->load(false); } } // wait for threads to finish preloading // _wq.wait_for_completion(); // Wait for completion // while (work_queue.size() != 0) { // work_queue.front().wait(); // work_queue.pop(); // } // load mesh if requested if (parse_mesh && _load_mesh) { // load nodes load_nodes(); // load parts load_parts(); // load elements load_elements(); } return true; }