|
| 1 | +/** |
| 2 | + * Copyright (c) 2016-2017, Daniel "Dadie" Korner |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * Redistribution and use in source and binary forms, with or without |
| 6 | + * modification, are permitted provided that the following conditions are met: |
| 7 | + * |
| 8 | + * 1. Redistributions of source code must retain the above copyright |
| 9 | + * notice, this list of conditions and the following disclaimer. |
| 10 | + * 2. Neither the source code nor the binary may be used for any military use. |
| 11 | + * |
| 12 | + * THIS SOFTWARE IS PROVIDED BY Daniel "Dadie" Korner ''AS IS'' AND ANY |
| 13 | + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 14 | + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 15 | + * DISCLAIMED. IN NO EVENT SHALL Daniel "Dadie" Korner BE LIABLE FOR ANY |
| 16 | + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 17 | + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 18 | + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 19 | + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 20 | + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 21 | + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 22 | + **/ |
| 23 | + |
| 24 | +// Ext |
| 25 | +#include <boost/lexical_cast.hpp> |
| 26 | +#include <boost/property_tree/ptree.hpp> |
| 27 | +#include <boost/property_tree/xml_parser.hpp> |
| 28 | + |
| 29 | +// Own |
| 30 | +#include "rlib/android/meta.h" |
| 31 | + |
| 32 | +// StdLib |
| 33 | +#include <iostream> |
| 34 | +#include <sstream> |
| 35 | +#include <string> |
| 36 | + |
| 37 | +rlib::android::meta::meta(std::string filename) |
| 38 | +{ |
| 39 | + this->meta_filename = filename; |
| 40 | + this->data_filename = filename.substr(0, filename.size() - 4) + "data"; |
| 41 | + this->event_filename = filename.substr(0, filename.size() - 4) + "event"; |
| 42 | + |
| 43 | + boost::property_tree::ptree meta_xml; |
| 44 | + boost::property_tree::read_xml(this->meta_filename, meta_xml); |
| 45 | + |
| 46 | + this->version = |
| 47 | + meta_xml.get< std::string >("grim.<xmlattr>.version", "0.0"); |
| 48 | + this->name = meta_xml.get< std::string >("grim.meta.name"); |
| 49 | + this->init = meta_xml.get< uint64_t >("grim.meta.init"); |
| 50 | + |
| 51 | + std::string format_text(meta_xml.get< std::string >("grim.meta.format")); |
| 52 | + std::istringstream format_stream(format_text); |
| 53 | + std::string format_element; |
| 54 | + while (format_stream.good()) { |
| 55 | + std::getline(format_stream, format_element, '|'); |
| 56 | + this->format.push_back(format_element); |
| 57 | + } |
| 58 | + |
| 59 | + for (auto& value : meta_xml.get_child("grim.values")) { |
| 60 | + if (value.first != "value") { |
| 61 | + continue; |
| 62 | + } |
| 63 | + auto value_name = |
| 64 | + value.second.get< std::string >("<xmlattr>.name", "N.N"); |
| 65 | + auto value_type = |
| 66 | + value.second.get< std::string >("<xmlattr>.type", "N.N"); |
| 67 | + auto value_unit = |
| 68 | + value.second.get< std::string >("<xmlattr>.unit", "N.N"); |
| 69 | + this->type[ value_name ] = value_type; |
| 70 | + this->unit[ value_name ] = value_unit; |
| 71 | + } |
| 72 | +} |
0 commit comments