void RuleMatrix::use_external_matrix(const std::string& path) { std::ifstream file(path); //file format // DECISIONS SCORES // D D C 3 3 0 if (file.good()) { while (std::getline(file, _line)) { _parts.clear(); _decision.clear(); _score.clear(); _split_string(_line); for (auto part: _parts) { if (part == "D") { _decision.push_back(DEFECT); } else if (part == "C") { _decision.push_back(COOPERATE); } else { _score.push_back(std::stoi(part)); } } _matrix[_decision] = _score; } file.close(); } }
bool STACKReader::_parse_record(Record& record, std::string& line) { std::vector<std::string> data; _split_string(data, line, '\t'); if (data.size() == 4) { record.count = atoi(data.at(0).c_str()); record.seq = data.at(1); record.frag1_length = atoi(data.at(2).c_str()); record.frag2_length = atoi(data.at(3).c_str()); } else false; return true; }
bool STACKReader::_parse_splice_junction(splice_junction& sj, std::string& line) { std::vector<std::string> data; _split_string(data, line, '\t'); if (data.size() == 5) { // Properly formatted stacker junction data.at(0).erase(0, 1); // Remove '@' symbol sj.ref = data.at(0); sj.donor_acceptor = data.at(1); sj.start = atoi(data.at(2).c_str()); sj.end = atoi(data.at(3).c_str()); } else return false; return true; }
void ResourceManager::LoadMesh(const std::string& fileName, Mesh& mesh) { std::vector<std::string> splits; int split_length = 0; split_length = _split_string(fileName, std::string("."), splits); IndexedModel *model; if (splits[split_length - 1] == "obj") { model = new ObjModel(fileName); model->loadToMesh(&mesh); delete model; } else { throw ResourceException("Mesh loading for file type " + splits[split_length - 1] + " not implemented yet"); } }
void ResourceManager::loadAudio(const std::string& fileName, AudioResource *resource) { std::vector<std::string> splits; int split_length = 0; split_length = _split_string(fileName, std::string("."), splits); AudioModel *model; if (splits[split_length - 1] == "wav") { // Parse model = new WavModel(std::string(fileName)); model->loadToAudio(resource); delete model; } else { throw ResourceException("Audio loading for file " + fileName + " not implemented yet."); } }
void ResourceManager::LoadShader(const std::string& fileName, std::string& shader_string) { shader_string.clear(); // Find path of the file - for later use std::string path; _get_path(fileName, path); std::ifstream file; file.open(fileName.c_str()); std::string line; if (file.is_open()) { while (file.good()) { std::getline(file, line); if (line.find(INCLUDE_KEYWORD) != std::string::npos) { // Parse included files std::vector<std::string> include_file; _split_string(line, " ", include_file); std::string included_file_string; LoadShader(path + include_file[1].substr(1, include_file[1].length() - 2), included_file_string); shader_string.append(included_file_string + "\n"); } else { shader_string.append(line + "\n"); } } } else { throw ResourceException("Unable to load shader: " + fileName); } }
nmea_s * nmea_parse(char *sentence, int length, int check_checksum) { nmea_t type = nmea_get_type(sentence); if (NMEA_UNKNOWN == type) { return (nmea_s *) NULL; } int n_vals; int val_index = 0; char *value; char *values[255]; nmea_parser_module_s *parser; /* Validate */ if (-1 == nmea_validate(sentence, length, check_checksum)) { return (nmea_s *) NULL; } /* Crop sentence from type word and checksum */ char *val_string = _crop_sentence(sentence, length); if (NULL == val_string) { return (nmea_s *) NULL; } /* Split the sentence into values */ n_vals = _split_string(val_string, values); if (0 == n_vals) { return (nmea_s *) NULL; } /* Get the right parser */ parser = nmea_get_parser_by_type(type); if (NULL == parser) { return (nmea_s *) NULL; } /* Allocate memory for parsed data */ parser->allocate_data((nmea_parser_s *) parser); if (NULL == parser->parser.data) { return (nmea_s *) NULL; } /* Set default values */ parser->set_default((nmea_parser_s *) parser); parser->errors = 0; /* Loop through the values and parse them... */ while (val_index < n_vals) { value = values[val_index]; if (-1 == _is_value_set(value)) { val_index++; continue; } if (-1 == parser->parse((nmea_parser_s *) parser, value, val_index)) { parser->errors++; } val_index++; } parser->parser.data->type = type; parser->parser.data->errors = parser->errors; return parser->parser.data; }